Salome HOME
Color for background and title are taken from resource manager
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasControlNode.cxx
index 21991ae60dd263c14737acc85bf496d8c17adec6..8e505cc5c1154e06aa46c2313f95bda29ee77e0f 100644 (file)
@@ -9,18 +9,23 @@
 using namespace std;
 #include "SUPERVGUI_CanvasControlNode.h"
 #include "SUPERVGUI_CanvasControlNodePrs.h"
+#include "SUPERVGUI_CanvasCellNodePrs.h"
+#include "SUPERVGUI_Clipboard.h"
 #include "SUPERVGUI_Main.h"
+#include "SUPERVGUI.h"
 #include "SUPERVGUI_Canvas.h"
-#include "SUPERVGUI_ControlNode.h" // access to SelectInlineDlg
 
-#include "QAD_FileDlg.h"
-#include "QAD_Application.h"
+#include "SUIT_FileDlg.h"
+#include "SUIT_Session.h"
+
+#include <qlabel.h>
+#include <qlayout.h>
 
 //=====================================================================
 // Compute node
 //=====================================================================
-SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
-  SUPERVGUI_CanvasNode(theParent, theMain, theNode)
+SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode( SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
+  SUPERVGUI_CanvasNode( mgr, theParent, theMain, theNode)
 {
   Trace("SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode");
 }
@@ -46,8 +51,8 @@ QPopupMenu* SUPERVGUI_CanvasComputeNode::getPopupMenu(QWidget* theParent)
 //=====================================================================
 // Start control node
 //=====================================================================
-SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
-  SUPERVGUI_CanvasNode(theParent, theMain, theNode), 
+SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode(SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
+  SUPERVGUI_CanvasNode( mgr, theParent, theMain, theNode), 
   myCoupled(0)
 {
   Trace("SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode");
@@ -55,8 +60,8 @@ SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode(QObject* theParent, SUPERVG
 
 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasStartNode::createPrs() const
 {
-  return new SUPERVGUI_CanvasStartNodePrs(getMain()->getCanvas(), 
-                                         (SUPERVGUI_CanvasStartNode*)this);
+  return new SUPERVGUI_CanvasStartNodePrs( resMgr(), getMain()->getCanvas(), 
+                                          (SUPERVGUI_CanvasStartNode*)this);
 }
 
 bool SUPERVGUI_CanvasStartNode::setNodeName(QString aName)
@@ -84,11 +89,36 @@ void SUPERVGUI_CanvasStartNode::remove()
   SUPERVGUI_Canvas* aCanvas = getMain()->getCanvas();
 
   setDestroyed();
-  if (myCoupled) myCoupled->setDestroyed();
+  SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
+  if (myCoupled) {
+
+    //set myCopyPort from Main object to empty if engine of this port is deleted
+    //check if any port of this deleted node has been copied
+    if ( aCB->isCopyPort() )
+      if ( QString(getEngine()->Name()) == QString(aCB->getCopyPort()->Node()->Name())   ||
+          QString(myCoupled->getEngine()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) )
+       aCB->setCopyPort( 0 );
+    
+    myCoupled->setDestroyed();
+  }
+
+  //set myCopyNode from Main object to empty if engine of this node is deleted
+  //check if myCopyNode and this node engine is equal
+  if ( aCB->isCopyNode() )
+    if ( QString(getEngine()->Name()) == QString(aCB->getCopyNode()->Name()) ) 
+      aCB->setCopyNode( 0 );
+
+  // mkr: since the deletion of the node allow only in CANVAS view,
+  // it is necessary to remove the CanvasArray's children, which
+  // have the same CNode engine as deleting node
+  getMain()->removeArrayChild(getEngine());
+  getMain()->removeArrayChild(myCoupled->getEngine());
 
   getEngine()->destroy();
 
-  if (myCoupled) delete myCoupled;
+  if (myCoupled) 
+    delete myCoupled;
+
   delete this;
 
   aCanvas->update();
@@ -103,7 +133,8 @@ void SUPERVGUI_CanvasStartNode::onDestroyed(QObject* theObject)
   }
 }
 
-void SUPERVGUI_CanvasStartNode::addInputPort()
+// mkr : IPAL9815 : commented the following code
+/*void SUPERVGUI_CanvasStartNode::addInputPort()
 {
   SUPERVGUI_CanvasNode::addInputPort();
   if (getEngine()->IsLoop()) merge();
@@ -114,14 +145,24 @@ void SUPERVGUI_CanvasStartNode::addOutputPort()
 {
   SUPERVGUI_CanvasNode::addOutputPort();
   if (myCoupled) myCoupled->merge();
+}*/
+void SUPERVGUI_CanvasStartNode::pastePort()
+{
+  SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
+  SUPERVGUI_CanvasNode::pastePort();
+  if ( aCB->getCopyPort()->IsInput() && getEngine()->IsLoop() ) 
+    merge();
+  if ( myCoupled )
+    myCoupled->merge();
 }
 
 //=====================================================================
 // End control node
 //=====================================================================
-SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode,
-                                                SUPERVGUI_CanvasStartNode* theStart):
-  SUPERVGUI_CanvasNode(theParent, theMain, theNode), 
+SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode(SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain,
+                                                SUPERV_CNode theNode, SUPERVGUI_CanvasStartNode* theStart):
+  SUPERVGUI_CanvasNode(mgr, theParent, theMain, theNode), 
   myCoupled(theStart)
 {
   Trace("SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode");
@@ -130,8 +171,8 @@ SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode(QObject* theParent, SUPERVGUI_M
 
 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasEndNode::createPrs() const
 {
-  return new SUPERVGUI_CanvasEndNodePrs(getMain()->getCanvas(), 
-                                       (SUPERVGUI_CanvasEndNode*)this);
+  return new SUPERVGUI_CanvasEndNodePrs( resMgr(), getMain()->getCanvas(), 
+                                        (SUPERVGUI_CanvasEndNode*)this);
 }
 
 QPopupMenu* SUPERVGUI_CanvasEndNode::getPopupMenu(QWidget* theParent) 
@@ -145,26 +186,27 @@ QPopupMenu* SUPERVGUI_CanvasEndNode::getPopupMenu(QWidget* theParent)
   return popup;
 }
 
-void SUPERVGUI_CanvasEndNode::addInputPort()
+// mkr : IPAL9815 : commented the following code
+/*void SUPERVGUI_CanvasEndNode::addInputPort()
 {
   SUPERVGUI_CanvasNode::addInputPort();
   if (getEngine()->IsEndSwitch()) merge();
-}
+}*/
 
 
 //=====================================================================
 // Goto control node
 //=====================================================================
-SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
-  SUPERVGUI_CanvasNode(theParent, theMain, theNode)
+SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode(SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
+  SUPERVGUI_CanvasNode(mgr, theParent, theMain, theNode)
 {
   Trace("SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode");
 }
 
 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasGotoNode::createPrs() const
 {
-  return new SUPERVGUI_CanvasGotoNodePrs(getMain()->getCanvas(), 
-                                        (SUPERVGUI_CanvasGotoNode*)this);
+  return new SUPERVGUI_CanvasGotoNodePrs( resMgr(), getMain()->getCanvas(), 
+                                         (SUPERVGUI_CanvasGotoNode*)this);
 }
 
 QPopupMenu* SUPERVGUI_CanvasGotoNode::getPopupMenu(QWidget* theParent) 
@@ -185,8 +227,10 @@ void SUPERVGUI_CanvasGotoNode::linkToNode() {
   SUPERVGUI_SelectInlineDlg* aDlg = new SUPERVGUI_SelectInlineDlg(getMain());
   if (aDlg->exec()) {
     QString aNodeName = aDlg->getName();
-    getGotoNode()->SetCoupled(aNodeName.latin1());
-    getMain()->getCanvas()->sync();
+    if (!aNodeName.isEmpty()) { //implement additional check from GUI side for bug PAL7007
+      getGotoNode()->SetCoupled(aNodeName.latin1());
+      getMain()->getCanvas()->sync();
+    }
   }
   delete aDlg;
 }
@@ -194,16 +238,16 @@ void SUPERVGUI_CanvasGotoNode::linkToNode() {
 //=====================================================================
 // Macro node
 //=====================================================================
-SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
-  SUPERVGUI_CanvasComputeNode(theParent, theMain, theNode)
+SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode(SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
+  SUPERVGUI_CanvasComputeNode(mgr, theParent, theMain, theNode)
 {
   Trace("SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode");
 }
 
 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasMacroNode::createPrs() const
 {
-  return new SUPERVGUI_CanvasMacroNodePrs(getMain()->getCanvas(), 
-                                         (SUPERVGUI_CanvasMacroNode*)this);
+  return new SUPERVGUI_CanvasMacroNodePrs( resMgr(), getMain()->getCanvas(), 
+                                          (SUPERVGUI_CanvasMacroNode*)this);
 }
 
 QPopupMenu* SUPERVGUI_CanvasMacroNode::getPopupMenu(QWidget* theParent) 
@@ -233,19 +277,181 @@ void SUPERVGUI_CanvasMacroNode::exportDataflow()
       aGraph = aMacro->FlowObjRef();
   }
   if (SUPERV_isNull(aGraph)) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
     return;
   }
   else {
-    QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
-                                                "",
-                                                "*.xml",
-                                                tr("TTL_EXPORT_DATAFLOW"),
-                                                false);
-    if (!aFileName.isEmpty()) {
+    QString aFileName = SUIT_FileDlg::getFileName(SUIT_Session::session()->activeApplication()->desktop(),
+                                                 "",
+                                                 "*.xml",
+                                                 tr("TTL_EXPORT_DATAFLOW"),
+                                                 false);
+    if ( !aFileName.isEmpty() ) {
+      // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file, 
+      // a backup copy of an existing file must be created (in case Export fails..)
+      QString aBackupFile = SUPERVGUI::createBackupFile( aFileName );
+
       if (!aGraph->Export(aFileName.latin1())) {
-       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING"));
+       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
+      }
+      // remove a backup file if export was successfull
+      else if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() ) {
+       QFile::remove( aBackupFile );
       }
     }
   }
 }
+
+//=====================================================================
+// Cell node: node for table view
+//=====================================================================
+SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode(SUIT_ResourceMgr* mgr, QObject* theParent, 
+                                                  SUPERVGUI_Main* theMain, 
+                                                  SUPERV_CNode theNode):
+  SUPERVGUI_CanvasNode(mgr, theParent, theMain, theNode, true)
+{
+  Trace("SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode");
+  
+  myIsControl = false;
+  myIsStart = false;
+
+  //check for control nodes
+  if (getEngine()->IsLoop() || getEngine()->IsSwitch()) {
+    myIsControl = true;  
+    myIsStart = true;
+  }
+  if (getEngine()->IsEndLoop() || getEngine()->IsEndSwitch())
+    myIsControl = true;
+}
+
+SUPERVGUI_CanvasCellNode::~SUPERVGUI_CanvasCellNode()
+{
+}
+/*
+QPopupMenu* SUPERVGUI_CanvasCellNode::getPopupMenu(QWidget* theParent)
+{
+  QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
+  popup->setItemEnabled(myDeleteItem, false);
+  return popup;
+}
+*/
+void SUPERVGUI_CanvasCellNode::setPairCell(SUPERVGUI_CanvasCellNode* thePairCell) {
+  if (myIsControl) { //only for ControlNode
+    myPairCell = thePairCell;
+  }
+  else 
+    myPairCell = 0;
+}
+
+SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasCellNode::getPairCell() {
+  return myPairCell;
+}
+
+void SUPERVGUI_CanvasCellNode::sync() {
+  const bool isExecuting = getMain()->getDataflow()->IsExecuting();
+  //if getEngine() is a MacroNode then set it state to state of its subgraph
+  if ( getEngine()->IsMacro() && isExecuting ) {
+    // get SubGraph from MacroNode
+    SUPERV_Graph aMacro = SUPERV::Graph::_narrow(getEngine());
+    if (!SUPERV_isNull(aMacro)) {
+      SUPERV_Graph aGraph;
+      if (aMacro->IsStreamMacro())
+       aGraph = aMacro->StreamObjRef();
+      else
+       aGraph = aMacro->FlowObjRef();
+      if (!SUPERV_isNull(aGraph)) {
+       if (aGraph->State() != SUPERV::UndefinedState && aGraph->State() != SUPERV::NoState)
+         getPrs()->setState(aGraph->State());
+       else 
+         getPrs()->setState(getEngine()->State());
+      }
+    }
+  }
+  else {
+    getPrs()->setState(getEngine()->State());
+  }
+}
+/*
+bool SUPERVGUI_CanvasCellNode::setNodeName(QString aName) 
+{
+  bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
+  if (result && myPairCell) {
+    result = myPairCell->setNodeName(QString(tr("ENDNODE_PREFIX"))+aName);
+  }
+  return result;
+}
+*/
+SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasCellNode::createPrs() const
+{
+  SUPERVGUI_CanvasNodePrs* aPrs = 
+    new SUPERVGUI_CanvasCellNodePrs( resMgr(), getMain()->getCanvasArray(), 
+                                    (SUPERVGUI_CanvasCellNode*)this);
+  return aPrs;
+}
+
+SUPERVGUI_CanvasCellEndNode::SUPERVGUI_CanvasCellEndNode( SUIT_ResourceMgr* mgr, QObject* theParent, 
+                                                         SUPERVGUI_Main* theMain, 
+                                                         SUPERV_CNode theNode, 
+                                                         SUPERVGUI_CanvasCellNode* theStart):
+  SUPERVGUI_CanvasCellNode(mgr, theParent, theMain, theNode)
+{
+  //set start cell for end cell as pair 
+  myPairCell = theStart; 
+  //set end cell for start cell as pair
+  myPairCell->setPairCell(dynamic_cast<SUPERVGUI_CanvasCellNode*>(this));
+}
+/*
+bool SUPERVGUI_CanvasCellEndNode::setNodeName(QString theName)
+{
+  return SUPERVGUI_CanvasNode::setNodeName(theName);
+}
+*/
+//-----------------------------------------------------------
+//*************** Select Inline node dialog******************
+// Taken from SUPERVGUI_ControlNode.cxx without change
+//-----------------------------------------------------------
+
+SUPERVGUI_SelectInlineDlg::SUPERVGUI_SelectInlineDlg(SUPERVGUI_Main* theMain)  
+  :QDialog(theMain, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
+{
+  setSizeGripEnabled( true );
+  setCaption(tr("TIT_FUNC_PYTHON"));
+  QGridLayout* aMainLayout = new QGridLayout(this, 2, 2, 7, 4);
+
+  QLabel* aLabel = new QLabel("Connect to", this );
+  aMainLayout->addWidget(aLabel, 0, 0);
+
+  myCombo = new QComboBox(this);
+  myCombo->clear(); //for the additional check from GUI side for bug PAL7007
+  SUPERV_Nodes aNodesList = theMain->getDataflow()->Nodes();  
+  int i;
+  for (i = 0; i < aNodesList->INodes.length(); i++) {
+    myCombo->insertItem(QString(aNodesList->INodes[i]->Name()));
+  }
+  for (i = 0; i < aNodesList->LNodes.length(); i++) {
+    myCombo->insertItem(QString(aNodesList->LNodes[i]->Name()));
+  }
+  for (i = 0; i < aNodesList->SNodes.length(); i++) {
+    myCombo->insertItem(QString(aNodesList->SNodes[i]->Name()));
+  }
+  aMainLayout->addWidget(myCombo, 0, 1);
+
+  QGroupBox* aBtnBox = new QGroupBox( this );
+  aBtnBox->setColumnLayout( 0, Qt::Vertical );
+  aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
+  QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
+  aBtnLayout->setAlignment( Qt::AlignTop );
+  aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
+  
+  QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
+  connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
+  aBtnLayout->addWidget( aOKBtn );
+
+  aBtnLayout->addStretch();
+
+  QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
+  connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
+  aBtnLayout->addWidget( aCancelBtn );
+
+  aMainLayout->addMultiCellWidget(aBtnBox, 1, 1, 0, 1);
+}