From 82860b4f3ff5ff7e0a9e39e482dc013113b345a7 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 18 Jun 2019 12:38:07 +0300 Subject: [PATCH] Task 3.9. Detect free points in the sketcher (issue #2927) Implement algorithm of fetching free points. --- src/GeomAPI/GeomAPI_Edge.cpp | 3 +- src/SketchAPI/CMakeLists.txt | 2 ++ src/SketchAPI/SketchAPI.i | 1 + src/SketchAPI/SketchAPI_Sketch.cpp | 13 +++++++ src/SketchAPI/SketchAPI_Sketch.h | 4 +++ src/SketchAPI/Test/TestFreePoints.py | 52 +++++++++++++++++++++++++++ src/SketcherPrs/SketcherPrs_Tools.cpp | 33 +++++++++++++++++ src/SketcherPrs/SketcherPrs_Tools.h | 7 ++++ 8 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 src/SketchAPI/Test/TestFreePoints.py diff --git a/src/GeomAPI/GeomAPI_Edge.cpp b/src/GeomAPI/GeomAPI_Edge.cpp index 379bdab86..682211f82 100644 --- a/src/GeomAPI/GeomAPI_Edge.cpp +++ b/src/GeomAPI/GeomAPI_Edge.cpp @@ -332,7 +332,8 @@ void GeomAPI_Edge::intersectWithPlane(const std::shared_ptr thePlan // find minimal distance between the plane and the curve GeomAPI_ExtremaCurveSurface anExtrema(aCurve, aPlane); double aTolerance = BRep_Tool::Tolerance(TopoDS::Edge(aShape)); - if (anExtrema.LowerDistance() < aTolerance) { + if (anExtrema.NbExtrema() > 0 && + anExtrema.LowerDistance() < aTolerance) { // distance is lower than tolerance => tangent case gp_Pnt aPntC, aPntS; anExtrema.NearestPoints(aPntC, aPntS); diff --git a/src/SketchAPI/CMakeLists.txt b/src/SketchAPI/CMakeLists.txt index 80b055bed..4cc22fb6c 100644 --- a/src/SketchAPI/CMakeLists.txt +++ b/src/SketchAPI/CMakeLists.txt @@ -61,6 +61,7 @@ SET(PROJECT_SOURCES SET(PROJECT_LIBRARIES ModelAPI ModelHighAPI + SketcherPrs ) INCLUDE_DIRECTORIES( @@ -129,6 +130,7 @@ INCLUDE(UnitTest) ADD_UNIT_TESTS( TestSketch.py + TestFreePoints.py ) # ADD_SUBDIRECTORY (Test) diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index 5ca8fdeb5..36732e2c2 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -64,6 +64,7 @@ // std::list -> [] %template(InterfaceList) std::list >; %template(EntityList) std::list >; +%template(SketchPointList) std::list >; %typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr, const std::shared_ptr & { std::shared_ptr * temp_feature; diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index 14ebf7f4c..66e043c1c 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -222,6 +222,19 @@ SketchPtr addSketch(const std::shared_ptr & thePart, } +//-------------------------------------------------------------------------------------- +std::list< std::shared_ptr > SketchAPI_Sketch::getFreePoints() +{ + std::list< std::shared_ptr > aFreePoints; + std::list aPoints = SketcherPrs_Tools::getFreePoints(compositeFeature()); + for (std::list::iterator anIt = aPoints.begin(); anIt != aPoints.end(); ++anIt) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); + PointPtr aPoint(new SketchAPI_Point(aFeature)); + aFreePoints.push_back(aPoint); + } + return aFreePoints; +} + //-------------------------------------------------------------------------------------- std::shared_ptr SketchAPI_Sketch::addPoint( double theX, double theY) diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index 1d3f762a6..8b3237f7f 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -111,6 +111,10 @@ public: SKETCHAPI_EXPORT void setExternal(std::shared_ptr thePlaneObject); + /// List points not connected by constraints with other sketch entitites + SKETCHAPI_EXPORT + std::list< std::shared_ptr > getFreePoints(); + /// Add point SKETCHAPI_EXPORT std::shared_ptr addPoint( diff --git a/src/SketchAPI/Test/TestFreePoints.py b/src/SketchAPI/Test/TestFreePoints.py new file mode 100644 index 000000000..66297fb44 --- /dev/null +++ b/src/SketchAPI/Test/TestFreePoints.py @@ -0,0 +1,52 @@ +# Copyright (C) 2019 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from SketchAPI import * + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchCircle_1 = Sketch_1.addCircle(46.22261352148133, 0, 23.58244120674807) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_1.center()) +model.do() +Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchPoint_1 = Sketch_2.addPoint(-17.08115772475531, -35.96860682980034) +SketchLine_2 = Sketch_2.addLine(-21.65537897222015, 0.8259975132940123, 39.97043562830241, -43.0039721165161) +SketchPoint_2 = Sketch_2.addPoint(15.99061885657872, -44.35579681082369) +SketchConstraintDistance_1 = Sketch_2.setDistance(SketchPoint_2.coordinates(), SketchLine_2.result(), 15, True) +SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), True) +SketchPoint_3 = SketchProjection_2.createdFeature() +SketchIntersectionPoint_1 = Sketch_2.addIntersectionPoint(model.selection("EDGE", "Sketch_1/SketchCircle_1_2"), False) +[SketchPoint_4, SketchPoint_5] = SketchIntersectionPoint_1.intersectionPoints() +SketchConstraintDistance_2 = Sketch_2.setDistance(SketchAPI_Point(SketchPoint_4).coordinates(), SketchLine_2.result(), 25, True) +model.do() + +FreePoints1 = Sketch_1.getFreePoints() +assert(len(FreePoints1) == 0) + +FreePoints2 = Sketch_2.getFreePoints() +assert(len(FreePoints2) == 3) + +model.end() diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 5e58787dd..0aecb72c9 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -186,6 +187,38 @@ std::shared_ptr getFeaturePoint(DataPtr theData, return aPointAttr; } +//************************************************************************************* +std::list getFreePoints(const CompositeFeaturePtr& theSketch) +{ + std::list aFreePoints; + if (!theSketch) + return aFreePoints; + + AttributeRefListPtr aFeatures = theSketch->reflist(SketchPlugin_Sketch::FEATURES_ID()); + if (!aFeatures) + return aFreePoints; + std::list anObjects = aFeatures->list(); + for (std::list::iterator anObjIt = anObjects.begin(); + anObjIt != anObjects.end(); ++anObjIt) { + FeaturePtr aCurrent = ModelAPI_Feature::feature(*anObjIt); + if (aCurrent && aCurrent->getKind() == SketchPlugin_Point::ID()) { + // check point is not referred by any constraints + const std::set& aRefs = aCurrent->data()->refsToMe(); + std::set::iterator aRIt = aRefs.begin(); + for (; aRIt != aRefs.end(); ++aRIt) { + FeaturePtr aRefFeat = ModelAPI_Feature::feature((*aRIt)->owner()); + std::shared_ptr aRefConstr = + std::dynamic_pointer_cast(aRefFeat); + if (aRefConstr) + break; + } + if (aRIt == aRefs.end()) + aFreePoints.push_back(aCurrent->lastResult()); + } + } + return aFreePoints; +} + //************************************************************************************* FeaturePtr getFeatureLine(DataPtr theData, const std::string& theAttribute) diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h index c8f8ea056..75d1b351e 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.h +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include @@ -154,6 +156,11 @@ namespace SketcherPrs_Tools { const std::string& theAttribute, const std::shared_ptr& thePlane); + /// Collect all sketch points which are not connected with other entities. + /// \param theSketch sketch feature + /// \return list of results of SketchPlugin_Point features + SKETCHERPRS_EXPORT std::list getFreePoints(const CompositeFeaturePtr& theSketch); + /// Returns value of dimension arrows size SKETCHERPRS_EXPORT double getArrowSize(); -- 2.39.2