// Author : Alexander SLADKOV
// Module : SUPERV
-using namespace std;
-
#include "SUIT_Desktop.h"
#include "SUIT_Session.h"
#include "SUPERVGUI_CanvasNode.h"
#include "SUPERVGUI_CanvasPort.h"
#include "SUPERVGUI_CanvasControlNode.h"
-#include "SUPERVGUI.h"
+#include "SUPERVGUI_CanvasLink.h"
#include <qlayout.h>
#include <qlabel.h>
SUPERVGUI_ManagePortsDlg::~SUPERVGUI_ManagePortsDlg() {
}
+// mkr : PAL8060
+void SUPERVGUI_ManagePortsDlg::createLinkEngine( SUPERV::Port_ptr thePort,
+ QValueList< QPair< QString,QString > >& theOwnList,
+ QValueList< QPair< QString,QString > >& theCorrespList ) {
+ // pair <NodeName, PortName> for the given port
+ QPair<QString, QString> anOwnPair(QString(thePort->Node()->Name()), QString(thePort->Name()));
+ int aNum = theOwnList.contains(anOwnPair);
+ while ( aNum > 0 ) {
+ int anId = theOwnList.findIndex(anOwnPair); // get index in theOwnList
+ QPair<QString, QString> aCorrespPair = theCorrespList[anId]; // corresponding pair in theCorrespList
+
+ theOwnList.remove(theOwnList.at(anId));
+ theCorrespList.remove(theCorrespList.at(anId));
+
+ SUPERV_Port aCorrespPort = myNode->getMain()->getDataflow()->Node(aCorrespPair.first)->Port(aCorrespPair.second);
+ SUPERV_Link aLinkEngine;
+ if ( thePort->IsInput() )
+ aLinkEngine = myNode->getMain()->getDataflow()->Link(aCorrespPort, thePort);
+ else
+ aLinkEngine = myNode->getMain()->getDataflow()->Link(thePort, aCorrespPort);
+ SUPERVGUI_CanvasLink* aLink = new SUPERVGUI_CanvasLink(myNode->getMain()->getCanvas(), myNode->getMain(), aLinkEngine);
+ aLink->show();
+
+ aNum--;
+ }
+}
+
/**
* Set the ports as entered by user (order, name/type, etc.) and close the dialog
*/
// automatically removes the corresponding Output Port. So for Loops the
// oldPorts list should be filtered to include only Input Ports.
// But I'll filter Gate-s as well..
+ bool isAnyLinked = false; // check if any port from old ports is linked
+ // map PortName <-> (PortType, PortInputValue) for non linked input ports, which have input
+ QMap< QString, QPair< QString,QString > > InNameInput;
QObjectList portsToRemove;
while ( (obj = it.current()) != 0 ) {
++it;
SUPERV::Port_var aPort = ((SUPERVGUI_CanvasPort*)obj)->getEngine();
- if ( !aPort->IsGate() && ( !isLoop || aPort->IsInput() ) )
+ if ( !aPort->IsGate() && ( !isLoop || aPort->IsInput() ) ) {
portsToRemove.append( obj );
+ }
+ // check if port has a link (output porst of Loop node are also checked)
+ if ( !aPort->IsGate() && aPort->IsLinked() && !isAnyLinked)
+ isAnyLinked = true;
+ // check if input port has an input value
+ if ( !aPort->IsGate() && aPort->IsInput() && aPort->HasInput() )
+ InNameInput.insert( QString(aPort->Name()),
+ QPair<QString, QString>(QString(aPort->Type()),QString(aPort->ToString())) );
}
delete oldPorts; // delete the list, not the objects
+
+ // mkr : PAL8060 -->
+ QString aNodeName = myNode->getEngine()->Name();
+ QValueList< QPair< QString,QString > > InPortsL, OutPortsL;
+ if ( isAnyLinked ) {
+ // if myNode has linked port(s), create two lists of In/Out ports (InPortsL, OutPortsL) to identify all links for myNode
+ QObjectList* list = myNode->getMain()->getCanvas()->queryList("SUPERVGUI_CanvasLink");
+ QObjectListIt listit( *list );
+ QObject *listobj;
+ while ( (listobj = listit.current()) != 0 ) {
+ ++listit;
+ SUPERV::Link_var aLink = ((SUPERVGUI_CanvasLink*)listobj)->getEngine();
+ if ( aNodeName.compare(aLink->InPort()->Node()->Name()) == 0
+ ||
+ aNodeName.compare(aLink->OutPort()->Node()->Name()) == 0 ) {
+ QPair<QString, QString> InPair(QString(aLink->InPort()->Node()->Name()), QString(aLink->InPort()->Name()));
+ QPair<QString, QString> OutPair(QString(aLink->OutPort()->Node()->Name()), QString(aLink->OutPort()->Name()));
+ InPortsL.append(InPair);
+ OutPortsL.append(OutPair);
+ }
+
+ if ( isLoop ) {
+ // put into In/Out lists all links for corresponding EndLoop node
+ QString aCoupledNodeName = ((SUPERVGUI_CanvasStartNode*)myNode)->getCoupled()->getEngine()->Name();
+ if ( aCoupledNodeName.compare(aLink->InPort()->Node()->Name()) == 0
+ ||
+ aCoupledNodeName.compare(aLink->OutPort()->Node()->Name()) == 0 ) {
+ QPair<QString, QString> InPair(QString(aLink->InPort()->Node()->Name()), QString(aLink->InPort()->Name()));
+ QPair<QString, QString> OutPair(QString(aLink->OutPort()->Node()->Name()), QString(aLink->OutPort()->Name()));
+ InPortsL.append(InPair);
+ OutPortsL.append(OutPair);
+ }
+ }
+ }
+ }
+ // mkr : PAL8060 <--
// portsToRemove list contains:
// for Loop node: all INPUT ports except Gates
for ( i = 0; i < myInList->count(); i++ ) {
item = (PortListItem*)myInList->item( i );
aPort = aINode->InPort( item->PortName.latin1(), item->PortType.latin1() );
- myNode->createPort( aPort.in() );
+ if ( InNameInput.contains( item->PortName )
+ &&
+ item->PortType.compare(InNameInput[item->PortName].first) == 0 ) {
+ // i.e. aPort is input and had a value (not linked!)
+ // if ports' name and type didn't change and ports had an input value => set this value again
+ SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+ if ( aSupMod )
+ aPort->Input( aSupMod->getEngine()->StringValue( InNameInput[item->PortName].second ) );
+ myNode->createPort( aPort.in() );
+ }
+ else {
+ myNode->createPort( aPort.in() );
+ // mkr : PAL8060
+ if ( !InPortsL.isEmpty() && !OutPortsL.isEmpty() )
+ // create links for those input ports, which had links earlier
+ createLinkEngine( aPort, InPortsL, OutPortsL );
+ }
+ }
+
+ if ( isLoop ) {
// asv : 11.01.05 : for Loop nodes do the same as in SUPERVGUI_CanvasStartNode::addInputPort()
- if ( isLoop ) {
- SUPERVGUI_CanvasStartNode* aStartLoopNode = (SUPERVGUI_CanvasStartNode*)myNode;
- aStartLoopNode->merge();
- aStartLoopNode->getCoupled()->merge();
+ SUPERVGUI_CanvasStartNode* aStartLoopNode = (SUPERVGUI_CanvasStartNode*)myNode;
+ aStartLoopNode->merge();
+ aStartLoopNode->getCoupled()->merge();
+
+ // mkr : PAL8060 -->
+ if ( !InPortsL.isEmpty() && !OutPortsL.isEmpty() ) {
+
+ // 1) create old links for output ports of Loop node
+ QObjectList* aPortsOut = aStartLoopNode->queryList("SUPERVGUI_CanvasPortOut");
+ QObjectListIt aPorstOutit( *aPortsOut );
+ QObject *listobj;
+ while ( (listobj = aPorstOutit.current()) != 0 ) {
+ ++aPorstOutit;
+
+ SUPERV::Port_var aPortOut = ((SUPERVGUI_CanvasPort*)listobj)->getEngine();
+ createLinkEngine( aPortOut, OutPortsL, InPortsL );
+ }
+
+ // 2) create old links for input ports of EndLoop node
+ QObjectList* aPortsIn = aStartLoopNode->getCoupled()->queryList("SUPERVGUI_CanvasPortIn");
+ QObjectListIt aPorstInit( *aPortsIn );
+ while ( (listobj = aPorstInit.current()) != 0 ) {
+ ++aPorstInit;
+
+ SUPERV::Port_var aPortIn = ((SUPERVGUI_CanvasPort*)listobj)->getEngine();
+ createLinkEngine( aPortIn, InPortsL, OutPortsL );
+ }
+
+ // 3) create old links for output ports of EndLoop node
+ aPortsOut = aStartLoopNode->getCoupled()->queryList("SUPERVGUI_CanvasPortOut");
+ aPorstOutit = QObjectListIt( *aPortsOut );
+ while ( (listobj = aPorstOutit.current()) != 0 ) {
+ ++aPorstOutit;
+
+ SUPERV::Port_var aPortOut = ((SUPERVGUI_CanvasPort*)listobj)->getEngine();
+ createLinkEngine( aPortOut, OutPortsL, InPortsL );
+ }
}
+ // mkr : PAL8060 <--
}
+
// creating Out-ports, except LoopNode-s
for ( i = 0; i < myOutList->count() && !isLoop; i++ ) {
item = (PortListItem*)myOutList->item( i );
aPort = aINode->OutPort( item->PortName.latin1(), item->PortType.latin1() );
myNode->createPort( aPort.in() );
+
+ // mkr : PAL8060
+ if ( !InPortsL.isEmpty() && !OutPortsL.isEmpty() )
+ // create links for those output ports, which had links earlier
+ createLinkEngine( aPort, OutPortsL, InPortsL );
}
// 2. update the node's presentation
// 1. fill myTypeCombo with all available types
myTypeCombo->insertStrList( gTypes );
-
+
// 2. fill Input and Output listboxes with Ports' names/types
QStringList aTypes;
SUPERV_Ports aPorts = aINode->Ports();
for ( int i=0; i < aPorts->length(); i++ ) {
if ( aPorts[i]->IsGate() )
continue;
- if ( aPorts[i]->IsInput() )
+ if ( aPorts[i]->IsInput()
+ &&
+ !myInList->findItem( QString( "%1 (%2)" ).arg( aPorts[i]->Name() ).arg( aPorts[i]->Type() ) ) ) // mkr : PAL11332
new PortListItem( myInList, aPorts[i]->Name(), aPorts[i]->Type() );
- else
+ if ( !aPorts[i]->IsInput()
+ &&
+ !myOutList->findItem( QString( "%1 (%2)" ).arg( aPorts[i]->Name() ).arg( aPorts[i]->Type() ) ) ) // mkr : PAL11332
new PortListItem( myOutList, aPorts[i]->Name(), aPorts[i]->Type() );
}
}