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 //================================================================================
214 * \brief Remove all nodes and elements for indicated shape
216 //================================================================================
218 void SMESH_Mesh_i::ClearSubMesh(CORBA::Long ShapeID)
219 throw (SALOME::SALOME_Exception)
221 Unexpect aCatch(SALOME_SalomeException);
223 _impl->ClearSubMesh( ShapeID );
225 catch(SALOME_Exception & S_ex) {
226 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
230 //=============================================================================
234 //=============================================================================
236 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
238 SMESH::DriverMED_ReadStatus res;
241 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
242 res = SMESH::DRS_OK; break;
243 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
244 res = SMESH::DRS_EMPTY; break;
245 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
246 res = SMESH::DRS_WARN_RENUMBER; break;
247 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
248 res = SMESH::DRS_WARN_SKIP_ELEM; break;
249 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
251 res = SMESH::DRS_FAIL; break;
256 //=============================================================================
260 * Imports mesh data from MED file
262 //=============================================================================
264 SMESH::DriverMED_ReadStatus
265 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
266 throw ( SALOME::SALOME_Exception )
268 Unexpect aCatch(SALOME_SalomeException);
271 status = _impl->MEDToMesh( theFileName, theMeshName );
273 catch( SALOME_Exception& S_ex ) {
274 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
277 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
280 CreateGroupServants();
282 int major, minor, release;
283 if( !MED::getMEDVersion( theFileName, major, minor, release ) )
284 major = minor = release = -1;
285 myFileInfo = new SALOME_MED::MedFileInfo();
286 myFileInfo->fileName = theFileName;
287 myFileInfo->fileSize = 0;
290 if ( ::_stati64( theFileName, &d ) != -1 )
293 if ( ::stat64( theFileName, &d ) != -1 )
295 myFileInfo->fileSize = d.st_size;
296 myFileInfo->major = major;
297 myFileInfo->minor = minor;
298 myFileInfo->release = release;
300 return ConvertDriverMEDReadStatus(status);
303 //================================================================================
305 * \brief Return string representation of a MED file version comprising nbDigits
307 //================================================================================
309 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
311 std::string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
313 return CORBA::string_dup( ver.c_str() );
316 //=============================================================================
320 * Imports mesh data from MED file
322 //=============================================================================
324 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
325 throw ( SALOME::SALOME_Exception )
327 // Read mesh with name = <theMeshName> into SMESH_Mesh
328 _impl->UNVToMesh( theFileName );
330 CreateGroupServants();
335 //=============================================================================
339 * Imports mesh data from STL file
341 //=============================================================================
342 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
343 throw ( SALOME::SALOME_Exception )
345 // Read mesh with name = <theMeshName> into SMESH_Mesh
346 _impl->STLToMesh( theFileName );
351 //=============================================================================
355 * Imports mesh data from MED file
357 //=============================================================================
359 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
361 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
362 // int status = _impl->MEDToMesh( theFileName, theMeshName );
363 // CreateGroupServants();
368 //=============================================================================
372 //=============================================================================
374 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
376 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
377 (SMESH_Hypothesis::Hypothesis_Status theStatus)
380 RETURNCASE( HYP_OK );
381 RETURNCASE( HYP_MISSING );
382 RETURNCASE( HYP_CONCURENT );
383 RETURNCASE( HYP_BAD_PARAMETER );
384 RETURNCASE( HYP_HIDDEN_ALGO );
385 RETURNCASE( HYP_HIDING_ALGO );
386 RETURNCASE( HYP_UNKNOWN_FATAL );
387 RETURNCASE( HYP_INCOMPATIBLE );
388 RETURNCASE( HYP_NOTCONFORM );
389 RETURNCASE( HYP_ALREADY_EXIST );
390 RETURNCASE( HYP_BAD_DIM );
391 RETURNCASE( HYP_BAD_SUBSHAPE );
392 RETURNCASE( HYP_BAD_GEOMETRY );
393 RETURNCASE( HYP_NEED_SHAPE );
396 return SMESH::HYP_UNKNOWN_FATAL;
399 //=============================================================================
403 * calls internal addHypothesis() and then adds a reference to <anHyp> under
404 * the SObject actually having a reference to <aSubShape>.
405 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
407 //=============================================================================
409 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
410 SMESH::SMESH_Hypothesis_ptr anHyp)
411 throw(SALOME::SALOME_Exception)
413 Unexpect aCatch(SALOME_SalomeException);
414 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
416 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
417 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
418 aSubShapeObject, anHyp );
420 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
422 // Update Python script
423 if(_impl->HasShapeToMesh()) {
424 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
425 << aSubShapeObject << ", " << anHyp << " )";
428 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
431 return ConvertHypothesisStatus(status);
434 //=============================================================================
438 //=============================================================================
440 SMESH_Hypothesis::Hypothesis_Status
441 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
442 SMESH::SMESH_Hypothesis_ptr anHyp)
444 if(MYDEBUG) MESSAGE("addHypothesis");
446 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
447 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
450 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
451 if (CORBA::is_nil(myHyp))
452 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
455 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
458 TopoDS_Shape myLocSubShape;
459 //use PseudoShape in case if mesh has no shape
461 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
463 myLocSubShape = _impl->GetShapeToMesh();
465 int hypId = myHyp->GetId();
466 status = _impl->AddHypothesis(myLocSubShape, hypId);
467 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
468 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
469 // assure there is a corresponding submesh
470 if ( !_impl->IsMainShape( myLocSubShape )) {
471 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
472 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
473 createSubMesh( aSubShapeObject );
477 catch(SALOME_Exception & S_ex)
479 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
484 //=============================================================================
488 //=============================================================================
490 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
491 SMESH::SMESH_Hypothesis_ptr anHyp)
492 throw(SALOME::SALOME_Exception)
494 Unexpect aCatch(SALOME_SalomeException);
495 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
497 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
498 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
499 aSubShapeObject, anHyp );
501 // Update Python script
502 // Update Python script
503 if(_impl->HasShapeToMesh()) {
504 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
505 << aSubShapeObject << ", " << anHyp << " )";
508 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
512 return ConvertHypothesisStatus(status);
515 //=============================================================================
519 //=============================================================================
521 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
522 SMESH::SMESH_Hypothesis_ptr anHyp)
524 if(MYDEBUG) MESSAGE("removeHypothesis()");
525 // **** proposer liste de subShape (selection multiple)
527 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
528 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
531 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
532 if (CORBA::is_nil(myHyp))
533 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
536 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
539 TopoDS_Shape myLocSubShape;
540 //use PseudoShape in case if mesh has no shape
542 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
544 myLocSubShape = _impl->GetShapeToMesh();
546 int hypId = myHyp->GetId();
547 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
548 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
549 _mapHypo.erase( hypId );
551 catch(SALOME_Exception & S_ex)
553 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
558 //=============================================================================
562 //=============================================================================
564 SMESH::ListOfHypothesis *
565 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
566 throw(SALOME::SALOME_Exception)
568 Unexpect aCatch(SALOME_SalomeException);
569 if (MYDEBUG) MESSAGE("GetHypothesisList");
570 if (CORBA::is_nil(aSubShapeObject))
571 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
574 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
577 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
578 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
579 int i = 0, n = aLocalList.size();
582 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
583 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
584 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
585 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
590 catch(SALOME_Exception & S_ex) {
591 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
594 return aList._retn();
597 //=============================================================================
601 //=============================================================================
602 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
603 const char* theName )
604 throw(SALOME::SALOME_Exception)
606 Unexpect aCatch(SALOME_SalomeException);
607 MESSAGE("SMESH_Mesh_i::GetSubMesh");
608 if (CORBA::is_nil(aSubShapeObject))
609 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
612 SMESH::SMESH_subMesh_var subMesh;
613 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
615 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
617 //Get or Create the SMESH_subMesh object implementation
619 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
620 subMesh = getSubMesh( subMeshId );
622 // create a new subMesh object servant if there is none for the shape
623 if ( subMesh->_is_nil() )
624 subMesh = createSubMesh( aSubShapeObject );
626 if ( _gen_i->CanPublishInStudy( subMesh )) {
627 SALOMEDS::SObject_var aSO =
628 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
629 subMesh, aSubShapeObject, theName );
630 if ( !aSO->_is_nil()) {
631 // Update Python script
632 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
633 << aSubShapeObject << ", '" << theName << "' )";
637 catch(SALOME_Exception & S_ex) {
638 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
640 return subMesh._retn();
643 //=============================================================================
647 //=============================================================================
649 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
650 throw (SALOME::SALOME_Exception)
652 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
653 if ( theSubMesh->_is_nil() )
656 GEOM::GEOM_Object_var aSubShapeObject;
657 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
658 if ( !aStudy->_is_nil() ) {
659 // Remove submesh's SObject
660 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
661 if ( !anSO->_is_nil() ) {
662 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
663 SALOMEDS::SObject_var anObj, aRef;
664 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
665 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
667 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
669 // Update Python script
670 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
674 removeSubMesh( theSubMesh, aSubShapeObject.in() );
677 //=============================================================================
681 //=============================================================================
682 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
683 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
685 switch (theElemType) {
690 CASE2STRING( VOLUME );
696 //=============================================================================
700 //=============================================================================
702 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
703 const char* theName )
704 throw(SALOME::SALOME_Exception)
706 Unexpect aCatch(SALOME_SalomeException);
707 SMESH::SMESH_Group_var aNewGroup =
708 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
710 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
711 SALOMEDS::SObject_var aSO =
712 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
713 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
714 if ( !aSO->_is_nil()) {
715 // Update Python script
716 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
717 << ElementTypeString(theElemType) << ", '" << theName << "' )";
720 return aNewGroup._retn();
724 //=============================================================================
728 //=============================================================================
729 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
731 GEOM::GEOM_Object_ptr theGeomObj)
732 throw(SALOME::SALOME_Exception)
734 Unexpect aCatch(SALOME_SalomeException);
735 SMESH::SMESH_GroupOnGeom_var aNewGroup;
737 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
738 if ( !aShape.IsNull() ) {
739 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
740 ( createGroup( theElemType, theName, aShape ));
741 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
742 SALOMEDS::SObject_var aSO =
743 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
744 aNewGroup, theGeomObj, theName);
745 if ( !aSO->_is_nil()) {
746 // Update Python script
747 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
748 << ElementTypeString(theElemType) << ", '" << theName << "', "
749 << theGeomObj << " )";
754 return aNewGroup._retn();
757 //=============================================================================
761 //=============================================================================
763 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
764 throw (SALOME::SALOME_Exception)
766 if ( theGroup->_is_nil() )
769 SMESH_GroupBase_i* aGroup =
770 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
774 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
775 if ( !aStudy->_is_nil() ) {
776 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
778 if ( !aGroupSO->_is_nil() ) {
779 // Update Python script
780 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
782 // Remove group's SObject
783 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
787 // Remove the group from SMESH data structures
788 removeGroup( aGroup->GetLocalID() );
791 //=============================================================================
792 /*! RemoveGroupWithContents
793 * Remove group with its contents
795 //=============================================================================
796 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
797 throw (SALOME::SALOME_Exception)
799 if ( theGroup->_is_nil() )
802 SMESH_GroupBase_i* aGroup =
803 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
807 SMESH::long_array_var anIds = aGroup->GetListOfID();
808 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
810 // Update Python script
811 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
814 if ( aGroup->GetType() == SMESH::NODE )
815 aMeshEditor->RemoveNodes( anIds );
817 aMeshEditor->RemoveElements( anIds );
820 RemoveGroup( theGroup );
822 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
823 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
824 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
828 //================================================================================
830 * \brief Get the list of groups existing in the mesh
831 * \retval SMESH::ListOfGroups * - list of groups
833 //================================================================================
835 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
837 Unexpect aCatch(SALOME_SalomeException);
838 if (MYDEBUG) MESSAGE("GetGroups");
840 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
843 TPythonDump aPythonDump;
844 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
848 aList->length( _mapGroups.size() );
850 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
851 for ( ; it != _mapGroups.end(); it++ ) {
852 if ( CORBA::is_nil( it->second )) continue;
853 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
855 if (i > 1) aPythonDump << ", ";
856 aPythonDump << it->second;
860 catch(SALOME_Exception & S_ex) {
861 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
864 // Update Python script
865 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
866 aPythonDump << " ] = " << _this() << ".GetGroups()";
868 return aList._retn();
870 //=============================================================================
872 * Get number of groups existing in the mesh
874 //=============================================================================
876 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
878 Unexpect aCatch(SALOME_SalomeException);
879 return _mapGroups.size();
882 //=============================================================================
884 * New group is created. All mesh elements that are
885 * present in initial groups are added to the new one
887 //=============================================================================
888 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
889 SMESH::SMESH_GroupBase_ptr theGroup2,
890 const char* theName )
891 throw (SALOME::SALOME_Exception)
895 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
896 theGroup1->GetType() != theGroup2->GetType() )
897 return SMESH::SMESH_Group::_nil();
900 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
901 if ( aResGrp->_is_nil() )
902 return SMESH::SMESH_Group::_nil();
904 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
905 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
907 TColStd_MapOfInteger aResMap;
909 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
910 aResMap.Add( anIds1[ i1 ] );
912 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
913 aResMap.Add( anIds2[ i2 ] );
915 SMESH::long_array_var aResIds = new SMESH::long_array;
916 aResIds->length( aResMap.Extent() );
919 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
920 for( ; anIter.More(); anIter.Next() )
921 aResIds[ resI++ ] = anIter.Key();
923 aResGrp->Add( aResIds );
925 // Clear python lines, created by CreateGroup() and Add()
926 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
927 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
928 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
930 // Update Python script
931 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
932 << theGroup1 << ", " << theGroup2 << ", '"
935 return aResGrp._retn();
939 return SMESH::SMESH_Group::_nil();
943 //=============================================================================
945 \brief Union list of groups. New group is created. All mesh elements that are
946 present in initial groups are added to the new one.
947 \param theGroups list of groups
948 \param theName name of group to be created
949 \return pointer on the group
951 //=============================================================================
952 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionListOfGroups(
953 const SMESH::ListOfGroups& theGroups, const char* theName )
954 throw (SALOME::SALOME_Exception)
957 return SMESH::SMESH_Group::_nil();
961 NCollection_Map< int > anIds;
962 SMESH::ElementType aType = SMESH::ALL;
963 for ( int g = 0, n = theGroups.length(); g < n; g++ )
965 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
966 if ( CORBA::is_nil( aGrp ) )
970 SMESH::ElementType aCurrType = aGrp->GetType();
971 if ( aType == SMESH::ALL )
975 if ( aType != aCurrType )
976 return SMESH::SMESH_Group::_nil();
980 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
981 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
983 int aCurrId = aCurrIds[ i ];
984 anIds.Add( aCurrId );
989 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
990 if ( aResGrp->_is_nil() )
991 return SMESH::SMESH_Group::_nil();
993 // Create array of identifiers
994 SMESH::long_array_var aResIds = new SMESH::long_array;
995 aResIds->length( anIds.Extent() );
997 NCollection_Map< int >::Iterator anIter( anIds );
998 for ( int i = 0; anIter.More(); anIter.Next(), i++ )
1000 aResIds[ i ] = anIter.Value();
1002 aResGrp->Add( aResIds );
1004 // Clear python lines, created by CreateGroup() and Add()
1005 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1006 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1007 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1009 // Update Python script
1011 TPythonDump() << aResGrp << " = " << _this() << ".UnionListOfGroups( "
1012 << &theGroups << ", '" << theName << "' )";
1014 return aResGrp._retn();
1018 return SMESH::SMESH_Group::_nil();
1022 //=============================================================================
1024 * New group is created. All mesh elements that are
1025 * present in both initial groups are added to the new one.
1027 //=============================================================================
1028 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1029 SMESH::SMESH_GroupBase_ptr theGroup2,
1030 const char* theName )
1031 throw (SALOME::SALOME_Exception)
1033 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
1034 theGroup1->GetType() != theGroup2->GetType() )
1035 return SMESH::SMESH_Group::_nil();
1037 // Create Intersection
1038 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
1039 if ( aResGrp->_is_nil() )
1042 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1043 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1045 TColStd_MapOfInteger aMap1;
1047 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1048 aMap1.Add( anIds1[ i1 ] );
1050 TColStd_SequenceOfInteger aSeq;
1052 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1053 if ( aMap1.Contains( anIds2[ i2 ] ) )
1054 aSeq.Append( anIds2[ i2 ] );
1056 SMESH::long_array_var aResIds = new SMESH::long_array;
1057 aResIds->length( aSeq.Length() );
1059 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1060 aResIds[ resI ] = aSeq( resI + 1 );
1062 aResGrp->Add( aResIds );
1064 // Clear python lines, created by CreateGroup() and Add()
1065 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1066 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1067 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1069 // Update Python script
1070 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
1071 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
1073 return aResGrp._retn();
1076 //=============================================================================
1078 \brief Intersect list of groups. New group is created. All mesh elements that
1079 are present in all initial groups simultaneously are added to the new one.
1080 \param theGroups list of groups
1081 \param theName name of group to be created
1082 \return pointer on the group
1084 //=============================================================================
1085 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectListOfGroups(
1086 const SMESH::ListOfGroups& theGroups, const char* theName )
1087 throw (SALOME::SALOME_Exception)
1090 return SMESH::SMESH_Group::_nil();
1094 NCollection_DataMap< int, int > anIdToCount;
1095 SMESH::ElementType aType = SMESH::ALL;
1096 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1098 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1099 if ( CORBA::is_nil( aGrp ) )
1103 SMESH::ElementType aCurrType = aGrp->GetType();
1104 if ( aType == SMESH::ALL )
1108 if ( aType != aCurrType )
1109 return SMESH::SMESH_Group::_nil();
1112 // calculates number of occurance ids in groups
1113 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1114 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1116 int aCurrId = aCurrIds[ i ];
1117 if ( !anIdToCount.IsBound( aCurrId ) )
1118 anIdToCount.Bind( aCurrId, 1 );
1120 anIdToCount( aCurrId ) = anIdToCount( aCurrId ) + 1;
1124 // create map of ids
1125 int nbGrp = theGroups.length();
1126 NCollection_Map< int > anIds;
1127 NCollection_DataMap< int, int >::Iterator anIter( anIdToCount );
1128 for ( ; anIter.More(); anIter.Next() )
1130 int aCurrId = anIter.Key();
1131 int aCurrNb = anIter.Value();
1132 if ( aCurrNb == nbGrp )
1133 anIds.Add( aCurrId );
1137 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
1138 if ( aResGrp->_is_nil() )
1139 return SMESH::SMESH_Group::_nil();
1141 // Create array of identifiers
1142 SMESH::long_array_var aResIds = new SMESH::long_array;
1143 aResIds->length( anIds.Extent() );
1145 NCollection_Map< int >::Iterator aListIter( anIds );
1146 for ( int i = 0; aListIter.More(); aListIter.Next(), i++ )
1148 aResIds[ i ] = aListIter.Value();
1150 aResGrp->Add( aResIds );
1152 // Clear python lines, created by CreateGroup() and Add()
1153 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1154 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1155 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1157 // Update Python script
1159 TPythonDump() << aResGrp << " = " << _this() << ".IntersectListOfGroups( "
1160 << &theGroups << ", '" << theName << "' )";
1162 return aResGrp._retn();
1166 return SMESH::SMESH_Group::_nil();
1170 //=============================================================================
1172 * New group is created. All mesh elements that are present in
1173 * main group but do not present in tool group are added to the new one
1175 //=============================================================================
1176 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1177 SMESH::SMESH_GroupBase_ptr theGroup2,
1178 const char* theName )
1179 throw (SALOME::SALOME_Exception)
1181 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
1182 theGroup1->GetType() != theGroup2->GetType() )
1183 return SMESH::SMESH_Group::_nil();
1186 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
1187 if ( aResGrp->_is_nil() )
1190 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1191 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1193 TColStd_MapOfInteger aMap2;
1195 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1196 aMap2.Add( anIds2[ i2 ] );
1198 TColStd_SequenceOfInteger aSeq;
1199 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1200 if ( !aMap2.Contains( anIds1[ i1 ] ) )
1201 aSeq.Append( anIds1[ i1 ] );
1203 SMESH::long_array_var aResIds = new SMESH::long_array;
1204 aResIds->length( aSeq.Length() );
1206 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1207 aResIds[ resI ] = aSeq( resI + 1 );
1209 aResGrp->Add( aResIds );
1211 // Clear python lines, created by CreateGroup() and Add()
1212 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1213 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1214 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1216 // Update Python script
1217 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1218 << theGroup1 << ", " << theGroup2 << ", '"
1219 << theName << "' )";
1221 return aResGrp._retn();
1224 //=============================================================================
1226 \brief Cut lists of groups. New group is created. All mesh elements that are
1227 present in main groups but do not present in tool groups are added to the new one
1228 \param theMainGroups list of main groups
1229 \param theToolGroups list of tool groups
1230 \param theName name of group to be created
1231 \return pointer on the group
1233 //=============================================================================
1234 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutListOfGroups(
1235 const SMESH::ListOfGroups& theMainGroups,
1236 const SMESH::ListOfGroups& theToolGroups,
1237 const char* theName )
1238 throw (SALOME::SALOME_Exception)
1241 return SMESH::SMESH_Group::_nil();
1245 NCollection_Map< int > aToolIds;
1246 SMESH::ElementType aType = SMESH::ALL;
1248 // iterate through tool groups
1249 for ( g = 0, n = theToolGroups.length(); g < n; g++ )
1251 SMESH::SMESH_GroupBase_var aGrp = theToolGroups[ g ];
1252 if ( CORBA::is_nil( aGrp ) )
1256 SMESH::ElementType aCurrType = aGrp->GetType();
1257 if ( aType == SMESH::ALL )
1261 if ( aType != aCurrType )
1262 return SMESH::SMESH_Group::_nil();
1266 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1267 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1269 int aCurrId = aCurrIds[ i ];
1270 aToolIds.Add( aCurrId );
1274 NCollection_Map< int > anIds; // result
1276 // Iterate through main group
1277 for ( g = 0, n = theMainGroups.length(); g < n; g++ )
1279 SMESH::SMESH_GroupBase_var aGrp = theMainGroups[ g ];
1280 if ( CORBA::is_nil( aGrp ) )
1284 SMESH::ElementType aCurrType = aGrp->GetType();
1285 if ( aType == SMESH::ALL )
1289 if ( aType != aCurrType )
1290 return SMESH::SMESH_Group::_nil();
1294 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1295 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1297 int aCurrId = aCurrIds[ i ];
1298 if ( !aToolIds.Contains( aCurrId ) )
1299 anIds.Add( aCurrId );
1304 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
1305 if ( aResGrp->_is_nil() )
1306 return SMESH::SMESH_Group::_nil();
1308 // Create array of identifiers
1309 SMESH::long_array_var aResIds = new SMESH::long_array;
1310 aResIds->length( anIds.Extent() );
1312 NCollection_Map< int >::Iterator anIter( anIds );
1313 for ( int i = 0; anIter.More(); anIter.Next(), i++ )
1315 aResIds[ i ] = anIter.Value();
1317 aResGrp->Add( aResIds );
1319 // Clear python lines, created by CreateGroup() and Add()
1320 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1321 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1322 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1324 // Update Python script
1326 TPythonDump() << aResGrp << " = " << _this() << ".CutListOfGroups( "
1327 << &theMainGroups << ", " << &theToolGroups << ", '"
1328 << theName << "' )";
1330 return aResGrp._retn();
1334 return SMESH::SMESH_Group::_nil();
1338 //=============================================================================
1340 \brief Create groups of entities from existing groups of superior dimensions
1342 1) extract all nodes from each group,
1343 2) combine all elements of specified dimension laying on these nodes.
1344 \param theGroups list of source groups
1345 \param theElemType dimension of elements
1346 \param theName name of new group
1347 \return pointer on new group
1349 //=============================================================================
1350 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateDimGroup(
1351 const SMESH::ListOfGroups& theGroups,
1352 SMESH::ElementType theElemType,
1353 const char* theName )
1354 throw (SALOME::SALOME_Exception)
1356 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
1358 if ( !theName || !aMeshDS )
1359 return SMESH::SMESH_Group::_nil();
1361 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)theElemType;
1365 // Create map of nodes from all groups
1367 NCollection_Map< int > aNodeMap;
1369 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1371 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1372 if ( CORBA::is_nil( aGrp ) )
1375 SMESH::ElementType aType = aGrp->GetType();
1376 if ( aType == SMESH::ALL )
1378 else if ( aType == SMESH::NODE )
1380 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1381 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1383 int aCurrId = aCurrIds[ i ];
1384 const SMDS_MeshNode* aNode = aMeshDS->FindNode( aCurrId );
1386 aNodeMap.Add( aNode->GetID() );
1391 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1392 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1394 int aCurrId = aCurrIds[ i ];
1395 const SMDS_MeshElement* anElem = aMeshDS->FindElement( aCurrId );
1398 SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
1399 while( aNodeIter->more() )
1401 const SMDS_MeshNode* aNode =
1402 dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
1404 aNodeMap.Add( aNode->GetID() );
1410 // Get result identifiers
1412 NCollection_Map< int > aResultIds;
1413 if ( theElemType == SMESH::NODE )
1415 NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
1416 for ( ; aNodeIter.More(); aNodeIter.Next() )
1417 aResultIds.Add( aNodeIter.Value() );
1421 // Create list of elements of given dimension constructed on the nodes
1422 NCollection_Map< int > anElemList;
1423 NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
1424 for ( ; aNodeIter.More(); aNodeIter.Next() )
1426 const SMDS_MeshElement* aNode =
1427 dynamic_cast<const SMDS_MeshElement*>( aMeshDS->FindNode( aNodeIter.Value() ) );
1431 SMDS_ElemIteratorPtr anElemIter = aNode->elementsIterator( anElemType );
1432 while( anElemIter->more() )
1434 const SMDS_MeshElement* anElem =
1435 dynamic_cast<const SMDS_MeshElement*>( anElemIter->next() );
1436 if ( anElem && anElem->GetType() == anElemType )
1437 anElemList.Add( anElem->GetID() );
1441 // check whether all nodes of elements are present in nodes map
1442 NCollection_Map< int >::Iterator anIter( anElemList );
1443 for ( ; anIter.More(); anIter.Next() )
1445 const SMDS_MeshElement* anElem = aMeshDS->FindElement( anIter.Value() );
1450 SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
1451 while( aNodeIter->more() )
1453 const SMDS_MeshNode* aNode =
1454 dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
1455 if ( !aNode || !aNodeMap.Contains( aNode->GetID() ) )
1462 aResultIds.Add( anElem->GetID() );
1468 SMESH::SMESH_Group_var aResGrp = CreateGroup( theElemType, theName );
1469 if ( aResGrp->_is_nil() )
1470 return SMESH::SMESH_Group::_nil();
1472 // Create array of identifiers
1473 SMESH::long_array_var aResIds = new SMESH::long_array;
1474 aResIds->length( aResultIds.Extent() );
1476 NCollection_Map< int >::Iterator aResIter( aResultIds );
1477 for ( int i = 0; aResIter.More(); aResIter.Next(), i++ )
1478 aResIds[ i ] = aResIter.Value();
1479 aResGrp->Add( aResIds );
1481 // Remove strings corresponding to group creation
1482 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1483 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1484 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1486 // Update Python script
1488 TPythonDump() << aResGrp << " = " << _this() << ".CreateDimGroup( "
1489 << &theGroups << ", " << theElemType << ", '" << theName << "' )";
1491 return aResGrp._retn();
1495 return SMESH::SMESH_Group::_nil();
1499 //================================================================================
1501 * \brief Return group items of a group present in a study
1503 //================================================================================
1505 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
1506 SMESH_Gen_i* theGen,
1507 list<TopoDS_Shape> & theItems)
1509 GEOM::GEOM_Object_var groupObj;
1510 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
1511 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
1512 if ( study->_is_nil() || geomGen->_is_nil() )
1513 return groupObj._retn();
1515 GEOM::GEOM_IGroupOperations_var groupOp =
1516 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
1517 GEOM::GEOM_IShapesOperations_var shapeOp =
1518 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
1520 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
1521 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
1522 return groupObj._retn();
1523 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
1524 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
1525 return groupObj._retn(); // keep only submeshes on groups
1527 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
1528 if ( anIter->_is_nil() ) return groupObj._retn();
1529 for ( ; anIter->More(); anIter->Next())
1531 SALOMEDS::SObject_var aSObject = anIter->Value();
1532 SALOMEDS::SObject_var aRefSO;
1533 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
1535 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
1536 if ( groupObj->_is_nil() ) break;
1537 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1538 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1539 for ( int i = 0; i < ids->length(); ++i ) {
1540 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1541 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1543 theItems.push_back( S );
1548 return groupObj._retn();
1551 //=============================================================================
1553 * \brief Update hypotheses assigned to geom groups if the latter change
1555 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1557 //=============================================================================
1559 void SMESH_Mesh_i::CheckGeomGroupModif()
1561 if ( !_impl->HasShapeToMesh() ) return;
1563 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1564 if ( study->_is_nil() ) return;
1566 // check if items of groups changed
1567 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1568 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1570 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1571 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1572 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1574 int oldID = i_sm->first;
1575 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1576 if ( i_smIor == _mapSubMeshIor.end() )
1578 list< TopoDS_Shape> newItems;
1579 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1580 if ( groupObj->_is_nil() )
1583 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1584 int nbNewItems = newItems.size();
1585 bool groupChanged = ( nbOldItems != nbNewItems);
1586 if ( !groupChanged ) {
1587 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1588 groupChanged = ( oldGroupShape != newItems.front() );
1591 list<TopoDS_Shape>::iterator item = newItems.begin();
1592 for ( ; item != newItems.end() && !groupChanged; ++item )
1594 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1595 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1599 // update hypotheses and submeshes if necessary
1602 // get a new group shape
1603 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1604 if ( !geomClient ) continue;
1605 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1606 geomClient->RemoveShapeFromBuffer( groupIOR );
1607 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1608 // update hypotheses
1609 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1610 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1611 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1613 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1614 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1616 // care of submeshes
1617 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1618 int newID = newSubmesh->GetId();
1619 if ( newID != oldID ) {
1620 _mapSubMesh [ newID ] = newSubmesh;
1621 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1622 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1623 _mapSubMesh.erase (oldID);
1624 _mapSubMesh_i.erase (oldID);
1625 _mapSubMeshIor.erase(oldID);
1626 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1632 //=============================================================================
1636 //=============================================================================
1638 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1640 if(MYDEBUG) MESSAGE( "createSubMesh" );
1641 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1643 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1644 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1645 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1646 SMESH::SMESH_subMesh_var subMesh
1647 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1649 _mapSubMesh[subMeshId] = mySubMesh;
1650 _mapSubMesh_i[subMeshId] = subMeshServant;
1651 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1653 // register CORBA object for persistence
1654 int nextId = _gen_i->RegisterObject( subMesh );
1655 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1657 return subMesh._retn();
1660 //=======================================================================
1661 //function : getSubMesh
1663 //=======================================================================
1665 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1667 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1668 if ( it == _mapSubMeshIor.end() )
1669 return SMESH::SMESH_subMesh::_nil();
1671 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1675 //=============================================================================
1679 //=============================================================================
1681 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1682 GEOM::GEOM_Object_ptr theSubShapeObject )
1684 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1685 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1689 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1690 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1691 removeHypothesis( theSubShapeObject, aHypList[i] );
1694 catch( const SALOME::SALOME_Exception& ) {
1695 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1698 int subMeshId = theSubMesh->GetId();
1700 _mapSubMesh.erase(subMeshId);
1701 _mapSubMesh_i.erase(subMeshId);
1702 _mapSubMeshIor.erase(subMeshId);
1703 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1706 //=============================================================================
1710 //=============================================================================
1712 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1713 const char* theName,
1714 const TopoDS_Shape& theShape )
1717 SMESH::SMESH_GroupBase_var aGroup;
1718 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1719 SMESH_GroupBase_i* aGroupImpl;
1720 if ( !theShape.IsNull() )
1721 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1723 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1725 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1726 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1727 aGroupImpl->Register();
1728 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1730 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1731 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1733 // register CORBA object for persistence
1734 int nextId = _gen_i->RegisterObject( aGroup );
1735 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1737 return aGroup._retn();
1740 //=============================================================================
1742 * SMESH_Mesh_i::removeGroup
1744 * Should be called by ~SMESH_Group_i()
1746 //=============================================================================
1748 void SMESH_Mesh_i::removeGroup( const int theId )
1750 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1751 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1752 _mapGroups.erase( theId );
1753 _impl->RemoveGroup( theId );
1758 //=============================================================================
1762 //=============================================================================
1764 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1765 throw(SALOME::SALOME_Exception)
1767 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1769 SMESH::log_array_var aLog;
1771 list < SMESHDS_Command * >logDS = _impl->GetLog();
1772 aLog = new SMESH::log_array;
1774 int lg = logDS.size();
1777 list < SMESHDS_Command * >::iterator its = logDS.begin();
1778 while(its != logDS.end()){
1779 SMESHDS_Command *com = *its;
1780 int comType = com->GetType();
1782 int lgcom = com->GetNumber();
1784 const list < int >&intList = com->GetIndexes();
1785 int inum = intList.size();
1787 list < int >::const_iterator ii = intList.begin();
1788 const list < double >&coordList = com->GetCoords();
1789 int rnum = coordList.size();
1791 list < double >::const_iterator ir = coordList.begin();
1792 aLog[indexLog].commandType = comType;
1793 aLog[indexLog].number = lgcom;
1794 aLog[indexLog].coords.length(rnum);
1795 aLog[indexLog].indexes.length(inum);
1796 for(int i = 0; i < rnum; i++){
1797 aLog[indexLog].coords[i] = *ir;
1798 //MESSAGE(" "<<i<<" "<<ir.Value());
1801 for(int i = 0; i < inum; i++){
1802 aLog[indexLog].indexes[i] = *ii;
1803 //MESSAGE(" "<<i<<" "<<ii.Value());
1812 catch(SALOME_Exception & S_ex){
1813 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1815 return aLog._retn();
1819 //=============================================================================
1823 //=============================================================================
1825 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1827 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1831 //=============================================================================
1835 //=============================================================================
1837 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1839 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1843 //=============================================================================
1847 //=============================================================================
1849 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1854 //=============================================================================
1858 //=============================================================================
1860 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1862 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1866 //=============================================================================
1870 //=============================================================================
1872 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1874 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1878 //=============================================================================
1880 * Return mesh editor
1882 //=============================================================================
1884 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1886 // Create MeshEditor
1887 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1888 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1890 // Update Python script
1891 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1893 return aMesh._retn();
1896 //=============================================================================
1898 * Return mesh edition previewer
1900 //=============================================================================
1902 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1904 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1905 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1906 return aMesh._retn();
1909 //=============================================================================
1913 //=============================================================================
1914 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1916 Unexpect aCatch(SALOME_SalomeException);
1917 _impl->SetAutoColor(theAutoColor);
1920 //=============================================================================
1924 //=============================================================================
1925 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1927 Unexpect aCatch(SALOME_SalomeException);
1928 return _impl->GetAutoColor();
1932 //=============================================================================
1934 * Export in different formats
1936 //=============================================================================
1938 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1940 return _impl->HasDuplicatedGroupNamesMED();
1943 void SMESH_Mesh_i::PrepareForWriting (const char* file)
1945 TCollection_AsciiString aFullName ((char*)file);
1946 OSD_Path aPath (aFullName);
1947 OSD_File aFile (aPath);
1948 if (aFile.Exists()) {
1949 // existing filesystem node
1950 if (aFile.KindOfFile() == OSD_FILE) {
1951 if (aFile.IsWriteable()) {
1954 if (aFile.Failed()) {
1955 TCollection_AsciiString msg ("File ");
1956 msg += aFullName + " cannot be replaced.";
1957 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1960 TCollection_AsciiString msg ("File ");
1961 msg += aFullName + " cannot be overwritten.";
1962 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1965 TCollection_AsciiString msg ("Location ");
1966 msg += aFullName + " is not a file.";
1967 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1970 // nonexisting file; check if it can be created
1972 aFile.Build(OSD_WriteOnly, OSD_Protection());
1973 if (aFile.Failed()) {
1974 TCollection_AsciiString msg ("You cannot create the file ");
1975 msg += aFullName + ". Check the directory existance and access rights.";
1976 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1984 void SMESH_Mesh_i::ExportToMED (const char* file,
1985 CORBA::Boolean auto_groups,
1986 SMESH::MED_VERSION theVersion)
1987 throw(SALOME::SALOME_Exception)
1989 Unexpect aCatch(SALOME_SalomeException);
1992 PrepareForWriting(file);
1993 const char* aMeshName = "Mesh";
1994 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1995 if ( !aStudy->_is_nil() ) {
1996 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1997 if ( !aMeshSO->_is_nil() ) {
1998 aMeshName = aMeshSO->GetName();
1999 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
2000 if ( !aStudy->GetProperties()->IsLocked() )
2002 SALOMEDS::GenericAttribute_var anAttr;
2003 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2004 SALOMEDS::AttributeExternalFileDef_var aFileName;
2005 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
2006 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
2007 ASSERT(!aFileName->_is_nil());
2008 aFileName->SetValue(file);
2009 SALOMEDS::AttributeFileType_var aFileType;
2010 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
2011 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
2012 ASSERT(!aFileType->_is_nil());
2013 aFileType->SetValue("FICHIERMED");
2017 // Update Python script
2018 // set name of mesh before export
2019 TPythonDump() << _gen_i << ".SetName(" << _this() << ", '" << aMeshName << "')";
2021 // check names of groups
2024 TPythonDump() << _this() << ".ExportToMED( '"
2025 << file << "', " << auto_groups << ", " << theVersion << " )";
2027 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
2030 void SMESH_Mesh_i::ExportMED (const char* file,
2031 CORBA::Boolean auto_groups)
2032 throw(SALOME::SALOME_Exception)
2034 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
2037 void SMESH_Mesh_i::ExportDAT (const char *file)
2038 throw(SALOME::SALOME_Exception)
2040 Unexpect aCatch(SALOME_SalomeException);
2042 // Update Python script
2043 // check names of groups
2045 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
2048 PrepareForWriting(file);
2049 _impl->ExportDAT(file);
2052 void SMESH_Mesh_i::ExportUNV (const char *file)
2053 throw(SALOME::SALOME_Exception)
2055 Unexpect aCatch(SALOME_SalomeException);
2057 // Update Python script
2058 // check names of groups
2060 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
2063 PrepareForWriting(file);
2064 _impl->ExportUNV(file);
2067 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
2068 throw(SALOME::SALOME_Exception)
2070 Unexpect aCatch(SALOME_SalomeException);
2072 // Update Python script
2073 // check names of groups
2075 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
2078 PrepareForWriting(file);
2079 _impl->ExportSTL(file, isascii);
2082 //=============================================================================
2086 //=============================================================================
2088 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
2090 Unexpect aCatch(SALOME_SalomeException);
2091 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
2092 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
2093 return aMesh._retn();
2096 //=============================================================================
2100 //=============================================================================
2101 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
2103 Unexpect aCatch(SALOME_SalomeException);
2104 return _impl->NbNodes();
2107 //=============================================================================
2111 //=============================================================================
2112 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
2114 Unexpect aCatch(SALOME_SalomeException);
2115 return NbEdges() + NbFaces() + NbVolumes();
2118 //=============================================================================
2122 //=============================================================================
2123 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
2125 Unexpect aCatch(SALOME_SalomeException);
2126 return _impl->NbEdges();
2129 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
2130 throw(SALOME::SALOME_Exception)
2132 Unexpect aCatch(SALOME_SalomeException);
2133 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
2136 //=============================================================================
2140 //=============================================================================
2141 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
2143 Unexpect aCatch(SALOME_SalomeException);
2144 return _impl->NbFaces();
2147 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
2149 Unexpect aCatch(SALOME_SalomeException);
2150 return _impl->NbTriangles();
2153 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
2155 Unexpect aCatch(SALOME_SalomeException);
2156 return _impl->NbQuadrangles();
2159 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
2161 Unexpect aCatch(SALOME_SalomeException);
2162 return _impl->NbPolygons();
2165 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
2166 throw(SALOME::SALOME_Exception)
2168 Unexpect aCatch(SALOME_SalomeException);
2169 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
2172 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
2173 throw(SALOME::SALOME_Exception)
2175 Unexpect aCatch(SALOME_SalomeException);
2176 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
2179 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
2180 throw(SALOME::SALOME_Exception)
2182 Unexpect aCatch(SALOME_SalomeException);
2183 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
2186 //=============================================================================
2190 //=============================================================================
2191 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
2193 Unexpect aCatch(SALOME_SalomeException);
2194 return _impl->NbVolumes();
2197 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
2199 Unexpect aCatch(SALOME_SalomeException);
2200 return _impl->NbTetras();
2203 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
2205 Unexpect aCatch(SALOME_SalomeException);
2206 return _impl->NbHexas();
2209 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
2211 Unexpect aCatch(SALOME_SalomeException);
2212 return _impl->NbPyramids();
2215 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
2217 Unexpect aCatch(SALOME_SalomeException);
2218 return _impl->NbPrisms();
2221 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
2223 Unexpect aCatch(SALOME_SalomeException);
2224 return _impl->NbPolyhedrons();
2227 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
2228 throw(SALOME::SALOME_Exception)
2230 Unexpect aCatch(SALOME_SalomeException);
2231 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
2234 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
2235 throw(SALOME::SALOME_Exception)
2237 Unexpect aCatch(SALOME_SalomeException);
2238 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
2241 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
2242 throw(SALOME::SALOME_Exception)
2244 Unexpect aCatch(SALOME_SalomeException);
2245 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
2248 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
2249 throw(SALOME::SALOME_Exception)
2251 Unexpect aCatch(SALOME_SalomeException);
2252 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
2255 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
2256 throw(SALOME::SALOME_Exception)
2258 Unexpect aCatch(SALOME_SalomeException);
2259 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
2262 //=============================================================================
2266 //=============================================================================
2267 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
2269 Unexpect aCatch(SALOME_SalomeException);
2270 return _impl->NbSubMesh();
2273 //=============================================================================
2277 //=============================================================================
2278 char* SMESH_Mesh_i::Dump()
2280 std::ostringstream os;
2282 return CORBA::string_dup( os.str().c_str() );
2285 //=============================================================================
2289 //=============================================================================
2290 SMESH::long_array* SMESH_Mesh_i::GetIDs()
2292 // SMESH::long_array_var aResult = new SMESH::long_array();
2293 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2294 // int aMinId = aSMESHDS_Mesh->MinElementID();
2295 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
2297 // aResult->length(aMaxId - aMinId + 1);
2299 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
2300 // aResult[i++] = id;
2302 // return aResult._retn();
2304 return GetElementsId();
2307 //=============================================================================
2311 //=============================================================================
2313 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
2314 throw (SALOME::SALOME_Exception)
2316 Unexpect aCatch(SALOME_SalomeException);
2317 MESSAGE("SMESH_Mesh_i::GetElementsId");
2318 SMESH::long_array_var aResult = new SMESH::long_array();
2319 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2321 if ( aSMESHDS_Mesh == NULL )
2322 return aResult._retn();
2324 long nbElements = NbElements();
2325 aResult->length( nbElements );
2326 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
2327 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
2328 aResult[i] = anIt->next()->GetID();
2330 return aResult._retn();
2334 //=============================================================================
2338 //=============================================================================
2340 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
2341 throw (SALOME::SALOME_Exception)
2343 Unexpect aCatch(SALOME_SalomeException);
2344 MESSAGE("SMESH_subMesh_i::GetElementsByType");
2345 SMESH::long_array_var aResult = new SMESH::long_array();
2346 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2348 if ( aSMESHDS_Mesh == NULL )
2349 return aResult._retn();
2351 long nbElements = NbElements();
2353 // No sense in returning ids of elements along with ids of nodes:
2354 // when theElemType == SMESH::ALL, return node ids only if
2355 // there are no elements
2356 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
2357 return GetNodesId();
2359 aResult->length( nbElements );
2363 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
2364 while ( i < nbElements && anIt->more() ) {
2365 const SMDS_MeshElement* anElem = anIt->next();
2366 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
2367 aResult[i++] = anElem->GetID();
2370 aResult->length( i );
2372 return aResult._retn();
2375 //=============================================================================
2379 //=============================================================================
2381 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
2382 throw (SALOME::SALOME_Exception)
2384 Unexpect aCatch(SALOME_SalomeException);
2385 MESSAGE("SMESH_subMesh_i::GetNodesId");
2386 SMESH::long_array_var aResult = new SMESH::long_array();
2387 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2389 if ( aSMESHDS_Mesh == NULL )
2390 return aResult._retn();
2392 long nbNodes = NbNodes();
2393 aResult->length( nbNodes );
2394 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
2395 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
2396 aResult[i] = anIt->next()->GetID();
2398 return aResult._retn();
2401 //=============================================================================
2405 //=============================================================================
2407 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
2408 throw (SALOME::SALOME_Exception)
2410 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
2414 //=============================================================================
2416 * Returns ID of elements for given submesh
2418 //=============================================================================
2419 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
2420 throw (SALOME::SALOME_Exception)
2422 SMESH::long_array_var aResult = new SMESH::long_array();
2424 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2425 if(!SM) return aResult._retn();
2427 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2428 if(!SDSM) return aResult._retn();
2430 aResult->length(SDSM->NbElements());
2432 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2434 while ( eIt->more() ) {
2435 aResult[i++] = eIt->next()->GetID();
2438 return aResult._retn();
2442 //=============================================================================
2444 * Returns ID of nodes for given submesh
2445 * If param all==true - returns all nodes, else -
2446 * returns only nodes on shapes.
2448 //=============================================================================
2449 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
2450 throw (SALOME::SALOME_Exception)
2452 SMESH::long_array_var aResult = new SMESH::long_array();
2454 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2455 if(!SM) return aResult._retn();
2457 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2458 if(!SDSM) return aResult._retn();
2461 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
2462 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
2463 while ( nIt->more() ) {
2464 const SMDS_MeshNode* elem = nIt->next();
2465 theElems.insert( elem->GetID() );
2468 else { // all nodes of submesh elements
2469 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2470 while ( eIt->more() ) {
2471 const SMDS_MeshElement* anElem = eIt->next();
2472 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
2473 while ( nIt->more() ) {
2474 const SMDS_MeshElement* elem = nIt->next();
2475 theElems.insert( elem->GetID() );
2480 aResult->length(theElems.size());
2481 set<int>::iterator itElem;
2483 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
2484 aResult[i++] = *itElem;
2486 return aResult._retn();
2490 //=============================================================================
2492 * Returns type of elements for given submesh
2494 //=============================================================================
2495 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2496 throw (SALOME::SALOME_Exception)
2498 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2499 if(!SM) return SMESH::ALL;
2501 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2502 if(!SDSM) return SMESH::ALL;
2504 if(SDSM->NbElements()==0)
2505 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2507 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2508 const SMDS_MeshElement* anElem = eIt->next();
2509 return ( SMESH::ElementType ) anElem->GetType();
2513 //=============================================================================
2517 //=============================================================================
2519 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2521 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2523 MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
2528 //=============================================================================
2530 * Get XYZ coordinates of node as list of double
2531 * If there is not node for given ID - returns empty list
2533 //=============================================================================
2535 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2537 SMESH::double_array_var aResult = new SMESH::double_array();
2538 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2539 if ( aSMESHDS_Mesh == NULL )
2540 return aResult._retn();
2543 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2545 return aResult._retn();
2549 aResult[0] = aNode->X();
2550 aResult[1] = aNode->Y();
2551 aResult[2] = aNode->Z();
2552 return aResult._retn();
2556 //=============================================================================
2558 * For given node returns list of IDs of inverse elements
2559 * If there is not node for given ID - returns empty list
2561 //=============================================================================
2563 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2565 SMESH::long_array_var aResult = new SMESH::long_array();
2566 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2567 if ( aSMESHDS_Mesh == NULL )
2568 return aResult._retn();
2571 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2573 return aResult._retn();
2575 // find inverse elements
2576 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2577 TColStd_SequenceOfInteger IDs;
2578 while(eIt->more()) {
2579 const SMDS_MeshElement* elem = eIt->next();
2580 IDs.Append(elem->GetID());
2582 if(IDs.Length()>0) {
2583 aResult->length(IDs.Length());
2585 for(; i<=IDs.Length(); i++) {
2586 aResult[i-1] = IDs.Value(i);
2589 return aResult._retn();
2592 //=============================================================================
2594 * \brief Return position of a node on shape
2596 //=============================================================================
2598 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2600 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2601 aNodePosition->shapeID = 0;
2602 aNodePosition->shapeType = GEOM::SHAPE;
2604 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2605 if ( !mesh ) return aNodePosition;
2607 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2609 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2611 aNodePosition->shapeID = pos->GetShapeId();
2612 switch ( pos->GetTypeOfPosition() ) {
2614 aNodePosition->shapeType = GEOM::EDGE;
2615 aNodePosition->params.length(1);
2616 aNodePosition->params[0] =
2617 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2620 aNodePosition->shapeType = GEOM::FACE;
2621 aNodePosition->params.length(2);
2622 aNodePosition->params[0] =
2623 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2624 aNodePosition->params[1] =
2625 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2627 case SMDS_TOP_VERTEX:
2628 aNodePosition->shapeType = GEOM::VERTEX;
2630 case SMDS_TOP_3DSPACE:
2631 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2632 aNodePosition->shapeType = GEOM::SOLID;
2633 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2634 aNodePosition->shapeType = GEOM::SHELL;
2640 return aNodePosition;
2643 //=============================================================================
2645 * If given element is node returns IDs of shape from position
2646 * If there is not node for given ID - returns -1
2648 //=============================================================================
2650 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2652 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2653 if ( aSMESHDS_Mesh == NULL )
2657 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2659 SMDS_PositionPtr pos = aNode->GetPosition();
2663 return pos->GetShapeId();
2670 //=============================================================================
2672 * For given element returns ID of result shape after
2673 * ::FindShape() from SMESH_MeshEditor
2674 * If there is not element for given ID - returns -1
2676 //=============================================================================
2678 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2680 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2681 if ( aSMESHDS_Mesh == NULL )
2684 // try to find element
2685 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2689 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2690 ::SMESH_MeshEditor aMeshEditor(_impl);
2691 int index = aMeshEditor.FindShape( elem );
2699 //=============================================================================
2701 * Returns number of nodes for given element
2702 * If there is not element for given ID - returns -1
2704 //=============================================================================
2706 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2708 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2709 if ( aSMESHDS_Mesh == NULL ) return -1;
2710 // try to find element
2711 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2712 if(!elem) return -1;
2713 return elem->NbNodes();
2717 //=============================================================================
2719 * Returns ID of node by given index for given element
2720 * If there is not element for given ID - returns -1
2721 * If there is not node for given index - returns -2
2723 //=============================================================================
2725 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2727 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2728 if ( aSMESHDS_Mesh == NULL ) return -1;
2729 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2730 if(!elem) return -1;
2731 if( index>=elem->NbNodes() || index<0 ) return -1;
2732 return elem->GetNode(index)->GetID();
2735 //=============================================================================
2737 * Returns IDs of nodes of given element
2739 //=============================================================================
2741 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2743 SMESH::long_array_var aResult = new SMESH::long_array();
2744 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2746 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2748 aResult->length( elem->NbNodes() );
2749 for ( int i = 0; i < elem->NbNodes(); ++i )
2750 aResult[ i ] = elem->GetNode( i )->GetID();
2753 return aResult._retn();
2756 //=============================================================================
2758 * Returns true if given node is medium node
2759 * in given quadratic element
2761 //=============================================================================
2763 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2765 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2766 if ( aSMESHDS_Mesh == NULL ) return false;
2768 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2769 if(!aNode) return false;
2770 // try to find element
2771 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2772 if(!elem) return false;
2774 return elem->IsMediumNode(aNode);
2778 //=============================================================================
2780 * Returns true if given node is medium node
2781 * in one of quadratic elements
2783 //=============================================================================
2785 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2786 SMESH::ElementType theElemType)
2788 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2789 if ( aSMESHDS_Mesh == NULL ) return false;
2792 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2793 if(!aNode) return false;
2795 SMESH_MesherHelper aHelper( *(_impl) );
2797 SMDSAbs_ElementType aType;
2798 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2799 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2800 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2801 else aType = SMDSAbs_All;
2803 return aHelper.IsMedium(aNode,aType);
2807 //=============================================================================
2809 * Returns number of edges for given element
2811 //=============================================================================
2813 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2815 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2816 if ( aSMESHDS_Mesh == NULL ) return -1;
2817 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2818 if(!elem) return -1;
2819 return elem->NbEdges();
2823 //=============================================================================
2825 * Returns number of faces for given element
2827 //=============================================================================
2829 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2831 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2832 if ( aSMESHDS_Mesh == NULL ) return -1;
2833 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2834 if(!elem) return -1;
2835 return elem->NbFaces();
2839 //=============================================================================
2841 * Returns true if given element is polygon
2843 //=============================================================================
2845 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2847 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2848 if ( aSMESHDS_Mesh == NULL ) return false;
2849 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2850 if(!elem) return false;
2851 return elem->IsPoly();
2855 //=============================================================================
2857 * Returns true if given element is quadratic
2859 //=============================================================================
2861 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2863 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2864 if ( aSMESHDS_Mesh == NULL ) return false;
2865 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2866 if(!elem) return false;
2867 return elem->IsQuadratic();
2871 //=============================================================================
2873 * Returns bary center for given element
2875 //=============================================================================
2877 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2879 SMESH::double_array_var aResult = new SMESH::double_array();
2880 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2881 if ( aSMESHDS_Mesh == NULL )
2882 return aResult._retn();
2884 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2886 return aResult._retn();
2888 if(elem->GetType()==SMDSAbs_Volume) {
2889 SMDS_VolumeTool aTool;
2890 if(aTool.Set(elem)) {
2892 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2897 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2899 double x=0., y=0., z=0.;
2900 for(; anIt->more(); ) {
2902 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2916 return aResult._retn();
2920 //=============================================================================
2922 * Create and publish group servants if any groups were imported or created anyhow
2924 //=============================================================================
2926 void SMESH_Mesh_i::CreateGroupServants()
2928 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2930 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2931 while ( groupIt->more() )
2933 ::SMESH_Group* group = groupIt->next();
2934 int anId = group->GetGroupDS()->GetID();
2936 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
2937 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2940 SMESH_GroupBase_i* aGroupImpl;
2942 if ( SMESHDS_GroupOnGeom* groupOnGeom =
2943 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
2945 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2946 shape = groupOnGeom->GetShape();
2949 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2952 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
2953 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2954 aGroupImpl->Register();
2956 SMESH::SMESH_GroupBase_var groupVar =
2957 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2958 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
2960 // register CORBA object for persistence
2961 int nextId = _gen_i->RegisterObject( groupVar );
2962 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2964 // publishing of the groups in the study
2965 if ( !aStudy->_is_nil() ) {
2966 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
2967 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
2972 //=============================================================================
2974 * \brief Return groups cantained in _mapGroups by their IDs
2976 //=============================================================================
2978 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
2980 int nbGroups = groupIDs.size();
2981 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
2982 aList->length( nbGroups );
2984 list<int>::const_iterator ids = groupIDs.begin();
2985 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
2987 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
2988 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2989 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
2991 aList->length( nbGroups );
2992 return aList._retn();
2995 //=============================================================================
2997 * \brief Return information about imported file
2999 //=============================================================================
3001 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
3003 SALOME_MED::MedFileInfo_var res( myFileInfo );
3004 if ( !res.operator->() ) {
3005 res = new SALOME_MED::MedFileInfo;
3007 res->fileSize = res->major = res->minor = res->release = -1;
3012 //=============================================================================
3014 * \brief Check and correct names of mesh groups
3016 //=============================================================================
3018 void SMESH_Mesh_i::checkGroupNames()
3020 int nbGrp = NbGroups();
3024 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
3025 if ( aStudy->_is_nil() )
3026 return; // nothing to do
3028 SMESH::ListOfGroups* grpList = 0;
3029 // avoid dump of "GetGroups"
3031 // store python dump into a local variable inside local scope
3032 SMESH::TPythonDump pDump; // do not delete this line of code
3033 grpList = GetGroups();
3036 for ( int gIndx = 0; gIndx < nbGrp; gIndx++ ) {
3037 SMESH::SMESH_GroupBase_ptr aGrp = (*grpList)[ gIndx ];
3040 SALOMEDS::SObject_var aGrpSO = _gen_i->ObjectToSObject( aStudy, aGrp );
3041 if ( aGrpSO->_is_nil() )
3043 // correct name of the mesh group if necessary
3044 const char* guiName = aGrpSO->GetName();
3045 if ( strcmp(guiName, aGrp->GetName()) )
3046 aGrp->SetName( guiName );