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 SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
98 if ( aSubMeshDS == NULL )
101 return aSubMeshDS->NbElements();
104 //=============================================================================
108 //=============================================================================
110 CORBA::Long SMESH_subMesh_i::GetNumberOfNodes(CORBA::Boolean all)
111 throw (SALOME::SALOME_Exception)
113 Unexpect aCatch(SALOME_SalomeException);
114 MESSAGE("SMESH_subMesh_i::GetNumberOfNodes");
115 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
118 SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
119 if ( aSubMeshDS == NULL )
122 if ( all ) { // all nodes of submesh elements
124 SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
125 while ( eIt->more() ) {
126 const SMDS_MeshElement* anElem = eIt->next();
127 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
128 while ( nIt->more() )
129 nodeIds.insert( nIt->next()->GetID() );
131 return nodeIds.size();
134 return aSubMeshDS->NbNodes();
137 //=============================================================================
141 //=============================================================================
143 SMESH::long_array* SMESH_subMesh_i::GetElementsId()
144 throw (SALOME::SALOME_Exception)
146 Unexpect aCatch(SALOME_SalomeException);
147 MESSAGE("SMESH_subMesh_i::GetElementsId");
148 SMESH::long_array_var aResult = new SMESH::long_array();
150 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
151 return aResult._retn();
153 SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
154 if ( aSubMeshDS == NULL )
155 return aResult._retn();
157 aResult->length( aSubMeshDS->NbElements() );
158 SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements();
159 for ( int i = 0, n = aSubMeshDS->NbElements(); i < n && anIt->more(); i++ )
160 aResult[i] = anIt->next()->GetID();
162 return aResult._retn();
166 //=============================================================================
170 //=============================================================================
172 SMESH::long_array* SMESH_subMesh_i::GetElementsByType( SMESH::ElementType theElemType )
173 throw (SALOME::SALOME_Exception)
175 Unexpect aCatch(SALOME_SalomeException);
176 MESSAGE("SMESH_subMesh_i::GetElementsByType");
177 SMESH::long_array_var aResult = new SMESH::long_array();
179 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
180 return aResult._retn();
182 SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
183 if ( aSubMeshDS == NULL )
184 return aResult._retn();
186 // No sense in returning ids of elements along with ids of nodes:
187 // when theElemType == SMESH::ALL, return node ids only if
188 // there are no elements
189 bool retNodes = (theElemType == SMESH::NODE ||
190 (theElemType == SMESH::ALL && aSubMeshDS->NbElements() == 0));
192 // PAL5440, return all nodes belonging to elements of submesh
195 SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
196 while ( eIt->more() ) {
197 const SMDS_MeshElement* anElem = eIt->next();
198 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
199 while ( nIt->more() )
200 nodeIds.insert( nIt->next()->GetID() );
204 if ( theElemType == SMESH::ALL )
205 aResult->length( aSubMeshDS->NbElements() + nodeIds.size());
206 else if ( theElemType == SMESH::NODE )
207 aResult->length( nodeIds.size() );
209 aResult->length( aSubMeshDS->NbElements() );
211 int i = 0, n = aResult->length();
213 if ( retNodes && !nodeIds.empty() ) {
214 set<int>::iterator idIt = nodeIds.begin();
215 for ( ; i < n && idIt != nodeIds.end() ; i++, idIt++ )
219 if ( theElemType == SMESH::ALL || theElemType != SMESH::NODE ) {
220 SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements();
221 while ( i < n && anIt->more() ) {
222 const SMDS_MeshElement* anElem = anIt->next();
223 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
224 aResult[i++] = anElem->GetID();
228 aResult->length( i );
230 return aResult._retn();
233 //=============================================================================
237 //=============================================================================
239 SMESH::long_array* SMESH_subMesh_i::GetNodesId()
240 throw (SALOME::SALOME_Exception)
242 Unexpect aCatch(SALOME_SalomeException);
243 MESSAGE("SMESH_subMesh_i::GetNodesId");
244 SMESH::long_array_var aResult = new SMESH::long_array();
246 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
247 return aResult._retn();
249 SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
250 if ( aSubMeshDS == NULL )
251 return aResult._retn();
253 aResult->length( aSubMeshDS->NbNodes() );
254 SMDS_NodeIteratorPtr anIt = aSubMeshDS->GetNodes();
255 for ( int i = 0, n = aSubMeshDS->NbNodes(); i < n && anIt->more(); i++ )
256 aResult[i] = anIt->next()->GetID();
258 return aResult._retn();
261 //=============================================================================
265 //=============================================================================
267 SMESH::SMESH_Mesh_ptr SMESH_subMesh_i::GetFather()
268 throw (SALOME::SALOME_Exception)
270 Unexpect aCatch(SALOME_SalomeException);
271 MESSAGE("SMESH_subMesh_i::GetFather");
272 return _mesh_i->_this();
275 //=============================================================================
279 //=============================================================================
281 CORBA::Long SMESH_subMesh_i::GetId()
283 MESSAGE("SMESH_subMesh_i::GetId");
287 //=======================================================================
288 //function : GetSubShape
290 //=======================================================================
292 GEOM::GEOM_Object_ptr SMESH_subMesh_i::GetSubShape()
293 throw (SALOME::SALOME_Exception)
295 Unexpect aCatch(SALOME_SalomeException);
296 GEOM::GEOM_Object_var aShapeObj;
298 if ( _mesh_i->_mapSubMesh.find( _localId ) != _mesh_i->_mapSubMesh.end()) {
299 TopoDS_Shape S = _mesh_i->_mapSubMesh[ _localId ]->GetSubShape();
301 aShapeObj = _gen_i->ShapeToGeomObject( S );
304 catch(SALOME_Exception & S_ex) {
305 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
307 return aShapeObj._retn();
310 //=============================================================================
314 //=============================================================================
315 SALOME_MED::FAMILY_ptr SMESH_subMesh_i::GetFamily()
316 throw (SALOME::SALOME_Exception)
318 Unexpect aCatch(SALOME_SalomeException);
319 SALOME_MED::MESH_var MEDMesh = GetFather()->GetMEDMesh();
321 SALOME_MED::Family_array_var families =
322 MEDMesh->getFamilies(SALOME_MED::MED_NODE);
324 for ( int i = 0; i < families->length(); i++ ) {
325 if ( families[i]->getIdentifier() == ( _localId ) )
329 return SALOME_MED::FAMILY::_nil();
332 //=============================================================================
336 //=============================================================================
337 SMESH::long_array* SMESH_subMesh_i::GetIDs()
339 SMESH::long_array_var aResult = GetElementsId();
340 return aResult._retn();