Salome HOME
An additional fix for the issue 2861 : Can't use a parameter created on the fly in...
[modules/shaper.git] / src / Model / Model_Document.cpp
index 6ba5fd91083871e1491d79a6bcb0b1373d330aab..bf42687a936f822b91ffd9299d6f6678d5a627d7 100755 (executable)
@@ -144,6 +144,7 @@ bool Model_Document::isRoot() const
   return this == Model_Session::get()->moduleDocument().get();
 }
 
+// LCOV_EXCL_START
 /// Makes all modification and generation naming shapes that have old shapes corresponding to
 /// shapes in a root document be equal to this root document
 static void updateShapesFromRoot(const TDF_Label theThisAccess, const TDF_Label theRootAccess)
@@ -219,6 +220,7 @@ static void updateShapesFromRoot(const TDF_Label theThisAccess, const TDF_Label
     }
   }
 }
+// LCOV_EXCL_STOP
 
 bool Model_Document::load(const char* theDirName, const char* theFileName, DocumentPtr theThis)
 {
@@ -238,6 +240,7 @@ bool Model_Document::load(const char* theDirName, const char* theFileName, Docum
   }
   bool isError = aStatus != PCDM_RS_OK;
   if (isError) {
+    // LCOV_EXCL_START
     switch (aStatus) {
       case PCDM_RS_UnknownDocument:
         Events_InfoMessage("Model_Document", "Can not open document").send();
@@ -292,6 +295,7 @@ bool Model_Document::load(const char* theDirName, const char* theFileName, Docum
         Events_InfoMessage("Model_Document", "Can not open document: unknown error").send();
         break;
     }
+    // LCOV_EXCL_STOP
   }
   std::shared_ptr<Model_Session> aSession =
     std::dynamic_pointer_cast<Model_Session>(Model_Session::get());
@@ -361,7 +365,10 @@ bool Model_Document::save(
   Handle(Model_Application) anApp = Model_Application::getApplication();
   if (isRoot()) {
 #ifdef WIN32
-    CreateDirectory((LPTSTR) theDirName, NULL);
+    size_t aDirLen = strlen(theDirName);
+    std::wstring aWStr(aDirLen, L'#');
+    mbstowcs(&aWStr[0], theDirName, aDirLen);
+    CreateDirectory(aWStr.c_str(), NULL);
 #else
     mkdir(theDirName, 0x1ff);
 #endif
@@ -667,10 +674,10 @@ bool Model_Document::finishOperation()
   }
   myObjs->synchronizeBackRefs();
   Events_Loop* aLoop = Events_Loop::loop();
-  static const Events_ID kCreatedEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED);
-  static const Events_ID kUpdatedEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
-  static const Events_ID kRedispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  static const Events_ID kDeletedEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED);
+  static const Events_ID kCreatedEvent = aLoop->eventByName(EVENT_OBJECT_CREATED);
+  static const Events_ID kUpdatedEvent = aLoop->eventByName(EVENT_OBJECT_UPDATED);
+  static const Events_ID kRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  static const Events_ID kDeletedEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
   aLoop->flush(kCreatedEvent);
   aLoop->flush(kUpdatedEvent);
   aLoop->flush(kRedispEvent);
@@ -949,7 +956,8 @@ void Model_Document::redo()
   // update the current features status
   setCurrentFeature(currentFeature(false), false);
 }
-
+// this is used for creation of undo/redo1-list by GUI
+// LCOV_EXCL_START
 std::list<std::string> Model_Document::undoList() const
 {
   std::list<std::string> aResult;
@@ -975,6 +983,7 @@ std::list<std::string> Model_Document::redoList() const
   }
   return aResult;
 }
+// LCOV_EXCL_STOP
 
 void Model_Document::operationId(const std::string& theId)
 {
@@ -1016,6 +1025,15 @@ FeaturePtr Model_Document::addFeature(std::string theID, const bool theMakeCurre
           aCurrent = aSub;
         }
       }
+      // #2861: if the parameter is added, add it after parameters existing in the list
+      if (aCurrent.get() &&
+          (aFeature->getKind() == "Parameter" || aFeature->getKind() == "ParametersMgr")) {
+        int anIndex = kUNDEFINED_FEATURE_INDEX;
+        for(FeaturePtr aNextFeat = myObjs->nextFeature(aCurrent, anIndex);
+            aNextFeat.get() && aNextFeat->getKind() == "Parameter";
+            aNextFeat = myObjs->nextFeature(aCurrent, anIndex))
+          aCurrent = aNextFeat;
+      }
     }
     aDocToAdd->myObjs->addFeature(aFeature, aCurrent);
     if (!aFeature->isAction()) {  // do not add action to the data model
@@ -1029,7 +1047,6 @@ FeaturePtr Model_Document::addFeature(std::string theID, const bool theMakeCurre
   return aFeature;
 }
 
-
 void Model_Document::refsToFeature(FeaturePtr theFeature,
   std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs, const bool isSendError)
 {
@@ -1040,7 +1057,7 @@ void Model_Document::removeFeature(FeaturePtr theFeature)
 {
   myObjs->removeFeature(theFeature);
   // fix for #2723: send signal that part is updated
-  if (!isRoot()) {
+  if (!isRoot() && isOperation()) {
     std::shared_ptr<Model_Document> aRoot =
       std::dynamic_pointer_cast<Model_Document>(ModelAPI_Session::get()->moduleDocument());
     std::list<ResultPtr> allParts;
@@ -1068,7 +1085,6 @@ static bool isSub(const CompositeFeaturePtr theMain, const FeaturePtr theSub) {
   return isSub(theMain, aParent);
 }
 
-
 void Model_Document::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
 {
   bool aCurrentUp = theMoved == currentFeature(false);
@@ -1454,7 +1470,6 @@ ResultPtr Model_Document::resultByLab(const TDF_Label& theLab)
   return ResultPtr(); // not found
 }
 
-
 void Model_Document::addNamingName(const TDF_Label theLabel, std::string theName)
 {
   std::map<std::string, std::list<TDF_Label> >::iterator aFind = myNamingNames.find(theName);
@@ -1510,7 +1525,7 @@ void Model_Document::changeNamingName(const std::string theOldName,
           Handle(TDataStd_Name) aSubName = Handle(TDataStd_Name)::DownCast(aChild.Value());
           std::string aName = TCollection_AsciiString(aSubName->Get()).ToCString();
           if (aName.find(theOldName) == 0) { // started from parent name
-            std::string aNewSubName = theNewName + aName.substr(theNewName.size());
+            std::string aNewSubName = theNewName + aName.substr(theOldName.size());
             changeNamingName(aName, aNewSubName, aSubName->Label());
             aSubName->Set(aNewSubName.c_str());
           }
@@ -1988,6 +2003,8 @@ bool Model_Document::isLater(FeaturePtr theLater, FeaturePtr theCurrent) const
   return myObjs->isLater(theLater, theCurrent);
 }
 
+// Object Browser nodes states
+// LCOV_EXCL_START
 void Model_Document::storeNodesState(const std::list<bool>& theStates)
 {
   TDF_Label aLab = generalLabel().FindChild(TAG_NODES_STATE);
@@ -2013,6 +2030,7 @@ void Model_Document::restoreNodesState(std::list<bool>& theStates) const
     }
   }
 }
+// LCOV_EXCL_STOP
 
 void Model_Document::eraseAllFeatures()
 {