1 // Copyright (C) 2014-2023 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "FeaturesAPI_Scale.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
25 //==================================================================================================
26 FeaturesAPI_Scale::FeaturesAPI_Scale(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
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)
40 fillAttribute(theMainObjects, mainObjects());
41 fillAttribute(theCenterPoint, centerPoint());
42 setScaleFactor(theScaleFactor);
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)
56 fillAttribute(theMainObjects, mainObjects());
57 fillAttribute(theCenterPoint, centerPoint());
58 setDimensions(theScaleFactorX, theScaleFactorY, theScaleFactorZ);
62 //==================================================================================================
63 FeaturesAPI_Scale::~FeaturesAPI_Scale()
67 //==================================================================================================
68 void FeaturesAPI_Scale::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
70 fillAttribute(theMainObjects, mainObjects());
74 //==================================================================================================
75 void FeaturesAPI_Scale::setCenterPoint(const ModelHighAPI_Selection& theCenterPoint)
77 fillAttribute(theCenterPoint, centerPoint());
81 //==================================================================================================
82 void FeaturesAPI_Scale::setScaleFactor(const ModelHighAPI_Double& theScaleFactor)
84 fillAttribute(FeaturesPlugin_Scale::CREATION_METHOD_BY_FACTOR(), creationMethod());
85 fillAttribute(theScaleFactor, scaleFactor());
89 //==================================================================================================
90 void FeaturesAPI_Scale::setDimensions(const ModelHighAPI_Double& theScaleFactorX,
91 const ModelHighAPI_Double& theScaleFactorY,
92 const ModelHighAPI_Double& theScaleFactorZ)
94 fillAttribute(FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
95 fillAttribute(theScaleFactorX, scaleFactorX());
96 fillAttribute(theScaleFactorY, scaleFactorY());
97 fillAttribute(theScaleFactorZ, scaleFactorZ());
101 //==================================================================================================
102 void FeaturesAPI_Scale::dump(ModelHighAPI_Dumper& theDumper) const
104 FeaturePtr aBase = feature();
105 const std::string& aDocName = theDumper.name(aBase->document());
107 AttributeSelectionListPtr anAttrObjects =
108 aBase->selectionList(FeaturesPlugin_Scale::OBJECTS_LIST_ID());
109 theDumper << aBase << " = model.addScale(" << aDocName << ", " << anAttrObjects;
111 AttributeSelectionPtr anAttrPoint =
112 aBase->selection(FeaturesPlugin_Scale::CENTER_POINT_ID());
113 theDumper << " , " << anAttrPoint;
115 std::string aCreationMethod =
116 aBase->string(FeaturesPlugin_Scale::CREATION_METHOD())->value();
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;
133 if (!aBase->data()->version().empty())
134 theDumper << ", keepSubResults = True";
136 theDumper << ")" << std::endl;
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)
148 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Scale::ID());
150 aFeature->data()->setVersion("");
152 if (theScaleFactorY.value() == 0 && theScaleFactorZ.value() == 0)
153 aScale.reset(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint, theScaleFactorX));
155 aScale.reset(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint,
156 theScaleFactorX, theScaleFactorY, theScaleFactorZ));