1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "FeaturesAPI_Translation.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
25 //==================================================================================================
26 FeaturesAPI_Translation::FeaturesAPI_Translation(
27 const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
33 //==================================================================================================
34 FeaturesAPI_Translation::FeaturesAPI_Translation(
35 const std::shared_ptr<ModelAPI_Feature>& theFeature,
36 const std::list<ModelHighAPI_Selection>& theMainObjects,
37 const ModelHighAPI_Selection& theAxisObject,
38 const ModelHighAPI_Double& theDistance)
39 : ModelHighAPI_Interface(theFeature)
42 fillAttribute(theMainObjects, mymainObjects);
43 setAxisAndDistance(theAxisObject, theDistance);
47 //==================================================================================================
48 FeaturesAPI_Translation::FeaturesAPI_Translation(
49 const std::shared_ptr<ModelAPI_Feature>& theFeature,
50 const std::list<ModelHighAPI_Selection>& theMainObjects,
51 const ModelHighAPI_Double& theDx,
52 const ModelHighAPI_Double& theDy,
53 const ModelHighAPI_Double& theDz)
54 : ModelHighAPI_Interface(theFeature)
57 fillAttribute(theMainObjects, mymainObjects);
58 setDimensions(theDx, theDy, theDz);
62 //==================================================================================================
63 FeaturesAPI_Translation::FeaturesAPI_Translation(
64 const std::shared_ptr<ModelAPI_Feature>& theFeature,
65 const std::list<ModelHighAPI_Selection>& theMainObjects,
66 const ModelHighAPI_Selection& theStartPoint,
67 const ModelHighAPI_Selection& theEndPoint)
68 : ModelHighAPI_Interface(theFeature)
71 fillAttribute(theMainObjects, mymainObjects);
72 setPoints(theStartPoint, theEndPoint);
76 //==================================================================================================
77 FeaturesAPI_Translation::~FeaturesAPI_Translation()
82 //==================================================================================================
83 void FeaturesAPI_Translation::setMainObjects(
84 const std::list<ModelHighAPI_Selection>& theMainObjects)
86 fillAttribute(theMainObjects, mymainObjects);
91 //==================================================================================================
92 void FeaturesAPI_Translation::setAxisAndDistance(const ModelHighAPI_Selection& theAxisObject,
93 const ModelHighAPI_Double& theDistance)
95 fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE(), mycreationMethod);
96 fillAttribute(theAxisObject, myaxisObject);
97 fillAttribute(theDistance, mydistance);
102 //==================================================================================================
103 void FeaturesAPI_Translation::setDimensions(const ModelHighAPI_Double& theDx,
104 const ModelHighAPI_Double& theDy,
105 const ModelHighAPI_Double& theDz)
107 fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS(), mycreationMethod);
108 fillAttribute(theDx, mydx);
109 fillAttribute(theDy, mydy);
110 fillAttribute(theDz, mydz);
115 //==================================================================================================
116 void FeaturesAPI_Translation::setPoints(const ModelHighAPI_Selection& theStartPoint,
117 const ModelHighAPI_Selection& theEndPoint)
119 fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS(), mycreationMethod);
120 fillAttribute(theStartPoint, mystartPoint);
121 fillAttribute(theEndPoint, myendPoint);
126 //==================================================================================================
127 void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
129 FeaturePtr aBase = feature();
130 const std::string& aDocName = theDumper.name(aBase->document());
132 AttributeSelectionListPtr anAttrObjects =
133 aBase->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
134 theDumper << aBase << " = model.addTranslation(" << aDocName << ", " << anAttrObjects;
136 std::string aCreationMethod =
137 aBase->string(FeaturesPlugin_Translation::CREATION_METHOD())->value();
139 if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE()) {
140 AttributeSelectionPtr anAttrAxis =
141 aBase->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
142 AttributeDoublePtr anAttrDistance =
143 aBase->real(FeaturesPlugin_Translation::DISTANCE_ID());
144 theDumper << ", " << anAttrAxis << ", " << anAttrDistance;
145 } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS()) {
146 AttributeDoublePtr anAttrDx = aBase->real(FeaturesPlugin_Translation::DX_ID());
147 AttributeDoublePtr anAttrDy = aBase->real(FeaturesPlugin_Translation::DY_ID());
148 AttributeDoublePtr anAttrDz = aBase->real(FeaturesPlugin_Translation::DZ_ID());
149 theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
150 } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS()) {
151 AttributeSelectionPtr anAttrStartPoint =
152 aBase->selection(FeaturesPlugin_Translation::START_POINT_ID());
153 AttributeSelectionPtr anAttrEndPoint =
154 aBase->selection(FeaturesPlugin_Translation::END_POINT_ID());
155 theDumper << ", " << anAttrStartPoint << ", " << anAttrEndPoint;
158 theDumper << ")" << std::endl;
161 //==================================================================================================
162 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
163 const std::list<ModelHighAPI_Selection>& theMainObjects,
164 const ModelHighAPI_Selection& theAxisObject,
165 const ModelHighAPI_Double& theDistance)
167 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
168 return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
169 theAxisObject, theDistance));
172 //==================================================================================================
173 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
174 const std::list<ModelHighAPI_Selection>& theMainObjects,
175 const ModelHighAPI_Double& theDx,
176 const ModelHighAPI_Double& theDy,
177 const ModelHighAPI_Double& theDz)
179 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
180 return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz));
183 //==================================================================================================
184 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
185 const std::list<ModelHighAPI_Selection>& theMainObjects,
186 const ModelHighAPI_Selection& theStartPoint,
187 const ModelHighAPI_Selection& theEndPoint)
189 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
190 return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
191 theStartPoint, theEndPoint));