Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/smesh.git] / src / SMESHDS / SMESHDS_Script.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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 //  SMESH SMESHDS : management of mesh data and SMESH document
24 //  File   : SMESH_Script.cxx
25 //  Author : Yves FRICAUD, OCC
26 //  Module : SMESH
27 //
28 #include "SMESHDS_Script.hxx"
29 #include <iostream>
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   //cerr << "=========================== myIsEmbeddedMode " << myIsEmbeddedMode << endl;
41 }
42
43 //=======================================================================
44 //function : Destructor
45 //purpose  : 
46 //=======================================================================
47 SMESHDS_Script::~SMESHDS_Script()
48 {
49   Clear();
50 }
51
52 //=======================================================================
53 void SMESHDS_Script::SetModified(bool theModified)
54 {
55   myIsModified = theModified;
56 }
57
58 //=======================================================================
59 bool SMESHDS_Script::IsModified()
60 {
61   return myIsModified;
62 }
63
64 //=======================================================================
65 //function : getCommand
66 //purpose  : 
67 //=======================================================================
68 SMESHDS_Command* SMESHDS_Script::getCommand(const SMESHDS_CommandType aType)
69 {
70   SMESHDS_Command* com;
71   if (myCommands.empty())
72   {
73     com = new SMESHDS_Command(aType);
74     myCommands.insert(myCommands.end(),com);
75   }
76   else
77   {
78     com = myCommands.back();
79     if (com->GetType() != aType)
80     {
81       com = new SMESHDS_Command(aType);
82       myCommands.insert(myCommands.end(),com);
83     }
84   }
85   return com;
86 }
87
88 //=======================================================================
89 //function : 
90 //purpose  : 
91 //=======================================================================
92 void SMESHDS_Script::AddNode(int NewNodeID, double x, double y, double z)
93 {
94   if(myIsEmbeddedMode){
95     myIsModified = true;
96     return;
97   }
98   getCommand(SMESHDS_AddNode)->AddNode(NewNodeID, x, y, z);
99 }
100
101 //=======================================================================
102 //function :
103 //purpose  :
104 //=======================================================================
105 void SMESHDS_Script::Add0DElement (int New0DElementID, int idnode)
106 {
107   if (myIsEmbeddedMode) {
108     myIsModified = true;
109     return;
110   }
111   getCommand(SMESHDS_Add0DElement)->Add0DElement(New0DElementID, idnode);
112 }
113
114 //=======================================================================
115 //function : 
116 //purpose  : 
117 //=======================================================================
118 void SMESHDS_Script::AddEdge(int NewEdgeID, int idnode1, int idnode2)
119 {
120   if(myIsEmbeddedMode){
121     myIsModified = true;
122     return;
123   }
124   getCommand(SMESHDS_AddEdge)->AddEdge(NewEdgeID, idnode1, idnode2);
125 }
126
127 //=======================================================================
128 //function : 
129 //purpose  : 
130 //=======================================================================
131 void SMESHDS_Script::AddFace(int NewFaceID,
132                              int idnode1, int idnode2, int idnode3)
133 {
134   if(myIsEmbeddedMode){
135     myIsModified = true;
136     return;
137   }
138   getCommand(SMESHDS_AddTriangle)->AddFace(NewFaceID,
139                                            idnode1, idnode2, idnode3);
140 }
141
142 //=======================================================================
143 //function : 
144 //purpose  : 
145 //=======================================================================
146 void SMESHDS_Script::AddFace(int NewFaceID,
147                              int idnode1, int idnode2,
148                              int idnode3, int idnode4)
149 {
150   if(myIsEmbeddedMode){
151     myIsModified = true;
152     return;
153   }
154   getCommand(SMESHDS_AddQuadrangle)->AddFace(NewFaceID,
155                                              idnode1, idnode2,
156                                              idnode3, idnode4);
157 }
158
159 //=======================================================================
160 //function : 
161 //purpose  : 
162 //=======================================================================
163 void SMESHDS_Script::AddVolume(int NewID,
164                                int idnode1, int idnode2,
165                                int idnode3, int idnode4)
166 {
167   if(myIsEmbeddedMode){
168     myIsModified = true;
169     return;
170   }
171   getCommand(SMESHDS_AddTetrahedron)->AddVolume(NewID,
172                                                 idnode1, idnode2,
173                                                 idnode3, idnode4);
174 }
175
176 //=======================================================================
177 //function : 
178 //purpose  : 
179 //=======================================================================
180 void SMESHDS_Script::AddVolume(int NewID,
181                                int idnode1, int idnode2,
182                                int idnode3, int idnode4, int idnode5)
183 {
184   if(myIsEmbeddedMode){
185     myIsModified = true;
186     return;
187   }
188   getCommand(SMESHDS_AddPyramid)->AddVolume(NewID,
189                                             idnode1, idnode2,
190                                             idnode3, idnode4, idnode5);
191 }
192
193 //=======================================================================
194 //function : 
195 //purpose  : 
196 //=======================================================================
197 void SMESHDS_Script::AddVolume(int NewID,
198                                int idnode1, int idnode2, int idnode3,
199                                int idnode4, int idnode5, int idnode6)
200 {
201   if(myIsEmbeddedMode){
202     myIsModified = true;
203     return;
204   }
205   getCommand(SMESHDS_AddPrism)->AddVolume(NewID,
206                                           idnode1, idnode2, idnode3,
207                                           idnode4, idnode5, idnode6);
208 }
209
210 //=======================================================================
211 //function : 
212 //purpose  : 
213 //=======================================================================
214 void SMESHDS_Script::AddVolume(int NewID,
215                                int idnode1, int idnode2, int idnode3, int idnode4,
216                                int idnode5, int idnode6, int idnode7, int idnode8)
217 {
218   if(myIsEmbeddedMode){
219     myIsModified = true;
220     return;
221   }
222   getCommand(SMESHDS_AddHexahedron)->AddVolume(NewID,
223                                                idnode1, idnode2, idnode3, idnode4,
224                                                idnode5, idnode6, idnode7, idnode8);
225 }
226
227 //=======================================================================
228 //function : 
229 //purpose  : 
230 //=======================================================================
231 void SMESHDS_Script::AddVolume(int NewVolID, int idnode1, int idnode2, int idnode3,
232                                int idnode4, int idnode5, int idnode6, int idnode7, int idnode8,
233                                int idnode9, int idnode10, int idnode11, int idnode12)
234 {
235   if(myIsEmbeddedMode){
236     myIsModified = true;
237     return;
238   }
239   getCommand(SMESHDS_AddHexagonalPrism)->AddVolume(NewVolID,
240                                                    idnode1, idnode2, idnode3, idnode4,
241                                                    idnode5, idnode6, idnode7, idnode8,
242                                                    idnode9, idnode10, idnode11, idnode12);
243 }
244
245 //=======================================================================
246 //function : AddPolygonalFace
247 //purpose  : 
248 //=======================================================================
249 void SMESHDS_Script::AddPolygonalFace (int NewFaceID, const std::vector<int>& nodes_ids)
250 {
251   if(myIsEmbeddedMode){
252     myIsModified = true;
253     return;
254   }
255   getCommand(SMESHDS_AddPolygon)->AddPolygonalFace(NewFaceID, nodes_ids);
256 }
257
258 //=======================================================================
259 //function : AddPolyhedralVolume
260 //purpose  : 
261 //=======================================================================
262 void SMESHDS_Script::AddPolyhedralVolume (int                     NewID,
263                                           const std::vector<int>& nodes_ids,
264                                           const std::vector<int>& quantities)
265 {
266   if(myIsEmbeddedMode){
267     myIsModified = true;
268     return;
269   }
270   getCommand(SMESHDS_AddPolyhedron)->AddPolyhedralVolume
271     (NewID, nodes_ids, quantities);
272 }
273
274 //=======================================================================
275 //function : AddBall
276 //purpose  : Record adding a Ball
277 //=======================================================================
278
279 void SMESHDS_Script::AddBall(int NewBallID, int node, double diameter)
280 {
281   if ( myIsEmbeddedMode )
282     myIsModified = true;
283   else
284     getCommand(SMESHDS_AddBall)->AddBall(NewBallID, node, diameter);
285 }
286
287 //=======================================================================
288 //function : 
289 //purpose  : 
290 //=======================================================================
291 void SMESHDS_Script::MoveNode(int NewNodeID, double x, double y, double z)
292 {
293   if(myIsEmbeddedMode){
294     myIsModified = true;
295     return;
296   }
297   getCommand(SMESHDS_MoveNode)->MoveNode(NewNodeID, x, y, z);
298 }
299
300 //=======================================================================
301 //function : 
302 //purpose  : 
303 //=======================================================================
304 void SMESHDS_Script::RemoveNode(int ID)
305 {
306   if(myIsEmbeddedMode){
307     myIsModified = true;
308     return;
309   }
310   getCommand(SMESHDS_RemoveNode)->RemoveNode(ID);
311 }
312
313 //=======================================================================
314 //function : 
315 //purpose  : 
316 //=======================================================================
317 void SMESHDS_Script::RemoveElement(int ElementID)
318 {
319   if(myIsEmbeddedMode){
320     myIsModified = true;
321     return;
322   }
323   getCommand(SMESHDS_RemoveElement)->RemoveElement(ElementID);
324 }
325
326 //=======================================================================
327 //function : ChangeElementNodes
328 //purpose  : 
329 //=======================================================================
330
331 void SMESHDS_Script::ChangeElementNodes(int ElementID, int nodes[], int nbnodes)
332 {
333   if(myIsEmbeddedMode){
334     myIsModified = true;
335     return;
336   }
337   getCommand(SMESHDS_ChangeElementNodes)->ChangeElementNodes( ElementID, nodes, nbnodes );
338 }
339
340 //=======================================================================
341 //function : ChangePolyhedronNodes
342 //purpose  : 
343 //=======================================================================
344 void SMESHDS_Script::ChangePolyhedronNodes (const int               ElementID,
345                                             const std::vector<int>& nodes_ids,
346                                             const std::vector<int>& quantities)
347 {
348   if(myIsEmbeddedMode){
349     myIsModified = true;
350     return;
351   }
352   getCommand(SMESHDS_ChangePolyhedronNodes)->ChangePolyhedronNodes
353     (ElementID, nodes_ids, quantities);
354 }
355
356 //=======================================================================
357 //function : Renumber
358 //purpose  : 
359 //=======================================================================
360 void SMESHDS_Script::Renumber (const bool isNodes, const int startID, const int deltaID)
361 {
362   if(myIsEmbeddedMode){
363     myIsModified = true;
364     return;
365   }
366   getCommand(SMESHDS_Renumber)->Renumber( isNodes, startID, deltaID );
367 }
368
369 //=======================================================================
370 //function : ClearMesh
371 //purpose  : 
372 //=======================================================================
373 void SMESHDS_Script::ClearMesh ()
374 {
375   if(myIsEmbeddedMode){
376     myIsModified = true;
377     return;
378   }
379   Clear();// previous commands become useless to reproduce on client side
380   getCommand(SMESHDS_ClearAll);
381 }
382
383 //=======================================================================
384 //function : 
385 //purpose  : 
386 //=======================================================================
387 void SMESHDS_Script::Clear()
388 {
389   list<SMESHDS_Command*>::iterator anIt = myCommands.begin();
390   for (; anIt != myCommands.end(); anIt++) {
391     delete (*anIt);
392   }
393   myCommands.clear();
394 }
395
396 //=======================================================================
397 //function : 
398 //purpose  : 
399 //=======================================================================
400 const list<SMESHDS_Command*>& SMESHDS_Script::GetCommands()
401 {
402   return myCommands;
403 }
404
405
406 //********************************************************************
407 //*****             Methods for quadratic elements              ******
408 //********************************************************************
409
410 //=======================================================================
411 //function : AddEdge
412 //purpose  : 
413 //=======================================================================
414 void SMESHDS_Script::AddEdge(int NewEdgeID, int n1, int n2, int n12)
415 {
416   if(myIsEmbeddedMode){
417     myIsModified = true;
418     return;
419   }
420   getCommand(SMESHDS_AddQuadEdge)->AddEdge(NewEdgeID, n1, n2, n12);
421 }
422
423 //=======================================================================
424 //function : AddFace
425 //purpose  : 
426 //=======================================================================
427 void SMESHDS_Script::AddFace(int NewFaceID, int n1, int n2, int n3,
428                              int n12, int n23, int n31)
429 {
430   if(myIsEmbeddedMode){
431     myIsModified = true;
432     return;
433   }
434   getCommand(SMESHDS_AddQuadTriangle)->AddFace(NewFaceID, n1, n2, n3,
435                                                n12, n23, n31);
436 }
437
438 //=======================================================================
439 //function : AddFace
440 //purpose  : 
441 //=======================================================================
442 void SMESHDS_Script::AddFace(int NewFaceID, int n1, int n2, int n3, int n4,
443                              int n12, int n23, int n34, int n41)
444 {
445   if(myIsEmbeddedMode){
446     myIsModified = true;
447     return;
448   }
449   getCommand(SMESHDS_AddQuadQuadrangle)->AddFace(NewFaceID, n1, n2, n3, n4,
450                                                  n12, n23, n34, n41);
451 }
452
453 //=======================================================================
454 //function : AddFace
455 //purpose  : 
456 //=======================================================================
457 void SMESHDS_Script::AddFace(int NewFaceID, int n1, int n2, int n3, int n4,
458                              int n12, int n23, int n34, int n41, int nCenter)
459 {
460   if(myIsEmbeddedMode){
461     myIsModified = true;
462     return;
463   }
464   getCommand(SMESHDS_AddBiQuadQuadrangle)->AddFace(NewFaceID, n1, n2, n3, n4,
465                                                    n12, n23, n34, n41, nCenter);
466 }
467
468 //=======================================================================
469 //function : AddVolume
470 //purpose  : 
471 //=======================================================================
472 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
473                                int n12, int n23, int n31,
474                                int n14, int n24, int n34)
475 {
476   if(myIsEmbeddedMode){
477     myIsModified = true;
478     return;
479   }
480   getCommand(SMESHDS_AddQuadTetrahedron)->AddVolume(NewVolID, n1, n2, n3, n4,
481                                                     n12, n23, n31,
482                                                     n14, n24, n34);
483 }
484
485 //=======================================================================
486 //function : AddVolume
487 //purpose  : 
488 //=======================================================================
489 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
490                                int n5, int n12, int n23, int n34, int n41,
491                                int n15, int n25, int n35, int n45)
492 {
493   if(myIsEmbeddedMode){
494     myIsModified = true;
495     return;
496   }
497   getCommand(SMESHDS_AddQuadPyramid)->AddVolume(NewVolID, n1, n2, n3, n4, n5,
498                                                 n12, n23, n34, n41,
499                                                 n15, n25, n35, n45);
500 }
501
502 //=======================================================================
503 //function : AddVolume
504 //purpose  : 
505 //=======================================================================
506 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
507                                 int n5,int n6, int n12, int n23, int n31,
508                                 int n45, int n56, int n64,
509                                 int n14, int n25, int n36)
510 {
511   if(myIsEmbeddedMode){
512     myIsModified = true;
513     return;
514   }
515   getCommand(SMESHDS_AddQuadPentahedron)->AddVolume(NewVolID, n1,n2,n3,n4,n5,n6,
516                                                     n12, n23, n31,
517                                                     n45, n56, n64,
518                                                     n14, n25, n36);
519 }
520
521 //=======================================================================
522 //function : AddVolume
523 //purpose  : 
524 //=======================================================================
525 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3,
526                                int n4, int n5, int n6, int n7, int n8,
527                                int n12, int n23, int n34, int n41,
528                                int n56, int n67, int n78, int n85,
529                                int n15, int n26, int n37, int n48)
530 {
531   if(myIsEmbeddedMode){
532     myIsModified = true;
533     return;
534   }
535   getCommand(SMESHDS_AddQuadHexahedron)->AddVolume(NewVolID, n1, n2, n3, n4,
536                                                    n5, n6, n7, n8,
537                                                    n12, n23, n34, n41,
538                                                    n56, n67, n78, n85,
539                                                    n15, n26, n37, n48);
540 }
541
542 //=======================================================================
543 //function : AddVolume
544 //purpose  : 
545 //=======================================================================
546 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3,
547                                int n4, int n5, int n6, int n7, int n8,
548                                int n12, int n23, int n34, int n41,
549                                int n56, int n67, int n78, int n85,
550                                int n15, int n26, int n37, int n48,
551                                int n1234,int n1256,int n2367,int n3478,
552                                int n1458,int n5678,int nCenter)
553 {
554   if(myIsEmbeddedMode){
555     myIsModified = true;
556     return;
557   }
558   getCommand(SMESHDS_AddTriQuadHexa)->AddVolume(NewVolID, n1, n2, n3, n4,
559                                                 n5, n6, n7, n8,
560                                                 n12, n23, n34, n41,
561                                                 n56, n67, n78, n85,
562                                                 n15, n26, n37, n48,
563                                                 n1234, n1256, n2367, n3478,
564                                                 n1458, n5678, nCenter);
565 }
566