Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : SMESH_Script.cxx
25 //  Author : Yves FRICAUD, OCC
26 //  Module : SMESH
27 //  $Header: 
28
29 #include "SMESHDS_Script.hxx"
30
31 using namespace std;
32
33 //=======================================================================
34 //function : Constructor
35 //purpose  : 
36 //=======================================================================
37 SMESHDS_Script::SMESHDS_Script(bool theIsEmbeddedMode):
38   myIsEmbeddedMode(theIsEmbeddedMode)
39 {}
40
41 //=======================================================================
42 //function : Destructor
43 //purpose  : 
44 //=======================================================================
45 SMESHDS_Script::~SMESHDS_Script()
46 {
47   Clear();
48 }
49
50 //=======================================================================
51 void SMESHDS_Script::SetModified(bool theModified)
52 {
53   myIsModified = theModified;
54 }
55
56 //=======================================================================
57 bool SMESHDS_Script::IsModified()
58 {
59   return myIsModified;
60 }
61
62 //=======================================================================
63 //function : getCommand
64 //purpose  : 
65 //=======================================================================
66 SMESHDS_Command* SMESHDS_Script::getCommand(const SMESHDS_CommandType aType)
67 {
68   SMESHDS_Command* com;
69   if (myCommands.empty())
70   {
71     com = new SMESHDS_Command(aType);
72     myCommands.insert(myCommands.end(),com);
73   }
74   else
75   {
76     com = myCommands.back();
77     if (com->GetType() != aType)
78     {
79       com = new SMESHDS_Command(aType);
80       myCommands.insert(myCommands.end(),com);
81     }
82   }
83   return com;
84 }
85
86 //=======================================================================
87 //function : 
88 //purpose  : 
89 //=======================================================================
90 void SMESHDS_Script::AddNode(int NewNodeID, double x, double y, double z)
91 {
92   if(myIsEmbeddedMode){
93     myIsModified = true;
94     return;
95   }
96   getCommand(SMESHDS_AddNode)->AddNode(NewNodeID, x, y, z);
97 }
98
99 //=======================================================================
100 //function : 
101 //purpose  : 
102 //=======================================================================
103 void SMESHDS_Script::AddEdge(int NewEdgeID, int idnode1, int idnode2)
104 {
105   if(myIsEmbeddedMode){
106     myIsModified = true;
107     return;
108   }
109   getCommand(SMESHDS_AddEdge)->AddEdge(NewEdgeID, idnode1, idnode2);
110 }
111
112 //=======================================================================
113 //function : 
114 //purpose  : 
115 //=======================================================================
116 void SMESHDS_Script::AddFace(int NewFaceID,
117                              int idnode1, int idnode2, int idnode3)
118 {
119   if(myIsEmbeddedMode){
120     myIsModified = true;
121     return;
122   }
123   getCommand(SMESHDS_AddTriangle)->AddFace(NewFaceID,
124                                            idnode1, idnode2, idnode3);
125 }
126
127 //=======================================================================
128 //function : 
129 //purpose  : 
130 //=======================================================================
131 void SMESHDS_Script::AddFace(int NewFaceID,
132                              int idnode1, int idnode2,
133                              int idnode3, int idnode4)
134 {
135   if(myIsEmbeddedMode){
136     myIsModified = true;
137     return;
138   }
139   getCommand(SMESHDS_AddQuadrangle)->AddFace(NewFaceID,
140                                              idnode1, idnode2,
141                                              idnode3, idnode4);
142 }
143
144 //=======================================================================
145 //function : 
146 //purpose  : 
147 //=======================================================================
148 void SMESHDS_Script::AddVolume(int NewID,
149                                int idnode1, int idnode2,
150                                int idnode3, int idnode4)
151 {
152   if(myIsEmbeddedMode){
153     myIsModified = true;
154     return;
155   }
156   getCommand(SMESHDS_AddTetrahedron)->AddVolume(NewID,
157                                                 idnode1, idnode2,
158                                                 idnode3, idnode4);
159 }
160
161 //=======================================================================
162 //function : 
163 //purpose  : 
164 //=======================================================================
165 void SMESHDS_Script::AddVolume(int NewID,
166                                int idnode1, int idnode2,
167                                int idnode3, int idnode4, int idnode5)
168 {
169   if(myIsEmbeddedMode){
170     myIsModified = true;
171     return;
172   }
173   getCommand(SMESHDS_AddPyramid)->AddVolume(NewID,
174                                             idnode1, idnode2,
175                                             idnode3, idnode4, idnode5);
176 }
177
178 //=======================================================================
179 //function : 
180 //purpose  : 
181 //=======================================================================
182 void SMESHDS_Script::AddVolume(int NewID,
183                                int idnode1, int idnode2, int idnode3,
184                                int idnode4, int idnode5, int idnode6)
185 {
186   if(myIsEmbeddedMode){
187     myIsModified = true;
188     return;
189   }
190   getCommand(SMESHDS_AddPrism)->AddVolume(NewID,
191                                           idnode1, idnode2, idnode3,
192                                           idnode4, idnode5, idnode6);
193 }
194
195 //=======================================================================
196 //function : 
197 //purpose  : 
198 //=======================================================================
199 void SMESHDS_Script::AddVolume(int NewID,
200                                int idnode1, int idnode2, int idnode3, int idnode4,
201                                int idnode5, int idnode6, int idnode7, int idnode8)
202 {
203   if(myIsEmbeddedMode){
204     myIsModified = true;
205     return;
206   }
207   getCommand(SMESHDS_AddHexahedron)->AddVolume(NewID,
208                                                idnode1, idnode2, idnode3, idnode4,
209                                                idnode5, idnode6, idnode7, idnode8);
210 }
211
212 //=======================================================================
213 //function : AddPolygonalFace
214 //purpose  : 
215 //=======================================================================
216 void SMESHDS_Script::AddPolygonalFace (int NewFaceID, std::vector<int> nodes_ids)
217 {
218   if(myIsEmbeddedMode){
219     myIsModified = true;
220     return;
221   }
222   getCommand(SMESHDS_AddPolygon)->AddPolygonalFace(NewFaceID, nodes_ids);
223 }
224
225 //=======================================================================
226 //function : AddPolyhedralVolume
227 //purpose  : 
228 //=======================================================================
229 void SMESHDS_Script::AddPolyhedralVolume (int NewID,
230                                           std::vector<int> nodes_ids,
231                                           std::vector<int> quantities)
232 {
233   if(myIsEmbeddedMode){
234     myIsModified = true;
235     return;
236   }
237   getCommand(SMESHDS_AddPolyhedron)->AddPolyhedralVolume
238     (NewID, nodes_ids, quantities);
239 }
240
241 //=======================================================================
242 //function : 
243 //purpose  : 
244 //=======================================================================
245 void SMESHDS_Script::MoveNode(int NewNodeID, double x, double y, double z)
246 {
247   if(myIsEmbeddedMode){
248     myIsModified = true;
249     return;
250   }
251   getCommand(SMESHDS_MoveNode)->MoveNode(NewNodeID, x, y, z);
252 }
253
254 //=======================================================================
255 //function : 
256 //purpose  : 
257 //=======================================================================
258 void SMESHDS_Script::RemoveNode(int ID)
259 {
260   if(myIsEmbeddedMode){
261     myIsModified = true;
262     return;
263   }
264   getCommand(SMESHDS_RemoveNode)->RemoveNode(ID);
265 }
266
267 //=======================================================================
268 //function : 
269 //purpose  : 
270 //=======================================================================
271 void SMESHDS_Script::RemoveElement(int ElementID)
272 {
273   if(myIsEmbeddedMode){
274     myIsModified = true;
275     return;
276   }
277   getCommand(SMESHDS_RemoveElement)->RemoveElement(ElementID);
278 }
279
280 //=======================================================================
281 //function : ChangeElementNodes
282 //purpose  : 
283 //=======================================================================
284
285 void SMESHDS_Script::ChangeElementNodes(int ElementID, int nodes[], int nbnodes)
286 {
287   if(myIsEmbeddedMode){
288     myIsModified = true;
289     return;
290   }
291   getCommand(SMESHDS_ChangeElementNodes)->ChangeElementNodes( ElementID, nodes, nbnodes );
292 }
293
294 //=======================================================================
295 //function : ChangePolyhedronNodes
296 //purpose  : 
297 //=======================================================================
298 void SMESHDS_Script::ChangePolyhedronNodes (const int        ElementID,
299                                             std::vector<int> nodes_ids,
300                                             std::vector<int> quantities)
301 {
302   if(myIsEmbeddedMode){
303     myIsModified = true;
304     return;
305   }
306   getCommand(SMESHDS_ChangePolyhedronNodes)->ChangePolyhedronNodes
307     (ElementID, nodes_ids, quantities);
308 }
309
310 //=======================================================================
311 //function : Renumber
312 //purpose  : 
313 //=======================================================================
314 void SMESHDS_Script::Renumber (const bool isNodes, const int startID, const int deltaID)
315 {
316   if(myIsEmbeddedMode){
317     myIsModified = true;
318     return;
319   }
320   getCommand(SMESHDS_Renumber)->Renumber( isNodes, startID, deltaID );
321 }
322
323 //=======================================================================
324 //function : 
325 //purpose  : 
326 //=======================================================================
327 void SMESHDS_Script::Clear()
328 {
329   list<SMESHDS_Command*>::iterator anIt = myCommands.begin();
330   for (; anIt != myCommands.end(); anIt++) {
331     delete (*anIt);
332   }
333   myCommands.clear();
334 }
335
336 //=======================================================================
337 //function : 
338 //purpose  : 
339 //=======================================================================
340 const list<SMESHDS_Command*>& SMESHDS_Script::GetCommands()
341 {
342   return myCommands;
343 }
344
345
346 //********************************************************************
347 //*****             Methods for quadratic elements              ******
348 //********************************************************************
349
350 //=======================================================================
351 //function : AddEdge
352 //purpose  : 
353 //=======================================================================
354 void SMESHDS_Script::AddEdge(int NewEdgeID, int n1, int n2, int n12)
355 {
356   if(myIsEmbeddedMode){
357     myIsModified = true;
358     return;
359   }
360   getCommand(SMESHDS_AddQuadEdge)->AddEdge(NewEdgeID, n1, n2, n12);
361 }
362
363 //=======================================================================
364 //function : AddFace
365 //purpose  : 
366 //=======================================================================
367 void SMESHDS_Script::AddFace(int NewFaceID, int n1, int n2, int n3,
368                              int n12, int n23, int n31)
369 {
370   if(myIsEmbeddedMode){
371     myIsModified = true;
372     return;
373   }
374   getCommand(SMESHDS_AddQuadTriangle)->AddFace(NewFaceID, n1, n2, n3,
375                                                n12, n23, n31);
376 }
377
378 //=======================================================================
379 //function : AddFace
380 //purpose  : 
381 //=======================================================================
382 void SMESHDS_Script::AddFace(int NewFaceID, int n1, int n2, int n3, int n4,
383                              int n12, int n23, int n34, int n41)
384 {
385   if(myIsEmbeddedMode){
386     myIsModified = true;
387     return;
388   }
389   getCommand(SMESHDS_AddQuadQuadrangle)->AddFace(NewFaceID, n1, n2, n3, n4,
390                                                  n12, n23, n34, n41);
391 }
392
393 //=======================================================================
394 //function : AddVolume
395 //purpose  : 
396 //=======================================================================
397 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
398                                int n12, int n23, int n31,
399                                int n14, int n24, int n34)
400 {
401   if(myIsEmbeddedMode){
402     myIsModified = true;
403     return;
404   }
405   getCommand(SMESHDS_AddQuadTetrahedron)->AddVolume(NewVolID, n1, n2, n3, n4,
406                                                     n12, n23, n31,
407                                                     n14, n24, n34);
408 }
409
410 //=======================================================================
411 //function : AddVolume
412 //purpose  : 
413 //=======================================================================
414 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
415                                int n5, int n12, int n23, int n34, int n41,
416                                int n15, int n25, int n35, int n45)
417 {
418   if(myIsEmbeddedMode){
419     myIsModified = true;
420     return;
421   }
422   getCommand(SMESHDS_AddQuadPyramid)->AddVolume(NewVolID, n1, n2, n3, n4, n5,
423                                                 n12, n23, n34, n41,
424                                                 n15, n25, n35, n45);
425 }
426
427 //=======================================================================
428 //function : AddVolume
429 //purpose  : 
430 //=======================================================================
431 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
432                                 int n5,int n6, int n12, int n23, int n31,
433                                 int n45, int n56, int n64,
434                                 int n14, int n25, int n36)
435 {
436   if(myIsEmbeddedMode){
437     myIsModified = true;
438     return;
439   }
440   getCommand(SMESHDS_AddQuadPentahedron)->AddVolume(NewVolID, n1,n2,n3,n4,n5,n6,
441                                                     n12, n23, n31,
442                                                     n45, n56, n64,
443                                                     n14, n25, n36);
444 }
445
446 //=======================================================================
447 //function : AddVolume
448 //purpose  : 
449 //=======================================================================
450 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3,
451                                int n4, int n5, int n6, int n7, int n8,
452                                int n12, int n23, int n34, int n41,
453                                int n56, int n67, int n78, int n85,
454                                int n15, int n26, int n37, int n48)
455 {
456   if(myIsEmbeddedMode){
457     myIsModified = true;
458     return;
459   }
460   getCommand(SMESHDS_AddQuadHexahedron)->AddVolume(NewVolID, n1, n2, n3, n4,
461                                                    n5, n6, n7, n8,
462                                                    n12, n23, n34, n41,
463                                                    n56, n67, n78, n85,
464                                                    n15, n26, n37, n48);
465 }
466