Salome HOME
SALOME PAL V1_4_1
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_GraphNode.cxx
index 283cf0f0de3b098dbb092d88223f977af022767a..af07998b7417e392ba885121a43ec4b789d81660 100644 (file)
@@ -26,8 +26,18 @@ SUPERVGUI_GraphNode::SUPERVGUI_GraphNode(QWidget* theParent, SUPERVGUI_Main* the
   connect(myTitle, SIGNAL(MouseMove (QMouseEvent*)), this, SLOT(mouseTitleMove(QMouseEvent*)));
   connect(myTitle, SIGNAL(MouseRelease(QMouseEvent*)), this, SLOT(mouseTitleRelease(QMouseEvent*)));
 
-  myPortsBox = new QFrame(0);
-  myPortLayout = new QGridLayout(myPortsBox, 0, 2, 0, 1);
+  myPortsBox = new QVBox(0);  
+  myPortsBox->setSpacing(3);
+  myValuesBox = new QWidget(myPortsBox);
+  myPortLayout = new QGridLayout(myValuesBox, 0, 2, 0, 1);
+
+  myGatesBox = new QFrame(myPortsBox);
+  myGatesBox->setFrameStyle( QFrame::Panel | QFrame::Raised );
+  myGatesBox->setLineWidth(2);
+  //  myGatesBox->setPaletteBackgroundColor(backgroundColor().dark(105));
+  myGatesBox->setPaletteBackgroundColor(green.light(170));
+  myGatesLayout = new QGridLayout(myGatesBox, 0, 2);
+  myGatesLayout->setMargin(3);
   
   myTimer = new QTimer(this);
   connect(myTimer, SIGNAL(timeout()), this, SLOT(movingNode(/*QMouseEvent* e*/)));
@@ -44,18 +54,40 @@ SUPERVGUI_GraphNode::SUPERVGUI_GraphNode(QWidget* theParent, SUPERVGUI_Main* the
   myPOcount = 0;
   SUPERV_Ports       ports = myNode->Ports();
   int                n     = ports->length();
-
   for (int i=0; i<n; i++) {
     if (ports[i]->IsInput()) {
-      myPortLayout->addWidget(new SUPERVGUI_PortIn(myPortsBox, myMain, ports[i]), 
-                            myPIcount, 0);
-      myPIcount++;
+      if (getComputingNode()->IsEndSwitch()) {
+       if (ports[i]->IsGate())
+         myGatesLayout->addWidget(new SUPERVGUI_PortInESNode(myGatesBox, myMain, ports[i]), 
+                                 0, 0);
+       else {
+         myPortLayout->addWidget(new SUPERVGUI_PortInESNode(myValuesBox, myMain, ports[i]), 
+                                 myPIcount, 0);
+         myPIcount++;
+       }
+      } else {
+       if (ports[i]->IsGate())
+         myGatesLayout->addWidget(new SUPERVGUI_PortIn(myGatesBox, myMain, ports[i]), 
+                                  0, 0);
+       else {
+         myPortLayout->addWidget(new SUPERVGUI_PortIn(myValuesBox, myMain, ports[i]), 
+                                 myPIcount, 0);
+         myPIcount++;
+       }
+      }
     } else {
-      myPortLayout->addWidget(new SUPERVGUI_PortOut(myPortsBox, myMain, ports[i]), 
-                            myPOcount, 1, Qt::AlignRight);
-      myPOcount++;
+      if (ports[i]->IsGate())
+       myGatesLayout->addWidget(new SUPERVGUI_PortOut(myGatesBox, myMain, ports[i]), 
+                                0, 1, Qt::AlignRight);
+      else {
+       myPortLayout->addWidget(new SUPERVGUI_PortOut(myValuesBox, myMain, ports[i]), 
+                               myPOcount, 1, Qt::AlignRight);
+       myPOcount++;
+      }
     }
   }
+
 }
 
 
@@ -254,7 +286,6 @@ void SUPERVGUI_GraphNode::sync() {
   //check: is creation of link is complete
   if (myMain->getGraph()->isAnyLinkCreating()) {
     //not creation complete
-    //cout<<"   --- $$$  1"<<endl;
     myPopup->setItemEnabled(myDeleteItem, false);
   }
   else {
@@ -271,23 +302,46 @@ void SUPERVGUI_GraphNode::sync() {
  * If toCheckExisting = true the existing of links will be checked before creation
  */
 void SUPERVGUI_GraphNode::updateLinksPrs(bool toCheckExisting) {
+    
   SUPERVGUI_Graph* aGraph= myMain->getGraph();
-  SUPERVGUI_PortIn* pi;
-  QObjectList* ihmList = queryList("SUPERVGUI_PortIn");
-  QObjectListIt i(*ihmList);
-  while ((pi=(SUPERVGUI_PortIn*)i.current()) != 0) {
-    ++i;
-    if (pi->getPort()->IsLinked()) {
-      SUPERV_Link aLink = pi->getPort()->Link();
-      if (toCheckExisting) {
-       if (aGraph->isLinkPrsExists(aLink))
-         continue;
+  //Find PortInESNode
+  SUPERVGUI_PortInESNode* piES;
+  QObjectList* ihmListES = queryList("SUPERVGUI_PortInESNode");
+  QObjectListIt iES(*ihmListES);
+  if (iES.count()) {
+    while ((piES=(SUPERVGUI_PortInESNode*)iES.current()) != 0) {
+      ++iES;
+      if (piES->getPort()->IsLinked()) {
+       SUPERV_Links aLinks = piES->getPort()->Links();
+       for (int j=0; j<aLinks->length(); j++) {
+         if (toCheckExisting) {
+           if (aGraph->isLinkPrsExists(aLinks[j]))
+             continue;
+         }
+         aGraph->createLinkPrs(aLinks[j]);
+       }
       }
-      aGraph->createLinkPrs(aLink);
     }
   }
-  delete ihmList;
+  else {
+    SUPERVGUI_PortIn* pi;
+    QObjectList* ihmList = queryList("SUPERVGUI_PortIn");
+    QObjectListIt i(*ihmList);
+    while ((pi=(SUPERVGUI_PortIn*)i.current()) != 0) {
+      ++i;
+      if (pi->getPort()->IsLinked()) {
+       SUPERV_Link aLink = pi->getPort()->Link();
+       if (toCheckExisting) {
+         if (aGraph->isLinkPrsExists(aLink))
+           continue;
+       }
+       aGraph->createLinkPrs(aLink);
+      }
+    }
+    delete ihmList;
+  }
 
+  delete ihmListES;
 }
 
 
@@ -307,7 +361,9 @@ void SUPERVGUI_GraphNode::deletePort(SUPERVGUI_Port* thePort) {
   thePort->deleteLinks();
   
   thePort->getPort()->destroy();
+
   thePort->close(true);
+
   updatePorts();
   updateShape();
 }
@@ -318,7 +374,7 @@ void SUPERVGUI_GraphNode::addInputPort() {
   if (aPort == NULL) return;
 
   if (getNodeType() == SUPERV::EndSwitchNode) {
-    SUPERVGUI_PortInESNode* aPortPrs = new SUPERVGUI_PortInESNode(myPortsBox, myMain, aPort);    
+    SUPERVGUI_PortInESNode* aPortPrs = new SUPERVGUI_PortInESNode(myValuesBox, myMain, aPort);    
     myPortLayout->addWidget(aPortPrs, myPIcount, 0);
 
     if (myPortsBox->isVisible()) {
@@ -326,7 +382,7 @@ void SUPERVGUI_GraphNode::addInputPort() {
     }
   }
   else {
-    SUPERVGUI_PortIn* aPortPrs = new SUPERVGUI_PortIn(myPortsBox, myMain, aPort);
+    SUPERVGUI_PortIn* aPortPrs = new SUPERVGUI_PortIn(myValuesBox, myMain, aPort);
     myPortLayout->addWidget(aPortPrs, myPIcount, 0);
 
     if (myPortsBox->isVisible()) {
@@ -344,7 +400,7 @@ void SUPERVGUI_GraphNode::addOutputPort() {
   SUPERV_Port aPort = createOutPort();
   if (aPort == NULL) return;
 
-  SUPERVGUI_PortOut* aPortPrs = new SUPERVGUI_PortOut(myPortsBox, myMain, aPort);
+  SUPERVGUI_PortOut* aPortPrs = new SUPERVGUI_PortOut(myValuesBox, myMain, aPort);
   myPortLayout->addWidget(aPortPrs, myPOcount, 1, Qt::AlignRight);
   myPOcount++;
   if (myPortsBox->isVisible()) {
@@ -367,16 +423,28 @@ void SUPERVGUI_GraphNode::updatePorts() {
     aPortPrs = (SUPERVGUI_Port*) child(aName, "SUPERVGUI_Port");
     if (aPortPrs == NULL) {
       if (aPorts[i]->IsInput()) {
-       SUPERVGUI_PortIn* aPortIn = new SUPERVGUI_PortIn(myPortsBox, myMain, aPorts[i]);
-       myPortLayout->addWidget(aPortIn, myPIcount, 0);
+       SUPERVGUI_PortIn* aPortIn;
+       if (aPorts[i]->IsGate()) {
+         aPortIn = new SUPERVGUI_PortIn(myGatesBox, myMain, aPorts[i]);
+         myGatesLayout->addWidget(aPortIn, myPIcount, 0);
+       } else {
+         aPortIn = new SUPERVGUI_PortIn(myValuesBox, myMain, aPorts[i]);
+         myPortLayout->addWidget(aPortIn, myPIcount, 0);
+         myPIcount++;
+       }
        if (aIsVisible) aPortIn->show();
-       myPIcount++;
        isAdded = true;
       } else {
-       SUPERVGUI_PortOut* aPortOut = new SUPERVGUI_PortOut(myPortsBox, myMain, aPorts[i]);
-       myPortLayout->addWidget(aPortOut, myPOcount, 1, Qt::AlignRight);
+       SUPERVGUI_PortOut* aPortOut;
+       if (aPorts[i]->IsGate()) {
+         aPortOut = new SUPERVGUI_PortOut(myGatesBox, myMain, aPorts[i]);
+         myGatesLayout->addWidget(aPortOut, myPOcount, 1, Qt::AlignRight);
+       } else {
+         aPortOut = new SUPERVGUI_PortOut(myValuesBox, myMain, aPorts[i]);
+         myPortLayout->addWidget(aPortOut, myPOcount, 1, Qt::AlignRight);
+         myPOcount++;
+       }
        if (aIsVisible) aPortOut->show();
-       myPOcount++;
        isAdded = true;
       }
     }
@@ -386,6 +454,7 @@ void SUPERVGUI_GraphNode::updatePorts() {
   QObjectListIt aLI(*aShownPortsList);
   SUPERVGUI_Port* aVisPort;
 
+
   while ((aVisPort=(SUPERVGUI_Port*)aLI.current()) != 0) {  
     ++aLI;
     QString aNameVisible(aVisPort->getPort()->Name());
@@ -402,3 +471,16 @@ void SUPERVGUI_GraphNode::updatePorts() {
     }
   }
 }
+
+
+/**
+ * Returns coordinates of connection point in content coordinates
+ */
+QPoint SUPERVGUI_GraphNode::getInConnectPnt() {
+  return QPoint(pos().x(), 
+               pos().y() + (height()/2));
+}
+QPoint SUPERVGUI_GraphNode::getOutConnectPnt() {
+  return QPoint(pos().x() + width(),
+               pos().y() + (height()/2));
+}