Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintRigid.cpp
1 // File:    SketchPlugin_ConstraintRigid.cpp
2 // Created: 13 Oct 2014
3 // Author:  Artem ZHIDKOV
4
5 #include "SketchPlugin_ConstraintRigid.h"
6
7 #include <ModelAPI_ResultConstruction.h>
8
9 #include <GeomDataAPI_Point2D.h>
10 #include <GeomAlgoAPI_PointBuilder.h>
11
12 SketchPlugin_ConstraintRigid::SketchPlugin_ConstraintRigid()
13 {
14 }
15
16 void SketchPlugin_ConstraintRigid::initAttributes()
17 {
18   data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
19 }
20
21 void SketchPlugin_ConstraintRigid::execute()
22 {
23 }
24
25 AISObjectPtr SketchPlugin_ConstraintRigid::getAISObject(AISObjectPtr thePrevious)
26 {
27   if (!sketch())
28     return thePrevious;
29
30   boost::shared_ptr<ModelAPI_Data> aData = data();
31   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = boost::dynamic_pointer_cast<
32       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
33   if (!anAttr /*|| !anAttr->isObject()*/)
34     return thePrevious;
35
36   boost::shared_ptr<GeomAPI_Shape> aShape;
37
38   if (anAttr->isObject()) {
39     boost::shared_ptr<ModelAPI_ResultConstruction> aConst;
40     aConst = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr->object());
41
42     if (!aConst) 
43       return thePrevious;
44     aShape = aConst->shape();
45   }
46   else {
47     boost::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
48                              boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
49     if (!aPointAttr)
50       return thePrevious;
51     boost::shared_ptr<GeomAPI_Pnt> aPoint(sketch()->to3D(aPointAttr->x(), aPointAttr->y()));
52     aShape = GeomAlgoAPI_PointBuilder::point(aPoint);
53   }
54
55   AISObjectPtr anAIS = thePrevious;
56   if (!anAIS)
57     anAIS = AISObjectPtr(new GeomAPI_AISObject);
58
59   boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
60   anAIS->createFixed(aShape, aPlane);
61
62   // Set color from preferences
63   //std::vector<int> aRGB = Config_PropManager::color("Visualization", "perpendicular_color",
64   //                                                  PERPENDICULAR_COLOR);
65   //anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
66
67   return anAIS;
68 }