Salome HOME
Task 3.9. Detect free points in the sketcher (issue #2927)
authorazv <azv@opencascade.com>
Tue, 18 Jun 2019 09:38:07 +0000 (12:38 +0300)
committerazv <azv@opencascade.com>
Tue, 18 Jun 2019 09:38:40 +0000 (12:38 +0300)
Implement algorithm of fetching free points.

src/GeomAPI/GeomAPI_Edge.cpp
src/SketchAPI/CMakeLists.txt
src/SketchAPI/SketchAPI.i
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h
src/SketchAPI/Test/TestFreePoints.py [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_Tools.cpp
src/SketcherPrs/SketcherPrs_Tools.h

index 379bdab86b9f396eee35febc5f608727d43d321b..682211f82620776e4ca640bd46f61f18f0117f12 100644 (file)
@@ -332,7 +332,8 @@ void GeomAPI_Edge::intersectWithPlane(const std::shared_ptr<GeomAPI_Pln> 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);
index 80b055bed50e7826c3c733dc0c6d4e025ade2c76..4cc22fb6c380c93c9653d859e0eaaccead5c0732 100644 (file)
@@ -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)
index 5ca8fdeb5ad0bcd8022672a21501ab807b39f15f..36732e2c2f1abb6472a6ae428108dbdb8b6fbb0d 100644 (file)
@@ -64,6 +64,7 @@
 // std::list -> []
 %template(InterfaceList) std::list<std::shared_ptr<ModelHighAPI_Interface> >;
 %template(EntityList)    std::list<std::shared_ptr<SketchAPI_SketchEntity> >;
+%template(SketchPointList) std::list<std::shared_ptr<SketchAPI_Point> >;
 
 %typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr<ModelAPI_Feature>, const std::shared_ptr<ModelAPI_Feature> & {
   std::shared_ptr<ModelAPI_Feature> * temp_feature;
index 14ebf7f4c34cf549b20364e2cd3518b73d295b07..66e043c1c85b201f3ebc64051c866b825a7a0263 100644 (file)
@@ -222,6 +222,19 @@ SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
 }
 
 
+//--------------------------------------------------------------------------------------
+std::list< std::shared_ptr<SketchAPI_Point> > SketchAPI_Sketch::getFreePoints()
+{
+  std::list< std::shared_ptr<SketchAPI_Point> > aFreePoints;
+  std::list<ResultPtr> aPoints = SketcherPrs_Tools::getFreePoints(compositeFeature());
+  for (std::list<ResultPtr>::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_Point> SketchAPI_Sketch::addPoint(
     double theX, double theY)
index 1d3f762a697157a756f226ecd9151d448a09d8ed..8b3237f7f04df08e3cb8e3da1dbf4a4e49185f90 100644 (file)
@@ -111,6 +111,10 @@ public:
   SKETCHAPI_EXPORT
   void setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject);
 
+  /// List points not connected by constraints with other sketch entitites
+  SKETCHAPI_EXPORT
+  std::list< std::shared_ptr<SketchAPI_Point> > getFreePoints();
+
   /// Add point
   SKETCHAPI_EXPORT
   std::shared_ptr<SketchAPI_Point> addPoint(
diff --git a/src/SketchAPI/Test/TestFreePoints.py b/src/SketchAPI/Test/TestFreePoints.py
new file mode 100644 (file)
index 0000000..66297fb
--- /dev/null
@@ -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()
index 5e58787ddd08ddc02679639286ce0e4657e46edd..0aecb72c9614bba19f5cb07eaad943a7c03efdae 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Events.h>
 
@@ -186,6 +187,38 @@ std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
   return aPointAttr;
 }
 
+//*************************************************************************************
+std::list<ResultPtr> getFreePoints(const CompositeFeaturePtr& theSketch)
+{
+  std::list<ResultPtr> aFreePoints;
+  if (!theSketch)
+    return aFreePoints;
+
+  AttributeRefListPtr aFeatures = theSketch->reflist(SketchPlugin_Sketch::FEATURES_ID());
+  if (!aFeatures)
+    return aFreePoints;
+  std::list<ObjectPtr> anObjects = aFeatures->list();
+  for (std::list<ObjectPtr>::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<AttributePtr>& aRefs = aCurrent->data()->refsToMe();
+      std::set<AttributePtr>::iterator aRIt = aRefs.begin();
+      for (; aRIt != aRefs.end(); ++aRIt) {
+        FeaturePtr aRefFeat = ModelAPI_Feature::feature((*aRIt)->owner());
+        std::shared_ptr<SketchPlugin_Constraint> aRefConstr =
+            std::dynamic_pointer_cast<SketchPlugin_Constraint>(aRefFeat);
+        if (aRefConstr)
+          break;
+      }
+      if (aRIt == aRefs.end())
+        aFreePoints.push_back(aCurrent->lastResult());
+    }
+  }
+  return aFreePoints;
+}
+
 //*************************************************************************************
 FeaturePtr getFeatureLine(DataPtr theData,
                           const std::string& theAttribute)
index c8f8ea05625359c855db3a4116372e88c492c993..75d1b351e0d1716bc7ab2cf055bcce835cbb4941 100644 (file)
@@ -27,6 +27,8 @@
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Result.h>
 #include <string>
 
 #include <Events_Loop.h>
@@ -154,6 +156,11 @@ namespace SketcherPrs_Tools {
                                                const std::string& theAttribute,
                                                const std::shared_ptr<GeomAPI_Ax3>& 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<ResultPtr> getFreePoints(const CompositeFeaturePtr& theSketch);
+
   /// Returns value of dimension arrows size
   SKETCHERPRS_EXPORT double getArrowSize();