1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <FeaturesAPI_MultiTranslation.h>
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
25 //==================================================================================================
26 FeaturesAPI_MultiTranslation::FeaturesAPI_MultiTranslation(
27 const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
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)
43 fillAttribute(theMainObjects, mainObjects());
44 fillAttribute(theAxisObject, firstAxisObject());
45 fillAttribute(theStep, firstStep());
46 fillAttribute("",useSecondDir());
47 setFirstNumber(theNumber);
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)
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);
75 //==================================================================================================
76 FeaturesAPI_MultiTranslation::~FeaturesAPI_MultiTranslation()
80 //==================================================================================================
81 void FeaturesAPI_MultiTranslation::setMainObjects(
82 const std::list<ModelHighAPI_Selection>& theMainObjects)
84 fillAttribute(theMainObjects, mainObjects());
89 //==================================================================================================
90 void FeaturesAPI_MultiTranslation::setFirstAxisAndDistance(
91 const ModelHighAPI_Selection& theAxisObject,
92 const ModelHighAPI_Double& theDistance)
94 fillAttribute(theAxisObject, firstAxisObject());
95 fillAttribute(theDistance, firstStep());
100 //==================================================================================================
101 void FeaturesAPI_MultiTranslation::setSecondAxisAndDistance(
102 const ModelHighAPI_Selection& theAxisObject,
103 const ModelHighAPI_Double& theDistance)
105 fillAttribute(theAxisObject, secondAxisObject());
106 fillAttribute(theDistance, secondStep());
111 //==================================================================================================
112 void FeaturesAPI_MultiTranslation::setFirstNumber(const ModelHighAPI_Integer& theFirstNumber)
114 fillAttribute(theFirstNumber, firstNumber());
119 //==================================================================================================
120 void FeaturesAPI_MultiTranslation::setSecondNumber(const ModelHighAPI_Integer& theSecondNumber)
122 fillAttribute(theSecondNumber, secondNumber());
127 //==================================================================================================
128 void FeaturesAPI_MultiTranslation::dump(ModelHighAPI_Dumper& theDumper) const
130 FeaturePtr aBase = feature();
131 const std::string& aDocName = theDumper.name(aBase->document());
133 AttributeSelectionListPtr anAttrObjects =
134 aBase->selectionList(FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID());
135 theDumper << aBase << " = model.addMultiTranslation(" << aDocName << ", " << anAttrObjects;
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;
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;
158 theDumper << ")" << std::endl;
161 //==================================================================================================
162 MultiTranslationPtr addMultiTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
163 const std::list<ModelHighAPI_Selection>& theMainObjects,
164 const ModelHighAPI_Selection& theAxisObject,
165 const ModelHighAPI_Double& theStep,
166 const ModelHighAPI_Integer& theNumber)
168 std::shared_ptr<ModelAPI_Feature> aFeature =
169 thePart->addFeature(FeaturesAPI_MultiTranslation::ID());
170 return MultiTranslationPtr(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects,
171 theAxisObject, theStep, theNumber));
174 //==================================================================================================
175 MultiTranslationPtr addMultiTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
176 const std::list<ModelHighAPI_Selection>& theMainObjects,
177 const ModelHighAPI_Selection& theFirstAxisObject,
178 const ModelHighAPI_Double& theFirstStep,
179 const ModelHighAPI_Integer& theFirstNumber,
180 const ModelHighAPI_Selection& theSecondAxisObject,
181 const ModelHighAPI_Double& theSecondStep,
182 const ModelHighAPI_Integer& theSecondNumber)
184 std::shared_ptr<ModelAPI_Feature> aFeature =
185 thePart->addFeature(FeaturesAPI_MultiTranslation::ID());
186 return MultiTranslationPtr(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects,
187 theFirstAxisObject, theFirstStep,
189 theSecondAxisObject, theSecondStep,