1 // Copyright (C) 2006-2008 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.
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
19 #include "SceneElementaryNodeItem.hxx"
20 #include "SceneInPortItem.hxx"
21 #include "SceneOutPortItem.hxx"
22 #include "guiObservers.hxx"
23 #include "commandsProc.hxx"
25 #include "ElementaryNode.hxx"
26 #include "InputPort.hxx"
27 #include "OutputPort.hxx"
29 #include "QtGuiContext.hxx"
35 #include "YacsTrace.hxx"
38 using namespace YACS::ENGINE;
39 using namespace YACS::HMI;
41 SceneElementaryNodeItem::SceneElementaryNodeItem(QGraphicsScene *scene, SceneItem *parent,
42 QString label, Subject *subject)
43 : SceneNodeItem(scene, parent, label, subject)
45 _brushColor = QColor(189,230,185);
46 _hiBrushColor = QColor(209,255,205);
47 _penColor = QColor( 15,180, 0);
48 _hiPenColor = QColor( 11,128, 0);
51 SceneElementaryNodeItem::~SceneElementaryNodeItem()
55 //! SceneElementaryNodeItem cannot be resized (only ComposedNodeItem can)
56 void SceneElementaryNodeItem::setWidth(qreal width)
60 //! SceneElementaryNodeItem cannot be resized (only ComposedNodeItem can)
61 void SceneElementaryNodeItem::setHeight(qreal height)
65 void SceneElementaryNodeItem::paint(QPainter *painter,
66 const QStyleOptionGraphicsItem *option,
69 //DEBTRACE("SceneElementaryNodeItem::paint");
71 painter->setBrush(QBrush(Qt::NoBrush));
72 painter->setPen(QPen(Qt::NoPen));
73 painter->drawRect(QRectF(0, 0, _width, _height));
74 painter->setPen(getPenColor());
75 painter->setBrush(getBrushColor());
76 painter->drawRect(QRectF(_nml, _nml,
77 _width-2*_nml, _height-2*_nml));
81 void SceneElementaryNodeItem::update(GuiEvent event, int type, Subject* son)
83 DEBTRACE("SceneElementaryNodeItem::update "<< eventName(event)<<" "<<type<<" "<<son);
84 SceneNodeItem::update(event, type, son);
91 case YACS::HMI::INPUTPORT:
92 case YACS::HMI::INPUTDATASTREAMPORT:
93 item = new SceneInPortItem(_scene,
95 son->getName().c_str(),
97 autoPosNewPort(item, _inPorts.size());
98 _inPorts.push_back(item);
100 case YACS::HMI::OUTPUTPORT:
101 case YACS::HMI::OUTPUTDATASTREAMPORT:
102 item = new SceneOutPortItem(_scene,
104 son->getName().c_str(),
106 autoPosNewPort(item, _outPorts.size());
107 _outPorts.push_back(item);
110 // DEBTRACE("SceneElementaryNodeItem::update() ADD, type not handled:" << type);
113 case YACS::HMI::REMOVE:
114 case YACS::HMI::SYNCHRO:
118 // DEBTRACE("SceneElementaryNodeItem::update(), event not handled:" << eventName(event));
122 void SceneElementaryNodeItem::popupMenu(QWidget *caller, const QPoint &globalPos)
124 ElementaryNodeMenu m;
125 m.popupMenu(caller, globalPos);
128 void SceneElementaryNodeItem::reorganize()
130 DEBTRACE("SceneElementaryNodeItem::reorganize() " << _label.toStdString());
132 SubjectNode* snode = dynamic_cast<SubjectNode*>(_subject);
133 ElementaryNode* father = dynamic_cast<ElementaryNode*>(snode->getNode());
136 list<InputPort*> plisti = father->getSetOfInputPort();
137 list<InputPort*>::iterator iti = plisti.begin();
139 for (; iti != plisti.end(); ++iti)
141 Subject *sub = QtGuiContext::getQtCurrent()->_mapOfSubjectDataPort[(*iti)];
142 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
143 autoPosNewPort(item, nbPorts);
147 list<OutputPort*> plisto = father->getSetOfOutputPort();
148 list<OutputPort*>::iterator ito = plisto.begin();
150 for (; ito != plisto.end(); ++ito)
152 Subject *sub = QtGuiContext::getQtCurrent()->_mapOfSubjectDataPort[(*ito)];
153 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
154 autoPosNewPort(item, nbPorts);