Salome HOME
Minor changes in various source files to remove compilation warnings (unused variable...
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_ManagePortsDlg.cxx
index e887e1fd06272302e479cdbd71b2a9f069acd844..eb8d83cb92dc6097ec88479cfdf19656833ee0ae 100644 (file)
@@ -13,6 +13,7 @@ using namespace std;
 #include "SUPERVGUI_ManagePortsDlg.h"
 #include "SUPERVGUI_CanvasNode.h"
 #include "SUPERVGUI_CanvasPort.h"
+#include "SUPERVGUI_CanvasControlNode.h"
 #include "SUPERVGUI.h"
 
 #include <qlayout.h>
@@ -130,7 +131,6 @@ SUPERVGUI_ManagePortsDlg::SUPERVGUI_ManagePortsDlg( SUPERVGUI_CanvasNode* theNod
 {
   myNode = theNode;
   myLastItem = 0;
-  myFromItemChanged = false;
   init();
 }
 
@@ -273,6 +273,16 @@ void SUPERVGUI_ManagePortsDlg::init()
   connect( myTypeCombo, SIGNAL(activated(const QString&)), this, SLOT(typeChanged(const QString&)));
 
   myNode->getMain()->lockedGraph( true );
+
+  // asv : 11.01.05 : if a node is a loop node, then only INPUT ports can be added/removed
+  if ( myNode->getNodeType() == SUPERV::LoopNode ) {
+    myOutList->setEnabled( false );
+    anAddOutputBtn->setEnabled( false );
+    aDeleteOutputBtn->setEnabled( false );
+    anUpOutputBtn->setEnabled( false );
+    aDownOutputBtn->setEnabled( false );
+  }
+    
 }
 
 /**
@@ -289,18 +299,34 @@ void SUPERVGUI_ManagePortsDlg::accept() {
   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) 
     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
+    // oldPorts list should be filtered to include only Input Ports.
+    // But I'll filter Gate-s as well..
+    QObjectList portsToRemove;
     while ( (obj = it.current()) != 0 ) {
       ++it;
-      if ( !((SUPERVGUI_CanvasPort*)obj)->getEngine()->IsGate() ) // never do anything with Gate ports
-       ((SUPERVGUI_CanvasPort*)obj)->remove();
+      SUPERV::Port_var aPort = ((SUPERVGUI_CanvasPort*)obj)->getEngine();
+      if ( !aPort->IsGate() && ( !isLoop || aPort->IsInput() ) )
+       portsToRemove.append( obj );
     }
     delete oldPorts; // delete the list, not the objects
+    
+    // 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
     PortListItem* item;
@@ -309,8 +335,15 @@ void SUPERVGUI_ManagePortsDlg::accept() {
       item = (PortListItem*)myInList->item( i );
       aPort = aINode->InPort( item->PortName.latin1(), item->PortType.latin1() );
       myNode->createPort( aPort.in() );
+      // 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();
+      }
     }
-    for ( i = 0; i < myOutList->count(); i++ ) {
+    // 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() );
@@ -393,6 +426,9 @@ void SUPERVGUI_ManagePortsDlg::addPort( QListBox* theLB ) {
   }
 }
 
+/**
+ * called on 'X' button press - remove selected port item
+ */
 void SUPERVGUI_ManagePortsDlg::removePort( QListBox* theLB ) {
   if ( !theLB )
     return;
@@ -402,9 +438,16 @@ void SUPERVGUI_ManagePortsDlg::removePort( QListBox* theLB ) {
     delete theLB->item( i );    
 }
 
-void moveItem( QListBox* theLB, const int from, const int to ) {
+/**
+ * called on up/down key press - move the selected list box item from position 'from' to position 'to'
+ */
+void SUPERVGUI_ManagePortsDlg::moveItem( QListBox* theLB, const int from, const int to ) {
   if ( !theLB )
     return;
+
+  // disconnect itemChanged - it leads to crash if there was only 1 item left
+  disconnect( theLB, SIGNAL(currentChanged(QListBoxItem*)), this, SLOT(itemChanged(QListBoxItem*)));
+
   if ( from >= 0 && from < theLB->count() && to >=0 && to < theLB->count() ) {
     QListBoxItem* item = theLB->item( from );
     theLB->takeItem( item );
@@ -412,8 +455,14 @@ void moveItem( QListBox* theLB, const int from, const int to ) {
     theLB->setCurrentItem( item );
     theLB->setSelected( item, true );
   }
+
+  // connect back..
+  connect( theLB, SIGNAL(currentChanged(QListBoxItem*)), this, SLOT(itemChanged(QListBoxItem*)));
 }
 
+/**
+ * move the selected item UP
+ */
 void SUPERVGUI_ManagePortsDlg::moveUp( QListBox* theLB ) {
   if ( !theLB )
     return;
@@ -421,6 +470,9 @@ void SUPERVGUI_ManagePortsDlg::moveUp( QListBox* theLB ) {
   moveItem( theLB, i, i-1 );
 }
 
+/**
+ * move the selected item DOWN
+ */
 void SUPERVGUI_ManagePortsDlg::moveDown( QListBox* theLB ) {
   if ( !theLB )
     return;
@@ -442,7 +494,6 @@ bool isEditingItem( const QListBoxItem* item, const QListBox* theLB ) {
  * the last selected by user item in myInList or myOutList (myLastItem)
  */
 void SUPERVGUI_ManagePortsDlg::nameChanged( const QString& name ) {
-  if ( myFromItemChanged ) return;
   if ( isEditingItem( myLastItem, myInList ) || isEditingItem( myLastItem, myOutList ) ) {
     ((PortListItem*)myLastItem)->PortName = name;
     //myLastItem->listBox()->repaint( true );
@@ -458,7 +509,6 @@ void SUPERVGUI_ManagePortsDlg::nameChanged( const QString& name ) {
  * of the last selected by user item in myInList or myOutList (myLastItem)
  */
 void SUPERVGUI_ManagePortsDlg::typeChanged( const QString& type ) {
-  if ( myFromItemChanged ) return;
   if ( isEditingItem( myLastItem, myInList ) || isEditingItem( myLastItem, myOutList ) ) {
     ((PortListItem*)myLastItem)->PortType = type;
     //myLastItem->listBox()->repaint( true );
@@ -473,7 +523,13 @@ void SUPERVGUI_ManagePortsDlg::typeChanged( const QString& type ) {
  * called when new item became "currentItem" in any myInList or myOutList listboxes.
  */
 void SUPERVGUI_ManagePortsDlg::itemChanged( QListBoxItem * item ) {
-  myFromItemChanged = true; // to disable nameChanged, typeChanged callbacks
+  if ( !item ) // after remove, etc..
+    return;
+
+  // disable nameChanged, typeChanged callbacks
+  disconnect( myNameEdt, SIGNAL(textChanged(const QString&)), this, SLOT(nameChanged(const QString&)));
+  disconnect( myTypeCombo, SIGNAL(activated(const QString&)), this, SLOT(typeChanged(const QString&)));
+  
   myLastItem = item;
   myNameEdt->setText( ((PortListItem*)item)->PortName );
   for ( int i = 0; i < myTypeCombo->count(); i++ )
@@ -481,7 +537,10 @@ void SUPERVGUI_ManagePortsDlg::itemChanged( QListBoxItem * item ) {
       myTypeCombo->setCurrentItem( i );
       break;
     }
-  myFromItemChanged = false; // to enable nameChanged, typeChanged callbacks
+
+  // connect back nameChanged, typeChanged
+  connect( myNameEdt, SIGNAL(textChanged(const QString&)), this, SLOT(nameChanged(const QString&)));
+  connect( myTypeCombo, SIGNAL(activated(const QString&)), this, SLOT(typeChanged(const QString&)));
 }
 
 
@@ -490,7 +549,6 @@ void SUPERVGUI_ManagePortsDlg::itemChanged( QListBoxItem * item ) {
 /*!
  * Port parameters dialog definition (taken from SUPERVGUI_Node.cxx without change)
  */
-
 SUPERVGUI_PortParamsDlg::SUPERVGUI_PortParamsDlg(const QStringList& thePortsNames)
   : QDialog(QAD_Application::getDesktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu  ),
     myPortsNames( thePortsNames )