Salome HOME
Added MultiRotation feature (parametric API).
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_MultiRotation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_MultiRotation.cpp
4 // Created:     04 Apr 2017
5 // Author:      Clarisse Genrault (CEA)
6
7 #include <FeaturesAPI_MultiRotation.h>
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
11
12 //==================================================================================================
13 FeaturesAPI_MultiRotation::FeaturesAPI_MultiRotation(
14   const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
20
21 //==================================================================================================
22 FeaturesAPI_MultiRotation::FeaturesAPI_MultiRotation(
23   const std::shared_ptr<ModelAPI_Feature>& theFeature,
24   const std::list<ModelHighAPI_Selection>& theMainObjects,
25   const ModelHighAPI_Selection& theAxis,
26   const ModelHighAPI_Integer& theNumber)
27 : ModelHighAPI_Interface(theFeature)
28 {
29   if(initialize()) {
30     fillAttribute(theMainObjects, mainObjects());
31     fillAttribute(theAxis, axisAngular());
32     fillAttribute("",useStepAngular());
33     setNumberAngular(theNumber);
34   }
35 }
36
37 //==================================================================================================
38 FeaturesAPI_MultiRotation::FeaturesAPI_MultiRotation(
39   const std::shared_ptr<ModelAPI_Feature>& theFeature,
40   const std::list<ModelHighAPI_Selection>& theMainObjects,
41   const ModelHighAPI_Selection& theAxis,
42   const ModelHighAPI_Double& theStep,
43   const ModelHighAPI_Integer& theNumber)
44 : ModelHighAPI_Interface(theFeature)
45 {
46   if(initialize()) {
47     fillAttribute(theMainObjects, mainObjects());
48     fillAttribute(theAxis, axisAngular());
49     fillAttribute(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID(),useStepAngular());
50     fillAttribute(theStep, stepAngular());
51     setNumberAngular(theNumber);
52   }
53 }
54
55 //==================================================================================================
56 FeaturesAPI_MultiRotation::~FeaturesAPI_MultiRotation()
57 {
58 }
59
60 //==================================================================================================
61 void FeaturesAPI_MultiRotation::setMainObjects(
62   const std::list<ModelHighAPI_Selection>& theMainObjects)
63 {
64   fillAttribute(theMainObjects, mainObjects());
65
66   execute();
67 }
68
69 //==================================================================================================
70 void FeaturesAPI_MultiRotation::setAxisAngular(const ModelHighAPI_Selection& theAxis)
71 {
72   fillAttribute(theAxis, axisAngular());
73
74   execute();
75 }
76
77 //==================================================================================================
78 void FeaturesAPI_MultiRotation::setStepAngular(const ModelHighAPI_Double& theStep)
79 {
80   fillAttribute(theStep, stepAngular());
81
82   execute();
83 }
84
85 //==================================================================================================
86 void FeaturesAPI_MultiRotation::setNumberAngular(const ModelHighAPI_Integer& theNumber)
87 {
88   fillAttribute(theNumber, nbAngular());
89
90   execute();
91 }
92
93 //==================================================================================================
94 void FeaturesAPI_MultiRotation::dump(ModelHighAPI_Dumper& theDumper) const
95 {
96   FeaturePtr aBase = feature();
97   const std::string& aDocName = theDumper.name(aBase->document());
98
99   AttributeSelectionListPtr anAttrObjects =
100     aBase->selectionList(FeaturesPlugin_MultiRotation::OBJECTS_LIST_ID());
101   theDumper << aBase << " = model.addMultiRotation(" << aDocName << ", " << anAttrObjects;
102
103   AttributeSelectionPtr anAttrAxis =
104     aBase->selection(FeaturesPlugin_MultiRotation::AXIS_ANGULAR_ID());
105   theDumper << ", " << anAttrAxis;
106
107   if (aBase->string(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID())->isInitialized()
108       && !aBase->string(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID())->value().empty()) {
109     AttributeDoublePtr anAttrStepAngular =
110       aBase->real(FeaturesPlugin_MultiRotation::STEP_ANGULAR_ID());
111       theDumper << ", " << anAttrStepAngular;
112   }
113
114   AttributeIntegerPtr anAttrNumberAngular =
115     aBase->integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID());
116   theDumper << ", " << anAttrNumberAngular;
117
118   theDumper << ")" << std::endl;
119 }
120
121 //==================================================================================================
122 MultiRotationPtr addMultiRotation(const std::shared_ptr<ModelAPI_Document>& thePart,
123                                   const std::list<ModelHighAPI_Selection>& theMainObjects,
124                                   const ModelHighAPI_Selection& theAxis,
125                                   const ModelHighAPI_Integer& theNumber)
126 {
127   std::shared_ptr<ModelAPI_Feature> aFeature =
128     thePart->addFeature(FeaturesAPI_MultiRotation::ID());
129   return MultiRotationPtr(new FeaturesAPI_MultiRotation(aFeature, theMainObjects,
130                                                         theAxis, theNumber));
131 }
132
133 //==================================================================================================
134 MultiRotationPtr addMultiRotation(const std::shared_ptr<ModelAPI_Document>& thePart,
135                                   const std::list<ModelHighAPI_Selection>& theMainObjects,
136                                   const ModelHighAPI_Selection& theAxis,
137                                   const ModelHighAPI_Double& theStep,
138                                   const ModelHighAPI_Integer& theNumber)
139 {
140   std::shared_ptr<ModelAPI_Feature> aFeature =
141     thePart->addFeature(FeaturesAPI_MultiRotation::ID());
142   return MultiRotationPtr(new FeaturesAPI_MultiRotation(aFeature, theMainObjects,
143                                                         theAxis, theStep, theNumber));
144 }