Salome HOME
Removed white spaces (Google Style).
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_MultiTranslation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_MultiTranslation.cpp
4 // Created:     09 Feb 2017
5 // Author:      Clarisse Genrault (CEA)
6
7 #include <FeaturesAPI_MultiTranslation.h>
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
11
12 //==================================================================================================
13 FeaturesAPI_MultiTranslation::FeaturesAPI_MultiTranslation(
14   const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
20 //==================================================================================================
21 FeaturesAPI_MultiTranslation::FeaturesAPI_MultiTranslation(
22   const std::shared_ptr<ModelAPI_Feature>& theFeature,
23   const std::list<ModelHighAPI_Selection>& theMainObjects,
24   const ModelHighAPI_Selection& theAxisObject,
25   const ModelHighAPI_Double& theStep,
26   const ModelHighAPI_Integer& theNumber)
27 : ModelHighAPI_Interface(theFeature)
28 {
29   if(initialize()) {
30     fillAttribute(theMainObjects, mainObjects());
31     fillAttribute(theAxisObject, firstAxisObject());
32     fillAttribute(theStep, firstStep());
33     fillAttribute("",useSecondDir());
34     setFirstNumber(theNumber);
35   }
36 }
37
38 //==================================================================================================
39 FeaturesAPI_MultiTranslation::FeaturesAPI_MultiTranslation(
40   const std::shared_ptr<ModelAPI_Feature>& theFeature,
41   const std::list<ModelHighAPI_Selection>& theMainObjects,
42   const ModelHighAPI_Selection& theFirstAxisObject,
43   const ModelHighAPI_Double& theFirstStep,
44   const ModelHighAPI_Integer& theFirstNumber,
45   const ModelHighAPI_Selection& theSecondAxisObject,
46   const ModelHighAPI_Double& theSecondStep,
47   const ModelHighAPI_Integer& theSecondNumber)
48 : ModelHighAPI_Interface(theFeature)
49 {
50   if(initialize()) {
51     fillAttribute(theMainObjects, mainObjects());
52     fillAttribute(theFirstAxisObject, firstAxisObject());
53     fillAttribute(theFirstStep, firstStep());
54     fillAttribute(theFirstNumber, firstNumber());
55     fillAttribute(theSecondAxisObject, secondAxisObject());
56     fillAttribute(theSecondStep, secondStep());
57     fillAttribute("true",useSecondDir());
58     setSecondNumber(theSecondNumber);
59   }
60 }
61
62 //==================================================================================================
63 FeaturesAPI_MultiTranslation::~FeaturesAPI_MultiTranslation()
64 {
65 }
66
67 //==================================================================================================
68 void FeaturesAPI_MultiTranslation::setMainObjects(
69   const std::list<ModelHighAPI_Selection>& theMainObjects)
70 {
71   fillAttribute(theMainObjects, mainObjects());
72
73   execute();
74 }
75
76 //==================================================================================================
77 void FeaturesAPI_MultiTranslation::setFirstAxisAndDistance(
78   const ModelHighAPI_Selection& theAxisObject,
79   const ModelHighAPI_Double& theDistance)
80 {
81   fillAttribute(theAxisObject, firstAxisObject());
82   fillAttribute(theDistance, firstStep());
83
84   execute();
85 }
86
87 //==================================================================================================
88 void FeaturesAPI_MultiTranslation::setSecondAxisAndDistance(
89   const ModelHighAPI_Selection& theAxisObject,
90   const ModelHighAPI_Double& theDistance)
91 {
92   fillAttribute(theAxisObject, secondAxisObject());
93   fillAttribute(theDistance, secondStep());
94
95   execute();
96 }
97
98 //==================================================================================================
99 void FeaturesAPI_MultiTranslation::setFirstNumber(const ModelHighAPI_Integer& theFirstNumber)
100 {
101   fillAttribute(theFirstNumber, firstNumber());
102
103   execute();
104 }
105
106 //==================================================================================================
107 void FeaturesAPI_MultiTranslation::setSecondNumber(const ModelHighAPI_Integer& theSecondNumber)
108 {
109   fillAttribute(theSecondNumber, secondNumber());
110
111   execute();
112 }
113
114 //==================================================================================================
115 void FeaturesAPI_MultiTranslation::dump(ModelHighAPI_Dumper& theDumper) const
116 {
117   FeaturePtr aBase = feature();
118   const std::string& aDocName = theDumper.name(aBase->document());
119
120   AttributeSelectionListPtr anAttrObjects =
121     aBase->selectionList(FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID());
122   theDumper << aBase << " = model.addMultiTranslation(" << aDocName << ", " << anAttrObjects;
123
124   AttributeSelectionPtr anAttrFirstAxis =
125     aBase->selection(FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID());
126   AttributeDoublePtr anAttrFirstStep =
127     aBase->real(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID());
128   AttributeIntegerPtr anAttrFirstNumber =
129     aBase->integer(FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID());
130   theDumper << ", " << anAttrFirstAxis << ", " << anAttrFirstStep;
131   theDumper << ", " << anAttrFirstNumber;
132
133   if (aBase->string(FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID())->isInitialized()
134       && !aBase->string(FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID())->value().empty()) {
135     AttributeSelectionPtr anAttrSecondAxis =
136       aBase->selection(FeaturesPlugin_MultiTranslation::AXIS_SECOND_DIR_ID());
137     AttributeDoublePtr anAttrSecondStep =
138       aBase->real(FeaturesPlugin_MultiTranslation::STEP_SECOND_DIR_ID());
139     AttributeIntegerPtr anAttrSecondNumber =
140       aBase->integer(FeaturesPlugin_MultiTranslation::NB_COPIES_SECOND_DIR_ID());
141     theDumper << ", " << anAttrSecondAxis << ", " << anAttrSecondStep;
142     theDumper << ", " << anAttrSecondStep;
143   }
144
145   theDumper << ")" << std::endl;
146 }
147
148 //==================================================================================================
149 MultiTranslationPtr addMultiTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
150                                         const std::list<ModelHighAPI_Selection>& theMainObjects,
151                                         const ModelHighAPI_Selection& theAxisObject,
152                                         const ModelHighAPI_Double& theStep,
153                                         const ModelHighAPI_Integer& theNumber)
154 {
155   std::shared_ptr<ModelAPI_Feature> aFeature =
156     thePart->addFeature(FeaturesAPI_MultiTranslation::ID());
157   return MultiTranslationPtr(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects,
158                                                               theAxisObject, theStep, theNumber));
159 }
160
161 //==================================================================================================
162 MultiTranslationPtr addMultiTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
163                                         const std::list<ModelHighAPI_Selection>& theMainObjects,
164                                         const ModelHighAPI_Selection& theFirstAxisObject,
165                                         const ModelHighAPI_Double& theFirstStep,
166                                         const ModelHighAPI_Integer& theFirstNumber,
167                                         const ModelHighAPI_Selection& theSecondAxisObject,
168                                         const ModelHighAPI_Double& theSecondStep,
169                                         const ModelHighAPI_Integer& theSecondNumber)
170 {
171   std::shared_ptr<ModelAPI_Feature> aFeature =
172     thePart->addFeature(FeaturesAPI_MultiTranslation::ID());
173   return MultiTranslationPtr(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects,
174                                                               theFirstAxisObject, theFirstStep,
175                                                               theFirstNumber,
176                                                               theSecondAxisObject, theSecondStep,
177                                                               theSecondNumber));
178 }