1 // Copyright (C) 2014-2021 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_Interpolation.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
25 //==================================================================================================
26 BuildAPI_Interpolation::BuildAPI_Interpolation(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
32 //==================================================================================================
33 BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature,
34 const std::list<ModelHighAPI_Selection>& theBaseObjects,
35 const ModelHighAPI_Selection& theStartTangent,
36 const ModelHighAPI_Selection& theEndTangent,
37 const bool theIsClosed,
38 const bool theIsToReorder)
39 : ModelHighAPI_Interface(theFeature)
42 fillAttribute(BuildPlugin_Interpolation::CREATION_METHOD_BY_SELECTION_ID(),mycreationmethod);
44 setTangents(theStartTangent, theEndTangent);
45 setClosed(theIsClosed);
46 setReorder(theIsToReorder);
47 setBase(theBaseObjects);
51 //==================================================================================================
52 BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature,
53 const std::list<ModelHighAPI_Selection>& theBaseObjects,
54 const bool theIsClosed,
55 const bool theIsToReorder)
56 : ModelHighAPI_Interface(theFeature)
59 fillAttribute(BuildPlugin_Interpolation::CREATION_METHOD_BY_SELECTION_ID(),mycreationmethod);
60 setClosed(theIsClosed);
61 setReorder(theIsToReorder);
62 setUseTangents(false);
63 setBase(theBaseObjects);
67 //==================================================================================================
68 BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature,
69 const std::string & theXTexpression,
70 const std::string & theYTexpression,
71 const std::string & theZTexpression,
72 const ModelHighAPI_Double& theMinT,
73 const ModelHighAPI_Double& theMaxT,
74 const ModelHighAPI_Integer& theNbStep)
75 : ModelHighAPI_Interface(theFeature)
78 fillAttribute(BuildPlugin_Interpolation::CREATION_METHOD_ANALYTICAL_ID(),mycreationmethod);
79 fillAttribute(theXTexpression, myxt);
80 fillAttribute(theYTexpression, myyt);
81 fillAttribute(theZTexpression, myzt);
82 fillAttribute(theMinT, mymint);
83 fillAttribute(theMaxT, mymaxt);
84 fillAttribute(theNbStep, mynumstep);
90 //==================================================================================================
91 BuildAPI_Interpolation::~BuildAPI_Interpolation()
95 //==================================================================================================
96 void BuildAPI_Interpolation::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
98 fillAttribute(theBaseObjects, mybaseObjects);
103 //==================================================================================================
104 void BuildAPI_Interpolation::setClosed(const bool theIsClosed)
106 fillAttribute(theIsClosed, myclosed);
108 execIfBaseNotEmpty();
111 void BuildAPI_Interpolation::setReorder(const bool theIsToReorder)
113 fillAttribute(theIsToReorder, myreorder);
115 execIfBaseNotEmpty();
118 void BuildAPI_Interpolation::setUseTangents(const bool theIsToUseTangents)
120 fillAttribute(theIsToUseTangents ? "true" : "", myuseTangents);
122 execIfBaseNotEmpty();
125 void BuildAPI_Interpolation::setTangents(const ModelHighAPI_Selection& theStartTangent,
126 const ModelHighAPI_Selection& theEndTangent)
128 fillAttribute(theStartTangent, mystartTangent);
129 fillAttribute(theEndTangent, myendTangent);
131 execIfBaseNotEmpty();
134 //==================================================================================================
135 void BuildAPI_Interpolation::dump(ModelHighAPI_Dumper& theDumper) const
137 FeaturePtr aBase = feature();
138 std::string aPartName = theDumper.name(aBase->document());
140 if (aBase->string(BuildPlugin_Interpolation::CREATION_METHOD_ID())->value() ==
141 BuildPlugin_Interpolation::CREATION_METHOD_BY_SELECTION_ID())
143 AttributeSelectionListPtr anAttrBaseObjects =
144 aBase->selectionList(BuildPlugin_Interpolation::BASE_OBJECTS_ID());
146 theDumper << aBase << " = model.addInterpolation(" << aPartName << ", "
147 << anAttrBaseObjects << ", ";
149 AttributeStringPtr useTangentsAttr = useTangents();
150 std::string useTangents = useTangentsAttr->value();
151 if (!useTangents.empty()) {
152 AttributeSelectionPtr anAttrStartTangent =
153 aBase->selection(BuildPlugin_Interpolation::TANGENT_START_ID());
154 AttributeSelectionPtr anAttrEndTangent =
155 aBase->selection(BuildPlugin_Interpolation::TANGENT_END_ID());
157 theDumper << anAttrStartTangent << ", " << anAttrEndTangent << ", ";
160 theDumper << closed() << ", " << reorder() << ")" << std::endl;
162 theDumper << aBase << " = model.addInterpolation(" << aPartName ;
163 AttributeStringPtr XtAttr = xt();
164 std::string xt = XtAttr->value();
165 AttributeStringPtr YtAttr = yt();
166 std::string yt = YtAttr->value();
167 AttributeStringPtr ZtAttr = zt();
168 std::string zt = ZtAttr->value();
169 AttributeDoublePtr minTAttr = mint();
170 double mint = minTAttr->value();
171 AttributeDoublePtr maxTAttr = maxt();
172 double maxt = maxTAttr->value();
173 AttributeIntegerPtr nbStepAttr = numstep();
174 int nbStep = nbStepAttr->value();
176 theDumper<< ", \"" << xt << "\", \"" << yt << "\", \""<< zt<< "\", " ;
177 theDumper << mint << ", " << maxt << ", "<< nbStep<< ")"<<std::endl;
181 //==================================================================================================
182 InterpolationPtr addInterpolation(const std::shared_ptr<ModelAPI_Document>& thePart,
183 const std::list<ModelHighAPI_Selection>& theBaseObjects,
184 const bool theIsClosed,
185 const bool theIsToReorder)
187 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Interpolation::ID());
188 return InterpolationPtr(new BuildAPI_Interpolation(aFeature,
194 //==================================================================================================
195 InterpolationPtr addInterpolation(const std::shared_ptr<ModelAPI_Document>& thePart,
196 const std::list<ModelHighAPI_Selection>& theBaseObjects,
197 const ModelHighAPI_Selection& theStartTangent,
198 const ModelHighAPI_Selection& theEndTangent,
199 const bool theIsClosed,
200 const bool theIsToReorder)
202 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Interpolation::ID());
203 return InterpolationPtr(new BuildAPI_Interpolation(aFeature,
211 InterpolationPtr addInterpolation(const std::shared_ptr<ModelAPI_Document>& thePart,
212 const std::string & theXTexpression,
213 const std::string & theYTexpression,
214 const std::string & theZTexpression,
215 const ModelHighAPI_Double& theMinT,
216 const ModelHighAPI_Double& theMaxT,
217 const ModelHighAPI_Integer& theNbStep)
219 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Interpolation::ID());
220 return InterpolationPtr(new BuildAPI_Interpolation(aFeature,
229 //==================================================================================================
230 void BuildAPI_Interpolation::execIfBaseNotEmpty()
232 if (baseObjects()->size() > 0)