Salome HOME
Issie #204: Size of Fixed constraint depends on object size
[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 #include <Config_PropManager.h>
9
10 #include <GeomDataAPI_Point2D.h>
11 #include <GeomAlgoAPI_PointBuilder.h>
12
13 SketchPlugin_ConstraintRigid::SketchPlugin_ConstraintRigid()
14 {
15 }
16
17 void SketchPlugin_ConstraintRigid::initAttributes()
18 {
19   data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
20 }
21
22 void SketchPlugin_ConstraintRigid::execute()
23 {
24 }
25
26 AISObjectPtr SketchPlugin_ConstraintRigid::getAISObject(AISObjectPtr thePrevious)
27 {
28   if (!sketch())
29     return thePrevious;
30
31   boost::shared_ptr<ModelAPI_Data> aData = data();
32   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = boost::dynamic_pointer_cast<
33       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
34   if (!anAttr /*|| !anAttr->isObject()*/)
35     return thePrevious;
36
37   boost::shared_ptr<GeomAPI_Shape> aShape;
38
39   if (anAttr->isObject()) {
40     boost::shared_ptr<ModelAPI_ResultConstruction> aConst;
41     aConst = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr->object());
42
43     if (!aConst) 
44       return thePrevious;
45     aShape = aConst->shape();
46   }
47   else {
48     boost::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
49                              boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
50     if (!aPointAttr)
51       return thePrevious;
52     boost::shared_ptr<GeomAPI_Pnt> aPoint(sketch()->to3D(aPointAttr->x(), aPointAttr->y()));
53     aShape = GeomAlgoAPI_PointBuilder::point(aPoint);
54   }
55
56   AISObjectPtr anAIS = thePrevious;
57   if (!anAIS)
58     anAIS = AISObjectPtr(new GeomAPI_AISObject);
59
60   boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
61   anAIS->createFixed(aShape, aPlane);
62
63   // Set color from preferences
64   std::vector<int> aRGB = Config_PropManager::color("Visualization", "fixing_color",
65                                                     FIXING_COLOR);
66   anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
67
68   return anAIS;
69 }