Salome HOME
Implementation of 3D Fillet operation
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Fillet.cpp
1 // Copyright (C) 2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "FeaturesAPI_Fillet.h"
22
23 #include <ModelHighAPI_Double.h>
24 #include <ModelHighAPI_Dumper.h>
25 ////#include <ModelHighAPI_Reference.h>
26 #include <ModelHighAPI_Tools.h>
27
28 FeaturesAPI_Fillet::FeaturesAPI_Fillet(const std::shared_ptr<ModelAPI_Feature>& theFeature)
29   : ModelHighAPI_Interface(theFeature)
30 {
31   initialize();
32 }
33
34 FeaturesAPI_Fillet::FeaturesAPI_Fillet(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35                                        const std::list<ModelHighAPI_Selection>& theBaseObjects,
36                                        const ModelHighAPI_Double& theRadius)
37   : ModelHighAPI_Interface(theFeature)
38 {
39   if (initialize()) {
40     fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_SINGLE_RADIUS(), mycreationMethod);
41     fillAttribute(theBaseObjects, mybaseObjects);
42     fillAttribute(theRadius, myradius);
43   }
44 }
45
46 FeaturesAPI_Fillet::FeaturesAPI_Fillet(const std::shared_ptr<ModelAPI_Feature>& theFeature,
47                                        const std::list<ModelHighAPI_Selection>& theBaseObjects,
48                                        const ModelHighAPI_Double& theRadius1,
49                                        const ModelHighAPI_Double& theRadius2)
50   : ModelHighAPI_Interface(theFeature)
51 {
52   if (initialize()) {
53     fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS(), mycreationMethod);
54     fillAttribute(theBaseObjects, mybaseObjects);
55     fillAttribute(theRadius1, mystartRadius);
56     fillAttribute(theRadius2, myendRadius);
57   }
58 }
59
60 FeaturesAPI_Fillet::~FeaturesAPI_Fillet()
61 {
62 }
63
64 //==================================================================================================
65 void FeaturesAPI_Fillet::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
66 {
67   mybaseObjects->clear();
68   fillAttribute(theBaseObjects, mybaseObjects);
69
70   execIfBaseNotEmpty();
71 }
72
73 void FeaturesAPI_Fillet::setRadius(const ModelHighAPI_Double& theRadius)
74 {
75   fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_SINGLE_RADIUS(), mycreationMethod);
76   fillAttribute(theRadius, myradius);
77
78   execIfBaseNotEmpty();
79 }
80
81 void FeaturesAPI_Fillet::setRadius(const ModelHighAPI_Double& theRadius1,
82                                    const ModelHighAPI_Double& theRadius2)
83 {
84   fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS(), mycreationMethod);
85   fillAttribute(theRadius1, mystartRadius);
86   fillAttribute(theRadius2, myendRadius);
87
88   execIfBaseNotEmpty();
89 }
90
91 void FeaturesAPI_Fillet::dump(ModelHighAPI_Dumper& theDumper) const
92 {
93   FeaturePtr aBase = feature();
94   const std::string& aDocName = theDumper.name(aBase->document());
95
96   AttributeSelectionListPtr anAttrObjects =
97     aBase->selectionList(FeaturesPlugin_Fillet::OBJECT_LIST_ID());
98
99   theDumper << aBase << " = model.addFillet(" << aDocName << ", " << anAttrObjects;
100
101   std::string aCreationMethod = aBase->string(FeaturesPlugin_Fillet::CREATION_METHOD())->value();
102
103   if(aCreationMethod == FeaturesPlugin_Fillet::CREATION_METHOD_SINGLE_RADIUS()) {
104     AttributeDoublePtr anAttrRadius = aBase->real(FeaturesPlugin_Fillet::RADIUS_ID());
105     theDumper << ", " << anAttrRadius;
106   } else if(aCreationMethod == FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS()) {
107     AttributeDoublePtr anAttrRadius1 = aBase->real(FeaturesPlugin_Fillet::START_RADIUS_ID());
108     AttributeDoublePtr anAttrRadius2 = aBase->real(FeaturesPlugin_Fillet::END_RADIUS_ID());
109     theDumper << ", " << anAttrRadius1 << ", " << anAttrRadius2;
110   }
111
112   theDumper << ")" << std::endl;
113 }
114
115 void FeaturesAPI_Fillet::execIfBaseNotEmpty()
116 {
117   if (mybaseObjects->size() > 0)
118     execute();
119 }
120
121
122 //==================================================================================================
123
124 FilletPtr addFillet(const std::shared_ptr<ModelAPI_Document>& thePart,
125                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
126                     const ModelHighAPI_Double& theRadius)
127 {
128   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Fillet::ID());
129   return FilletPtr(new FeaturesAPI_Fillet(aFeature, theBaseObjects, theRadius));
130 }
131
132 FilletPtr addFillet(const std::shared_ptr<ModelAPI_Document>& thePart,
133                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
134                     const ModelHighAPI_Double& theRadius1,
135                     const ModelHighAPI_Double& theRadius2)
136 {
137   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Fillet::ID());
138   return FilletPtr(new FeaturesAPI_Fillet(aFeature, theBaseObjects, theRadius1, theRadius2));
139 }