Salome HOME
Updated copyright comment
[modules/gui.git] / src / LightApp / LightApp_Study.cxx
index 2b4f0f4df17cce978b797cf4cc27a6008d301344..9aa9403316083dccaba1b99ec4add421919f854f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -60,8 +60,6 @@ LightApp_Study::~LightApp_Study()
 */
 bool LightApp_Study::createDocument( const QString& theStr )
 {
-  setStudyName( QString( "Study%1" ).arg( LightApp_Application::studyId() ) );
-
   // create myRoot
   setRoot( new LightApp_RootObject( this ) );
 
@@ -79,7 +77,7 @@ bool LightApp_Study::openDocument( const QString& theFileName )
 {
   myDriver->ClearDriverContents();
   // create files for models from theFileName
-  if( !openStudyData(theFileName))
+  if( !openStudyData(theFileName, 0)) // 0 means persistence file
     return false;
 
   setRoot( new LightApp_RootObject( this ) ); // create myRoot
@@ -107,7 +105,7 @@ bool LightApp_Study::openDocument( const QString& theFileName )
 bool LightApp_Study::loadDocument( const QString& theStudyName )
 {
   myDriver->ClearDriverContents();
-  if( !openStudyData(theStudyName))
+  if( !openStudyData(theStudyName, 0)) // 0 means persistence file
     return false;
 
   setRoot( new LightApp_RootObject( this ) ); // create myRoot
@@ -157,7 +155,8 @@ bool LightApp_Study::saveDocumentAs( const QString& theFileName )
     listOfFiles.clear();
     aModel->saveAs( theFileName, this, listOfFiles );
     if ( !listOfFiles.isEmpty() )
-      saveModuleData(aModel->module()->name(), listOfFiles);
+      saveModuleData(aModel->module()->name(), 0, // 0 means persistence file
+                    listOfFiles);
 
     // Remove files if necessary. File is removed if it was in the list of files before
     // saving and it is not contained in the list after saving. This provides correct 
@@ -168,7 +167,7 @@ bool LightApp_Study::saveDocumentAs( const QString& theFileName )
     
     std::set<std::string> aNewNames;
     std::set<std::string> toRemove;
-    int i, n;
+    size_t i, n;
     for( i = 0, n = aNewList.size(); i < n; i++ )
       aNewNames.insert( aNewList[ i ] );
     for( i = 0, n = anOldList.size(); i < n; i++ )
@@ -188,7 +187,7 @@ bool LightApp_Study::saveDocumentAs( const QString& theFileName )
     myDriver->RemoveFiles( toRemoveList, isMultiFile );
   }
 
-  bool res = saveStudyData(theFileName);
+  bool res = saveStudyData(theFileName, 0); // 0 means persistence file
   res = res && CAM_Study::saveDocumentAs( theFileName );
   //SRN: BugID IPAL9377, removed usage of uninitialized variable <res>
   if ( res )
@@ -213,10 +212,11 @@ bool LightApp_Study::saveDocument()
 
     listOfFiles.clear();
     aModel->save( listOfFiles );
-    saveModuleData(aModel->module()->name(), listOfFiles);
+    saveModuleData(aModel->module()->name(), 0, // 0 means persistence file
+                  listOfFiles);
   }
 
-  bool res = saveStudyData(studyName());
+  bool res = saveStudyData(studyName(), 0); // 0 means persistence file
   res = res && CAM_Study::saveDocument();
   if (res)
     emit saved( this );
@@ -319,14 +319,14 @@ bool LightApp_Study::isSaved() const
 /*!
   Creates SComponent for module, necessary for SalomeApp study
 */
-void LightApp_Study::addComponent(const CAM_DataModel* dm)
+void LightApp_Study::addComponent(const CAM_DataModel* /*dm*/)
 {
 }
 
 /*!
   Saves list file for module 'theModuleName'
 */
-void LightApp_Study::saveModuleData(QString theModuleName, QStringList theListOfFiles)
+void LightApp_Study::saveModuleData(QString theModuleName, int type, QStringList theListOfFiles)
 {
   int aNb = theListOfFiles.count();
   if ( aNb == 0 )
@@ -337,19 +337,19 @@ void LightApp_Study::saveModuleData(QString theModuleName, QStringList theListOf
   for ( QStringList::Iterator it = theListOfFiles.begin(); it != theListOfFiles.end(); ++it ) {
     if ( (*it).isEmpty() )
       continue;
-    aListOfFiles[anIndex] = (*it).toLatin1().constData();
+    aListOfFiles[anIndex] = (*it).toUtf8().constData();
     anIndex++;
   }
-  myDriver->SetListOfFiles(theModuleName.toLatin1().constData(), aListOfFiles);
+  SetListOfFiles(theModuleName.toLatin1().constData(), type, aListOfFiles);
 }
 
 /*!
   Gets list of file for module 'theModuleNam'
 */
-void LightApp_Study::openModuleData(QString theModuleName, QStringList& theListOfFiles)
+void LightApp_Study::openModuleData(QString theModuleName, int /*type*/, QStringList& theListOfFiles)
 {
   std::vector<std::string> aListOfFiles =  myDriver->GetListOfFiles(theModuleName.toLatin1().constData());
-  int i, aLength = aListOfFiles.size() - 1;
+  int i, aLength = (int)aListOfFiles.size() - 1; //!< TODO: conversion size_t to int
   if (aLength < 0)
     return;
 
@@ -362,7 +362,7 @@ void LightApp_Study::openModuleData(QString theModuleName, QStringList& theListO
 /*!
   Saves data from study
 */
-bool LightApp_Study::saveStudyData( const QString& theFileName )
+bool LightApp_Study::saveStudyData( const QString& theFileName, int /*type*/ )
 {
   ModelList list; dataModels( list );
   SUIT_ResourceMgr* resMgr = application()->resourceMgr();
@@ -370,21 +370,21 @@ bool LightApp_Study::saveStudyData( const QString& theFileName )
     return false;
   bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
 
-  bool aRes = myDriver->SaveDatasInFile(theFileName.toLatin1(), isMultiFile);
+  bool aRes = myDriver->SaveDatasInFile(theFileName.toUtf8(), isMultiFile);
   return aRes;
 }
 
 /*!
   Opens data for study
 */
-bool LightApp_Study::openStudyData( const QString& theFileName )
+bool LightApp_Study::openStudyData( const QString& theFileName, int /*type*/ )
 {
   SUIT_ResourceMgr* resMgr = application()->resourceMgr();
   if( !resMgr )
     return false;
   bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
 
-  bool aRes = myDriver->ReadDatasFromFile(theFileName.toLatin1(), isMultiFile);
+  bool aRes = myDriver->ReadDatasFromFile(theFileName.toUtf8(), isMultiFile);
   return aRes;
 }
 
@@ -397,7 +397,8 @@ bool LightApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm
     return false;
 
   QStringList listOfFiles;
-  openModuleData(dm->module()->name(), listOfFiles);
+  openModuleData(dm->module()->name(), 0, // 0 means persistence file
+                listOfFiles);
   if (dm && dm->open(studyName, this, listOfFiles)) {
     // Something has been read -> create data model tree
     LightApp_DataModel* aDM = dynamic_cast<LightApp_DataModel*>( dm );
@@ -421,11 +422,9 @@ std::string LightApp_Study::GetTmpDir (const char* theURL,
   \return list of files necessary for module
   \param theModuleName - name of module
 */
-std::vector<std::string> LightApp_Study::GetListOfFiles(const char* theModuleName) const
+std::vector<std::string> LightApp_Study::GetListOfFiles(const char* theModuleName, int /*type*/) const
 {
-  std::vector<std::string> aListOfFiles;
-  aListOfFiles = myDriver->GetListOfFiles(theModuleName);
-  return aListOfFiles;
+  return myDriver->GetListOfFiles(theModuleName);
 }
 
 /*!
@@ -433,7 +432,7 @@ std::vector<std::string> LightApp_Study::GetListOfFiles(const char* theModuleNam
   \param theModuleName - name of module
   \param theListOfFiles - list of files
 */
-void LightApp_Study::SetListOfFiles (const char* theModuleName, const std::vector<std::string> theListOfFiles)
+void LightApp_Study::SetListOfFiles (const char* theModuleName, int /*type*/, const std::vector<std::string> theListOfFiles)
 {
   myDriver->SetListOfFiles(theModuleName, theListOfFiles);
 }
@@ -441,7 +440,7 @@ void LightApp_Study::SetListOfFiles (const char* theModuleName, const std::vecto
 /*!
   Removes temporary files
 */
-void LightApp_Study::RemoveTemporaryFiles (const char* theModuleName, const bool isMultiFile) const
+void LightApp_Study::RemoveTemporaryFiles (const char* theModuleName, bool isMultiFile, bool /*force*/)
 {
   if (isMultiFile)
     return;
@@ -532,49 +531,19 @@ QString LightApp_Study::getVisualComponentName() const
   return "Interface Applicative";
 }
 
-
-
-
-
 /*!
   Set a visual property of the object
-  \param theViewId - Id of the viewer namager
+  \param theViewMgrId - Id of the viewer namager
   \param theEntry - Entry of the object
   \param thePropName - the name of the visual property
   \param theValue - the value of the visual property
 */
-void LightApp_Study::setObjectProperty(int theViewId, QString theEntry, QString thePropName, QVariant theValue) {
-  
-  //Try to find viewer manager in the map
-  ViewMgrMap::Iterator v_it = myViewMgrMap.find(theViewId);
-  if(v_it == myViewMgrMap.end()) {
-
-    //1) Create property map
-    PropMap aPropMap;
-    aPropMap.insert(thePropName, theValue);
-    
-    //2) Create object map
-    ObjMap anObjMap;
-    anObjMap.insert(theEntry,aPropMap);
-
-    //3) Insert in the view manager map
-    myViewMgrMap.insert(theViewId, anObjMap);
-    
-  } else {
-    ObjMap& anObjMap = v_it.value();
-    ObjMap::Iterator o_it = anObjMap.find(theEntry);
-    if(o_it == anObjMap.end()) {
-      //1) Create property map
-      PropMap aPropMap;
-      aPropMap.insert(thePropName, theValue);
-      
-      //2) Insert in the object map
-      anObjMap.insert(theEntry, aPropMap);
-    } else {
-      PropMap& aPropMap = o_it.value();
-      aPropMap.insert(thePropName, theValue);
-    }
-  }
+void LightApp_Study::setObjectProperty( int theViewMgrId,
+                                       const QString& theEntry,
+                                       const QString& thePropName,
+                                       const QVariant& theValue )
+{
+  myViewMgrMap[theViewMgrId][theEntry][thePropName] = theValue;
 }
 
 /*!
@@ -585,16 +554,20 @@ void LightApp_Study::setObjectProperty(int theViewId, QString theEntry, QString
   \param theDefValue - the default value of the visual property.
   \return value of the visual propetry. If value is't found then return theDefValue.
 */
-QVariant LightApp_Study::getObjectProperty(int theViewMgrId, QString theEntry, QString thePropName, QVariant theDefValue) const {
-  QVariant& aResult = theDefValue;
-  ViewMgrMap::ConstIterator v_it = myViewMgrMap.find(theViewMgrId);
-  if(v_it != myViewMgrMap.end()){
+QVariant LightApp_Study::getObjectProperty( int theViewMgrId,
+                                           const QString& theEntry,
+                                           const QString& thePropName,
+                                           const QVariant& theDefValue ) const
+{
+  QVariant aResult = theDefValue;
+  ViewMgrMap::ConstIterator v_it = myViewMgrMap.find( theViewMgrId );
+  if ( v_it != myViewMgrMap.end() ) {
     const ObjMap& anObjectMap = v_it.value();
-    ObjMap::ConstIterator o_it = anObjectMap.find(theEntry);
-    if(o_it != anObjectMap.end()) {
+    ObjMap::ConstIterator o_it = anObjectMap.find( theEntry );
+    if ( o_it != anObjectMap.end() ) {
       const PropMap& aPropMap = o_it.value();
-      PropMap::ConstIterator p_it = aPropMap.find(thePropName);
-      if(p_it != aPropMap.end()) {
+      PropMap::ConstIterator p_it = aPropMap.find( thePropName );
+      if ( p_it != aPropMap.end() ) {
        aResult = p_it.value();
       }
     }
@@ -603,13 +576,38 @@ QVariant LightApp_Study::getObjectProperty(int theViewMgrId, QString theEntry, Q
 }
 
 /*!
-  Remove view manager with all objects.
-  \param theViewMgrId - Id of the viewer manager.
+  Set a visual property of the object for all registered viewers
+  \param theEntry - Entry of the object
+  \param thePropName - the name of the visual property
+  \param theValue - the value of the visual property
 */
-void LightApp_Study::removeViewMgr( int theViewMgrId ) { 
-  myViewMgrMap.remove(theViewMgrId);
+void LightApp_Study::setObjectProperty( const QString& theEntry,
+                                       const QString& thePropName,
+                                       const QVariant& theValue )
+{
+  const ViewMgrMap& vm = getObjectProperties();
+  ViewMgrMap::ConstIterator v_it;
+  for ( v_it = vm.begin(); v_it != vm.end(); ++v_it ) {
+    setObjectProperty( v_it.key(), theEntry, thePropName, theValue );
+  }
 }
 
+/*!
+  Set a visual property for all registered objects for given viewer
+  \param theViewMgrId - Id of the viewer manager.
+  \param thePropName - the name of the visual property
+  \param theValue - the value of the visual property
+*/
+void LightApp_Study::setObjectProperty( int theViewMgrId,
+                                       const QString& thePropName,
+                                       const QVariant& theValue )
+{
+  const ObjMap& om = getObjectProperties( theViewMgrId );
+  ObjMap::ConstIterator o_it;
+  for ( o_it = om.begin(); o_it != om.end(); ++o_it ) {
+    setObjectProperty( theViewMgrId, o_it.key(), thePropName, theValue );
+  }
+}
 
 /*!
   Get a map of the properties of the object identified by theViewMgrId and theEntry.
@@ -617,27 +615,18 @@ void LightApp_Study::removeViewMgr( int theViewMgrId ) {
   \param theEntry - Entry of the object.
   \return a map of the properties of the object.
 */
-const PropMap& LightApp_Study::getObjectPropMap(int theViewMgrId, QString theEntry) {
-  ViewMgrMap::Iterator v_it = myViewMgrMap.find(theViewMgrId);
-  if (v_it != myViewMgrMap.end()) {
-    ObjMap& anObjectMap = v_it.value();
-    ObjMap::Iterator o_it = anObjectMap.find(theEntry);
-    if(o_it != anObjectMap.end()) {
-      return o_it.value();
-    } else {
-      PropMap aPropMap;
-      anObjectMap.insert(theEntry, aPropMap);
-      return anObjectMap.find(theEntry).value();
-    }
-  } else {
-    PropMap aPropMap;
-    ObjMap anObjMap;
-    anObjMap.insert(theEntry,aPropMap);
-    myViewMgrMap.insert(theViewMgrId, anObjMap);
-
-    ObjMap& anObjectMap = myViewMgrMap.find(theViewMgrId).value();
-    return anObjectMap.find(theEntry).value();
-  }
+const PropMap& LightApp_Study::getObjectProperties( int theViewMgrId, const QString& theEntry )
+{
+  ViewMgrMap::Iterator v_it = myViewMgrMap.find( theViewMgrId );
+  if ( v_it == myViewMgrMap.end() )
+    v_it = myViewMgrMap.insert( theViewMgrId, ObjMap() );
+  
+  ObjMap& anObjectMap = v_it.value();
+  ObjMap::Iterator o_it = anObjectMap.find( theEntry );
+  if ( o_it == anObjectMap.end() )
+    o_it = anObjectMap.insert( theEntry, PropMap() );
+  
+  return o_it.value();
 }
 
 /*!
@@ -645,84 +634,85 @@ const PropMap& LightApp_Study::getObjectPropMap(int theViewMgrId, QString theEnt
   \param theViewMgrId - Id of the viewer manager.
   \param theEntry - Entry of the object.
 */
-void LightApp_Study::setObjectPropMap(int theViewMgrId, QString theEntry, PropMap thePropMap) {
-  //Try to find viewer manager in the map
-  ViewMgrMap::Iterator v_it = myViewMgrMap.find(theViewMgrId);
-  if(v_it == myViewMgrMap.end()) {
-    
-    //1) Create object map
-    ObjMap anObjMap;
-    anObjMap.insert(theEntry,thePropMap);
-
-    //3) Insert in the view manager map
-    myViewMgrMap.insert(theViewMgrId, anObjMap);
-  } else {
-    ObjMap& anObjMap = v_it.value();
-    anObjMap.insert(theEntry,thePropMap);
-  }
+void LightApp_Study::setObjectProperties( int theViewMgrId,
+                                         const QString& theEntry,
+                                         const PropMap& thePropMap )
+{
+  myViewMgrMap[theViewMgrId][theEntry] = thePropMap;
 }
 
+/*!
+  Remove view manager with all objects.
+  \param theViewMgrId - Id of the viewer manager.
+*/
+void LightApp_Study::removeObjectProperties( int theViewMgrId )
+{ 
+  myViewMgrMap.remove( theViewMgrId );
+}
+
+
 /*!
    Remove object's properties from all view managers.
   \param theEntry - Entry of the object.
 */
-void LightApp_Study::removeObjectFromAll( QString theEntry ) {
-  ViewMgrMap::Iterator v_it = myViewMgrMap.begin();
-  for( ;v_it != myViewMgrMap.end(); v_it++ ) {
-    v_it.value().remove(theEntry);
-  }
+void LightApp_Study::removeObjectProperties( const QString& theEntry )
+{
+  ViewMgrMap::Iterator v_it;
+  for ( v_it = myViewMgrMap.begin(); v_it != myViewMgrMap.end(); v_it++ )
+    v_it.value().remove( theEntry );
 }
 
 /*!
   Get all objects and it's properties from view manager identified by theViewMgrId.
   \param theEntry - Entry of the object.
 */
-const ObjMap& LightApp_Study::getObjectMap ( int theViewMgrId ) {
-  ViewMgrMap::Iterator v_it = myViewMgrMap.find(theViewMgrId);
-  if( v_it == myViewMgrMap.end() ) {
-    ObjMap anObjMap;
-    myViewMgrMap.insert(theViewMgrId , anObjMap);
-    return myViewMgrMap.find(theViewMgrId).value();
-  }
+const ObjMap& LightApp_Study::getObjectProperties( int theViewMgrId )
+{
+  ViewMgrMap::Iterator v_it = myViewMgrMap.find( theViewMgrId );
+  if ( v_it == myViewMgrMap.end() )
+    v_it = myViewMgrMap.insert( theViewMgrId, ObjMap() );
   return v_it.value();
 }
 
+/*!
+  Get global properties map
+*/
+const ViewMgrMap& LightApp_Study::getObjectProperties() const
+{
+  return myViewMgrMap;
+}
+
 /*!
   Set 'visibility state' property of the object.
   \param theEntry - Entry of the object.
   \param theState - visibility status
 */
-void LightApp_Study::setVisibilityState(const QString& theEntry, Qtx::VisibilityState theState) {
+void LightApp_Study::setVisibilityState( const QString& theEntry, Qtx::VisibilityState theState )
+ {
   LightApp_Application* app = (LightApp_Application*)application();
-  if(!app)
-    return;
+  if ( !app ) return;
   SUIT_DataBrowser* db = app->objectBrowser();
-  if(!db)
-    return;
-
-  SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>(db->model());
-  
-  if(treeModel)
-    treeModel->setVisibilityState(theEntry,theState);
+  if ( !db ) return;
+  SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( db->model() );
+  if ( treeModel ) {
+    treeModel->setVisibilityState( theEntry, theState );
+    emit objVisibilityChanged( theEntry, theState );
+  }
 }
 
 /*!
   Set 'visibility state' property for all object.
   \param theEntry - Entry of the object.
 */
-void LightApp_Study::setVisibilityStateForAll(Qtx::VisibilityState theState) {
-  
+void LightApp_Study::setVisibilityStateForAll( Qtx::VisibilityState theState )
+{
   LightApp_Application* app = (LightApp_Application*)application();
-  if(!app)
-    return;
+  if ( !app ) return;
   SUIT_DataBrowser* db = app->objectBrowser();
-  if(!db)
-    return;
-
-  SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>(db->model());
-  
-  if(treeModel)
-    treeModel->setVisibilityStateForAll(theState);
+  if ( !db ) return;
+  SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( db->model() );
+  if ( treeModel )
+    treeModel->setVisibilityStateForAll( theState );
 }
 
 /*!
@@ -730,18 +720,19 @@ void LightApp_Study::setVisibilityStateForAll(Qtx::VisibilityState theState) {
   \param theEntry - Entry of the object.
   \return 'visibility state' property of the object.
 */
-Qtx::VisibilityState LightApp_Study::visibilityState(const QString& theEntry) const {
+Qtx::VisibilityState LightApp_Study::visibilityState( const QString& theEntry ) const
+{
+  Qtx::VisibilityState state = Qtx::UnpresentableState;
   LightApp_Application* app = (LightApp_Application*)application();
-  if(app) {
-    
+  if ( app ) {
     SUIT_DataBrowser* db = app->objectBrowser();
-    if(db) {
-      SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>(db->model());
-      if(treeModel)
-       return treeModel->visibilityState(theEntry);
+    if ( db ) {
+      SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( db->model() );
+      if ( treeModel )
+       state = treeModel->visibilityState( theEntry );
     }
   }
-  return Qtx::UnpresentableState;
+  return state;
 }
 
 /*!