1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: FeaturesAPI_MultiTranslation.cpp
4 // Created: 09 Feb 2017
5 // Author: Clarisse Genrault (CEA)
7 #include <FeaturesAPI_MultiTranslation.h>
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
12 //==================================================================================================
13 FeaturesAPI_MultiTranslation::FeaturesAPI_MultiTranslation(
14 const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
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)
30 fillAttribute(theMainObjects, mainObjects());
31 fillAttribute(theAxisObject, firstAxisObject());
32 fillAttribute(theStep, firstStep());
33 fillAttribute("",useSecondDir());
34 setFirstNumber(theNumber);
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)
51 fillAttribute(theMainObjects, mainObjects());
52 fillAttribute(theFirstAxisObject, firstAxisObject());
53 fillAttribute(theFirstStep, firstStep());
54 fillAttribute(theFirstNumber, firstNumber());
55 fillAttribute(FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID(),useSecondDir());
56 fillAttribute(theSecondAxisObject, secondAxisObject());
57 fillAttribute(theSecondStep, secondStep());
58 setSecondNumber(theSecondNumber);
62 //==================================================================================================
63 FeaturesAPI_MultiTranslation::~FeaturesAPI_MultiTranslation()
67 //==================================================================================================
68 void FeaturesAPI_MultiTranslation::setMainObjects(
69 const std::list<ModelHighAPI_Selection>& theMainObjects)
71 fillAttribute(theMainObjects, mainObjects());
76 //==================================================================================================
77 void FeaturesAPI_MultiTranslation::setFirstAxisAndDistance(
78 const ModelHighAPI_Selection& theAxisObject,
79 const ModelHighAPI_Double& theDistance)
81 fillAttribute(theAxisObject, firstAxisObject());
82 fillAttribute(theDistance, firstStep());
87 //==================================================================================================
88 void FeaturesAPI_MultiTranslation::setSecondAxisAndDistance(
89 const ModelHighAPI_Selection& theAxisObject,
90 const ModelHighAPI_Double& theDistance)
92 fillAttribute(theAxisObject, secondAxisObject());
93 fillAttribute(theDistance, secondStep());
98 //==================================================================================================
99 void FeaturesAPI_MultiTranslation::setFirstNumber(const ModelHighAPI_Integer& theFirstNumber)
101 fillAttribute(theFirstNumber, firstNumber());
106 //==================================================================================================
107 void FeaturesAPI_MultiTranslation::setSecondNumber(const ModelHighAPI_Integer& theSecondNumber)
109 fillAttribute(theSecondNumber, secondNumber());
114 //==================================================================================================
115 void FeaturesAPI_MultiTranslation::dump(ModelHighAPI_Dumper& theDumper) const
117 FeaturePtr aBase = feature();
118 const std::string& aDocName = theDumper.name(aBase->document());
120 AttributeSelectionListPtr anAttrObjects =
121 aBase->selectionList(FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID());
122 theDumper << aBase << " = model.addMultiTranslation(" << aDocName << ", " << anAttrObjects;
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;
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 << ", " << anAttrSecondNumber;
145 theDumper << ")" << std::endl;
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)
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));
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)
171 std::shared_ptr<ModelAPI_Feature> aFeature =
172 thePart->addFeature(FeaturesAPI_MultiTranslation::ID());
173 return MultiTranslationPtr(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects,
174 theFirstAxisObject, theFirstStep,
176 theSecondAxisObject, theSecondStep,