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 setAngles(theAngle, ModelHighAPI_Double());
145 //==================================================================================================
146 void FeaturesAPI_Revolution::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
147 const ModelHighAPI_Double& theToOffset,
148 const ModelHighAPI_Selection& theFromObject,
149 const ModelHighAPI_Double& theFromOffset)
151 fillAttribute("ByPlanesAndOffsets", mycreationMethod);
152 fillAttribute(theToObject, mytoObject);
153 fillAttribute(theToOffset, mytoOffset);
154 fillAttribute(theFromObject, myfromObject);
155 fillAttribute(theFromOffset, myfromOffset);
157 execIfBaseNotEmpty();
160 //==================================================================================================
161 void FeaturesAPI_Revolution::dump(ModelHighAPI_Dumper& theDumper) const
163 FeaturePtr aBase = feature();
164 const std::string& aDocName = theDumper.name(aBase->document());
166 AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
167 AttributeSelectionListPtr anAttrObjects =
168 aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
169 AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
171 theDumper << aBase << " = model.addRevolution(" << aDocName << ", ";
172 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
173 theDumper << ", " << anAttrAxis;
175 std::string aCreationMethod =
176 aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
178 if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
179 AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
180 AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
182 theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
183 } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
184 AttributeSelectionPtr anAttrToObject =
185 aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
186 AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
187 AttributeSelectionPtr anAttrFromObject =
188 aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
189 AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
191 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
192 ", " << anAttrFromObject << ", " << anAttrFromOffset;
195 theDumper << ")" << std::endl;
197 if(anAttrSketch->isInitialized()) {
198 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
202 //==================================================================================================
203 void FeaturesAPI_Revolution::execIfBaseNotEmpty()
205 if(mybaseObjects->size() > 0) {
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& theAngle)
216 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
217 return RevolutionPtr(new FeaturesAPI_Revolution(aFeature, theBaseObjects, theAxis, theAngle));
220 //==================================================================================================
221 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
222 const std::list<ModelHighAPI_Selection>& theBaseObjects,
223 const ModelHighAPI_Selection& theAxis,
224 const ModelHighAPI_Double& theToAngle,
225 const ModelHighAPI_Double& theFromAngle)
227 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
228 return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,
235 //==================================================================================================
236 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
237 const std::list<ModelHighAPI_Selection>& theBaseObjects,
238 const ModelHighAPI_Selection& theAxis,
239 const ModelHighAPI_Selection& theToObject,
240 const ModelHighAPI_Double& theToOffset,
241 const ModelHighAPI_Selection& theFromObject,
242 const ModelHighAPI_Double& theFromOffset)
244 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
245 return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,