1 // Copyright (C) 2014-201x CEA/DEN, EDF R&D -->
3 // File: FeaturesAPI_Scale.cpp
4 // Created: 24 Jan 2017
5 // Author: Clarisse Genrault (CEA)
7 #include "FeaturesAPI_Scale.h"
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
12 //==================================================================================================
13 FeaturesAPI_Scale::FeaturesAPI_Scale(const std::shared_ptr<ModelAPI_Feature>& theFeature)
14 : ModelHighAPI_Interface(theFeature)
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)
27 fillAttribute(theMainObjects, mainObjects());
28 fillAttribute(theCenterPoint, centerPoint());
29 setScaleFactor(theScaleFactor);
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)
43 fillAttribute(theMainObjects, mainObjects());
44 fillAttribute(theCenterPoint, centerPoint());
45 setDimensions(theScaleFactorX, theScaleFactorY, theScaleFactorZ);
49 //==================================================================================================
50 FeaturesAPI_Scale::~FeaturesAPI_Scale()
54 //==================================================================================================
55 void FeaturesAPI_Scale::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
57 fillAttribute(theMainObjects, mainObjects());
61 //==================================================================================================
62 void FeaturesAPI_Scale::setCenterPoint(const ModelHighAPI_Selection& theCenterPoint)
64 fillAttribute(theCenterPoint, centerPoint());
68 //==================================================================================================
69 void FeaturesAPI_Scale::setScaleFactor(const ModelHighAPI_Double& theScaleFactor)
71 fillAttribute(FeaturesPlugin_Scale::CREATION_METHOD_BY_FACTOR(), creationMethod());
72 fillAttribute(theScaleFactor, scaleFactor());
76 //==================================================================================================
77 void FeaturesAPI_Scale::setDimensions(const ModelHighAPI_Double& theScaleFactorX,
78 const ModelHighAPI_Double& theScaleFactorY,
79 const ModelHighAPI_Double& theScaleFactorZ)
81 fillAttribute(FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
82 fillAttribute(theScaleFactorX, scaleFactorX());
83 fillAttribute(theScaleFactorY, scaleFactorY());
84 fillAttribute(theScaleFactorZ, scaleFactorZ());
88 //==================================================================================================
89 void FeaturesAPI_Scale::dump(ModelHighAPI_Dumper& theDumper) const
91 FeaturePtr aBase = feature();
92 const std::string& aDocName = theDumper.name(aBase->document());
94 AttributeSelectionListPtr anAttrObjects =
95 aBase->selectionList(FeaturesPlugin_Scale::OBJECTS_LIST_ID());
96 theDumper << aBase << " = model.addScale(" << aDocName << ", " << anAttrObjects;
98 AttributeSelectionPtr anAttrPoint =
99 aBase->selection(FeaturesPlugin_Scale::CENTER_POINT_ID());
100 theDumper << " , " << anAttrPoint;
102 std::string aCreationMethod =
103 aBase->string(FeaturesPlugin_Scale::CREATION_METHOD())->value();
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;
120 theDumper << ")" << std::endl;
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)
129 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Scale::ID());
130 return ScalePtr(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint, theScaleFactor));
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)
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));