Salome HOME
Use nodes and elements pointer instead on IDs
[modules/smesh.git] / src / SMESHDS / SMESHDS_Script.cxx
1 //  SMESH SMESHDS : management of mesh data and SMESH document
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_Script.cxx
25 //  Author : Yves FRICAUD, OCC
26 //  Module : SMESH
27 //  $Header: 
28
29 using namespace std;
30 #include "SMESHDS_Script.hxx"
31
32 //=======================================================================
33 //function : 
34 //purpose  : 
35 //=======================================================================
36 void SMESHDS_Script::AddNode(int NewNodeID, double x, double y, double z)
37 {
38         SMESHDS_Command* com;
39         if (myCommands.empty())
40         {
41                 com = new SMESHDS_Command(SMESHDS_AddNode);
42                 myCommands.insert(myCommands.end(),com);
43         }
44         else
45         {
46                 com = myCommands.back();
47                 if (com->GetType() != SMESHDS_AddNode)
48                 {
49                         com = new SMESHDS_Command(SMESHDS_AddNode);
50                         myCommands.insert(myCommands.end(),com);
51                 }
52         }
53         com->AddNode(NewNodeID, x, y, z);
54 }
55
56 //=======================================================================
57 //function : 
58 //purpose  : 
59 //=======================================================================
60 void SMESHDS_Script::AddEdge(int NewEdgeID, int idnode1, int idnode2)
61 {
62         SMESHDS_Command* com;
63         if (myCommands.empty())
64         {
65                 com = new SMESHDS_Command(SMESHDS_AddEdge);
66                 myCommands.insert(myCommands.end(), com);
67         }
68         else
69         {
70                 com = myCommands.back();
71                 if (com->GetType() != SMESHDS_AddEdge)
72                 {
73                         com = new SMESHDS_Command(SMESHDS_AddEdge);
74                         myCommands.insert(myCommands.end(), com);
75                 }
76         }
77         com->AddEdge(NewEdgeID, idnode1, idnode2);
78 }
79
80 //=======================================================================
81 //function : 
82 //purpose  : 
83 //=======================================================================
84 void SMESHDS_Script::AddFace(int NewFaceID,
85         int idnode1, int idnode2, int idnode3)
86 {
87         SMESHDS_Command * com;
88         if (myCommands.empty())
89         {
90                 com = new SMESHDS_Command(SMESHDS_AddTriangle);
91                 myCommands.insert(myCommands.end(),com);
92         }
93         else
94         {
95                 com = myCommands.back();
96                 if (com->GetType() != SMESHDS_AddTriangle)
97                 {
98                         com = new SMESHDS_Command(SMESHDS_AddTriangle);
99                         myCommands.insert(myCommands.end(),com);
100                 }
101         }
102         com->AddFace(NewFaceID, idnode1, idnode2, idnode3);
103 }
104
105 //=======================================================================
106 //function : 
107 //purpose  : 
108 //=======================================================================
109 void SMESHDS_Script::AddFace(int NewFaceID,
110         int idnode1, int idnode2, int idnode3, int idnode4)
111 {
112         SMESHDS_Command * com;
113         if (myCommands.empty())
114         {
115                 com = new SMESHDS_Command(SMESHDS_AddQuadrangle);
116                 myCommands.insert(myCommands.end(),com);
117         }
118         else
119         {
120                 com = myCommands.back();
121                 if (com->GetType() != SMESHDS_AddQuadrangle)
122                 {
123                         com = new SMESHDS_Command(SMESHDS_AddQuadrangle);
124                         myCommands.insert(myCommands.end(),com);
125                 }
126         }
127         com->AddFace(NewFaceID, idnode1, idnode2, idnode3, idnode4);
128 }
129
130 //=======================================================================
131 //function : 
132 //purpose  : 
133 //=======================================================================
134 void SMESHDS_Script::AddVolume(int NewID,
135         int idnode1, int idnode2, int idnode3, int idnode4)
136 {
137         SMESHDS_Command * com;
138         if (myCommands.empty())
139         {
140                 com = new SMESHDS_Command(SMESHDS_AddTetrahedron);
141                 myCommands.insert(myCommands.end(),com);
142         }
143         else
144         {
145                 com = myCommands.back();
146                 if (com->GetType() != SMESHDS_AddQuadrangle)
147                 {
148                         com = new SMESHDS_Command(SMESHDS_AddQuadrangle);
149                         myCommands.insert(myCommands.end(),com);
150                 }
151         }
152         com->AddVolume(NewID, idnode1, idnode2, idnode3, idnode4);
153 }
154
155 //=======================================================================
156 //function : 
157 //purpose  : 
158 //=======================================================================
159 void SMESHDS_Script::AddVolume(int NewID,
160         int idnode1, int idnode2, int idnode3, int idnode4, int idnode5)
161 {
162         SMESHDS_Command * com;
163         if (myCommands.empty())
164         {
165                 com = new SMESHDS_Command(SMESHDS_AddPyramid);
166                 myCommands.insert(myCommands.end(),com);
167         }
168         else
169         {
170                 com = myCommands.back();
171                 if (com->GetType() != SMESHDS_AddPyramid)
172                 {
173                         com = new SMESHDS_Command(SMESHDS_AddPyramid);
174                         myCommands.insert(myCommands.end(),com);
175                 }
176         }
177         com->AddVolume(NewID, idnode1, idnode2, idnode3, idnode4, idnode5);
178 }
179
180 //=======================================================================
181 //function : 
182 //purpose  : 
183 //=======================================================================
184 void SMESHDS_Script::AddVolume(int NewID,
185         int idnode1,
186         int idnode2, int idnode3, int idnode4, int idnode5, int idnode6)
187 {
188         SMESHDS_Command * com;
189         if (myCommands.empty())
190         {
191                 com = new SMESHDS_Command(SMESHDS_AddPrism);
192                 myCommands.insert(myCommands.end(),com);
193         }
194         else
195         {
196                 com = myCommands.back();
197                 if (com->GetType() != SMESHDS_AddPrism)
198                 {
199                         com = new SMESHDS_Command(SMESHDS_AddPrism);
200                         myCommands.insert(myCommands.end(),com);
201                 }
202         }
203         com->AddVolume(NewID, idnode1, idnode2, idnode3, idnode4, idnode5, idnode6);
204 }
205
206 //=======================================================================
207 //function : 
208 //purpose  : 
209 //=======================================================================
210 void SMESHDS_Script::AddVolume(int NewID,
211         int idnode1,
212         int idnode2,
213         int idnode3,
214         int idnode4, int idnode5, int idnode6, int idnode7, int idnode8)
215 {
216         SMESHDS_Command * com;
217         if (myCommands.empty())
218         {
219                 com = new SMESHDS_Command(SMESHDS_AddHexahedron);
220                 myCommands.insert(myCommands.end(),com);
221         }
222         else
223         {
224                 com = myCommands.back();
225                 if (com->GetType() != SMESHDS_AddHexahedron)
226                 {
227                         com = new SMESHDS_Command(SMESHDS_AddHexahedron);
228                         myCommands.insert(myCommands.end(),com);
229                 }
230         }
231         com->AddVolume(NewID, idnode1, idnode2, idnode3, idnode4,
232                 idnode5, idnode6, idnode7, idnode8);
233 }
234
235 //=======================================================================
236 //function : 
237 //purpose  : 
238 //=======================================================================
239 void SMESHDS_Script::MoveNode(int NewNodeID, double x, double y, double z)
240 {
241         SMESHDS_Command * com;
242         if (myCommands.empty())
243         {
244                 com = new SMESHDS_Command(SMESHDS_MoveNode);
245                 myCommands.insert(myCommands.end(),com);
246         }
247         else
248         {
249                 com = myCommands.back();
250                 if (com->GetType() != SMESHDS_MoveNode)
251                 {
252                         com = new SMESHDS_Command(SMESHDS_MoveNode);
253                         myCommands.insert(myCommands.end(),com);
254                 }
255         }
256         com->MoveNode(NewNodeID, x, y, z);
257 }
258
259 //=======================================================================
260 //function : 
261 //purpose  : 
262 //=======================================================================
263 void SMESHDS_Script::RemoveNode(int ID)
264 {
265         SMESHDS_Command * com;
266         if (myCommands.empty())
267         {
268                 com = new SMESHDS_Command(SMESHDS_RemoveNode);
269                 myCommands.insert(myCommands.end(),com);
270         }
271         else
272         {
273                 com = myCommands.back();
274                 if (com->GetType() != SMESHDS_RemoveNode)
275                 {
276                         com = new SMESHDS_Command(SMESHDS_RemoveNode);
277                         myCommands.insert(myCommands.end(),com);
278                 }
279         }
280         com->RemoveNode(ID);
281 }
282
283 //=======================================================================
284 //function : 
285 //purpose  : 
286 //=======================================================================
287 void SMESHDS_Script::RemoveElement(int ElementID)
288 {
289         SMESHDS_Command * com;
290         if (myCommands.empty())
291         {
292                 com = new SMESHDS_Command(SMESHDS_RemoveElement);
293                 myCommands.insert(myCommands.end(),com);
294         }
295         else
296         {
297                 com = myCommands.back();
298                 if (com->GetType() != SMESHDS_RemoveElement)
299                 {
300                         com = new SMESHDS_Command(SMESHDS_RemoveElement);
301                         myCommands.insert(myCommands.end(),com);
302                 }
303         }
304         com->RemoveElement(ElementID);
305 }
306
307 //=======================================================================
308 //function : 
309 //purpose  : 
310 //=======================================================================
311 void SMESHDS_Script::Clear()
312 {
313         myCommands.clear();
314 }
315
316 //=======================================================================
317 //function : 
318 //purpose  : 
319 //=======================================================================
320 const list<SMESHDS_Command*>& SMESHDS_Script::GetCommands()
321 {
322         return myCommands;
323 }