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_Mesh_i.cxx
25 // Author : Paul RASCLE, EDF
29 #include "SMESH_Mesh_i.hxx"
30 #include "SMESH_subMesh_i.hxx"
31 #include "SMESH_MEDMesh_i.hxx"
32 #include "SMESH_Group_i.hxx"
33 #include "SMESH_Filter_i.hxx"
35 #include "Utils_CorbaException.hxx"
36 #include "Utils_ExceptHandlers.hxx"
37 #include "utilities.h"
39 #include "SALOME_NamingService.hxx"
40 #include "Utils_SINGLETON.hxx"
43 #include "TCollection_AsciiString.hxx"
44 #include "SMESHDS_Command.hxx"
45 #include "SMESHDS_CommandType.hxx"
46 #include "SMESH_MeshEditor_i.hxx"
47 #include "SMESH_Gen_i.hxx"
48 #include "DriverMED_R_SMESHDS_Mesh.h"
50 #include <TColStd_MapOfInteger.hxx>
51 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
52 #include <TColStd_SequenceOfInteger.hxx>
59 static int MYDEBUG = 0;
61 static int MYDEBUG = 0;
66 int SMESH_Mesh_i::myIdGenerator = 0;
68 //=============================================================================
72 //=============================================================================
74 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
77 : SALOME::GenericObj_i( thePOA )
79 INFOS("SMESH_Mesh_i");
82 _id = myIdGenerator++;
84 thePOA->activate_object( this );
87 //=============================================================================
91 //=============================================================================
93 SMESH_Mesh_i::~SMESH_Mesh_i()
95 INFOS("~SMESH_Mesh_i");
96 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
97 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
98 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
101 // this method is colled from destructor of group (PAL6331)
102 //_impl->RemoveGroup( aGroup->GetLocalID() );
110 //=============================================================================
114 * Associates <this> mesh with <theShape> and puts a reference
115 * to <theShape> into the current study;
116 * the previous shape is substituted by the new one.
118 //=============================================================================
120 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
121 throw (SALOME::SALOME_Exception)
123 Unexpect aCatch(SALOME_SalomeException);
125 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
127 catch(SALOME_Exception & S_ex) {
128 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
132 //=======================================================================
133 //function : GetShapeToMesh
135 //=======================================================================
137 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
138 throw (SALOME::SALOME_Exception)
140 Unexpect aCatch(SALOME_SalomeException);
141 GEOM::GEOM_Object_var aShapeObj;
143 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
145 aShapeObj = _gen_i->ShapeToGeomObject( S );
147 catch(SALOME_Exception & S_ex) {
148 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
150 return aShapeObj._retn();
153 //=============================================================================
157 //=============================================================================
159 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
161 SMESH::DriverMED_ReadStatus res;
164 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
165 res = SMESH::DRS_OK; break;
166 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
167 res = SMESH::DRS_EMPTY; break;
168 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
169 res = SMESH::DRS_WARN_RENUMBER; break;
170 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
171 res = SMESH::DRS_WARN_SKIP_ELEM; break;
172 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
174 res = SMESH::DRS_FAIL; break;
179 //=============================================================================
183 * Imports mesh data from MED file
185 //=============================================================================
187 SMESH::DriverMED_ReadStatus
188 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
189 throw ( SALOME::SALOME_Exception )
191 Unexpect aCatch(SALOME_SalomeException);
194 status = importMEDFile( theFileName, theMeshName );
196 catch( SALOME_Exception& S_ex ) {
197 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
200 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
203 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
204 if ( !aStudy->_is_nil() ) {
205 // publishing of the groups in the study (sub-meshes are out of scope of MED import)
206 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
207 for (; it != _mapGroups.end(); it++ ) {
208 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
209 _gen_i->PublishGroup( aStudy, _this(), aGroup,
210 GEOM::GEOM_Object::_nil(), aGroup->GetName());
213 return ConvertDriverMEDReadStatus(status);
216 //=============================================================================
220 * Imports mesh data from MED file
222 //=============================================================================
224 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
225 throw ( SALOME::SALOME_Exception )
227 // Read mesh with name = <theMeshName> into SMESH_Mesh
228 _impl->UNVToMesh( theFileName );
233 //=============================================================================
237 * Imports mesh data from STL file
239 //=============================================================================
240 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
241 throw ( SALOME::SALOME_Exception )
243 // Read mesh with name = <theMeshName> into SMESH_Mesh
244 _impl->STLToMesh( theFileName );
249 //=============================================================================
253 * Imports mesh data from MED file
255 //=============================================================================
257 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
259 // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
260 int status = _impl->MEDToMesh( theFileName, theMeshName );
262 // Create group servants, if any groups were imported
263 list<int> aGroupIds = _impl->GetGroupIds();
264 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
265 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
267 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
268 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
269 aGroupImpl->Register();
270 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
272 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
273 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
275 // register CORBA object for persistence
276 int nextId = _gen_i->RegisterObject( aGroup );
277 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
283 //=============================================================================
287 //=============================================================================
289 static SMESH::Hypothesis_Status ConvertHypothesisStatus
290 (SMESH_Hypothesis::Hypothesis_Status theStatus)
292 SMESH::Hypothesis_Status res;
295 case SMESH_Hypothesis::HYP_OK:
296 res = SMESH::HYP_OK; break;
297 case SMESH_Hypothesis::HYP_MISSING:
298 res = SMESH::HYP_MISSING; break;
299 case SMESH_Hypothesis::HYP_CONCURENT:
300 res = SMESH::HYP_CONCURENT; break;
301 case SMESH_Hypothesis::HYP_BAD_PARAMETER:
302 res = SMESH::HYP_BAD_PARAMETER; break;
303 case SMESH_Hypothesis::HYP_INCOMPATIBLE:
304 res = SMESH::HYP_INCOMPATIBLE; break;
305 case SMESH_Hypothesis::HYP_NOTCONFORM:
306 res = SMESH::HYP_NOTCONFORM; break;
307 case SMESH_Hypothesis::HYP_ALREADY_EXIST:
308 res = SMESH::HYP_ALREADY_EXIST; break;
309 case SMESH_Hypothesis::HYP_BAD_DIM:
310 res = SMESH::HYP_BAD_DIM; break;
312 res = SMESH::HYP_UNKNOWN_FATAL;
317 //=============================================================================
321 * calls internal addHypothesis() and then adds a reference to <anHyp> under
322 * the SObject actually having a reference to <aSubShape>.
323 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
325 //=============================================================================
327 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
328 SMESH::SMESH_Hypothesis_ptr anHyp)
329 throw(SALOME::SALOME_Exception)
331 Unexpect aCatch(SALOME_SalomeException);
332 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
334 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
335 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
336 aSubShapeObject, anHyp );
338 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
340 // Update Python script
341 TCollection_AsciiString aStr ("status = ");
342 SMESH_Gen_i::AddObject(aStr, _this()) += ".AddHypothesis(";
343 SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", ";
344 SMESH_Gen_i::AddObject(aStr, anHyp) += ")";
346 SMESH_Gen_i::AddToCurrentPyScript(aStr);
348 return ConvertHypothesisStatus(status);
351 //=============================================================================
355 //=============================================================================
357 SMESH_Hypothesis::Hypothesis_Status
358 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
359 SMESH::SMESH_Hypothesis_ptr anHyp)
361 if(MYDEBUG) MESSAGE("addHypothesis");
363 if (CORBA::is_nil(aSubShapeObject))
364 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
367 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
368 if (CORBA::is_nil(myHyp))
369 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
372 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
375 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
376 int hypId = myHyp->GetId();
377 status = _impl->AddHypothesis(myLocSubShape, hypId);
378 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
379 _mapHypo[hypId] = myHyp;
380 // assure there is a corresponding submesh
381 if ( !_impl->IsMainShape( myLocSubShape )) {
382 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
383 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
384 createSubMesh( aSubShapeObject );
388 catch(SALOME_Exception & S_ex)
390 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
395 //=============================================================================
399 //=============================================================================
401 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
402 SMESH::SMESH_Hypothesis_ptr anHyp)
403 throw(SALOME::SALOME_Exception)
405 Unexpect aCatch(SALOME_SalomeException);
406 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
408 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
409 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
410 aSubShapeObject, anHyp );
412 // Update Python script
413 TCollection_AsciiString aStr ("status = ");
414 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveHypothesis(";
415 SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", ";
416 SMESH_Gen_i::AddObject(aStr, anHyp) += ")";
418 SMESH_Gen_i::AddToCurrentPyScript(aStr);
420 return ConvertHypothesisStatus(status);
423 //=============================================================================
427 //=============================================================================
429 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
430 SMESH::SMESH_Hypothesis_ptr anHyp)
432 if(MYDEBUG) MESSAGE("removeHypothesis()");
433 // **** proposer liste de subShape (selection multiple)
435 if (CORBA::is_nil(aSubShapeObject))
436 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
439 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
440 if (CORBA::is_nil(myHyp))
441 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
444 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
447 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
448 int hypId = myHyp->GetId();
449 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
450 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
451 _mapHypo.erase( hypId );
453 catch(SALOME_Exception & S_ex)
455 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
460 //=============================================================================
464 //=============================================================================
466 SMESH::ListOfHypothesis *
467 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
468 throw(SALOME::SALOME_Exception)
470 Unexpect aCatch(SALOME_SalomeException);
471 if (MYDEBUG) MESSAGE("GetHypothesisList");
472 if (CORBA::is_nil(aSubShapeObject))
473 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
476 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
479 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
480 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
481 int i = 0, n = aLocalList.size();
484 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
485 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
486 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
487 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
492 catch(SALOME_Exception & S_ex) {
493 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
496 return aList._retn();
499 //=============================================================================
503 //=============================================================================
504 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
505 const char* theName )
506 throw(SALOME::SALOME_Exception)
508 Unexpect aCatch(SALOME_SalomeException);
509 MESSAGE("SMESH_Mesh_i::GetSubMesh");
510 if (CORBA::is_nil(aSubShapeObject))
511 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
514 SMESH::SMESH_subMesh_var subMesh;
515 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
517 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
519 //Get or Create the SMESH_subMesh object implementation
521 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
522 subMesh = getSubMesh( subMeshId );
524 // create a new subMesh object servant if there is none for the shape
525 if ( subMesh->_is_nil() )
526 subMesh = createSubMesh( aSubShapeObject );
528 if ( _gen_i->CanPublishInStudy( subMesh )) {
529 SALOMEDS::SObject_var aSO =
530 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
531 subMesh, aSubShapeObject, theName );
532 if ( !aSO->_is_nil()) {
533 // Update Python script
534 TCollection_AsciiString aStr (aSO->GetID());
536 SMESH_Gen_i::AddObject(aStr, _this()) += ".GetSubMesh(";
537 SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", \"";
538 aStr += (char*)theName;
541 SMESH_Gen_i::AddToCurrentPyScript(aStr);
545 catch(SALOME_Exception & S_ex) {
546 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
548 return subMesh._retn();
551 //=============================================================================
555 //=============================================================================
557 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
558 throw (SALOME::SALOME_Exception)
560 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
561 if ( theSubMesh->_is_nil() )
564 GEOM::GEOM_Object_var aSubShapeObject;
565 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
566 if ( !aStudy->_is_nil() ) {
567 // Remove submesh's SObject
568 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
569 if ( !anSO->_is_nil() ) {
570 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
571 SALOMEDS::SObject_var anObj, aRef;
572 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
573 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
575 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
577 // Update Python script
578 TCollection_AsciiString aStr;
579 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveSubMesh(";
580 aStr += anSO->GetID();
583 SMESH_Gen_i::AddToCurrentPyScript(aStr);
587 removeSubMesh( theSubMesh, aSubShapeObject.in() );
590 //=============================================================================
594 //=============================================================================
595 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
597 TCollection_AsciiString aStr;
598 switch (theElemType) {
612 aStr = "SMESH.VOLUME";
620 //=============================================================================
624 //=============================================================================
626 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
627 const char* theName )
628 throw(SALOME::SALOME_Exception)
630 Unexpect aCatch(SALOME_SalomeException);
631 SMESH::SMESH_Group_var aNewGroup =
632 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
634 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
635 SALOMEDS::SObject_var aSO =
636 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
637 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
638 if ( !aSO->_is_nil()) {
639 // Update Python script
640 TCollection_AsciiString aStr (aSO->GetID());
642 SMESH_Gen_i::AddObject(aStr, _this()) += ".CreateGroup(";
643 aStr += ElementTypeString(theElemType) + ", \"" + (char*)theName + "\")";
645 SMESH_Gen_i::AddToCurrentPyScript(aStr);
649 return aNewGroup._retn();
653 //=============================================================================
657 //=============================================================================
658 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
660 GEOM::GEOM_Object_ptr theGeomObj)
661 throw(SALOME::SALOME_Exception)
663 Unexpect aCatch(SALOME_SalomeException);
664 SMESH::SMESH_GroupOnGeom_var aNewGroup;
666 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
667 if ( !aShape.IsNull() ) {
668 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
669 ( createGroup( theElemType, theName, aShape ));
670 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
671 SALOMEDS::SObject_var aSO =
672 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
673 aNewGroup, theGeomObj, theName);
674 if ( !aSO->_is_nil()) {
675 // Update Python script
676 TCollection_AsciiString aStr (aSO->GetID());
678 SMESH_Gen_i::AddObject(aStr, _this()) += ".CreateGroupFromGEOM(";
679 aStr += ElementTypeString(theElemType) + ", \"" + (char*)theName + "\", ";
680 SMESH_Gen_i::AddObject(aStr, theGeomObj) += ")";
682 SMESH_Gen_i::AddToCurrentPyScript(aStr);
687 return aNewGroup._retn();
690 //=============================================================================
694 //=============================================================================
696 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
697 throw (SALOME::SALOME_Exception)
699 if ( theGroup->_is_nil() )
702 SMESH_GroupBase_i* aGroup =
703 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
707 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
708 if ( !aStudy->_is_nil() ) {
709 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
711 if ( !aGroupSO->_is_nil() ) {
712 // Update Python script
713 TCollection_AsciiString aStr;
714 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveGroup(";
715 aStr += aGroupSO->GetID();
718 SMESH_Gen_i::AddToCurrentPyScript(aStr);
720 // Remove group's SObject
721 aStudy->NewBuilder()->RemoveObject( aGroupSO );
725 // Remove the group from SMESH data structures
726 removeGroup( aGroup->GetLocalID() );
729 //=============================================================================
730 /*! RemoveGroupWithContents
731 * Remove group with its contents
733 //=============================================================================
734 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
735 throw (SALOME::SALOME_Exception)
737 if ( theGroup->_is_nil() )
740 SMESH_GroupBase_i* aGroup =
741 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
745 SMESH::long_array_var anIds = aGroup->GetListOfID();
746 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
748 // Update Python script
749 TCollection_AsciiString aStr;
750 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveGroupWithContents(";
751 SMESH_Gen_i::AddObject(aStr, theGroup) += ")";
753 SMESH_Gen_i::AddToCurrentPyScript(aStr);
756 if ( aGroup->GetType() == SMESH::NODE )
757 aMeshEditor->RemoveNodes( anIds );
759 aMeshEditor->RemoveElements( anIds );
762 RemoveGroup( theGroup );
764 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
765 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
766 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
769 //=============================================================================
771 * New group is created. All mesh elements that are
772 * present in initial groups are added to the new one
774 //=============================================================================
775 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
776 SMESH::SMESH_GroupBase_ptr theGroup2,
777 const char* theName )
778 throw (SALOME::SALOME_Exception)
782 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
783 theGroup1->GetType() != theGroup2->GetType() )
784 return SMESH::SMESH_Group::_nil();
787 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
788 if ( aResGrp->_is_nil() )
789 return SMESH::SMESH_Group::_nil();
791 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
792 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
794 TColStd_MapOfInteger aResMap;
796 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
797 aResMap.Add( anIds1[ i1 ] );
799 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
800 aResMap.Add( anIds2[ i2 ] );
802 SMESH::long_array_var aResIds = new SMESH::long_array;
803 aResIds->length( aResMap.Extent() );
806 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
807 for( ; anIter.More(); anIter.Next() )
808 aResIds[ resI++ ] = anIter.Key();
810 aResGrp->Add( aResIds );
812 // Clear python lines, created by CreateGroup() and Add()
813 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
814 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
815 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
817 // Update Python script
818 TCollection_AsciiString aStr;
819 SMESH_Gen_i::AddObject(aStr, aResGrp) += " = ";
820 SMESH_Gen_i::AddObject(aStr, _this()) += ".UnionGroups(";
821 SMESH_Gen_i::AddObject(aStr, theGroup1) += ", ";
822 SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \"";
823 aStr += TCollection_AsciiString((char*)theName) + "\")";
825 SMESH_Gen_i::AddToCurrentPyScript(aStr);
827 return aResGrp._retn();
831 return SMESH::SMESH_Group::_nil();
835 //=============================================================================
837 * New group is created. All mesh elements that are
838 * present in both initial groups are added to the new one.
840 //=============================================================================
841 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
842 SMESH::SMESH_GroupBase_ptr theGroup2,
843 const char* theName )
844 throw (SALOME::SALOME_Exception)
846 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
847 theGroup1->GetType() != theGroup2->GetType() )
848 return SMESH::SMESH_Group::_nil();
850 // Create Intersection
851 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
852 if ( aResGrp->_is_nil() )
855 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
856 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
858 TColStd_MapOfInteger aMap1;
860 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
861 aMap1.Add( anIds1[ i1 ] );
863 TColStd_SequenceOfInteger aSeq;
865 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
866 if ( aMap1.Contains( anIds2[ i2 ] ) )
867 aSeq.Append( anIds2[ i2 ] );
869 SMESH::long_array_var aResIds = new SMESH::long_array;
870 aResIds->length( aSeq.Length() );
872 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
873 aResIds[ resI ] = aSeq( resI + 1 );
875 aResGrp->Add( aResIds );
877 // Clear python lines, created by CreateGroup() and Add()
878 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
879 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
880 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
882 // Update Python script
883 TCollection_AsciiString aStr;
884 SMESH_Gen_i::AddObject(aStr, aResGrp) += " = ";
885 SMESH_Gen_i::AddObject(aStr, _this()) += ".IntersectGroups(";
886 SMESH_Gen_i::AddObject(aStr, theGroup1) += ", ";
887 SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \"";
888 aStr += TCollection_AsciiString((char*)theName) + "\")";
890 SMESH_Gen_i::AddToCurrentPyScript(aStr);
892 return aResGrp._retn();
895 //=============================================================================
897 * New group is created. All mesh elements that are present in
898 * main group but do not present in tool group are added to the new one
900 //=============================================================================
901 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
902 SMESH::SMESH_GroupBase_ptr theGroup2,
903 const char* theName )
904 throw (SALOME::SALOME_Exception)
906 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
907 theGroup1->GetType() != theGroup2->GetType() )
908 return SMESH::SMESH_Group::_nil();
911 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
912 if ( aResGrp->_is_nil() )
915 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
916 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
918 TColStd_MapOfInteger aMap2;
920 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
921 aMap2.Add( anIds2[ i2 ] );
924 TColStd_SequenceOfInteger aSeq;
925 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
926 if ( !aMap2.Contains( anIds1[ i1 ] ) )
927 aSeq.Append( anIds1[ i1 ] );
929 SMESH::long_array_var aResIds = new SMESH::long_array;
930 aResIds->length( aSeq.Length() );
932 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
933 aResIds[ resI ] = aSeq( resI + 1 );
935 aResGrp->Add( aResIds );
937 // Clear python lines, created by CreateGroup() and Add()
938 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
939 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
940 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
942 // Update Python script
943 TCollection_AsciiString aStr;
944 SMESH_Gen_i::AddObject(aStr, aResGrp) += " = ";
945 SMESH_Gen_i::AddObject(aStr, _this()) += ".CutGroups(";
946 SMESH_Gen_i::AddObject(aStr, theGroup1) += ", ";
947 SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \"";
948 aStr += TCollection_AsciiString((char*)theName) + "\")";
950 SMESH_Gen_i::AddToCurrentPyScript(aStr);
952 return aResGrp._retn();
955 //=============================================================================
959 //=============================================================================
961 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
963 if(MYDEBUG) MESSAGE( "createSubMesh" );
964 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
966 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
967 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
968 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
969 SMESH::SMESH_subMesh_var subMesh
970 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
972 _mapSubMesh[subMeshId] = mySubMesh;
973 _mapSubMesh_i[subMeshId] = subMeshServant;
974 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
976 // register CORBA object for persistence
977 int nextId = _gen_i->RegisterObject( subMesh );
978 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
980 return subMesh._retn();
983 //=======================================================================
984 //function : getSubMesh
986 //=======================================================================
988 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
990 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
991 if ( it == _mapSubMeshIor.end() )
992 return SMESH::SMESH_subMesh::_nil();
994 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
998 //=============================================================================
1002 //=============================================================================
1004 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1005 GEOM::GEOM_Object_ptr theSubShapeObject )
1007 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1008 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1012 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1013 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1014 removeHypothesis( theSubShapeObject, aHypList[i] );
1017 catch( const SALOME::SALOME_Exception& ) {
1018 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1021 int subMeshId = theSubMesh->GetId();
1023 _mapSubMesh.erase(subMeshId);
1024 _mapSubMesh_i.erase(subMeshId);
1025 _mapSubMeshIor.erase(subMeshId);
1026 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1029 //=============================================================================
1033 //=============================================================================
1035 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1036 const char* theName,
1037 const TopoDS_Shape& theShape )
1040 SMESH::SMESH_GroupBase_var aGroup;
1041 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1042 SMESH_GroupBase_i* aGroupImpl;
1043 if ( !theShape.IsNull() )
1044 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1046 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1048 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1049 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1050 aGroupImpl->Register();
1051 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1053 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1054 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1056 // register CORBA object for persistence
1057 int nextId = _gen_i->RegisterObject( aGroup );
1058 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1060 return aGroup._retn();
1063 //=============================================================================
1065 * SMESH_Mesh_i::removeGroup
1067 * Should be called by ~SMESH_Group_i()
1069 //=============================================================================
1071 void SMESH_Mesh_i::removeGroup( const int theId )
1073 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1074 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1075 _mapGroups.erase( theId );
1076 _impl->RemoveGroup( theId );
1081 //=============================================================================
1085 //=============================================================================
1087 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1088 throw(SALOME::SALOME_Exception)
1090 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1092 SMESH::log_array_var aLog;
1094 list < SMESHDS_Command * >logDS = _impl->GetLog();
1095 aLog = new SMESH::log_array;
1097 int lg = logDS.size();
1100 list < SMESHDS_Command * >::iterator its = logDS.begin();
1101 while(its != logDS.end()){
1102 SMESHDS_Command *com = *its;
1103 int comType = com->GetType();
1105 int lgcom = com->GetNumber();
1107 const list < int >&intList = com->GetIndexes();
1108 int inum = intList.size();
1110 list < int >::const_iterator ii = intList.begin();
1111 const list < double >&coordList = com->GetCoords();
1112 int rnum = coordList.size();
1114 list < double >::const_iterator ir = coordList.begin();
1115 aLog[indexLog].commandType = comType;
1116 aLog[indexLog].number = lgcom;
1117 aLog[indexLog].coords.length(rnum);
1118 aLog[indexLog].indexes.length(inum);
1119 for(int i = 0; i < rnum; i++){
1120 aLog[indexLog].coords[i] = *ir;
1121 //MESSAGE(" "<<i<<" "<<ir.Value());
1124 for(int i = 0; i < inum; i++){
1125 aLog[indexLog].indexes[i] = *ii;
1126 //MESSAGE(" "<<i<<" "<<ii.Value());
1135 catch(SALOME_Exception & S_ex){
1136 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1138 return aLog._retn();
1142 //=============================================================================
1146 //=============================================================================
1148 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1150 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1154 //=============================================================================
1158 //=============================================================================
1160 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1162 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1166 //=============================================================================
1170 //=============================================================================
1172 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1177 //=============================================================================
1181 //=============================================================================
1183 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1185 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1189 //=============================================================================
1193 //=============================================================================
1195 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1197 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1202 //=============================================================================
1206 //=============================================================================
1208 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1210 // Update Python script
1211 TCollection_AsciiString aStr ("mesh_editor = ");
1212 SMESH_Gen_i::AddObject(aStr, _this()) += ".GetMeshEditor()";
1214 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1216 // Create MeshEditor
1217 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );
1218 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1219 return aMesh._retn();
1222 //=============================================================================
1224 * Export in different formats
1226 //=============================================================================
1228 void SMESH_Mesh_i::ExportToMED (const char* file,
1229 CORBA::Boolean auto_groups,
1230 SMESH::MED_VERSION theVersion)
1231 throw(SALOME::SALOME_Exception)
1233 Unexpect aCatch(SALOME_SalomeException);
1235 // Update Python script
1236 TCollection_AsciiString aStr;
1237 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportToMED(\"";
1238 aStr += TCollection_AsciiString((char*)file) + "\", ";
1239 aStr += TCollection_AsciiString((int)auto_groups) + ", ";
1240 switch (theVersion) {
1241 case SMESH::MED_V2_1:
1242 aStr += "SMESH.MED_V2_1)";
1244 case SMESH::MED_V2_2:
1245 aStr += "SMESH.MED_V2_2)";
1248 aStr += TCollection_AsciiString(theVersion) + ")";
1252 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1255 char* aMeshName = "Mesh";
1256 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1257 if ( !aStudy->_is_nil() ) {
1258 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1259 if ( !aMeshSO->_is_nil() ) {
1260 aMeshName = aMeshSO->GetName();
1262 //SCRUTE(aMeshName);
1263 //SCRUTE(aMeshSO->GetID());
1265 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1266 if ( !aStudy->GetProperties()->IsLocked() )
1268 SALOMEDS::GenericAttribute_var anAttr;
1269 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1270 SALOMEDS::AttributeExternalFileDef_var aFileName;
1271 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1272 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1273 ASSERT(!aFileName->_is_nil());
1274 aFileName->SetValue(file);
1275 SALOMEDS::AttributeFileType_var aFileType;
1276 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1277 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1278 ASSERT(!aFileType->_is_nil());
1279 aFileType->SetValue("FICHIERMED");
1283 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1286 void SMESH_Mesh_i::ExportMED (const char* file,
1287 CORBA::Boolean auto_groups)
1288 throw(SALOME::SALOME_Exception)
1290 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1293 void SMESH_Mesh_i::ExportDAT (const char *file)
1294 throw(SALOME::SALOME_Exception)
1296 Unexpect aCatch(SALOME_SalomeException);
1298 // Update Python script
1299 TCollection_AsciiString aStr;
1300 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportDAT(\"";
1301 aStr += TCollection_AsciiString((char*)file) + "\")";
1303 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1306 _impl->ExportDAT(file);
1309 void SMESH_Mesh_i::ExportUNV (const char *file)
1310 throw(SALOME::SALOME_Exception)
1312 Unexpect aCatch(SALOME_SalomeException);
1314 // Update Python script
1315 TCollection_AsciiString aStr;
1316 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportUNV(\"";
1317 aStr += TCollection_AsciiString((char*)file) + "\")";
1319 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1322 _impl->ExportUNV(file);
1325 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1326 throw(SALOME::SALOME_Exception)
1328 Unexpect aCatch(SALOME_SalomeException);
1330 // Update Python script
1331 TCollection_AsciiString aStr;
1332 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportToMED(\"";
1333 aStr += TCollection_AsciiString((char*)file) + "\", ";
1334 aStr += TCollection_AsciiString((int)isascii) + ")";
1336 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1339 _impl->ExportSTL(file, isascii);
1342 //=============================================================================
1346 //=============================================================================
1348 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1350 Unexpect aCatch(SALOME_SalomeException);
1351 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1352 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1353 return aMesh._retn();
1356 //=============================================================================
1360 //=============================================================================
1361 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1363 Unexpect aCatch(SALOME_SalomeException);
1364 return _impl->NbNodes();
1367 //=============================================================================
1371 //=============================================================================
1372 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1374 Unexpect aCatch(SALOME_SalomeException);
1375 return NbEdges() + NbFaces() + NbVolumes();
1378 //=============================================================================
1382 //=============================================================================
1383 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1385 Unexpect aCatch(SALOME_SalomeException);
1386 return _impl->NbEdges();
1389 //=============================================================================
1393 //=============================================================================
1394 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1396 Unexpect aCatch(SALOME_SalomeException);
1397 return _impl->NbFaces();
1400 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1402 Unexpect aCatch(SALOME_SalomeException);
1403 return _impl->NbTriangles();
1406 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1408 Unexpect aCatch(SALOME_SalomeException);
1409 return _impl->NbQuadrangles();
1412 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1414 Unexpect aCatch(SALOME_SalomeException);
1415 return _impl->NbPolygons();
1418 //=============================================================================
1422 //=============================================================================
1423 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1425 Unexpect aCatch(SALOME_SalomeException);
1426 return _impl->NbVolumes();
1429 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1431 Unexpect aCatch(SALOME_SalomeException);
1432 return _impl->NbTetras();
1435 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1437 Unexpect aCatch(SALOME_SalomeException);
1438 return _impl->NbHexas();
1441 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1443 Unexpect aCatch(SALOME_SalomeException);
1444 return _impl->NbPyramids();
1447 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1449 Unexpect aCatch(SALOME_SalomeException);
1450 return _impl->NbPrisms();
1453 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1455 Unexpect aCatch(SALOME_SalomeException);
1456 return _impl->NbPolyhedrons();
1459 //=============================================================================
1463 //=============================================================================
1464 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1466 Unexpect aCatch(SALOME_SalomeException);
1467 return _impl->NbSubMesh();
1470 //=============================================================================
1474 //=============================================================================
1475 char* SMESH_Mesh_i::Dump()
1477 std::ostringstream os;
1479 return CORBA::string_dup( os.str().c_str() );
1482 //=============================================================================
1486 //=============================================================================
1487 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1489 SMESH::long_array_var aResult = new SMESH::long_array();
1490 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1491 int aMinId = aSMESHDS_Mesh->MinElementID();
1492 int aMaxId = aSMESHDS_Mesh->MaxElementID();
1494 aResult->length(aMaxId - aMinId + 1);
1496 for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1499 return aResult._retn();
1502 //=============================================================================
1506 //=============================================================================
1508 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1509 throw (SALOME::SALOME_Exception)
1511 Unexpect aCatch(SALOME_SalomeException);
1512 MESSAGE("SMESH_Mesh_i::GetElementsId");
1513 SMESH::long_array_var aResult = new SMESH::long_array();
1514 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1516 if ( aSMESHDS_Mesh == NULL )
1517 return aResult._retn();
1519 long nbElements = NbElements();
1520 aResult->length( nbElements );
1521 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1522 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1523 aResult[i] = anIt->next()->GetID();
1525 return aResult._retn();
1529 //=============================================================================
1533 //=============================================================================
1535 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1536 throw (SALOME::SALOME_Exception)
1538 Unexpect aCatch(SALOME_SalomeException);
1539 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1540 SMESH::long_array_var aResult = new SMESH::long_array();
1541 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1543 if ( aSMESHDS_Mesh == NULL )
1544 return aResult._retn();
1546 long nbElements = NbElements();
1548 // No sense in returning ids of elements along with ids of nodes:
1549 // when theElemType == SMESH::ALL, return node ids only if
1550 // there are no elements
1551 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1552 return GetNodesId();
1554 aResult->length( nbElements );
1558 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1559 while ( i < nbElements && anIt->more() ) {
1560 const SMDS_MeshElement* anElem = anIt->next();
1561 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1562 aResult[i++] = anElem->GetID();
1565 aResult->length( i );
1567 return aResult._retn();
1570 //=============================================================================
1574 //=============================================================================
1576 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1577 throw (SALOME::SALOME_Exception)
1579 Unexpect aCatch(SALOME_SalomeException);
1580 MESSAGE("SMESH_subMesh_i::GetNodesId");
1581 SMESH::long_array_var aResult = new SMESH::long_array();
1582 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1584 if ( aSMESHDS_Mesh == NULL )
1585 return aResult._retn();
1587 long nbNodes = NbNodes();
1588 aResult->length( nbNodes );
1589 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1590 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1591 aResult[i] = anIt->next()->GetID();
1593 return aResult._retn();
1597 //=============================================================================
1601 //=============================================================================
1603 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1604 throw (SALOME::SALOME_Exception)
1606 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );