1 // Copyright (C) 2014-2020 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 email : webmaster.salome@opencascade.com
20 #include "FeaturesAPI_Revolution.h"
22 #include <ModelHighAPI_Double.h>
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Reference.h>
25 #include <ModelHighAPI_Tools.h>
27 //==================================================================================================
28 FeaturesAPI_Revolution::FeaturesAPI_Revolution(const std::shared_ptr<ModelAPI_Feature>& theFeature)
29 : ModelHighAPI_Interface(theFeature)
34 //==================================================================================================
35 FeaturesAPI_Revolution::FeaturesAPI_Revolution(
36 const std::shared_ptr<ModelAPI_Feature>& theFeature,
37 const std::list<ModelHighAPI_Selection>& theBaseObjects,
38 const ModelHighAPI_Selection& theAxis,
39 const ModelHighAPI_Double& theAngle)
40 : ModelHighAPI_Interface(theFeature)
43 fillAttribute(theBaseObjects, mybaseObjects);
44 fillAttribute(theAxis, myaxis);
45 setAngles(theAngle, ModelHighAPI_Double());
49 //==================================================================================================
50 FeaturesAPI_Revolution::FeaturesAPI_Revolution(
51 const std::shared_ptr<ModelAPI_Feature>& theFeature,
52 const std::list<ModelHighAPI_Selection>& theBaseObjects,
53 const ModelHighAPI_Selection& theAxis,
54 const ModelHighAPI_Double& theToAngle,
55 const ModelHighAPI_Double& theFromAngle)
56 : ModelHighAPI_Interface(theFeature)
59 fillAttribute(theBaseObjects, mybaseObjects);
60 fillAttribute(theAxis, myaxis);
61 setAngles(theToAngle, theFromAngle);
65 //==================================================================================================
66 FeaturesAPI_Revolution::FeaturesAPI_Revolution(
67 const std::shared_ptr<ModelAPI_Feature>& theFeature,
68 const std::list<ModelHighAPI_Selection>& theBaseObjects,
69 const ModelHighAPI_Selection& theAxis,
70 const ModelHighAPI_Selection& theToObject,
71 const ModelHighAPI_Double& theToOffset,
72 const ModelHighAPI_Selection& theFromObject,
73 const ModelHighAPI_Double& theFromOffset)
74 : ModelHighAPI_Interface(theFeature)
77 fillAttribute(theBaseObjects, mybaseObjects);
78 fillAttribute(theAxis, myaxis);
79 setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
83 //==================================================================================================
84 FeaturesAPI_Revolution::~FeaturesAPI_Revolution()
89 //==================================================================================================
90 void FeaturesAPI_Revolution::setNestedSketch(const ModelHighAPI_Reference& theSketch)
92 mysketch->setValue(theSketch.feature());
94 // To make Sketch feature execute and subfeatures execute.
95 feature()->document()->setCurrentFeature(feature(), false);
97 // to inform that the history is updated due to the sketch moved under the composite feature
98 if (theSketch.feature().get()) {
99 theSketch.feature()->document()->updateHistory(ModelAPI_Feature::group());
100 if (theSketch.feature()->firstResult().get())
101 theSketch.feature()->firstResult()->setDisplayed(false);
103 mybaseObjects->clear();
104 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
106 execIfBaseNotEmpty();
109 //==================================================================================================
110 void FeaturesAPI_Revolution::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
112 mysketch->setValue(ObjectPtr());
113 mybaseObjects->clear();
114 fillAttribute(theBaseObjects, mybaseObjects);
116 execIfBaseNotEmpty();
119 //==================================================================================================
120 void FeaturesAPI_Revolution::setAxis(const ModelHighAPI_Selection& theAxis)
122 fillAttribute(theAxis, myaxis);
124 execIfBaseNotEmpty();
127 //==================================================================================================
128 void FeaturesAPI_Revolution::setAngles(const ModelHighAPI_Double& theToAngle,
129 const ModelHighAPI_Double& theFromAngle)
131 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
132 fillAttribute(theToAngle, mytoAngle);
133 fillAttribute(theFromAngle, myfromAngle);
135 execIfBaseNotEmpty();
138 //==================================================================================================
139 void FeaturesAPI_Revolution::setAngle(const ModelHighAPI_Double& theAngle)
141 setAngles(theAngle, ModelHighAPI_Double());
144 //==================================================================================================
145 void FeaturesAPI_Revolution::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
146 const ModelHighAPI_Double& theToOffset,
147 const ModelHighAPI_Selection& theFromObject,
148 const ModelHighAPI_Double& theFromOffset)
150 fillAttribute("ByPlanesAndOffsets", mycreationMethod);
151 fillAttribute(theToObject, mytoObject);
152 fillAttribute(theToOffset, mytoOffset);
153 fillAttribute(theFromObject, myfromObject);
154 fillAttribute(theFromOffset, myfromOffset);
156 execIfBaseNotEmpty();
159 //==================================================================================================
160 void FeaturesAPI_Revolution::dump(ModelHighAPI_Dumper& theDumper) const
162 FeaturePtr aBase = feature();
163 const std::string& aDocName = theDumper.name(aBase->document());
165 AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
166 AttributeSelectionListPtr anAttrObjects =
167 aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
168 AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
170 theDumper << aBase << " = model.addRevolution(" << aDocName << ", ";
171 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
172 theDumper << ", " << anAttrAxis;
174 std::string aCreationMethod =
175 aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
177 if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
178 AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
179 AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
181 theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
182 } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
183 AttributeSelectionPtr anAttrToObject =
184 aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
185 AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
186 AttributeSelectionPtr anAttrFromObject =
187 aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
188 AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
190 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
191 ", " << anAttrFromObject << ", " << anAttrFromOffset;
194 theDumper << ")" << std::endl;
196 if(anAttrSketch->isInitialized()) {
197 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
201 //==================================================================================================
202 void FeaturesAPI_Revolution::execIfBaseNotEmpty()
204 if(mybaseObjects->size() > 0) {
209 //==================================================================================================
210 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
211 const std::list<ModelHighAPI_Selection>& theBaseObjects,
212 const ModelHighAPI_Selection& theAxis,
213 const ModelHighAPI_Double& theAngle)
215 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
216 return RevolutionPtr(new FeaturesAPI_Revolution(aFeature, theBaseObjects, theAxis, theAngle));
219 //==================================================================================================
220 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
221 const std::list<ModelHighAPI_Selection>& theBaseObjects,
222 const ModelHighAPI_Selection& theAxis,
223 const ModelHighAPI_Double& theToAngle,
224 const ModelHighAPI_Double& theFromAngle)
226 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
227 return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,
234 //==================================================================================================
235 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
236 const std::list<ModelHighAPI_Selection>& theBaseObjects,
237 const ModelHighAPI_Selection& theAxis,
238 const ModelHighAPI_Selection& theToObject,
239 const ModelHighAPI_Double& theToOffset,
240 const ModelHighAPI_Selection& theFromObject,
241 const ModelHighAPI_Double& theFromOffset)
243 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
244 return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,