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