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