1 // File: SketchPlugin_ConstraintPerpendicular.cpp
2 // Created: 26 May 2014
3 // Author: Artem ZHIDKOV
5 #include "SketchPlugin_ConstraintPerpendicular.h"
7 #include <ModelAPI_AttributeDouble.h>
8 #include <ModelAPI_Data.h>
9 #include <ModelAPI_ResultConstruction.h>
11 #include <SketchPlugin_Line.h>
12 #include <SketchPlugin_Sketch.h>
14 #include <GeomDataAPI_Point2D.h>
15 #include <GeomAPI_Pnt2d.h>
16 #include <GeomAPI_Pnt.h>
18 SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
22 void SketchPlugin_ConstraintPerpendicular::initAttributes()
24 data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
25 data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
26 data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type());
29 void SketchPlugin_ConstraintPerpendicular::execute()
33 boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintPerpendicular::getAISObject(
34 boost::shared_ptr<GeomAPI_AISObject> thePrevious)
39 boost::shared_ptr<ModelAPI_Data> aData = data();
40 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 =
41 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
42 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
43 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
44 if (!anAttr1 || !anAttr1->isObject() ||
45 !anAttr2 || !anAttr2->isObject())
47 boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
48 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->object());
49 boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
50 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->object());
51 if (!aLine1Feature || !aLine2Feature)
54 boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
55 boost::shared_ptr<GeomAPI_Shape> aLine1, aLine2;
56 boost::shared_ptr<ModelAPI_ResultConstruction> aConst1 =
57 boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aLine1Feature->firstResult());
58 if (aConst1) aLine1 = aConst1->shape();
59 boost::shared_ptr<ModelAPI_ResultConstruction> aConst2 =
60 boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aLine1Feature->firstResult());
61 if (aConst2) aLine2 = aConst2->shape();
63 boost::shared_ptr<GeomAPI_AISObject> anAIS = thePrevious;
65 anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject);
66 anAIS->createPerpendicular(aLine1, aLine2, aPlane);
70 void SketchPlugin_ConstraintPerpendicular::move(double theDeltaX, double theDeltaY)
72 boost::shared_ptr<ModelAPI_Data> aData = data();
73 if (!aData->isValid())
76 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
77 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
78 aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);