]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for the issue #1682 and the problem of selection of planes for partition in test...
authormpv <mpv@opencascade.com>
Fri, 2 Sep 2016 17:40:18 +0000 (20:40 +0300)
committermpv <mpv@opencascade.com>
Fri, 2 Sep 2016 17:40:18 +0000 (20:40 +0300)
src/FeaturesPlugin/FeaturesPlugin_Recover.cpp
src/Model/Model_AttributeSelection.cpp
src/Model/Model_SelectionNaming.cpp
src/Model/Model_SelectionNaming.h

index cb54944eb37a38cdd07b392e60e29df290fcc898..54f3bbdcf298de73d1520ff69abda5abdea6f0fc 100644 (file)
@@ -29,9 +29,6 @@ void FeaturesPlugin_Recover::initAttributes()
   data()->addAttribute(PERSISTENT(), ModelAPI_AttributeBoolean::typeId());
 
   myPersistent = boolean(PERSISTENT())->value();
-  // temporary modification for empty list
-  // ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), RECOVERED_ENTITIES());
-
   synchronizeRegistered();
 }
 
index 7f8710c9e0362648e4124e64850c4cf81c2ea925..3a9d350c7267d7bd07309d5169ab19f753f88b31 100644 (file)
@@ -507,16 +507,10 @@ bool Model_AttributeSelection::update()
               }
             }
           }
-          aNewSelected = Model_SelectionNaming::findAppropriateFace(aContext, allCurves);
+          aNewSelected = Model_SelectionNaming::findAppropriateFace(
+            aContext, allCurves, aShapeType == TopAbs_WIRE);
         }
         if (aNewSelected) { // store this new selection
-          if (aShapeType == TopAbs_WIRE) { // just get a wire from face to have wire
-            TopExp_Explorer aWireExp(aNewSelected->impl<TopoDS_Shape>(), TopAbs_WIRE);
-            if (aWireExp.More()) {
-              aNewSelected.reset(new GeomAPI_Shape);
-              aNewSelected->setImpl<TopoDS_Shape>(new TopoDS_Shape(aWireExp.Current()));
-            }
-          }
           selectConstruction(aContext, aNewSelected);
           setInvalidIfFalse(aSelLab, true);
           owner()->data()->sendAttributeUpdated(this);
index a3f9ace283ec807898b03917b39d74b25a49e16d..f85886a010d7857489d12dc8c197ca792459b9aa 100644 (file)
@@ -14,6 +14,7 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_ResultBody.h>
+#include <GeomAPI_Wire.h>
 
 #include <TopoDS_Iterator.hxx>
 #include <TopoDS.hxx>
@@ -559,7 +560,7 @@ int Model_SelectionNaming::edgeOrientation(const TopoDS_Shape& theContext, TopoD
 
 std::shared_ptr<GeomAPI_Shape> Model_SelectionNaming::findAppropriateFace(
   std::shared_ptr<ModelAPI_Result>& theConstr, 
-  NCollection_DataMap<Handle(Geom_Curve), int>& theCurves)
+  NCollection_DataMap<Handle(Geom_Curve), int>& theCurves, const bool theIsWire)
 {
   int aBestFound = 0; // best number of found edges (not percentage: issue 1019)
   int aBestOrient = 0; // for the equal "BestFound" additional parameter is orientation
@@ -572,34 +573,51 @@ std::shared_ptr<GeomAPI_Shape> Model_SelectionNaming::findAppropriateFace(
     int aFound = 0, aNotFound = 0, aSameOrientation = 0;
     TopoDS_Face aFace = 
       TopoDS::Face(aConstructionContext->face(aFaceIndex)->impl<TopoDS_Shape>());
-    TopExp_Explorer anEdgesExp(aFace, TopAbs_EDGE);
-    TColStd_MapOfTransient alreadyProcessed; // to avoid counting edges with same curved (841)
-    for(; anEdgesExp.More(); anEdgesExp.Next()) {
-      TopoDS_Edge anEdge = TopoDS::Edge(anEdgesExp.Current());
-      if (!anEdge.IsNull()) {
-        Standard_Real aFirst, aLast;
-        Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
-        if (alreadyProcessed.Contains(aCurve))
-          continue;
-        alreadyProcessed.Add(aCurve);
-        if (theCurves.IsBound(aCurve)) {
-          aFound++;
-          int anOrient = theCurves.Find(aCurve);
-          if (anOrient != 0) {  // extra comparision score is orientation
-            if (edgeOrientation(aFace, anEdge) == anOrient)
-              aSameOrientation++;
+    std::list<TopoDS_Shape> aFacesWires; // faces or wires to iterate
+    if (theIsWire) {
+      for(TopExp_Explorer aWires(aFace, TopAbs_WIRE); aWires.More(); aWires.Next()) {
+        aFacesWires.push_back(aWires.Current());
+      }
+    } else {
+      aFacesWires.push_back(aFace);
+    }
+    std::list<TopoDS_Shape>::iterator aFW = aFacesWires.begin();
+    for(; aFW != aFacesWires.end(); aFW++) {
+      TopExp_Explorer anEdgesExp(*aFW, TopAbs_EDGE);
+      TColStd_MapOfTransient alreadyProcessed; // to avoid counting edges with same curved (841)
+      for(; anEdgesExp.More(); anEdgesExp.Next()) {
+        TopoDS_Edge anEdge = TopoDS::Edge(anEdgesExp.Current());
+        if (!anEdge.IsNull()) {
+          Standard_Real aFirst, aLast;
+          Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+          if (alreadyProcessed.Contains(aCurve))
+            continue;
+          alreadyProcessed.Add(aCurve);
+          if (theCurves.IsBound(aCurve)) {
+            aFound++;
+            int anOrient = theCurves.Find(aCurve);
+            if (anOrient != 0) {  // extra comparision score is orientation
+              if (edgeOrientation(aFace, anEdge) == anOrient)
+                aSameOrientation++;
+            }
+          } else {
+            aNotFound++;
           }
-        } else {
-          aNotFound++;
         }
       }
-    }
-    if (aFound + aNotFound != 0) {
-      if (aFound > aBestFound || 
-        (aFound == aBestFound && aSameOrientation > aBestOrient)) {
-          aBestFound = aFound;
-          aBestOrient = aSameOrientation;
-          aResult = aConstructionContext->face(aFaceIndex);
+      if (aFound + aNotFound != 0) {
+        if (aFound > aBestFound || 
+          (aFound == aBestFound && aSameOrientation > aBestOrient)) {
+            aBestFound = aFound;
+            aBestOrient = aSameOrientation;
+            if (theIsWire) {
+              std::shared_ptr<GeomAPI_Wire> aWire(new GeomAPI_Wire);
+              aWire->setImpl(new TopoDS_Shape(*aFW));
+              aResult = aWire;
+            } else {
+              aResult = aConstructionContext->face(aFaceIndex);
+            }
+        }
       }
     }
   }
@@ -762,13 +780,6 @@ bool Model_SelectionNaming::selectSubShape(const std::string& theType,
       aSelection = findCommonShape(aType, aList);
     }
   }
-  if (!aSelection.IsNull()) {// Select it
-    std::shared_ptr<GeomAPI_Shape> aShapeToBeSelected(new GeomAPI_Shape());
-    aShapeToBeSelected->setImpl(new TopoDS_Shape(aSelection));
-    theShapeToBeSelected = aShapeToBeSelected;
-    theCont = aCont;
-    return true;
-  }
   // in case of construction, there is no registered names for all sub-elements,
   // even for the main element; so, trying to find them by name (without "&" intersections)
   if (aN == 0) {
@@ -859,17 +870,10 @@ bool Model_SelectionNaming::selectSubShape(const std::string& theType,
               }
             }
           }
-          std::shared_ptr<GeomAPI_Shape> aFoundFace = findAppropriateFace(aConstr, allCurves);
-          if (aFoundFace.get()) {
-            if (aType == TopAbs_WIRE) { // just get a wire from face to have wire
-              TopExp_Explorer aWireExp(aFoundFace->impl<TopoDS_Shape>(), TopAbs_WIRE);
-              if (aWireExp.More()) {
-                theShapeToBeSelected.reset(new GeomAPI_Shape);
-                theShapeToBeSelected->setImpl<TopoDS_Shape>(new TopoDS_Shape(aWireExp.Current()));
-              } else return false;
-            } else {
-              theShapeToBeSelected = aFoundFace;
-            }
+          std::shared_ptr<GeomAPI_Shape> aFoundFW =
+            findAppropriateFace(aConstr, allCurves, aType == TopAbs_WIRE);
+          if (aFoundFW.get()) {
+            theShapeToBeSelected = aFoundFW;
             return true;
           }
         } else if (aType == TopAbs_WIRE) { // sketch faces is identified by format "Sketch_1/Face-2f-8f-11r"
@@ -900,14 +904,23 @@ bool Model_SelectionNaming::selectSubShape(const std::string& theType,
               }
             }
           }
-          std::shared_ptr<GeomAPI_Shape> aFoundFace = findAppropriateFace(aConstr, allCurves);
-          if (aFoundFace.get()) {
-            theShapeToBeSelected = aFoundFace;
+          std::shared_ptr<GeomAPI_Shape> aFoundFW = 
+            findAppropriateFace(aConstr, allCurves, aType == TopAbs_WIRE);
+          if (aFoundFW.get()) {
+            theShapeToBeSelected = aFoundFW;
             return true;
           }
         }
       }
     }
   }
+  if (!aSelection.IsNull()) {// Select it (must be after N=0 checking, since for simple constructions the shape must be null)
+    std::shared_ptr<GeomAPI_Shape> aShapeToBeSelected(new GeomAPI_Shape());
+    aShapeToBeSelected->setImpl(new TopoDS_Shape(aSelection));
+    theShapeToBeSelected = aShapeToBeSelected;
+    theCont = aCont;
+    return true;
+  }
+
   return false;
 }
index ca513fe76b4992ccc8c5a09b7513d1661e3cb9cf..97c49a68e14ccfdaf8d81052675fe91eb16fcda3 100644 (file)
@@ -45,10 +45,11 @@ public:
   /// Searches the face more appropriate to the given curves (with higher level of matched parameters)
   /// \param theConstr construction result that contains one or several  faces
   /// \param theCurves map from the face edges curves to orientation (-1 reversed, 0 unknown, 1 forward)
+  /// \param theIsWire for wire algorithm isquite the same, but if in face several wires, it returns the needed wire
   /// \returns faces fron this construction if found
   static std::shared_ptr<GeomAPI_Shape> findAppropriateFace(
     std::shared_ptr<ModelAPI_Result>& theConstr, 
-    NCollection_DataMap<Handle(Geom_Curve), int>& theCurves);
+    NCollection_DataMap<Handle(Geom_Curve), int>& theCurves, const bool theIsWire);
 
   /// Returns orientation of the edge in the context shape
   static int edgeOrientation(const TopoDS_Shape& theContext, TopoDS_Edge& theEdge);