1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "FeaturesAPI_Scale.h"
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
26 //==================================================================================================
27 FeaturesAPI_Scale::FeaturesAPI_Scale(const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
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)
41 fillAttribute(theMainObjects, mainObjects());
42 fillAttribute(theCenterPoint, centerPoint());
43 setScaleFactor(theScaleFactor);
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)
57 fillAttribute(theMainObjects, mainObjects());
58 fillAttribute(theCenterPoint, centerPoint());
59 setDimensions(theScaleFactorX, theScaleFactorY, theScaleFactorZ);
63 //==================================================================================================
64 FeaturesAPI_Scale::~FeaturesAPI_Scale()
68 //==================================================================================================
69 void FeaturesAPI_Scale::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
71 fillAttribute(theMainObjects, mainObjects());
75 //==================================================================================================
76 void FeaturesAPI_Scale::setCenterPoint(const ModelHighAPI_Selection& theCenterPoint)
78 fillAttribute(theCenterPoint, centerPoint());
82 //==================================================================================================
83 void FeaturesAPI_Scale::setScaleFactor(const ModelHighAPI_Double& theScaleFactor)
85 fillAttribute(FeaturesPlugin_Scale::CREATION_METHOD_BY_FACTOR(), creationMethod());
86 fillAttribute(theScaleFactor, scaleFactor());
90 //==================================================================================================
91 void FeaturesAPI_Scale::setDimensions(const ModelHighAPI_Double& theScaleFactorX,
92 const ModelHighAPI_Double& theScaleFactorY,
93 const ModelHighAPI_Double& theScaleFactorZ)
95 fillAttribute(FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
96 fillAttribute(theScaleFactorX, scaleFactorX());
97 fillAttribute(theScaleFactorY, scaleFactorY());
98 fillAttribute(theScaleFactorZ, scaleFactorZ());
102 //==================================================================================================
103 void FeaturesAPI_Scale::dump(ModelHighAPI_Dumper& theDumper) const
105 FeaturePtr aBase = feature();
106 const std::string& aDocName = theDumper.name(aBase->document());
108 AttributeSelectionListPtr anAttrObjects =
109 aBase->selectionList(FeaturesPlugin_Scale::OBJECTS_LIST_ID());
110 theDumper << aBase << " = model.addScale(" << aDocName << ", " << anAttrObjects;
112 AttributeSelectionPtr anAttrPoint =
113 aBase->selection(FeaturesPlugin_Scale::CENTER_POINT_ID());
114 theDumper << " , " << anAttrPoint;
116 std::string aCreationMethod =
117 aBase->string(FeaturesPlugin_Scale::CREATION_METHOD())->value();
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;
134 theDumper << ")" << std::endl;
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)
143 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Scale::ID());
144 return ScalePtr(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint, theScaleFactor));
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)
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));