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 #include <Config_PropManager.h>
20 SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
24 void SketchPlugin_ConstraintPerpendicular::initAttributes()
26 data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
27 data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
28 data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type());
31 void SketchPlugin_ConstraintPerpendicular::execute()
35 AISObjectPtr SketchPlugin_ConstraintPerpendicular::getAISObject(AISObjectPtr thePrevious)
40 boost::shared_ptr<ModelAPI_Data> aData = data();
41 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 = boost::dynamic_pointer_cast<
42 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
43 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 = boost::dynamic_pointer_cast<
44 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
45 if (!anAttr1 || !anAttr1->isObject() || !anAttr2 || !anAttr2->isObject())
48 FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object());
51 boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
52 boost::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
54 aFeature = ModelAPI_Feature::feature(anAttr2->object());
57 boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
58 boost::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
60 if (!aLine1Feature || !aLine2Feature)
63 boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
64 boost::shared_ptr<GeomAPI_Shape> aLine1, aLine2;
65 boost::shared_ptr<ModelAPI_ResultConstruction> aConst1 = boost::dynamic_pointer_cast<
66 ModelAPI_ResultConstruction>(anAttr1->object());
68 aLine1 = aConst1->shape();
69 boost::shared_ptr<ModelAPI_ResultConstruction> aConst2 = boost::dynamic_pointer_cast<
70 ModelAPI_ResultConstruction>(anAttr2->object());
72 aLine2 = aConst2->shape();
74 AISObjectPtr anAIS = thePrevious;
76 anAIS = AISObjectPtr(new GeomAPI_AISObject);
77 anAIS->createPerpendicular(aLine1, aLine2, aPlane);
79 // Set color from preferences
80 std::vector<int> aRGB = Config_PropManager::color("Visualization", "perpendicular_color",
82 anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
86 void SketchPlugin_ConstraintPerpendicular::move(double theDeltaX, double theDeltaY)
88 boost::shared_ptr<ModelAPI_Data> aData = data();
89 if (!aData->isValid())
92 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
93 aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
94 aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);