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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Mesh_i.cxx
25 // Author : Paul RASCLE, EDF
29 #include "SMESH_Mesh_i.hxx"
31 #include "SMESH_Filter_i.hxx"
32 #include "SMESH_Gen_i.hxx"
33 #include "SMESH_Group_i.hxx"
34 #include "SMESH_MEDMesh_i.hxx"
35 #include "SMESH_MeshEditor_i.hxx"
36 #include "SMESH_PythonDump.hxx"
37 #include "SMESH_subMesh_i.hxx"
39 #include "DriverMED_R_SMESHDS_Mesh.h"
40 #include "DriverMED_W_SMESHDS_Mesh.h"
41 #include "SMDS_VolumeTool.hxx"
42 #include "SMESHDS_Command.hxx"
43 #include "SMESHDS_CommandType.hxx"
44 #include "SMESHDS_GroupOnGeom.hxx"
45 #include "SMESH_Group.hxx"
46 #include "SMESH_MeshEditor.hxx"
47 #include "SMESH_MesherHelper.hxx"
48 #include "SMDS_EdgePosition.hxx"
49 #include "SMDS_FacePosition.hxx"
52 #include "SALOME_NamingService.hxx"
53 #include "Utils_CorbaException.hxx"
54 #include "Utils_ExceptHandlers.hxx"
55 #include "Utils_SINGLETON.hxx"
56 #include "utilities.h"
59 #include <BRep_Builder.hxx>
60 #include <OSD_Directory.hxx>
61 #include <OSD_File.hxx>
62 #include <OSD_Path.hxx>
63 #include <OSD_Protection.hxx>
64 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
65 #include <TColStd_MapOfInteger.hxx>
66 #include <TColStd_SequenceOfInteger.hxx>
67 #include <TCollection_AsciiString.hxx>
68 #include <TopExp_Explorer.hxx>
69 #include <TopoDS_Compound.hxx>
78 static int MYDEBUG = 0;
80 static int MYDEBUG = 0;
84 using SMESH::TPythonDump;
86 int SMESH_Mesh_i::myIdGenerator = 0;
90 //=============================================================================
94 //=============================================================================
96 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
99 : SALOME::GenericObj_i( thePOA )
101 MESSAGE("SMESH_Mesh_i");
104 _id = myIdGenerator++;
108 //=============================================================================
112 //=============================================================================
114 SMESH_Mesh_i::~SMESH_Mesh_i()
116 INFOS("~SMESH_Mesh_i");
117 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
118 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
119 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
121 // this method is colled from destructor of group (PAL6331)
122 //_impl->RemoveGroup( aGroup->GetLocalID() );
131 //=============================================================================
135 * Associates <this> mesh with <theShape> and puts a reference
136 * to <theShape> into the current study;
137 * the previous shape is substituted by the new one.
139 //=============================================================================
141 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
142 throw (SALOME::SALOME_Exception)
144 Unexpect aCatch(SALOME_SalomeException);
146 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
148 catch(SALOME_Exception & S_ex) {
149 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
153 //================================================================================
155 * \brief return true if mesh has a shape to build a shape on
157 //================================================================================
159 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
160 throw (SALOME::SALOME_Exception)
162 Unexpect aCatch(SALOME_SalomeException);
165 res = _impl->HasShapeToMesh();
167 catch(SALOME_Exception & S_ex) {
168 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
173 //=======================================================================
174 //function : GetShapeToMesh
176 //=======================================================================
178 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
179 throw (SALOME::SALOME_Exception)
181 Unexpect aCatch(SALOME_SalomeException);
182 GEOM::GEOM_Object_var aShapeObj;
184 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
186 aShapeObj = _gen_i->ShapeToGeomObject( S );
188 catch(SALOME_Exception & S_ex) {
189 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
191 return aShapeObj._retn();
194 //================================================================================
196 * \brief Remove all nodes and elements
198 //================================================================================
200 void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
202 Unexpect aCatch(SALOME_SalomeException);
206 catch(SALOME_Exception & S_ex) {
207 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
209 TPythonDump() << _this() << ".Clear()";
212 //=============================================================================
216 //=============================================================================
218 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
220 SMESH::DriverMED_ReadStatus res;
223 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
224 res = SMESH::DRS_OK; break;
225 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
226 res = SMESH::DRS_EMPTY; break;
227 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
228 res = SMESH::DRS_WARN_RENUMBER; break;
229 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
230 res = SMESH::DRS_WARN_SKIP_ELEM; break;
231 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
233 res = SMESH::DRS_FAIL; break;
238 //=============================================================================
242 * Imports mesh data from MED file
244 //=============================================================================
246 SMESH::DriverMED_ReadStatus
247 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
248 throw ( SALOME::SALOME_Exception )
250 Unexpect aCatch(SALOME_SalomeException);
253 status = _impl->MEDToMesh( theFileName, theMeshName );
255 catch( SALOME_Exception& S_ex ) {
256 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
259 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
262 CreateGroupServants();
264 int major, minor, release;
265 if( !MED::getMEDVersion( theFileName, major, minor, release ) )
266 major = minor = release = -1;
267 myFileInfo = new SALOME_MED::MedFileInfo();
268 myFileInfo->fileName = theFileName;
269 myFileInfo->fileSize = 0;
272 if ( ::_stati64( theFileName, &d ) != -1 )
275 if ( ::stat64( theFileName, &d ) != -1 )
277 myFileInfo->fileSize = d.st_size;
278 myFileInfo->major = major;
279 myFileInfo->minor = minor;
280 myFileInfo->release = release;
282 return ConvertDriverMEDReadStatus(status);
285 //================================================================================
287 * \brief Return string representation of a MED file version comprising nbDigits
289 //================================================================================
291 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
293 std::string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
295 return CORBA::string_dup( ver.c_str() );
298 //=============================================================================
302 * Imports mesh data from MED file
304 //=============================================================================
306 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
307 throw ( SALOME::SALOME_Exception )
309 // Read mesh with name = <theMeshName> into SMESH_Mesh
310 _impl->UNVToMesh( theFileName );
312 CreateGroupServants();
317 //=============================================================================
321 * Imports mesh data from STL file
323 //=============================================================================
324 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
325 throw ( SALOME::SALOME_Exception )
327 // Read mesh with name = <theMeshName> into SMESH_Mesh
328 _impl->STLToMesh( theFileName );
333 //=============================================================================
337 * Imports mesh data from MED file
339 //=============================================================================
341 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
343 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
344 // int status = _impl->MEDToMesh( theFileName, theMeshName );
345 // CreateGroupServants();
350 //=============================================================================
354 //=============================================================================
356 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
358 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
359 (SMESH_Hypothesis::Hypothesis_Status theStatus)
362 RETURNCASE( HYP_OK );
363 RETURNCASE( HYP_MISSING );
364 RETURNCASE( HYP_CONCURENT );
365 RETURNCASE( HYP_BAD_PARAMETER );
366 RETURNCASE( HYP_HIDDEN_ALGO );
367 RETURNCASE( HYP_HIDING_ALGO );
368 RETURNCASE( HYP_UNKNOWN_FATAL );
369 RETURNCASE( HYP_INCOMPATIBLE );
370 RETURNCASE( HYP_NOTCONFORM );
371 RETURNCASE( HYP_ALREADY_EXIST );
372 RETURNCASE( HYP_BAD_DIM );
373 RETURNCASE( HYP_BAD_SUBSHAPE );
374 RETURNCASE( HYP_BAD_GEOMETRY );
375 RETURNCASE( HYP_NEED_SHAPE );
378 return SMESH::HYP_UNKNOWN_FATAL;
381 //=============================================================================
385 * calls internal addHypothesis() and then adds a reference to <anHyp> under
386 * the SObject actually having a reference to <aSubShape>.
387 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
389 //=============================================================================
391 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
392 SMESH::SMESH_Hypothesis_ptr anHyp)
393 throw(SALOME::SALOME_Exception)
395 Unexpect aCatch(SALOME_SalomeException);
396 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
398 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
399 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
400 aSubShapeObject, anHyp );
402 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
404 // Update Python script
405 if(_impl->HasShapeToMesh()) {
406 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
407 << aSubShapeObject << ", " << anHyp << " )";
410 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
413 return ConvertHypothesisStatus(status);
416 //=============================================================================
420 //=============================================================================
422 SMESH_Hypothesis::Hypothesis_Status
423 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
424 SMESH::SMESH_Hypothesis_ptr anHyp)
426 if(MYDEBUG) MESSAGE("addHypothesis");
428 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
429 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
432 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
433 if (CORBA::is_nil(myHyp))
434 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
437 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
440 TopoDS_Shape myLocSubShape;
441 //use PseudoShape in case if mesh has no shape
443 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
445 myLocSubShape = _impl->GetShapeToMesh();
447 int hypId = myHyp->GetId();
448 status = _impl->AddHypothesis(myLocSubShape, hypId);
449 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
450 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
451 // assure there is a corresponding submesh
452 if ( !_impl->IsMainShape( myLocSubShape )) {
453 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
454 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
455 createSubMesh( aSubShapeObject );
459 catch(SALOME_Exception & S_ex)
461 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
466 //=============================================================================
470 //=============================================================================
472 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
473 SMESH::SMESH_Hypothesis_ptr anHyp)
474 throw(SALOME::SALOME_Exception)
476 Unexpect aCatch(SALOME_SalomeException);
477 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
479 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
480 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
481 aSubShapeObject, anHyp );
483 // Update Python script
484 // Update Python script
485 if(_impl->HasShapeToMesh()) {
486 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
487 << aSubShapeObject << ", " << anHyp << " )";
490 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
494 return ConvertHypothesisStatus(status);
497 //=============================================================================
501 //=============================================================================
503 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
504 SMESH::SMESH_Hypothesis_ptr anHyp)
506 if(MYDEBUG) MESSAGE("removeHypothesis()");
507 // **** proposer liste de subShape (selection multiple)
509 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
510 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
513 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
514 if (CORBA::is_nil(myHyp))
515 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
518 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
521 TopoDS_Shape myLocSubShape;
522 //use PseudoShape in case if mesh has no shape
524 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
526 myLocSubShape = _impl->GetShapeToMesh();
528 int hypId = myHyp->GetId();
529 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
530 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
531 _mapHypo.erase( hypId );
533 catch(SALOME_Exception & S_ex)
535 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
540 //=============================================================================
544 //=============================================================================
546 SMESH::ListOfHypothesis *
547 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
548 throw(SALOME::SALOME_Exception)
550 Unexpect aCatch(SALOME_SalomeException);
551 if (MYDEBUG) MESSAGE("GetHypothesisList");
552 if (CORBA::is_nil(aSubShapeObject))
553 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
556 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
559 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
560 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
561 int i = 0, n = aLocalList.size();
564 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
565 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
566 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
567 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
572 catch(SALOME_Exception & S_ex) {
573 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
576 return aList._retn();
579 //=============================================================================
583 //=============================================================================
584 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
585 const char* theName )
586 throw(SALOME::SALOME_Exception)
588 Unexpect aCatch(SALOME_SalomeException);
589 MESSAGE("SMESH_Mesh_i::GetSubMesh");
590 if (CORBA::is_nil(aSubShapeObject))
591 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
594 SMESH::SMESH_subMesh_var subMesh;
595 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
597 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
599 //Get or Create the SMESH_subMesh object implementation
601 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
602 subMesh = getSubMesh( subMeshId );
604 // create a new subMesh object servant if there is none for the shape
605 if ( subMesh->_is_nil() )
606 subMesh = createSubMesh( aSubShapeObject );
608 if ( _gen_i->CanPublishInStudy( subMesh )) {
609 SALOMEDS::SObject_var aSO =
610 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
611 subMesh, aSubShapeObject, theName );
612 if ( !aSO->_is_nil()) {
613 // Update Python script
614 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
615 << aSubShapeObject << ", '" << theName << "' )";
619 catch(SALOME_Exception & S_ex) {
620 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
622 return subMesh._retn();
625 //=============================================================================
629 //=============================================================================
631 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
632 throw (SALOME::SALOME_Exception)
634 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
635 if ( theSubMesh->_is_nil() )
638 GEOM::GEOM_Object_var aSubShapeObject;
639 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
640 if ( !aStudy->_is_nil() ) {
641 // Remove submesh's SObject
642 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
643 if ( !anSO->_is_nil() ) {
644 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
645 SALOMEDS::SObject_var anObj, aRef;
646 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
647 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
649 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
651 // Update Python script
652 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
656 removeSubMesh( theSubMesh, aSubShapeObject.in() );
659 //=============================================================================
663 //=============================================================================
664 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
665 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
667 switch (theElemType) {
672 CASE2STRING( VOLUME );
678 //=============================================================================
682 //=============================================================================
684 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
685 const char* theName )
686 throw(SALOME::SALOME_Exception)
688 Unexpect aCatch(SALOME_SalomeException);
689 SMESH::SMESH_Group_var aNewGroup =
690 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
692 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
693 SALOMEDS::SObject_var aSO =
694 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
695 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
696 if ( !aSO->_is_nil()) {
697 // Update Python script
698 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
699 << ElementTypeString(theElemType) << ", '" << theName << "' )";
702 return aNewGroup._retn();
706 //=============================================================================
710 //=============================================================================
711 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
713 GEOM::GEOM_Object_ptr theGeomObj)
714 throw(SALOME::SALOME_Exception)
716 Unexpect aCatch(SALOME_SalomeException);
717 SMESH::SMESH_GroupOnGeom_var aNewGroup;
719 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
720 if ( !aShape.IsNull() ) {
721 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
722 ( createGroup( theElemType, theName, aShape ));
723 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
724 SALOMEDS::SObject_var aSO =
725 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
726 aNewGroup, theGeomObj, theName);
727 if ( !aSO->_is_nil()) {
728 // Update Python script
729 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
730 << ElementTypeString(theElemType) << ", '" << theName << "', "
731 << theGeomObj << " )";
736 return aNewGroup._retn();
739 //=============================================================================
743 //=============================================================================
745 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
746 throw (SALOME::SALOME_Exception)
748 if ( theGroup->_is_nil() )
751 SMESH_GroupBase_i* aGroup =
752 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
756 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
757 if ( !aStudy->_is_nil() ) {
758 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
760 if ( !aGroupSO->_is_nil() ) {
761 // Update Python script
762 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
764 // Remove group's SObject
765 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
769 // Remove the group from SMESH data structures
770 removeGroup( aGroup->GetLocalID() );
773 //=============================================================================
774 /*! RemoveGroupWithContents
775 * Remove group with its contents
777 //=============================================================================
778 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
779 throw (SALOME::SALOME_Exception)
781 if ( theGroup->_is_nil() )
784 SMESH_GroupBase_i* aGroup =
785 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
789 SMESH::long_array_var anIds = aGroup->GetListOfID();
790 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
792 // Update Python script
793 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
796 if ( aGroup->GetType() == SMESH::NODE )
797 aMeshEditor->RemoveNodes( anIds );
799 aMeshEditor->RemoveElements( anIds );
802 RemoveGroup( theGroup );
804 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
805 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
806 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
810 //================================================================================
812 * \brief Get the list of groups existing in the mesh
813 * \retval SMESH::ListOfGroups * - list of groups
815 //================================================================================
817 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
819 Unexpect aCatch(SALOME_SalomeException);
820 if (MYDEBUG) MESSAGE("GetGroups");
822 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
825 TPythonDump aPythonDump;
826 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
830 aList->length( _mapGroups.size() );
832 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
833 for ( ; it != _mapGroups.end(); it++ ) {
834 if ( CORBA::is_nil( it->second )) continue;
835 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
837 if (i > 1) aPythonDump << ", ";
838 aPythonDump << it->second;
842 catch(SALOME_Exception & S_ex) {
843 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
846 // Update Python script
847 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
848 aPythonDump << " ] = " << _this() << ".GetGroups()";
850 return aList._retn();
852 //=============================================================================
854 * Get number of groups existing in the mesh
856 //=============================================================================
858 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
860 Unexpect aCatch(SALOME_SalomeException);
861 return _mapGroups.size();
864 //=============================================================================
866 * New group is created. All mesh elements that are
867 * present in initial groups are added to the new one
869 //=============================================================================
870 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
871 SMESH::SMESH_GroupBase_ptr theGroup2,
872 const char* theName )
873 throw (SALOME::SALOME_Exception)
877 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
878 theGroup1->GetType() != theGroup2->GetType() )
879 return SMESH::SMESH_Group::_nil();
882 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
883 if ( aResGrp->_is_nil() )
884 return SMESH::SMESH_Group::_nil();
886 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
887 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
889 TColStd_MapOfInteger aResMap;
891 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
892 aResMap.Add( anIds1[ i1 ] );
894 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
895 aResMap.Add( anIds2[ i2 ] );
897 SMESH::long_array_var aResIds = new SMESH::long_array;
898 aResIds->length( aResMap.Extent() );
901 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
902 for( ; anIter.More(); anIter.Next() )
903 aResIds[ resI++ ] = anIter.Key();
905 aResGrp->Add( aResIds );
907 // Clear python lines, created by CreateGroup() and Add()
908 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
909 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
910 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
912 // Update Python script
913 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
914 << theGroup1 << ", " << theGroup2 << ", '"
917 return aResGrp._retn();
921 return SMESH::SMESH_Group::_nil();
925 //=============================================================================
927 \brief Union list of groups. New group is created. All mesh elements that are
928 present in initial groups are added to the new one.
929 \param theGroups list of groups
930 \param theName name of group to be created
931 \return pointer on the group
933 //=============================================================================
934 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionListOfGroups(
935 const SMESH::ListOfGroups& theGroups, const char* theName )
936 throw (SALOME::SALOME_Exception)
939 return SMESH::SMESH_Group::_nil();
943 NCollection_Map< int > anIds;
944 SMESH::ElementType aType = SMESH::ALL;
945 for ( int g = 0, n = theGroups.length(); g < n; g++ )
947 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
948 if ( CORBA::is_nil( aGrp ) )
952 SMESH::ElementType aCurrType = aGrp->GetType();
953 if ( aType == SMESH::ALL )
957 if ( aType != aCurrType )
958 return SMESH::SMESH_Group::_nil();
962 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
963 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
965 int aCurrId = aCurrIds[ i ];
966 anIds.Add( aCurrId );
971 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
972 if ( aResGrp->_is_nil() )
973 return SMESH::SMESH_Group::_nil();
975 // Create array of identifiers
976 SMESH::long_array_var aResIds = new SMESH::long_array;
977 aResIds->length( anIds.Extent() );
979 NCollection_Map< int >::Iterator anIter( anIds );
980 for ( int i = 0; anIter.More(); anIter.Next(), i++ )
982 aResIds[ i ] = anIter.Value();
984 aResGrp->Add( aResIds );
986 // Clear python lines, created by CreateGroup() and Add()
987 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
988 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
989 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
991 // Update Python script
993 TPythonDump() << aResGrp << " = " << _this() << ".UnionListOfGroups( "
994 << &theGroups << ", '" << theName << "' )";
996 return aResGrp._retn();
1000 return SMESH::SMESH_Group::_nil();
1004 //=============================================================================
1006 * New group is created. All mesh elements that are
1007 * present in both initial groups are added to the new one.
1009 //=============================================================================
1010 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1011 SMESH::SMESH_GroupBase_ptr theGroup2,
1012 const char* theName )
1013 throw (SALOME::SALOME_Exception)
1015 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
1016 theGroup1->GetType() != theGroup2->GetType() )
1017 return SMESH::SMESH_Group::_nil();
1019 // Create Intersection
1020 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
1021 if ( aResGrp->_is_nil() )
1024 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1025 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1027 TColStd_MapOfInteger aMap1;
1029 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1030 aMap1.Add( anIds1[ i1 ] );
1032 TColStd_SequenceOfInteger aSeq;
1034 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1035 if ( aMap1.Contains( anIds2[ i2 ] ) )
1036 aSeq.Append( anIds2[ i2 ] );
1038 SMESH::long_array_var aResIds = new SMESH::long_array;
1039 aResIds->length( aSeq.Length() );
1041 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1042 aResIds[ resI ] = aSeq( resI + 1 );
1044 aResGrp->Add( aResIds );
1046 // Clear python lines, created by CreateGroup() and Add()
1047 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1048 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1049 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1051 // Update Python script
1052 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
1053 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
1055 return aResGrp._retn();
1058 //=============================================================================
1060 \brief Intersect list of groups. New group is created. All mesh elements that
1061 are present in all initial groups simultaneously are added to the new one.
1062 \param theGroups list of groups
1063 \param theName name of group to be created
1064 \return pointer on the group
1066 //=============================================================================
1067 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectListOfGroups(
1068 const SMESH::ListOfGroups& theGroups, const char* theName )
1069 throw (SALOME::SALOME_Exception)
1072 return SMESH::SMESH_Group::_nil();
1076 NCollection_DataMap< int, int > anIdToCount;
1077 SMESH::ElementType aType = SMESH::ALL;
1078 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1080 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1081 if ( CORBA::is_nil( aGrp ) )
1085 SMESH::ElementType aCurrType = aGrp->GetType();
1086 if ( aType == SMESH::ALL )
1090 if ( aType != aCurrType )
1091 return SMESH::SMESH_Group::_nil();
1094 // calculates number of occurance ids in groups
1095 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1096 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1098 int aCurrId = aCurrIds[ i ];
1099 if ( !anIdToCount.IsBound( aCurrId ) )
1100 anIdToCount.Bind( aCurrId, 1 );
1102 anIdToCount( aCurrId ) = anIdToCount( aCurrId ) + 1;
1106 // create map of ids
1107 int nbGrp = theGroups.length();
1108 NCollection_Map< int > anIds;
1109 NCollection_DataMap< int, int >::Iterator anIter( anIdToCount );
1110 for ( ; anIter.More(); anIter.Next() )
1112 int aCurrId = anIter.Key();
1113 int aCurrNb = anIter.Value();
1114 if ( aCurrNb == nbGrp )
1115 anIds.Add( aCurrId );
1119 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
1120 if ( aResGrp->_is_nil() )
1121 return SMESH::SMESH_Group::_nil();
1123 // Create array of identifiers
1124 SMESH::long_array_var aResIds = new SMESH::long_array;
1125 aResIds->length( anIds.Extent() );
1127 NCollection_Map< int >::Iterator aListIter( anIds );
1128 for ( int i = 0; aListIter.More(); aListIter.Next(), i++ )
1130 aResIds[ i ] = aListIter.Value();
1132 aResGrp->Add( aResIds );
1134 // Clear python lines, created by CreateGroup() and Add()
1135 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1136 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1137 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1139 // Update Python script
1141 TPythonDump() << aResGrp << " = " << _this() << ".IntersectListOfGroups( "
1142 << &theGroups << ", '" << theName << "' )";
1144 return aResGrp._retn();
1148 return SMESH::SMESH_Group::_nil();
1152 //=============================================================================
1154 * New group is created. All mesh elements that are present in
1155 * main group but do not present in tool group are added to the new one
1157 //=============================================================================
1158 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1159 SMESH::SMESH_GroupBase_ptr theGroup2,
1160 const char* theName )
1161 throw (SALOME::SALOME_Exception)
1163 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
1164 theGroup1->GetType() != theGroup2->GetType() )
1165 return SMESH::SMESH_Group::_nil();
1168 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
1169 if ( aResGrp->_is_nil() )
1172 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1173 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1175 TColStd_MapOfInteger aMap2;
1177 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1178 aMap2.Add( anIds2[ i2 ] );
1180 TColStd_SequenceOfInteger aSeq;
1181 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1182 if ( !aMap2.Contains( anIds1[ i1 ] ) )
1183 aSeq.Append( anIds1[ i1 ] );
1185 SMESH::long_array_var aResIds = new SMESH::long_array;
1186 aResIds->length( aSeq.Length() );
1188 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1189 aResIds[ resI ] = aSeq( resI + 1 );
1191 aResGrp->Add( aResIds );
1193 // Clear python lines, created by CreateGroup() and Add()
1194 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1195 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1196 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1198 // Update Python script
1199 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1200 << theGroup1 << ", " << theGroup2 << ", '"
1201 << theName << "' )";
1203 return aResGrp._retn();
1206 //=============================================================================
1208 \brief Cut lists of groups. New group is created. All mesh elements that are
1209 present in main groups but do not present in tool groups are added to the new one
1210 \param theMainGroups list of main groups
1211 \param theToolGroups list of tool groups
1212 \param theName name of group to be created
1213 \return pointer on the group
1215 //=============================================================================
1216 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutListOfGroups(
1217 const SMESH::ListOfGroups& theMainGroups,
1218 const SMESH::ListOfGroups& theToolGroups,
1219 const char* theName )
1220 throw (SALOME::SALOME_Exception)
1223 return SMESH::SMESH_Group::_nil();
1227 NCollection_Map< int > aToolIds;
1228 SMESH::ElementType aType = SMESH::ALL;
1230 // iterate through tool groups
1231 for ( g = 0, n = theToolGroups.length(); g < n; g++ )
1233 SMESH::SMESH_GroupBase_var aGrp = theToolGroups[ g ];
1234 if ( CORBA::is_nil( aGrp ) )
1238 SMESH::ElementType aCurrType = aGrp->GetType();
1239 if ( aType == SMESH::ALL )
1243 if ( aType != aCurrType )
1244 return SMESH::SMESH_Group::_nil();
1248 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1249 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1251 int aCurrId = aCurrIds[ i ];
1252 aToolIds.Add( aCurrId );
1256 NCollection_Map< int > anIds; // result
1258 // Iterate through main group
1259 for ( g = 0, n = theMainGroups.length(); g < n; g++ )
1261 SMESH::SMESH_GroupBase_var aGrp = theMainGroups[ g ];
1262 if ( CORBA::is_nil( aGrp ) )
1266 SMESH::ElementType aCurrType = aGrp->GetType();
1267 if ( aType == SMESH::ALL )
1271 if ( aType != aCurrType )
1272 return SMESH::SMESH_Group::_nil();
1276 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1277 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1279 int aCurrId = aCurrIds[ i ];
1280 if ( !aToolIds.Contains( aCurrId ) )
1281 anIds.Add( aCurrId );
1286 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
1287 if ( aResGrp->_is_nil() )
1288 return SMESH::SMESH_Group::_nil();
1290 // Create array of identifiers
1291 SMESH::long_array_var aResIds = new SMESH::long_array;
1292 aResIds->length( anIds.Extent() );
1294 NCollection_Map< int >::Iterator anIter( anIds );
1295 for ( int i = 0; anIter.More(); anIter.Next(), i++ )
1297 aResIds[ i ] = anIter.Value();
1299 aResGrp->Add( aResIds );
1301 // Clear python lines, created by CreateGroup() and Add()
1302 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1303 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1304 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1306 // Update Python script
1308 TPythonDump() << aResGrp << " = " << _this() << ".CutListOfGroups( "
1309 << &theMainGroups << ", " << &theToolGroups << ", '"
1310 << theName << "' )";
1312 return aResGrp._retn();
1316 return SMESH::SMESH_Group::_nil();
1320 //=============================================================================
1322 \brief Create groups of entities from existing groups of superior dimensions
1324 1) extract all nodes from each group,
1325 2) combine all elements of specified dimension laying on these nodes.
1326 \param theGroups list of source groups
1327 \param theElemType dimension of elements
1328 \param theName name of new group
1329 \return pointer on new group
1331 //=============================================================================
1332 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateDimGroup(
1333 const SMESH::ListOfGroups& theGroups,
1334 SMESH::ElementType theElemType,
1335 const char* theName )
1336 throw (SALOME::SALOME_Exception)
1338 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
1340 if ( !theName || !aMeshDS )
1341 return SMESH::SMESH_Group::_nil();
1343 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)theElemType;
1347 // Create map of nodes from all groups
1349 NCollection_Map< int > aNodeMap;
1351 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1353 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1354 if ( CORBA::is_nil( aGrp ) )
1357 SMESH::ElementType aType = aGrp->GetType();
1358 if ( aType == SMESH::ALL )
1360 else if ( aType == SMESH::NODE )
1362 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1363 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1365 int aCurrId = aCurrIds[ i ];
1366 const SMDS_MeshNode* aNode = aMeshDS->FindNode( aCurrId );
1368 aNodeMap.Add( aNode->GetID() );
1373 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1374 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1376 int aCurrId = aCurrIds[ i ];
1377 const SMDS_MeshElement* anElem = aMeshDS->FindElement( aCurrId );
1380 SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
1381 while( aNodeIter->more() )
1383 const SMDS_MeshNode* aNode =
1384 dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
1386 aNodeMap.Add( aNode->GetID() );
1392 // Get result identifiers
1394 NCollection_Map< int > aResultIds;
1395 if ( theElemType == SMESH::NODE )
1397 NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
1398 for ( ; aNodeIter.More(); aNodeIter.Next() )
1399 aResultIds.Add( aNodeIter.Value() );
1403 // Create list of elements of given dimension constructed on the nodes
1404 NCollection_Map< int > anElemList;
1405 NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
1406 for ( ; aNodeIter.More(); aNodeIter.Next() )
1408 const SMDS_MeshElement* aNode =
1409 dynamic_cast<const SMDS_MeshElement*>( aMeshDS->FindNode( aNodeIter.Value() ) );
1413 SMDS_ElemIteratorPtr anElemIter = aNode->elementsIterator( anElemType );
1414 while( anElemIter->more() )
1416 const SMDS_MeshElement* anElem =
1417 dynamic_cast<const SMDS_MeshElement*>( anElemIter->next() );
1418 if ( anElem && anElem->GetType() == anElemType )
1419 anElemList.Add( anElem->GetID() );
1423 // check whether all nodes of elements are present in nodes map
1424 NCollection_Map< int >::Iterator anIter( anElemList );
1425 for ( ; anIter.More(); anIter.Next() )
1427 const SMDS_MeshElement* anElem = aMeshDS->FindElement( anIter.Value() );
1432 SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
1433 while( aNodeIter->more() )
1435 const SMDS_MeshNode* aNode =
1436 dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
1437 if ( !aNode || !aNodeMap.Contains( aNode->GetID() ) )
1444 aResultIds.Add( anElem->GetID() );
1450 SMESH::SMESH_Group_var aResGrp = CreateGroup( theElemType, theName );
1451 if ( aResGrp->_is_nil() )
1452 return SMESH::SMESH_Group::_nil();
1454 // Create array of identifiers
1455 SMESH::long_array_var aResIds = new SMESH::long_array;
1456 aResIds->length( aResultIds.Extent() );
1458 NCollection_Map< int >::Iterator aResIter( aResultIds );
1459 for ( int i = 0; aResIter.More(); aResIter.Next(), i++ )
1460 aResIds[ i ] = aResIter.Value();
1461 aResGrp->Add( aResIds );
1463 // Remove strings corresponding to group creation
1464 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1465 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1466 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1468 // Update Python script
1470 TPythonDump() << aResGrp << " = " << _this() << ".CreateDimGroup( "
1471 << &theGroups << ", " << theElemType << ", '" << theName << "' )";
1473 return aResGrp._retn();
1477 return SMESH::SMESH_Group::_nil();
1481 //================================================================================
1483 * \brief Return group items of a group present in a study
1485 //================================================================================
1487 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
1488 SMESH_Gen_i* theGen,
1489 list<TopoDS_Shape> & theItems)
1491 GEOM::GEOM_Object_var groupObj;
1492 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
1493 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
1494 if ( study->_is_nil() || geomGen->_is_nil() )
1495 return groupObj._retn();
1497 GEOM::GEOM_IGroupOperations_var groupOp =
1498 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
1499 GEOM::GEOM_IShapesOperations_var shapeOp =
1500 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
1502 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
1503 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
1504 return groupObj._retn();
1505 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
1506 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
1507 return groupObj._retn(); // keep only submeshes on groups
1509 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
1510 if ( anIter->_is_nil() ) return groupObj._retn();
1511 for ( ; anIter->More(); anIter->Next())
1513 SALOMEDS::SObject_var aSObject = anIter->Value();
1514 SALOMEDS::SObject_var aRefSO;
1515 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
1517 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
1518 if ( groupObj->_is_nil() ) break;
1519 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1520 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1521 for ( int i = 0; i < ids->length(); ++i ) {
1522 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1523 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1525 theItems.push_back( S );
1530 return groupObj._retn();
1533 //=============================================================================
1535 * \brief Update hypotheses assigned to geom groups if the latter change
1537 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1539 //=============================================================================
1541 void SMESH_Mesh_i::CheckGeomGroupModif()
1543 if ( !_impl->HasShapeToMesh() ) return;
1545 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1546 if ( study->_is_nil() ) return;
1548 // check if items of groups changed
1549 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1550 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1552 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1553 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1554 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1556 int oldID = i_sm->first;
1557 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1558 if ( i_smIor == _mapSubMeshIor.end() )
1560 list< TopoDS_Shape> newItems;
1561 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1562 if ( groupObj->_is_nil() )
1565 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1566 int nbNewItems = newItems.size();
1567 bool groupChanged = ( nbOldItems != nbNewItems);
1568 if ( !groupChanged ) {
1569 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1570 groupChanged = ( oldGroupShape != newItems.front() );
1573 list<TopoDS_Shape>::iterator item = newItems.begin();
1574 for ( ; item != newItems.end() && !groupChanged; ++item )
1576 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1577 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1581 // update hypotheses and submeshes if necessary
1584 // get a new group shape
1585 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1586 if ( !geomClient ) continue;
1587 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1588 geomClient->RemoveShapeFromBuffer( groupIOR );
1589 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1590 // update hypotheses
1591 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1592 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1593 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1595 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1596 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1598 // care of submeshes
1599 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1600 int newID = newSubmesh->GetId();
1601 if ( newID != oldID ) {
1602 _mapSubMesh [ newID ] = newSubmesh;
1603 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1604 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1605 _mapSubMesh.erase (oldID);
1606 _mapSubMesh_i.erase (oldID);
1607 _mapSubMeshIor.erase(oldID);
1608 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1614 //=============================================================================
1618 //=============================================================================
1620 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1622 if(MYDEBUG) MESSAGE( "createSubMesh" );
1623 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1625 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1626 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1627 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1628 SMESH::SMESH_subMesh_var subMesh
1629 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1631 _mapSubMesh[subMeshId] = mySubMesh;
1632 _mapSubMesh_i[subMeshId] = subMeshServant;
1633 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1635 // register CORBA object for persistence
1636 int nextId = _gen_i->RegisterObject( subMesh );
1637 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1639 return subMesh._retn();
1642 //=======================================================================
1643 //function : getSubMesh
1645 //=======================================================================
1647 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1649 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1650 if ( it == _mapSubMeshIor.end() )
1651 return SMESH::SMESH_subMesh::_nil();
1653 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1657 //=============================================================================
1661 //=============================================================================
1663 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1664 GEOM::GEOM_Object_ptr theSubShapeObject )
1666 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1667 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1671 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1672 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1673 removeHypothesis( theSubShapeObject, aHypList[i] );
1676 catch( const SALOME::SALOME_Exception& ) {
1677 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1680 int subMeshId = theSubMesh->GetId();
1682 _mapSubMesh.erase(subMeshId);
1683 _mapSubMesh_i.erase(subMeshId);
1684 _mapSubMeshIor.erase(subMeshId);
1685 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1688 //=============================================================================
1692 //=============================================================================
1694 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1695 const char* theName,
1696 const TopoDS_Shape& theShape )
1699 SMESH::SMESH_GroupBase_var aGroup;
1700 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1701 SMESH_GroupBase_i* aGroupImpl;
1702 if ( !theShape.IsNull() )
1703 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1705 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1707 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1708 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1709 aGroupImpl->Register();
1710 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1712 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1713 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1715 // register CORBA object for persistence
1716 int nextId = _gen_i->RegisterObject( aGroup );
1717 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1719 return aGroup._retn();
1722 //=============================================================================
1724 * SMESH_Mesh_i::removeGroup
1726 * Should be called by ~SMESH_Group_i()
1728 //=============================================================================
1730 void SMESH_Mesh_i::removeGroup( const int theId )
1732 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1733 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1734 _mapGroups.erase( theId );
1735 _impl->RemoveGroup( theId );
1740 //=============================================================================
1744 //=============================================================================
1746 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1747 throw(SALOME::SALOME_Exception)
1749 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1751 SMESH::log_array_var aLog;
1753 list < SMESHDS_Command * >logDS = _impl->GetLog();
1754 aLog = new SMESH::log_array;
1756 int lg = logDS.size();
1759 list < SMESHDS_Command * >::iterator its = logDS.begin();
1760 while(its != logDS.end()){
1761 SMESHDS_Command *com = *its;
1762 int comType = com->GetType();
1764 int lgcom = com->GetNumber();
1766 const list < int >&intList = com->GetIndexes();
1767 int inum = intList.size();
1769 list < int >::const_iterator ii = intList.begin();
1770 const list < double >&coordList = com->GetCoords();
1771 int rnum = coordList.size();
1773 list < double >::const_iterator ir = coordList.begin();
1774 aLog[indexLog].commandType = comType;
1775 aLog[indexLog].number = lgcom;
1776 aLog[indexLog].coords.length(rnum);
1777 aLog[indexLog].indexes.length(inum);
1778 for(int i = 0; i < rnum; i++){
1779 aLog[indexLog].coords[i] = *ir;
1780 //MESSAGE(" "<<i<<" "<<ir.Value());
1783 for(int i = 0; i < inum; i++){
1784 aLog[indexLog].indexes[i] = *ii;
1785 //MESSAGE(" "<<i<<" "<<ii.Value());
1794 catch(SALOME_Exception & S_ex){
1795 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1797 return aLog._retn();
1801 //=============================================================================
1805 //=============================================================================
1807 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1809 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1813 //=============================================================================
1817 //=============================================================================
1819 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1821 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1825 //=============================================================================
1829 //=============================================================================
1831 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1836 //=============================================================================
1840 //=============================================================================
1842 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1844 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1848 //=============================================================================
1852 //=============================================================================
1854 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1856 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1860 //=============================================================================
1862 * Return mesh editor
1864 //=============================================================================
1866 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1868 // Create MeshEditor
1869 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1870 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1872 // Update Python script
1873 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1875 return aMesh._retn();
1878 //=============================================================================
1880 * Return mesh edition previewer
1882 //=============================================================================
1884 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1886 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1887 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1888 return aMesh._retn();
1891 //=============================================================================
1895 //=============================================================================
1896 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1898 Unexpect aCatch(SALOME_SalomeException);
1899 _impl->SetAutoColor(theAutoColor);
1902 //=============================================================================
1906 //=============================================================================
1907 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1909 Unexpect aCatch(SALOME_SalomeException);
1910 return _impl->GetAutoColor();
1914 //=============================================================================
1916 * Export in different formats
1918 //=============================================================================
1920 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1922 return _impl->HasDuplicatedGroupNamesMED();
1925 void SMESH_Mesh_i::PrepareForWriting (const char* file)
1927 TCollection_AsciiString aFullName ((char*)file);
1928 OSD_Path aPath (aFullName);
1929 OSD_File aFile (aPath);
1930 if (aFile.Exists()) {
1931 // existing filesystem node
1932 if (aFile.KindOfFile() == OSD_FILE) {
1933 if (aFile.IsWriteable()) {
1936 if (aFile.Failed()) {
1937 TCollection_AsciiString msg ("File ");
1938 msg += aFullName + " cannot be replaced.";
1939 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1942 TCollection_AsciiString msg ("File ");
1943 msg += aFullName + " cannot be overwritten.";
1944 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1947 TCollection_AsciiString msg ("Location ");
1948 msg += aFullName + " is not a file.";
1949 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1952 // nonexisting file; check if it can be created
1954 aFile.Build(OSD_WriteOnly, OSD_Protection());
1955 if (aFile.Failed()) {
1956 TCollection_AsciiString msg ("You cannot create the file ");
1957 msg += aFullName + ". Check the directory existance and access rights.";
1958 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1966 void SMESH_Mesh_i::ExportToMED (const char* file,
1967 CORBA::Boolean auto_groups,
1968 SMESH::MED_VERSION theVersion)
1969 throw(SALOME::SALOME_Exception)
1971 Unexpect aCatch(SALOME_SalomeException);
1973 // Update Python script
1974 TPythonDump() << _this() << ".ExportToMED( '"
1975 << file << "', " << auto_groups << ", " << theVersion << " )";
1978 PrepareForWriting(file);
1979 char* aMeshName = "Mesh";
1980 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1981 if ( !aStudy->_is_nil() ) {
1982 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1983 if ( !aMeshSO->_is_nil() ) {
1984 aMeshName = aMeshSO->GetName();
1986 //SCRUTE(aMeshName);
1987 //SCRUTE(aMeshSO->GetID());
1989 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1990 if ( !aStudy->GetProperties()->IsLocked() )
1992 SALOMEDS::GenericAttribute_var anAttr;
1993 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1994 SALOMEDS::AttributeExternalFileDef_var aFileName;
1995 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1996 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1997 ASSERT(!aFileName->_is_nil());
1998 aFileName->SetValue(file);
1999 SALOMEDS::AttributeFileType_var aFileType;
2000 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
2001 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
2002 ASSERT(!aFileType->_is_nil());
2003 aFileType->SetValue("FICHIERMED");
2007 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
2010 void SMESH_Mesh_i::ExportMED (const char* file,
2011 CORBA::Boolean auto_groups)
2012 throw(SALOME::SALOME_Exception)
2014 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
2017 void SMESH_Mesh_i::ExportDAT (const char *file)
2018 throw(SALOME::SALOME_Exception)
2020 Unexpect aCatch(SALOME_SalomeException);
2022 // Update Python script
2023 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
2026 PrepareForWriting(file);
2027 _impl->ExportDAT(file);
2030 void SMESH_Mesh_i::ExportUNV (const char *file)
2031 throw(SALOME::SALOME_Exception)
2033 Unexpect aCatch(SALOME_SalomeException);
2035 // Update Python script
2036 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
2039 PrepareForWriting(file);
2040 _impl->ExportUNV(file);
2043 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
2044 throw(SALOME::SALOME_Exception)
2046 Unexpect aCatch(SALOME_SalomeException);
2048 // Update Python script
2049 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
2052 PrepareForWriting(file);
2053 _impl->ExportSTL(file, isascii);
2056 //=============================================================================
2060 //=============================================================================
2062 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
2064 Unexpect aCatch(SALOME_SalomeException);
2065 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
2066 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
2067 return aMesh._retn();
2070 //=============================================================================
2074 //=============================================================================
2075 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
2077 Unexpect aCatch(SALOME_SalomeException);
2078 return _impl->NbNodes();
2081 //=============================================================================
2085 //=============================================================================
2086 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
2088 Unexpect aCatch(SALOME_SalomeException);
2089 return NbEdges() + NbFaces() + NbVolumes();
2092 //=============================================================================
2096 //=============================================================================
2097 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
2099 Unexpect aCatch(SALOME_SalomeException);
2100 return _impl->NbEdges();
2103 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
2104 throw(SALOME::SALOME_Exception)
2106 Unexpect aCatch(SALOME_SalomeException);
2107 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
2110 //=============================================================================
2114 //=============================================================================
2115 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
2117 Unexpect aCatch(SALOME_SalomeException);
2118 return _impl->NbFaces();
2121 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
2123 Unexpect aCatch(SALOME_SalomeException);
2124 return _impl->NbTriangles();
2127 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
2129 Unexpect aCatch(SALOME_SalomeException);
2130 return _impl->NbQuadrangles();
2133 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
2135 Unexpect aCatch(SALOME_SalomeException);
2136 return _impl->NbPolygons();
2139 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
2140 throw(SALOME::SALOME_Exception)
2142 Unexpect aCatch(SALOME_SalomeException);
2143 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
2146 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
2147 throw(SALOME::SALOME_Exception)
2149 Unexpect aCatch(SALOME_SalomeException);
2150 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
2153 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
2154 throw(SALOME::SALOME_Exception)
2156 Unexpect aCatch(SALOME_SalomeException);
2157 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
2160 //=============================================================================
2164 //=============================================================================
2165 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
2167 Unexpect aCatch(SALOME_SalomeException);
2168 return _impl->NbVolumes();
2171 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
2173 Unexpect aCatch(SALOME_SalomeException);
2174 return _impl->NbTetras();
2177 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
2179 Unexpect aCatch(SALOME_SalomeException);
2180 return _impl->NbHexas();
2183 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
2185 Unexpect aCatch(SALOME_SalomeException);
2186 return _impl->NbPyramids();
2189 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
2191 Unexpect aCatch(SALOME_SalomeException);
2192 return _impl->NbPrisms();
2195 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
2197 Unexpect aCatch(SALOME_SalomeException);
2198 return _impl->NbPolyhedrons();
2201 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
2202 throw(SALOME::SALOME_Exception)
2204 Unexpect aCatch(SALOME_SalomeException);
2205 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
2208 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
2209 throw(SALOME::SALOME_Exception)
2211 Unexpect aCatch(SALOME_SalomeException);
2212 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
2215 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
2216 throw(SALOME::SALOME_Exception)
2218 Unexpect aCatch(SALOME_SalomeException);
2219 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
2222 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
2223 throw(SALOME::SALOME_Exception)
2225 Unexpect aCatch(SALOME_SalomeException);
2226 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
2229 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
2230 throw(SALOME::SALOME_Exception)
2232 Unexpect aCatch(SALOME_SalomeException);
2233 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
2236 //=============================================================================
2240 //=============================================================================
2241 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
2243 Unexpect aCatch(SALOME_SalomeException);
2244 return _impl->NbSubMesh();
2247 //=============================================================================
2251 //=============================================================================
2252 char* SMESH_Mesh_i::Dump()
2254 std::ostringstream os;
2256 return CORBA::string_dup( os.str().c_str() );
2259 //=============================================================================
2263 //=============================================================================
2264 SMESH::long_array* SMESH_Mesh_i::GetIDs()
2266 // SMESH::long_array_var aResult = new SMESH::long_array();
2267 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2268 // int aMinId = aSMESHDS_Mesh->MinElementID();
2269 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
2271 // aResult->length(aMaxId - aMinId + 1);
2273 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
2274 // aResult[i++] = id;
2276 // return aResult._retn();
2278 return GetElementsId();
2281 //=============================================================================
2285 //=============================================================================
2287 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
2288 throw (SALOME::SALOME_Exception)
2290 Unexpect aCatch(SALOME_SalomeException);
2291 MESSAGE("SMESH_Mesh_i::GetElementsId");
2292 SMESH::long_array_var aResult = new SMESH::long_array();
2293 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2295 if ( aSMESHDS_Mesh == NULL )
2296 return aResult._retn();
2298 long nbElements = NbElements();
2299 aResult->length( nbElements );
2300 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
2301 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
2302 aResult[i] = anIt->next()->GetID();
2304 return aResult._retn();
2308 //=============================================================================
2312 //=============================================================================
2314 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
2315 throw (SALOME::SALOME_Exception)
2317 Unexpect aCatch(SALOME_SalomeException);
2318 MESSAGE("SMESH_subMesh_i::GetElementsByType");
2319 SMESH::long_array_var aResult = new SMESH::long_array();
2320 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2322 if ( aSMESHDS_Mesh == NULL )
2323 return aResult._retn();
2325 long nbElements = NbElements();
2327 // No sense in returning ids of elements along with ids of nodes:
2328 // when theElemType == SMESH::ALL, return node ids only if
2329 // there are no elements
2330 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
2331 return GetNodesId();
2333 aResult->length( nbElements );
2337 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
2338 while ( i < nbElements && anIt->more() ) {
2339 const SMDS_MeshElement* anElem = anIt->next();
2340 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
2341 aResult[i++] = anElem->GetID();
2344 aResult->length( i );
2346 return aResult._retn();
2349 //=============================================================================
2353 //=============================================================================
2355 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
2356 throw (SALOME::SALOME_Exception)
2358 Unexpect aCatch(SALOME_SalomeException);
2359 MESSAGE("SMESH_subMesh_i::GetNodesId");
2360 SMESH::long_array_var aResult = new SMESH::long_array();
2361 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2363 if ( aSMESHDS_Mesh == NULL )
2364 return aResult._retn();
2366 long nbNodes = NbNodes();
2367 aResult->length( nbNodes );
2368 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
2369 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
2370 aResult[i] = anIt->next()->GetID();
2372 return aResult._retn();
2375 //=============================================================================
2379 //=============================================================================
2381 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
2382 throw (SALOME::SALOME_Exception)
2384 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
2388 //=============================================================================
2390 * Returns ID of elements for given submesh
2392 //=============================================================================
2393 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
2394 throw (SALOME::SALOME_Exception)
2396 SMESH::long_array_var aResult = new SMESH::long_array();
2398 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2399 if(!SM) return aResult._retn();
2401 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2402 if(!SDSM) return aResult._retn();
2404 aResult->length(SDSM->NbElements());
2406 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2408 while ( eIt->more() ) {
2409 aResult[i++] = eIt->next()->GetID();
2412 return aResult._retn();
2416 //=============================================================================
2418 * Returns ID of nodes for given submesh
2419 * If param all==true - returns all nodes, else -
2420 * returns only nodes on shapes.
2422 //=============================================================================
2423 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
2424 throw (SALOME::SALOME_Exception)
2426 SMESH::long_array_var aResult = new SMESH::long_array();
2428 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2429 if(!SM) return aResult._retn();
2431 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2432 if(!SDSM) return aResult._retn();
2435 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
2436 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
2437 while ( nIt->more() ) {
2438 const SMDS_MeshNode* elem = nIt->next();
2439 theElems.insert( elem->GetID() );
2442 else { // all nodes of submesh elements
2443 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2444 while ( eIt->more() ) {
2445 const SMDS_MeshElement* anElem = eIt->next();
2446 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
2447 while ( nIt->more() ) {
2448 const SMDS_MeshElement* elem = nIt->next();
2449 theElems.insert( elem->GetID() );
2454 aResult->length(theElems.size());
2455 set<int>::iterator itElem;
2457 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
2458 aResult[i++] = *itElem;
2460 return aResult._retn();
2464 //=============================================================================
2466 * Returns type of elements for given submesh
2468 //=============================================================================
2469 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2470 throw (SALOME::SALOME_Exception)
2472 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2473 if(!SM) return SMESH::ALL;
2475 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2476 if(!SDSM) return SMESH::ALL;
2478 if(SDSM->NbElements()==0)
2479 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2481 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2482 const SMDS_MeshElement* anElem = eIt->next();
2483 return ( SMESH::ElementType ) anElem->GetType();
2487 //=============================================================================
2491 //=============================================================================
2493 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2495 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2497 MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
2502 //=============================================================================
2504 * Get XYZ coordinates of node as list of double
2505 * If there is not node for given ID - returns empty list
2507 //=============================================================================
2509 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2511 SMESH::double_array_var aResult = new SMESH::double_array();
2512 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2513 if ( aSMESHDS_Mesh == NULL )
2514 return aResult._retn();
2517 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2519 return aResult._retn();
2523 aResult[0] = aNode->X();
2524 aResult[1] = aNode->Y();
2525 aResult[2] = aNode->Z();
2526 return aResult._retn();
2530 //=============================================================================
2532 * For given node returns list of IDs of inverse elements
2533 * If there is not node for given ID - returns empty list
2535 //=============================================================================
2537 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2539 SMESH::long_array_var aResult = new SMESH::long_array();
2540 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2541 if ( aSMESHDS_Mesh == NULL )
2542 return aResult._retn();
2545 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2547 return aResult._retn();
2549 // find inverse elements
2550 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2551 TColStd_SequenceOfInteger IDs;
2552 while(eIt->more()) {
2553 const SMDS_MeshElement* elem = eIt->next();
2554 IDs.Append(elem->GetID());
2556 if(IDs.Length()>0) {
2557 aResult->length(IDs.Length());
2559 for(; i<=IDs.Length(); i++) {
2560 aResult[i-1] = IDs.Value(i);
2563 return aResult._retn();
2566 //=============================================================================
2568 * \brief Return position of a node on shape
2570 //=============================================================================
2572 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2574 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2575 aNodePosition->shapeID = 0;
2576 aNodePosition->shapeType = GEOM::SHAPE;
2578 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2579 if ( !mesh ) return aNodePosition;
2581 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2583 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2585 aNodePosition->shapeID = pos->GetShapeId();
2586 switch ( pos->GetTypeOfPosition() ) {
2588 aNodePosition->shapeType = GEOM::EDGE;
2589 aNodePosition->params.length(1);
2590 aNodePosition->params[0] =
2591 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2594 aNodePosition->shapeType = GEOM::FACE;
2595 aNodePosition->params.length(2);
2596 aNodePosition->params[0] =
2597 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2598 aNodePosition->params[1] =
2599 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2601 case SMDS_TOP_VERTEX:
2602 aNodePosition->shapeType = GEOM::VERTEX;
2604 case SMDS_TOP_3DSPACE:
2605 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2606 aNodePosition->shapeType = GEOM::SOLID;
2607 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2608 aNodePosition->shapeType = GEOM::SHELL;
2614 return aNodePosition;
2617 //=============================================================================
2619 * If given element is node returns IDs of shape from position
2620 * If there is not node for given ID - returns -1
2622 //=============================================================================
2624 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2626 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2627 if ( aSMESHDS_Mesh == NULL )
2631 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2633 SMDS_PositionPtr pos = aNode->GetPosition();
2637 return pos->GetShapeId();
2644 //=============================================================================
2646 * For given element returns ID of result shape after
2647 * ::FindShape() from SMESH_MeshEditor
2648 * If there is not element for given ID - returns -1
2650 //=============================================================================
2652 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2654 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2655 if ( aSMESHDS_Mesh == NULL )
2658 // try to find element
2659 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2663 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2664 ::SMESH_MeshEditor aMeshEditor(_impl);
2665 int index = aMeshEditor.FindShape( elem );
2673 //=============================================================================
2675 * Returns number of nodes for given element
2676 * If there is not element for given ID - returns -1
2678 //=============================================================================
2680 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2682 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2683 if ( aSMESHDS_Mesh == NULL ) return -1;
2684 // try to find element
2685 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2686 if(!elem) return -1;
2687 return elem->NbNodes();
2691 //=============================================================================
2693 * Returns ID of node by given index for given element
2694 * If there is not element for given ID - returns -1
2695 * If there is not node for given index - returns -2
2697 //=============================================================================
2699 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2701 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2702 if ( aSMESHDS_Mesh == NULL ) return -1;
2703 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2704 if(!elem) return -1;
2705 if( index>=elem->NbNodes() || index<0 ) return -1;
2706 return elem->GetNode(index)->GetID();
2709 //=============================================================================
2711 * Returns IDs of nodes of given element
2713 //=============================================================================
2715 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2717 SMESH::long_array_var aResult = new SMESH::long_array();
2718 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2720 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2722 aResult->length( elem->NbNodes() );
2723 for ( int i = 0; i < elem->NbNodes(); ++i )
2724 aResult[ i ] = elem->GetNode( i )->GetID();
2727 return aResult._retn();
2730 //=============================================================================
2732 * Returns true if given node is medium node
2733 * in given quadratic element
2735 //=============================================================================
2737 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2739 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2740 if ( aSMESHDS_Mesh == NULL ) return false;
2742 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2743 if(!aNode) return false;
2744 // try to find element
2745 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2746 if(!elem) return false;
2748 return elem->IsMediumNode(aNode);
2752 //=============================================================================
2754 * Returns true if given node is medium node
2755 * in one of quadratic elements
2757 //=============================================================================
2759 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2760 SMESH::ElementType theElemType)
2762 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2763 if ( aSMESHDS_Mesh == NULL ) return false;
2766 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2767 if(!aNode) return false;
2769 SMESH_MesherHelper aHelper( *(_impl) );
2771 SMDSAbs_ElementType aType;
2772 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2773 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2774 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2775 else aType = SMDSAbs_All;
2777 return aHelper.IsMedium(aNode,aType);
2781 //=============================================================================
2783 * Returns number of edges for given element
2785 //=============================================================================
2787 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2789 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2790 if ( aSMESHDS_Mesh == NULL ) return -1;
2791 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2792 if(!elem) return -1;
2793 return elem->NbEdges();
2797 //=============================================================================
2799 * Returns number of faces for given element
2801 //=============================================================================
2803 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2805 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2806 if ( aSMESHDS_Mesh == NULL ) return -1;
2807 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2808 if(!elem) return -1;
2809 return elem->NbFaces();
2813 //=============================================================================
2815 * Returns true if given element is polygon
2817 //=============================================================================
2819 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2821 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2822 if ( aSMESHDS_Mesh == NULL ) return false;
2823 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2824 if(!elem) return false;
2825 return elem->IsPoly();
2829 //=============================================================================
2831 * Returns true if given element is quadratic
2833 //=============================================================================
2835 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2837 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2838 if ( aSMESHDS_Mesh == NULL ) return false;
2839 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2840 if(!elem) return false;
2841 return elem->IsQuadratic();
2845 //=============================================================================
2847 * Returns bary center for given element
2849 //=============================================================================
2851 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2853 SMESH::double_array_var aResult = new SMESH::double_array();
2854 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2855 if ( aSMESHDS_Mesh == NULL )
2856 return aResult._retn();
2858 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2860 return aResult._retn();
2862 if(elem->GetType()==SMDSAbs_Volume) {
2863 SMDS_VolumeTool aTool;
2864 if(aTool.Set(elem)) {
2866 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2871 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2873 double x=0., y=0., z=0.;
2874 for(; anIt->more(); ) {
2876 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2890 return aResult._retn();
2894 //=============================================================================
2896 * Create and publish group servants if any groups were imported or created anyhow
2898 //=============================================================================
2900 void SMESH_Mesh_i::CreateGroupServants()
2902 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2904 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2905 while ( groupIt->more() )
2907 ::SMESH_Group* group = groupIt->next();
2908 int anId = group->GetGroupDS()->GetID();
2910 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
2911 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2914 SMESH_GroupBase_i* aGroupImpl;
2916 if ( SMESHDS_GroupOnGeom* groupOnGeom =
2917 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
2919 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2920 shape = groupOnGeom->GetShape();
2923 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2926 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
2927 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2928 aGroupImpl->Register();
2930 SMESH::SMESH_GroupBase_var groupVar =
2931 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2932 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
2934 // register CORBA object for persistence
2935 int nextId = _gen_i->RegisterObject( groupVar );
2936 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2938 // publishing of the groups in the study
2939 if ( !aStudy->_is_nil() ) {
2940 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
2941 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
2946 //=============================================================================
2948 * \brief Return groups cantained in _mapGroups by their IDs
2950 //=============================================================================
2952 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
2954 int nbGroups = groupIDs.size();
2955 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
2956 aList->length( nbGroups );
2958 list<int>::const_iterator ids = groupIDs.begin();
2959 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
2961 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
2962 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2963 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
2965 aList->length( nbGroups );
2966 return aList._retn();
2969 //=============================================================================
2971 * \brief Return information about imported file
2973 //=============================================================================
2975 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
2977 SALOME_MED::MedFileInfo_var res( myFileInfo );
2978 if ( !res.operator->() ) {
2979 res = new SALOME_MED::MedFileInfo;
2981 res->fileSize = res->major = res->minor = res->release = -1;