Salome HOME
Memory Leaks
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasPort.cxx
index 91f32e5eb94777027ef7806d5574434453ff82ca..1a5c30b88545e3fc83a1646b52a24d2c53379236 100644 (file)
@@ -11,6 +11,7 @@ using namespace std;
 #include "SUPERVGUI_CanvasNode.h"
 #include "SUPERVGUI_CanvasLink.h"
 #include "SUPERVGUI_CanvasNodePrs.h"
+#include "SUPERVGUI_Clipboard.h"
 #include "SUPERVGUI_Main.h"
 #include "SUPERVGUI.h"
 #include "SUPERVGUI_BrowseNodeDlg.h"
@@ -55,7 +56,7 @@ SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::createPrs() const
 QPopupMenu* SUPERVGUI_CanvasPort::getPopupMenu(QWidget* theParent) 
 {
   QPopupMenu* popup = new QPopupMenu(theParent);
-  if (myMain->isEditable()) {
+  if ( myMain->isEditable() && !myMain->getDataflow()->IsExecuting() ) {
     int anItem = popup->insertItem(tr("MSG_SKETCH_LINK"), this, SLOT(sketchLink()));
     if (myMain->getDataflow()->IsExecuting())
       popup->setItemEnabled(anItem, false);
@@ -64,7 +65,7 @@ QPopupMenu* SUPERVGUI_CanvasPort::getPopupMenu(QWidget* theParent)
                            || myPort->Kind() == SUPERV::EndSwitchParameter);
     popup->insertSeparator();
   }
-  if (myMain->isEditable() 
+  if (myMain->isEditable() && !myMain->getDataflow()->IsExecuting()
       &&
       ((myPort->IsEndSwitch() && myPort->IsInput()) 
        ||
@@ -73,8 +74,13 @@ QPopupMenu* SUPERVGUI_CanvasPort::getPopupMenu(QWidget* theParent)
        !(myPort->Node()->Kind() == SUPERV::LoopNode && !myPort->IsInput())))) {
     popup->insertItem(tr("ITM_DEL_PORT"), this, SLOT(remove()));    
   }
+  // Copy Port functionality
+  if (myMain->isEditable() && !myPort->Node()->IsFactory()
+                           && !myPort->Node()->IsComputing()
+                           && !myPort->Node()->IsMacro())
+    popup->insertItem(tr("ITM_COPY_PORT"), this, SLOT(copy()));
 
-  int anItem = popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
+  /*int anItem = */popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
 //   if (getEngine()->IsLinked())
 //     popup->setItemEnabled(anItem, getEngine()->State() == SUPERV_Ready);
 //   else 
@@ -111,12 +117,24 @@ void SUPERVGUI_CanvasPort::sync()
   getPrs()->update();
 }
 
-void SUPERVGUI_CanvasPort::sketchLink() 
-{
+void SUPERVGUI_CanvasPort::sketchLink() {
+  myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
+  
   myMain->getCanvasView()->startSketch(this);
 }
 
 void SUPERVGUI_CanvasPort::remove() {
+  myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
+
+  //set myCopyPort from Main object to empty if engine of this port is deleted
+  //check if myCopyPort and this port engine is equal
+  SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
+  if ( aCB->isCopyPort() )
+    if ( QString(myPort->Node()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) &&
+        QString(myPort->Name()) == QString(aCB->getCopyPort()->Name()) &&
+        myPort->IsInput() == aCB->getCopyPort()->IsInput() )
+       aCB->setCopyPort( 0 );
+
   Trace("SUPERVGUI_CanvasPort::remove");
   myPort->destroy();
   delete this;
@@ -161,6 +179,11 @@ void SUPERVGUI_CanvasPort::browse()
   QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), aMes);
 }
 
+void SUPERVGUI_CanvasPort::copy()
+{
+  SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
+  aCB->setCopyPort(SUPERV::Port::_duplicate(getEngine()));
+}
 
 //***********************************************************
 // Input Port
@@ -180,7 +203,7 @@ SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn()
 QPopupMenu* SUPERVGUI_CanvasPortIn::getPopupMenu(QWidget* theParent) 
 {
   QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
-  bool editable = getEngine()->IsInput() && (!getEngine()->IsLinked());
+  bool editable = getEngine()->IsInput() && !getEngine()->IsLinked() && !getMain()->getDataflow()->IsExecuting();
 
   if (!getEngine()->IsGate() && editable)
     popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
@@ -198,6 +221,8 @@ void SUPERVGUI_CanvasPortIn::setValue(const char* theValue)
 
 void SUPERVGUI_CanvasPortIn::setInput() 
 {
+  // asv 28.01.05 : set "Editing" flag only on "OK" pressed in BrowseDlg
+  //getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
   if (!myDlg) {
     myDlg = new SUPERVGUI_GetValueDlg(this);
     myDlg->installEventFilter(this);
@@ -209,7 +234,6 @@ void SUPERVGUI_CanvasPortIn::setInput()
     myDlg->setActiveWindow();
     myDlg->setFocus();
   }
-  
 }
 
 bool SUPERVGUI_CanvasPortIn::eventFilter(QObject* o, QEvent* e)
@@ -249,10 +273,17 @@ QPopupMenu* SUPERVGUI_CanvasPortOut::getPopupMenu(QWidget* theParent)
 
 void SUPERVGUI_CanvasPortOut::sync() 
 {
+  /* asv : 26.01.05 : Bug PAL7164 : sometimes CanvasPortOut::sync() is called twice (or maybe even more)
+           by mistake.  It happens because of incorrect Qt events, or other reason, but it is not a
+          stable feature (bug). Adding an object in the study in sync() is therefore called more than once
+          which is a BUG.  I decided to move call to putDataStudy() method to Event handling function.
+          When a node successfully finishes execution - check the ports and put out-value to study,
+          if the corresponding flag is set.
   bool ok = getEngine()->State() == SUPERV_Ready;
   if (ok && myInStudy) {
     myInStudy = getMain()->putDataStudy(getEngine(), STUDY_PORT_OUT);
   }
+  */
   SUPERVGUI_CanvasPort::update();
 }
 
@@ -260,19 +291,19 @@ void SUPERVGUI_CanvasPortOut::toStudy()
 {
   Trace("SUPERVGUI_CanvasPortOut::toStudy");
 
-  if (getMain()->getStudy()->getStudyDocument()->GetProperties()->IsLocked()) {
+  // asv 08.02.05 : added && !myInStudy - fix for PAL8105
+  if ( getMain()->getStudy()->getStudyDocument()->GetProperties()->IsLocked() && !myInStudy ) {
     QMessageBox::warning(QAD_Application::getDesktop(), tr("WRN_WARNING"), 
                         tr("WRN_STUDY_LOCKED"));
     return;
   }
 
-  if (!getMain()->isFromStudy()) {
-    if (getMain()->addStudy())
-      getMain()->setAsFromStudy(true);
-  }
   myInStudy = !myInStudy;
   sync();
   getMain()->getCanvas()->update();
+
+  if ( myInStudy ) // put values to study (supervision, supervision->dataflow, supervision->dataflow->runXXX, etc.
+    getMain()->putDataStudy( getEngine(), STUDY_PORT_OUT ); 
 }