Salome HOME
Issie #204: Size of Fixed constraint depends on object size
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintRigid.cpp
index c9763327e2b6f23f97452473eef478a45c902b2a..847ecfc86238c86c59afe562b3d7b1adb2151727 100644 (file)
@@ -5,6 +5,10 @@
 #include "SketchPlugin_ConstraintRigid.h"
 
 #include <ModelAPI_ResultConstruction.h>
+#include <Config_PropManager.h>
+
+#include <GeomDataAPI_Point2D.h>
+#include <GeomAlgoAPI_PointBuilder.h>
 
 SketchPlugin_ConstraintRigid::SketchPlugin_ConstraintRigid()
 {
@@ -27,16 +31,27 @@ AISObjectPtr SketchPlugin_ConstraintRigid::getAISObject(AISObjectPtr thePrevious
   boost::shared_ptr<ModelAPI_Data> aData = data();
   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = boost::dynamic_pointer_cast<
       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
-  if (!anAttr || !anAttr->isObject())
-    return thePrevious;
-
-  boost::shared_ptr<ModelAPI_ResultConstruction> aConst = 
-    boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr->object());
-  if (!aConst) 
+  if (!anAttr /*|| !anAttr->isObject()*/)
     return thePrevious;
 
   boost::shared_ptr<GeomAPI_Shape> aShape;
-  aShape = aConst->shape();
+
+  if (anAttr->isObject()) {
+    boost::shared_ptr<ModelAPI_ResultConstruction> aConst;
+    aConst = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr->object());
+
+    if (!aConst) 
+      return thePrevious;
+    aShape = aConst->shape();
+  }
+  else {
+    boost::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
+                             boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+    if (!aPointAttr)
+      return thePrevious;
+    boost::shared_ptr<GeomAPI_Pnt> aPoint(sketch()->to3D(aPointAttr->x(), aPointAttr->y()));
+    aShape = GeomAlgoAPI_PointBuilder::point(aPoint);
+  }
 
   AISObjectPtr anAIS = thePrevious;
   if (!anAIS)
@@ -46,9 +61,9 @@ AISObjectPtr SketchPlugin_ConstraintRigid::getAISObject(AISObjectPtr thePrevious
   anAIS->createFixed(aShape, aPlane);
 
   // Set color from preferences
-  //std::vector<int> aRGB = Config_PropManager::color("Visualization", "perpendicular_color",
-  //                                                  PERPENDICULAR_COLOR);
-  //anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
+  std::vector<int> aRGB = Config_PropManager::color("Visualization", "fixing_color",
+                                                    FIXING_COLOR);
+  anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
 
   return anAIS;
 }
\ No newline at end of file