Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Translation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_Translation.cpp
4 // Created:     07 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "FeaturesAPI_Translation.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
11
12 //==================================================================================================
13 FeaturesAPI_Translation::FeaturesAPI_Translation(
14   const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
20 //==================================================================================================
21 FeaturesAPI_Translation::FeaturesAPI_Translation(
22   const std::shared_ptr<ModelAPI_Feature>& theFeature,
23   const std::list<ModelHighAPI_Selection>& theMainObjects,
24   const ModelHighAPI_Selection& theAxisObject,
25   const ModelHighAPI_Double& theDistance)
26 : ModelHighAPI_Interface(theFeature)
27 {
28   if(initialize()) {
29     fillAttribute(theMainObjects, mymainObjects);
30     setAxisAndDistance(theAxisObject, theDistance);
31   }
32 }
33
34 //==================================================================================================
35 FeaturesAPI_Translation::FeaturesAPI_Translation(
36   const std::shared_ptr<ModelAPI_Feature>& theFeature,
37   const std::list<ModelHighAPI_Selection>& theMainObjects,
38   const ModelHighAPI_Double& theDx,
39   const ModelHighAPI_Double& theDy,
40   const ModelHighAPI_Double& theDz)
41 : ModelHighAPI_Interface(theFeature)
42 {
43   if(initialize()) {
44     fillAttribute(theMainObjects, mymainObjects);
45     setDimensions(theDx, theDy, theDz);
46   }
47 }
48
49 //==================================================================================================
50 FeaturesAPI_Translation::FeaturesAPI_Translation(
51   const std::shared_ptr<ModelAPI_Feature>& theFeature,
52   const std::list<ModelHighAPI_Selection>& theMainObjects,
53   const ModelHighAPI_Selection& theStartPoint,
54   const ModelHighAPI_Selection& theEndPoint)
55 : ModelHighAPI_Interface(theFeature)
56 {
57   if(initialize()) {
58     fillAttribute(theMainObjects, mymainObjects);
59     setPoints(theStartPoint, theEndPoint);
60   }
61 }
62
63 //==================================================================================================
64 FeaturesAPI_Translation::~FeaturesAPI_Translation()
65 {
66
67 }
68
69 //==================================================================================================
70 void FeaturesAPI_Translation::setMainObjects(
71   const std::list<ModelHighAPI_Selection>& theMainObjects)
72 {
73   fillAttribute(theMainObjects, mymainObjects);
74
75   execute();
76 }
77
78 //==================================================================================================
79 void FeaturesAPI_Translation::setAxisAndDistance(const ModelHighAPI_Selection& theAxisObject,
80                                                  const ModelHighAPI_Double& theDistance)
81 {
82   fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE(), mycreationMethod);
83   fillAttribute(theAxisObject, myaxisObject);
84   fillAttribute(theDistance, mydistance);
85
86   execute();
87 }
88
89 //==================================================================================================
90 void FeaturesAPI_Translation::setDimensions(const ModelHighAPI_Double& theDx,
91                                             const ModelHighAPI_Double& theDy,
92                                             const ModelHighAPI_Double& theDz)
93 {
94   fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS(), mycreationMethod);
95   fillAttribute(theDx, mydx);
96   fillAttribute(theDy, mydy);
97   fillAttribute(theDz, mydz);
98
99   execute();
100 }
101
102 //==================================================================================================
103 void FeaturesAPI_Translation::setPoints(const ModelHighAPI_Selection& theStartPoint,
104                                         const ModelHighAPI_Selection& theEndPoint)
105 {
106   fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS(), mycreationMethod);
107   fillAttribute(theStartPoint, mystartPoint);
108   fillAttribute(theEndPoint, myendPoint);
109
110   execute();
111 }
112
113 //==================================================================================================
114 void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
115 {
116   FeaturePtr aBase = feature();
117   const std::string& aDocName = theDumper.name(aBase->document());
118
119   AttributeSelectionListPtr anAttrObjects =
120     aBase->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
121   theDumper << aBase << " = model.addTranslation(" << aDocName << ", " << anAttrObjects;
122
123   std::string aCreationMethod =
124     aBase->string(FeaturesPlugin_Translation::CREATION_METHOD())->value();
125
126   if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE()) {
127     AttributeSelectionPtr anAttrAxis =
128       aBase->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
129     AttributeDoublePtr anAttrDistance =
130       aBase->real(FeaturesPlugin_Translation::DISTANCE_ID());
131     theDumper << ", " << anAttrAxis << ", " << anAttrDistance;
132   } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS()) {
133     AttributeDoublePtr anAttrDx = aBase->real(FeaturesPlugin_Translation::DX_ID());
134     AttributeDoublePtr anAttrDy = aBase->real(FeaturesPlugin_Translation::DY_ID());
135     AttributeDoublePtr anAttrDz = aBase->real(FeaturesPlugin_Translation::DZ_ID());
136     theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
137   } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS()) {
138     AttributeSelectionPtr anAttrStartPoint =
139       aBase->selection(FeaturesPlugin_Translation::START_POINT_ID());
140     AttributeSelectionPtr anAttrEndPoint =
141       aBase->selection(FeaturesPlugin_Translation::END_POINT_ID());
142     theDumper << ", " << anAttrStartPoint << ", " << anAttrEndPoint;
143   }
144
145    theDumper << ")" << std::endl;
146 }
147
148 //==================================================================================================
149 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
150                               const std::list<ModelHighAPI_Selection>& theMainObjects,
151                               const ModelHighAPI_Selection& theAxisObject,
152                               const ModelHighAPI_Double& theDistance)
153 {
154   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
155   return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
156                                                     theAxisObject, theDistance));
157 }
158
159 //==================================================================================================
160 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
161                               const std::list<ModelHighAPI_Selection>& theMainObjects,
162                               const ModelHighAPI_Double& theDx,
163                               const ModelHighAPI_Double& theDy,
164                               const ModelHighAPI_Double& theDz)
165 {
166   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
167   return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz));
168 }
169
170 //==================================================================================================
171 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
172                               const std::list<ModelHighAPI_Selection>& theMainObjects,
173                               const ModelHighAPI_Selection& theStartPoint,
174                               const ModelHighAPI_Selection& theEndPoint)
175 {
176   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
177   return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
178                                                     theStartPoint, theEndPoint));
179 }