From: lucasjerome Date: Thu, 25 Mar 2021 10:27:06 +0000 (+0100) Subject: Add Vertical and horizontal constraint, documentation and traduction X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8f083ee0de7d955e7d2e83520e3fc5ac22de9879;p=modules%2Fshaper.git Add Vertical and horizontal constraint, documentation and traduction --- diff --git a/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp b/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp index f256187a8..ef8fedd5c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -29,6 +30,8 @@ #include //#include +#include + #include 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& theLine) +{ + FeaturePtr aFeature; + if (theSketch) { + aFeature = theSketch->addFeature(SketchPlugin_ConstraintHorizontal::ID()); + } else { + std::shared_ptr aDoc = theSketch->document(); + aFeature = aDoc->addFeature(SketchPlugin_ConstraintHorizontal::ID()); + } + + std::shared_ptr aData = aFeature->data(); + + std::shared_ptr 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)); +} + diff --git a/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.h b/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.h index 591c8423a..8ef096159 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.h @@ -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& theLine); + /// \brief Use plugin manager for features creation SketchPlugin_ConstraintHorizontal(); }; diff --git a/src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp b/src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp index 917cfbfb5..cf317f703 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -29,6 +30,7 @@ #include #include +#include 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& theLine) +{ + FeaturePtr aFeature; + if (theSketch) { + aFeature = theSketch->addFeature(SketchPlugin_ConstraintVertical::ID()); + } else { + std::shared_ptr aDoc = theSketch->document(); + aFeature = aDoc->addFeature(SketchPlugin_ConstraintVertical::ID()); + } + + std::shared_ptr aData = aFeature->data(); + + std::shared_ptr 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)); +} diff --git a/src/SketchPlugin/SketchPlugin_ConstraintVertical.h b/src/SketchPlugin/SketchPlugin_ConstraintVertical.h index dc533a96f..cb5bab81b 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintVertical.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintVertical.h @@ -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& theLine); + /// \brief Use plugin manager for features creation SketchPlugin_ConstraintVertical(); }; diff --git a/src/SketchPlugin/SketchPlugin_Polyline.cpp b/src/SketchPlugin/SketchPlugin_Polyline.cpp index c73fd7a79..a8fd95c38 100644 --- a/src/SketchPlugin/SketchPlugin_Polyline.cpp +++ b/src/SketchPlugin/SketchPlugin_Polyline.cpp @@ -23,6 +23,8 @@ #include "SketchPlugin_Sketch.h" #include "SketchPlugin_ConstraintCoincidence.h" +#include "SketchPlugin_ConstraintVertical.h" +#include "SketchPlugin_ConstraintHorizontal.h" #include #include @@ -38,7 +40,7 @@ #include #include -#include +#include 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(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 aStartA = std::dynamic_pointer_cast( - aLine->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aStartA = + std::dynamic_pointer_cast( + aLine->attribute(SketchPlugin_Line::START_ID())); aStartA->setValue(aPointsArray->pnt(anIndex-1)); - std::shared_ptr aEndA = std::dynamic_pointer_cast( - aLine->attribute(SketchPlugin_Line::END_ID())); + std::shared_ptr aEndA = + std::dynamic_pointer_cast( + 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 aSFData = aLastline->data(); std::shared_ptr aSPoint = - std::dynamic_pointer_cast( - aSFData->attribute(SketchPlugin_Line::END_ID())); + std::dynamic_pointer_cast( + aSFData->attribute(SketchPlugin_Line::END_ID())); std::shared_ptr aNFData = aLine->data(); std::shared_ptr aNPoint = - std::dynamic_pointer_cast( - aNFData->attribute(SketchPlugin_Line::START_ID())); + std::dynamic_pointer_cast( + 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 aSFData = aLastline->data(); - std::shared_ptr aSPoint = - std::dynamic_pointer_cast( + std::shared_ptr aSPoint = std::dynamic_pointer_cast( aSFData->attribute(SketchPlugin_Line::END_ID())); std::shared_ptr aNFData = aFirstline->data(); - std::shared_ptr aNPoint = - std::dynamic_pointer_cast( - aNFData->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aNPoint = std::dynamic_pointer_cast( + 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); } diff --git a/src/SketchPlugin/SketchPlugin_Polyline.h b/src/SketchPlugin/SketchPlugin_Polyline.h index 7decbf441..2237ae8ee 100644 --- a/src/SketchPlugin/SketchPlugin_Polyline.h +++ b/src/SketchPlugin/SketchPlugin_Polyline.h @@ -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 diff --git a/src/SketchPlugin/SketchPlugin_msg_fr.ts b/src/SketchPlugin/SketchPlugin_msg_fr.ts index 74e559170..ca6fd6d68 100644 --- a/src/SketchPlugin/SketchPlugin_msg_fr.ts +++ b/src/SketchPlugin/SketchPlugin_msg_fr.ts @@ -2980,7 +2980,20 @@ Élément de construction - + + SketchPolyline + + Polyline + Polyligne + + + + SketchPolyline:Auxiliary + + Auxiliary + Auxiliaire + + SketchMacroArc diff --git a/src/SketchPlugin/doc/SketchPlugin.rst b/src/SketchPlugin/doc/SketchPlugin.rst index d1c47eb22..4196b8a0e 100644 --- a/src/SketchPlugin/doc/SketchPlugin.rst +++ b/src/SketchPlugin/doc/SketchPlugin.rst @@ -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 index 000000000..954a65990 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 index 000000000..139aeef7b 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 index 000000000..7f55aaf29 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 index 000000000..475ec88fd --- /dev/null +++ b/src/SketchPlugin/doc/polylineFeature.rst @@ -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 diff --git a/src/SketchPlugin/icons/polyline.png b/src/SketchPlugin/icons/polyline.png index 8ed9356e7..7f55aaf29 100644 Binary files a/src/SketchPlugin/icons/polyline.png and b/src/SketchPlugin/icons/polyline.png differ diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 411884a64..c8c765291 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -42,7 +42,7 @@ + helpfile="lineFeature.html" > + helpfile="polylineFeature.html">