Salome HOME
Copyright update 2020
[modules/shaper.git] / src / BuildAPI / BuildAPI_Interpolation.cpp
1 // Copyright (C) 2014-2020  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 email : webmaster.salome@opencascade.com
18 //
19
20 #include "BuildAPI_Interpolation.h"
21
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
24
25 //==================================================================================================
26 BuildAPI_Interpolation::BuildAPI_Interpolation(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
28 {
29   initialize();
30 }
31
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)
40 {
41   if(initialize()) {
42     setUseTangents(true);
43     setTangents(theStartTangent, theEndTangent);
44     setClosed(theIsClosed);
45     setReorder(theIsToReorder);
46     setBase(theBaseObjects);
47   }
48 }
49
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)
56 {
57   if (initialize()) {
58     setClosed(theIsClosed);
59     setReorder(theIsToReorder);
60     setUseTangents(false);
61     setBase(theBaseObjects);
62   }
63 }
64
65 //==================================================================================================
66 BuildAPI_Interpolation::~BuildAPI_Interpolation()
67 {
68 }
69
70 //==================================================================================================
71 void BuildAPI_Interpolation::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
72 {
73   fillAttribute(theBaseObjects, mybaseObjects);
74
75   execute();
76 }
77
78 //==================================================================================================
79 void BuildAPI_Interpolation::setClosed(const bool theIsClosed)
80 {
81   fillAttribute(theIsClosed, myclosed);
82
83   execIfBaseNotEmpty();
84 }
85
86 void BuildAPI_Interpolation::setReorder(const bool theIsToReorder)
87 {
88   fillAttribute(theIsToReorder, myreorder);
89
90   execIfBaseNotEmpty();
91 }
92
93 void BuildAPI_Interpolation::setUseTangents(const bool theIsToUseTangents)
94 {
95   fillAttribute(theIsToUseTangents ? "true" : "", myuseTangents);
96
97   execIfBaseNotEmpty();
98 }
99
100 void BuildAPI_Interpolation::setTangents(const ModelHighAPI_Selection& theStartTangent,
101                                          const ModelHighAPI_Selection& theEndTangent)
102 {
103   fillAttribute(theStartTangent, mystartTangent);
104   fillAttribute(theEndTangent, myendTangent);
105
106   execIfBaseNotEmpty();
107 }
108
109 //==================================================================================================
110 void BuildAPI_Interpolation::dump(ModelHighAPI_Dumper& theDumper) const
111 {
112   FeaturePtr aBase = feature();
113   std::string aPartName = theDumper.name(aBase->document());
114
115   AttributeSelectionListPtr anAttrBaseObjects =
116     aBase->selectionList(BuildPlugin_Interpolation::BASE_OBJECTS_ID());
117
118   theDumper << aBase << " = model.addInterpolation(" << aPartName << ", "
119             << anAttrBaseObjects << ", ";
120
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());
128
129     theDumper << anAttrStartTangent << ", " << anAttrEndTangent << ", ";
130   }
131
132   theDumper << closed() << ", " << reorder() << ")" << std::endl;
133 }
134
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)
140 {
141   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Interpolation::ID());
142   return InterpolationPtr(new BuildAPI_Interpolation(aFeature,
143                                                      theBaseObjects,
144                                                      theIsClosed,
145                                                      theIsToReorder));
146 }
147
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)
155 {
156   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Interpolation::ID());
157   return InterpolationPtr(new BuildAPI_Interpolation(aFeature,
158                                                      theBaseObjects,
159                                                      theStartTangent,
160                                                      theEndTangent,
161                                                      theIsClosed,
162                                                      theIsToReorder));
163 }
164
165 //==================================================================================================
166 void BuildAPI_Interpolation::execIfBaseNotEmpty()
167 {
168   if (baseObjects()->size() > 0)
169     execute();
170 }