]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintDistance.cpp
1 // File:    SketchPlugin_ConstraintDistance.cpp
2 // Created: 23 May 2014
3 // Author:  Artem ZHIDKOV
4
5 #include "SketchPlugin_ConstraintDistance.h"
6
7 #include "GeomDataAPI_Point2D.h"
8
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_Data.h>
11 #include <SketchPlugin_Point.h>
12
13 SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance()
14 {
15 }
16
17 void SketchPlugin_ConstraintDistance::initAttributes()
18 {
19   data()->addAttribute(CONSTRAINT_ATTR_VALUE,    ModelAPI_AttributeDouble::type());
20   data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
21   data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
22   data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type());
23 }
24
25 void SketchPlugin_ConstraintDistance::execute()
26 {
27   boost::shared_ptr<ModelAPI_Data> aData = data();
28
29   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr_A = 
30           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
31   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr_B = 
32           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
33
34   AttributeDoublePtr anAttr_Value =
35       boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
36   if (anAttr_A && anAttr_B && !anAttr_Value->isInitialized())
37   {
38     FeaturePtr aFeature_A = anAttr_A->feature();
39     FeaturePtr aFeature_B = anAttr_B->feature();
40
41     double aValue = 40; // TODO
42     anAttr_Value->setValue(aValue);
43   }
44 }
45
46 const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintDistance::preview()
47 {
48   /// \todo Preview for distance constraint
49   return getPreview();
50 }
51