Salome HOME
Copyright update 2021
[modules/gui.git] / src / SalomeApp / SalomeApp_Study.cxx
index e3ffd5930affd756863e106830eab4c72bd55a57..e99b38d0515d92c6a6c466d13e1a81540f311800 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  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
@@ -154,7 +154,7 @@ public:
           SalomeApp_DataObject* aFatherDO = it->second;
 
           it = entry2SuitObject.find(theID);
-          if (it != entry2SuitObject.end()) { // this SOobject is already added somethere
+          if (it != entry2SuitObject.end()) { // this SOobject is already added somewhere
             suit_obj = it->second;
             SUIT_DataObject* oldFather = suit_obj->parent();
             if (oldFather) {
@@ -181,15 +181,7 @@ public:
 
           suit_obj->updateItem();
           // define position in the data tree (in aFatherDO) to insert the aSObj
-          int pos = -1;
-          //int childDataObjCount = aFatherDO->childCount();
-          _PTR(UseCaseIterator) aUseCaseIter = aUseCaseBuilder->GetUseCaseIterator(aFatherSO);
-          for (int cur = 0; aUseCaseIter->More() && pos < 0; cur++, aUseCaseIter->Next()) {
-            if (aUseCaseIter->Value()->GetID() == theID) {
-              pos = cur;
-              break;
-            }
-          }
+          int pos = aUseCaseBuilder->GetIndexInFather(aFatherSO, aSObj);
 
           aFatherDO->insertChildAtPos(suit_obj, pos);
           //aFatherDO->insertChild(suit_obj, pos);
@@ -198,17 +190,16 @@ public:
           /* Define visibility state */
           bool isComponent = dynamic_cast<SalomeApp_ModuleObject*>( suit_obj ) != 0;
           if ( suit_obj && !isComponent && myStudy->visibilityState( theID.c_str() ) == Qtx::UnpresentableState ) {
-            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 ); //hide the just added object
-                  //MESSAGE("Object with entry : "<< theID <<" CAN be displayed !!!");
-                }
-                //else
-                  //MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!");
+            LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer
+              (suit_obj->componentDataType(),false);
+            if (aDisplayer) {
+              if (aDisplayer->canBeDisplayed(theID.c_str())) {
+                //hide the just added object
+                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
@@ -219,7 +210,7 @@ public:
             return;
           }
 
-          int last2Pnt_pos = theID.rfind( ":" );
+          int last2Pnt_pos = (int)theID.rfind( ":" ); //!< TODO: conversion from size_t to int
           std::string parent_id = theID.substr( 0, last2Pnt_pos );
           int tag = atoi( theID.substr( last2Pnt_pos+1 ).c_str() );
 
@@ -331,17 +322,15 @@ public:
         /* 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 !!!");
+          LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer
+            (suit_obj->componentDataType(),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 !!!");
           }
         }
         break;
@@ -373,7 +362,7 @@ private:
         // parse the children
         o = o->firstChild();
       }
-      else if ( o->nextBrother() > 0 ) {
+      else if ( o->nextBrother() ) {
         o = o->nextBrother();
       }
       else {
@@ -625,7 +614,7 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
       aModel->saveAs( theFileName, this, listOfFiles );
       if ( !listOfFiles.isEmpty() )
         saveModuleData(aModel->module()->name(), 0, // 0 means persistence file
-                      listOfFiles);
+                       listOfFiles);
     }
   }
 
@@ -669,7 +658,7 @@ bool SalomeApp_Study::saveDocument()
       aModel->save(listOfFiles);
       if ( !listOfFiles.isEmpty() )
         saveModuleData(aModel->module()->name(), 0, // 0 means persistence file
-                      listOfFiles);
+                       listOfFiles);
     }
   }
 
@@ -732,7 +721,7 @@ bool SalomeApp_Study::dump( const QString& theFileName,
                             bool isMultiFile,
                             bool toSaveGUI )
 {
-  int savePoint;
+  int savePoint = 0;
   _PTR(AttributeParameter) ap;
   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
 
@@ -764,7 +753,7 @@ bool SalomeApp_Study::dump( const QString& theFileName,
         // This code is shared with persistence mechanism.
         // NOTE: this should be revised if behavior of saveModuleData() changes!
         saveModuleData(aModel->module()->name(), 1, // 1 means dump file
-                      listOfFiles);
+                       listOfFiles);
     }
   }
 
@@ -850,7 +839,7 @@ void SalomeApp_Study::openModuleData( QString theModuleName, int type, QStringLi
 {
   std::vector<std::string> aListOfFiles = GetListOfFiles( theModuleName.toStdString().c_str(), type );
 
-  int i, aLength = aListOfFiles.size() - 1;
+  int i, aLength = (int)aListOfFiles.size() - 1; //!< TODO: conversion from size_t to int
   if ( aLength < 0 )
     return;
 
@@ -865,7 +854,7 @@ void SalomeApp_Study::openModuleData( QString theModuleName, int type, QStringLi
   Re-implemented from LightApp_Study, actually does not save anything but
   simply cleans up light modules' data
 */
-bool SalomeApp_Study::saveStudyData( const QString& theFileName, int type )
+bool SalomeApp_Study::saveStudyData( const QString& /*theFileName*/, int type )
 {
   ModelList list; dataModels( list );
   QListIterator<CAM_DataModel*> it( list );
@@ -1042,14 +1031,14 @@ bool SalomeApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm
   }
   QStringList listOfFiles;
   openModuleData(dm->module()->name(), 0, // 0 means persistence file
-                listOfFiles);
+                 listOfFiles);
   if (dm && dm->open(studyName, this, listOfFiles)) {
     // Remove the files and temporary directory, created
     // for this module by LightApp_Engine_i::Load()
     bool isMultiFile = false; // TODO: decide, how to access this parameter
     RemoveTemporaryFiles( dm->module()->name().toStdString().c_str(), isMultiFile, true );
     SetListOfFiles( dm->module()->name().toStdString().c_str(), 0, // 0 means persistence file
-                   std::vector<std::string>() );
+                    std::vector<std::string>() );
 
     // Something has been read -> create data model tree
     LightApp_DataModel* aDM = dynamic_cast<LightApp_DataModel*>( dm );
@@ -1116,14 +1105,14 @@ void SalomeApp_Study::RemoveTemporaryFiles ( const char* theModuleName, bool isM
   if (aListOfFiles.size() > 0) {
     std::string aTmpDir = aListOfFiles[0];
 
-    const int n = aListOfFiles.size() - 1;
+    const int n = (int)aListOfFiles.size() - 1; //!< TODO: conversion from size_t to int
     std::vector<std::string> aSeq;
     aSeq.reserve(n);
     for (int i = 0; i < n; i++)
       aSeq.push_back(CORBA::string_dup(aListOfFiles[i + 1].c_str()));
 
     SalomeApp_Engine_i* engine = SalomeApp_Engine_i::GetInstance( theModuleName, false );
-    bool toRemove = force || engine && !engine->keepFiles();
+    bool toRemove = force || ( engine && !engine->keepFiles() );
 
     if ( toRemove ) {
       SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq, true);
@@ -1165,7 +1154,7 @@ void SalomeApp_Study::deleteReferencesTo( _PTR( SObject ) obj )
 {
   _PTR(StudyBuilder) sb = studyDS()->NewBuilder();
   std::vector<_PTR(SObject)> aRefs = studyDS()->FindDependances( obj );
-  for( int i=0, n=aRefs.size(); i<n; i++ )
+  for( size_t i=0, n=aRefs.size(); i<n; i++ )
   {
     _PTR( SObject ) o = aRefs[i];
     if( o->GetFatherComponent()->ComponentDataType()==obj->GetFatherComponent()->ComponentDataType() )