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_Revolution.h"
23 #include <ModelHighAPI_Double.h>
24 #include <ModelHighAPI_Dumper.h>
25 #include <ModelHighAPI_Reference.h>
26 #include <ModelHighAPI_Tools.h>
28 //==================================================================================================
29 FeaturesAPI_Revolution::FeaturesAPI_Revolution(const std::shared_ptr<ModelAPI_Feature>& theFeature)
30 : ModelHighAPI_Interface(theFeature)
35 //==================================================================================================
36 FeaturesAPI_Revolution::FeaturesAPI_Revolution(
37 const std::shared_ptr<ModelAPI_Feature>& theFeature,
38 const std::list<ModelHighAPI_Selection>& theBaseObjects,
39 const ModelHighAPI_Selection& theAxis,
40 const ModelHighAPI_Double& theAngle)
41 : ModelHighAPI_Interface(theFeature)
44 fillAttribute(theBaseObjects, mybaseObjects);
45 fillAttribute(theAxis, myaxis);
46 setAngles(theAngle, ModelHighAPI_Double());
50 //==================================================================================================
51 FeaturesAPI_Revolution::FeaturesAPI_Revolution(
52 const std::shared_ptr<ModelAPI_Feature>& theFeature,
53 const std::list<ModelHighAPI_Selection>& theBaseObjects,
54 const ModelHighAPI_Selection& theAxis,
55 const ModelHighAPI_Double& theToAngle,
56 const ModelHighAPI_Double& theFromAngle)
57 : ModelHighAPI_Interface(theFeature)
60 fillAttribute(theBaseObjects, mybaseObjects);
61 fillAttribute(theAxis, myaxis);
62 setAngles(theToAngle, theFromAngle);
66 //==================================================================================================
67 FeaturesAPI_Revolution::FeaturesAPI_Revolution(
68 const std::shared_ptr<ModelAPI_Feature>& theFeature,
69 const std::list<ModelHighAPI_Selection>& theBaseObjects,
70 const ModelHighAPI_Selection& theAxis,
71 const ModelHighAPI_Selection& theToObject,
72 const ModelHighAPI_Double& theToOffset,
73 const ModelHighAPI_Selection& theFromObject,
74 const ModelHighAPI_Double& theFromOffset)
75 : ModelHighAPI_Interface(theFeature)
78 fillAttribute(theBaseObjects, mybaseObjects);
79 fillAttribute(theAxis, myaxis);
80 setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
84 //==================================================================================================
85 FeaturesAPI_Revolution::~FeaturesAPI_Revolution()
90 //==================================================================================================
91 void FeaturesAPI_Revolution::setNestedSketch(const ModelHighAPI_Reference& theSketch)
93 mysketch->setValue(theSketch.feature());
95 // To make Sketch feature execute and subfeatures execute.
96 feature()->document()->setCurrentFeature(feature(), false);
98 // to inform that the history is updated due to the sketch moved under the composite feature
99 if (theSketch.feature().get()) {
100 theSketch.feature()->document()->updateHistory(ModelAPI_Feature::group());
101 if (theSketch.feature()->firstResult().get())
102 theSketch.feature()->firstResult()->setDisplayed(false);
104 mybaseObjects->clear();
105 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
107 execIfBaseNotEmpty();
110 //==================================================================================================
111 void FeaturesAPI_Revolution::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
113 mysketch->setValue(ObjectPtr());
114 mybaseObjects->clear();
115 fillAttribute(theBaseObjects, mybaseObjects);
117 execIfBaseNotEmpty();
120 //==================================================================================================
121 void FeaturesAPI_Revolution::setAxis(const ModelHighAPI_Selection& theAxis)
123 fillAttribute(theAxis, myaxis);
125 execIfBaseNotEmpty();
128 //==================================================================================================
129 void FeaturesAPI_Revolution::setAngles(const ModelHighAPI_Double& theToAngle,
130 const ModelHighAPI_Double& theFromAngle)
132 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
133 fillAttribute(theToAngle, mytoAngle);
134 fillAttribute(theFromAngle, myfromAngle);
136 execIfBaseNotEmpty();
139 //==================================================================================================
140 void FeaturesAPI_Revolution::setAngle(const ModelHighAPI_Double& theAngle)
142 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
143 fillAttribute(theAngle, mytoAngle);
144 fillAttribute(ModelHighAPI_Double(), myfromAngle);
146 execIfBaseNotEmpty();
149 //==================================================================================================
150 void FeaturesAPI_Revolution::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
151 const ModelHighAPI_Double& theToOffset,
152 const ModelHighAPI_Selection& theFromObject,
153 const ModelHighAPI_Double& theFromOffset)
155 fillAttribute("ByPlanesAndOffsets", mycreationMethod);
156 fillAttribute(theToObject, mytoObject);
157 fillAttribute(theToOffset, mytoOffset);
158 fillAttribute(theFromObject, myfromObject);
159 fillAttribute(theFromOffset, myfromOffset);
161 execIfBaseNotEmpty();
164 //==================================================================================================
165 void FeaturesAPI_Revolution::dump(ModelHighAPI_Dumper& theDumper) const
167 FeaturePtr aBase = feature();
168 const std::string& aDocName = theDumper.name(aBase->document());
170 AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
171 AttributeSelectionListPtr anAttrObjects =
172 aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
173 AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
175 theDumper << aBase << " = model.addRevolution(" << aDocName << ", ";
176 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
177 theDumper << ", " << anAttrAxis;
179 std::string aCreationMethod =
180 aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
182 if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
183 AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
184 AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
186 theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
187 } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
188 AttributeSelectionPtr anAttrToObject =
189 aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
190 AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
191 AttributeSelectionPtr anAttrFromObject =
192 aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
193 AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
195 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
196 ", " << anAttrFromObject << ", " << anAttrFromOffset;
199 theDumper << ")" << std::endl;
201 if(anAttrSketch->isInitialized()) {
202 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
206 //==================================================================================================
207 void FeaturesAPI_Revolution::execIfBaseNotEmpty()
209 if(mybaseObjects->size() > 0) {
214 //==================================================================================================
215 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
216 const std::list<ModelHighAPI_Selection>& theBaseObjects,
217 const ModelHighAPI_Selection& theAxis,
218 const ModelHighAPI_Double& theAngle)
220 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
221 return RevolutionPtr(new FeaturesAPI_Revolution(aFeature, theBaseObjects, theAxis, theAngle));
224 //==================================================================================================
225 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
226 const std::list<ModelHighAPI_Selection>& theBaseObjects,
227 const ModelHighAPI_Selection& theAxis,
228 const ModelHighAPI_Double& theToAngle,
229 const ModelHighAPI_Double& theFromAngle)
231 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
232 return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,
239 //==================================================================================================
240 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
241 const std::list<ModelHighAPI_Selection>& theBaseObjects,
242 const ModelHighAPI_Selection& theAxis,
243 const ModelHighAPI_Selection& theToObject,
244 const ModelHighAPI_Double& theToOffset,
245 const ModelHighAPI_Selection& theFromObject,
246 const ModelHighAPI_Double& theFromOffset)
248 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
249 return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,