Salome HOME
Movement of examples to CVS EXAMPLES SAMPLES_SRC.
[modules/smesh.git] / src / SMESHDS / SMESHDS_Command.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_Command.cxx
25 //  Author : Yves FRICAUD, OCC
26 //  Module : SMESH
27 //  $Header: 
28
29 #include "SMESHDS_Command.hxx"
30
31 #include "utilities.h"
32
33 using namespace std;
34
35 //=======================================================================
36 //function : 
37 //purpose  : 
38 //=======================================================================
39 SMESHDS_Command::SMESHDS_Command(const SMESHDS_CommandType aType):myType(aType),
40 myNumber(0)
41 {
42 }
43
44 //=======================================================================
45 //function : 
46 //purpose  : 
47 //=======================================================================
48 void SMESHDS_Command::AddNode(int NewNodeID, double x, double y, double z)
49 {
50         if (!myType == SMESHDS_AddNode)
51         {
52                 MESSAGE("SMESHDS_Command::AddNode : Bad Type");
53                 return;
54         }
55         myIntegers.push_back(NewNodeID);
56         myReals.push_back(x);
57         myReals.push_back(y);
58         myReals.push_back(z);
59         myNumber++;
60 }
61
62 //=======================================================================
63 //function : 
64 //purpose  : 
65 //=======================================================================
66 void SMESHDS_Command::MoveNode(int NodeID, double x, double y, double z)
67 {
68         if (!myType == SMESHDS_MoveNode)
69         {
70                 MESSAGE("SMESHDS_Command::MoveNode : Bad Type");
71                 return;
72         }
73         myIntegers.push_back(NodeID);
74         myReals.push_back(x);
75         myReals.push_back(y);
76         myReals.push_back(z);
77         myNumber++;
78 }
79
80 //=======================================================================
81 //function : 
82 //purpose  : 
83 //=======================================================================
84 void SMESHDS_Command::AddEdge(int NewEdgeID, int idnode1, int idnode2)
85 {
86         if (!myType == SMESHDS_AddEdge)
87         {
88                 MESSAGE("SMESHDS_Command::AddEdge : Bad Type");
89                 return;
90         }
91         myIntegers.push_back(NewEdgeID);
92         myIntegers.push_back(idnode1);
93         myIntegers.push_back(idnode2);
94         myNumber++;
95 }
96
97 //=======================================================================
98 //function : 
99 //purpose  : 
100 //=======================================================================
101 void SMESHDS_Command::AddFace(int NewFaceID,
102         int idnode1, int idnode2, int idnode3)
103 {
104         if (!myType == SMESHDS_AddTriangle)
105         {
106                 MESSAGE("SMESHDS_Command::AddFace : Bad Type");
107                 return;
108         }
109         myIntegers.push_back(NewFaceID);
110         myIntegers.push_back(idnode1);
111         myIntegers.push_back(idnode2);
112         myIntegers.push_back(idnode3);
113         myNumber++;
114 }
115
116 //=======================================================================
117 //function : 
118 //purpose  : 
119 //=======================================================================
120 void SMESHDS_Command::AddFace(int NewFaceID,
121         int idnode1, int idnode2, int idnode3, int idnode4)
122 {
123         if (!myType == SMESHDS_AddQuadrangle)
124         {
125                 MESSAGE("SMESHDS_Command::AddFace : Bad Type");
126                 return;
127         }
128         myIntegers.push_back(NewFaceID);
129         myIntegers.push_back(idnode1);
130         myIntegers.push_back(idnode2);
131         myIntegers.push_back(idnode3);
132         myIntegers.push_back(idnode4);
133         myNumber++;
134 }
135
136 //=======================================================================
137 //function : 
138 //purpose  : 
139 //=======================================================================
140 void SMESHDS_Command::AddVolume(int NewVolID,
141         int idnode1, int idnode2, int idnode3, int idnode4)
142 {
143         if (!myType == SMESHDS_AddTetrahedron)
144         {
145                 MESSAGE("SMESHDS_Command::AddVolume : Bad Type");
146                 return;
147         }
148         myIntegers.push_back(NewVolID);
149         myIntegers.push_back(idnode1);
150         myIntegers.push_back(idnode2);
151         myIntegers.push_back(idnode3);
152         myIntegers.push_back(idnode4);
153         myNumber++;
154 }
155
156 //=======================================================================
157 //function : 
158 //purpose  : 
159 //=======================================================================
160 void SMESHDS_Command::AddVolume(int NewVolID,
161         int idnode1, int idnode2, int idnode3, int idnode4, int idnode5)
162 {
163         if (!myType == SMESHDS_AddPyramid)
164         {
165                 MESSAGE("SMESHDS_Command::AddVolume : Bad Type");
166                 return;
167         }
168         myIntegers.push_back(NewVolID);
169         myIntegers.push_back(idnode1);
170         myIntegers.push_back(idnode2);
171         myIntegers.push_back(idnode3);
172         myIntegers.push_back(idnode4);
173         myIntegers.push_back(idnode5);
174         myNumber++;
175 }
176
177 //=======================================================================
178 //function : 
179 //purpose  : 
180 //=======================================================================
181 void SMESHDS_Command::AddVolume(int NewVolID,
182         int idnode1,
183         int idnode2, int idnode3, int idnode4, int idnode5, int idnode6)
184 {
185         if (!myType == SMESHDS_AddPrism)
186         {
187                 MESSAGE("SMESHDS_Command::AddVolume : Bad Type");
188                 return;
189         }
190         myIntegers.push_back(NewVolID);
191         myIntegers.push_back(idnode1);
192         myIntegers.push_back(idnode2);
193         myIntegers.push_back(idnode3);
194         myIntegers.push_back(idnode4);
195         myIntegers.push_back(idnode5);
196         myIntegers.push_back(idnode6);
197         myNumber++;
198 }
199
200 //=======================================================================
201 //function : 
202 //purpose  : 
203 //=======================================================================
204 void SMESHDS_Command::AddVolume(int NewVolID,
205         int idnode1,
206         int idnode2,
207         int idnode3,
208         int idnode4, int idnode5, int idnode6, int idnode7, int idnode8)
209 {
210         if (!myType == SMESHDS_AddHexahedron)
211         {
212                 MESSAGE("SMESHDS_Command::AddVolume : Bad Type");
213                 return;
214         }
215         myIntegers.push_back(NewVolID);
216         myIntegers.push_back(idnode1);
217         myIntegers.push_back(idnode2);
218         myIntegers.push_back(idnode3);
219         myIntegers.push_back(idnode4);
220         myIntegers.push_back(idnode5);
221         myIntegers.push_back(idnode6);
222         myIntegers.push_back(idnode7);
223         myIntegers.push_back(idnode8);
224         myNumber++;
225 }
226
227 //=======================================================================
228 //function : AddPolygonalFace
229 //purpose  : 
230 //=======================================================================
231 void SMESHDS_Command::AddPolygonalFace (const int        ElementID,
232                                         std::vector<int> nodes_ids)
233 {
234   if (!myType == SMESHDS_AddPolygon) {
235     MESSAGE("SMESHDS_Command::AddPolygonalFace : Bad Type");
236     return;
237   }
238   myIntegers.push_back(ElementID);
239
240   int i, nbNodes = nodes_ids.size();
241   myIntegers.push_back(nbNodes);
242   for (i = 0; i < nbNodes; i++) {
243     myIntegers.push_back(nodes_ids[i]);
244   }
245
246   myNumber++;
247 }
248
249 //=======================================================================
250 //function : AddPolyhedralVolume
251 //purpose  : 
252 //=======================================================================
253 void SMESHDS_Command::AddPolyhedralVolume (const int        ElementID,
254                                            std::vector<int> nodes_ids,
255                                            std::vector<int> quantities)
256 {
257   if (!myType == SMESHDS_AddPolyhedron) {
258     MESSAGE("SMESHDS_Command::AddPolyhedralVolume : Bad Type");
259     return;
260   }
261   myIntegers.push_back(ElementID);
262
263   int i, nbNodes = nodes_ids.size();
264   myIntegers.push_back(nbNodes);
265   for (i = 0; i < nbNodes; i++) {
266     myIntegers.push_back(nodes_ids[i]);
267   }
268
269   int nbFaces = quantities.size();
270   myIntegers.push_back(nbFaces);
271   for (i = 0; i < nbFaces; i++) {
272     myIntegers.push_back(quantities[i]);
273   }
274
275   myNumber++;
276 }
277
278 //=======================================================================
279 //function : 
280 //purpose  : 
281 //=======================================================================
282 void SMESHDS_Command::RemoveNode(int NodeID)
283 {
284         if (!myType == SMESHDS_RemoveNode)
285         {
286                 MESSAGE("SMESHDS_Command::RemoveNode : Bad Type");
287                 return;
288         }
289         myIntegers.push_back(NodeID);
290         myNumber++;
291 }
292
293 //=======================================================================
294 //function : 
295 //purpose  : 
296 //=======================================================================
297 void SMESHDS_Command::RemoveElement(int ElementID)
298 {
299         if (!myType == SMESHDS_RemoveElement)
300         {
301                 MESSAGE("SMESHDS_Command::RemoveElement : Bad Type");
302                 return;
303         }
304         myIntegers.push_back(ElementID);
305         myNumber++;
306 }
307
308 //=======================================================================
309 //function : ChangeElementNodes
310 //purpose  : 
311 //=======================================================================
312
313 void SMESHDS_Command::ChangeElementNodes(int ElementID, int nodes[], int nbnodes)
314 {
315   if (!myType == SMESHDS_ChangeElementNodes)
316   {
317     MESSAGE("SMESHDS_Command::ChangeElementNodes : Bad Type");
318     return;
319   }
320   myIntegers.push_back(ElementID);
321   myIntegers.push_back(nbnodes);
322   for ( int i = 0; i < nbnodes; i++ )
323     myIntegers.push_back( nodes[ i ] );
324
325   myNumber++;
326 }
327
328 //=======================================================================
329 //function : ChangePolyhedronNodes
330 //purpose  : 
331 //=======================================================================
332 void SMESHDS_Command::ChangePolyhedronNodes (const int ElementID,
333                                              std::vector<int> nodes_ids,
334                                              std::vector<int> quantities)
335 {
336   if (myType != SMESHDS_ChangePolyhedronNodes)
337   {
338     MESSAGE("SMESHDS_Command::ChangePolyhedronNodes : Bad Type");
339     return;
340   }
341   myIntegers.push_back(ElementID);
342
343   int i, nbNodes = nodes_ids.size();
344   myIntegers.push_back(nbNodes);
345   for (i = 0; i < nbNodes; i++) {
346     myIntegers.push_back(nodes_ids[i]);
347   }
348
349   int nbFaces = quantities.size();
350   myIntegers.push_back(nbFaces);
351   for (i = 0; i < nbFaces; i++) {
352     myIntegers.push_back(quantities[i]);
353   }
354
355   myNumber++;
356 }
357
358 //=======================================================================
359 //function : Renumber
360 //purpose  : 
361 //=======================================================================
362
363 void SMESHDS_Command::Renumber (const bool isNodes, const int startID, const int deltaID)
364 {
365   if (!myType == SMESHDS_Renumber)
366   {
367     MESSAGE("SMESHDS_Command::Renumber : Bad Type");
368     return;
369   }
370   myIntegers.push_back(isNodes);
371   myIntegers.push_back(startID);
372   myIntegers.push_back(deltaID);
373   myNumber++;
374 }
375
376 //=======================================================================
377 //function : 
378 //purpose  : 
379 //=======================================================================
380 SMESHDS_CommandType SMESHDS_Command::GetType()
381 {
382         return myType;
383 }
384
385 //=======================================================================
386 //function : 
387 //purpose  : 
388 //=======================================================================
389 int SMESHDS_Command::GetNumber()
390 {
391         return myNumber;
392 }
393
394 //=======================================================================
395 //function : 
396 //purpose  : 
397 //=======================================================================
398 const list < int >&SMESHDS_Command::GetIndexes()
399 {
400         return myIntegers;
401 }
402
403 //=======================================================================
404 //function : 
405 //purpose  : 
406 //=======================================================================
407 const list < double >&SMESHDS_Command::GetCoords()
408 {
409         return myReals;
410 }