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