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