1 // Copyright (C) 2006-2014 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SceneDataPortItem.hxx"
21 #include "SceneTextItem.hxx"
22 #include "SceneNodeItem.hxx"
23 #include "SceneLinkItem.hxx"
26 #include "QtGuiContext.hxx"
28 #include "Resource.hxx"
31 #include "YacsTrace.hxx"
34 using namespace YACS::ENGINE;
35 using namespace YACS::HMI;
38 SceneDataPortItem::SceneDataPortItem(QGraphicsScene *scene, SceneItem *parent,
39 QString label, Subject *subject)
40 : SceneObserverItem(scene, parent, label, subject), ScenePortItem(label)
43 _width = Resource::DataPort_Width;
44 _height = Resource::DataPort_Height;
45 switch (getSubject()->getType())
49 _brushColor = Resource::DataPort_brush;
50 _hiBrushColor = Resource::DataPort_hiBrush;
51 _penColor = Resource::DataPort_pen;
52 _hiPenColor = Resource::DataPort_hiPen;
54 case INPUTDATASTREAMPORT:
55 case OUTPUTDATASTREAMPORT:
56 _brushColor = Resource::DataStreamPort_brush;
57 _hiBrushColor = Resource::DataStreamPort_hiBrush;
58 _penColor = Resource::DataStreamPort_pen;
59 _hiPenColor = Resource::DataStreamPort_hiPen;
64 SceneDataPortItem::~SceneDataPortItem()
66 DEBTRACE("ScenePortItem::~SceneDataPortItem");
69 void SceneDataPortItem::paint(QPainter *painter,
70 const QStyleOptionGraphicsItem *option,
73 DEBTRACE("ScenePortItem::paint");
76 QPen pen(getPenColor());
77 pen.setWidth(Resource::Thickness);
79 painter->setBrush(getBrushColor());
80 QRectF rect(0, 0, Resource::DataPort_Width, Resource::DataPort_Height);
81 painter->drawRoundedRect(rect, Resource::Radius, Resource::Radius);
86 void SceneDataPortItem::setText(QString label)
89 _text = new SceneTextItem(_scene,
94 void SceneDataPortItem::update(GuiEvent event, int type, Subject* son)
96 DEBTRACE("SceneDataPortItem::update "<< eventName(event)<<" "<<type<<" "<<son);
97 SceneObserverItem::update(event, type, son);
100 case YACS::HMI::RENAME:
101 _text->setPlainTextTrunc(son->getName().c_str());
102 QGraphicsItem::update();
104 case YACS::HMI::REMOVE:
105 SceneObserverItem::update(event, type, son);
110 SceneNodeItem* SceneDataPortItem::getParent()
113 return dynamic_cast<SceneNodeItem*>(_parent);
118 void SceneDataPortItem::updateChildItems()
120 DEBTRACE("SceneDataPortItem::updateChildItems " << _label.toStdString());
121 if(SubjectDataPort* sdp=dynamic_cast<SubjectDataPort*>(_subject))
123 std::list<SubjectLink*> lsl=sdp->getListOfSubjectLink();
124 for (std::list<SubjectLink*>::const_iterator it = lsl.begin(); it != lsl.end(); ++it)
126 SceneLinkItem* item = dynamic_cast<SceneLinkItem*>(QtGuiContext::getQtCurrent()->_mapOfSceneItem[*it]);
132 void SceneDataPortItem::updateLinks()
134 DEBTRACE("SceneDataPortItem::updateLinks " << _label.toStdString());
135 if(SubjectDataPort* sdp=dynamic_cast<SubjectDataPort*>(_subject))
137 std::list<SubjectLink*> lsl=sdp->getListOfSubjectLink();
138 for (std::list<SubjectLink*>::const_iterator it = lsl.begin(); it != lsl.end(); ++it)
140 SceneLinkItem* item = dynamic_cast<SceneLinkItem*>(QtGuiContext::getQtCurrent()->_mapOfSceneItem[*it]);
146 void SceneDataPortItem::shrinkExpandLink(bool se)
148 if(SubjectDataPort* sdp=dynamic_cast<SubjectDataPort*>(_subject))
150 std::list<SubjectLink*> lsl=sdp->getListOfSubjectLink();
151 for (std::list<SubjectLink*>::const_iterator it = lsl.begin(); it != lsl.end(); ++it)
153 SceneLinkItem* item = dynamic_cast<SceneLinkItem*>(QtGuiContext::getQtCurrent()->_mapOfSceneItem[*it]);