1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: FeaturesAPI_Translation.cpp
4 // Created: 07 June 2016
5 // Author: Dmitry Bobylev
7 #include "FeaturesAPI_Translation.h"
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
12 //==================================================================================================
13 FeaturesAPI_Translation::FeaturesAPI_Translation(
14 const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
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)
29 fillAttribute(theMainObjects, mymainObjects);
30 setAxisAndDistance(theAxisObject, theDistance);
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)
44 fillAttribute(theMainObjects, mymainObjects);
45 setDimensions(theDx, theDy, theDz);
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)
58 fillAttribute(theMainObjects, mymainObjects);
59 setPoints(theStartPoint, theEndPoint);
63 //==================================================================================================
64 FeaturesAPI_Translation::~FeaturesAPI_Translation()
69 //==================================================================================================
70 void FeaturesAPI_Translation::setMainObjects(
71 const std::list<ModelHighAPI_Selection>& theMainObjects)
73 fillAttribute(theMainObjects, mymainObjects);
78 //==================================================================================================
79 void FeaturesAPI_Translation::setAxisAndDistance(const ModelHighAPI_Selection& theAxisObject,
80 const ModelHighAPI_Double& theDistance)
82 fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE(), mycreationMethod);
83 fillAttribute(theAxisObject, myaxisObject);
84 fillAttribute(theDistance, mydistance);
89 //==================================================================================================
90 void FeaturesAPI_Translation::setDimensions(const ModelHighAPI_Double& theDx,
91 const ModelHighAPI_Double& theDy,
92 const ModelHighAPI_Double& theDz)
94 fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS(), mycreationMethod);
95 fillAttribute(theDx, mydx);
96 fillAttribute(theDy, mydy);
97 fillAttribute(theDz, mydz);
102 //==================================================================================================
103 void FeaturesAPI_Translation::setPoints(const ModelHighAPI_Selection& theStartPoint,
104 const ModelHighAPI_Selection& theEndPoint)
106 fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS(), mycreationMethod);
107 fillAttribute(theStartPoint, mystartPoint);
108 fillAttribute(theEndPoint, myendPoint);
113 //==================================================================================================
114 void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
116 FeaturePtr aBase = feature();
117 const std::string& aDocName = theDumper.name(aBase->document());
119 AttributeSelectionListPtr anAttrObjects =
120 aBase->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
121 theDumper << aBase << " = model.addTranslation(" << aDocName << ", " << anAttrObjects;
123 std::string aCreationMethod =
124 aBase->string(FeaturesPlugin_Translation::CREATION_METHOD())->value();
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;
145 theDumper << ")" << std::endl;
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)
154 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
155 return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
156 theAxisObject, theDistance));
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)
166 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
167 return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz));
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)
176 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
177 return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
178 theStartPoint, theEndPoint));