]> SALOME platform Git repositories - modules/superv.git/commitdiff
Salome HOME
Fix for PAL7823 (checking for if study is locked before doing New Dataflow command).
authorasv <asv@opencascade.com>
Thu, 27 Jan 2005 08:17:22 +0000 (08:17 +0000)
committerasv <asv@opencascade.com>
Thu, 27 Jan 2005 08:17:22 +0000 (08:17 +0000)
Also some re-engineering of the code: new function createDataflow() is introduced, it combines functionality of the 3 commands: newDataflow(), importDataflow(), modifyDataflow().  These 3 functions did basically the same thing, with slight differences, which are implemented in createDataflow() using 'mode' parameter.

src/SUPERVGUI/SUPERVGUI.cxx
src/SUPERVGUI/SUPERVGUI.h

index 11ac798d47d445cadf7000afc718016c998f015b..811600dce436addfc3d69180e60fcd7d6a4551e6 100644 (file)
@@ -37,13 +37,14 @@ using namespace std;
 #include "QAD_ViewFrame.h"
 #include "QAD_ObjectBrowser.h"
 #include "QAD_ObjectBrowserItem.h"
+#include "QAD_MessageBox.h"
+
 #include "SALOME_Selection.h"
-#include "SALOMEGUI_NameDlg.h"            
-#include "Utils_ORB_INIT.hxx"
 #include "SALOME_ListIteratorOfListIO.hxx"
 #include "SALOME_InteractiveObject.hxx"
-#include <qapplication.h>
 #include "SALOMEGUI_ImportOperation.h"
+#include "SALOMEGUI_NameDlg.h"            
+#include "Utils_ORB_INIT.hxx"
 
 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
 
@@ -266,42 +267,6 @@ void SUPERVGUI::setMain(QWidget* w) {
   Trace("SUPERVGUI::setMain - main: "<<main);
 }
 
-
-void SUPERVGUI::importDataflow() {
-  Trace("SUPERVGUI::importDataflow");
-  QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
-                                      "",
-                                      "*.xml",
-                                      tr("MSG_IMPORT"),
-                                      true);
-  
-  if (!f.isEmpty()) {
-    if (isContains(study, f)) {
-      if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), 
-                              tr("MSG_GRAPH_DISPLAYED").arg(f), 
-                              QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
-       return;
-    }
-
-    SUPERV_Graph aGraph = engine->StreamGraphE(f);
-    //QFileInfo aFile(f);
-    //aGraph->SetName(aFile.baseName());
-    if (SUPERV_isNull(aGraph)) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
-      return;
-    }
-
-    QAD_StudyFrame* aStudyFrame = createGraph();
-    SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
-      (aStudyFrame->getRightFrame()->getViewFrame());
-    if(aViewFrame) {
-      main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
-      registerGraph(f, main);
-      study->showFrame(aStudyFrame);
-    }  
-  }
-}
-
 void SUPERVGUI::displayDataflow() {
     Trace("SUPERVGUI::displayDataflow");
     QAD_ObjectBrowser* aBrowser = ((QAD_StudyFrame*)(desktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
@@ -445,60 +410,71 @@ QString SUPERVGUI::createBackupFile( const QString& theOriginalFileName ) {
 }
 
 void SUPERVGUI::newDataflow() {
-    Trace("SUPERVGUI::editDataflow");
-
-    //asv 20.10.04: removed 2 SUPERVGUI_Main constructors.  there is only ONE way 
-    //to create a Main object now: with a non-null DataFlow as a 3d parameter
-    //1. create a Graph object
-    SUPERV_Graph aNewDataFlow = engine->StreamGraph( MAIN_NEW );
-    if (SUPERV_isNull( aNewDataFlow )) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_DF"));
-      return;
-    }
-    //2. create a ViewFrame object
-    QAD_StudyFrame* aStudyFrame = createGraph();
-    SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
-      (aStudyFrame->getRightFrame()->getViewFrame());
-    if(aViewFrame){
-      //3. bind Graph and ViewFrame -> create Main
-      main = new SUPERVGUI_Main(aViewFrame, desktop, aNewDataFlow );
-      main->addNode();
-      study->showFrame(aStudyFrame);
-    }
+  createDataflow( New );
+}
+
+void SUPERVGUI::importDataflow() {
+  createDataflow( Import );
 }
 
 void SUPERVGUI::modifyDataflow() {
-    Trace("SUPERVGUI::modifyDataflow")
-    QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
-                                        "",
-                                        "*.xml",
-                                        tr("Modify Dataflow"),
-                                        true);
-    if (!f.isEmpty()){
-      if (isContains(study, f)) {
-      if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), 
-                              tr("MSG_GRAPH_DISPLAYED").arg(f), 
-                              QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
-       return;
-      }
-      
-      SUPERV_Graph aGraph = engine->StreamGraph(f);
-      //QFile aFile(f);
-      //aGraph->SetName(aFile.name());
-      if (SUPERV_isNull(aGraph)) {
-       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
-       return;
-      }
+  createDataflow( Modify );
+}
 
-      QAD_StudyFrame* aStudyFrame = createGraph();
-      SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
-       (aStudyFrame->getRightFrame()->getViewFrame());
-      if(aViewFrame) {
-       main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
-       registerGraph(f, main);
-       study->showFrame(aStudyFrame);
-      }
+bool SUPERVGUI::createDataflow( const NEW_DF_MODE mode ) {
+  Trace("SUPERVGUI::createDataflow, mode = " << mode );
+
+  // asv : 27.01.05 : fix for PAL7823 : if the study is locked - warn the user and return.
+  SALOMEDS::Study_var aStudy = study->getStudyDocument();
+  if ( aStudy->GetProperties()->IsLocked() ) {
+    QMessageBox::warning(QAD_Application::getDesktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
+    return false;
+  }
+
+  SUPERV::Graph_var aGraph;
+
+  QString f; // file name.  declared here because may be used below in error msg construction..
+  if ( mode == Import || mode == Modify ) { // 0. import or modify existing dataflow - select XML file
+    QString title = QString( "TLT_CREATE_DF_%1" ).arg( mode );
+    f = QAD_FileDlg::getFileName( QAD_Application::getDesktop(), "", "*.xml", tr( title ), true );
+    if ( f.isEmpty() ) // pressed Cancel in file select dialog
+      return false;
+    
+    // check if study already contains a graph imported from the same file
+    if ( isContains( study, f ) ) {
+      if ( QMessageBox::warning( QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_GRAPH_DISPLAYED").arg(f), 
+                                QMessageBox::Yes, QMessageBox::No) == QMessageBox::No )
+       return false;
     }
+    
+    // 1. create a graph
+    aGraph = ( mode == Import ) ? engine->StreamGraphE( f ) : engine->StreamGraph( f );        
+  }
+  else
+    aGraph = engine->StreamGraph( MAIN_NEW );
+
+  if ( CORBA::is_nil( aGraph ) ) {
+    QString msg( mode == New ? QString("MSG_CANT_CREATE_DF") : QString("MSG_BAD_FILE").arg(f) );
+    QAD_MessageBox::warn1( QAD_Application::getDesktop(), tr("ERROR"), tr(msg), tr("BUT_OK") );
+    return false;
+  }
+
+  // 2. create a ViewFrame object
+  QAD_StudyFrame* aStudyFrame = createGraph();
+  SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
+    (aStudyFrame->getRightFrame()->getViewFrame());
+  if ( aViewFrame ) {
+
+    // 3. bind Graph and ViewFrame == create SUPERVGUI_Main object
+    main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
+    if ( mode == New )
+      main->addNode();
+    else
+      registerGraph( f, main );
+    study->showFrame(aStudyFrame);
+  }
+
+  return true;
 }
 
 void SUPERVGUI::reloadDataflow() {
index eb8e90359c2df7fea26df532c2c2bce0f5fa3d35..32b6b231b64104eb72f363de2c4c6beef4ff3b36 100644 (file)
@@ -121,6 +121,13 @@ class SUPERVGUI: public SALOMEGUI {
   private:
     void loadEngine(SALOME_NamingService* namingService);
 
+    // enumeration used in newDataflow() method
+    enum NEW_DF_MODE { Import, Modify, New }; 
+    // method called from importDataflow(), modifyDataflow(), newDataflow() with
+    // different modes.  The behavior of the function is very similar in all 3 cases, 
+    // but some differences still exist.  These differences are implemented using NEW_DF_MODE param.
+    bool createDataflow( const NEW_DF_MODE f );  
+
     static int             factory;
     QAD_Desktop*           desktop;
     QAD_Study*             study;