1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_subMesh_i.cxx
25 // Author : Paul RASCLE, EDF
30 #include "SMESH_subMesh_i.hxx"
31 #include "SMESH_Gen_i.hxx"
32 #include "SMESH_Mesh_i.hxx"
34 #include "Utils_CorbaException.hxx"
35 #include "utilities.h"
37 #include "Utils_ExceptHandlers.hxx"
39 //=============================================================================
43 //=============================================================================
45 SMESH_subMesh_i::SMESH_subMesh_i()
46 : SALOME::GenericObj_i( PortableServer::POA::_nil() )
48 MESSAGE("SMESH_subMesh_i::SMESH_subMesh_i default, not for use");
52 //=============================================================================
56 //=============================================================================
58 SMESH_subMesh_i::SMESH_subMesh_i( PortableServer::POA_ptr thePOA,
62 : SALOME::GenericObj_i( thePOA )
64 MESSAGE("SMESH_subMesh_i::SMESH_subMesh_i");
68 thePOA->activate_object( this );
71 //=============================================================================
75 //=============================================================================
77 SMESH_subMesh_i::~SMESH_subMesh_i()
79 MESSAGE("SMESH_subMesh_i::~SMESH_subMesh_i");
83 //=============================================================================
87 //=============================================================================
89 CORBA::Long SMESH_subMesh_i::GetNumberOfElements()
90 throw (SALOME::SALOME_Exception)
92 Unexpect aCatch(SALOME_SalomeException);
93 MESSAGE("SMESH_subMesh_i::GetNumberOfElements");
94 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
97 ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId];
98 SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS();
100 int nbElems = aSubMeshDS ? aSubMeshDS->NbElements() : 0;
102 // volumes are bound to shell
103 if ( nbElems == 0 && aSubMesh->GetSubShape().ShapeType() <= TopAbs_SOLID )
105 SMESHDS_Mesh* aMeshDS = aSubMesh->GetFather()->GetMeshDS();
106 TopExp_Explorer exp( aSubMesh->GetSubShape(), TopAbs_SHELL );
107 for ( ; exp.More(); exp.Next() )
109 aSubMeshDS = aMeshDS->MeshElements( exp.Current() );
111 nbElems += aSubMeshDS->NbElements();
117 //=============================================================================
121 //=============================================================================
123 CORBA::Long SMESH_subMesh_i::GetNumberOfNodes(CORBA::Boolean all)
124 throw (SALOME::SALOME_Exception)
126 Unexpect aCatch(SALOME_SalomeException);
127 MESSAGE("SMESH_subMesh_i::GetNumberOfNodes");
128 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
131 ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId];
132 SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS();
136 // node are bound to shell instead of solid
137 if ( all && aSubMesh->GetSubShape().ShapeType() <= TopAbs_SOLID )
139 SMESHDS_Mesh* aMeshDS = aSubMesh->GetFather()->GetMeshDS();
140 TopExp_Explorer exp( aSubMesh->GetSubShape(), TopAbs_SHELL );
141 for ( ; exp.More(); exp.Next() )
143 aSubMeshDS = aMeshDS->MeshElements( exp.Current() );
145 SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
146 while ( eIt->more() ) {
147 const SMDS_MeshElement* anElem = eIt->next();
148 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
149 while ( nIt->more() )
150 nodeIds.insert( nIt->next()->GetID() );
154 return nodeIds.size();
157 if ( aSubMeshDS == NULL )
160 if ( all ) { // all nodes of submesh elements
161 SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
162 while ( eIt->more() ) {
163 const SMDS_MeshElement* anElem = eIt->next();
164 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
165 while ( nIt->more() )
166 nodeIds.insert( nIt->next()->GetID() );
168 return nodeIds.size();
171 return aSubMeshDS->NbNodes();
174 //=============================================================================
178 //=============================================================================
180 SMESH::long_array* SMESH_subMesh_i::GetElementsId()
181 throw (SALOME::SALOME_Exception)
183 Unexpect aCatch(SALOME_SalomeException);
184 MESSAGE("SMESH_subMesh_i::GetElementsId");
185 SMESH::long_array_var aResult = new SMESH::long_array();
187 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
188 return aResult._retn();
190 ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId];
191 SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS();
193 int nbElems = aSubMeshDS ? aSubMeshDS->NbElements() : 0;
194 list<SMESHDS_SubMesh*> smList;
196 smList.push_back( aSubMeshDS );
198 // volumes are bound to shell
199 if ( nbElems == 0 && aSubMesh->GetSubShape().ShapeType() <= TopAbs_SOLID )
201 SMESHDS_Mesh* aMeshDS = aSubMesh->GetFather()->GetMeshDS();
202 TopExp_Explorer exp( aSubMesh->GetSubShape(), TopAbs_SHELL );
203 for ( ; exp.More(); exp.Next() )
205 aSubMeshDS = aMeshDS->MeshElements( exp.Current() );
207 smList.push_back( aSubMeshDS );
208 nbElems += aSubMeshDS->NbElements();
215 aResult->length( nbElems );
216 list<SMESHDS_SubMesh*>::iterator sm = smList.begin();
217 for ( int i = 0; sm != smList.end(); sm++ )
220 SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements();
221 for ( int n = aSubMeshDS->NbElements(); i < n && anIt->more(); i++ )
222 aResult[i] = anIt->next()->GetID();
225 return aResult._retn();
229 //=============================================================================
233 //=============================================================================
235 SMESH::long_array* SMESH_subMesh_i::GetElementsByType( SMESH::ElementType theElemType )
236 throw (SALOME::SALOME_Exception)
238 Unexpect aCatch(SALOME_SalomeException);
239 MESSAGE("SMESH_subMesh_i::GetElementsByType");
240 SMESH::long_array_var aResult = new SMESH::long_array();
242 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
243 return aResult._retn();
245 ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId];
246 SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS();
248 // PAL5440, return all nodes belonging to elements of submesh
250 int nbElems = aSubMeshDS ? aSubMeshDS->NbElements() : 0;
252 // volumes may be bound to shell instead of solid
253 list< SMESHDS_SubMesh* > smList;
254 if ( nbElems == 0 && aSubMesh->GetSubShape().ShapeType() <= TopAbs_SOLID )
256 SMESHDS_Mesh* aMeshDS = aSubMesh->GetFather()->GetMeshDS();
257 TopExp_Explorer exp( aSubMesh->GetSubShape(), TopAbs_SHELL );
258 for ( ; exp.More(); exp.Next() )
260 aSubMeshDS = aMeshDS->MeshElements( exp.Current() );
261 if ( !aSubMeshDS ) continue;
262 if ( theElemType == SMESH::NODE )
264 SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
265 while ( eIt->more() ) {
266 const SMDS_MeshElement* anElem = eIt->next();
267 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
268 while ( nIt->more() )
269 nodeIds.insert( nIt->next()->GetID() );
274 smList.push_back( aSubMeshDS );
275 nbElems += aSubMeshDS->NbElements();
283 smList.push_back( aSubMeshDS );
286 if ( theElemType == SMESH::NODE && aSubMeshDS )
288 SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
289 while ( eIt->more() ) {
290 const SMDS_MeshElement* anElem = eIt->next();
291 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
292 while ( nIt->more() )
293 nodeIds.insert( nIt->next()->GetID() );
297 if ( theElemType == SMESH::NODE )
298 aResult->length( nodeIds.size() );
300 aResult->length( nbElems );
302 int i = 0, n = aResult->length();
304 if ( theElemType == SMESH::NODE && !nodeIds.empty() ) {
305 set<int>::iterator idIt = nodeIds.begin();
306 for ( ; i < n && idIt != nodeIds.end() ; i++, idIt++ )
310 if ( theElemType != SMESH::NODE ) {
311 list<SMESHDS_SubMesh*>::iterator sm = smList.begin();
312 for ( i = 0; sm != smList.end(); sm++ )
315 SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements();
316 while ( i < n && anIt->more() ) {
317 const SMDS_MeshElement* anElem = anIt->next();
318 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
319 aResult[i++] = anElem->GetID();
324 aResult->length( i );
326 return aResult._retn();
329 //=============================================================================
333 //=============================================================================
335 SMESH::long_array* SMESH_subMesh_i::GetNodesId()
336 throw (SALOME::SALOME_Exception)
338 Unexpect aCatch(SALOME_SalomeException);
339 MESSAGE("SMESH_subMesh_i::GetNodesId");
340 SMESH::long_array_var aResult = GetElementsByType( SMESH::NODE );
341 return aResult._retn();
344 //=============================================================================
348 //=============================================================================
350 SMESH::SMESH_Mesh_ptr SMESH_subMesh_i::GetFather()
351 throw (SALOME::SALOME_Exception)
353 Unexpect aCatch(SALOME_SalomeException);
354 MESSAGE("SMESH_subMesh_i::GetFather");
355 return _mesh_i->_this();
358 //=============================================================================
362 //=============================================================================
364 CORBA::Long SMESH_subMesh_i::GetId()
366 MESSAGE("SMESH_subMesh_i::GetId");
370 //=======================================================================
371 //function : GetSubShape
373 //=======================================================================
375 GEOM::GEOM_Object_ptr SMESH_subMesh_i::GetSubShape()
376 throw (SALOME::SALOME_Exception)
378 Unexpect aCatch(SALOME_SalomeException);
379 GEOM::GEOM_Object_var aShapeObj;
381 if ( _mesh_i->_mapSubMesh.find( _localId ) != _mesh_i->_mapSubMesh.end()) {
382 TopoDS_Shape S = _mesh_i->_mapSubMesh[ _localId ]->GetSubShape();
384 aShapeObj = _gen_i->ShapeToGeomObject( S );
387 catch(SALOME_Exception & S_ex) {
388 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
390 return aShapeObj._retn();
393 //=============================================================================
397 //=============================================================================
398 SALOME_MED::FAMILY_ptr SMESH_subMesh_i::GetFamily()
399 throw (SALOME::SALOME_Exception)
401 Unexpect aCatch(SALOME_SalomeException);
402 SALOME_MED::MESH_var MEDMesh = GetFather()->GetMEDMesh();
404 SALOME_MED::Family_array_var families =
405 MEDMesh->getFamilies(SALOME_MED::MED_NODE);
407 for ( int i = 0; i < families->length(); i++ ) {
408 if ( families[i]->getIdentifier() == ( _localId ) )
412 return SALOME_MED::FAMILY::_nil();
415 //=============================================================================
419 //=============================================================================
420 SMESH::long_array* SMESH_subMesh_i::GetIDs()
422 SMESH::long_array_var aResult = GetElementsId();
423 return aResult._retn();