]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
Salome HOME
13ef22dd86cf0f3d1e06d3420b0f01930b01ea1a
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintDistance.cpp
1 // File:    SketchPlugin_ConstraintDistance.cpp
2 // Created: 08 May 2014
3 // Author:  Artem ZHIDKOV
4
5 #include "SketchPlugin_ConstraintDistance.h"
6
7 #include <ModelAPI_AttributeDouble.h>
8 #include <ModelAPI_Data.h>
9 #include <SketchPlugin_Point.h>
10
11 SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance()
12 {
13   myAttrList.push_back(CONSTRAINT_ATTR_DISTANCE);
14 }
15
16 void SketchPlugin_ConstraintDistance::execute()
17 {
18 }
19
20
21 void SketchPlugin_ConstraintDistance::setAttributes(
22           const double                                  theDistance, 
23           const boost::shared_ptr<SketchPlugin_Feature> theEntityA, 
24           const boost::shared_ptr<SketchPlugin_Feature> theEntityB)
25 {
26   // Assign the value of the distance
27   data()->addAttribute(CONSTRAINT_ATTR_DISTANCE, ModelAPI_AttributeDouble::type());
28   boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
29     data()->attribute(CONSTRAINT_ATTR_DISTANCE))->setValue(theDistance);
30
31   // Assign parameters of the constraint
32   std::string aPoints[2] = {CONSTRAINT_ATTR_POINT_A, CONSTRAINT_ATTR_POINT_B};
33   std::string anEntities[2] = {CONSTRAINT_ATTR_ENTITY_A, CONSTRAINT_ATTR_ENTITY_B};
34   int aCurPt = 0;
35   int aCurEnt = 0;
36   std::string aCurAttr;
37   // add entityA depending on its type
38   if (theEntityA->getKind() == SketchPlugin_Point().getKind())
39     aCurAttr = aPoints[aCurPt++];
40   else
41     aCurAttr = anEntities[aCurEnt++];
42   myAttrList.push_back(aCurAttr);
43   data()->addAttribute(aCurAttr, ModelAPI_AttributeReference::type());
44   boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(
45     data()->attribute(aCurAttr))->setValue(theEntityA);
46   // add entityB depending on its type
47   if (theEntityB->getKind() == SketchPlugin_Point().getKind())
48     aCurAttr = aPoints[aCurPt++];
49   else
50     aCurAttr = anEntities[aCurEnt++];
51   myAttrList.push_back(aCurAttr);
52   data()->addAttribute(aCurAttr, ModelAPI_AttributeReference::type());
53   boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(
54     data()->attribute(aCurAttr))->setValue(theEntityB);
55 }
56
57 void SketchPlugin_ConstraintDistance::setAttributes(
58           const double                                  theDistance, 
59           const boost::shared_ptr<ModelAPI_Attribute>   thePoint, 
60           const boost::shared_ptr<SketchPlugin_Feature> theEntity)
61 {
62   // Assign the value of the distance
63   data()->addAttribute(CONSTRAINT_ATTR_DISTANCE, ModelAPI_AttributeDouble::type());
64   boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
65     data()->attribute(CONSTRAINT_ATTR_DISTANCE))->setValue(theDistance);
66
67   // Assign reference to the first point
68   myAttrList.push_back(CONSTRAINT_ATTR_POINT_A);
69   data()->addAttribute(CONSTRAINT_ATTR_POINT_A, ModelAPI_AttributeRefAttr::type());
70   boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
71     data()->attribute(CONSTRAINT_ATTR_POINT_A))->setValue(thePoint);
72
73   // Assign reference to the entity
74   std::string aCurAttr;
75   if (theEntity->getKind() == SketchPlugin_Point().getKind())
76     aCurAttr = CONSTRAINT_ATTR_POINT_B;
77   else
78     aCurAttr = CONSTRAINT_ATTR_ENTITY_A;
79   myAttrList.push_back(aCurAttr);
80   data()->addAttribute(aCurAttr, ModelAPI_AttributeReference::type());
81   boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(
82     data()->attribute(aCurAttr))->setValue(theEntity);
83 }
84
85 void SketchPlugin_ConstraintDistance::setAttributes(
86           const double                                  theDistance, 
87           const boost::shared_ptr<ModelAPI_Attribute>   thePointA, 
88           const boost::shared_ptr<ModelAPI_Attribute>   thePointB)
89 {
90   // Assign the value of the distance
91   data()->addAttribute(CONSTRAINT_ATTR_DISTANCE, ModelAPI_AttributeDouble::type());
92   boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
93     data()->attribute(CONSTRAINT_ATTR_DISTANCE))->setValue(theDistance);
94
95   // Assign reference to the first point
96   myAttrList.push_back(CONSTRAINT_ATTR_POINT_A);
97   data()->addAttribute(CONSTRAINT_ATTR_POINT_A, ModelAPI_AttributeRefAttr::type());
98   boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
99     data()->attribute(CONSTRAINT_ATTR_POINT_A))->setValue(thePointA);
100
101   // Assign reference to the second point
102   myAttrList.push_back(CONSTRAINT_ATTR_POINT_B);
103   data()->addAttribute(CONSTRAINT_ATTR_POINT_B, ModelAPI_AttributeRefAttr::type());
104   boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
105     data()->attribute(CONSTRAINT_ATTR_POINT_B))->setValue(thePointB);
106 }
107
108 void SketchPlugin_ConstraintDistance::setAttributes(
109           const double                                  theRadius, 
110           const boost::shared_ptr<SketchPlugin_Feature> theCircle)
111 {
112    /// \todo Need to be implemented
113 }
114
115 void SketchPlugin_ConstraintDistance::setAttributes(
116           const double                                  theDistance, 
117           const boost::shared_ptr<SketchPlugin_Feature> thePointA, 
118           const boost::shared_ptr<SketchPlugin_Feature> thePointB, 
119           const boost::shared_ptr<SketchPlugin_Feature> theEntity)
120 {
121    /// \todo Need to be implemented. Possibly need to add points by their attributes
122 }
123
124