]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
For the issue #1156 : do not cause Placement error on activation of previous Part...
authormpv <mpv@opencascade.com>
Tue, 22 Dec 2015 14:08:00 +0000 (17:08 +0300)
committermpv <mpv@opencascade.com>
Tue, 22 Dec 2015 14:08:00 +0000 (17:08 +0300)
src/Model/Model_Document.cpp
src/Model/Model_ResultPart.cpp
src/Model/Model_Session.cpp
src/ModelAPI/ModelAPI_Tools.cpp
src/ModelAPI/ModelAPI_Tools.h

index c38a70f539def2dbfc863e351739a696681ce0b8..ec071b40300a35ca2d586f902764a204002897ed 100755 (executable)
@@ -870,6 +870,8 @@ const int Model_Document::index(std::shared_ptr<ModelAPI_Object> theObject)
 
 int Model_Document::size(const std::string& theGroupID)
 {
+  if (myObjs == 0) // may be on close
+    return 0;
   return myObjs->size(theGroupID);
 }
 
index 431576afbacd1cd57096b850b45cfa445ec24f25..772cbb3849b3affa7f4059dc56ae94a6e637aee5 100644 (file)
@@ -97,6 +97,8 @@ std::shared_ptr<ModelAPI_ResultPart> Model_ResultPart::original()
 bool Model_ResultPart::isActivated() 
 {
   if (myTrsf.get()) {
+    if (!baseRef().get()) // may be on close
+      return false;
     return baseRef()->isActivated();
   }
 
index 4f95c72cc7cefdf0934e46a8ad4e3997730344b9..1bb0cebd23c67c73a3582fad03128e2750f1945b 100644 (file)
@@ -252,6 +252,18 @@ void Model_Session::setActiveDocument(
     std::shared_ptr<ModelAPI_Document> aPrevious = myCurrentDoc;
     myCurrentDoc = theDoc;
     if (theDoc.get() && theSendSignal) {
+      // this must be before the synchronisation call because features in PartSet lower than this
+      // part feature must be disabled and don't recomputed anymore (issue 1156,
+      // translation feature is failed on activation of Part 2)
+      if (isOperation()) { // do it only in transaction, not on opening of document
+        DocumentPtr aRoot = moduleDocument();
+        if (myCurrentDoc != aRoot) {
+          FeaturePtr aPartFeat = ModelAPI_Tools::findPartFeature(aRoot, myCurrentDoc);
+          if (aPartFeat.get()) {
+            aRoot->setCurrentFeature(aPartFeat, false);
+          }
+        }
+      }
       // syncronize the document: it may be just opened or opened but removed before
       std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(theDoc);
       if (aDoc.get()) {
@@ -275,14 +287,6 @@ void Model_Session::setActiveDocument(
       } else {
         // make the current feature the latest in sub, root current feature becomes this sub
         makeCurrentLast(myCurrentDoc);
-        DocumentPtr aRoot = moduleDocument();
-        ResultPtr aPartRes = ModelAPI_Tools::findPartResult(aRoot, myCurrentDoc);
-        if (aPartRes.get()) {
-          FeaturePtr aPartFeat = aRoot->feature(aPartRes);
-          if (aPartFeat.get()) {
-            aRoot->setCurrentFeature(aPartFeat, false);
-          }
-        }
       }
     }
   }
index 442549557bf197ce3b4a1b03ca13d292793b48d0..1b618562d6e8c10dc3b3c6daa61a59574a8fbc0e 100755 (executable)
@@ -209,6 +209,28 @@ ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub)
   return ResultPtr();
 }
 
+FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub)
+{
+  if (theMain != theSub) { // to optimize and avoid of crash on partset document close (don't touch the sub-document structure)
+    for (int a = theMain->size(ModelAPI_Feature::group()) - 1; a >= 0; a--) {
+      FeaturePtr aPartFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(
+          theMain->object(ModelAPI_Feature::group(), a));
+      if (aPartFeat.get()) {
+        const std::list<std::shared_ptr<ModelAPI_Result> >& aResList = aPartFeat->results();
+        std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResList.begin();
+        for(; aRes != aResList.end(); aRes++) {
+          ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes);
+          if (aPart.get()) {
+            if (aPart->isActivated() && aPart->partDoc() == theSub)
+              return aPartFeat;
+          } else break; // if the first is not Part, others are also not
+        }
+      }
+    }
+  }
+  return FeaturePtr();
+}
+
 CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature)
 {
   if (theFeature.get() && theFeature->data()->isValid()) {
index 0b3f965b7f19ea7c6360bc147a207d45eb98e733..1d86a03cc038880cfa3668b4f8edc61dd45fce7c 100755 (executable)
@@ -53,12 +53,22 @@ MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues);
 
 /*!
  * Searches for Part result that contains the reference to the given document.
+ * The result must be presented in the tree.
  * \param theMain document that contains the searched feature
  * \param theSub document that is searched, the resulting feature references to it
  * \returns null if not found
  */
 MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub);
 
+/*!
+ * Searches for Part the feature that contains in result the reference to the given document.
+ * The result may be disabled.
+ * \param theMain document that contains the searched feature
+ * \param theSub document that is searched, the resulting feature references to it
+ * \returns null if not found
+ */
+MODELAPI_EXPORT FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub);
+
 /*!
  * Returns the composite feature - parent of this feature.
  * \param theFeature the sub-element of composite