Salome HOME
Merge branch 'Dev_GroupsRevision'
[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     execIfBaseNotEmpty();
45   }
46 }
47
48 FeaturesAPI_Fillet::FeaturesAPI_Fillet(const std::shared_ptr<ModelAPI_Feature>& theFeature,
49                                        const std::list<ModelHighAPI_Selection>& theBaseObjects,
50                                        const ModelHighAPI_Double& theRadius1,
51                                        const ModelHighAPI_Double& theRadius2)
52   : ModelHighAPI_Interface(theFeature)
53 {
54   if (initialize()) {
55     fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS(), mycreationMethod);
56     fillAttribute(theBaseObjects, mybaseObjects);
57     fillAttribute(theRadius1, mystartRadius);
58     fillAttribute(theRadius2, myendRadius);
59
60     execIfBaseNotEmpty();
61   }
62 }
63
64 FeaturesAPI_Fillet::~FeaturesAPI_Fillet()
65 {
66 }
67
68 //==================================================================================================
69 void FeaturesAPI_Fillet::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
70 {
71   mybaseObjects->clear();
72   fillAttribute(theBaseObjects, mybaseObjects);
73
74   execIfBaseNotEmpty();
75 }
76
77 void FeaturesAPI_Fillet::setRadius(const ModelHighAPI_Double& theRadius)
78 {
79   fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_SINGLE_RADIUS(), mycreationMethod);
80   fillAttribute(theRadius, myradius);
81
82   execIfBaseNotEmpty();
83 }
84
85 void FeaturesAPI_Fillet::setRadius(const ModelHighAPI_Double& theRadius1,
86                                    const ModelHighAPI_Double& theRadius2)
87 {
88   fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS(), mycreationMethod);
89   fillAttribute(theRadius1, mystartRadius);
90   fillAttribute(theRadius2, myendRadius);
91
92   execIfBaseNotEmpty();
93 }
94
95 void FeaturesAPI_Fillet::dump(ModelHighAPI_Dumper& theDumper) const
96 {
97   FeaturePtr aBase = feature();
98   const std::string& aDocName = theDumper.name(aBase->document());
99
100   AttributeSelectionListPtr anAttrObjects =
101     aBase->selectionList(FeaturesPlugin_Fillet::OBJECT_LIST_ID());
102
103   theDumper << aBase << " = model.addFillet(" << aDocName << ", " << anAttrObjects;
104
105   std::string aCreationMethod = aBase->string(FeaturesPlugin_Fillet::CREATION_METHOD())->value();
106
107   if(aCreationMethod == FeaturesPlugin_Fillet::CREATION_METHOD_SINGLE_RADIUS()) {
108     AttributeDoublePtr anAttrRadius = aBase->real(FeaturesPlugin_Fillet::RADIUS_ID());
109     theDumper << ", " << anAttrRadius;
110   } else if(aCreationMethod == FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS()) {
111     AttributeDoublePtr anAttrRadius1 = aBase->real(FeaturesPlugin_Fillet::START_RADIUS_ID());
112     AttributeDoublePtr anAttrRadius2 = aBase->real(FeaturesPlugin_Fillet::END_RADIUS_ID());
113     theDumper << ", " << anAttrRadius1 << ", " << anAttrRadius2;
114   }
115
116   theDumper << ")" << std::endl;
117 }
118
119 void FeaturesAPI_Fillet::execIfBaseNotEmpty()
120 {
121   if (mybaseObjects->size() > 0)
122     execute();
123 }
124
125
126 //==================================================================================================
127
128 FilletPtr addFillet(const std::shared_ptr<ModelAPI_Document>& thePart,
129                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
130                     const ModelHighAPI_Double& theRadius)
131 {
132   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Fillet::ID());
133   return FilletPtr(new FeaturesAPI_Fillet(aFeature, theBaseObjects, theRadius));
134 }
135
136 FilletPtr addFillet(const std::shared_ptr<ModelAPI_Document>& thePart,
137                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
138                     const ModelHighAPI_Double& theRadius1,
139                     const ModelHighAPI_Double& theRadius2)
140 {
141   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Fillet::ID());
142   return FilletPtr(new FeaturesAPI_Fillet(aFeature, theBaseObjects, theRadius1, theRadius2));
143 }