std::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch)
{
+ std::shared_ptr<GeomAPI_Pln> aPlane;
+
std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- if (!anOrigin || !aNorm)
- return std::shared_ptr<GeomAPI_Pln>();
+ if (aNormal.get() && aNormal->isInitialized() &&
+ anOrigin.get() && anOrigin->isInitialized())
+ aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNormal->dir()));
- return std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
+ return aPlane;
}
std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
: SketchPlugin_SketchEntity()
{}
+void SketchPlugin_Line::initAttributes()
+{
+ SketchPlugin_SketchEntity::initAttributes();
+ /// new attributes should be added to end of the feature in order to provide
+ /// correct attribute values in previous saved studies
+ data()->addAttribute(LENGTH_ID(), ModelAPI_AttributeDouble::typeId());
+}
+
void SketchPlugin_Line::initDerivedClassAttributes()
{
data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId());
data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId());
data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
-#ifndef LINE_LENGHT_BLOCKED
- data()->addAttribute(LENGTH_ID(), ModelAPI_AttributeDouble::typeId());
-#endif
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
void SketchPlugin_Line::updateLenghtValue()
{
-#ifndef LINE_LENGHT_BLOCKED
std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
GeomDataAPI_Point2D>(data()->attribute(START_ID()));
std::shared_ptr<GeomDataAPI_Point2D> anEndAttr = std::dynamic_pointer_cast<
double aDistance = aStartAttr->pnt()->distance(anEndAttr->pnt());
data()->real(LENGTH_ID())->setValue(aDistance);
}
-#endif
}
#include <SketchPlugin_Sketch.h>
#include <list>
-#define LINE_LENGHT_BLOCKED
class GeomAPI_Pnt2d;
/**\class SketchPlugin_Line
}
/// Line length.
-#ifndef LINE_LENGHT_BLOCKED
static const std::string& LENGTH_ID()
{
static const std::string MY_LENGTH("LineLength");
return MY_LENGTH;
}
-#endif
+
/// Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind();
/// Returns true is sketch element is under the rigid constraint
SKETCHPLUGIN_EXPORT virtual bool isFixed();
+ /// Request for initialization of data model of the feature: adding all attributes
+ virtual void initAttributes();
+
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
aX->dir(), aDirY, aPoints);
- int aCoincidentToFeature = aPoints.size();
+ int aCoincidentToFeature = (int)aPoints.size();
if (aKind == SketchPlugin_Circle::ID())
aValid = aCoincidentToFeature >= 2;
else
enable_value="enable_by_preferences"/>
<sketch-2dpoint_selector id="EndPoint" accept_expressions="0" title="End point" tooltip="End point coordinates"
enable_value="enable_by_preferences"/>
- <!--LINE_LENGHT_BLOCKED
<doublevalue id="LineLength" accept_expressions="0" label="Length:" default="computed" icon="icons/Sketch/distance_value.png"
- tooltip="Line length" obligatory="0" enable_value="false"/> -->
+ tooltip="Line length" obligatory="0" enable_value="false"/>
<boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
<validator id="GeomValidators_Different" parameters="StartPoint,EndPoint"/>
</feature>
<box id="CenterRadius" title="Center and radius" icon="icons/Sketch/circle_pt_rad_32x32.png">
<sketch-2dpoint_selector id="CircleCenter" accept_expressions="0" title="Center" tooltip="Center coordinates"
enable_value="enable_by_preferences"/>
- <point2ddistance id="CircleRadius" accept_expressions="0" first_point="CircleCenter" label="Radius:" min="0" step="1.0"
- default="0" icon="icons/Sketch/radius.png" tooltip="Set radius"
- enable_value="enable_by_preferences">
- <validator id="GeomValidators_Positive"/>
- </point2ddistance>
</box>
<box id="ThreePoints" title="Three points" icon="icons/Sketch/circle_3pt_32x32.png">
<sketch-2dpoint_selector id="FirstPoint" accept_expressions="0" title="First point" tooltip="First point"
enable_value="enable_by_preferences"/>
</box>
</toolbox>
+ <point2ddistance id="CircleRadius" accept_expressions="0" first_point="CircleCenter" label="Radius:" min="0" step="1.0"
+ default="0" icon="icons/Sketch/radius.png" tooltip="Set radius"
+ enable_value="enable_by_preferences">
+ <validator id="GeomValidators_Positive"/>
+ </point2ddistance>
<boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
</feature>