Salome HOME
Filling operation: create a face from a set of edges/wires
[modules/shaper.git] / src / BuildAPI / BuildAPI_Filling.cpp
1 // Copyright (C) 2017-20xx  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 "BuildAPI_Filling.h"
22
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
25
26 BuildAPI_Filling::BuildAPI_Filling(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27   : ModelHighAPI_Interface(theFeature)
28 {
29   initialize();
30 }
31
32 BuildAPI_Filling::BuildAPI_Filling(const std::shared_ptr<ModelAPI_Feature>& theFeature,
33                                    const std::list<ModelHighAPI_Selection>& theBaseObjects)
34   : ModelHighAPI_Interface(theFeature)
35 {
36   if(initialize())
37     setBase(theBaseObjects);
38 }
39
40 BuildAPI_Filling::BuildAPI_Filling(const std::shared_ptr<ModelAPI_Feature>& theFeature,
41                                    const std::list<ModelHighAPI_Selection>& theBaseObjects,
42                                    const std::string& theOrientCorrection,
43                                    const int theMinDegree,
44                                    const int theMaxDegree,
45                                    const int theNbIter,
46                                    const double theTolerance2D,
47                                    const double theTolerance3D,
48                                    const bool theApproximate)
49   : ModelHighAPI_Interface(theFeature)
50 {
51   if(initialize()) {
52     setOrientationMethod(theOrientCorrection);
53     setMinDegree(theMinDegree);
54     setMaxDegree(theMaxDegree);
55     setNbIterations(theNbIter);
56     setTolerance2d(theTolerance2D);
57     setTolerance3d(theTolerance3D);
58     setApproximation(theApproximate);
59     setAdvancedOptions();
60     setBase(theBaseObjects);
61   }
62 }
63
64 BuildAPI_Filling::~BuildAPI_Filling()
65 {
66 }
67
68 void BuildAPI_Filling::execIfBaseNotEmpty()
69 {
70   if (baseObjects()->size() > 0)
71     execute();
72 }
73
74 void BuildAPI_Filling::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
75 {
76   fillAttribute(theBaseObjects, mybaseObjects);
77   execIfBaseNotEmpty();
78 }
79
80 void BuildAPI_Filling::setOrientationMethod(const std::string& theMethod)
81 {
82   fillAttribute(theMethod, myorientationMethod);
83   if (theMethod != BuildPlugin_Filling::METHOD_DEFAULT())
84     setAdvancedOptions();
85   execIfBaseNotEmpty();
86 }
87
88 void BuildAPI_Filling::setMinDegree(const int theMinDegree)
89 {
90   fillAttribute(theMinDegree, myminDegree);
91   if (theMinDegree != BuildPlugin_Filling::MINIMAL_DEGREE_DEFAULT())
92     setAdvancedOptions();
93   execIfBaseNotEmpty();
94 }
95
96 void BuildAPI_Filling::setMaxDegree(const int theMaxDegree)
97 {
98   fillAttribute(theMaxDegree, mymaxDegree);
99   if (theMaxDegree != BuildPlugin_Filling::MAXIMAL_DEGREE_DEFAULT())
100     setAdvancedOptions();
101   execIfBaseNotEmpty();
102 }
103
104 void BuildAPI_Filling::setNbIterations(const int theNbIter)
105 {
106   fillAttribute(theNbIter, mynbIterations);
107   if (theNbIter != BuildPlugin_Filling::NUMBER_OF_ITERATIONS_DEFAULT())
108     setAdvancedOptions();
109   execIfBaseNotEmpty();
110 }
111
112 void BuildAPI_Filling::setTolerance2d(const double theTol2d)
113 {
114   fillAttribute(theTol2d, mytolerance2d);
115   if (theTol2d != BuildPlugin_Filling::TOLERANCE_2D_DEFAULT())
116     setAdvancedOptions();
117   execIfBaseNotEmpty();
118 }
119
120 void BuildAPI_Filling::setTolerance3d(const double theTol3d)
121 {
122   fillAttribute(theTol3d, mytolerance3d);
123   if (theTol3d != BuildPlugin_Filling::TOLERANCE_3D_DEFAULT())
124     setAdvancedOptions();
125   execIfBaseNotEmpty();
126 }
127
128 void BuildAPI_Filling::setApproximation(const bool theApproximate)
129 {
130   fillAttribute(theApproximate, myapproximate);
131   if (theApproximate != BuildPlugin_Filling::APPROXIMATION_DEFAULT())
132     setAdvancedOptions();
133   execIfBaseNotEmpty();
134 }
135
136 void BuildAPI_Filling::setAdvancedOptions()
137 {
138   feature()->string(BuildPlugin_Filling::ADVANCED_OPTIONS_ID())->setValue("true");
139 }
140
141 void BuildAPI_Filling::dump(ModelHighAPI_Dumper& theDumper) const
142 {
143   FeaturePtr aBase = feature();
144   std::string aPartName = theDumper.name(aBase->document());
145
146   theDumper << aBase << " = model.addFilling(" << aPartName << ", " << baseObjects();
147
148   if (!aBase->string(BuildPlugin_Filling::ADVANCED_OPTIONS_ID())->value().empty()) {
149     // dump options too,
150     theDumper << ", " << orientationMethod()
151               << ", " << minDegree() << ", " << maxDegree() << ", " << nbIterations()
152               << ", " << tolerance2d() << ", " << tolerance3d()
153               << ", " << approximate();
154   }
155   theDumper << ")" << std::endl;
156 }
157
158 //==================================================================================================
159
160 FillingPtr addFilling(const std::shared_ptr<ModelAPI_Document>& thePart,
161                       const std::list<ModelHighAPI_Selection>& theBaseObjects)
162 {
163   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Filling::ID());
164   return FillingPtr(new BuildAPI_Filling(aFeature, theBaseObjects));
165 }
166
167 FillingPtr addFilling(const std::shared_ptr<ModelAPI_Document>& thePart,
168                       const std::list<ModelHighAPI_Selection>& theBaseObjects,
169                       const std::string& theOrientCorrection,
170                       const int theMinDegree,
171                       const int theMaxDegree,
172                       const int theNbIter,
173                       const double theTolerance2D,
174                       const double theTolerance3D,
175                       const bool theApproximate)
176 {
177   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Filling::ID());
178   return FillingPtr(new BuildAPI_Filling(aFeature, theBaseObjects, theOrientCorrection,
179       theMinDegree, theMaxDegree, theNbIter, theTolerance2D, theTolerance3D, theApproximate));
180 }