Salome HOME
Simplification of environment due to SALOME standards
[modules/shaper.git] / src / Model / Model_Document.cpp
index 09469b85b193fad9c22f712243d6d6d4719b6e5d..b0960472f2ff5245bfc33c80606c6420c028aaa4 100755 (executable)
@@ -621,7 +621,7 @@ void Model_Document::abortOperation()
   for (; aSubIter != aSubs.end(); aSubIter++)
     subDoc(*aSubIter)->abortOperation();
   // references may be changed because they are set in attributes on the fly
-  myObjs->synchronizeFeatures(aDeltaLabels, true, isRoot());
+  myObjs->synchronizeFeatures(aDeltaLabels, true, false, isRoot());
 }
 
 bool Model_Document::isOperation() const
@@ -687,7 +687,7 @@ void Model_Document::undoInternal(const bool theWithSubs, const bool theSynchron
   }
   // after undo of all sub-documents to avoid updates on not-modified data (issue 370)
   if (theSynchronize) {
-    myObjs->synchronizeFeatures(aDeltaLabels, true, isRoot());
+    myObjs->synchronizeFeatures(aDeltaLabels, true, false, isRoot());
     // update the current features status
     setCurrentFeature(currentFeature(false), false);
   }
@@ -734,7 +734,7 @@ void Model_Document::redo()
     subDoc(*aSubIter)->redo();
 
   // after redo of all sub-documents to avoid updates on not-modified data (issue 370)
-  myObjs->synchronizeFeatures(aDeltaLabels, true, isRoot());
+  myObjs->synchronizeFeatures(aDeltaLabels, true, false, isRoot());
   // update the current features status
   setCurrentFeature(currentFeature(false), false);
 }
@@ -832,9 +832,18 @@ void Model_Document::removeFeature(FeaturePtr theFeature)
 
 void Model_Document::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
 {
+  bool aCurrentUp = theMoved == currentFeature(false);
+  if (aCurrentUp) {
+    setCurrentFeatureUp();
+  }
+
   myObjs->moveFeature(theMoved, theAfterThis);
-  if (theAfterThis == currentFeature(true))
+  if (aCurrentUp) { // make the moved feature enabled or disabled due to the real status
+    setCurrentFeature(currentFeature(false), false);
+  } else if (theAfterThis == currentFeature(false)) {
+    // must be after move to make enabled all features which are before theMoved
     setCurrentFeature(theMoved, true);
+  }
 }
 
 void Model_Document::updateHistory(const std::shared_ptr<ModelAPI_Object> theObject)
@@ -945,7 +954,7 @@ void Model_Document::setCurrentFeature(
     }
   }
 
-  if (theVisible) { // make features below which are not in history also enabled: sketch subs
+  if (theVisible && !theCurrent.get()) { // needed to avoid disabling of PartSet initial constructions
     FeaturePtr aNext = 
       theCurrent.get() ? myObjs->nextFeature(theCurrent) : myObjs->firstFeature();
     for (; aNext.get(); aNext = myObjs->nextFeature(theCurrent)) {
@@ -975,8 +984,6 @@ void Model_Document::setCurrentFeature(
   }
   // make all features after this feature disabled in reversed order (to remove results without deps)
   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  static Events_ID aCreateEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
-  static Events_ID aDeleteEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
 
   bool aPassed = false; // flag that the current object is already passed in cycle
   FeaturePtr anIter = myObjs->lastFeature();
@@ -1036,6 +1043,12 @@ void Model_Document::setCurrentFeatureUp()
   FeaturePtr aCurrent = currentFeature(false);
   if (aCurrent.get()) { // if not, do nothing because null is the upper
     FeaturePtr aPrev = myObjs->nextFeature(aCurrent, true);
+    // make the higher level composite as current (sketch becomes disabled if line is enabled)
+    if (aPrev.get()) {
+      for(FeaturePtr aComp = ModelAPI_Tools::compositeOwner(aPrev); aComp.get();
+        aComp = ModelAPI_Tools::compositeOwner(aPrev))
+          aPrev = aComp;
+    }
     // do not flush: it is called only on remove, it will be flushed in the end of transaction
     setCurrentFeature(aPrev, false);
   }
@@ -1286,6 +1299,15 @@ std::shared_ptr<ModelAPI_Feature> Model_Document::producedByFeature(
   if (aShape.IsNull())
     return FeaturePtr();
 
+  // for comsolids and compounds all the naming is located in the main object, so, try to use
+  // it first
+  ResultCompSolidPtr aMain = ModelAPI_Tools::compSolidOwner(theResult);
+  if (aMain.get()) {
+    FeaturePtr aMainRes = producedByFeature(aMain, theShape);
+    if (aMainRes)
+      return aMainRes;
+  }
+
   std::shared_ptr<Model_Data> aBodyData = std::dynamic_pointer_cast<Model_Data>(theResult->data());
   if (!aBodyData.get() || !aBodyData->isValid())
     return FeaturePtr();
@@ -1295,8 +1317,8 @@ std::shared_ptr<ModelAPI_Feature> Model_Document::producedByFeature(
   Handle(TNaming_NamedShape) aCandidatInThis, aCandidatContainer;
   TDF_Label aBodyLab = aBodyData->label();
   // use childs and this label (the lowest priority)
-  bool aUseThis = false;
   TDF_ChildIDIterator aNSIter(aBodyLab, TNaming_NamedShape::GetID(), Standard_True);
+  bool aUseThis = !aNSIter.More();
   while(anOldShape.IsNull() && (aNSIter.More() || aUseThis)) {
     Handle(TNaming_NamedShape) aNS;
     if (aUseThis) {
@@ -1376,3 +1398,8 @@ std::shared_ptr<ModelAPI_Feature> Model_Document::producedByFeature(
   }
   return aResult;
 }
+
+bool Model_Document::isLater(FeaturePtr theLater, FeaturePtr theCurrent) const
+{
+  return myObjs->isLater(theLater, theCurrent);
+}