Salome HOME
NRI : First integration.
[modules/smesh.git] / src / SMESHDS / SMESHDS_Script.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : SMESH_Script.cxx
4 // Created   : 
5 // Author    : Yves FRICAUD, OCC
6 // Project   : SALOME
7 // Copyright : OCC 2002
8 // $Header: 
9 //=============================================================================
10
11 #include "SMESHDS_Script.ixx"
12 #include "SMESHDS_Command.hxx"
13 #include "SMESHDS_CommandType.hxx"
14 #include "SMESHDS_ListOfCommand.hxx"
15
16 //=======================================================================
17 //function : 
18 //purpose  : 
19 //=======================================================================
20 void SMESHDS_Script::AddNode(const Standard_Integer NewNodeID,
21                              const Standard_Real x,
22                              const Standard_Real y,
23                              const Standard_Real z) 
24 {
25   Handle(SMESHDS_Command) com;
26   if (myCommands.IsEmpty()) {
27     com = new SMESHDS_Command(SMESHDS_AddNode);
28     myCommands.Append (com);
29   }
30   else {
31     com = myCommands.Last();
32     if (com->GetType() != SMESHDS_AddNode) {
33       com = new SMESHDS_Command(SMESHDS_AddNode);
34       myCommands.Append (com);
35     }
36   }
37   com->AddNode (NewNodeID,x,y,z);
38 }
39
40
41 //=======================================================================
42 //function : 
43 //purpose  : 
44 //=======================================================================
45 void SMESHDS_Script::AddEdge(const Standard_Integer NewEdgeID,
46                              const Standard_Integer idnode1,
47                              const Standard_Integer idnode2) 
48 {
49   Handle(SMESHDS_Command) com;
50   if (myCommands.IsEmpty()) {
51     com = new SMESHDS_Command(SMESHDS_AddEdge);
52     myCommands.Append (com);
53   }
54   else {
55     com = myCommands.Last();
56     if (com->GetType() != SMESHDS_AddEdge) {
57       com = new SMESHDS_Command(SMESHDS_AddEdge);
58       myCommands.Append (com);
59     }
60   }
61   com->AddEdge (NewEdgeID,idnode1,idnode2);
62 }
63
64 //=======================================================================
65 //function : 
66 //purpose  : 
67 //=======================================================================
68 void SMESHDS_Script::AddFace(const Standard_Integer NewFaceID,
69                              const Standard_Integer idnode1,
70                              const Standard_Integer idnode2,
71                              const Standard_Integer idnode3) 
72 {
73   Handle(SMESHDS_Command) com;
74   if (myCommands.IsEmpty()) {
75     com = new SMESHDS_Command(SMESHDS_AddTriangle);
76     myCommands.Append (com);
77   }
78   else {
79     com = myCommands.Last();
80     if (com->GetType() != SMESHDS_AddTriangle) {
81       com = new SMESHDS_Command(SMESHDS_AddTriangle);
82       myCommands.Append (com);
83     }
84   }
85   com->AddFace (NewFaceID,idnode1,idnode2,idnode3);
86 }
87
88 //=======================================================================
89 //function : 
90 //purpose  : 
91 //=======================================================================
92 void SMESHDS_Script::AddFace(const Standard_Integer NewFaceID,
93                              const Standard_Integer idnode1,
94                              const Standard_Integer idnode2,
95                              const Standard_Integer idnode3,
96                              const Standard_Integer idnode4) 
97 {
98   Handle(SMESHDS_Command) com;
99   if (myCommands.IsEmpty()) {
100     com = new SMESHDS_Command(SMESHDS_AddQuadrangle);
101     myCommands.Append (com);
102   }
103   else {
104     com = myCommands.Last();
105     if (com->GetType() != SMESHDS_AddQuadrangle) {
106       com = new SMESHDS_Command(SMESHDS_AddQuadrangle);
107       myCommands.Append (com);
108     }
109   }
110   com->AddFace (NewFaceID,idnode1,idnode2,idnode3,idnode4);
111 }
112
113 //=======================================================================
114 //function : 
115 //purpose  : 
116 //=======================================================================
117 void SMESHDS_Script::AddVolume(const Standard_Integer NewID,
118                                const Standard_Integer idnode1,
119                                const Standard_Integer idnode2,
120                                const Standard_Integer idnode3,
121                                const Standard_Integer idnode4) 
122 {
123   Handle(SMESHDS_Command) com;
124   if (myCommands.IsEmpty()) {
125     com = new SMESHDS_Command(SMESHDS_AddTetrahedron);
126     myCommands.Append (com);
127   }
128   else {
129     com = myCommands.Last();
130     if (com->GetType() != SMESHDS_AddQuadrangle) {
131       com = new SMESHDS_Command(SMESHDS_AddQuadrangle);
132       myCommands.Append (com);
133     }
134   }
135   com->AddVolume (NewID,idnode1,idnode2,idnode3,idnode4);
136 }
137
138 //=======================================================================
139 //function : 
140 //purpose  : 
141 //=======================================================================
142 void SMESHDS_Script::AddVolume(const Standard_Integer NewID,
143                                const Standard_Integer idnode1,
144                                const Standard_Integer idnode2,
145                                const Standard_Integer idnode3,
146                                const Standard_Integer idnode4,
147                                const Standard_Integer idnode5) 
148 {
149   Handle(SMESHDS_Command) com;
150   if (myCommands.IsEmpty()) {
151     com = new SMESHDS_Command(SMESHDS_AddPyramid);
152     myCommands.Append (com);
153   }
154   else {
155     com = myCommands.Last();
156     if (com->GetType() != SMESHDS_AddPyramid) {
157       com = new SMESHDS_Command(SMESHDS_AddPyramid);
158       myCommands.Append (com);
159     }
160   }
161   com->AddVolume (NewID,idnode1,idnode2,idnode3,idnode4,idnode5);
162 }
163
164 //=======================================================================
165 //function : 
166 //purpose  : 
167 //=======================================================================
168 void SMESHDS_Script::AddVolume(const Standard_Integer NewID,
169                                const Standard_Integer idnode1,
170                                const Standard_Integer idnode2,
171                                const Standard_Integer idnode3,
172                                const Standard_Integer idnode4,
173                                const Standard_Integer idnode5,
174                                const Standard_Integer idnode6) 
175 {
176   Handle(SMESHDS_Command) com;
177   if (myCommands.IsEmpty()) {
178     com = new SMESHDS_Command(SMESHDS_AddPrism);
179     myCommands.Append (com);
180   }
181   else {
182     com = myCommands.Last();
183     if (com->GetType() != SMESHDS_AddPrism) {
184       com = new SMESHDS_Command(SMESHDS_AddPrism);
185       myCommands.Append (com);
186     }
187   }
188   com->AddVolume (NewID,idnode1,idnode2,idnode3,idnode4,idnode5,idnode6);
189 }
190
191 //=======================================================================
192 //function : 
193 //purpose  : 
194 //=======================================================================
195 void SMESHDS_Script::AddVolume(const Standard_Integer NewID,
196                                const Standard_Integer idnode1,
197                                const Standard_Integer idnode2,
198                                const Standard_Integer idnode3,
199                                const Standard_Integer idnode4,
200                                const Standard_Integer idnode5,
201                                const Standard_Integer idnode6,
202                                const Standard_Integer idnode7,
203                                const Standard_Integer idnode8) 
204 {
205   Handle(SMESHDS_Command) com;
206   if (myCommands.IsEmpty()) {
207     com = new SMESHDS_Command(SMESHDS_AddHexahedron);
208     myCommands.Append (com);
209   }
210   else {
211     com = myCommands.Last();
212     if (com->GetType() != SMESHDS_AddHexahedron) {
213       com = new SMESHDS_Command(SMESHDS_AddHexahedron);
214       myCommands.Append (com);
215     }
216   }
217   com->AddVolume (NewID,idnode1,idnode2,idnode3,idnode4,
218                  idnode5,idnode6,idnode7,idnode8);
219 }
220
221 //=======================================================================
222 //function : 
223 //purpose  : 
224 //=======================================================================
225 void SMESHDS_Script::MoveNode(const Standard_Integer NewNodeID,
226                               const Standard_Real x,
227                               const Standard_Real y,
228                               const Standard_Real z) 
229 {
230   Handle(SMESHDS_Command) com;
231   if (myCommands.IsEmpty()) {
232     com = new SMESHDS_Command(SMESHDS_MoveNode);
233     myCommands.Append (com);
234   }
235   else {
236     com = myCommands.Last();
237     if (com->GetType() != SMESHDS_MoveNode) {
238       com = new SMESHDS_Command(SMESHDS_MoveNode);
239       myCommands.Append (com);
240     }
241   }
242   com->MoveNode (NewNodeID,x,y,z);
243 }
244
245
246 //=======================================================================
247 //function : 
248 //purpose  : 
249 //=======================================================================
250 void SMESHDS_Script::RemoveNode(const Standard_Integer ID) 
251 {
252   Handle(SMESHDS_Command) com;
253   if (myCommands.IsEmpty()) {
254     com = new SMESHDS_Command(SMESHDS_RemoveNode);
255     myCommands.Append (com);
256   }
257   else {
258     com = myCommands.Last();
259     if (com->GetType() != SMESHDS_RemoveNode) {
260       com = new SMESHDS_Command(SMESHDS_RemoveNode);
261       myCommands.Append (com);
262     }
263   }
264   com->RemoveNode (ID);
265 }
266
267 //=======================================================================
268 //function : 
269 //purpose  : 
270 //=======================================================================
271  void SMESHDS_Script::RemoveElement(const Standard_Integer ElementID) 
272 {
273   Handle(SMESHDS_Command) com;
274   if (myCommands.IsEmpty()) {
275     com = new SMESHDS_Command(SMESHDS_RemoveElement);
276     myCommands.Append (com);
277   }
278   else {
279     com = myCommands.Last();
280     if (com->GetType() != SMESHDS_RemoveElement) {
281       com = new SMESHDS_Command(SMESHDS_RemoveElement);
282       myCommands.Append (com);
283     }
284   }
285   com->RemoveElement (ElementID);
286 }
287
288 //=======================================================================
289 //function : 
290 //purpose  : 
291 //=======================================================================
292 void SMESHDS_Script::Clear() 
293 {
294   myCommands.Clear();
295 }
296
297 //=======================================================================
298 //function : 
299 //purpose  : 
300 //=======================================================================
301 const SMESHDS_ListOfCommand&  SMESHDS_Script::GetCommands() 
302 {
303   return myCommands;
304 }