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