1 // File: SketchPlugin_ConstraintParallel.cpp
2 // Created: 26 May 2014
3 // Author: Artem ZHIDKOV
5 #include "SketchPlugin_ConstraintParallel.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_ConstraintParallel::SketchPlugin_ConstraintParallel()
24 void SketchPlugin_ConstraintParallel::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_ConstraintParallel::execute()
35 boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintParallel::getAISObject(
36 boost::shared_ptr<GeomAPI_AISObject> thePrevious)
41 boost::shared_ptr<ModelAPI_Data> aData = data();
42 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 =
43 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
44 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
45 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
46 if (!anAttr1 || !anAttr1->isObject() ||
47 !anAttr2 || !anAttr2->isObject())
50 FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object());
53 boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
54 boost::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
56 aFeature = ModelAPI_Feature::feature(anAttr2->object());
59 boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
60 boost::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
62 if (!aLine1Feature || !aLine2Feature)
65 boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
66 boost::shared_ptr<GeomAPI_Shape> aLine1, aLine2;
67 boost::shared_ptr<ModelAPI_ResultConstruction> aConst1 =
68 boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr1->object());
69 if (aConst1) aLine1 = aConst1->shape();
70 boost::shared_ptr<ModelAPI_ResultConstruction> aConst2 =
71 boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr2->object());
72 if (aConst2) aLine2 = aConst2->shape();
74 boost::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
75 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
76 boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
78 boost::shared_ptr<GeomAPI_AISObject> anAIS = thePrevious;
80 anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject);
81 anAIS->createParallel(aLine1, aLine2, aFlyoutPnt, aPlane);
83 // Set color from preferences
84 std::string aColor = Config_PropManager::value("Sketcher", "Visualization",
85 "parallel_color", PARALLEL_COLOR);
86 std::vector<int> aRGB = stringToRGB(aColor);
87 anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
91 void SketchPlugin_ConstraintParallel::move(double theDeltaX, double theDeltaY)
93 boost::shared_ptr<ModelAPI_Data> aData = data();
94 if (!aData->isValid())
97 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
98 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
99 aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);