#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_Events.h>
#include <ModelAPI_ResultConstruction.h>
#include <SketchPlugin_Line.h>
#include <SketcherPrs_Factory.h>
//#include <SketcherPrs_Tools.h>
+#include <Events_Loop.h>
+
#include <Config_PropManager.h>
SketchPlugin_ConstraintHorizontal::SketchPlugin_ConstraintHorizontal()
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));
+}
+
/// 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();
};
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_Events.h>
#include <ModelAPI_ResultConstruction.h>
#include <SketchPlugin_Line.h>
#include <SketcherPrs_Factory.h>
#include <Config_PropManager.h>
+#include <Events_Loop.h>
SketchPlugin_ConstraintVertical::SketchPlugin_ConstraintVertical()
{
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));
+}
/// 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();
};
#include "SketchPlugin_Sketch.h"
#include "SketchPlugin_ConstraintCoincidence.h"
+#include "SketchPlugin_ConstraintVertical.h"
+#include "SketchPlugin_ConstraintHorizontal.h"
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeBoolean.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
#include <SketchPlugin_Tools.h>
-#include <iostream>
+#include <cmath>
SketchPlugin_Polyline::SketchPlugin_Polyline()
: SketchPlugin_SketchEntity()
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;
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));
// 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);
}
* \brief Feature for creation of polyline in PartSet.
*/
class SketchPlugin_Polyline : public SketchPlugin_SketchEntity,
- public GeomAPI_IPresentable
+ public GeomAPI_IPresentable
{
public:
/// Arc feature kind
<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>
pointFeature.rst
lineFeature.rst
+ polylineFeature.rst
rectangleFeature.rst
circleFeature.rst
arcFeature.rst
--- /dev/null
+.. _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
<!-- 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"
</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"