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