1 // Copyright (C) 2014-2019 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)
43 setTangents(theStartTangent, theEndTangent);
44 setClosed(theIsClosed);
45 setReorder(theIsToReorder);
46 setBase(theBaseObjects);
50 //==================================================================================================
51 BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature,
52 const std::list<ModelHighAPI_Selection>& theBaseObjects,
53 const bool theIsClosed,
54 const bool theIsToReorder)
55 : ModelHighAPI_Interface(theFeature)
58 setClosed(theIsClosed);
59 setReorder(theIsToReorder);
60 setUseTangents(false);
61 setBase(theBaseObjects);
65 //==================================================================================================
66 BuildAPI_Interpolation::~BuildAPI_Interpolation()
70 //==================================================================================================
71 void BuildAPI_Interpolation::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
73 fillAttribute(theBaseObjects, mybaseObjects);
78 //==================================================================================================
79 void BuildAPI_Interpolation::setClosed(const bool theIsClosed)
81 fillAttribute(theIsClosed, myclosed);
86 void BuildAPI_Interpolation::setReorder(const bool theIsToReorder)
88 fillAttribute(theIsToReorder, myreorder);
93 void BuildAPI_Interpolation::setUseTangents(const bool theIsToUseTangents)
95 fillAttribute(theIsToUseTangents ? "true" : "", myuseTangents);
100 void BuildAPI_Interpolation::setTangents(const ModelHighAPI_Selection& theStartTangent,
101 const ModelHighAPI_Selection& theEndTangent)
103 fillAttribute(theStartTangent, mystartTangent);
104 fillAttribute(theEndTangent, myendTangent);
106 execIfBaseNotEmpty();
109 //==================================================================================================
110 void BuildAPI_Interpolation::dump(ModelHighAPI_Dumper& theDumper) const
112 FeaturePtr aBase = feature();
113 std::string aPartName = theDumper.name(aBase->document());
115 AttributeSelectionListPtr anAttrBaseObjects =
116 aBase->selectionList(BuildPlugin_Interpolation::BASE_OBJECTS_ID());
118 theDumper << aBase << " = model.addInterpolation(" << aPartName << ", "
119 << anAttrBaseObjects << ", ";
121 AttributeStringPtr useTangentsAttr = useTangents();
122 std::string useTangents = useTangentsAttr->value();
123 if (!useTangents.empty()) {
124 AttributeSelectionPtr anAttrStartTangent =
125 aBase->selection(BuildPlugin_Interpolation::TANGENT_START_ID());
126 AttributeSelectionPtr anAttrEndTangent =
127 aBase->selection(BuildPlugin_Interpolation::TANGENT_END_ID());
129 theDumper << anAttrStartTangent << ", " << anAttrEndTangent << ", ";
132 theDumper << closed() << ", " << reorder() << ")" << std::endl;
135 //==================================================================================================
136 InterpolationPtr addInterpolation(const std::shared_ptr<ModelAPI_Document>& thePart,
137 const std::list<ModelHighAPI_Selection>& theBaseObjects,
138 const bool theIsClosed,
139 const bool theIsToReorder)
141 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Interpolation::ID());
142 return InterpolationPtr(new BuildAPI_Interpolation(aFeature,
148 //==================================================================================================
149 InterpolationPtr addInterpolation(const std::shared_ptr<ModelAPI_Document>& thePart,
150 const std::list<ModelHighAPI_Selection>& theBaseObjects,
151 const ModelHighAPI_Selection& theStartTangent,
152 const ModelHighAPI_Selection& theEndTangent,
153 const bool theIsClosed,
154 const bool theIsToReorder)
156 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Interpolation::ID());
157 return InterpolationPtr(new BuildAPI_Interpolation(aFeature,
165 //==================================================================================================
166 void BuildAPI_Interpolation::execIfBaseNotEmpty()
168 if (baseObjects()->size() > 0)