]> SALOME platform Git repositories - modules/superv.git/commitdiff
Salome HOME
An improvement on link creation: if a link already exists between the ports, then...
authorasv <asv@opencascade.com>
Wed, 22 Dec 2004 11:20:26 +0000 (11:20 +0000)
committerasv <asv@opencascade.com>
Wed, 22 Dec 2004 11:20:26 +0000 (11:20 +0000)
src/SUPERVGUI/SUPERVGUI_CanvasView.cxx

index ea908fc6e25ab16971c417f9e2cd44e657838808..0f78023132104d094f1ba05f84797108a0463922 100644 (file)
@@ -532,6 +532,41 @@ void SUPERVGUI_CanvasView::endSketch(SUPERVGUI_CanvasPort* thePort)
     if (SUPERV_isNull(aLinkEngine)) 
       return;    
 
+    // here, in fact, aLinkEngine may NOT be a newly created link.  If a link already existed between the
+    // the 2 given ports - it will be return (NOT created again).
+    // this should be checked and new presentation should NOT be created for existing link.
+    // Solution 1: NOT to allow creation of a link if it already exists between the ports in 
+    //             myLinkBuilder->canCreateEngine()
+    // Solution 2: check here if aLinkEngine is "new" or "old"
+    // Implement 2nd solution, because canCreateEngine() checks for types of ports, etc.. - it's another thing
+    // THE CHECK:
+    QObjectList* canvasLinks = canvas()->queryList("SUPERVGUI_CanvasLink");
+    SUPERVGUI_CanvasLink* canvasLink = 0;
+    QObjectListIt it(*canvasLinks);
+    bool prsAlreadyExists = false;
+    while ( (canvasLink=(SUPERVGUI_CanvasLink*)it.current()) ) {
+      ++it;
+      SUPERV_Link existingLinkWithPrs = canvasLink->getEngine();
+      if ( !SUPERV_isNull( existingLinkWithPrs ) ) {
+       if ( existingLinkWithPrs->IsEqual( aLinkEngine ) ) {
+         prsAlreadyExists = true;
+         break;
+       }       
+      }
+    }
+    delete canvasLinks;
+    if ( prsAlreadyExists ) { // aLinkEngine is already bound with a SUPERVGUI_CanvasLink object
+      //return;  // -> if return here, than the old CanvasLink is kept
+
+      // we want to delete old and create a new CanvasLink for this Link
+      delete canvasLink;
+      canvasLink = 0;
+      // clear old corrdinates in Engine link
+      for ( int i = 1; i <= aLinkEngine->CoordsSize(); i++ )
+       aLinkEngine->RemoveCoord( i );
+      // now we are ready to set coords for a link and create a new CanvasLink presentation that will use them.
+    }
+
     myLinkBuilder->setCoords(aLinkEngine.in());
 
     delete myLinkBuilder;
@@ -547,8 +582,8 @@ void SUPERVGUI_CanvasView::endSketch(SUPERVGUI_CanvasPort* thePort)
     if ( !aLinkEngine->IsValid() ) { 
       const int id = QAD_MessageBox::warn2( this, tr( "TLT_INVALID_LINK" ), tr( "MSG_INVALID_LINK" ), 
                                           tr( "Keep" ), tr( "Remove" ), 0, 1, 0 );
-      if ( id == 1 ) { // Remove selected
-       aLink->remove(); // it did not live long...
+      if ( id == 1 ) { // "Remove" was selected in Message Box
+       aLink->remove(); // the new link did not live long...
       }
     }
   }