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