From cbe11b4dcd4c3259c11c28f9ab853cb5ddff8b55 Mon Sep 17 00:00:00 2001 From: asv Date: Wed, 22 Dec 2004 11:20:26 +0000 Subject: [PATCH] An improvement on link creation: if a link already exists between the ports, then on new link creation it is removed, and new link is created. If link already exists - is important check for Input Gate ports, which can accept many incoming links. --- src/SUPERVGUI/SUPERVGUI_CanvasView.cxx | 39 ++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/SUPERVGUI/SUPERVGUI_CanvasView.cxx b/src/SUPERVGUI/SUPERVGUI_CanvasView.cxx index ea908fc..0f78023 100644 --- a/src/SUPERVGUI/SUPERVGUI_CanvasView.cxx +++ b/src/SUPERVGUI/SUPERVGUI_CanvasView.cxx @@ -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... } } } -- 2.39.2