1 // Copyright (C) 2017-20xx CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "BuildAPI_Filling.h"
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
26 BuildAPI_Filling::BuildAPI_Filling(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
32 BuildAPI_Filling::BuildAPI_Filling(const std::shared_ptr<ModelAPI_Feature>& theFeature,
33 const std::list<ModelHighAPI_Selection>& theBaseObjects)
34 : ModelHighAPI_Interface(theFeature)
37 setAdvancedOptions(false);
38 setBase(theBaseObjects);
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,
48 const double theTolerance2D,
49 const double theTolerance3D,
50 const bool theApproximate)
51 : ModelHighAPI_Interface(theFeature)
54 setOrientationMethod(theOrientCorrection);
55 setMinDegree(theMinDegree);
56 setMaxDegree(theMaxDegree);
57 setNbIterations(theNbIter);
58 setTolerance2d(theTolerance2D);
59 setTolerance3d(theTolerance3D);
60 setApproximation(theApproximate);
62 setBase(theBaseObjects);
66 BuildAPI_Filling::~BuildAPI_Filling()
70 void BuildAPI_Filling::execIfBaseNotEmpty()
72 if (baseObjects()->size() > 0)
76 void BuildAPI_Filling::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
78 fillAttribute(theBaseObjects, mybaseObjects);
82 void BuildAPI_Filling::setOrientationMethod(const std::string& theMethod)
84 fillAttribute(theMethod, myorientationMethod);
85 if (theMethod != BuildPlugin_Filling::METHOD_DEFAULT())
90 void BuildAPI_Filling::setMinDegree(const int theMinDegree)
92 fillAttribute(theMinDegree, myminDegree);
93 if (theMinDegree != BuildPlugin_Filling::MINIMAL_DEGREE_DEFAULT())
98 void BuildAPI_Filling::setMaxDegree(const int theMaxDegree)
100 fillAttribute(theMaxDegree, mymaxDegree);
101 if (theMaxDegree != BuildPlugin_Filling::MAXIMAL_DEGREE_DEFAULT())
102 setAdvancedOptions();
103 execIfBaseNotEmpty();
106 void BuildAPI_Filling::setNbIterations(const int theNbIter)
108 fillAttribute(theNbIter, mynbIterations);
109 if (theNbIter != BuildPlugin_Filling::NUMBER_OF_ITERATIONS_DEFAULT())
110 setAdvancedOptions();
111 execIfBaseNotEmpty();
114 void BuildAPI_Filling::setTolerance2d(const double theTol2d)
116 fillAttribute(theTol2d, mytolerance2d);
117 if (theTol2d != BuildPlugin_Filling::TOLERANCE_2D_DEFAULT())
118 setAdvancedOptions();
119 execIfBaseNotEmpty();
122 void BuildAPI_Filling::setTolerance3d(const double theTol3d)
124 fillAttribute(theTol3d, mytolerance3d);
125 if (theTol3d != BuildPlugin_Filling::TOLERANCE_3D_DEFAULT())
126 setAdvancedOptions();
127 execIfBaseNotEmpty();
130 void BuildAPI_Filling::setApproximation(const bool theApproximate)
132 fillAttribute(theApproximate, myapproximate);
133 if (theApproximate != BuildPlugin_Filling::APPROXIMATION_DEFAULT())
134 setAdvancedOptions();
135 execIfBaseNotEmpty();
138 void BuildAPI_Filling::setAdvancedOptions(bool isEnabled)
140 feature()->string(BuildPlugin_Filling::ADVANCED_OPTIONS_ID())->setValue(isEnabled ? "true" : "");
143 void BuildAPI_Filling::dump(ModelHighAPI_Dumper& theDumper) const
145 FeaturePtr aBase = feature();
146 std::string aPartName = theDumper.name(aBase->document());
148 theDumper << aBase << " = model.addFilling(" << aPartName << ", " << baseObjects();
150 if (!aBase->string(BuildPlugin_Filling::ADVANCED_OPTIONS_ID())->value().empty()) {
152 theDumper << ", " << orientationMethod()
153 << ", " << minDegree() << ", " << maxDegree() << ", " << nbIterations()
154 << ", " << tolerance2d() << ", " << tolerance3d()
155 << ", " << approximate();
157 theDumper << ")" << std::endl;
160 //==================================================================================================
162 FillingPtr addFilling(const std::shared_ptr<ModelAPI_Document>& thePart,
163 const std::list<ModelHighAPI_Selection>& theBaseObjects)
165 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Filling::ID());
166 return FillingPtr(new BuildAPI_Filling(aFeature, theBaseObjects));
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,
175 const double theTolerance2D,
176 const double theTolerance3D,
177 const bool theApproximate)
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));