1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SUPERVGUI_ComputeNode.cxx
8 // Author : Vitaly SMETANNIKOV
12 #include "SUPERVGUI_GraphNode.h"
13 #include "SUPERVGUI_Graph.h"
14 #include "SUPERVGUI_Main.h"
17 SUPERVGUI_GraphNode::SUPERVGUI_GraphNode(QWidget* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode)
18 :SUPERVGUI_Node(theParent, theMain, theNode),
22 //disconnect(myTitle, 0, this, 0);
23 myTitle = new SUPERVGUI_Label(this, LABEL_WIDTH, LABEL_HEIGHT, name(), QLabel::AlignLeft);
25 connect(myTitle, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(mouseTitlePress(QMouseEvent*)));
26 connect(myTitle, SIGNAL(MouseMove (QMouseEvent*)), this, SLOT(mouseTitleMove(QMouseEvent*)));
27 connect(myTitle, SIGNAL(MouseRelease(QMouseEvent*)), this, SLOT(mouseTitleRelease(QMouseEvent*)));
29 myPortsBox = new QFrame(0);
30 myPortLayout = new QGridLayout(myPortsBox, 0, 2, 0, 1);
32 myTimer = new QTimer(this);
33 connect(myTimer, SIGNAL(timeout()), this, SLOT(movingNode(/*QMouseEvent* e*/)));
45 SUPERV_Ports ports = myNode->Ports();
46 int n = ports->length();
48 for (int i=0; i<n; i++) {
49 if (ports[i]->IsInput()) {
50 myPortLayout->addWidget(new SUPERVGUI_PortIn(myPortsBox, myMain, ports[i]),
54 myPortLayout->addWidget(new SUPERVGUI_PortOut(myPortsBox, myMain, ports[i]),
55 myPOcount, 1, Qt::AlignRight);
63 SUPERVGUI_GraphNode::~SUPERVGUI_GraphNode() {
66 void SUPERVGUI_GraphNode::mouseTitlePress(QMouseEvent* e) {
67 if (!myMain->getGraph()->isAnyLinkCreating()) {
68 if (e->button() == RightButton) {
73 SUPERVGUI_Graph* sv = myMain->getGraph();
74 MouseX = sv->childX(this) - e->globalX();
75 MouseY = sv->childY(this) - e->globalY();
80 void SUPERVGUI_GraphNode::mouseTitleMove(QMouseEvent* e) {
81 Trace("SUPERVGUI_Node::moveAgain")
82 SUPERVGUI_Graph* sv = myMain->getGraph();
84 if ((MouseX == MouseNo) && (MouseY == MouseNo)) {
85 MouseX = sv->childX(this) - e->globalX();
86 MouseY = sv->childY(this) - e->globalY();
87 MouseLeft = (e->state() == RightButton? 0: 1);
92 int x = e->globalX()+MouseX;
93 int y = e->globalY()+MouseY;
97 if (x > myMain->getGraph()->horizontalScrollBar()->value()
98 + myMain->getGraph()->viewport()->width() - width()/2
100 y > myMain->getGraph()->verticalScrollBar()->value()
101 + myMain->getGraph()->viewport()->height() - height()/2
103 x < myMain->getGraph()->horizontalScrollBar()->value()
105 y < myMain->getGraph()->verticalScrollBar()->value()){
106 if (!myTimer->isActive()) {
109 myDifX = x - myNode->X();
110 myDifY = y - myNode->Y();
111 myFirstDifX = myDifX;
112 myFirstDifY = myDifY;
118 if (x - myNode->X() > 15 && abs(myDifX) < abs(myDifY)) {
119 if (x > myMain->getGraph()->horizontalScrollBar()->value()
120 + myMain->getGraph()->viewport()->width() - width()/2)
121 myDifX = 5; // or another positive number
123 //not out of the right boundary
124 sv->moveChild(this, x, myNode->Y()); //new X and old Y
125 myNode->Coords(x, myNode->Y());
130 if (x - myNode->X() < -15 && abs(myDifX) < abs(myDifY)) {
131 if(x < myMain->getGraph()->horizontalScrollBar()->value())
132 myDifX = -5; //or another negative number
134 //not out of the left boundary
135 sv->moveChild(this, x, myNode->Y()); //new X and old Y
136 myNode->Coords(x, myNode->Y());
141 if (y - myNode->Y() > 15 && abs(myDifX) > abs(myDifY)) {
142 if (y > myMain->getGraph()->verticalScrollBar()->value()
143 + myMain->getGraph()->viewport()->height() - height()/2)
144 myDifY = 5; //or another positive number
146 //not out of the lower boundary
147 sv->moveChild(this, myNode->X(), y); //old X and new Y
148 myNode->Coords(myNode->X(), y);
153 if (y - myNode->Y() < -15 && abs(myDifX) > abs(myDifY)) {
154 if (y < myMain->getGraph()->verticalScrollBar()->value())
155 myDifY = -5; //or another negative number
157 //not out of the upper boundary
158 sv->moveChild(this, myNode->X(), y); //old X and new Y
159 myNode->Coords(myNode->X(), y);
166 if ((myDifX*(x - myNode->X()) < 0 || myDifY*(y - myNode->Y()) < 0)) {
170 //for mouse moving to boundaries from outside space (chack then node must be move)
171 int xp1, yp1, xp2, yp2;
172 xp1 = myMain->getGraph()->horizontalScrollBar()->value();
173 xp2 = myMain->getGraph()->horizontalScrollBar()->value() +
174 myMain->getGraph()->viewport()->width();
175 yp1 = myMain->getGraph()->verticalScrollBar()->value();
176 yp2 = myMain->getGraph()->verticalScrollBar()->value() +
177 myMain->getGraph()->viewport()->height();
179 && x <= xp1+myMain->getGraph()->viewport()->visibleRect().width()
181 && y <= yp1+myMain->getGraph()->viewport()->visibleRect().height()) {
182 sv->moveChild(this, x, y);
183 myNode->Coords(x, y);
190 void SUPERVGUI_GraphNode::mouseTitleRelease(QMouseEvent* e) {
195 void SUPERVGUI_GraphNode::movingNode() {
196 SUPERVGUI_Graph* sv = myMain->getGraph();
198 myX = myX<0 ? 0: myX;
199 myY = myY<0 ? 0: myY;
210 myMain->getGraph()->ResizeGraph(this, myX, myY);
211 myMain->getGraph()->scrollBy( myX - myNode->X(), myY - myNode->Y() );
212 sv->moveChild(this, myX, myY);
213 myNode->Coords(myX, myY);
216 void SUPERVGUI_GraphNode::StartTimer() {
217 Trace("SUPERVGUI_Main::StartTimer")
218 if (!myTimer->isActive()) {
223 void SUPERVGUI_GraphNode::StopTimer() {
224 Trace("SUPERVGUI_Main::StopTimer")
225 if (myTimer->isActive()) {
230 void SUPERVGUI_GraphNode::deleteLinks() {
231 QObjectList* aList = queryList("SUPERVGUI_Port");
232 SUPERVGUI_Port* aPort;
233 QObjectListIt aIt(*aList);
234 while ((aPort=(SUPERVGUI_Port*)aIt.current()) != 0) {
236 aPort->deleteLinks();
242 void SUPERVGUI_GraphNode::sync() {
243 SUPERVGUI_Node::sync();
246 QObjectList* ihmList = queryList("SUPERVGUI_Port");
247 QObjectListIt i(*ihmList);
248 while ((pi=(SUPERVGUI_Port*)i.current()) != 0) {
254 //check: is creation of link is complete
255 if (myMain->getGraph()->isAnyLinkCreating()) {
256 //not creation complete
257 //cout<<" --- $$$ 1"<<endl;
258 myPopup->setItemEnabled(myDeleteItem, false);
262 myPopup->setItemEnabled(myDeleteItem, true);
268 * Creates presentation of links to In ports
269 * If toCheckExisting = false the links will be created without checking
270 * of their existing in Graph
271 * If toCheckExisting = true the existing of links will be checked before creation
273 void SUPERVGUI_GraphNode::updateLinksPrs(bool toCheckExisting) {
274 SUPERVGUI_Graph* aGraph= myMain->getGraph();
275 SUPERVGUI_PortIn* pi;
276 QObjectList* ihmList = queryList("SUPERVGUI_PortIn");
277 QObjectListIt i(*ihmList);
278 while ((pi=(SUPERVGUI_PortIn*)i.current()) != 0) {
280 if (pi->getPort()->IsLinked()) {
281 SUPERV_Link aLink = pi->getPort()->Link();
282 if (toCheckExisting) {
283 if (aGraph->isLinkPrsExists(aLink))
286 aGraph->createLinkPrs(aLink);
294 void SUPERVGUI_GraphNode::setNodeName(QString theName) {
295 SUPERVGUI_Node::setNodeName(theName);
296 myTitle->setText(name());
300 void SUPERVGUI_GraphNode::deletePort(SUPERVGUI_Port* thePort) {
301 if (thePort->isA("SUPERVGUI_PortIn") || thePort->isA("SUPERVGUI_PortInESNode")) {
307 thePort->deleteLinks();
309 thePort->getPort()->destroy();
310 thePort->close(true);
316 void SUPERVGUI_GraphNode::addInputPort() {
317 SUPERV_Port aPort = createInPort();
318 if (aPort == NULL) return;
320 if (getNodeType() == SUPERV::EndSwitchNode) {
321 SUPERVGUI_PortInESNode* aPortPrs = new SUPERVGUI_PortInESNode(myPortsBox, myMain, aPort);
322 myPortLayout->addWidget(aPortPrs, myPIcount, 0);
324 if (myPortsBox->isVisible()) {
329 SUPERVGUI_PortIn* aPortPrs = new SUPERVGUI_PortIn(myPortsBox, myMain, aPort);
330 myPortLayout->addWidget(aPortPrs, myPIcount, 0);
332 if (myPortsBox->isVisible()) {
343 void SUPERVGUI_GraphNode::addOutputPort() {
344 SUPERV_Port aPort = createOutPort();
345 if (aPort == NULL) return;
347 SUPERVGUI_PortOut* aPortPrs = new SUPERVGUI_PortOut(myPortsBox, myMain, aPort);
348 myPortLayout->addWidget(aPortPrs, myPOcount, 1, Qt::AlignRight);
350 if (myPortsBox->isVisible()) {
358 void SUPERVGUI_GraphNode::updatePorts() {
359 bool isAdded = false;
360 SUPERV_Ports aPorts = getEngine()->Ports();
361 int n = aPorts->length();
362 SUPERVGUI_Port* aPortPrs;
363 bool aIsVisible = myPortsBox->isVisible();
364 for (int i=0; i < n; i++) {
365 QString aName(aPorts[i]->Name());
366 aName += (aPorts[i]->IsInput())? "Input":"Output";
367 aPortPrs = (SUPERVGUI_Port*) child(aName, "SUPERVGUI_Port");
368 if (aPortPrs == NULL) {
369 if (aPorts[i]->IsInput()) {
370 SUPERVGUI_PortIn* aPortIn = new SUPERVGUI_PortIn(myPortsBox, myMain, aPorts[i]);
371 myPortLayout->addWidget(aPortIn, myPIcount, 0);
372 if (aIsVisible) aPortIn->show();
376 SUPERVGUI_PortOut* aPortOut = new SUPERVGUI_PortOut(myPortsBox, myMain, aPorts[i]);
377 myPortLayout->addWidget(aPortOut, myPOcount, 1, Qt::AlignRight);
378 if (aIsVisible) aPortOut->show();
385 QObjectList* aShownPortsList = queryList("SUPERVGUI_Port");
386 QObjectListIt aLI(*aShownPortsList);
387 SUPERVGUI_Port* aVisPort;
389 while ((aVisPort=(SUPERVGUI_Port*)aLI.current()) != 0) {
391 QString aNameVisible(aVisPort->getPort()->Name());
393 bool aIsExists = false;
394 for (int i=0; i < n; i++) {
395 QString aName(aPorts[i]->Name());
396 if (aName == aNameVisible)
400 if (!aIsExists) { //we have a visible object, which has no engine entity
401 aVisPort->close(true);