1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_ConstraintPerpendicular.cpp
4 // Created: 26 May 2014
5 // Author: Artem ZHIDKOV
7 #include "SketchPlugin_ConstraintPerpendicular.h"
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_ResultConstruction.h>
13 #include <SketchPlugin_Line.h>
14 #include <SketchPlugin_Sketch.h>
16 #include <GeomDataAPI_Point2D.h>
17 #include <GeomAPI_Pnt2d.h>
18 #include <GeomAPI_Pnt.h>
20 #include <Config_PropManager.h>
22 SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
26 void SketchPlugin_ConstraintPerpendicular::initAttributes()
28 data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
29 data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
32 void SketchPlugin_ConstraintPerpendicular::execute()
36 AISObjectPtr SketchPlugin_ConstraintPerpendicular::getAISObject(AISObjectPtr thePrevious)
41 std::shared_ptr<ModelAPI_Data> aData = data();
42 std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 = std::dynamic_pointer_cast<
43 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
44 std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 = std::dynamic_pointer_cast<
45 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
46 if (!anAttr1 || !anAttr1->isObject() || !anAttr2 || !anAttr2->isObject())
49 FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object());
52 std::shared_ptr<SketchPlugin_Line> aLine1Feature =
53 std::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
55 aFeature = ModelAPI_Feature::feature(anAttr2->object());
58 std::shared_ptr<SketchPlugin_Line> aLine2Feature =
59 std::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
61 if (!aLine1Feature || !aLine2Feature)
64 std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
65 std::shared_ptr<GeomAPI_Shape> aLine1, aLine2;
66 std::shared_ptr<ModelAPI_ResultConstruction> aConst1 = std::dynamic_pointer_cast<
67 ModelAPI_ResultConstruction>(anAttr1->object());
69 aLine1 = aConst1->shape();
70 std::shared_ptr<ModelAPI_ResultConstruction> aConst2 = std::dynamic_pointer_cast<
71 ModelAPI_ResultConstruction>(anAttr2->object());
73 aLine2 = aConst2->shape();
75 AISObjectPtr anAIS = thePrevious;
77 anAIS = AISObjectPtr(new GeomAPI_AISObject);
78 anAIS->createPerpendicular(aLine1, aLine2, aPlane);
80 // Set color from preferences
81 std::vector<int> aRGB = Config_PropManager::color("Visualization", "perpendicular_color",
83 anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
87 void SketchPlugin_ConstraintPerpendicular::move(double theDeltaX, double theDeltaY)
89 //Flyout point of the constraint follows it's features