]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add Vertical and horizontal constraint, documentation and traduction
authorlucasjerome <jerome.lucas@cegsenslab.fr>
Thu, 25 Mar 2021 10:27:06 +0000 (11:27 +0100)
committerlucasjerome <jerome.lucas@cegsenslab.fr>
Thu, 25 Mar 2021 10:27:06 +0000 (11:27 +0100)
14 files changed:
src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp
src/SketchPlugin/SketchPlugin_ConstraintHorizontal.h
src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp
src/SketchPlugin/SketchPlugin_ConstraintVertical.h
src/SketchPlugin/SketchPlugin_Polyline.cpp
src/SketchPlugin/SketchPlugin_Polyline.h
src/SketchPlugin/SketchPlugin_msg_fr.ts
src/SketchPlugin/doc/SketchPlugin.rst
src/SketchPlugin/doc/images/Polyline_panel.png [new file with mode: 0644]
src/SketchPlugin/doc/images/Polyline_res.png [new file with mode: 0644]
src/SketchPlugin/doc/images/polyline.png [new file with mode: 0644]
src/SketchPlugin/doc/polylineFeature.rst [new file with mode: 0644]
src/SketchPlugin/icons/polyline.png
src/SketchPlugin/plugin-Sketch.xml

index f256187a85b7b916ebb526756f2c7e073b2dc1a8..ef8fedd5cce67f32ea95091574a0d9423524c59f 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
+#include <ModelAPI_Events.h>
 #include <ModelAPI_ResultConstruction.h>
 
 #include <SketchPlugin_Line.h>
@@ -29,6 +30,8 @@
 #include <SketcherPrs_Factory.h>
 //#include <SketcherPrs_Tools.h>
 
+#include <Events_Loop.h>
+
 #include <Config_PropManager.h>
 
 SketchPlugin_ConstraintHorizontal::SketchPlugin_ConstraintHorizontal()
@@ -54,3 +57,24 @@ AISObjectPtr SketchPlugin_ConstraintHorizontal::getAISObject(AISObjectPtr thePre
   return anAIS;
 }
 
+void SketchPlugin_ConstraintHorizontal::createHorizontalFeature(SketchPlugin_Sketch* theSketch,
+                                              const std::shared_ptr<ModelAPI_Result>& theLine)
+{
+  FeaturePtr aFeature;
+  if (theSketch) {
+    aFeature = theSketch->addFeature(SketchPlugin_ConstraintHorizontal::ID());
+  } else {
+    std::shared_ptr<ModelAPI_Document> aDoc = theSketch->document();
+    aFeature = aDoc->addFeature(SketchPlugin_ConstraintHorizontal::ID());
+  }
+
+  std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+
+  std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = std::dynamic_pointer_cast<
+      ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
+  aRef->setObject(theLine);
+
+  // we need to flush created signal in order to coincidence is processed by solver
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+}
+
index 591c8423a610eb1b1a3f65bbc07ac90e0697836f..8ef096159d2cfbb9cea998f9ef2654525f70fe97 100644 (file)
@@ -56,6 +56,12 @@ class SketchPlugin_ConstraintHorizontal : public SketchPlugin_ConstraintBase
   /// Returns the AIS preview
   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
 
+  /// Creates a horizontal constraint on line
+  /// \param theSketch a sketch feature
+  /// \param theLine the line
+  static void createHorizontalFeature(SketchPlugin_Sketch* theSketch,
+                                    const std::shared_ptr<ModelAPI_Result>& theLine);
+
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintHorizontal();
 };
index 917cfbfb54fd025569d186c23b3d6c085c345436..cf317f703c15cd3d9b740f8c4f88a2a2dd63b433 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
+#include <ModelAPI_Events.h>
 #include <ModelAPI_ResultConstruction.h>
 
 #include <SketchPlugin_Line.h>
@@ -29,6 +30,7 @@
 #include <SketcherPrs_Factory.h>
 
 #include <Config_PropManager.h>
+#include <Events_Loop.h>
 
 SketchPlugin_ConstraintVertical::SketchPlugin_ConstraintVertical()
 {
@@ -53,4 +55,24 @@ AISObjectPtr SketchPlugin_ConstraintVertical::getAISObject(AISObjectPtr thePrevi
   return anAIS;
 }
 
+void SketchPlugin_ConstraintVertical::createVerticalFeature(SketchPlugin_Sketch* theSketch,
+                                          const std::shared_ptr<ModelAPI_Result>& theLine)
+{
+  FeaturePtr aFeature;
+  if (theSketch) {
+    aFeature = theSketch->addFeature(SketchPlugin_ConstraintVertical::ID());
+  } else {
+    std::shared_ptr<ModelAPI_Document> aDoc = theSketch->document();
+    aFeature = aDoc->addFeature(SketchPlugin_ConstraintVertical::ID());
+  }
+
+  std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+
+  std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = std::dynamic_pointer_cast<
+      ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
+  aRef->setObject(theLine);
+
+  // we need to flush created signal in order to coincidence is processed by solver
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+}
 
index dc533a96fe35eae39111ed5851bc741d1e47d11a..cb5bab81b0a54a59568cfda493b14e3d61b76aa6 100644 (file)
@@ -56,6 +56,12 @@ class SketchPlugin_ConstraintVertical : public SketchPlugin_ConstraintBase
   /// Returns the AIS preview
   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
 
+  /// Creates a vertical constraint on line
+  /// \param theSketch a sketch feature
+  /// \param theLine the line
+  static void createVerticalFeature(SketchPlugin_Sketch* theSketch,
+                                    const std::shared_ptr<ModelAPI_Result>& theLine);
+
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintVertical();
 };
index c73fd7a796c9d649702e7a585cd3bc4914298ead..a8fd95c38b40c3149db0fa0936343f67350f73ff 100644 (file)
@@ -23,6 +23,8 @@
 #include "SketchPlugin_Sketch.h"
 
 #include "SketchPlugin_ConstraintCoincidence.h"
+#include "SketchPlugin_ConstraintVertical.h"
+#include "SketchPlugin_ConstraintHorizontal.h"
 
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeBoolean.h>
@@ -38,7 +40,7 @@
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <SketchPlugin_Tools.h>
 
-#include <iostream>
+#include <cmath>
 
 SketchPlugin_Polyline::SketchPlugin_Polyline()
     : SketchPlugin_SketchEntity()
@@ -61,14 +63,14 @@ void SketchPlugin_Polyline::execute()
   createLineFeature();
 }
 
-void  SketchPlugin_Polyline::createLineFeature()
+void SketchPlugin_Polyline::createLineFeature()
 {
   AttributePoint2DArrayPtr aPointsArray =
       std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(attribute(POINTS_ID()));
 
   getAISObject(AISObjectPtr());
 
-  if (aPointsArray->isInitialized())
+  if (aPointsArray->isInitialized() && aPointsArray->size() > 1)
   {
     FeaturePtr aLastline;
     FeaturePtr aFirstline;
@@ -79,13 +81,15 @@ void  SketchPlugin_Polyline::createLineFeature()
       if (anIndex ==1) {
         aFirstline = aLine;
       }
-      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>(
+                                      aLine->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>(
+                                         aLine->attribute(SketchPlugin_Line::END_ID()));
 
       aEndA->setValue(aPointsArray->pnt(anIndex));
 
@@ -96,31 +100,36 @@ void  SketchPlugin_Polyline::createLineFeature()
         // 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>(
-                                                aSFData->attribute(SketchPlugin_Line::END_ID()));
+                              std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                                               aSFData->attribute(SketchPlugin_Line::END_ID()));
         std::shared_ptr<ModelAPI_Data> aNFData = aLine->data();
         std::shared_ptr<GeomDataAPI_Point2D> aNPoint =
-                                    std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                                              aNFData->attribute(SketchPlugin_Line::START_ID()));
+                              std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                                             aNFData->attribute(SketchPlugin_Line::START_ID()));
         aNPoint->setValue(aSPoint->x(), aSPoint->y());
         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());
+      }
+
       aLastline = aLine;
     }
     // 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>(
+    std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
                                                 aSFData->attribute(SketchPlugin_Line::END_ID()));
     std::shared_ptr<ModelAPI_Data> aNFData = aFirstline->data();
-    std::shared_ptr<GeomDataAPI_Point2D> aNPoint =
-                                           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                                              aNFData->attribute(SketchPlugin_Line::START_ID()));
+    std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                                                aNFData->attribute(SketchPlugin_Line::START_ID()));
 
     double aDistance = aSPoint->pnt()->distance(aNPoint->pnt());
-    if (aDistance < 1) {
+    if (aDistance < 2) {
       aNPoint->setValue(aSPoint->x(), aSPoint->y());
       SketchPlugin_ConstraintCoincidence::createCoincidenceFeature(sketch(), aSPoint, aNPoint);
     }
index 7decbf4417158ae7d949d7bdab1aec5c43da3859..2237ae8ee226b592c93d7913d6838b4c3ff0c013 100644 (file)
@@ -36,7 +36,7 @@ class GeomAPI_Pnt2d;
  * \brief Feature for creation of polyline in PartSet.
  */
 class SketchPlugin_Polyline : public SketchPlugin_SketchEntity,
-                               public GeomAPI_IPresentable
+                              public GeomAPI_IPresentable
 {
  public:
   /// Arc feature kind
index 74e55917088470edc0cf85ec69fcbf913ad3729d..ca6fd6d68e06968a0ef810daa2dc4476db7959d5 100644 (file)
       <translation>Élément de construction</translation>
     </message>
   </context>
-
+  <context>
+    <name>SketchPolyline</name>
+    <message>
+      <source>Polyline</source>
+      <translation>Polyligne</translation>
+    </message>
+  </context>
+  <context>
+    <name>SketchPolyline:Auxiliary</name>
+    <message>
+      <source>Auxiliary</source>
+      <translation>Auxiliaire</translation>
+    </message>
+  </context>
   <context>
     <name>SketchMacroArc</name>
     <message>
index d1c47eb22e9a7de66ca19fb79c34f3bd14543a47..4196b8a0eb82b341c395a9d285c2c765a7bed4c6 100644 (file)
@@ -87,6 +87,7 @@ The plug-in includes the following features for creation of 2D objects:
 
    pointFeature.rst
    lineFeature.rst
+   polylineFeature.rst
    rectangleFeature.rst
    circleFeature.rst
    arcFeature.rst
diff --git a/src/SketchPlugin/doc/images/Polyline_panel.png b/src/SketchPlugin/doc/images/Polyline_panel.png
new file mode 100644 (file)
index 0000000..954a659
Binary files /dev/null and b/src/SketchPlugin/doc/images/Polyline_panel.png differ
diff --git a/src/SketchPlugin/doc/images/Polyline_res.png b/src/SketchPlugin/doc/images/Polyline_res.png
new file mode 100644 (file)
index 0000000..139aeef
Binary files /dev/null and b/src/SketchPlugin/doc/images/Polyline_res.png differ
diff --git a/src/SketchPlugin/doc/images/polyline.png b/src/SketchPlugin/doc/images/polyline.png
new file mode 100644 (file)
index 0000000..7f55aaf
Binary files /dev/null and b/src/SketchPlugin/doc/images/polyline.png differ
diff --git a/src/SketchPlugin/doc/polylineFeature.rst b/src/SketchPlugin/doc/polylineFeature.rst
new file mode 100644 (file)
index 0000000..475ec88
--- /dev/null
@@ -0,0 +1,33 @@
+.. _SketchPolyline:
+.. |polyline.icon|    image:: images/polyline.png
+
+Polyline
+========
+
+Polyline feature creates polyline in the current Sketch.
+
+To add a new Polyline to the Sketch:
+
+#. select in the Main Menu *Sketch - > Polyline* item  or
+#. click |polyline.icon| **Polyline** button in Sketch toolbar:
+
+The following property panel appears:
+
+.. figure:: images/Polyline_panel.png
+   :align: center
+
+   Polyline
+
+Pick points in the view to create a Line.  
+
+Start and end points coordinates are displayed in the property panel.
+
+Result
+""""""
+
+Created line appears in the view.
+
+.. figure:: images/Polyline_res.png
+   :align: center
+
+   Polyline created
index 8ed9356e716da9301db9463787b8aed48660b3ca..7f55aaf2919eda66d3a8738f89f932b7da854d11 100644 (file)
Binary files a/src/SketchPlugin/icons/polyline.png and b/src/SketchPlugin/icons/polyline.png differ
index 411884a6483af4ae14cf0e8c2f3479bea912c1ed..c8c76529137eccbd8a42f65804aecab5e8a4bb9a 100644 (file)
@@ -42,7 +42,7 @@
 
       <!-- SketchLine -->
       <feature id="SketchLine" title="Line" tooltip="Create line" icon="icons/Sketch/line.png"
-               helpfile="lineFeature.html">
+               helpfile="lineFeature.html" >
         <sketch-2dpoint_selector id="StartPoint" accept_expressions="0" title="Start point" tooltip="Start point coordinates"
                                  enable_value="enable_by_preferences"/>
         <sketch-2dpoint_selector id="EndPoint" accept_expressions="0" title="End point" tooltip="End point coordinates"
@@ -54,7 +54,7 @@
       </feature>
       <!-- SketchPolyline -->
       <feature id="SketchPolyline" title="Polyline" tooltip="Create polyline" icon="icons/Sketch/polyline.png"
-               helpfile="lineFeature.html">
+               helpfile="polylineFeature.html">
         <sketch-polyline_selector id="points"
                           title="Points"
                           tooltip="Polyline points"