1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <FeaturesAPI_MultiTranslation.h>
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
26 //==================================================================================================
27 FeaturesAPI_MultiTranslation::FeaturesAPI_MultiTranslation(
28 const std::shared_ptr<ModelAPI_Feature>& theFeature)
29 : ModelHighAPI_Interface(theFeature)
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)
44 fillAttribute(theMainObjects, mainObjects());
45 fillAttribute(theAxisObject, firstAxisObject());
46 fillAttribute(theStep, firstStep());
47 fillAttribute("",useSecondDir());
48 setFirstNumber(theNumber);
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)
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);
76 //==================================================================================================
77 FeaturesAPI_MultiTranslation::~FeaturesAPI_MultiTranslation()
81 //==================================================================================================
82 void FeaturesAPI_MultiTranslation::setMainObjects(
83 const std::list<ModelHighAPI_Selection>& theMainObjects)
85 fillAttribute(theMainObjects, mainObjects());
90 //==================================================================================================
91 void FeaturesAPI_MultiTranslation::setFirstAxisAndDistance(
92 const ModelHighAPI_Selection& theAxisObject,
93 const ModelHighAPI_Double& theDistance)
95 fillAttribute(theAxisObject, firstAxisObject());
96 fillAttribute(theDistance, firstStep());
101 //==================================================================================================
102 void FeaturesAPI_MultiTranslation::setSecondAxisAndDistance(
103 const ModelHighAPI_Selection& theAxisObject,
104 const ModelHighAPI_Double& theDistance)
106 fillAttribute(theAxisObject, secondAxisObject());
107 fillAttribute(theDistance, secondStep());
112 //==================================================================================================
113 void FeaturesAPI_MultiTranslation::setFirstNumber(const ModelHighAPI_Integer& theFirstNumber)
115 fillAttribute(theFirstNumber, firstNumber());
120 //==================================================================================================
121 void FeaturesAPI_MultiTranslation::setSecondNumber(const ModelHighAPI_Integer& theSecondNumber)
123 fillAttribute(theSecondNumber, secondNumber());
128 //==================================================================================================
129 void FeaturesAPI_MultiTranslation::dump(ModelHighAPI_Dumper& theDumper) const
131 FeaturePtr aBase = feature();
132 const std::string& aDocName = theDumper.name(aBase->document());
134 AttributeSelectionListPtr anAttrObjects =
135 aBase->selectionList(FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID());
136 theDumper << aBase << " = model.addMultiTranslation(" << aDocName << ", " << anAttrObjects;
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;
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;
159 theDumper << ")" << std::endl;
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)
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));
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)
185 std::shared_ptr<ModelAPI_Feature> aFeature =
186 thePart->addFeature(FeaturesAPI_MultiTranslation::ID());
187 return MultiTranslationPtr(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects,
188 theFirstAxisObject, theFirstStep,
190 theSecondAxisObject, theSecondStep,