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