Salome HOME
Copyright update 2022
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Pipe.cpp
1 // Copyright (C) 2014-2022  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 "FeaturesAPI_Pipe.h"
21
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
24
25 //==================================================================================================
26 FeaturesAPI_Pipe::FeaturesAPI_Pipe(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
28 {
29   initialize();
30 }
31
32 //==================================================================================================
33 FeaturesAPI_Pipe::FeaturesAPI_Pipe(const std::shared_ptr<ModelAPI_Feature>& theFeature,
34                                    const std::list<ModelHighAPI_Selection>& theBaseObjects,
35                                    const ModelHighAPI_Selection& thePath)
36 : ModelHighAPI_Interface(theFeature)
37 {
38   if(initialize()) {
39     setByBasePath(theBaseObjects, thePath);
40   }
41 }
42
43 //==================================================================================================
44 FeaturesAPI_Pipe::FeaturesAPI_Pipe(const std::shared_ptr<ModelAPI_Feature>& theFeature,
45                                    const std::list<ModelHighAPI_Selection>& theBaseObjects,
46                                    const ModelHighAPI_Selection& thePath,
47                                    const ModelHighAPI_Selection& theBiNoramal)
48 : ModelHighAPI_Interface(theFeature)
49 {
50   if(initialize()) {
51     setByBasePathBiNormal(theBaseObjects, thePath, theBiNoramal);
52   }
53 }
54
55 //==================================================================================================
56 FeaturesAPI_Pipe::FeaturesAPI_Pipe(const std::shared_ptr<ModelAPI_Feature>& theFeature,
57                                    const std::list<ModelHighAPI_Selection>& theBaseObjects,
58                                    const ModelHighAPI_Selection& thePath,
59                                    const std::list<ModelHighAPI_Selection>& theLocations)
60 : ModelHighAPI_Interface(theFeature)
61 {
62   if(initialize()) {
63     setByBasePathLocations(theBaseObjects, thePath, theLocations);
64   }
65 }
66
67 //==================================================================================================
68 FeaturesAPI_Pipe::~FeaturesAPI_Pipe()
69 {
70
71 }
72
73 //==================================================================================================
74 void FeaturesAPI_Pipe::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
75 {
76   fillAttribute(theBaseObjects, mybaseObjects);
77
78   execute();
79 }
80
81 //==================================================================================================
82 void FeaturesAPI_Pipe::setPath(const ModelHighAPI_Selection& thePath)
83 {
84   fillAttribute(thePath, mypath);
85
86   execute();
87 }
88
89 //==================================================================================================
90 void FeaturesAPI_Pipe::setByBasePath(const std::list<ModelHighAPI_Selection>& theBaseObjects,
91                                      const ModelHighAPI_Selection& thePath)
92 {
93   fillAttribute(FeaturesPlugin_Pipe::CREATION_METHOD_SIMPLE(), mycreationMethod);
94   fillAttribute(theBaseObjects, mybaseObjects);
95   fillAttribute(thePath, mypath);
96
97   execute();
98 }
99
100 //==================================================================================================
101 void FeaturesAPI_Pipe::setByBasePathBiNormal(
102   const std::list<ModelHighAPI_Selection>& theBaseObjects,
103   const ModelHighAPI_Selection& thePath,
104   const ModelHighAPI_Selection& theBiNoramal)
105 {
106   fillAttribute(FeaturesPlugin_Pipe::CREATION_METHOD_BINORMAL(), mycreationMethod);
107   fillAttribute(theBaseObjects, mybaseObjects);
108   fillAttribute(thePath, mypath);
109   fillAttribute(theBiNoramal, mybiNormal);
110
111   execute();
112 }
113
114 //==================================================================================================
115 void FeaturesAPI_Pipe::setByBasePathLocations(
116   const std::list<ModelHighAPI_Selection>& theBaseObjects,
117   const ModelHighAPI_Selection& thePath,
118   const std::list<ModelHighAPI_Selection>& theLocations)
119 {
120   fillAttribute(FeaturesPlugin_Pipe::CREATION_METHOD_LOCATIONS(), mycreationMethod);
121   fillAttribute(theBaseObjects, mybaseObjects);
122   fillAttribute(thePath, mypath);
123   fillAttribute(theLocations, mylocations);
124
125   execute();
126 }
127
128 //==================================================================================================
129 void FeaturesAPI_Pipe::dump(ModelHighAPI_Dumper& theDumper) const
130 {
131   FeaturePtr aBase = feature();
132   const std::string& aDocName = theDumper.name(aBase->document());
133
134   AttributeSelectionListPtr anAttrObjects =
135     aBase->selectionList(FeaturesPlugin_Pipe::BASE_OBJECTS_ID());
136   AttributeSelectionPtr anAttrPath = aBase->selection(FeaturesPlugin_Pipe::PATH_OBJECT_ID());
137
138   theDumper << aBase << " = model.addPipe(" << aDocName << ", "
139             << anAttrObjects << ", " << anAttrPath;
140
141   std::string aCreationMethod = aBase->string(FeaturesPlugin_Pipe::CREATION_METHOD())->value();
142
143   if(aCreationMethod == FeaturesPlugin_Pipe::CREATION_METHOD_SIMPLE()) {
144     // Do nothing;
145   } else if(aCreationMethod == FeaturesPlugin_Pipe::CREATION_METHOD_BINORMAL()) {
146     AttributeSelectionPtr anAttrBiNormal = aBase->selection(FeaturesPlugin_Pipe::BINORMAL_ID());
147
148     theDumper << ", " << anAttrBiNormal;
149   } else if(aCreationMethod == FeaturesPlugin_Pipe::CREATION_METHOD_LOCATIONS()) {
150     AttributeSelectionListPtr anAttrLocations =
151       aBase->selectionList(FeaturesPlugin_Pipe::LOCATIONS_ID());
152
153     theDumper << ", " << anAttrLocations;
154   }
155
156   theDumper << ")" << std::endl;
157 }
158
159 //==================================================================================================
160 PipePtr addPipe(const std::shared_ptr<ModelAPI_Document>& thePart,
161                 const std::list<ModelHighAPI_Selection>& theBaseObjects,
162                 const ModelHighAPI_Selection& thePath)
163 {
164   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Pipe::ID());
165   return PipePtr(new FeaturesAPI_Pipe(aFeature, theBaseObjects, thePath));
166 }
167
168 //==================================================================================================
169 PipePtr addPipe(const std::shared_ptr<ModelAPI_Document>& thePart,
170                 const std::list<ModelHighAPI_Selection>& theBaseObjects,
171                 const ModelHighAPI_Selection& thePath,
172                 const ModelHighAPI_Selection& theBiNoramal)
173 {
174   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Pipe::ID());
175   return PipePtr(new FeaturesAPI_Pipe(aFeature, theBaseObjects, thePath, theBiNoramal));
176 }
177
178 //==================================================================================================
179 PipePtr addPipe(const std::shared_ptr<ModelAPI_Document>& thePart,
180                 const std::list<ModelHighAPI_Selection>& theBaseObjects,
181                 const ModelHighAPI_Selection& thePath,
182                 const std::list<ModelHighAPI_Selection>& theLocations)
183 {
184   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Pipe::ID());
185   return PipePtr(new FeaturesAPI_Pipe(aFeature, theBaseObjects, thePath, theLocations));
186 }