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
31 #include "SMESH_subMesh_i.hxx"
32 #include "SMESH_Gen_i.hxx"
33 #include "SMESH_Mesh_i.hxx"
35 #include "Utils_CorbaException.hxx"
36 #include "utilities.h"
38 #include "Utils_ExceptHandlers.hxx"
40 //=============================================================================
44 //=============================================================================
46 SMESH_subMesh_i::SMESH_subMesh_i()
47 : SALOME::GenericObj_i( PortableServer::POA::_nil() )
49 MESSAGE("SMESH_subMesh_i::SMESH_subMesh_i default, not for use");
53 //=============================================================================
57 //=============================================================================
59 SMESH_subMesh_i::SMESH_subMesh_i( PortableServer::POA_ptr thePOA,
63 : SALOME::GenericObj_i( thePOA )
65 MESSAGE("SMESH_subMesh_i::SMESH_subMesh_i");
69 thePOA->activate_object( this );
72 //=============================================================================
76 //=============================================================================
78 SMESH_subMesh_i::~SMESH_subMesh_i()
80 MESSAGE("SMESH_subMesh_i::~SMESH_subMesh_i");
84 //=============================================================================
88 //=============================================================================
90 CORBA::Long SMESH_subMesh_i::GetNumberOfElements()
91 throw (SALOME::SALOME_Exception)
93 Unexpect aCatch(SALOME_SalomeException);
94 MESSAGE("SMESH_subMesh_i::GetNumberOfElements");
95 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
98 SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
99 if ( aSubMeshDS == NULL )
102 return aSubMeshDS->NbElements();
105 //=============================================================================
109 //=============================================================================
111 CORBA::Long SMESH_subMesh_i::GetNumberOfNodes()
112 throw (SALOME::SALOME_Exception)
114 Unexpect aCatch(SALOME_SalomeException);
115 MESSAGE("SMESH_subMesh_i::GetNumberOfNodes");
116 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
119 SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
120 if ( aSubMeshDS == NULL )
123 return aSubMeshDS->NbNodes();
126 //=============================================================================
130 //=============================================================================
132 SMESH::long_array* SMESH_subMesh_i::GetElementsId()
133 throw (SALOME::SALOME_Exception)
135 Unexpect aCatch(SALOME_SalomeException);
136 MESSAGE("SMESH_subMesh_i::GetElementsId");
137 SMESH::long_array_var aResult = new SMESH::long_array();
139 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
140 return aResult._retn();
142 SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
143 if ( aSubMeshDS == NULL )
144 return aResult._retn();
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();
151 return aResult._retn();
155 //=============================================================================
159 //=============================================================================
161 SMESH::long_array* SMESH_subMesh_i::GetElementsByType( SMESH::ElementType theElemType )
162 throw (SALOME::SALOME_Exception)
164 Unexpect aCatch(SALOME_SalomeException);
165 MESSAGE("SMESH_subMesh_i::GetElementsByType");
166 SMESH::long_array_var aResult = new SMESH::long_array();
168 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
169 return aResult._retn();
171 SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
172 if ( aSubMeshDS == NULL )
173 return aResult._retn();
176 if ( theElemType == SMESH::ALL )
177 aResult->length( aSubMeshDS->NbElements() + aSubMeshDS->NbNodes() );
178 else if ( theElemType == SMESH::NODE )
179 aResult->length( aSubMeshDS->NbNodes() );
181 aResult->length( aSubMeshDS->NbElements() );
183 int n = aResult->length();
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();
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();
200 aResult->length( i );
202 return aResult._retn();
205 //=============================================================================
209 //=============================================================================
211 SMESH::long_array* SMESH_subMesh_i::GetNodesId()
212 throw (SALOME::SALOME_Exception)
214 Unexpect aCatch(SALOME_SalomeException);
215 MESSAGE("SMESH_subMesh_i::GetNodesId");
216 SMESH::long_array_var aResult = new SMESH::long_array();
218 if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
219 return aResult._retn();
221 SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
222 if ( aSubMeshDS == NULL )
223 return aResult._retn();
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();
230 return aResult._retn();
233 //=============================================================================
237 //=============================================================================
239 SMESH::SMESH_Mesh_ptr SMESH_subMesh_i::GetFather()
240 throw (SALOME::SALOME_Exception)
242 Unexpect aCatch(SALOME_SalomeException);
243 MESSAGE("SMESH_subMesh_i::GetFather");
244 return _mesh_i->_this();
247 //=============================================================================
251 //=============================================================================
253 CORBA::Long SMESH_subMesh_i::GetId()
255 MESSAGE("SMESH_subMesh_i::GetId");
259 //=============================================================================
263 //=============================================================================
264 SALOME_MED::FAMILY_ptr SMESH_subMesh_i::GetFamily()
265 throw (SALOME::SALOME_Exception)
267 Unexpect aCatch(SALOME_SalomeException);
268 SALOME_MED::MESH_var MEDMesh = GetFather()->GetMEDMesh();
270 SALOME_MED::Family_array_var families =
271 MEDMesh->getFamilies(SALOME_MED::MED_NODE);
273 for ( int i = 0; i < families->length(); i++ ) {
274 if ( families[i]->getIdentifier() == ( _localId ) )