Salome HOME
bugfix for libSketchSolver.so: removing unresolved symbols from the SketchPlugin
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintParallel.cpp
1 // File:    SketchPlugin_ConstraintParallel.cpp
2 // Created: 26 May 2014
3 // Author:  Artem ZHIDKOV
4
5 #include "SketchPlugin_ConstraintParallel.h"
6
7 #include <ModelAPI_AttributeDouble.h>
8 #include <ModelAPI_Data.h>
9 #include <ModelAPI_ResultConstruction.h>
10
11 #include <SketchPlugin_Line.h>
12 #include <SketchPlugin_Sketch.h>
13
14 #include <GeomDataAPI_Point2D.h>
15 #include <GeomAPI_Pnt2d.h>
16 #include <GeomAPI_Pnt.h>
17
18 #include <Config_PropManager.h>
19
20 SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel()
21 {
22 }
23
24 void SketchPlugin_ConstraintParallel::initAttributes()
25 {
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());
29 }
30
31 void SketchPlugin_ConstraintParallel::execute()
32 {
33 }
34
35 AISObjectPtr SketchPlugin_ConstraintParallel::getAISObject(AISObjectPtr thePrevious)
36 {
37   if (!sketch())
38     return thePrevious;
39
40   boost::shared_ptr<ModelAPI_Data> aData = data();
41   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 = 
42     boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
43   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 = 
44     boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
45   if (!anAttr1 || !anAttr1->isObject() || 
46       !anAttr2 || !anAttr2->isObject())
47     return thePrevious;
48
49   FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object());
50   if (!aFeature)
51     return thePrevious;
52   boost::shared_ptr<SketchPlugin_Line> aLine1Feature = 
53     boost::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
54
55   aFeature = ModelAPI_Feature::feature(anAttr2->object());
56   if (!aFeature)
57     return thePrevious;
58   boost::shared_ptr<SketchPlugin_Line> aLine2Feature = 
59     boost::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
60
61   if (!aLine1Feature || !aLine2Feature)
62     return thePrevious;
63
64   boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
65   boost::shared_ptr<GeomAPI_Shape> aLine1, aLine2;
66   boost::shared_ptr<ModelAPI_ResultConstruction> aConst1 = 
67     boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr1->object());
68   if (aConst1) aLine1 = aConst1->shape();
69   boost::shared_ptr<ModelAPI_ResultConstruction> aConst2 = 
70     boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr2->object());
71   if (aConst2) aLine2 = aConst2->shape();
72
73   boost::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = 
74     boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
75   boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
76
77   AISObjectPtr anAIS = thePrevious;
78   if (!anAIS)
79     anAIS = AISObjectPtr(new GeomAPI_AISObject);
80   anAIS->createParallel(aLine1, aLine2, aFlyoutPnt, aPlane);
81
82   // Set color from preferences
83   std::vector<int> aRGB = Config_PropManager::color("Visualization", "parallel_color", PARALLEL_COLOR);
84   anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
85   return anAIS;
86 }
87
88 void SketchPlugin_ConstraintParallel::move(double theDeltaX, double theDeltaY)
89 {
90   boost::shared_ptr<ModelAPI_Data> aData = data();
91   if (!aData->isValid())
92     return;
93
94   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
95         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
96   aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);
97 }
98