Version: 8.3.0
SceneDataPortItem.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
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 
33 using namespace std;
34 using namespace YACS::ENGINE;
35 using namespace YACS::HMI;
36 
37 
38 SceneDataPortItem::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 
69 void 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 
86 void SceneDataPortItem::setText(QString label)
87 {
88  if (!_text)
90  this,
91  label );
92 }
93 
94 void 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  {
100  case YACS::HMI::RENAME:
101  _text->setPlainTextTrunc(son->getName().c_str());
102  QGraphicsItem::update();
103  break;
104  case YACS::HMI::REMOVE:
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 }