Salome HOME
Fix for TestFillWireVertex.py : take the latest context for the filter by neighbors
authormpv <mpv@opencascade.com>
Fri, 26 Oct 2018 14:23:58 +0000 (17:23 +0300)
committermpv <mpv@opencascade.com>
Mon, 19 Nov 2018 08:45:52 +0000 (11:45 +0300)
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/Model/Model_Document.cpp
src/Selector/Selector_NameGenerator.h
src/Selector/Selector_Selector.cpp

index 20bdc6284432ee3b69eeed1da65f67534d4e3671..b3357626fea9c932f7f7aa20eb90def166dc762a 100644 (file)
@@ -1682,6 +1682,18 @@ bool Model_AttributeSelection::restoreContext(std::string theName,
   return true;
 }
 
+TDF_Label Model_AttributeSelection::newestContext(const TDF_Label theCurrentContext) {
+  std::shared_ptr<Model_Document> aDoc = myRestoreDocument.get() ? myRestoreDocument :
+    std::dynamic_pointer_cast<Model_Document>(owner()->document());
+  ResultPtr aContext = aDoc->resultByLab(theCurrentContext);
+  if (aContext.get()) {
+    aContext = newestContext(aContext, GeomShapePtr(), true);
+    if (aContext.get())
+      return std::dynamic_pointer_cast<Model_Data>(aContext->data())->label();
+  }
+  return theCurrentContext; // nothing is changed
+}
+
 bool Model_AttributeSelection::isLater(
   const TDF_Label theResult1, const TDF_Label theResult2) const
 {
@@ -1697,7 +1709,7 @@ bool Model_AttributeSelection::isLater(
 }
 
 ResultPtr Model_AttributeSelection::newestContext(
-  const ResultPtr theCurrent, const GeomShapePtr theValue)
+  const ResultPtr theCurrent, const GeomShapePtr theValue, const bool theAnyValue)
 {
   ResultPtr aResult = theCurrent;
   GeomShapePtr aSelectedShape = theValue.get() ? theValue : theCurrent->shape();
@@ -1716,7 +1728,7 @@ ResultPtr Model_AttributeSelection::newestContext(
         TDF_Label aLab = aNS->Label();
         ResultPtr aRes = aDoc->resultByLab(aLab);
         if (aRes.get()) {
-          if (aRes->shape()->isSubShape(aSelectedShape)) {
+          if (theAnyValue || aRes->shape()->isSubShape(aSelectedShape)) {
             aResult = aRes;
             aFindNewContext = true;
             continue;
@@ -1724,57 +1736,57 @@ ResultPtr Model_AttributeSelection::newestContext(
         }
       }
     }
-    if (aResult->groupName() == ModelAPI_ResultBody::group()) {
+    // TestFillWireVertex.py - sketch constructions for wire may participate too
+    //if (aResult->groupName() == ModelAPI_ResultBody::group()) {
       // try to search newer context by the concealment references
       // take references to all results: root one, any sub
-      std::list<ResultPtr> allRes;
-      ResultPtr aCompContext;
-      ResultBodyPtr aCompBody = ModelAPI_Tools::bodyOwner(aResult, true);
-      if (aCompBody.get()) {
-        ModelAPI_Tools::allSubs(aCompBody, allRes);
-        allRes.push_back(aCompBody);
-        aCompContext = aCompBody;
-      }
-      if (allRes.empty())
-        allRes.push_back(aResult);
-
-      for (std::list<ResultPtr>::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) {
-        ResultPtr aResCont = *aSub;
-        ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResCont);
-        if (aResBody.get() && aResBody->numberOfSubs() > 0 && aResBody != aCompContext)
-          continue; // only lower and higher level subs are counted
-        const std::set<AttributePtr>& aRefs = aResCont->data()->refsToMe();
-        std::set<AttributePtr>::const_iterator aRef = aRefs.begin();
-        for (; !aFindNewContext && aRef != aRefs.end(); aRef++) {
-          if (!aRef->get() || !(*aRef)->owner().get())
-            continue;
-          // concealed attribute only
-          FeaturePtr aRefFeat = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRef)->owner());
-          if (!ModelAPI_Session::get()->validators()->isConcealed(
-            aRefFeat->getKind(), (*aRef)->id()))
+    std::list<ResultPtr> allRes;
+    ResultPtr aCompContext;
+    ResultBodyPtr aCompBody = ModelAPI_Tools::bodyOwner(aResult, true);
+    if (aCompBody.get()) {
+      ModelAPI_Tools::allSubs(aCompBody, allRes);
+      allRes.push_back(aCompBody);
+      aCompContext = aCompBody;
+    }
+    if (allRes.empty())
+      allRes.push_back(aResult);
+
+    for (std::list<ResultPtr>::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) {
+      ResultPtr aResCont = *aSub;
+      ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResCont);
+      if (aResBody.get() && aResBody->numberOfSubs() > 0 && aResBody != aCompContext)
+        continue; // only lower and higher level subs are counted
+      const std::set<AttributePtr>& aRefs = aResCont->data()->refsToMe();
+      std::set<AttributePtr>::const_iterator aRef = aRefs.begin();
+      for (; !aFindNewContext && aRef != aRefs.end(); aRef++) {
+        if (!aRef->get() || !(*aRef)->owner().get())
+          continue;
+        // concealed attribute only
+        FeaturePtr aRefFeat = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRef)->owner());
+        if (!ModelAPI_Session::get()->validators()->isConcealed(
+          aRefFeat->getKind(), (*aRef)->id()))
+          continue;
+        // search the feature result that contains sub-shape selected
+        std::list<std::shared_ptr<ModelAPI_Result> > aResults;
+
+        // take all sub-results or one result
+        std::list<ResultPtr> aRefFeatResults;
+        ModelAPI_Tools::allResults(aRefFeat, aRefFeatResults);
+        std::list<ResultPtr>::iterator aRefResIter = aRefFeatResults.begin();
+        for (; aRefResIter != aRefFeatResults.end(); aRefResIter++) {
+          ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRefResIter);
+          if (aBody.get() && aBody->numberOfSubs() == 0) // add only lower level subs
+            aResults.push_back(aBody);
+        }
+        std::list<std::shared_ptr<ModelAPI_Result> >::iterator aResIter = aResults.begin();
+        for (; aResIter != aResults.end(); aResIter++) {
+          if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled())
             continue;
-          // search the feature result that contains sub-shape selected
-          std::list<std::shared_ptr<ModelAPI_Result> > aResults;
-
-          // take all sub-results or one result
-          std::list<ResultPtr> aRefFeatResults;
-          ModelAPI_Tools::allResults(aRefFeat, aRefFeatResults);
-          std::list<ResultPtr>::iterator aRefResIter = aRefFeatResults.begin();
-          for (; aRefResIter != aRefFeatResults.end(); aRefResIter++) {
-            ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRefResIter);
-            if (aBody.get() && aBody->numberOfSubs() == 0) // add only lower level subs
-              aResults.push_back(aBody);
-          }
-          std::list<std::shared_ptr<ModelAPI_Result> >::iterator aResIter = aResults.begin();
-          for (; aResIter != aResults.end(); aResIter++) {
-            if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled())
-              continue;
-            GeomShapePtr aShape = (*aResIter)->shape();
-            if (aShape.get() && aShape->isSubShape(aSelectedShape, false)) {
-              aResult = *aResIter; // found new context (produced from this) with same subshape
-              aFindNewContext = true; // continue searching futher
-              break;
-            }
+          GeomShapePtr aShape = (*aResIter)->shape();
+          if (aShape.get() && (theAnyValue || aShape->isSubShape(aSelectedShape, false))) {
+            aResult = *aResIter; // found new context (produced from this) with same subshape
+            aFindNewContext = true; // continue searching futher
+            break;
           }
         }
       }
@@ -1789,11 +1801,15 @@ ResultPtr Model_AttributeSelection::newestContext(
     for (; aS != allSubs.end(); aS++) {
       ResultBodyPtr aSub = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aS);
       if (aSub && aSub->numberOfSubs() == 0 && aSub->shape().get() &&
-        aSub->shape()->isSubShape(aSelectedShape)) {
+        (theAnyValue || aSub->shape()->isSubShape(aSelectedShape))) {
         aResult = aSub;
         break;
       }
     }
   }
+  // in case sketch line was selected for wire, but wire was concealed and not such line anymore,
+  // so, actually, the sketch element was selected (which is never concealed)
+  if (aResult != theCurrent && aResult->isConcealed())
+    aResult = theCurrent;
   return aResult;
 }
index 8f692da98abd2c99a951d90fe4ab83222c7eb37a..62a3e09afb7e7f9b073e29f633fcc523c7bc758c 100644 (file)
@@ -137,6 +137,9 @@ public:
   MODEL_EXPORT virtual bool restoreContext(std::string theName,
     TDF_Label& theContext, TDF_Label& theValue) override;
 
+  /// Returns the label of the newest context presented by the current one
+  MODEL_EXPORT virtual TDF_Label newestContext(const TDF_Label theCurrentContext) override;
+
   /// Returns true if the first result is newer than the second one in the tree of features
   MODEL_EXPORT virtual bool isLater(const TDF_Label theResult1, const TDF_Label theResult2)
     const override;
@@ -190,7 +193,7 @@ protected:
 
   /// Searches for the newest context, modification of the current, that contains theValue
   ResultPtr newestContext(const ResultPtr theCurrent,
-    const std::shared_ptr<GeomAPI_Shape> theValue);
+    const std::shared_ptr<GeomAPI_Shape> theValue, const bool theAnyValue = false);
 
   /// computes theShapes list - shapes that were generated/modified/deleted the theValShape
   /// during creation from new to old context
index 6fc16f5cfbf48c6fa435d55f73fa067cc434b2bd..4d4207648740649aec6d7da1fdad57830da3701d 100755 (executable)
@@ -1000,12 +1000,14 @@ void Model_Document::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
 
 void Model_Document::updateHistory(const std::shared_ptr<ModelAPI_Object> theObject)
 {
-  myObjs->updateHistory(theObject);
+  if (myObjs)
+    myObjs->updateHistory(theObject);
 }
 
 void Model_Document::updateHistory(const std::string theGroup)
 {
-  myObjs->updateHistory(theGroup);
+  if (myObjs)
+    myObjs->updateHistory(theGroup);
 }
 
 const std::set<int> Model_Document::subDocuments() const
index 4a06abc072e8adec7a1dcfff2496a78392cfdbc5..6ac0f4ce471d440571b2f1320e9b2d0fab9cb40f 100644 (file)
@@ -47,6 +47,9 @@ public:
 
   /// Returns true if the first result is older than the second one in the tree of features
   virtual bool isLater(const TDF_Label theResult1, const TDF_Label theResult2) const = 0;
+
+  /// Returns the label of the newest context presented by the current one
+  virtual TDF_Label newestContext(const TDF_Label theCurrentContext) = 0;
 };
 
 #endif
index 8fe3532efd234043835bc6c82b5a892427b0683e..0347c136018235539cf09a63428fc06e8a183c04 100644 (file)
@@ -1032,6 +1032,9 @@ TDF_Label Selector_Selector::restoreByName(
         } else {
           aContext = aSubContext;
         }
+        if (!aContext.IsNull()) // for filters by neighbour the latest context shape is vital
+          aContext = theNameGenerator->newestContext(aContext);
+
         // searching for the level index
         std::string aLevel;
         for(anEndPos++; anEndPos != std::string::npos &&