]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Update the context search after the restore by name basing on TestFillEdgeVertex...
authormpv <mpv@opencascade.com>
Fri, 26 Oct 2018 08:21:24 +0000 (11:21 +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

index 6b008ce7ca9424675180a227a22cf8492801515c..20bdc6284432ee3b69eeed1da65f67534d4e3671 100644 (file)
@@ -188,8 +188,14 @@ bool Model_AttributeSelection::setValue(const ObjectPtr& theContext,
     if (aConstruction->isInfinite()) {
       // For correct naming selection, put the shape into the naming structure.
       // It seems sub-shapes are not needed: only this shape is (and can be) selected.
+      /*
       TNaming_Builder aBuilder(aSelLab);
       aBuilder.Generated(aConstruction->shape()->impl<TopoDS_Shape>());
+      std::string anInfinitiveName = contextName(aConstruction);
+      TDataStd_Name::Set(aSelLab, anInfinitiveName.c_str());
+      std::dynamic_pointer_cast<Model_Document>(owner()->document())
+        ->addNamingName(aSelLab, anInfinitiveName.c_str());
+        */
     }
   } else if (theContext->groupName() == ModelAPI_ResultPart::group()) {
     aSelLab.ForgetAllAttributes(true);
@@ -1022,8 +1028,11 @@ void Model_AttributeSelection::selectSubShape(
       if (aContext.get() && aContext->shape().get()) {
         TopoDS_Shape aContextShape = aContext->shape()->impl<TopoDS_Shape>();
         if (aSelector.solve(aContextShape)) {
+          TopoDS_Shape aSelectorShape = aSelector.value();
           GeomShapePtr aShapeToBeSelected(new GeomAPI_Shape);
-          aShapeToBeSelected->setImpl<TopoDS_Shape>(new TopoDS_Shape(aSelector.value()));
+          aShapeToBeSelected->setImpl<TopoDS_Shape>(new TopoDS_Shape(aSelectorShape));
+          // make the context result the latest existing
+          aContext = newestContext(aContext, aShapeToBeSelected);
           if (aCenterType != NOT_CENTER) {
             if (!aShapeToBeSelected->isEdge())
               continue;
@@ -1667,57 +1676,76 @@ bool Model_AttributeSelection::restoreContext(std::string theName,
     }
   }
 
-  /* to find the latest lower result that keeps given shape
+  if (aCont.get()) {
+    theContext = std::dynamic_pointer_cast<Model_Data>(aCont->data())->label();
+  }
+  return true;
+}
+
+bool Model_AttributeSelection::isLater(
+  const TDF_Label theResult1, const TDF_Label theResult2) const
+{
+  std::shared_ptr<Model_Document> aDoc = myRestoreDocument.get() ? myRestoreDocument :
+    std::dynamic_pointer_cast<Model_Document>(owner()->document());
+  FeaturePtr aFeat1 = aDoc->featureByLab(theResult1);
+  if (!aFeat1.get())
+    return false;
+  FeaturePtr aFeat2 = aDoc->featureByLab(theResult2);
+  if (!aFeat2.get())
+    return false;
+  return aDoc->isLaterByDep(aFeat1, aFeat2);
+}
+
+ResultPtr Model_AttributeSelection::newestContext(
+  const ResultPtr theCurrent, const GeomShapePtr theValue)
+{
+  ResultPtr aResult = theCurrent;
+  GeomShapePtr aSelectedShape = theValue.get() ? theValue : theCurrent->shape();
+  std::shared_ptr<Model_Document> aDoc =
+    std::dynamic_pointer_cast<Model_Document>(owner()->document());
   bool aFindNewContext = true;
-  while(aFindNewContext && aCont.get()) {
+  while (aFindNewContext && aResult.get()) {
     aFindNewContext = false;
     // try to find the last context to find the up to date shape
-    TopoDS_Shape aConShape = aCont->shape()->impl<TopoDS_Shape>();
+    TopoDS_Shape aConShape = aResult->shape()->impl<TopoDS_Shape>();
     Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aConShape, selectionLabel());
     if (!aNS.IsNull()) {
       aNS = TNaming_Tool::CurrentNamedShape(aNS);
-      if (!aNS.IsNull() && isOlderThanMe(aNS->Label())) { // scope check is for 2228
+      if (!aNS.IsNull() && isLater(selectionLabel(), aNS->Label()) &&
+          isLater(aNS->Label(), std::dynamic_pointer_cast<Model_Data>(aResult->data())->label())) {
         TDF_Label aLab = aNS->Label();
-        if (aLab.Depth() % 2 == 0)
-          aLab = aLab.Father();
-        ObjectPtr anObj = aDoc->objects()->object(aLab);
-        while (!anObj.get() && aLab.Depth() > 5) {
-          aLab = aLab.Father().Father();
-          anObj = aDoc->objects()->object(aLab);
-        }
-
-        if (anObj.get()) {
-          ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
-          if (aRes) {
-            aCont = aRes;
+        ResultPtr aRes = aDoc->resultByLab(aLab);
+        if (aRes.get()) {
+          if (aRes->shape()->isSubShape(aSelectedShape)) {
+            aResult = aRes;
             aFindNewContext = true;
+            continue;
           }
         }
       }
-    } else if (aCont->groupName() == ModelAPI_ResultBody::group()) {
+    }
+    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;
-      if (aCont->groupName() == ModelAPI_ResultBody::group()) {
-        ResultBodyPtr aCompBody = ModelAPI_Tools::bodyOwner(aCont, true);
-        if (aCompBody.get()) {
-          ModelAPI_Tools::allSubs(aCompBody, allRes);
-          allRes.push_back(aCompBody);
-          aCompContext = aCompBody;
-        }
+      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(aCont);
+        allRes.push_back(aResult);
 
-      for(std::list<ResultPtr>::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) {
+      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++) {
+        for (; !aFindNewContext && aRef != aRefs.end(); aRef++) {
           if (!aRef->get() || !(*aRef)->owner().get())
             continue;
           // concealed attribute only
@@ -1732,20 +1760,18 @@ bool Model_AttributeSelection::restoreContext(std::string theName,
           std::list<ResultPtr> aRefFeatResults;
           ModelAPI_Tools::allResults(aRefFeat, aRefFeatResults);
           std::list<ResultPtr>::iterator aRefResIter = aRefFeatResults.begin();
-          for(; aRefResIter != aRefFeatResults.end(); aRefResIter++) {
+          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++) {
+          for (; aResIter != aResults.end(); aResIter++) {
             if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled())
               continue;
             GeomShapePtr aShape = (*aResIter)->shape();
-            GeomShapePtr aSelectedShape =
-              aShapeToBeSelected.get() ? aShapeToBeSelected : aCont->shape();
             if (aShape.get() && aShape->isSubShape(aSelectedShape, false)) {
-              aCont = *aResIter; // found new context (produced from this) with same subshape
+              aResult = *aResIter; // found new context (produced from this) with same subshape
               aFindNewContext = true; // continue searching futher
               break;
             }
@@ -1755,7 +1781,7 @@ bool Model_AttributeSelection::restoreContext(std::string theName,
     }
   }
   // if compsolid is context, try to take sub-solid as context: like in GUI and scripts
-  ResultBodyPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aCont);
+  ResultBodyPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
   if (aComp && aComp->numberOfSubs()) {
     std::list<ResultPtr> allSubs;
     ModelAPI_Tools::allSubs(aComp, allSubs);
@@ -1763,29 +1789,11 @@ bool Model_AttributeSelection::restoreContext(std::string theName,
     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(aShapeToBeSelected)) {
-        aCont = aSub;
+        aSub->shape()->isSubShape(aSelectedShape)) {
+        aResult = aSub;
         break;
       }
     }
   }
-  */
-  if (aCont.get()) {
-    theContext = std::dynamic_pointer_cast<Model_Data>(aCont->data())->label();
-  }
-  return true;
-}
-
-bool Model_AttributeSelection::isLater(
-  const TDF_Label theResult1, const TDF_Label theResult2) const
-{
-  std::shared_ptr<Model_Document> aDoc = myRestoreDocument.get() ? myRestoreDocument :
-    std::dynamic_pointer_cast<Model_Document>(owner()->document());
-  FeaturePtr aFeat1 = aDoc->featureByLab(theResult1);
-  if (!aFeat1.get())
-    return false;
-  FeaturePtr aFeat2 = aDoc->featureByLab(theResult2);
-  if (!aFeat2.get())
-    return false;
-  return aDoc->isLaterByDep(aFeat1, aFeat2);
+  return aResult;
 }
index 4c8f09f2a15d09008c2fa43e28a012b9b971adaf..8f692da98abd2c99a951d90fe4ab83222c7eb37a 100644 (file)
@@ -188,6 +188,10 @@ protected:
                         ResultPtr theContext, TopoDS_Shape theValShape, TDF_Label theAccessLabel,
                         std::list<ResultPtr>& theResults, TopTools_ListOfShape& theValShapes);
 
+  /// Searches for the newest context, modification of the current, that contains theValue
+  ResultPtr newestContext(const ResultPtr theCurrent,
+    const std::shared_ptr<GeomAPI_Shape> theValue);
+
   /// computes theShapes list - shapes that were generated/modified/deleted the theValShape
   /// during creation from new to old context
   void computeValues(ResultPtr theOldContext, ResultPtr theNewContext, TopoDS_Shape theValShape,