1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "FeaturesAPI_Translation.h"
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
26 //==================================================================================================
27 FeaturesAPI_Translation::FeaturesAPI_Translation(
28 const std::shared_ptr<ModelAPI_Feature>& theFeature)
29 : ModelHighAPI_Interface(theFeature)
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)
43 fillAttribute(theMainObjects, mymainObjects);
44 setAxisAndDistance(theAxisObject, theDistance);
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)
58 fillAttribute(theMainObjects, mymainObjects);
59 setDimensions(theDx, theDy, theDz);
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)
72 fillAttribute(theMainObjects, mymainObjects);
73 setPoints(theStartPoint, theEndPoint);
77 //==================================================================================================
78 FeaturesAPI_Translation::~FeaturesAPI_Translation()
83 //==================================================================================================
84 void FeaturesAPI_Translation::setMainObjects(
85 const std::list<ModelHighAPI_Selection>& theMainObjects)
87 fillAttribute(theMainObjects, mymainObjects);
92 //==================================================================================================
93 void FeaturesAPI_Translation::setAxisAndDistance(const ModelHighAPI_Selection& theAxisObject,
94 const ModelHighAPI_Double& theDistance)
96 fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE(), mycreationMethod);
97 fillAttribute(theAxisObject, myaxisObject);
98 fillAttribute(theDistance, mydistance);
103 //==================================================================================================
104 void FeaturesAPI_Translation::setDimensions(const ModelHighAPI_Double& theDx,
105 const ModelHighAPI_Double& theDy,
106 const ModelHighAPI_Double& theDz)
108 fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS(), mycreationMethod);
109 fillAttribute(theDx, mydx);
110 fillAttribute(theDy, mydy);
111 fillAttribute(theDz, mydz);
116 //==================================================================================================
117 void FeaturesAPI_Translation::setPoints(const ModelHighAPI_Selection& theStartPoint,
118 const ModelHighAPI_Selection& theEndPoint)
120 fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS(), mycreationMethod);
121 fillAttribute(theStartPoint, mystartPoint);
122 fillAttribute(theEndPoint, myendPoint);
127 //==================================================================================================
128 void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
130 FeaturePtr aBase = feature();
131 const std::string& aDocName = theDumper.name(aBase->document());
133 AttributeSelectionListPtr anAttrObjects =
134 aBase->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
135 theDumper << aBase << " = model.addTranslation(" << aDocName << ", " << anAttrObjects;
137 std::string aCreationMethod =
138 aBase->string(FeaturesPlugin_Translation::CREATION_METHOD())->value();
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;
159 theDumper << ")" << std::endl;
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)
168 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
169 return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
170 theAxisObject, theDistance));
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)
180 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
181 return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz));
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)
190 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
191 return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
192 theStartPoint, theEndPoint));