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>
10 #include <SketchPlugin_Line.h>
11 #include <SketchPlugin_Sketch.h>
13 #include <GeomDataAPI_Point2D.h>
14 #include <GeomAPI_Pnt2d.h>
15 #include <GeomAPI_Pnt.h>
17 SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
21 void SketchPlugin_ConstraintPerpendicular::initAttributes()
23 data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
24 data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type());
25 data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
28 void SketchPlugin_ConstraintPerpendicular::execute(boost::shared_ptr<ModelAPI_Result>& theResult)
32 boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintPerpendicular::getAISObject(
33 boost::shared_ptr<GeomAPI_AISObject> thePrevious)
38 boost::shared_ptr<ModelAPI_Data> aData = data();
39 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 =
40 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
41 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
42 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
43 if (!anAttr1 || !anAttr1->isFeature() ||
44 !anAttr2 || !anAttr2->isFeature())
46 boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
47 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
48 boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
49 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
50 if (!aLine1Feature || !aLine2Feature)
53 boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
54 boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
55 boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
57 boost::shared_ptr<GeomAPI_AISObject> anAIS = thePrevious;
59 anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject);
60 anAIS->createPerpendicular(aLine1, aLine2, aPlane);
64 void SketchPlugin_ConstraintPerpendicular::move(double theDeltaX, double theDeltaY)
66 boost::shared_ptr<ModelAPI_Data> aData = data();
67 if (!aData->isValid())
70 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
71 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
72 aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);