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