From c5d26d0539a5d8e831fd02d90cda3b884d5506b8 Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 2 Sep 2016 20:40:18 +0300 Subject: [PATCH] Fix for the issue #1682 and the problem of selection of planes for partition in test scenarios (on execution of the dumped study) --- src/FeaturesPlugin/FeaturesPlugin_Recover.cpp | 3 - src/Model/Model_AttributeSelection.cpp | 10 +- src/Model/Model_SelectionNaming.cpp | 107 ++++++++++-------- src/Model/Model_SelectionNaming.h | 3 +- 4 files changed, 64 insertions(+), 59 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp index cb54944eb..54f3bbdcf 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp @@ -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(); } diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 7f8710c9e..3a9d350c7 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -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(), TopAbs_WIRE); - if (aWireExp.More()) { - aNewSelected.reset(new GeomAPI_Shape); - aNewSelected->setImpl(new TopoDS_Shape(aWireExp.Current())); - } - } selectConstruction(aContext, aNewSelected); setInvalidIfFalse(aSelLab, true); owner()->data()->sendAttributeUpdated(this); diff --git a/src/Model/Model_SelectionNaming.cpp b/src/Model/Model_SelectionNaming.cpp index a3f9ace28..f85886a01 100644 --- a/src/Model/Model_SelectionNaming.cpp +++ b/src/Model/Model_SelectionNaming.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -559,7 +560,7 @@ int Model_SelectionNaming::edgeOrientation(const TopoDS_Shape& theContext, TopoD std::shared_ptr Model_SelectionNaming::findAppropriateFace( std::shared_ptr& theConstr, - NCollection_DataMap& theCurves) + NCollection_DataMap& 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 Model_SelectionNaming::findAppropriateFace( int aFound = 0, aNotFound = 0, aSameOrientation = 0; TopoDS_Face aFace = TopoDS::Face(aConstructionContext->face(aFaceIndex)->impl()); - 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 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::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 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 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 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(), TopAbs_WIRE); - if (aWireExp.More()) { - theShapeToBeSelected.reset(new GeomAPI_Shape); - theShapeToBeSelected->setImpl(new TopoDS_Shape(aWireExp.Current())); - } else return false; - } else { - theShapeToBeSelected = aFoundFace; - } + std::shared_ptr 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 aFoundFace = findAppropriateFace(aConstr, allCurves); - if (aFoundFace.get()) { - theShapeToBeSelected = aFoundFace; + std::shared_ptr 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 aShapeToBeSelected(new GeomAPI_Shape()); + aShapeToBeSelected->setImpl(new TopoDS_Shape(aSelection)); + theShapeToBeSelected = aShapeToBeSelected; + theCont = aCont; + return true; + } + return false; } diff --git a/src/Model/Model_SelectionNaming.h b/src/Model/Model_SelectionNaming.h index ca513fe76..97c49a68e 100644 --- a/src/Model/Model_SelectionNaming.h +++ b/src/Model/Model_SelectionNaming.h @@ -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 findAppropriateFace( std::shared_ptr& theConstr, - NCollection_DataMap& theCurves); + NCollection_DataMap& theCurves, const bool theIsWire); /// Returns orientation of the edge in the context shape static int edgeOrientation(const TopoDS_Shape& theContext, TopoDS_Edge& theEdge); -- 2.39.2