]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add angular precision for V and H contraints in degrees (4°) CEA_2020/Lot3_Polyline
authorlucasjerome <jerome.lucas@cegsenslab.fr>
Fri, 2 Apr 2021 09:15:12 +0000 (11:15 +0200)
committerlucasjerome <jerome.lucas@cegsenslab.fr>
Fri, 2 Apr 2021 09:15:12 +0000 (11:15 +0200)
src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp
src/PartSet/PartSet_SketcherReentrantMgr.cpp
src/SketchPlugin/SketchPlugin_Polyline.cpp

index 69e900fdc50dbc1a1ad715ed14da817521634c8b..9411724c86b5658e77870ad3a2c36d2fc1923d8c 100644 (file)
@@ -61,7 +61,7 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin()
   Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_thickness", "Thickness",
     Config_Prop::IntSpin, SKETCH_WIDTH);
   Config_PropManager::registerProp(SKETCH_TAB_NAME, "angular_tolerance", "Angular tolerance",
-    Config_Prop::DblSpin, "0.04");
+    Config_Prop::DblSpin, "4.0");
   Config_PropManager::registerProp(SKETCH_TAB_NAME, "spline_weight", "Default spline weight",
     Config_Prop::DblSpin, "1.0");
   Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane",
index 90dee037af4340a47c60cd40e0e6f700fd525083..0269ca8213f54c95c3c06fbd9f92f06f8348d723 100644 (file)
@@ -867,7 +867,7 @@ void PartSet_SketcherReentrantMgr::addConstraints(const FeaturePtr& theFeature)
     if (aVertAngle > M_PI/2.)
       aVertAngle = M_PI - aVertAngle;
 
-    double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance");
+    double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance")* M_PI/180.0;
     CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
     FeaturePtr aFeature;
     if (aHorAngle < aTolerance) {
index a8fd95c38b40c3149db0fa0936343f67350f73ff..176eb29ea61792694f344d382e796a360c17b5d6 100644 (file)
@@ -40,6 +40,9 @@
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <SketchPlugin_Tools.h>
 
+#include "GeomAPI_Lin2d.h"
+#include "GeomAPI_Dir2d.h"
+
 #include <cmath>
 
 SketchPlugin_Polyline::SketchPlugin_Polyline()
@@ -72,28 +75,29 @@ void SketchPlugin_Polyline::createLineFeature()
 
   if (aPointsArray->isInitialized() && aPointsArray->size() > 1)
   {
+    static GeomDir2dPtr myHorDir(new GeomAPI_Dir2d(1, 0));
+    static GeomDir2dPtr myVertDir(new GeomAPI_Dir2d(0, 1));
+
     FeaturePtr aLastline;
     FeaturePtr aFirstline;
     // collect points
     for (int anIndex = 1; anIndex < aPointsArray->size(); ++anIndex) {
 
-      FeaturePtr aLine = sketch()->addFeature(SketchPlugin_Line::ID());
+      FeaturePtr aLineFtr = sketch()->addFeature(SketchPlugin_Line::ID());
       if (anIndex ==1) {
-        aFirstline = aLine;
+        aFirstline = aLineFtr;
       }
-      std::shared_ptr<GeomDataAPI_Point2D> aStartA =
-                              std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                                      aLine->attribute(SketchPlugin_Line::START_ID()));
+      std::shared_ptr<GeomDataAPI_Point2D> aStartA = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+        aLineFtr->attribute(SketchPlugin_Line::START_ID()));
 
       aStartA->setValue(aPointsArray->pnt(anIndex-1));
 
-      std::shared_ptr<GeomDataAPI_Point2D> aEndA =
-                              std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                                         aLine->attribute(SketchPlugin_Line::END_ID()));
+      std::shared_ptr<GeomDataAPI_Point2D> aEndA = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+        aLineFtr->attribute(SketchPlugin_Line::END_ID()));
 
       aEndA->setValue(aPointsArray->pnt(anIndex));
 
-      aLine->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(
+      aLineFtr->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(
           boolean(AUXILIARY_ID())->value());
 
       if (aLastline) {
@@ -102,7 +106,7 @@ void SketchPlugin_Polyline::createLineFeature()
         std::shared_ptr<GeomDataAPI_Point2D> aSPoint =
                               std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
                                                aSFData->attribute(SketchPlugin_Line::END_ID()));
-        std::shared_ptr<ModelAPI_Data> aNFData = aLine->data();
+        std::shared_ptr<ModelAPI_Data> aNFData = aLineFtr->data();
         std::shared_ptr<GeomDataAPI_Point2D> aNPoint =
                               std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
                                              aNFData->attribute(SketchPlugin_Line::START_ID()));
@@ -110,16 +114,30 @@ void SketchPlugin_Polyline::createLineFeature()
         SketchPlugin_ConstraintCoincidence::createCoincidenceFeature(sketch(), aSPoint, aNPoint);
       }
 
-      aLine->execute();
-
-      if (fabs(aPointsArray->pnt(anIndex-1)->x() - aPointsArray->pnt(anIndex)->x()) <  1.0) {
-        SketchPlugin_ConstraintVertical::createVerticalFeature(sketch(),aLine->firstResult());
-      } else if (fabs(aPointsArray->pnt(anIndex-1)->y() - aPointsArray->pnt(anIndex)->y()) < 1.0) {
-        SketchPlugin_ConstraintHorizontal::createHorizontalFeature(sketch(),aLine->firstResult());
+      aLineFtr->execute();
+
+      GeomLine2dPtr aLine(new GeomAPI_Lin2d(aPointsArray->pnt(anIndex-1),
+                                            aPointsArray->pnt(anIndex)));
+      GeomDir2dPtr aDir = aLine->direction();
+      double aHorAngle = fabs(myHorDir->angle(aDir));
+      double aVertAngle = fabs(myVertDir->angle(aDir));
+      if (aHorAngle > M_PI/2.)
+      aHorAngle = M_PI - aHorAngle;
+      if (aVertAngle > M_PI/2.)
+      aVertAngle = M_PI - aVertAngle;
+      double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME,
+                                                   "angular_tolerance") * M_PI/180.0;
+
+      if (aHorAngle < aTolerance) {
+        SketchPlugin_ConstraintHorizontal::createHorizontalFeature(sketch(),
+                                                                   aLineFtr->firstResult());
+      } else if (aVertAngle < aTolerance) {
+        SketchPlugin_ConstraintVertical::createVerticalFeature(sketch(),
+                                                               aLineFtr->firstResult());
       }
-
-      aLastline = aLine;
+      aLastline = aLineFtr;
     }
+
     // Initialize new line with first point equal to end of previous
     std::shared_ptr<ModelAPI_Data> aSFData = aLastline->data();
     std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(