Salome HOME
Allow passing multiple scripts with arguments from command line
[modules/gui.git] / src / SalomeApp / SalomeApp_Study.cxx
index 1a38c88e12a179a31704ddca75a4d17a7ffa0905..07ffd4aba283c6339d93990834f5060a1cd5a237 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -26,7 +26,7 @@
 #include "SalomeApp_DataObject.h"
 #include "SalomeApp_DataModel.h"
 #include "SalomeApp_Application.h"
-#include "SalomeApp_Engine_i.hxx"
+#include "SalomeApp_Engine_i.h"
 #include "SalomeApp_VisualState.h"
 
 // temporary commented
@@ -75,7 +75,7 @@ class SalomeApp_Study::Observer_i : public virtual POA_SALOMEDS::Observer, QObje
 
 public:
 
-  Observer_i(_PTR(Study) aStudyDS, SalomeApp_Study* aStudy)
+  Observer_i(_PTR(Study) aStudyDS, SalomeApp_Study* aStudy):QObject(aStudy)
   {
     myStudyDS=aStudyDS;
     myStudy=aStudy;
@@ -153,10 +153,10 @@ public:
             SUIT_DataObject* oldFather = suit_obj->parent();
             if (oldFather) {
               oldFather->removeChild(suit_obj, false);
-             SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( myStudy->application() );
-             SUIT_AbstractModel* model = dynamic_cast<SUIT_AbstractModel*>(app->objectBrowser()->model());
-             model->forgetObject( suit_obj );
-               
+              SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( myStudy->application() );
+              SUIT_AbstractModel* model = dynamic_cast<SUIT_AbstractModel*>(app->objectBrowser()->model());
+              model->forgetObject( suit_obj );
+                
               if (SalomeApp_DataObject* oldFatherSA = dynamic_cast<SalomeApp_DataObject*>(oldFather)) {
                 oldFatherSA->updateItem();
               }
@@ -167,7 +167,7 @@ public:
             entry2SuitObject[theID] = suit_obj;
           }
 
-         suit_obj->updateItem();
+          suit_obj->updateItem();
           // define position in the data tree (in aFatherDO) to insert the aSObj
           int pos = -1;
           //int childDataObjCount = aFatherDO->childCount();
@@ -183,6 +183,22 @@ public:
           //aFatherDO->insertChild(suit_obj, pos);
           aFatherDO->updateItem();
 
+         /* Define visibility state */
+         bool isComponent = dynamic_cast<SalomeApp_ModuleObject*>( suit_obj ) != 0;
+         if ( suit_obj && !isComponent ) {
+           QString moduleTitle = ((CAM_Application*)myStudy->application())->moduleTitle(suit_obj->componentDataType());
+           if (!moduleTitle.isEmpty()) {
+             LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer(moduleTitle,false);
+             if (aDisplayer) {
+               if(aDisplayer->canBeDisplayed(theID.c_str())) {
+                 myStudy->setVisibilityState( theID.c_str(), Qtx::HiddenState );
+                 //MESSAGE("Object with entry : "<< theID <<" CAN be displayed !!!");
+               }
+               else
+                 MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!");
+             }
+           }
+         }
         } // END: work with tree nodes structure
         else { // BEGIN: work with study structure
           EntryMapIter it = entry2SuitObject.find( theID );
@@ -318,6 +334,11 @@ public:
         }
         break;
       }
+    case 6: //NoteBook variables were modified
+      {
+       myStudy->onNoteBookVarUpdate( QString( theID.c_str() ) );
+       break;
+      }
     default:MESSAGE("Unknown event: "  << event);break;
     } //switch
   } //notifyObserverID_real
@@ -375,6 +396,15 @@ SalomeApp_Study::SalomeApp_Study( SUIT_Application* app )
 */
 SalomeApp_Study::~SalomeApp_Study()
 {
+  if ( myObserver ) {
+    PortableServer::ObjectId_var oid = myObserver->_default_POA()->servant_to_id( myObserver );
+    myObserver->_default_POA()->deactivate_object( oid.in() );
+  }
+}
+
+void SalomeApp_Study::onNoteBookVarUpdate( QString theVarName)
+{
+  emit notebookVarUpdated( theVarName );
 }
 
 /*!
@@ -543,6 +573,10 @@ bool SalomeApp_Study::loadDocument( const QString& theStudyName )
 #endif
 
   bool res = CAM_Study::openDocument( theStudyName );
+  
+  //rnv: to fix the "0051779: TC7.2.0: Save operation works incorrectly for study loaded from data server"
+  //     mark study as "not saved" after call openDocument( ... ) method.
+  setIsSaved(false);
   emit opened( this );
 
   bool restore = application()->resourceMgr()->booleanValue( "Study", "store_visual_state", true );
@@ -574,7 +608,7 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
     // Cast to LightApp class in order to give a chance
     // to light modules to save their data
     if ( LightApp_DataModel* aModel = 
-        dynamic_cast<LightApp_DataModel*>( it.next() ) ) {
+         dynamic_cast<LightApp_DataModel*>( it.next() ) ) {
       listOfFiles.clear();
       aModel->saveAs( theFileName, this, listOfFiles );
       if ( !listOfFiles.isEmpty() )
@@ -619,7 +653,7 @@ bool SalomeApp_Study::saveDocument()
     // Cast to LightApp class in order to give a chance
     // to light modules to save their data
     if ( LightApp_DataModel* aModel = 
-        dynamic_cast<LightApp_DataModel*>( it.next() ) ) {
+         dynamic_cast<LightApp_DataModel*>( it.next() ) ) {
       listOfFiles.clear();
       aModel->save(listOfFiles);
       if ( !listOfFiles.isEmpty() )
@@ -680,9 +714,9 @@ void SalomeApp_Study::closeDocument(bool permanently)
   \return - true if the operation succeeds, and false otherwise.
 */
 bool SalomeApp_Study::dump( const QString& theFileName, 
-                           bool toPublish, 
-                           bool isMultiFile,
-                           bool toSaveGUI )
+                            bool toPublish, 
+                            bool isMultiFile,
+                            bool toSaveGUI )
 {
   int savePoint;
   _PTR(AttributeParameter) ap;
@@ -709,13 +743,13 @@ bool SalomeApp_Study::dump( const QString& theFileName,
   QStringList listOfFiles;
   while ( it.hasNext() ) {
     if ( LightApp_DataModel* aModel = 
-        dynamic_cast<LightApp_DataModel*>( it.next() ) ) {
+         dynamic_cast<LightApp_DataModel*>( it.next() ) ) {
       listOfFiles.clear();
       if ( aModel->dumpPython( theFileName, this, isMultiFile, listOfFiles ) && 
-          !listOfFiles.isEmpty() )
-       // This call simply passes the data model's dump output to SalomeApp_Engine servant.
-       // This code is shared with persistence mechanism.
-       // NOTE: this should be revised if behavior of saveModuleData() changes!
+           !listOfFiles.isEmpty() )
+        // This call simply passes the data model's dump output to SalomeApp_Engine servant.
+        // This code is shared with persistence mechanism.
+        // NOTE: this should be revised if behavior of saveModuleData() changes!
         saveModuleData(aModel->module()->name(), listOfFiles);
     }
   }
@@ -724,9 +758,9 @@ bool SalomeApp_Study::dump( const QString& theFileName,
   // any light module is present in the current configuration
   QFileInfo aFileInfo( theFileName );
   bool res = aStudy->DumpStudy( aFileInfo.absolutePath().toUtf8().data(),
-                               aFileInfo.baseName().toUtf8().data(),
-                               toPublish,
-                               isMultiFile);
+                                aFileInfo.baseName().toUtf8().data(),
+                                toPublish,
+                                isMultiFile);
   if ( toSaveGUI )
     removeSavePoint( savePoint ); //SRN: remove the created temporary save point.
 
@@ -860,7 +894,7 @@ void SalomeApp_Study::setStudyDS( const _PTR(Study)& s )
   \sa LightApp_Study class, LightApp_DataModel class
 */
 CAM_ModuleObject* SalomeApp_Study::createModuleObject( LightApp_DataModel* theDataModel, 
-                                                      SUIT_DataObject* theParent ) const
+                                                       SUIT_DataObject* theParent ) const
 {
   SalomeApp_Study* that = const_cast<SalomeApp_Study*>( this );
   
@@ -941,7 +975,7 @@ void SalomeApp_Study::addComponent(const CAM_DataModel* dm)
       // Set default engine IOR
       // Issue 21377 - using separate engine for each type of light module
       std::string anEngineIOR = SalomeApp_Engine_i::EngineIORForComponent( aCompDataType.c_str(),
-                                                                          true );
+                                                                           true );
       aBuilder->DefineComponentInstance(aComp, anEngineIOR);
       //SalomeApp_DataModel::BuildTree( aComp, root(), this, /*skipExisitng=*/true );
       SalomeApp_DataModel::synchronize( aComp, this );
@@ -1120,10 +1154,11 @@ void SalomeApp_Study::RemoveTemporaryFiles ( const char* theModuleName, const bo
   Mark the study as saved in the file
   \param theFileName - the name of file
 */
-void SalomeApp_Study::markAsSavedIn(QString theFileName)
+void SalomeApp_Study::updateFromNotebook( const QString& theFileName, bool isSaved )
 {
   setStudyName(theFileName);
-  setIsSaved(true);
+  studyDS()->Name(theFileName.toStdString());
+  setIsSaved( isSaved );
 }
 
 LightApp_DataObject* SalomeApp_Study::findObjectByEntry( const QString& theEntry )