1 // Copyright (C) 2014-2021 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 << ", axis = " << anAttrAxis << ", distance = " << 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 << ", vector = [" << 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 << ", startPoint = " << anAttrStartPoint << ", endPoint = " << anAttrEndPoint;
158 if (!aBase->data()->version().empty())
159 theDumper << ", keepSubResults = True";
161 theDumper << ")" << std::endl;
164 //==================================================================================================
165 TranslationPtr addTranslation(
166 const std::shared_ptr<ModelAPI_Document>& part,
167 const std::list<ModelHighAPI_Selection>& objects,
168 const std::pair<ModelHighAPI_Selection, ModelHighAPI_Double>& deprecated1,
169 const std::pair<ModelHighAPI_Selection, ModelHighAPI_Double>& deprecated2,
170 const std::pair<ModelHighAPI_Selection, ModelHighAPI_Double>& deprecated3,
171 const ModelHighAPI_Selection& axis, const ModelHighAPI_Double& distance,
172 const std::list<ModelHighAPI_Double>& vector,
173 const ModelHighAPI_Selection& startPoint, const ModelHighAPI_Selection& endPoint,
174 const bool keepSubResults)
176 std::shared_ptr<ModelAPI_Feature> aFeature = part->addFeature(FeaturesAPI_Translation::ID());
178 aFeature->data()->setVersion("");
180 static const int VEC_SIZE = 3;
182 bool byAxis = axis.variantType() != ModelHighAPI_Selection::VT_Empty;
183 bool byVector = vector.size() == VEC_SIZE;
184 bool byPoints = startPoint.variantType() != ModelHighAPI_Selection::VT_Empty &&
185 endPoint.variantType() != ModelHighAPI_Selection::VT_Empty;
187 ModelHighAPI_Selection firstSel, secondSel;
188 ModelHighAPI_Double values[VEC_SIZE];
191 values[0] = distance;
194 std::list<ModelHighAPI_Double>::const_iterator it = vector.begin();
195 for (ModelHighAPI_Double* vIt = values; it != vector.end(); ++vIt, ++it)
199 firstSel = startPoint;
200 secondSel = endPoint;
203 byVector = deprecated1.first.variantType() == ModelHighAPI_Selection::VT_Empty;
205 values[0] = deprecated1.second;
206 values[1] = deprecated2.second;
207 values[2] = deprecated3.second;
210 firstSel = deprecated1.first;
211 secondSel = deprecated2.first;
212 values[0] = deprecated2.second;
213 if (secondSel.variantType() == ModelHighAPI_Selection::VT_Empty)
220 TranslationPtr aTranslation;
222 aTranslation.reset(new FeaturesAPI_Translation(aFeature, objects, firstSel, values[0]));
224 aTranslation.reset(new FeaturesAPI_Translation(aFeature, objects,
225 values[0], values[1], values[2]));
228 aTranslation.reset(new FeaturesAPI_Translation(aFeature, objects, firstSel, secondSel));