Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasLink.cxx
index 4ed27d15d741bcbf2d62166426ce14cf7768a114..3c957e645eca7c9ef4ed595fd7cfd22230cb0ca1 100644 (file)
@@ -1,12 +1,28 @@
 //  SUPERV SUPERVGUI : GUI for Supervisor component
 //
-//  Copyright (C) 2003  OPEN CASCADE
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //  File   : SUPERVGUI_GanvasNodePrs.cxx
 //  Author : Natalia KOPNOVA
 //  Module : SUPERV
 
-using namespace std;
 #include "SUPERVGUI_CanvasLink.h"
 #include "SUPERVGUI_Canvas.h"
 #include "SUPERVGUI_CanvasPort.h"
@@ -52,6 +68,9 @@ SUPERVGUI_CanvasLink::SUPERVGUI_CanvasLink(QObject* theParent, SUPERVGUI_Main* t
     else
       myColor = DRAW_COLOR;
   }
+
+  // mkr : PAL8237
+  connect(this, SIGNAL(objectCreatedDeleted()), myMain, SLOT(onObjectCreatedDeleted()));
 }
 
 SUPERVGUI_CanvasLink::~SUPERVGUI_CanvasLink()
@@ -71,8 +90,8 @@ void SUPERVGUI_CanvasLink::createPrs()
       addPoint(myInputPort->getConnectionPoint());
     }
     if (!myMain->getCanvas()->isControlView()) {
-      long x, y;
-      for (int i = 0; i < myLink->CoordsSize(); i++) {
+      CORBA::Long x, y;
+      for (CORBA::Long i = 0; i < myLink->CoordsSize(); i++) {
        myLink->Coords(i+1, x, y);
        addPoint(QPoint(x, y), i+1);
       }
@@ -214,6 +233,12 @@ void SUPERVGUI_CanvasLink::setColor(const QColor& theColor)
 }
 
 void SUPERVGUI_CanvasLink::remove() {
+  // IPAL9369 : check the dataflow readiness to modify
+  if ( !myMain->ReadyToModify() ) // null dataflow or executing, ..
+    return;
+
+  myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
+
   QString aValue;
   SUPERVGUI_CanvasPortIn* aPort = 0;
   SUPERVGUI_Canvas* aCanvas = myMain->getCanvas();
@@ -225,7 +250,10 @@ void SUPERVGUI_CanvasLink::remove() {
       }
     }
     myLink->destroy();
+
+    emit objectCreatedDeleted(); // mkr : PAL8237
   }
+
   delete this;
   if (aPort && !aValue.isEmpty() && myMain->getDataflow()->GraphLevel() == 0) {
     aPort->setValue(aValue);
@@ -248,8 +276,10 @@ void SUPERVGUI_CanvasLink::addPoint() {
       anIndex = aPoint->getIndex()+1;
       if (anIndex < 1) anIndex = 1;
     }
-    if (myLink && !SUPERV_isNull(myLink)) 
+    if (myLink && !SUPERV_isNull(myLink)) {
       myLink->AddCoord(anIndex, mySelectedPoint.x(), mySelectedPoint.y());
+      emit objectCreatedDeleted(); // mkr : PAL8237
+    }
     merge();
     myMain->getCanvas()->update();
   }
@@ -258,13 +288,25 @@ void SUPERVGUI_CanvasLink::addPoint() {
 void SUPERVGUI_CanvasLink::removePoint() {
   if (mySelectedItem && mySelectedItem->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
     SUPERVGUI_CanvasPointPrs* aPoint = (SUPERVGUI_CanvasPointPrs*) mySelectedItem;
-    if (myLink && !SUPERV_isNull(myLink)) 
+    if (myLink && !SUPERV_isNull(myLink)) {
       myLink->RemoveCoord(aPoint->getIndex());
+      emit objectCreatedDeleted(); // mkr : PAL8237
+    }
     merge();
     myMain->getCanvas()->update();
   }
 }
 
+QString SUPERVGUI_CanvasLink::getToolTipText() const {
+  QString aTTT;
+  if (myInputPort && myOutputPort)
+    aTTT = myOutputPort->getEngine()->Node()->Name() + QString(" : ") + 
+      myOutputPort->getEngine()->Name() + QString(" => ") +
+      myInputPort->getEngine()->Node()->Name() + QString(" : ") + 
+      myInputPort->getEngine()->Name();
+  return aTTT;
+}
+
 /*
 //===============================================================================
 //  SUPERVGUI_CanvasStreamLink: new link to be created
@@ -324,7 +366,6 @@ SUPERVGUI_CanvasLinkBuilder::~SUPERVGUI_CanvasLinkBuilder()
 
 bool SUPERVGUI_CanvasLinkBuilder::canCreateEngine(SUPERVGUI_CanvasPort* thePort)
 {
-  bool result = false;
   if (thePort && myPort) {
     SUPERVGUI_CanvasPort* aInPort;
     SUPERVGUI_CanvasPort* aOutPort;
@@ -343,17 +384,10 @@ bool SUPERVGUI_CanvasLinkBuilder::canCreateEngine(SUPERVGUI_CanvasPort* thePort)
       aInPort = thePort;
     }
 
-    // control if node is different
+    // control if nodes are different, not the same node
     QString aInNode(aInPort->getEngine()->Node()->Name());
     QString aOutNode(aOutPort->getEngine()->Node()->Name());
-    if (aInNode.compare(aOutNode) == 0) 
-      return false;
-
-    // control if no port is "Default"
-    QString aInName(aInPort->getEngine()->Name());
-    QString aOutName(aOutPort->getEngine()->Name());
-    if (aInName.compare("Default") == 0 ||
-       aOutName.compare("Default") == 0)
+    if (aInNode.compare(aOutNode) == 0) // linking outport and inport of the same node
       return false;
 
     // control types of ports
@@ -365,23 +399,31 @@ bool SUPERVGUI_CanvasLinkBuilder::canCreateEngine(SUPERVGUI_CanvasPort* thePort)
        (aOutKind == SUPERV::DataStreamParameter && aInKind != SUPERV::DataStreamParameter))
       return false;
 
-    // connect gate port with gate or inline port
-    if (aInKind == SUPERV::GateParameter || aOutKind == SUPERV::GateParameter) {
-      if (aInKind != aOutKind && 
-         aInKind != SUPERV::InLineParameter && 
-         aOutKind != SUPERV::InLineParameter)
-       return false;
-    }
+    // asv : 15.12.04 : NOT allow to connect Gate-to-InLine --> it does not make sence!
+    // Out Gate port can be connected only to In Gate port 
+    // mkr : NPAL14823 : Out Gate port can be connected to Inline port too
+    if ( aOutKind == SUPERV::GateParameter && aInKind != SUPERV::GateParameter && aInKind != SUPERV::InLineParameter )
+      return false;
 
-    // control if port is already linked except for input port of end switch node
-    if (!(aInKind == SUPERV::EndSwitchParameter || 
-         aInPort->getEngine()->Node()->Kind() == SUPERV::EndSwitchNode)) {
-      if (aInPort->getEngine()->IsLinked())
+    // In Gate can be connected to (receive links from) Gate port and InLine ports (important for Switch nodes)
+    if ( aInKind == SUPERV::GateParameter && aOutKind != SUPERV::GateParameter && aOutKind != SUPERV::InLineParameter )
        return false;
-    }
-    result = true;
+
+    // asv : 15.12.04 : PAL7374, p.2.2 "Bugs and Improvements": multiple links into Gate port 
+    //                  for InGate it's OK to accept more than 1 link
+    // THESE NEEDS REVISION, ALSO DON'T ALLOW MANY LINKS TO "DEFAULT" PORT OF EndSwitch
+    //if ( aInPort->getEngine()->IsLinked() && aInKind != SUPERV::GateParameter ) 
+    
+    // control if port is already linked except for input inline ports of end switch node (check for EndSwitchParameter)
+    // and "Default" port of Switch node (check for aNode->isEndSwitch()).  "Default" port is linked by default, but we
+    // let it to be "re-linked" to another port. 
+    const bool isEndSwitch = ( aInKind == SUPERV::EndSwitchParameter || aInPort->getEngine()->Node()->IsEndSwitch() );
+    if ( !isEndSwitch && aInPort->getEngine()->IsLinked() ) 
+      return false;
+    
+    return true;
   }
-  return result;
+  return false;
 }
 
 void SUPERVGUI_CanvasLinkBuilder::setCoords(SUPERV::Link_ptr theLink)
@@ -508,20 +550,26 @@ int SUPERVGUI_CanvasPointPrs::rtti() const
 void SUPERVGUI_CanvasPointPrs::setInEdge(SUPERVGUI_CanvasEdgePrs* theEdge)
 {
   myInEdge = theEdge;
-  theEdge->setFromPoint((int)x(), (int)y());
+  theEdge->setFromPoint(this);
 }
 
 void SUPERVGUI_CanvasPointPrs::setOutEdge(SUPERVGUI_CanvasEdgePrs* theEdge)
 {
   myOutEdge = theEdge;
-  theEdge->setToPoint((int)x(), (int)y());
+  theEdge->setToPoint(this); 
 }
 
 void SUPERVGUI_CanvasPointPrs::moveBy(double dx, double dy)
 {
   QCanvasEllipse::moveBy(dx, dy);
-  if (myInEdge) myInEdge->setFromPoint((int)x(), (int)y());
-  if (myOutEdge) myOutEdge->setToPoint((int)x(), (int)y());
+  if (myInEdge) myInEdge->setFromPoint(this);
+  if (myOutEdge) myOutEdge->setToPoint(this);
+  //resize canvas view if mouse is outside
+  int w = (int)(x()+dx) + width() + GRAPH_MARGIN;
+  int h = (int)(y()+dy) + height() + GRAPH_MARGIN;
+  if (canvas()->width() > w) w = canvas()->width();
+  if (canvas()->height() > h) h = canvas()->height();
+  if (canvas()->width() < w || canvas()->height() < h) canvas()->resize(w, h);
   if (myIndex > 0 && isMoving()) {
     myLink->getEngine()->ChangeCoord(myIndex, (int)x(), (int)y());
   }
@@ -548,17 +596,32 @@ int SUPERVGUI_CanvasEdgePrs::rtti() const
   return SUPERVGUI_Canvas::Rtti_LinkEdge;
 }
 
-void SUPERVGUI_CanvasEdgePrs::setFromPoint(int x, int y)
+void SUPERVGUI_CanvasEdgePrs::setFromPoint(SUPERVGUI_CanvasPointPrs* thePoint)
 {
-  setPoints(x, y, endPoint().x(), endPoint().y());
+  myStartPoint = thePoint;
+  setPoints((int)(thePoint->x()), (int)(thePoint->y()), endPoint().x(), endPoint().y());
 }
 
-void SUPERVGUI_CanvasEdgePrs::setToPoint(int x, int y)
+void SUPERVGUI_CanvasEdgePrs::setToPoint(SUPERVGUI_CanvasPointPrs* thePoint)
 {
-  setPoints(startPoint().x(), startPoint().y(), x, y);
+  myEndPoint = thePoint;
+  setPoints(startPoint().x(), startPoint().y(), (int)(thePoint->x()), (int)(thePoint->y()));
 }
 
 void SUPERVGUI_CanvasEdgePrs::setColor(const QColor& theColor)
 {
   setPen(QPen(theColor, LINE_WIDTH));
 }
+
+void SUPERVGUI_CanvasEdgePrs::moveBy(double dx, double dy)
+{
+  //mkr: for moving segment of link
+  if (myStartPoint && myEndPoint) {
+    myStartPoint->setMoving(true);
+    myStartPoint->moveBy(dx, dy);
+    
+    myEndPoint->setMoving(true);
+    myEndPoint->moveBy(dx,dy);
+  }
+}
+