2 // File : SUPERVGUI_ComputeNode.cxx
3 // Created : 09 / 01 / 2003
4 // Author : Vitaly SMETANNIKOV
7 // Copyright : Open CASCADE
9 #include "SUPERVGUI_GraphNode.h"
10 #include "SUPERVGUI_Graph.h"
11 #include "SUPERVGUI_Main.h"
14 SUPERVGUI_GraphNode::SUPERVGUI_GraphNode(QWidget* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode)
15 :SUPERVGUI_Node(theParent, theMain, theNode),
19 //disconnect(myTitle, 0, this, 0);
20 myTitle = new SUPERVGUI_Label(this, LABEL_WIDTH, LABEL_HEIGHT, name(), QLabel::AlignLeft);
22 connect(myTitle, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(mouseTitlePress(QMouseEvent*)));
23 connect(myTitle, SIGNAL(MouseMove (QMouseEvent*)), this, SLOT(mouseTitleMove(QMouseEvent*)));
24 connect(myTitle, SIGNAL(MouseRelease(QMouseEvent*)), this, SLOT(mouseTitleRelease(QMouseEvent*)));
26 myPortsBox = new QFrame(0);
27 myPortLayout = new QGridLayout(myPortsBox, 0, 2, 0, 1);
29 myTimer = new QTimer(this);
30 connect(myTimer, SIGNAL(timeout()), this, SLOT(movingNode(/*QMouseEvent* e*/)));
42 SUPERV_Ports ports = myNode->Ports();
43 int n = ports->length();
45 for (int i=0; i<n; i++) {
46 if (ports[i]->IsInput()) {
47 myPortLayout->addWidget(new SUPERVGUI_PortIn(myPortsBox, myMain, ports[i]),
51 myPortLayout->addWidget(new SUPERVGUI_PortOut(myPortsBox, myMain, ports[i]),
52 myPOcount, 1, Qt::AlignRight);
60 SUPERVGUI_GraphNode::~SUPERVGUI_GraphNode() {
63 void SUPERVGUI_GraphNode::mouseTitlePress(QMouseEvent* e) {
64 if (e->button() == RightButton) {
69 SUPERVGUI_Graph* sv = myMain->getGraph();
70 MouseX = sv->childX(this) - e->globalX();
71 MouseY = sv->childY(this) - e->globalY();
75 void SUPERVGUI_GraphNode::mouseTitleMove(QMouseEvent* e) {
76 Trace("SUPERVGUI_Node::moveAgain")
77 SUPERVGUI_Graph* sv = myMain->getGraph();
79 if ((MouseX == MouseNo) && (MouseY == MouseNo)) {
80 MouseX = sv->childX(this) - e->globalX();
81 MouseY = sv->childY(this) - e->globalY();
82 MouseLeft = (e->state() == RightButton? 0: 1);
87 int x = e->globalX()+MouseX;
88 int y = e->globalY()+MouseY;
92 if (x > myMain->getGraph()->horizontalScrollBar()->value()
93 + myMain->getGraph()->viewport()->width() - width()/2
95 y > myMain->getGraph()->verticalScrollBar()->value()
96 + myMain->getGraph()->viewport()->height() - height()/2
98 x < myMain->getGraph()->horizontalScrollBar()->value()
100 y < myMain->getGraph()->verticalScrollBar()->value()){
101 if (!myTimer->isActive()) {
104 myDifX = x - myNode->X();
105 myDifY = y - myNode->Y();
106 myFirstDifX = myDifX;
107 myFirstDifY = myDifY;
113 if (x - myNode->X() > 15 && abs(myDifX) < abs(myDifY)) {
114 if (x > myMain->getGraph()->horizontalScrollBar()->value()
115 + myMain->getGraph()->viewport()->width() - width()/2)
116 myDifX = 5; // or another positive number
118 //not out of the right boundary
119 sv->moveChild(this, x, myNode->Y()); //new X and old Y
120 myNode->Coords(x, myNode->Y());
125 if (x - myNode->X() < -15 && abs(myDifX) < abs(myDifY)) {
126 if(x < myMain->getGraph()->horizontalScrollBar()->value())
127 myDifX = -5; //or another negative number
129 //not out of the left boundary
130 sv->moveChild(this, x, myNode->Y()); //new X and old Y
131 myNode->Coords(x, myNode->Y());
136 if (y - myNode->Y() > 15 && abs(myDifX) > abs(myDifY)) {
137 if (y > myMain->getGraph()->verticalScrollBar()->value()
138 + myMain->getGraph()->viewport()->height() - height()/2)
139 myDifY = 5; //or another positive number
141 //not out of the lower boundary
142 sv->moveChild(this, myNode->X(), y); //old X and new Y
143 myNode->Coords(myNode->X(), y);
148 if (y - myNode->Y() < -15 && abs(myDifX) > abs(myDifY)) {
149 if (y < myMain->getGraph()->verticalScrollBar()->value())
150 myDifY = -5; //or another negative number
152 //not out of the upper boundary
153 sv->moveChild(this, myNode->X(), y); //old X and new Y
154 myNode->Coords(myNode->X(), y);
161 if ((myDifX*(x - myNode->X()) < 0 || myDifY*(y - myNode->Y()) < 0)) {
165 //for mouse moving to boundaries from outside space (chack then node must be move)
166 int xp1, yp1, xp2, yp2;
167 xp1 = myMain->getGraph()->horizontalScrollBar()->value();
168 xp2 = myMain->getGraph()->horizontalScrollBar()->value() +
169 myMain->getGraph()->viewport()->width();
170 yp1 = myMain->getGraph()->verticalScrollBar()->value();
171 yp2 = myMain->getGraph()->verticalScrollBar()->value() +
172 myMain->getGraph()->viewport()->height();
174 && x <= xp1+myMain->getGraph()->viewport()->visibleRect().width()
176 && y <= yp1+myMain->getGraph()->viewport()->visibleRect().height()) {
177 sv->moveChild(this, x, y);
178 myNode->Coords(x, y);
185 void SUPERVGUI_GraphNode::mouseTitleRelease(QMouseEvent* e) {
190 void SUPERVGUI_GraphNode::movingNode() {
191 SUPERVGUI_Graph* sv = myMain->getGraph();
193 myX = myX<0 ? 0: myX;
194 myY = myY<0 ? 0: myY;
205 myMain->getGraph()->ResizeGraph(this, myX, myY);
206 myMain->getGraph()->scrollBy( myX - myNode->X(), myY - myNode->Y() );
207 sv->moveChild(this, myX, myY);
208 myNode->Coords(myX, myY);
211 void SUPERVGUI_GraphNode::StartTimer() {
212 Trace("SUPERVGUI_Main::StartTimer")
213 if (!myTimer->isActive()) {
218 void SUPERVGUI_GraphNode::StopTimer() {
219 Trace("SUPERVGUI_Main::StopTimer")
220 if (myTimer->isActive()) {
225 void SUPERVGUI_GraphNode::deleteLinks() {
226 QObjectList* aList = queryList("SUPERVGUI_Port");
227 SUPERVGUI_Port* aPort;
228 QObjectListIt aIt(*aList);
229 while ((aPort=(SUPERVGUI_Port*)aIt.current()) != 0) {
231 aPort->deleteLinks();
237 void SUPERVGUI_GraphNode::sync() {
238 SUPERVGUI_Node::sync();
241 QObjectList* ihmList = queryList("SUPERVGUI_Port");
242 QObjectListIt i(*ihmList);
243 while ((pi=(SUPERVGUI_Port*)i.current()) != 0) {
252 * Creates presentation of links to In ports
253 * If toCheckExisting = false the links will be created without checking
254 * of their existing in Graph
255 * If toCheckExisting = true the existing of links will be checked before creation
257 void SUPERVGUI_GraphNode::updateLinksPrs(bool toCheckExisting) {
258 SUPERVGUI_Graph* aGraph= myMain->getGraph();
259 SUPERVGUI_PortIn* pi;
260 QObjectList* ihmList = queryList("SUPERVGUI_PortIn");
261 QObjectListIt i(*ihmList);
262 while ((pi=(SUPERVGUI_PortIn*)i.current()) != 0) {
264 if (pi->getPort()->IsLinked()) {
265 SUPERV_Link aLink = pi->getPort()->Link();
266 if (toCheckExisting) {
267 if (aGraph->isLinkPrsExists(aLink))
270 aGraph->createLinkPrs(aLink);
278 void SUPERVGUI_GraphNode::setNodeName(QString theName) {
279 SUPERVGUI_Node::setNodeName(theName);
280 myTitle->setText(name());
284 void SUPERVGUI_GraphNode::deletePort(SUPERVGUI_Port* thePort) {
285 if (thePort->isA("SUPERVGUI_PortIn") || thePort->isA("SUPERVGUI_PortInESNode")) {
291 thePort->deleteLinks();
293 thePort->getPort()->destroy();
294 thePort->close(true);
300 void SUPERVGUI_GraphNode::addInputPort() {
301 SUPERV_Port aPort = createInPort();
302 if (aPort == NULL) return;
304 if (getNodeType() == SUPERV::EndSwitchNode) {
305 SUPERVGUI_PortInESNode* aPortPrs = new SUPERVGUI_PortInESNode(myPortsBox, myMain, aPort);
306 myPortLayout->addWidget(aPortPrs, myPIcount, 0);
308 if (myPortsBox->isVisible()) {
313 SUPERVGUI_PortIn* aPortPrs = new SUPERVGUI_PortIn(myPortsBox, myMain, aPort);
314 myPortLayout->addWidget(aPortPrs, myPIcount, 0);
316 if (myPortsBox->isVisible()) {
327 void SUPERVGUI_GraphNode::addOutputPort() {
328 SUPERV_Port aPort = createOutPort();
329 if (aPort == NULL) return;
331 SUPERVGUI_PortOut* aPortPrs = new SUPERVGUI_PortOut(myPortsBox, myMain, aPort);
332 myPortLayout->addWidget(aPortPrs, myPOcount, 1, Qt::AlignRight);
334 if (myPortsBox->isVisible()) {
342 void SUPERVGUI_GraphNode::updatePorts() {
343 bool isAdded = false;
344 SUPERV_Ports aPorts = getEngine()->Ports();
345 int n = aPorts->length();
346 SUPERVGUI_Port* aPortPrs;
347 bool aIsVisible = myPortsBox->isVisible();
348 for (int i=0; i < n; i++) {
349 QString aName(aPorts[i]->Name());
350 aName += (aPorts[i]->IsInput())? "Input":"Output";
351 aPortPrs = (SUPERVGUI_Port*) child(aName, "SUPERVGUI_Port");
352 if (aPortPrs == NULL) {
353 if (aPorts[i]->IsInput()) {
354 SUPERVGUI_PortIn* aPortIn = new SUPERVGUI_PortIn(myPortsBox, myMain, aPorts[i]);
355 myPortLayout->addWidget(aPortIn, myPIcount, 0);
356 if (aIsVisible) aPortIn->show();
360 SUPERVGUI_PortOut* aPortOut = new SUPERVGUI_PortOut(myPortsBox, myMain, aPorts[i]);
361 myPortLayout->addWidget(aPortOut, myPOcount, 1, Qt::AlignRight);
362 if (aIsVisible) aPortOut->show();
369 QObjectList* aShownPortsList = queryList("SUPERVGUI_Port");
370 QObjectListIt aLI(*aShownPortsList);
371 SUPERVGUI_Port* aVisPort;
373 while ((aVisPort=(SUPERVGUI_Port*)aLI.current()) != 0) {
375 QString aNameVisible(aVisPort->getPort()->Name());
377 bool aIsExists = false;
378 for (int i=0; i < n; i++) {
379 QString aName(aPorts[i]->Name());
380 if (aName == aNameVisible)
384 if (!aIsExists) { //we have a visible object, which has no engine entity
385 aVisPort->close(true);