Version: 9.16.0
SceneDataPortItem.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#include "SceneDataPortItem.hxx"
21#include "SceneTextItem.hxx"
22#include "SceneNodeItem.hxx"
23#include "SceneLinkItem.hxx"
24#include "Scene.hxx"
25
26#include "QtGuiContext.hxx"
27
28#include "Resource.hxx"
29
30//#define _DEVDEBUG_
31#include "YacsTrace.hxx"
32
33using namespace std;
34using namespace YACS::ENGINE;
35using namespace YACS::HMI;
36
37
38SceneDataPortItem::SceneDataPortItem(QGraphicsScene *scene, SceneItem *parent,
39 QString label, Subject *subject)
40 : SceneObserverItem(scene, parent, label, subject), ScenePortItem(label)
41{
42 setText(label);
45 switch (getSubject()->getType())
46 {
47 case INPUTPORT:
48 case OUTPUTPORT:
53 break;
60 break;
61 }
62}
63
65{
66 DEBTRACE("ScenePortItem::~SceneDataPortItem");
67}
68
69void SceneDataPortItem::paint(QPainter *painter,
70 const QStyleOptionGraphicsItem *option,
71 QWidget *widget)
72{
73 DEBTRACE("ScenePortItem::paint");
74 painter->save();
75
76 QPen pen(getPenColor());
77 pen.setWidth(Resource::Thickness);
78 painter->setPen(pen);
79 painter->setBrush(getBrushColor());
81 painter->drawRoundedRect(rect, Resource::Radius, Resource::Radius);
82
83 painter->restore();
84}
85
86void SceneDataPortItem::setText(QString label)
87{
88 if (!_text)
90 this,
91 label );
92}
93
94void SceneDataPortItem::update(GuiEvent event, int type, Subject* son)
95{
96 DEBTRACE("SceneDataPortItem::update "<< eventName(event)<<" "<<type<<" "<<son);
97 SceneObserverItem::update(event, type, son);
98 switch (event)
99 {
101 _text->setPlainTextTrunc(son->getName().c_str());
102 QGraphicsItem::update();
103 break;
105 SceneObserverItem::update(event, type, son);
106 break;
107 }
108}
109
111{
112 if (_parent)
113 return dynamic_cast<SceneNodeItem*>(_parent);
114 else
115 return 0;
116}
117
119{
120 DEBTRACE("SceneDataPortItem::updateChildItems " << _label.toStdString());
121 if(SubjectDataPort* sdp=dynamic_cast<SubjectDataPort*>(_subject))
122 {
123 std::list<SubjectLink*> lsl=sdp->getListOfSubjectLink();
124 for (std::list<SubjectLink*>::const_iterator it = lsl.begin(); it != lsl.end(); ++it)
125 {
127 item->updateShape();
128 }
129 }
130}
131
133{
134 DEBTRACE("SceneDataPortItem::updateLinks " << _label.toStdString());
135 if(SubjectDataPort* sdp=dynamic_cast<SubjectDataPort*>(_subject))
136 {
137 std::list<SubjectLink*> lsl=sdp->getListOfSubjectLink();
138 for (std::list<SubjectLink*>::const_iterator it = lsl.begin(); it != lsl.end(); ++it)
139 {
141 item->updateShape();
142 }
143 }
144}
145
147{
148 if(SubjectDataPort* sdp=dynamic_cast<SubjectDataPort*>(_subject))
149 {
150 std::list<SubjectLink*> lsl=sdp->getListOfSubjectLink();
151 for (std::list<SubjectLink*>::const_iterator it = lsl.begin(); it != lsl.end(); ++it)
152 {
154 if (se) {
155 item->show();
156 } else {
157 item->hide();
158 };
159 }
160 }
161}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
YACS::HMI::Scene * _scene
Definition: SceneItem.hxx:98
static std::string eventName(GuiEvent event)
static QtGuiContext * getQtCurrent()
std::map< YACS::HMI::Subject *, YACS::HMI::SceneItem * > _mapOfSceneItem
static int DataPort_Width
Definition: Resource.hxx:305
static QColor DataPort_brush
Definition: Resource.hxx:291
static QColor DataStreamPort_hiBrush
Definition: Resource.hxx:296
static QColor DataPort_hiBrush
Definition: Resource.hxx:292
static QColor DataStreamPort_hiPen
Definition: Resource.hxx:298
static QColor DataStreamPort_pen
Definition: Resource.hxx:297
static int DataPort_Height
Definition: Resource.hxx:306
static QColor DataPort_pen
Definition: Resource.hxx:293
static QColor DataStreamPort_brush
Definition: Resource.hxx:295
static int Thickness
Definition: Resource.hxx:308
static QColor DataPort_hiPen
Definition: Resource.hxx:294
static int Radius
Definition: Resource.hxx:320
virtual void shrinkExpandLink(bool se)
virtual void update(GuiEvent event, int type, Subject *son)
virtual SceneNodeItem * getParent()
virtual void setText(QString label)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
virtual QColor getPenColor()
virtual void update(GuiEvent event, int type, Subject *son)
virtual void setPlainTextTrunc(QString label)
virtual std::string getName()
@ OUTPUTDATASTREAMPORT
@ INPUTDATASTREAMPORT