Salome HOME
5c790942866721d84bb86df0d9a9cc5832d84792
[modules/smesh.git] / src / SMESH_I / SMESH_MeshEditor_i.cxx
1 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
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_MeshEditor_i.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESH_MeshEditor_i.hxx"
31
32 #include "SMDS_MeshEdge.hxx"
33 #include "SMDS_MeshFace.hxx"
34 #include "SMDS_MeshVolume.hxx"
35
36 #include "utilities.h"
37
38 #include <TColStd_MapOfInteger.hxx>
39 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
40
41 //=============================================================================
42 /*!
43  *  
44  */
45 //=============================================================================
46
47 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESHDS_Mesh* theMesh)
48 {
49         _myMeshDS = theMesh;
50 };
51
52 //=============================================================================
53 /*!
54  *  
55  */
56 //=============================================================================
57
58 CORBA::Boolean SMESH_MeshEditor_i::RemoveElements(const SMESH::
59         long_array & IDsOfElements)
60 {
61         for (int i = 0; i < IDsOfElements.length(); i++)
62         {
63                 CORBA::Long index = IDsOfElements[i];
64                 _myMeshDS->RemoveElement(index);
65                 MESSAGE("Element " << index << " was removed")
66         }
67         return true;
68 };
69
70 //=============================================================================
71 /*!
72  *  
73  */
74 //=============================================================================
75
76 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::
77         long_array & IDsOfNodes)
78 {
79         // It's nodes' turn to die
80         for (int i = 0; i < IDsOfNodes.length(); i++)
81         {
82                 const SMDS_MeshNode * node=_myMeshDS->FindNode(IDsOfNodes[i]);
83                 if(node==NULL)
84                 {
85                         MESSAGE("SMESH_MeshEditor_i::RemoveNodes: Node "<<IDsOfNodes[i]
86                                 <<" not found");
87                         continue;
88                 }
89                 _myMeshDS->RemoveNode(IDsOfNodes[i]);
90                 MESSAGE("Node " << index << " was removed")
91         }
92         return true;
93 };
94
95 //=============================================================================
96 /*!
97  *  
98  */
99 //=============================================================================
100
101 CORBA::Boolean SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
102 {
103         int NbNodes = IDsOfNodes.length();
104         if (NbNodes == 2)
105         {
106                 CORBA::Long index1 = IDsOfNodes[0];
107                 CORBA::Long index2 = IDsOfNodes[1];
108                 _myMeshDS->AddEdge(index1, index2);
109         }
110         return true;
111 }
112
113 //=============================================================================
114 /*!
115  *  
116  */
117 //=============================================================================
118
119 CORBA::Boolean SMESH_MeshEditor_i::AddNode(CORBA::Double x,
120         CORBA::Double y, CORBA::Double z)
121 {
122         MESSAGE(" AddNode " << x << " , " << y << " , " << z)
123                 int idNode = _myMeshDS->AddNode(x, y, z)->GetID();
124         MESSAGE(" idNode " << idNode) return true;
125 }
126
127 //=============================================================================
128 /*!
129  *  
130  */
131 //=============================================================================
132
133 CORBA::Boolean SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
134 {
135         int NbNodes = IDsOfNodes.length();
136         if (NbNodes == 3)
137         {
138                 CORBA::Long index1 = IDsOfNodes[0];
139                 CORBA::Long index2 = IDsOfNodes[1];
140                 CORBA::Long index3 = IDsOfNodes[2];
141                 _myMeshDS->AddFace(index1, index2, index3);
142         }
143         else if (NbNodes == 4)
144         {
145                 CORBA::Long index1 = IDsOfNodes[0];
146                 CORBA::Long index2 = IDsOfNodes[1];
147                 CORBA::Long index3 = IDsOfNodes[2];
148                 CORBA::Long index4 = IDsOfNodes[3];
149                 _myMeshDS->AddFace(index1, index2, index3, index4);
150         }
151         return true;
152 };
153
154 //=============================================================================
155 /*!
156  *  
157  */
158 //=============================================================================
159
160 CORBA::Boolean SMESH_MeshEditor_i::AddVolume(const SMESH::
161         long_array & IDsOfNodes)
162 {
163         int NbNodes = IDsOfNodes.length();
164         if (NbNodes == 4)
165         {
166                 CORBA::Long index1 = IDsOfNodes[0];
167                 CORBA::Long index2 = IDsOfNodes[1];
168                 CORBA::Long index3 = IDsOfNodes[2];
169                 CORBA::Long index4 = IDsOfNodes[3];
170                 _myMeshDS->AddVolume(index1, index2, index3, index4);
171         }
172         else if (NbNodes == 5)
173         {
174                 CORBA::Long index1 = IDsOfNodes[0];
175                 CORBA::Long index2 = IDsOfNodes[1];
176                 CORBA::Long index3 = IDsOfNodes[2];
177                 CORBA::Long index4 = IDsOfNodes[3];
178                 CORBA::Long index5 = IDsOfNodes[4];
179                 _myMeshDS->AddVolume(index1, index2, index3, index4, index5);
180         }
181         else if (NbNodes == 6)
182         {
183                 CORBA::Long index1 = IDsOfNodes[0];
184                 CORBA::Long index2 = IDsOfNodes[1];
185                 CORBA::Long index3 = IDsOfNodes[2];
186                 CORBA::Long index4 = IDsOfNodes[3];
187                 CORBA::Long index5 = IDsOfNodes[4];
188                 CORBA::Long index6 = IDsOfNodes[5];
189                 _myMeshDS->AddVolume(index1, index2, index3, index4, index5, index6);
190         }
191         else if (NbNodes == 8)
192         {
193                 CORBA::Long index1 = IDsOfNodes[0];
194                 CORBA::Long index2 = IDsOfNodes[1];
195                 CORBA::Long index3 = IDsOfNodes[2];
196                 CORBA::Long index4 = IDsOfNodes[3];
197                 CORBA::Long index5 = IDsOfNodes[4];
198                 CORBA::Long index6 = IDsOfNodes[5];
199                 CORBA::Long index7 = IDsOfNodes[6];
200                 CORBA::Long index8 = IDsOfNodes[7];
201                 _myMeshDS->AddVolume(index1, index2, index3, index4, index5, index6,
202                         index7, index8);
203         }
204         return true;
205 };