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