1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: FeaturesAPI_Revolution.cpp
4 // Created: 09 June 2016
5 // Author: Dmitry Bobylev
7 #include "FeaturesAPI_Revolution.h"
9 #include <ModelHighAPI_Double.h>
10 #include <ModelHighAPI_Dumper.h>
11 #include <ModelHighAPI_Reference.h>
12 #include <ModelHighAPI_Tools.h>
14 //==================================================================================================
15 FeaturesAPI_Revolution::FeaturesAPI_Revolution(const std::shared_ptr<ModelAPI_Feature>& theFeature)
16 : ModelHighAPI_Interface(theFeature)
21 //==================================================================================================
22 FeaturesAPI_Revolution::FeaturesAPI_Revolution(
23 const std::shared_ptr<ModelAPI_Feature>& theFeature,
24 const std::list<ModelHighAPI_Selection>& theBaseObjects,
25 const ModelHighAPI_Selection& theAxis,
26 const ModelHighAPI_Double& theAngle)
27 : ModelHighAPI_Interface(theFeature)
30 fillAttribute(theBaseObjects, mybaseObjects);
31 fillAttribute(theAxis, myaxis);
32 setAngles(theAngle, ModelHighAPI_Double());
36 //==================================================================================================
37 FeaturesAPI_Revolution::FeaturesAPI_Revolution(
38 const std::shared_ptr<ModelAPI_Feature>& theFeature,
39 const std::list<ModelHighAPI_Selection>& theBaseObjects,
40 const ModelHighAPI_Selection& theAxis,
41 const ModelHighAPI_Double& theToAngle,
42 const ModelHighAPI_Double& theFromAngle)
43 : ModelHighAPI_Interface(theFeature)
46 fillAttribute(theBaseObjects, mybaseObjects);
47 fillAttribute(theAxis, myaxis);
48 setAngles(theToAngle, theFromAngle);
52 //==================================================================================================
53 FeaturesAPI_Revolution::FeaturesAPI_Revolution(
54 const std::shared_ptr<ModelAPI_Feature>& theFeature,
55 const std::list<ModelHighAPI_Selection>& theBaseObjects,
56 const ModelHighAPI_Selection& theAxis,
57 const ModelHighAPI_Selection& theToObject,
58 const ModelHighAPI_Double& theToOffset,
59 const ModelHighAPI_Selection& theFromObject,
60 const ModelHighAPI_Double& theFromOffset)
61 : ModelHighAPI_Interface(theFeature)
64 fillAttribute(theBaseObjects, mybaseObjects);
65 fillAttribute(theAxis, myaxis);
66 setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
70 //==================================================================================================
71 FeaturesAPI_Revolution::~FeaturesAPI_Revolution()
76 //==================================================================================================
77 void FeaturesAPI_Revolution::setNestedSketch(const ModelHighAPI_Reference& theSketch)
79 mysketch->setValue(theSketch.feature());
81 // To make Sketch feature execute and subfeatures execute.
82 feature()->document()->setCurrentFeature(feature(), false);
84 // to inform that the history is updated due to the sketch moved under the composite feature
85 if (theSketch.feature().get()) {
86 theSketch.feature()->document()->updateHistory(ModelAPI_Feature::group());
87 if (theSketch.feature()->firstResult().get())
88 theSketch.feature()->firstResult()->setDisplayed(false);
90 mybaseObjects->clear();
91 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
96 //==================================================================================================
97 void FeaturesAPI_Revolution::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
99 mysketch->setValue(ObjectPtr());
100 mybaseObjects->clear();
101 fillAttribute(theBaseObjects, mybaseObjects);
103 execIfBaseNotEmpty();
106 //==================================================================================================
107 void FeaturesAPI_Revolution::setAxis(const ModelHighAPI_Selection& theAxis)
109 fillAttribute(theAxis, myaxis);
111 execIfBaseNotEmpty();
114 //==================================================================================================
115 void FeaturesAPI_Revolution::setAngles(const ModelHighAPI_Double& theToAngle,
116 const ModelHighAPI_Double& theFromAngle)
118 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
119 fillAttribute(theToAngle, mytoAngle);
120 fillAttribute(theFromAngle, myfromAngle);
122 execIfBaseNotEmpty();
125 //==================================================================================================
126 void FeaturesAPI_Revolution::setAngle(const ModelHighAPI_Double& theAngle)
128 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
129 fillAttribute(theAngle, mytoAngle);
130 fillAttribute(ModelHighAPI_Double(), myfromAngle);
132 execIfBaseNotEmpty();
135 //==================================================================================================
136 void FeaturesAPI_Revolution::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
137 const ModelHighAPI_Double& theToOffset,
138 const ModelHighAPI_Selection& theFromObject,
139 const ModelHighAPI_Double& theFromOffset)
141 fillAttribute("ByPlanesAndOffsets", mycreationMethod);
142 fillAttribute(theToObject, mytoObject);
143 fillAttribute(theToOffset, mytoOffset);
144 fillAttribute(theFromObject, myfromObject);
145 fillAttribute(theFromOffset, myfromOffset);
147 execIfBaseNotEmpty();
150 //==================================================================================================
151 void FeaturesAPI_Revolution::dump(ModelHighAPI_Dumper& theDumper) const
153 FeaturePtr aBase = feature();
154 const std::string& aDocName = theDumper.name(aBase->document());
156 AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
157 AttributeSelectionListPtr anAttrObjects =
158 aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
159 AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
161 theDumper << aBase << " = model.addRevolution(" << aDocName << ", ";
162 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
163 theDumper << ", " << anAttrAxis;
165 std::string aCreationMethod =
166 aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
168 if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
169 AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
170 AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
172 theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
173 } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
174 AttributeSelectionPtr anAttrToObject =
175 aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
176 AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
177 AttributeSelectionPtr anAttrFromObject =
178 aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
179 AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
181 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
182 ", " << anAttrFromObject << ", " << anAttrFromOffset;
185 theDumper << ")" << std::endl;
187 if(anAttrSketch->isInitialized()) {
188 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
192 //==================================================================================================
193 void FeaturesAPI_Revolution::execIfBaseNotEmpty()
195 if(mybaseObjects->size() > 0) {
200 //==================================================================================================
201 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
202 const std::list<ModelHighAPI_Selection>& theBaseObjects,
203 const ModelHighAPI_Selection& theAxis,
204 const ModelHighAPI_Double& theAngle)
206 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
207 return RevolutionPtr(new FeaturesAPI_Revolution(aFeature, theBaseObjects, theAxis, theAngle));
210 //==================================================================================================
211 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
212 const std::list<ModelHighAPI_Selection>& theBaseObjects,
213 const ModelHighAPI_Selection& theAxis,
214 const ModelHighAPI_Double& theToAngle,
215 const ModelHighAPI_Double& theFromAngle)
217 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
218 return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,
225 //==================================================================================================
226 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
227 const std::list<ModelHighAPI_Selection>& theBaseObjects,
228 const ModelHighAPI_Selection& theAxis,
229 const ModelHighAPI_Selection& theToObject,
230 const ModelHighAPI_Double& theToOffset,
231 const ModelHighAPI_Selection& theFromObject,
232 const ModelHighAPI_Double& theFromOffset)
234 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
235 return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,