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