Salome HOME
Merge branch 'V8_4_BR'
[modules/smesh.git] / src / SMESHDS / SMESHDS_Script.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 : AddQuadPolygonalFace
260 //purpose  : 
261 //=======================================================================
262 void SMESHDS_Script::AddQuadPolygonalFace(int NewFaceID, const std::vector<int>& nodes_ids)
263 {
264   if(myIsEmbeddedMode){
265     myIsModified = true;
266     return;
267   }
268   getCommand(SMESHDS_AddQuadPolygon)->AddQuadPolygonalFace(NewFaceID, nodes_ids);
269 }
270
271 //=======================================================================
272 //function : AddPolyhedralVolume
273 //purpose  : 
274 //=======================================================================
275 void SMESHDS_Script::AddPolyhedralVolume (int                     NewID,
276                                           const std::vector<int>& nodes_ids,
277                                           const std::vector<int>& quantities)
278 {
279   if(myIsEmbeddedMode){
280     myIsModified = true;
281     return;
282   }
283   getCommand(SMESHDS_AddPolyhedron)->AddPolyhedralVolume
284     (NewID, nodes_ids, quantities);
285 }
286
287 //=======================================================================
288 //function : AddBall
289 //purpose  : Record adding a Ball
290 //=======================================================================
291
292 void SMESHDS_Script::AddBall(int NewBallID, int node, double diameter)
293 {
294   if ( myIsEmbeddedMode )
295     myIsModified = true;
296   else
297     getCommand(SMESHDS_AddBall)->AddBall(NewBallID, node, diameter);
298 }
299
300 //=======================================================================
301 //function : 
302 //purpose  : 
303 //=======================================================================
304 void SMESHDS_Script::MoveNode(int NewNodeID, double x, double y, double z)
305 {
306   if(myIsEmbeddedMode){
307     myIsModified = true;
308     return;
309   }
310   getCommand(SMESHDS_MoveNode)->MoveNode(NewNodeID, x, y, z);
311 }
312
313 //=======================================================================
314 //function : 
315 //purpose  : 
316 //=======================================================================
317 void SMESHDS_Script::RemoveNode(int ID)
318 {
319   if(myIsEmbeddedMode){
320     myIsModified = true;
321     return;
322   }
323   getCommand(SMESHDS_RemoveNode)->RemoveNode(ID);
324 }
325
326 //=======================================================================
327 //function : 
328 //purpose  : 
329 //=======================================================================
330 void SMESHDS_Script::RemoveElement(int ElementID)
331 {
332   if(myIsEmbeddedMode){
333     myIsModified = true;
334     return;
335   }
336   getCommand(SMESHDS_RemoveElement)->RemoveElement(ElementID);
337 }
338
339 //=======================================================================
340 //function : ChangeElementNodes
341 //purpose  : 
342 //=======================================================================
343
344 void SMESHDS_Script::ChangeElementNodes(int ElementID, int nodes[], int nbnodes)
345 {
346   if(myIsEmbeddedMode){
347     myIsModified = true;
348     return;
349   }
350   getCommand(SMESHDS_ChangeElementNodes)->ChangeElementNodes( ElementID, nodes, nbnodes );
351 }
352
353 //=======================================================================
354 //function : ChangePolyhedronNodes
355 //purpose  : 
356 //=======================================================================
357 void SMESHDS_Script::ChangePolyhedronNodes (const int               ElementID,
358                                             const std::vector<int>& nodes_ids,
359                                             const std::vector<int>& quantities)
360 {
361   if(myIsEmbeddedMode){
362     myIsModified = true;
363     return;
364   }
365   getCommand(SMESHDS_ChangePolyhedronNodes)->ChangePolyhedronNodes
366     (ElementID, nodes_ids, quantities);
367 }
368
369 //=======================================================================
370 //function : Renumber
371 //purpose  : 
372 //=======================================================================
373 void SMESHDS_Script::Renumber (const bool isNodes, const int startID, const int deltaID)
374 {
375   if(myIsEmbeddedMode){
376     myIsModified = true;
377     return;
378   }
379   getCommand(SMESHDS_Renumber)->Renumber( isNodes, startID, deltaID );
380 }
381
382 //=======================================================================
383 //function : ClearMesh
384 //purpose  : 
385 //=======================================================================
386 void SMESHDS_Script::ClearMesh ()
387 {
388   if(myIsEmbeddedMode){
389     myIsModified = true;
390     return;
391   }
392   Clear();// previous commands become useless to reproduce on client side
393   getCommand(SMESHDS_ClearAll);
394 }
395
396 //=======================================================================
397 //function : 
398 //purpose  : 
399 //=======================================================================
400 void SMESHDS_Script::Clear()
401 {
402   list<SMESHDS_Command*>::iterator anIt = myCommands.begin();
403   for (; anIt != myCommands.end(); anIt++) {
404     delete (*anIt);
405   }
406   myCommands.clear();
407 }
408
409 //=======================================================================
410 //function : 
411 //purpose  : 
412 //=======================================================================
413 const list<SMESHDS_Command*>& SMESHDS_Script::GetCommands()
414 {
415   return myCommands;
416 }
417
418
419 //********************************************************************
420 //*****             Methods for quadratic elements              ******
421 //********************************************************************
422
423 //=======================================================================
424 //function : AddEdge
425 //purpose  : 
426 //=======================================================================
427 void SMESHDS_Script::AddEdge(int NewEdgeID, int n1, int n2, int n12)
428 {
429   if(myIsEmbeddedMode){
430     myIsModified = true;
431     return;
432   }
433   getCommand(SMESHDS_AddQuadEdge)->AddEdge(NewEdgeID, n1, n2, n12);
434 }
435
436 //=======================================================================
437 //function : AddFace
438 //purpose  : 
439 //=======================================================================
440 void SMESHDS_Script::AddFace(int NewFaceID, int n1, int n2, int n3,
441                              int n12, int n23, int n31)
442 {
443   if(myIsEmbeddedMode){
444     myIsModified = true;
445     return;
446   }
447   getCommand(SMESHDS_AddQuadTriangle)->AddFace(NewFaceID, n1, n2, n3,
448                                                n12, n23, n31);
449 }
450
451 //=======================================================================
452 //function : AddFace
453 //purpose  : 
454 //=======================================================================
455 void SMESHDS_Script::AddFace(int NewFaceID, int n1, int n2, int n3,
456                              int n12, int n23, int n31, int nCenter)
457 {
458   if(myIsEmbeddedMode){
459     myIsModified = true;
460     return;
461   }
462   getCommand(SMESHDS_AddBiQuadTriangle)->AddFace(NewFaceID, n1, n2, n3,
463                                                  n12, n23, n31, nCenter);
464 }
465
466 //=======================================================================
467 //function : AddFace
468 //purpose  : 
469 //=======================================================================
470 void SMESHDS_Script::AddFace(int NewFaceID, int n1, int n2, int n3, int n4,
471                              int n12, int n23, int n34, int n41)
472 {
473   if(myIsEmbeddedMode){
474     myIsModified = true;
475     return;
476   }
477   getCommand(SMESHDS_AddQuadQuadrangle)->AddFace(NewFaceID, n1, n2, n3, n4,
478                                                  n12, n23, n34, n41);
479 }
480
481 //=======================================================================
482 //function : AddFace
483 //purpose  : 
484 //=======================================================================
485 void SMESHDS_Script::AddFace(int NewFaceID, int n1, int n2, int n3, int n4,
486                              int n12, int n23, int n34, int n41, int nCenter)
487 {
488   if(myIsEmbeddedMode){
489     myIsModified = true;
490     return;
491   }
492   getCommand(SMESHDS_AddBiQuadQuadrangle)->AddFace(NewFaceID, n1, n2, n3, n4,
493                                                    n12, n23, n34, n41, nCenter);
494 }
495
496 //=======================================================================
497 //function : AddVolume
498 //purpose  : 
499 //=======================================================================
500 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
501                                int n12, int n23, int n31,
502                                int n14, int n24, int n34)
503 {
504   if(myIsEmbeddedMode){
505     myIsModified = true;
506     return;
507   }
508   getCommand(SMESHDS_AddQuadTetrahedron)->AddVolume(NewVolID, n1, n2, n3, n4,
509                                                     n12, n23, n31,
510                                                     n14, n24, n34);
511 }
512
513 //=======================================================================
514 //function : AddVolume
515 //purpose  : 
516 //=======================================================================
517 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
518                                int n5, int n12, int n23, int n34, int n41,
519                                int n15, int n25, int n35, int n45)
520 {
521   if(myIsEmbeddedMode){
522     myIsModified = true;
523     return;
524   }
525   getCommand(SMESHDS_AddQuadPyramid)->AddVolume(NewVolID, n1, n2, n3, n4, n5,
526                                                 n12, n23, n34, n41,
527                                                 n15, n25, n35, n45);
528 }
529
530 //=======================================================================
531 //function : AddVolume
532 //purpose  : 
533 //=======================================================================
534 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
535                                 int n5,int n6, int n12, int n23, int n31,
536                                 int n45, int n56, int n64,
537                                 int n14, int n25, int n36)
538 {
539   if(myIsEmbeddedMode){
540     myIsModified = true;
541     return;
542   }
543   getCommand(SMESHDS_AddQuadPentahedron)->AddVolume(NewVolID, n1,n2,n3,n4,n5,n6,
544                                                     n12, n23, n31,
545                                                     n45, n56, n64,
546                                                     n14, n25, n36);
547 }
548
549 //=======================================================================
550 //function : AddVolume
551 //purpose  : 
552 //=======================================================================
553 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3, int n4,
554                                 int n5,int n6, int n12, int n23, int n31,
555                                 int n45, int n56, int n64,
556                                 int n14, int n25, int n36,
557                                 int n1245, int n2356, int n1346)
558 {
559   if(myIsEmbeddedMode){
560     myIsModified = true;
561     return;
562   }
563   getCommand(SMESHDS_AddBiQuadPentahedron)->AddVolume(NewVolID, n1,n2,n3,n4,n5,n6,
564                                                     n12, n23, n31,
565                                                     n45, n56, n64,
566                                                     n14, n25, n36,
567                                                     n1245, n2356, n1346);
568 }
569
570 //=======================================================================
571 //function : AddVolume
572 //purpose  :
573 //=======================================================================
574 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3,
575                                int n4, int n5, int n6, int n7, int n8,
576                                int n12, int n23, int n34, int n41,
577                                int n56, int n67, int n78, int n85,
578                                int n15, int n26, int n37, int n48)
579 {
580   if(myIsEmbeddedMode){
581     myIsModified = true;
582     return;
583   }
584   getCommand(SMESHDS_AddQuadHexahedron)->AddVolume(NewVolID, n1, n2, n3, n4,
585                                                    n5, n6, n7, n8,
586                                                    n12, n23, n34, n41,
587                                                    n56, n67, n78, n85,
588                                                    n15, n26, n37, n48);
589 }
590
591 //=======================================================================
592 //function : AddVolume
593 //purpose  : 
594 //=======================================================================
595 void SMESHDS_Script::AddVolume(int NewVolID, int n1, int n2, int n3,
596                                int n4, int n5, int n6, int n7, int n8,
597                                int n12, int n23, int n34, int n41,
598                                int n56, int n67, int n78, int n85,
599                                int n15, int n26, int n37, int n48,
600                                int n1234,int n1256,int n2367,int n3478,
601                                int n1458,int n5678,int nCenter)
602 {
603   if(myIsEmbeddedMode){
604     myIsModified = true;
605     return;
606   }
607   getCommand(SMESHDS_AddTriQuadHexa)->AddVolume(NewVolID, n1, n2, n3, n4,
608                                                 n5, n6, n7, n8,
609                                                 n12, n23, n34, n41,
610                                                 n56, n67, n78, n85,
611                                                 n15, n26, n37, n48,
612                                                 n1234, n1256, n2367, n3478,
613                                                 n1458, n5678, nCenter);
614 }
615