Salome HOME
Merge remote-tracking branch 'remotes/origin/2018_Lot1_Tasks'
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Scale.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "FeaturesAPI_Scale.h"
22
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
25
26 //==================================================================================================
27 FeaturesAPI_Scale::FeaturesAPI_Scale(const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
29 {
30   initialize();
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& theScaleFactor)
38 : ModelHighAPI_Interface(theFeature)
39 {
40   if (initialize()) {
41     fillAttribute(theMainObjects, mainObjects());
42     fillAttribute(theCenterPoint, centerPoint());
43     setScaleFactor(theScaleFactor);
44   }
45 }
46
47 //==================================================================================================
48 FeaturesAPI_Scale::FeaturesAPI_Scale(const std::shared_ptr<ModelAPI_Feature>& theFeature,
49                                      const std::list<ModelHighAPI_Selection>& theMainObjects,
50                                      const ModelHighAPI_Selection& theCenterPoint,
51                                      const ModelHighAPI_Double& theScaleFactorX,
52                                      const ModelHighAPI_Double& theScaleFactorY,
53                                      const ModelHighAPI_Double& theScaleFactorZ)
54 : ModelHighAPI_Interface(theFeature)
55 {
56   if (initialize()) {
57     fillAttribute(theMainObjects, mainObjects());
58     fillAttribute(theCenterPoint, centerPoint());
59     setDimensions(theScaleFactorX, theScaleFactorY, theScaleFactorZ);
60   }
61 }
62
63 //==================================================================================================
64 FeaturesAPI_Scale::~FeaturesAPI_Scale()
65 {
66 }
67
68 //==================================================================================================
69 void FeaturesAPI_Scale::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
70 {
71   fillAttribute(theMainObjects, mainObjects());
72   execute();
73 }
74
75 //==================================================================================================
76 void FeaturesAPI_Scale::setCenterPoint(const ModelHighAPI_Selection& theCenterPoint)
77 {
78   fillAttribute(theCenterPoint, centerPoint());
79   execute();
80 }
81
82 //==================================================================================================
83 void FeaturesAPI_Scale::setScaleFactor(const ModelHighAPI_Double& theScaleFactor)
84 {
85   fillAttribute(FeaturesPlugin_Scale::CREATION_METHOD_BY_FACTOR(), creationMethod());
86   fillAttribute(theScaleFactor, scaleFactor());
87   execute();
88 }
89
90 //==================================================================================================
91 void FeaturesAPI_Scale::setDimensions(const ModelHighAPI_Double& theScaleFactorX,
92                                       const ModelHighAPI_Double& theScaleFactorY,
93                                       const ModelHighAPI_Double& theScaleFactorZ)
94 {
95   fillAttribute(FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
96   fillAttribute(theScaleFactorX, scaleFactorX());
97   fillAttribute(theScaleFactorY, scaleFactorY());
98   fillAttribute(theScaleFactorZ, scaleFactorZ());
99   execute();
100 }
101
102 //==================================================================================================
103 void FeaturesAPI_Scale::dump(ModelHighAPI_Dumper& theDumper) const
104 {
105   FeaturePtr aBase = feature();
106   const std::string& aDocName = theDumper.name(aBase->document());
107
108   AttributeSelectionListPtr anAttrObjects =
109     aBase->selectionList(FeaturesPlugin_Scale::OBJECTS_LIST_ID());
110   theDumper << aBase << " = model.addScale(" << aDocName << ", " << anAttrObjects;
111
112   AttributeSelectionPtr anAttrPoint =
113     aBase->selection(FeaturesPlugin_Scale::CENTER_POINT_ID());
114   theDumper << " , " << anAttrPoint;
115
116   std::string aCreationMethod =
117     aBase->string(FeaturesPlugin_Scale::CREATION_METHOD())->value();
118
119   if (aCreationMethod == FeaturesPlugin_Scale::CREATION_METHOD_BY_FACTOR()) {
120     AttributeDoublePtr anAttrScaleFactor =
121       aBase->real(FeaturesPlugin_Scale::SCALE_FACTOR_ID());
122     theDumper << ", " << anAttrScaleFactor;
123   } else if (aCreationMethod == FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS()) {
124     AttributeDoublePtr anAttrScaleFactorX =
125       aBase->real(FeaturesPlugin_Scale::SCALE_FACTOR_X_ID());
126     AttributeDoublePtr anAttrScaleFactorY =
127       aBase->real(FeaturesPlugin_Scale::SCALE_FACTOR_Y_ID());
128     AttributeDoublePtr anAttrScaleFactorZ =
129       aBase->real(FeaturesPlugin_Scale::SCALE_FACTOR_Z_ID());
130     theDumper << ", " << anAttrScaleFactorX << " , " << anAttrScaleFactorY;
131     theDumper << ", " << anAttrScaleFactorZ;
132   }
133
134   theDumper << ")" << std::endl;
135 }
136
137 //==================================================================================================
138 ScalePtr addScale(const std::shared_ptr<ModelAPI_Document>& thePart,
139                   const std::list<ModelHighAPI_Selection>& theMainObjects,
140                   const ModelHighAPI_Selection& theCenterPoint,
141                   const ModelHighAPI_Double& theScaleFactor)
142 {
143   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Scale::ID());
144   return ScalePtr(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint, theScaleFactor));
145 }
146
147 //==================================================================================================
148 ScalePtr addScale(const std::shared_ptr<ModelAPI_Document>& thePart,
149                   const std::list<ModelHighAPI_Selection>& theMainObjects,
150                   const ModelHighAPI_Selection& theCenterPoint,
151                   const ModelHighAPI_Double& theScaleFactorX,
152                   const ModelHighAPI_Double& theScaleFactorY,
153                   const ModelHighAPI_Double& theScaleFactorZ)
154 {
155   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Scale::ID());
156   return ScalePtr(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint,
157                   theScaleFactorX, theScaleFactorY, theScaleFactorZ));
158 }