Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Scale.cpp
1 // Copyright (C) 2014-201x CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_Scale.cpp
4 // Created:     24 Jan 2017
5 // Author:      Clarisse Genrault (CEA)
6
7 #include "FeaturesAPI_Scale.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
11
12 //==================================================================================================
13 FeaturesAPI_Scale::FeaturesAPI_Scale(const std::shared_ptr<ModelAPI_Feature>& theFeature)
14 : ModelHighAPI_Interface(theFeature)
15 {
16   initialize();
17 }
18
19 //==================================================================================================
20 FeaturesAPI_Scale::FeaturesAPI_Scale(const std::shared_ptr<ModelAPI_Feature>& theFeature,
21                                      const std::list<ModelHighAPI_Selection>& theMainObjects,
22                                      const ModelHighAPI_Selection& theCenterPoint,
23                                      const ModelHighAPI_Double& theScaleFactor)
24 : ModelHighAPI_Interface(theFeature)
25 {
26   if (initialize()) {
27     fillAttribute(theMainObjects, mainObjects());
28     fillAttribute(theCenterPoint, centerPoint());
29     setScaleFactor(theScaleFactor);
30   }
31 }
32
33 //==================================================================================================
34 FeaturesAPI_Scale::FeaturesAPI_Scale(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35                                      const std::list<ModelHighAPI_Selection>& theMainObjects,
36                                      const ModelHighAPI_Selection& theCenterPoint,
37                                      const ModelHighAPI_Double& theScaleFactorX,
38                                      const ModelHighAPI_Double& theScaleFactorY,
39                                      const ModelHighAPI_Double& theScaleFactorZ)
40 : ModelHighAPI_Interface(theFeature)
41 {
42   if (initialize()) {
43     fillAttribute(theMainObjects, mainObjects());
44     fillAttribute(theCenterPoint, centerPoint());
45     setDimensions(theScaleFactorX, theScaleFactorY, theScaleFactorZ);
46   }
47 }
48
49 //==================================================================================================
50 FeaturesAPI_Scale::~FeaturesAPI_Scale()
51 {
52 }
53
54 //==================================================================================================
55 void FeaturesAPI_Scale::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
56 {
57   fillAttribute(theMainObjects, mainObjects());
58   execute();
59 }
60
61 //==================================================================================================
62 void FeaturesAPI_Scale::setCenterPoint(const ModelHighAPI_Selection& theCenterPoint)
63 {
64   fillAttribute(theCenterPoint, centerPoint());
65   execute();
66 }
67
68 //==================================================================================================
69 void FeaturesAPI_Scale::setScaleFactor(const ModelHighAPI_Double& theScaleFactor)
70 {
71   fillAttribute(FeaturesPlugin_Scale::CREATION_METHOD_BY_FACTOR(), creationMethod());
72   fillAttribute(theScaleFactor, scaleFactor());
73   execute();
74 }
75
76 //==================================================================================================
77 void FeaturesAPI_Scale::setDimensions(const ModelHighAPI_Double& theScaleFactorX,
78                                       const ModelHighAPI_Double& theScaleFactorY,
79                                       const ModelHighAPI_Double& theScaleFactorZ)
80 {
81   fillAttribute(FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
82   fillAttribute(theScaleFactorX, scaleFactorX());
83   fillAttribute(theScaleFactorY, scaleFactorY());
84   fillAttribute(theScaleFactorZ, scaleFactorZ());
85   execute();
86 }
87
88 //==================================================================================================
89 void FeaturesAPI_Scale::dump(ModelHighAPI_Dumper& theDumper) const
90 {
91   FeaturePtr aBase = feature();
92   const std::string& aDocName = theDumper.name(aBase->document());
93
94   AttributeSelectionListPtr anAttrObjects =
95     aBase->selectionList(FeaturesPlugin_Scale::OBJECTS_LIST_ID());
96   theDumper << aBase << " = model.addScale(" << aDocName << ", " << anAttrObjects;
97
98   AttributeSelectionPtr anAttrPoint =
99     aBase->selection(FeaturesPlugin_Scale::CENTER_POINT_ID());
100   theDumper << " , " << anAttrPoint;
101
102   std::string aCreationMethod =
103     aBase->string(FeaturesPlugin_Scale::CREATION_METHOD())->value();
104
105   if (aCreationMethod == FeaturesPlugin_Scale::CREATION_METHOD_BY_FACTOR()) {
106     AttributeDoublePtr anAttrScaleFactor =
107       aBase->real(FeaturesPlugin_Scale::SCALE_FACTOR_ID());
108     theDumper << ", " << anAttrScaleFactor;
109   } else if (aCreationMethod == FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS()) {
110     AttributeDoublePtr anAttrScaleFactorX =
111       aBase->real(FeaturesPlugin_Scale::SCALE_FACTOR_X_ID());
112     AttributeDoublePtr anAttrScaleFactorY =
113       aBase->real(FeaturesPlugin_Scale::SCALE_FACTOR_Y_ID());
114     AttributeDoublePtr anAttrScaleFactorZ =
115       aBase->real(FeaturesPlugin_Scale::SCALE_FACTOR_Z_ID());
116     theDumper << ", " << anAttrScaleFactorX << " , " << anAttrScaleFactorY;
117     theDumper << ", " << anAttrScaleFactorZ;
118   }
119
120   theDumper << ")" << std::endl;
121 }
122
123 //==================================================================================================
124 ScalePtr addScale(const std::shared_ptr<ModelAPI_Document>& thePart,
125                   const std::list<ModelHighAPI_Selection>& theMainObjects,
126                   const ModelHighAPI_Selection& theCenterPoint,
127                   const ModelHighAPI_Double& theScaleFactor)
128 {
129   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Scale::ID());
130   return ScalePtr(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint, theScaleFactor));
131 }
132
133 //==================================================================================================
134 ScalePtr addScale(const std::shared_ptr<ModelAPI_Document>& thePart,
135                   const std::list<ModelHighAPI_Selection>& theMainObjects,
136                   const ModelHighAPI_Selection& theCenterPoint,
137                   const ModelHighAPI_Double& theScaleFactorX,
138                   const ModelHighAPI_Double& theScaleFactorY,
139                   const ModelHighAPI_Double& theScaleFactorZ)
140 {
141   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Scale::ID());
142   return ScalePtr(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint,
143                   theScaleFactorX, theScaleFactorY, theScaleFactorZ));
144 }