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()
55 //==================================================================================================
56 void FeaturesAPI_Translation::setMainObjects(
57 const std::list<ModelHighAPI_Selection>& theMainObjects)
59 fillAttribute(theMainObjects, mymainObjects);
64 //==================================================================================================
65 void FeaturesAPI_Translation::setAxisAndDistance(const ModelHighAPI_Selection& theAxisObject,
66 const ModelHighAPI_Double& theDistance)
68 fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE(), mycreationMethod);
69 fillAttribute(theAxisObject, myaxisObject);
70 fillAttribute(theDistance, mydistance);
75 //==================================================================================================
76 void FeaturesAPI_Translation::setDimensions(const ModelHighAPI_Double& theDx,
77 const ModelHighAPI_Double& theDy,
78 const ModelHighAPI_Double& theDz)
80 fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS(), mycreationMethod);
81 fillAttribute(theDx, mydx);
82 fillAttribute(theDy, mydy);
83 fillAttribute(theDz, mydz);
88 //==================================================================================================
89 void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
91 FeaturePtr aBase = feature();
92 const std::string& aDocName = theDumper.name(aBase->document());
94 AttributeSelectionListPtr anAttrObjects =
95 aBase->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
96 theDumper << aBase << " = model.addTranslation(" << aDocName << ", " << anAttrObjects;
98 std::string aCreationMethod =
99 aBase->string(FeaturesPlugin_Translation::CREATION_METHOD())->value();
101 if(aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE()) {
102 AttributeSelectionPtr anAttrAxis =
103 aBase->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
104 AttributeDoublePtr anAttrDistance =
105 aBase->real(FeaturesPlugin_Translation::DISTANCE_ID());
106 theDumper << ", " << anAttrAxis << ", " << anAttrDistance;
107 } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS()) {
108 AttributeDoublePtr anAttrDx = aBase->real(FeaturesPlugin_Translation::DX_ID());
109 AttributeDoublePtr anAttrDy = aBase->real(FeaturesPlugin_Translation::DY_ID());
110 AttributeDoublePtr anAttrDz = aBase->real(FeaturesPlugin_Translation::DZ_ID());
111 theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
114 theDumper << ")" << std::endl;
117 //==================================================================================================
118 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
119 const std::list<ModelHighAPI_Selection>& theMainObjects,
120 const ModelHighAPI_Selection& theAxisObject,
121 const ModelHighAPI_Double& theDistance)
123 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
124 return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
125 theAxisObject, theDistance));
128 //==================================================================================================
129 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
130 const std::list<ModelHighAPI_Selection>& theMainObjects,
131 const ModelHighAPI_Double& theDx,
132 const ModelHighAPI_Double& theDy,
133 const ModelHighAPI_Double& theDz)
135 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
136 return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz));