#include "SUPERVGUI_ManagePortsDlg.h"
#include "SUPERVGUI_CanvasNode.h"
+#include "SUPERVGUI_CanvasNodePrs.h"
#include "SUPERVGUI_CanvasPort.h"
#include "SUPERVGUI_CanvasControlNode.h"
#include "SUPERVGUI_CanvasLink.h"
}
// mkr : PAL8060
-void SUPERVGUI_ManagePortsDlg::createLinkEngine( SUPERV::Port_ptr thePort,
- QValueList< QPair< QString,QString > >& theOwnList,
- QValueList< QPair< QString,QString > >& theCorrespList ) {
+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);
theOwnList.remove(theOwnList.at(anId));
theCorrespList.remove(theCorrespList.at(anId));
- SUPERV_Port aCorrespPort = myNode->getMain()->getDataflow()->Node(aCorrespPair.first)->Port(aCorrespPair.second);
+ 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);
+ 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
*/
-void SUPERVGUI_ManagePortsDlg::accept() {
+void SUPERVGUI_ManagePortsDlg::accept()
+{
myNode->getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
+
// 1. set the ports to Engine's CNode
SUPERV_INode aINode = myNode->getInlineNode();
if ( !SUPERV_isNull( aINode ) ) {
int i;
const bool isLoop = ( myNode->getNodeType() == SUPERV::LoopNode );
- // 1.1 delete all ports (delete CanvasPorts, they delete SUPERV_Ports)
+ // 1.1 form a list of ports to be removed
QObjectList* oldPorts = myNode->queryList("SUPERVGUI_CanvasPort");
- QObjectListIt it( *oldPorts ); // iterate over the old ports
- QObject *obj;
// asv : 11.01.05 : fix for a bug: for Loop node, removal of an Input Port
- // automatically removes the corresponding Output Port. So for Loops the
+ // 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;
+ QObject *obj;
+ QObjectListIt it ( *oldPorts ); // iterate over the old ports
+ for (; (obj = it.current()) != 0; ++it) {
SUPERV::Port_var aPort = ((SUPERVGUI_CanvasPort*)obj)->getEngine();
- if ( !aPort->IsGate() && ( !isLoop || aPort->IsInput() ) ) {
- portsToRemove.append( obj );
+ if ( !aPort->IsGate() ) {
+ if ( !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 other Inline: all INPUT and OUTPUT ports except Gates
- it = QObjectListIt( portsToRemove );
- while ( (obj = it.current()) != 0 ) {
- ++it;
- ((SUPERVGUI_CanvasPort*)obj)->remove();
- }
-
// 1.2 create new ports in INode and CanvasPort in myNode
+ // or just reorder existing ports
PortListItem* item;
- SUPERV_Port aPort;
- for ( i = 0; i < myInList->count(); i++ ) {
+ for (i = 0; i < myInList->count(); i++) {
item = (PortListItem*)myInList->item( i );
- aPort = aINode->InPort( item->PortName.latin1(), item->PortType.latin1() );
- 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() );
+ // try existing ports
+ bool isExisting = false;
+ QObjectListIt itRem (portsToRemove);
+ QObject *objRem;
+ for (; (objRem = itRem.current()) != 0 && !isExisting; ++itRem) {
+ SUPERV::Port_var aPort = ((SUPERVGUI_CanvasPort*)objRem)->getEngine();
+ if (item->PortName.compare(aPort->Name()) == 0 &&
+ item->PortType.compare(aPort->Type()) == 0) {
+ // ports reordering
+ myNode->removeChild(objRem);
+ myNode->insertChild(objRem);
+ portsToRemove.remove(objRem);
+ isExisting = true;
+ }
}
- 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 (!isExisting) {
+ // create a new port
+ SUPERV::Port_var aPort = aINode->InPort( item->PortName.latin1(), item->PortType.latin1() );
+ myNode->createPort( aPort.in() );
}
}
-
- if ( isLoop ) {
+
+ // 1.3 create/reorder Out-ports
+ if (isLoop) {
// asv : 11.01.05 : for Loop nodes do the same as in SUPERVGUI_CanvasStartNode::addInputPort()
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 );
- }
+ }
+ else {
+ // for non-loop nodes manage out-ports in the same way as in-ports
+ for (i = 0; i < myOutList->count(); i++) {
+ item = (PortListItem*)myOutList->item( i );
+ // try existing ports
+ bool isExisting = false;
+ QObjectListIt itRem (portsToRemove);
+ QObject *objRem;
+ for (; (objRem = itRem.current()) != 0 && !isExisting; ++itRem) {
+ SUPERV::Port_var aPort = ((SUPERVGUI_CanvasPort*)objRem)->getEngine();
+ if (item->PortName.compare(aPort->Name()) == 0 &&
+ item->PortType.compare(aPort->Type()) == 0) {
+ // ports reordering
+ myNode->removeChild(objRem);
+ myNode->insertChild(objRem);
+ portsToRemove.remove(objRem);
+ isExisting = true;
+ }
+ }
+ if (!isExisting) {
+ // create a new port
+ SUPERV::Port_var aPort = aINode->OutPort(item->PortName.latin1(), item->PortType.latin1());
+ myNode->createPort(aPort.in());
+ }
}
- // 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 );
- }
+ // 1.4 remove disappeared ports
+ QObjectListIt itRem ( portsToRemove );
+ QObject *objRem;
+ for (; (objRem = itRem.current()) != 0; ++itRem) {
+ ((SUPERVGUI_CanvasPort*)objRem)->remove();
+ }
// 2. update the node's presentation
+ myNode->getPrs()->updatePorts();
myNode->getMain()->getCanvas()->update();
}
-
+
// 3. close the dialog
myNode->getMain()->lockedGraph( false );
QDialog::accept();
- close();
}
/**
if ( aPorts[i]->IsGate() )
continue;
if ( aPorts[i]->IsInput()
- &&
- !myInList->findItem( QString( "%1 (%2)" ).arg( aPorts[i]->Name() ).arg( aPorts[i]->Type() ) ) ) // mkr : PAL11332
+ &&
+ !myInList->findItem( QString( "%1 (%2)" ).arg( aPorts[i]->Name() ).arg( aPorts[i]->Type() ) ) ) // mkr : PAL11332
new PortListItem( myInList, aPorts[i]->Name(), aPorts[i]->Type() );
if ( !aPorts[i]->IsInput()
- &&
- !myOutList->findItem( QString( "%1 (%2)" ).arg( aPorts[i]->Name() ).arg( aPorts[i]->Type() ) ) ) // mkr : PAL11332
+ &&
+ !myOutList->findItem( QString( "%1 (%2)" ).arg( aPorts[i]->Name() ).arg( aPorts[i]->Type() ) ) ) // mkr : PAL11332
new PortListItem( myOutList, aPorts[i]->Name(), aPorts[i]->Type() );
}
}
bool found = false; // check if already exists -- and don't allow if yes
for ( int i = 0; i < theLB->count(); i++ ) {
if ( ((PortListItem*)theLB->item(i))->PortName == name ) {
- found = true;
- break;
+ found = true;
+ break;
}
}
if ( found )
void SUPERVGUI_PortParamsDlg::clickOnOk()
{
if (getName().isEmpty() || getType().isEmpty())
- QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr( "ERROR" ), tr( "MSG_CANT_CREATE_PORT" ) );
+ QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(),
+ tr("ERROR"), tr("MSG_CANT_CREATE_PORT"));
else if (myPortsNames.contains(getName()))
QMessageBox::warning( this, tr("ERROR"), tr("MSG_PORT_EXIST") ); // mkr : IPAL10386
- else
+ else {
accept();
+ close();
+ }
}