Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Translation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_Translation.cpp
4 // Created:     07 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "FeaturesAPI_Translation.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
11
12 //==================================================================================================
13 FeaturesAPI_Translation::FeaturesAPI_Translation(
14   const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
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)
27 {
28   if(initialize()) {
29     fillAttribute(theMainObjects, mymainObjects);
30     setAxisAndDistance(theAxisObject, theDistance);
31   }
32 }
33
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)
42 {
43   if(initialize()) {
44     fillAttribute(theMainObjects, mymainObjects);
45     setDimensions(theDx, theDy, theDz);
46   }
47 }
48
49 //==================================================================================================
50 FeaturesAPI_Translation::~FeaturesAPI_Translation()
51 {
52
53 }
54
55 //==================================================================================================
56 void FeaturesAPI_Translation::setMainObjects(
57   const std::list<ModelHighAPI_Selection>& theMainObjects)
58 {
59   fillAttribute(theMainObjects, mymainObjects);
60
61   execute();
62 }
63
64 //==================================================================================================
65 void FeaturesAPI_Translation::setAxisAndDistance(const ModelHighAPI_Selection& theAxisObject,
66                                                  const ModelHighAPI_Double& theDistance)
67 {
68   fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE(), mycreationMethod);
69   fillAttribute(theAxisObject, myaxisObject);
70   fillAttribute(theDistance, mydistance);
71
72   execute();
73 }
74
75 //==================================================================================================
76 void FeaturesAPI_Translation::setDimensions(const ModelHighAPI_Double& theDx,
77                                             const ModelHighAPI_Double& theDy,
78                                             const ModelHighAPI_Double& theDz)
79 {
80   fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS(), mycreationMethod);
81   fillAttribute(theDx, mydx);
82   fillAttribute(theDy, mydy);
83   fillAttribute(theDz, mydz);
84
85   execute();
86 }
87
88 //==================================================================================================
89 void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
90 {
91   FeaturePtr aBase = feature();
92   const std::string& aDocName = theDumper.name(aBase->document());
93   
94   AttributeSelectionListPtr anAttrObjects =
95     aBase->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
96   theDumper << aBase << " = model.addTranslation(" << aDocName << ", " << anAttrObjects;
97   
98   std::string aCreationMethod =
99     aBase->string(FeaturesPlugin_Translation::CREATION_METHOD())->value();
100   
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;
112   }
113
114    theDumper << ")" << std::endl;
115 }
116
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)
122 {
123   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
124   return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
125                                                     theAxisObject, theDistance));
126 }
127
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)
134 {
135   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
136   return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz));
137 }