Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[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 #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   getCommand(SMESHDS_AddNode)->AddNode(NewNodeID, x, y, z);
93 }
94
95 //=======================================================================
96 //function : 
97 //purpose  : 
98 //=======================================================================
99 void SMESHDS_Script::AddEdge(int NewEdgeID, int idnode1, int idnode2)
100 {
101   if(myIsEmbeddedMode){
102     myIsModified = true;
103     return;
104   }
105   getCommand(SMESHDS_AddEdge)->AddEdge(NewEdgeID, idnode1, idnode2);
106 }
107
108 //=======================================================================
109 //function : 
110 //purpose  : 
111 //=======================================================================
112 void SMESHDS_Script::AddFace(int NewFaceID,
113                              int idnode1, int idnode2, int idnode3)
114 {
115   if(myIsEmbeddedMode){
116     myIsModified = true;
117     return;
118   }
119   getCommand(SMESHDS_AddTriangle)->AddFace(NewFaceID,
120                                            idnode1, idnode2, idnode3);
121 }
122
123 //=======================================================================
124 //function : 
125 //purpose  : 
126 //=======================================================================
127 void SMESHDS_Script::AddFace(int NewFaceID,
128                              int idnode1, int idnode2,
129                              int idnode3, int idnode4)
130 {
131   if(myIsEmbeddedMode){
132     myIsModified = true;
133     return;
134   }
135   getCommand(SMESHDS_AddQuadrangle)->AddFace(NewFaceID,
136                                              idnode1, idnode2,
137                                              idnode3, idnode4);
138 }
139
140 //=======================================================================
141 //function : 
142 //purpose  : 
143 //=======================================================================
144 void SMESHDS_Script::AddVolume(int NewID,
145                                int idnode1, int idnode2,
146                                int idnode3, int idnode4)
147 {
148   if(myIsEmbeddedMode){
149     myIsModified = true;
150     return;
151   }
152   getCommand(SMESHDS_AddTetrahedron)->AddVolume(NewID,
153                                                 idnode1, idnode2,
154                                                 idnode3, idnode4);
155 }
156
157 //=======================================================================
158 //function : 
159 //purpose  : 
160 //=======================================================================
161 void SMESHDS_Script::AddVolume(int NewID,
162                                int idnode1, int idnode2,
163                                int idnode3, int idnode4, int idnode5)
164 {
165   if(myIsEmbeddedMode){
166     myIsModified = true;
167     return;
168   }
169   getCommand(SMESHDS_AddPyramid)->AddVolume(NewID,
170                                             idnode1, idnode2,
171                                             idnode3, idnode4, idnode5);
172 }
173
174 //=======================================================================
175 //function : 
176 //purpose  : 
177 //=======================================================================
178 void SMESHDS_Script::AddVolume(int NewID,
179                                int idnode1, int idnode2, int idnode3,
180                                int idnode4, int idnode5, int idnode6)
181 {
182   if(myIsEmbeddedMode){
183     myIsModified = true;
184     return;
185   }
186   getCommand(SMESHDS_AddPrism)->AddVolume(NewID,
187                                           idnode1, idnode2, idnode3,
188                                           idnode4, idnode5, idnode6);
189 }
190
191 //=======================================================================
192 //function : 
193 //purpose  : 
194 //=======================================================================
195 void SMESHDS_Script::AddVolume(int NewID,
196                                int idnode1, int idnode2, int idnode3, int idnode4,
197                                int idnode5, int idnode6, int idnode7, int idnode8)
198 {
199   if(myIsEmbeddedMode){
200     myIsModified = true;
201     return;
202   }
203   getCommand(SMESHDS_AddHexahedron)->AddVolume(NewID,
204                                                idnode1, idnode2, idnode3, idnode4,
205                                                idnode5, idnode6, idnode7, idnode8);
206 }
207
208 //=======================================================================
209 //function : AddPolygonalFace
210 //purpose  : 
211 //=======================================================================
212 void SMESHDS_Script::AddPolygonalFace (int NewFaceID, std::vector<int> nodes_ids)
213 {
214   if(myIsEmbeddedMode){
215     myIsModified = true;
216     return;
217   }
218   getCommand(SMESHDS_AddPolygon)->AddPolygonalFace(NewFaceID, nodes_ids);
219 }
220
221 //=======================================================================
222 //function : AddPolyhedralVolume
223 //purpose  : 
224 //=======================================================================
225 void SMESHDS_Script::AddPolyhedralVolume (int NewID,
226                                           std::vector<int> nodes_ids,
227                                           std::vector<int> quantities)
228 {
229   if(myIsEmbeddedMode){
230     myIsModified = true;
231     return;
232   }
233   getCommand(SMESHDS_AddPolyhedron)->AddPolyhedralVolume
234     (NewID, nodes_ids, quantities);
235 }
236
237 //=======================================================================
238 //function : 
239 //purpose  : 
240 //=======================================================================
241 void SMESHDS_Script::MoveNode(int NewNodeID, double x, double y, double z)
242 {
243   if(myIsEmbeddedMode){
244     myIsModified = true;
245     return;
246   }
247   getCommand(SMESHDS_MoveNode)->MoveNode(NewNodeID, x, y, z);
248 }
249
250 //=======================================================================
251 //function : 
252 //purpose  : 
253 //=======================================================================
254 void SMESHDS_Script::RemoveNode(int ID)
255 {
256   if(myIsEmbeddedMode){
257     myIsModified = true;
258     return;
259   }
260   getCommand(SMESHDS_RemoveNode)->RemoveNode(ID);
261 }
262
263 //=======================================================================
264 //function : 
265 //purpose  : 
266 //=======================================================================
267 void SMESHDS_Script::RemoveElement(int ElementID)
268 {
269   if(myIsEmbeddedMode){
270     myIsModified = true;
271     return;
272   }
273   getCommand(SMESHDS_RemoveElement)->RemoveElement(ElementID);
274 }
275
276 //=======================================================================
277 //function : ChangeElementNodes
278 //purpose  : 
279 //=======================================================================
280
281 void SMESHDS_Script::ChangeElementNodes(int ElementID, int nodes[], int nbnodes)
282 {
283   if(myIsEmbeddedMode){
284     myIsModified = true;
285     return;
286   }
287   getCommand(SMESHDS_ChangeElementNodes)->ChangeElementNodes( ElementID, nodes, nbnodes );
288 }
289
290 //=======================================================================
291 //function : ChangePolyhedronNodes
292 //purpose  : 
293 //=======================================================================
294 void SMESHDS_Script::ChangePolyhedronNodes (const int        ElementID,
295                                             std::vector<int> nodes_ids,
296                                             std::vector<int> quantities)
297 {
298   if(myIsEmbeddedMode){
299     myIsModified = true;
300     return;
301   }
302   getCommand(SMESHDS_ChangePolyhedronNodes)->ChangePolyhedronNodes
303     (ElementID, nodes_ids, quantities);
304 }
305
306 //=======================================================================
307 //function : Renumber
308 //purpose  : 
309 //=======================================================================
310 void SMESHDS_Script::Renumber (const bool isNodes, const int startID, const int deltaID)
311 {
312   if(myIsEmbeddedMode){
313     myIsModified = true;
314     return;
315   }
316   getCommand(SMESHDS_Renumber)->Renumber( isNodes, startID, deltaID );
317 }
318
319 //=======================================================================
320 //function : 
321 //purpose  : 
322 //=======================================================================
323 void SMESHDS_Script::Clear()
324 {
325   list<SMESHDS_Command*>::iterator anIt = myCommands.begin();
326   for (; anIt != myCommands.end(); anIt++) {
327     delete (*anIt);
328   }
329   myCommands.clear();
330 }
331
332 //=======================================================================
333 //function : 
334 //purpose  : 
335 //=======================================================================
336 const list<SMESHDS_Command*>& SMESHDS_Script::GetCommands()
337 {
338   return myCommands;
339 }
340
341
342 //********************************************************************
343 //*****             Methods for quadratic elements              ******
344 //********************************************************************
345
346 //=======================================================================
347 //function : AddEdge
348 //purpose  : 
349 //=======================================================================
350 void SMESHDS_Script::AddEdge(int NewEdgeID, int n1, int n2, int n12)
351 {
352   if(myIsEmbeddedMode){
353     myIsModified = true;
354     return;
355   }
356   getCommand(SMESHDS_AddQuadEdge)->AddEdge(NewEdgeID, n1, n2, n12);
357 }
358
359 //=======================================================================
360 //function : AddFace
361 //purpose  : 
362 //=======================================================================
363 void SMESHDS_Script::AddFace(int NewFaceID, int n1, int n2, int n3,
364                              int n12, int n23, int n31)
365 {
366   if(myIsEmbeddedMode){
367     myIsModified = true;
368     return;
369   }
370   getCommand(SMESHDS_AddQuadTriangle)->AddFace(NewFaceID, n1, n2, n3,
371                                                n12, n23, n31);
372 }
373
374 //=======================================================================
375 //function : AddFace
376 //purpose  : 
377 //=======================================================================
378 void SMESHDS_Script::AddFace(int NewFaceID, int n1, int n2, int n3, int n4,
379                              int n12, int n23, int n34, int n41)
380 {
381   if(myIsEmbeddedMode){
382     myIsModified = true;
383     return;
384   }
385   getCommand(SMESHDS_AddQuadQuadrangle)->AddFace(NewFaceID, n1, n2, n3, n4,
386                                                  n12, n23, n34, n41);
387 }
388
389 //=======================================================================
390 //function : AddVolume
391 //purpose  : 
392 //=======================================================================
393 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
394                                int n12, int n23, int n31,
395                                int n14, int n24, int n34)
396 {
397   if(myIsEmbeddedMode){
398     myIsModified = true;
399     return;
400   }
401   getCommand(SMESHDS_AddQuadTetrahedron)->AddVolume(NewVolID, n1, n2, n3, n4,
402                                                     n12, n23, n31,
403                                                     n14, n24, n34);
404 }
405
406 //=======================================================================
407 //function : AddVolume
408 //purpose  : 
409 //=======================================================================
410 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
411                                int n5, int n12, int n23, int n34, int n41,
412                                int n15, int n25, int n35, int n45)
413 {
414   if(myIsEmbeddedMode){
415     myIsModified = true;
416     return;
417   }
418   getCommand(SMESHDS_AddQuadPyramid)->AddVolume(NewVolID, n1, n2, n3, n4, n5,
419                                                 n12, n23, n34, n41,
420                                                 n15, n25, n35, n45);
421 }
422
423 //=======================================================================
424 //function : AddVolume
425 //purpose  : 
426 //=======================================================================
427 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
428                                 int n5,int n6, int n12, int n23, int n31,
429                                 int n45, int n56, int n64,
430                                 int n14, int n25, int n36)
431 {
432   if(myIsEmbeddedMode){
433     myIsModified = true;
434     return;
435   }
436   getCommand(SMESHDS_AddQuadPentahedron)->AddVolume(NewVolID, n1,n2,n3,n4,n5,n6,
437                                                     n12, n23, n31,
438                                                     n45, n56, n64,
439                                                     n14, n25, n36);
440 }
441
442 //=======================================================================
443 //function : AddVolume
444 //purpose  : 
445 //=======================================================================
446 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3,
447                                int n4, int n5, int n6, int n7, int n8,
448                                int n12, int n23, int n34, int n41,
449                                int n56, int n67, int n78, int n85,
450                                int n15, int n26, int n37, int n48)
451 {
452   if(myIsEmbeddedMode){
453     myIsModified = true;
454     return;
455   }
456   getCommand(SMESHDS_AddQuadHexahedron)->AddVolume(NewVolID, n1, n2, n3, n4,
457                                                    n5, n6, n7, n8,
458                                                    n12, n23, n34, n41,
459                                                    n56, n67, n78, n85,
460                                                    n15, n26, n37, n48);
461 }
462