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