Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/smesh.git] / src / SMESH_I / SMESH_subMesh_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_subMesh_i.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 using namespace std;
31 #include "SMESH_subMesh_i.hxx"
32 #include "SMESH_Gen_i.hxx"
33 #include "SMESH_Mesh_i.hxx"
34
35 #include "Utils_CorbaException.hxx"
36 #include "utilities.h"
37 #include "OpUtil.hxx"
38 #include "Utils_ExceptHandlers.hxx"
39
40 //=============================================================================
41 /*!
42  *  
43  */
44 //=============================================================================
45
46 SMESH_subMesh_i::SMESH_subMesh_i()
47      : SALOME::GenericObj_i( PortableServer::POA::_nil() )
48 {
49   MESSAGE("SMESH_subMesh_i::SMESH_subMesh_i default, not for use");
50     ASSERT(0);
51 }
52
53 //=============================================================================
54 /*!
55  *  
56  */
57 //=============================================================================
58
59 SMESH_subMesh_i::SMESH_subMesh_i( PortableServer::POA_ptr thePOA,
60                                   SMESH_Gen_i*            gen_i,
61                                   SMESH_Mesh_i*           mesh_i,
62                                   int                     localId )
63      : SALOME::GenericObj_i( thePOA )
64 {
65   MESSAGE("SMESH_subMesh_i::SMESH_subMesh_i");
66   _gen_i = gen_i;
67   _mesh_i = mesh_i;
68   _localId = localId;
69   thePOA->activate_object( this );
70   // ****
71 }
72 //=============================================================================
73 /*!
74  *  
75  */
76 //=============================================================================
77
78 SMESH_subMesh_i::~SMESH_subMesh_i()
79 {
80   MESSAGE("SMESH_subMesh_i::~SMESH_subMesh_i");
81   // ****
82 }
83
84 //=============================================================================
85 /*!
86  *  
87  */
88 //=============================================================================
89
90 CORBA::Long SMESH_subMesh_i::GetNumberOfElements()
91   throw (SALOME::SALOME_Exception)
92 {
93   Unexpect aCatch(SALOME_SalomeException);
94   MESSAGE("SMESH_subMesh_i::GetNumberOfElements");
95   if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
96     return 0;
97
98   SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
99   if ( aSubMeshDS == NULL )
100     return 0;
101
102   return aSubMeshDS->NbElements();
103 }
104
105 //=============================================================================
106 /*!
107  *  
108  */
109 //=============================================================================
110
111 CORBA::Long SMESH_subMesh_i::GetNumberOfNodes()
112   throw (SALOME::SALOME_Exception)
113 {
114   Unexpect aCatch(SALOME_SalomeException);
115   MESSAGE("SMESH_subMesh_i::GetNumberOfNodes");
116   if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
117     return 0;
118
119   SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
120   if ( aSubMeshDS == NULL )
121     return 0;
122
123   return aSubMeshDS->NbNodes();
124 }
125
126 //=============================================================================
127 /*!
128  *  
129  */
130 //=============================================================================
131   
132 SMESH::long_array* SMESH_subMesh_i::GetElementsId()
133   throw (SALOME::SALOME_Exception)
134 {
135   Unexpect aCatch(SALOME_SalomeException);
136   MESSAGE("SMESH_subMesh_i::GetElementsId");
137   SMESH::long_array_var aResult = new SMESH::long_array();
138
139   if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
140     return aResult._retn();
141
142   SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
143   if ( aSubMeshDS == NULL )
144     return aResult._retn();
145
146   aResult->length( aSubMeshDS->NbElements() );
147   SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements();
148   for ( int i = 0, n = aSubMeshDS->NbElements(); i < n && anIt->more(); i++ )
149     aResult[i] = anIt->next()->GetID();
150
151   return aResult._retn();
152 }
153
154
155 //=============================================================================
156 /*!
157  *  
158  */
159 //=============================================================================
160
161 SMESH::long_array* SMESH_subMesh_i::GetElementsByType( SMESH::ElementType theElemType )
162     throw (SALOME::SALOME_Exception)
163 {
164   Unexpect aCatch(SALOME_SalomeException);
165   MESSAGE("SMESH_subMesh_i::GetElementsByType");
166   SMESH::long_array_var aResult = new SMESH::long_array();
167
168   if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
169     return aResult._retn();
170
171   SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
172   if ( aSubMeshDS == NULL )
173     return aResult._retn();
174
175   int i = 0;
176   if ( theElemType == SMESH::ALL )
177     aResult->length( aSubMeshDS->NbElements() + aSubMeshDS->NbNodes() );
178   else if ( theElemType == SMESH::NODE )
179     aResult->length( aSubMeshDS->NbNodes() );
180   else
181     aResult->length( aSubMeshDS->NbElements() );
182
183   int n = aResult->length();
184
185   if ( theElemType == SMESH::ALL || theElemType == SMESH::NODE ) {
186     SMDS_NodeIteratorPtr anIt = aSubMeshDS->GetNodes();
187     while ( i < n && anIt->more() )
188       aResult[i++] = anIt->next()->GetID();
189   }
190
191   if ( theElemType == SMESH::ALL || theElemType != SMESH::NODE ) {
192     SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements();
193     while ( i < n && anIt->more() ) {
194       const SMDS_MeshElement* anElem = anIt->next();
195       if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
196         aResult[i++] = anElem->GetID();
197     }
198   }
199
200   aResult->length( i );
201
202   return aResult._retn();
203 }
204
205 //=============================================================================
206 /*!
207  *  
208  */
209 //=============================================================================
210   
211 SMESH::long_array* SMESH_subMesh_i::GetNodesId()
212   throw (SALOME::SALOME_Exception)
213 {
214   Unexpect aCatch(SALOME_SalomeException);
215   MESSAGE("SMESH_subMesh_i::GetNodesId");
216   SMESH::long_array_var aResult = new SMESH::long_array();
217
218   if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
219     return aResult._retn();
220
221   SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
222   if ( aSubMeshDS == NULL )
223     return aResult._retn();
224
225   aResult->length( aSubMeshDS->NbNodes() );
226   SMDS_NodeIteratorPtr anIt = aSubMeshDS->GetNodes();
227   for ( int i = 0, n = aSubMeshDS->NbNodes(); i < n && anIt->more(); i++ )
228     aResult[i] = anIt->next()->GetID();
229
230   return aResult._retn();
231 }
232
233 //=============================================================================
234 /*!
235  *  
236  */
237 //=============================================================================
238   
239 SMESH::SMESH_Mesh_ptr SMESH_subMesh_i::GetFather()
240   throw (SALOME::SALOME_Exception)
241 {
242   Unexpect aCatch(SALOME_SalomeException);
243   MESSAGE("SMESH_subMesh_i::GetFather");
244   return _mesh_i->_this();
245 }
246
247 //=============================================================================
248 /*!
249  *  
250  */
251 //=============================================================================
252   
253 CORBA::Long SMESH_subMesh_i::GetId()
254 {
255   MESSAGE("SMESH_subMesh_i::GetId");
256   return _localId;
257 }
258
259 //=============================================================================
260 /*!
261  *  
262  */
263 //=============================================================================
264 SALOME_MED::FAMILY_ptr SMESH_subMesh_i::GetFamily()
265   throw (SALOME::SALOME_Exception)
266 {
267   Unexpect aCatch(SALOME_SalomeException);
268   SALOME_MED::MESH_var MEDMesh = GetFather()->GetMEDMesh();
269
270   SALOME_MED::Family_array_var families = 
271     MEDMesh->getFamilies(SALOME_MED::MED_NODE);
272     
273   for ( int i = 0; i < families->length(); i++ ) {
274     if ( families[i]->getIdentifier() == ( _localId ) )
275       return families[i];
276   }
277 }