Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Translation.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "FeaturesAPI_Translation.h"
22
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
25
26 //==================================================================================================
27 FeaturesAPI_Translation::FeaturesAPI_Translation(
28   const std::shared_ptr<ModelAPI_Feature>& theFeature)
29 : ModelHighAPI_Interface(theFeature)
30 {
31   initialize();
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_Selection& theAxisObject,
39   const ModelHighAPI_Double& theDistance)
40 : ModelHighAPI_Interface(theFeature)
41 {
42   if(initialize()) {
43     fillAttribute(theMainObjects, mymainObjects);
44     setAxisAndDistance(theAxisObject, theDistance);
45   }
46 }
47
48 //==================================================================================================
49 FeaturesAPI_Translation::FeaturesAPI_Translation(
50   const std::shared_ptr<ModelAPI_Feature>& theFeature,
51   const std::list<ModelHighAPI_Selection>& theMainObjects,
52   const ModelHighAPI_Double& theDx,
53   const ModelHighAPI_Double& theDy,
54   const ModelHighAPI_Double& theDz)
55 : ModelHighAPI_Interface(theFeature)
56 {
57   if(initialize()) {
58     fillAttribute(theMainObjects, mymainObjects);
59     setDimensions(theDx, theDy, theDz);
60   }
61 }
62
63 //==================================================================================================
64 FeaturesAPI_Translation::FeaturesAPI_Translation(
65   const std::shared_ptr<ModelAPI_Feature>& theFeature,
66   const std::list<ModelHighAPI_Selection>& theMainObjects,
67   const ModelHighAPI_Selection& theStartPoint,
68   const ModelHighAPI_Selection& theEndPoint)
69 : ModelHighAPI_Interface(theFeature)
70 {
71   if(initialize()) {
72     fillAttribute(theMainObjects, mymainObjects);
73     setPoints(theStartPoint, theEndPoint);
74   }
75 }
76
77 //==================================================================================================
78 FeaturesAPI_Translation::~FeaturesAPI_Translation()
79 {
80
81 }
82
83 //==================================================================================================
84 void FeaturesAPI_Translation::setMainObjects(
85   const std::list<ModelHighAPI_Selection>& theMainObjects)
86 {
87   fillAttribute(theMainObjects, mymainObjects);
88
89   execute();
90 }
91
92 //==================================================================================================
93 void FeaturesAPI_Translation::setAxisAndDistance(const ModelHighAPI_Selection& theAxisObject,
94                                                  const ModelHighAPI_Double& theDistance)
95 {
96   fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE(), mycreationMethod);
97   fillAttribute(theAxisObject, myaxisObject);
98   fillAttribute(theDistance, mydistance);
99
100   execute();
101 }
102
103 //==================================================================================================
104 void FeaturesAPI_Translation::setDimensions(const ModelHighAPI_Double& theDx,
105                                             const ModelHighAPI_Double& theDy,
106                                             const ModelHighAPI_Double& theDz)
107 {
108   fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS(), mycreationMethod);
109   fillAttribute(theDx, mydx);
110   fillAttribute(theDy, mydy);
111   fillAttribute(theDz, mydz);
112
113   execute();
114 }
115
116 //==================================================================================================
117 void FeaturesAPI_Translation::setPoints(const ModelHighAPI_Selection& theStartPoint,
118                                         const ModelHighAPI_Selection& theEndPoint)
119 {
120   fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS(), mycreationMethod);
121   fillAttribute(theStartPoint, mystartPoint);
122   fillAttribute(theEndPoint, myendPoint);
123
124   execute();
125 }
126
127 //==================================================================================================
128 void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
129 {
130   FeaturePtr aBase = feature();
131   const std::string& aDocName = theDumper.name(aBase->document());
132
133   AttributeSelectionListPtr anAttrObjects =
134     aBase->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
135   theDumper << aBase << " = model.addTranslation(" << aDocName << ", " << anAttrObjects;
136
137   std::string aCreationMethod =
138     aBase->string(FeaturesPlugin_Translation::CREATION_METHOD())->value();
139
140   if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE()) {
141     AttributeSelectionPtr anAttrAxis =
142       aBase->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
143     AttributeDoublePtr anAttrDistance =
144       aBase->real(FeaturesPlugin_Translation::DISTANCE_ID());
145     theDumper << ", " << anAttrAxis << ", " << anAttrDistance;
146   } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS()) {
147     AttributeDoublePtr anAttrDx = aBase->real(FeaturesPlugin_Translation::DX_ID());
148     AttributeDoublePtr anAttrDy = aBase->real(FeaturesPlugin_Translation::DY_ID());
149     AttributeDoublePtr anAttrDz = aBase->real(FeaturesPlugin_Translation::DZ_ID());
150     theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
151   } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS()) {
152     AttributeSelectionPtr anAttrStartPoint =
153       aBase->selection(FeaturesPlugin_Translation::START_POINT_ID());
154     AttributeSelectionPtr anAttrEndPoint =
155       aBase->selection(FeaturesPlugin_Translation::END_POINT_ID());
156     theDumper << ", " << anAttrStartPoint << ", " << anAttrEndPoint;
157   }
158
159   theDumper << ")" << std::endl;
160 }
161
162 //==================================================================================================
163 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
164                               const std::list<ModelHighAPI_Selection>& theMainObjects,
165                               const ModelHighAPI_Selection& theAxisObject,
166                               const ModelHighAPI_Double& theDistance)
167 {
168   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
169   return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
170                                                     theAxisObject, theDistance));
171 }
172
173 //==================================================================================================
174 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
175                               const std::list<ModelHighAPI_Selection>& theMainObjects,
176                               const ModelHighAPI_Double& theDx,
177                               const ModelHighAPI_Double& theDy,
178                               const ModelHighAPI_Double& theDz)
179 {
180   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
181   return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz));
182 }
183
184 //==================================================================================================
185 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
186                               const std::list<ModelHighAPI_Selection>& theMainObjects,
187                               const ModelHighAPI_Selection& theStartPoint,
188                               const ModelHighAPI_Selection& theEndPoint)
189 {
190   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
191   return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
192                                                     theStartPoint, theEndPoint));
193 }