1 // Copyright (C) 2017-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_Fillet.h"
22 #include <ModelHighAPI_Double.h>
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Selection.h>
25 #include <ModelHighAPI_Tools.h>
27 static GeomAPI_Shape::ShapeType typeOfSelection(
28 const std::list<ModelHighAPI_Selection>& theBaseObjects)
30 std::string aType = theBaseObjects.empty() ? "SHAPE" : theBaseObjects.front().shapeType();
31 return GeomAPI_Shape::shapeTypeByStr(aType);
34 //==================================================================================================
36 FeaturesAPI_Fillet::FeaturesAPI_Fillet(const std::shared_ptr<ModelAPI_Feature>& theFeature)
37 : ModelHighAPI_Interface(theFeature)
41 //==================================================================================================
43 FeaturesAPI_Fillet1D::FeaturesAPI_Fillet1D(const std::shared_ptr<ModelAPI_Feature>& theFeature)
44 : FeaturesAPI_Fillet(theFeature)
49 FeaturesAPI_Fillet1D::FeaturesAPI_Fillet1D(const std::shared_ptr<ModelAPI_Feature>& theFeature,
50 const std::list<ModelHighAPI_Selection>& theBaseObjects,
51 const ModelHighAPI_Double& theRadius)
52 : FeaturesAPI_Fillet(theFeature)
55 setBase(theBaseObjects);
56 fillAttribute(theRadius, myradius);
62 FeaturesAPI_Fillet1D::~FeaturesAPI_Fillet1D()
66 void FeaturesAPI_Fillet1D::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
69 mybaseVertices->clear();
71 if (typeOfSelection(theBaseObjects) == GeomAPI_Shape::WIRE) {
72 fillAttribute(FeaturesPlugin_Fillet1D::CREATION_BY_WIRES(), mycreationMethod);
73 fillAttribute(theBaseObjects, mybaseWires);
76 fillAttribute(FeaturesPlugin_Fillet1D::CREATION_BY_VERTICES(), mycreationMethod);
77 fillAttribute(theBaseObjects, mybaseVertices);
83 void FeaturesAPI_Fillet1D::setRadius(const ModelHighAPI_Double& theRadius)
85 fillAttribute(theRadius, myradius);
89 void FeaturesAPI_Fillet1D::execIfBaseNotEmpty()
91 if (mybaseWires->size() > 0 || mybaseVertices->size() > 0)
95 void FeaturesAPI_Fillet1D::dump(ModelHighAPI_Dumper& theDumper) const
97 FeaturePtr aBase = feature();
98 const std::string& aDocName = theDumper.name(aBase->document());
100 AttributeSelectionListPtr anAttrObjects;
101 if (creationMethod()->value() == FeaturesPlugin_Fillet1D::CREATION_BY_WIRES())
102 anAttrObjects = aBase->selectionList(FeaturesPlugin_Fillet1D::WIRE_LIST_ID());
103 else if (creationMethod()->value() == FeaturesPlugin_Fillet1D::CREATION_BY_VERTICES())
104 anAttrObjects = aBase->selectionList(FeaturesPlugin_Fillet1D::VERTEX_LIST_ID());
106 AttributeDoublePtr anAttrRadius = aBase->real(FeaturesPlugin_Fillet1D::RADIUS_ID());
108 theDumper << aBase << " = model.addFillet(" << aDocName << ", " << anAttrObjects
109 << ", " << anAttrRadius;
111 if (!aBase->data()->version().empty())
112 theDumper << ", keepSubResults = True";
114 theDumper << ")" << std::endl;
117 //==================================================================================================
119 FeaturesAPI_Fillet2D::FeaturesAPI_Fillet2D(const std::shared_ptr<ModelAPI_Feature>& theFeature)
120 : FeaturesAPI_Fillet(theFeature)
125 FeaturesAPI_Fillet2D::FeaturesAPI_Fillet2D(const std::shared_ptr<ModelAPI_Feature>& theFeature,
126 const std::list<ModelHighAPI_Selection>& theBaseObjects,
127 const ModelHighAPI_Double& theRadius)
128 : FeaturesAPI_Fillet(theFeature)
131 fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_SINGLE_RADIUS(), mycreationMethod);
132 fillAttribute(theBaseObjects, mybaseObjects);
133 fillAttribute(theRadius, myradius);
135 execIfBaseNotEmpty();
139 FeaturesAPI_Fillet2D::FeaturesAPI_Fillet2D(const std::shared_ptr<ModelAPI_Feature>& theFeature,
140 const std::list<ModelHighAPI_Selection>& theBaseObjects,
141 const ModelHighAPI_Double& theRadius1,
142 const ModelHighAPI_Double& theRadius2)
143 : FeaturesAPI_Fillet(theFeature)
146 fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS(), mycreationMethod);
147 fillAttribute(theBaseObjects, mybaseObjects);
148 fillAttribute(theRadius1, mystartRadius);
149 fillAttribute(theRadius2, myendRadius);
151 execIfBaseNotEmpty();
155 FeaturesAPI_Fillet2D::~FeaturesAPI_Fillet2D()
159 void FeaturesAPI_Fillet2D::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
161 mybaseObjects->clear();
162 fillAttribute(theBaseObjects, mybaseObjects);
164 execIfBaseNotEmpty();
167 void FeaturesAPI_Fillet2D::setRadius(const ModelHighAPI_Double& theRadius)
169 fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_SINGLE_RADIUS(), mycreationMethod);
170 fillAttribute(theRadius, myradius);
172 execIfBaseNotEmpty();
175 void FeaturesAPI_Fillet2D::setRadius(const ModelHighAPI_Double& theRadius1,
176 const ModelHighAPI_Double& theRadius2)
178 fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS(), mycreationMethod);
179 fillAttribute(theRadius1, mystartRadius);
180 fillAttribute(theRadius2, myendRadius);
182 execIfBaseNotEmpty();
185 void FeaturesAPI_Fillet2D::dump(ModelHighAPI_Dumper& theDumper) const
187 FeaturePtr aBase = feature();
188 const std::string& aDocName = theDumper.name(aBase->document());
190 AttributeSelectionListPtr anAttrObjects =
191 aBase->selectionList(FeaturesPlugin_Fillet::OBJECT_LIST_ID());
193 theDumper << aBase << " = model.addFillet(" << aDocName << ", " << anAttrObjects;
195 std::string aCreationMethod = aBase->string(FeaturesPlugin_Fillet::CREATION_METHOD())->value();
197 if(aCreationMethod == FeaturesPlugin_Fillet::CREATION_METHOD_SINGLE_RADIUS()) {
198 AttributeDoublePtr anAttrRadius = aBase->real(FeaturesPlugin_Fillet::RADIUS_ID());
199 theDumper << ", " << anAttrRadius;
200 } else if(aCreationMethod == FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS()) {
201 AttributeDoublePtr anAttrRadius1 = aBase->real(FeaturesPlugin_Fillet::START_RADIUS_ID());
202 AttributeDoublePtr anAttrRadius2 = aBase->real(FeaturesPlugin_Fillet::END_RADIUS_ID());
203 theDumper << ", " << anAttrRadius1 << ", " << anAttrRadius2;
206 if (!aBase->data()->version().empty())
207 theDumper << ", keepSubResults = True";
209 theDumper << ")" << std::endl;
212 void FeaturesAPI_Fillet2D::execIfBaseNotEmpty()
214 if (mybaseObjects->size() > 0)
219 //==================================================================================================
221 FilletPtr addFillet(const std::shared_ptr<ModelAPI_Document>& thePart,
222 const std::list<ModelHighAPI_Selection>& theBaseObjects,
223 const ModelHighAPI_Double& theRadius1,
224 const ModelHighAPI_Double& theRadius2,
225 const bool keepSubResults)
227 GeomAPI_Shape::ShapeType aType = typeOfSelection(theBaseObjects);
228 bool is1D = aType == GeomAPI_Shape::WIRE || aType == GeomAPI_Shape::VERTEX;
230 FeaturePtr aFeature =
231 thePart->addFeature(is1D ? FeaturesAPI_Fillet1D::ID() : FeaturesAPI_Fillet2D::ID());
233 aFeature->data()->setVersion("");
237 aFillet.reset(new FeaturesAPI_Fillet1D(aFeature, theBaseObjects, theRadius1));
238 else if (theRadius2.value() < 0.0)
239 aFillet.reset(new FeaturesAPI_Fillet2D(aFeature, theBaseObjects, theRadius1));
241 aFillet.reset(new FeaturesAPI_Fillet2D(aFeature, theBaseObjects, theRadius1, theRadius2));