1 // Copyright (C) 2017-2020 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 email : webmaster.salome@opencascade.com
20 #include "BuildAPI_Filling.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
25 BuildAPI_Filling::BuildAPI_Filling(const std::shared_ptr<ModelAPI_Feature>& theFeature)
26 : ModelHighAPI_Interface(theFeature)
31 BuildAPI_Filling::BuildAPI_Filling(const std::shared_ptr<ModelAPI_Feature>& theFeature,
32 const std::list<ModelHighAPI_Selection>& theBaseObjects)
33 : ModelHighAPI_Interface(theFeature)
36 setAdvancedOptions(false);
37 setBase(theBaseObjects);
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,
47 const double theTolerance2D,
48 const double theTolerance3D,
49 const bool theApproximate)
50 : ModelHighAPI_Interface(theFeature)
53 setOrientationMethod(theOrientCorrection);
54 setMinDegree(theMinDegree);
55 setMaxDegree(theMaxDegree);
56 setNbIterations(theNbIter);
57 setTolerance2d(theTolerance2D);
58 setTolerance3d(theTolerance3D);
59 setApproximation(theApproximate);
61 setBase(theBaseObjects);
65 BuildAPI_Filling::~BuildAPI_Filling()
69 void BuildAPI_Filling::execIfBaseNotEmpty()
71 if (baseObjects()->size() > 0)
75 void BuildAPI_Filling::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
77 fillAttribute(theBaseObjects, mybaseObjects);
81 void BuildAPI_Filling::setOrientationMethod(const std::string& theMethod)
83 fillAttribute(theMethod, myorientationMethod);
84 if (theMethod != BuildPlugin_Filling::METHOD_DEFAULT())
89 void BuildAPI_Filling::setMinDegree(const int theMinDegree)
91 fillAttribute(theMinDegree, myminDegree);
92 if (theMinDegree != BuildPlugin_Filling::MINIMAL_DEGREE_DEFAULT())
97 void BuildAPI_Filling::setMaxDegree(const int theMaxDegree)
99 fillAttribute(theMaxDegree, mymaxDegree);
100 if (theMaxDegree != BuildPlugin_Filling::MAXIMAL_DEGREE_DEFAULT())
101 setAdvancedOptions();
102 execIfBaseNotEmpty();
105 void BuildAPI_Filling::setNbIterations(const int theNbIter)
107 fillAttribute(theNbIter, mynbIterations);
108 if (theNbIter != BuildPlugin_Filling::NUMBER_OF_ITERATIONS_DEFAULT())
109 setAdvancedOptions();
110 execIfBaseNotEmpty();
113 void BuildAPI_Filling::setTolerance2d(const double theTol2d)
115 fillAttribute(theTol2d, mytolerance2d);
116 if (theTol2d != BuildPlugin_Filling::TOLERANCE_2D_DEFAULT())
117 setAdvancedOptions();
118 execIfBaseNotEmpty();
121 void BuildAPI_Filling::setTolerance3d(const double theTol3d)
123 fillAttribute(theTol3d, mytolerance3d);
124 if (theTol3d != BuildPlugin_Filling::TOLERANCE_3D_DEFAULT())
125 setAdvancedOptions();
126 execIfBaseNotEmpty();
129 void BuildAPI_Filling::setApproximation(const bool theApproximate)
131 fillAttribute(theApproximate, myapproximate);
132 if (theApproximate != BuildPlugin_Filling::APPROXIMATION_DEFAULT())
133 setAdvancedOptions();
134 execIfBaseNotEmpty();
137 void BuildAPI_Filling::setAdvancedOptions(bool isEnabled)
139 feature()->string(BuildPlugin_Filling::ADVANCED_OPTIONS_ID())->setValue(isEnabled ? "true" : "");
142 void BuildAPI_Filling::dump(ModelHighAPI_Dumper& theDumper) const
144 FeaturePtr aBase = feature();
145 std::string aPartName = theDumper.name(aBase->document());
147 theDumper << aBase << " = model.addFilling(" << aPartName << ", " << baseObjects();
149 if (!aBase->string(BuildPlugin_Filling::ADVANCED_OPTIONS_ID())->value().empty()) {
151 theDumper << ", " << orientationMethod()
152 << ", " << minDegree() << ", " << maxDegree() << ", " << nbIterations()
153 << ", " << tolerance2d() << ", " << tolerance3d()
154 << ", " << approximate();
156 theDumper << ")" << std::endl;
159 //==================================================================================================
161 FillingPtr addFilling(const std::shared_ptr<ModelAPI_Document>& thePart,
162 const std::list<ModelHighAPI_Selection>& theBaseObjects)
164 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Filling::ID());
165 return FillingPtr(new BuildAPI_Filling(aFeature, theBaseObjects));
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,
174 const double theTolerance2D,
175 const double theTolerance3D,
176 const bool theApproximate)
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));