1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_Mesh_i.cxx
24 // Author : Paul RASCLE, EDF
27 #include "SMESH_Mesh_i.hxx"
29 #include "SMESH_Filter_i.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Group_i.hxx"
32 #include "SMESH_MEDMesh_i.hxx"
33 #include "SMESH_MeshEditor_i.hxx"
34 #include "SMESH_PythonDump.hxx"
35 #include "SMESH_subMesh_i.hxx"
37 #include "DriverMED_R_SMESHDS_Mesh.h"
38 #include "DriverMED_W_SMESHDS_Mesh.h"
39 #include "SMDS_VolumeTool.hxx"
40 #include "SMESHDS_Command.hxx"
41 #include "SMESHDS_CommandType.hxx"
42 #include "SMESHDS_GroupOnGeom.hxx"
43 #include "SMESH_Group.hxx"
44 #include "SMESH_MeshEditor.hxx"
45 #include "SMESH_MesherHelper.hxx"
46 #include "SMDS_EdgePosition.hxx"
47 #include "SMDS_FacePosition.hxx"
50 #include "SALOME_NamingService.hxx"
51 #include "Utils_CorbaException.hxx"
52 #include "Utils_ExceptHandlers.hxx"
53 #include "Utils_SINGLETON.hxx"
54 #include "utilities.h"
55 #include "GEOMImpl_Types.hxx"
58 #include <BRep_Builder.hxx>
59 #include <OSD_Directory.hxx>
60 #include <OSD_File.hxx>
61 #include <OSD_Path.hxx>
62 #include <OSD_Protection.hxx>
63 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
64 #include <TColStd_MapOfInteger.hxx>
65 #include <TColStd_SequenceOfInteger.hxx>
66 #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);
151 // to track changes of GEOM groups
152 addGeomGroupData( theShapeObject, _this() );
155 //================================================================================
157 * \brief return true if mesh has a shape to build a shape on
159 //================================================================================
161 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
162 throw (SALOME::SALOME_Exception)
164 Unexpect aCatch(SALOME_SalomeException);
167 res = _impl->HasShapeToMesh();
169 catch(SALOME_Exception & S_ex) {
170 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
175 //=======================================================================
176 //function : GetShapeToMesh
178 //=======================================================================
180 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
181 throw (SALOME::SALOME_Exception)
183 Unexpect aCatch(SALOME_SalomeException);
184 GEOM::GEOM_Object_var aShapeObj;
186 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
188 aShapeObj = _gen_i->ShapeToGeomObject( S );
190 catch(SALOME_Exception & S_ex) {
191 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
193 return aShapeObj._retn();
196 //================================================================================
198 * \brief Remove all nodes and elements
200 //================================================================================
202 void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
204 Unexpect aCatch(SALOME_SalomeException);
207 CheckGeomGroupModif(); // issue 20145
209 catch(SALOME_Exception & S_ex) {
210 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
212 TPythonDump() << _this() << ".Clear()";
215 //================================================================================
217 * \brief Remove all nodes and elements for indicated shape
219 //================================================================================
221 void SMESH_Mesh_i::ClearSubMesh(CORBA::Long ShapeID)
222 throw (SALOME::SALOME_Exception)
224 Unexpect aCatch(SALOME_SalomeException);
226 _impl->ClearSubMesh( ShapeID );
228 catch(SALOME_Exception & S_ex) {
229 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
233 //=============================================================================
237 //=============================================================================
239 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
241 SMESH::DriverMED_ReadStatus res;
244 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
245 res = SMESH::DRS_OK; break;
246 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
247 res = SMESH::DRS_EMPTY; break;
248 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
249 res = SMESH::DRS_WARN_RENUMBER; break;
250 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
251 res = SMESH::DRS_WARN_SKIP_ELEM; break;
252 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
254 res = SMESH::DRS_FAIL; break;
259 //=============================================================================
263 * Imports mesh data from MED file
265 //=============================================================================
267 SMESH::DriverMED_ReadStatus
268 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
269 throw ( SALOME::SALOME_Exception )
271 Unexpect aCatch(SALOME_SalomeException);
274 status = _impl->MEDToMesh( theFileName, theMeshName );
276 catch( SALOME_Exception& S_ex ) {
277 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
280 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
283 CreateGroupServants();
285 int major, minor, release;
286 if( !MED::getMEDVersion( theFileName, major, minor, release ) )
287 major = minor = release = -1;
288 myFileInfo = new SALOME_MED::MedFileInfo();
289 myFileInfo->fileName = theFileName;
290 myFileInfo->fileSize = 0;
293 if ( ::_stati64( theFileName, &d ) != -1 )
296 if ( ::stat64( theFileName, &d ) != -1 )
298 myFileInfo->fileSize = d.st_size;
299 myFileInfo->major = major;
300 myFileInfo->minor = minor;
301 myFileInfo->release = release;
303 return ConvertDriverMEDReadStatus(status);
306 //================================================================================
308 * \brief Return string representation of a MED file version comprising nbDigits
310 //================================================================================
312 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
314 std::string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
316 return CORBA::string_dup( ver.c_str() );
319 //=============================================================================
323 * Imports mesh data from MED file
325 //=============================================================================
327 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
328 throw ( SALOME::SALOME_Exception )
330 // Read mesh with name = <theMeshName> into SMESH_Mesh
331 _impl->UNVToMesh( theFileName );
333 CreateGroupServants();
338 //=============================================================================
342 * Imports mesh data from STL file
344 //=============================================================================
345 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
346 throw ( SALOME::SALOME_Exception )
348 // Read mesh with name = <theMeshName> into SMESH_Mesh
349 _impl->STLToMesh( theFileName );
354 //=============================================================================
358 * Imports mesh data from MED file
360 //=============================================================================
362 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
364 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
365 // int status = _impl->MEDToMesh( theFileName, theMeshName );
366 // CreateGroupServants();
371 //=============================================================================
375 //=============================================================================
377 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
379 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
380 (SMESH_Hypothesis::Hypothesis_Status theStatus)
383 RETURNCASE( HYP_OK );
384 RETURNCASE( HYP_MISSING );
385 RETURNCASE( HYP_CONCURENT );
386 RETURNCASE( HYP_BAD_PARAMETER );
387 RETURNCASE( HYP_HIDDEN_ALGO );
388 RETURNCASE( HYP_HIDING_ALGO );
389 RETURNCASE( HYP_UNKNOWN_FATAL );
390 RETURNCASE( HYP_INCOMPATIBLE );
391 RETURNCASE( HYP_NOTCONFORM );
392 RETURNCASE( HYP_ALREADY_EXIST );
393 RETURNCASE( HYP_BAD_DIM );
394 RETURNCASE( HYP_BAD_SUBSHAPE );
395 RETURNCASE( HYP_BAD_GEOMETRY );
396 RETURNCASE( HYP_NEED_SHAPE );
399 return SMESH::HYP_UNKNOWN_FATAL;
402 //=============================================================================
406 * calls internal addHypothesis() and then adds a reference to <anHyp> under
407 * the SObject actually having a reference to <aSubShape>.
408 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
410 //=============================================================================
412 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
413 SMESH::SMESH_Hypothesis_ptr anHyp)
414 throw(SALOME::SALOME_Exception)
416 Unexpect aCatch(SALOME_SalomeException);
417 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
419 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
420 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
421 aSubShapeObject, anHyp );
423 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
425 // Update Python script
426 if(_impl->HasShapeToMesh()) {
427 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
428 << aSubShapeObject << ", " << anHyp << " )";
431 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
434 return ConvertHypothesisStatus(status);
437 //=============================================================================
441 //=============================================================================
443 SMESH_Hypothesis::Hypothesis_Status
444 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
445 SMESH::SMESH_Hypothesis_ptr anHyp)
447 if(MYDEBUG) MESSAGE("addHypothesis");
449 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
450 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
453 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
454 if (CORBA::is_nil(myHyp))
455 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
458 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
461 TopoDS_Shape myLocSubShape;
462 //use PseudoShape in case if mesh has no shape
464 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
466 myLocSubShape = _impl->GetShapeToMesh();
468 int hypId = myHyp->GetId();
469 status = _impl->AddHypothesis(myLocSubShape, hypId);
470 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
471 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
472 // assure there is a corresponding submesh
473 if ( !_impl->IsMainShape( myLocSubShape )) {
474 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
475 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
476 createSubMesh( aSubShapeObject );
480 catch(SALOME_Exception & S_ex)
482 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
487 //=============================================================================
491 //=============================================================================
493 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
494 SMESH::SMESH_Hypothesis_ptr anHyp)
495 throw(SALOME::SALOME_Exception)
497 Unexpect aCatch(SALOME_SalomeException);
498 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
500 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
501 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
502 aSubShapeObject, anHyp );
504 // Update Python script
505 // Update Python script
506 if(_impl->HasShapeToMesh()) {
507 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
508 << aSubShapeObject << ", " << anHyp << " )";
511 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
515 return ConvertHypothesisStatus(status);
518 //=============================================================================
522 //=============================================================================
524 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
525 SMESH::SMESH_Hypothesis_ptr anHyp)
527 if(MYDEBUG) MESSAGE("removeHypothesis()");
528 // **** proposer liste de subShape (selection multiple)
530 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
531 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
534 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
535 if (CORBA::is_nil(myHyp))
536 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
539 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
542 TopoDS_Shape myLocSubShape;
543 //use PseudoShape in case if mesh has no shape
545 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
547 myLocSubShape = _impl->GetShapeToMesh();
549 int hypId = myHyp->GetId();
550 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
551 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
552 _mapHypo.erase( hypId );
554 catch(SALOME_Exception & S_ex)
556 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
561 //=============================================================================
565 //=============================================================================
567 SMESH::ListOfHypothesis *
568 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
569 throw(SALOME::SALOME_Exception)
571 Unexpect aCatch(SALOME_SalomeException);
572 if (MYDEBUG) MESSAGE("GetHypothesisList");
573 if (_impl->HasShapeToMesh() && CORBA::is_nil(aSubShapeObject))
574 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
577 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
580 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
581 if ( myLocSubShape.IsNull() && !_impl->HasShapeToMesh() )
582 myLocSubShape = _impl->GetShapeToMesh();
583 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
584 int i = 0, n = aLocalList.size();
587 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
588 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
589 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
590 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
595 catch(SALOME_Exception & S_ex) {
596 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
599 return aList._retn();
602 //=============================================================================
606 //=============================================================================
607 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
608 const char* theName )
609 throw(SALOME::SALOME_Exception)
611 Unexpect aCatch(SALOME_SalomeException);
612 MESSAGE("SMESH_Mesh_i::GetSubMesh");
613 if (CORBA::is_nil(aSubShapeObject))
614 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
617 SMESH::SMESH_subMesh_var subMesh;
618 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
620 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
622 //Get or Create the SMESH_subMesh object implementation
624 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
625 subMesh = getSubMesh( subMeshId );
627 // create a new subMesh object servant if there is none for the shape
628 if ( subMesh->_is_nil() )
629 subMesh = createSubMesh( aSubShapeObject );
630 if ( _gen_i->CanPublishInStudy( subMesh )) {
631 SALOMEDS::SObject_var aSO =
632 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
633 subMesh, aSubShapeObject, theName );
634 if ( !aSO->_is_nil()) {
635 // Update Python script
636 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
637 << aSubShapeObject << ", '" << theName << "' )";
641 catch(SALOME_Exception & S_ex) {
642 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
644 return subMesh._retn();
647 //=============================================================================
651 //=============================================================================
653 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
654 throw (SALOME::SALOME_Exception)
656 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
657 if ( theSubMesh->_is_nil() )
660 GEOM::GEOM_Object_var aSubShapeObject;
661 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
662 if ( !aStudy->_is_nil() ) {
663 // Remove submesh's SObject
664 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
665 if ( !anSO->_is_nil() ) {
666 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
667 SALOMEDS::SObject_var anObj, aRef;
668 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
669 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
671 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
673 // Update Python script
674 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
678 removeSubMesh( theSubMesh, aSubShapeObject.in() );
681 //=============================================================================
685 //=============================================================================
686 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
687 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
689 switch (theElemType) {
694 CASE2STRING( VOLUME );
700 //=============================================================================
704 //=============================================================================
706 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
707 const char* theName )
708 throw(SALOME::SALOME_Exception)
710 Unexpect aCatch(SALOME_SalomeException);
711 SMESH::SMESH_Group_var aNewGroup =
712 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
714 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
715 SALOMEDS::SObject_var aSO =
716 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
717 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
718 if ( !aSO->_is_nil()) {
719 // Update Python script
720 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
721 << ElementTypeString(theElemType) << ", '" << theName << "' )";
724 return aNewGroup._retn();
728 //=============================================================================
732 //=============================================================================
733 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
735 GEOM::GEOM_Object_ptr theGeomObj)
736 throw(SALOME::SALOME_Exception)
738 Unexpect aCatch(SALOME_SalomeException);
739 SMESH::SMESH_GroupOnGeom_var aNewGroup;
741 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
742 if ( !aShape.IsNull() )
744 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
745 ( createGroup( theElemType, theName, aShape ));
747 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
748 SALOMEDS::SObject_var aSO =
749 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
750 aNewGroup, theGeomObj, theName);
751 if ( !aSO->_is_nil()) {
752 // Update Python script
753 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
754 << ElementTypeString(theElemType) << ", '" << theName << "', "
755 << theGeomObj << " )";
760 return aNewGroup._retn();
763 //=============================================================================
767 //=============================================================================
769 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
770 throw (SALOME::SALOME_Exception)
772 if ( theGroup->_is_nil() )
775 SMESH_GroupBase_i* aGroup =
776 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
780 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
781 if ( !aStudy->_is_nil() ) {
782 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
784 if ( !aGroupSO->_is_nil() ) {
785 // Update Python script
786 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
788 // Remove group's SObject
789 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
793 // Remove the group from SMESH data structures
794 removeGroup( aGroup->GetLocalID() );
797 //=============================================================================
798 /*! RemoveGroupWithContents
799 * Remove group with its contents
801 //=============================================================================
802 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
803 throw (SALOME::SALOME_Exception)
805 if ( theGroup->_is_nil() )
808 SMESH_GroupBase_i* aGroup =
809 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
813 SMESH::long_array_var anIds = aGroup->GetListOfID();
814 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
816 // Update Python script
817 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
820 if ( aGroup->GetType() == SMESH::NODE )
821 aMeshEditor->RemoveNodes( anIds );
823 aMeshEditor->RemoveElements( anIds );
826 RemoveGroup( theGroup );
828 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
829 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
830 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
834 //================================================================================
836 * \brief Get the list of groups existing in the mesh
837 * \retval SMESH::ListOfGroups * - list of groups
839 //================================================================================
841 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
843 Unexpect aCatch(SALOME_SalomeException);
844 if (MYDEBUG) MESSAGE("GetGroups");
846 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
849 TPythonDump aPythonDump;
850 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
854 aList->length( _mapGroups.size() );
856 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
857 for ( ; it != _mapGroups.end(); it++ ) {
858 if ( CORBA::is_nil( it->second )) continue;
859 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
861 if (i > 1) aPythonDump << ", ";
862 aPythonDump << it->second;
866 catch(SALOME_Exception & S_ex) {
867 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
870 // Update Python script
871 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
872 aPythonDump << " ] = " << _this() << ".GetGroups()";
874 return aList._retn();
876 //=============================================================================
878 * Get number of groups existing in the mesh
880 //=============================================================================
882 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
884 Unexpect aCatch(SALOME_SalomeException);
885 return _mapGroups.size();
888 //=============================================================================
890 * New group is created. All mesh elements that are
891 * present in initial groups are added to the new one
893 //=============================================================================
894 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
895 SMESH::SMESH_GroupBase_ptr theGroup2,
896 const char* theName )
897 throw (SALOME::SALOME_Exception)
901 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
902 theGroup1->GetType() != theGroup2->GetType() )
903 return SMESH::SMESH_Group::_nil();
906 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
907 if ( aResGrp->_is_nil() )
908 return SMESH::SMESH_Group::_nil();
910 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
911 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
913 TColStd_MapOfInteger aResMap;
915 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
916 aResMap.Add( anIds1[ i1 ] );
918 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
919 aResMap.Add( anIds2[ i2 ] );
921 SMESH::long_array_var aResIds = new SMESH::long_array;
922 aResIds->length( aResMap.Extent() );
925 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
926 for( ; anIter.More(); anIter.Next() )
927 aResIds[ resI++ ] = anIter.Key();
929 aResGrp->Add( aResIds );
931 // Clear python lines, created by CreateGroup() and Add()
932 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
933 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
934 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
936 // Update Python script
937 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
938 << theGroup1 << ", " << theGroup2 << ", '"
941 return aResGrp._retn();
945 return SMESH::SMESH_Group::_nil();
949 //=============================================================================
951 \brief Union list of groups. New group is created. All mesh elements that are
952 present in initial groups are added to the new one.
953 \param theGroups list of groups
954 \param theName name of group to be created
955 \return pointer on the group
957 //=============================================================================
958 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionListOfGroups(const SMESH::ListOfGroups& theGroups,
959 const char* theName )
960 throw (SALOME::SALOME_Exception)
963 return SMESH::SMESH_Group::_nil();
967 NCollection_Map< int > anIds;
968 SMESH::ElementType aType = SMESH::ALL;
969 for ( int g = 0, n = theGroups.length(); g < n; g++ )
971 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
972 if ( CORBA::is_nil( aGrp ) )
976 SMESH::ElementType aCurrType = aGrp->GetType();
977 if ( aType == SMESH::ALL )
981 if ( aType != aCurrType )
982 return SMESH::SMESH_Group::_nil();
986 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
987 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
989 int aCurrId = aCurrIds[ i ];
990 anIds.Add( aCurrId );
995 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
996 if ( aResGrp->_is_nil() )
997 return SMESH::SMESH_Group::_nil();
999 // Create array of identifiers
1000 SMESH::long_array_var aResIds = new SMESH::long_array;
1001 aResIds->length( anIds.Extent() );
1003 NCollection_Map< int >::Iterator anIter( anIds );
1004 for ( int i = 0; anIter.More(); anIter.Next(), i++ )
1006 aResIds[ i ] = anIter.Value();
1008 aResGrp->Add( aResIds );
1010 // Clear python lines, created by CreateGroup() and Add()
1011 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1012 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1013 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1015 // Update Python script
1017 TPythonDump() << aResGrp << " = " << _this() << ".UnionListOfGroups( "
1018 << &theGroups << ", '" << theName << "' )";
1020 return aResGrp._retn();
1024 return SMESH::SMESH_Group::_nil();
1028 //=============================================================================
1030 * New group is created. All mesh elements that are
1031 * present in both initial groups are added to the new one.
1033 //=============================================================================
1034 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1035 SMESH::SMESH_GroupBase_ptr theGroup2,
1036 const char* theName )
1037 throw (SALOME::SALOME_Exception)
1039 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
1040 theGroup1->GetType() != theGroup2->GetType() )
1041 return SMESH::SMESH_Group::_nil();
1043 // Create Intersection
1044 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
1045 if ( aResGrp->_is_nil() )
1048 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1049 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1051 TColStd_MapOfInteger aMap1;
1053 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1054 aMap1.Add( anIds1[ i1 ] );
1056 TColStd_SequenceOfInteger aSeq;
1058 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1059 if ( aMap1.Contains( anIds2[ i2 ] ) )
1060 aSeq.Append( anIds2[ i2 ] );
1062 SMESH::long_array_var aResIds = new SMESH::long_array;
1063 aResIds->length( aSeq.Length() );
1065 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1066 aResIds[ resI ] = aSeq( resI + 1 );
1068 aResGrp->Add( aResIds );
1070 // Clear python lines, created by CreateGroup() and Add()
1071 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1072 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1073 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1075 // Update Python script
1076 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
1077 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
1079 return aResGrp._retn();
1082 //=============================================================================
1084 \brief Intersect list of groups. New group is created. All mesh elements that
1085 are present in all initial groups simultaneously are added to the new one.
1086 \param theGroups list of groups
1087 \param theName name of group to be created
1088 \return pointer on the group
1090 //=============================================================================
1091 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectListOfGroups(
1092 const SMESH::ListOfGroups& theGroups, const char* theName )
1093 throw (SALOME::SALOME_Exception)
1096 return SMESH::SMESH_Group::_nil();
1100 NCollection_DataMap< int, int > anIdToCount;
1101 SMESH::ElementType aType = SMESH::ALL;
1102 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1104 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1105 if ( CORBA::is_nil( aGrp ) )
1109 SMESH::ElementType aCurrType = aGrp->GetType();
1110 if ( aType == SMESH::ALL )
1114 if ( aType != aCurrType )
1115 return SMESH::SMESH_Group::_nil();
1118 // calculates number of occurance ids in groups
1119 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1120 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1122 int aCurrId = aCurrIds[ i ];
1123 if ( !anIdToCount.IsBound( aCurrId ) )
1124 anIdToCount.Bind( aCurrId, 1 );
1126 anIdToCount( aCurrId ) = anIdToCount( aCurrId ) + 1;
1130 // create map of ids
1131 int nbGrp = theGroups.length();
1132 NCollection_Map< int > anIds;
1133 NCollection_DataMap< int, int >::Iterator anIter( anIdToCount );
1134 for ( ; anIter.More(); anIter.Next() )
1136 int aCurrId = anIter.Key();
1137 int aCurrNb = anIter.Value();
1138 if ( aCurrNb == nbGrp )
1139 anIds.Add( aCurrId );
1143 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
1144 if ( aResGrp->_is_nil() )
1145 return SMESH::SMESH_Group::_nil();
1147 // Create array of identifiers
1148 SMESH::long_array_var aResIds = new SMESH::long_array;
1149 aResIds->length( anIds.Extent() );
1151 NCollection_Map< int >::Iterator aListIter( anIds );
1152 for ( int i = 0; aListIter.More(); aListIter.Next(), i++ )
1154 aResIds[ i ] = aListIter.Value();
1156 aResGrp->Add( aResIds );
1158 // Clear python lines, created by CreateGroup() and Add()
1159 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1160 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1161 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1163 // Update Python script
1165 TPythonDump() << aResGrp << " = " << _this() << ".IntersectListOfGroups( "
1166 << &theGroups << ", '" << theName << "' )";
1168 return aResGrp._retn();
1172 return SMESH::SMESH_Group::_nil();
1176 //=============================================================================
1178 * New group is created. All mesh elements that are present in
1179 * main group but do not present in tool group are added to the new one
1181 //=============================================================================
1182 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1183 SMESH::SMESH_GroupBase_ptr theGroup2,
1184 const char* theName )
1185 throw (SALOME::SALOME_Exception)
1187 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
1188 theGroup1->GetType() != theGroup2->GetType() )
1189 return SMESH::SMESH_Group::_nil();
1192 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
1193 if ( aResGrp->_is_nil() )
1196 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1197 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1199 TColStd_MapOfInteger aMap2;
1201 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1202 aMap2.Add( anIds2[ i2 ] );
1204 TColStd_SequenceOfInteger aSeq;
1205 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1206 if ( !aMap2.Contains( anIds1[ i1 ] ) )
1207 aSeq.Append( anIds1[ i1 ] );
1209 SMESH::long_array_var aResIds = new SMESH::long_array;
1210 aResIds->length( aSeq.Length() );
1212 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1213 aResIds[ resI ] = aSeq( resI + 1 );
1215 aResGrp->Add( aResIds );
1217 // Clear python lines, created by CreateGroup() and Add()
1218 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1219 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1220 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1222 // Update Python script
1223 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1224 << theGroup1 << ", " << theGroup2 << ", '"
1225 << theName << "' )";
1227 return aResGrp._retn();
1230 //=============================================================================
1232 \brief Cut lists of groups. New group is created. All mesh elements that are
1233 present in main groups but do not present in tool groups are added to the new one
1234 \param theMainGroups list of main groups
1235 \param theToolGroups list of tool groups
1236 \param theName name of group to be created
1237 \return pointer on the group
1239 //=============================================================================
1240 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutListOfGroups(
1241 const SMESH::ListOfGroups& theMainGroups,
1242 const SMESH::ListOfGroups& theToolGroups,
1243 const char* theName )
1244 throw (SALOME::SALOME_Exception)
1247 return SMESH::SMESH_Group::_nil();
1251 NCollection_Map< int > aToolIds;
1252 SMESH::ElementType aType = SMESH::ALL;
1254 // iterate through tool groups
1255 for ( g = 0, n = theToolGroups.length(); g < n; g++ )
1257 SMESH::SMESH_GroupBase_var aGrp = theToolGroups[ g ];
1258 if ( CORBA::is_nil( aGrp ) )
1262 SMESH::ElementType aCurrType = aGrp->GetType();
1263 if ( aType == SMESH::ALL )
1267 if ( aType != aCurrType )
1268 return SMESH::SMESH_Group::_nil();
1272 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1273 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1275 int aCurrId = aCurrIds[ i ];
1276 aToolIds.Add( aCurrId );
1280 NCollection_Map< int > anIds; // result
1282 // Iterate through main group
1283 for ( g = 0, n = theMainGroups.length(); g < n; g++ )
1285 SMESH::SMESH_GroupBase_var aGrp = theMainGroups[ g ];
1286 if ( CORBA::is_nil( aGrp ) )
1290 SMESH::ElementType aCurrType = aGrp->GetType();
1291 if ( aType == SMESH::ALL )
1295 if ( aType != aCurrType )
1296 return SMESH::SMESH_Group::_nil();
1300 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1301 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1303 int aCurrId = aCurrIds[ i ];
1304 if ( !aToolIds.Contains( aCurrId ) )
1305 anIds.Add( aCurrId );
1310 SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName );
1311 if ( aResGrp->_is_nil() )
1312 return SMESH::SMESH_Group::_nil();
1314 // Create array of identifiers
1315 SMESH::long_array_var aResIds = new SMESH::long_array;
1316 aResIds->length( anIds.Extent() );
1318 NCollection_Map< int >::Iterator anIter( anIds );
1319 for ( int i = 0; anIter.More(); anIter.Next(), i++ )
1321 aResIds[ i ] = anIter.Value();
1323 aResGrp->Add( aResIds );
1325 // Clear python lines, created by CreateGroup() and Add()
1326 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1327 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1328 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1330 // Update Python script
1332 TPythonDump() << aResGrp << " = " << _this() << ".CutListOfGroups( "
1333 << &theMainGroups << ", " << &theToolGroups << ", '"
1334 << theName << "' )";
1336 return aResGrp._retn();
1340 return SMESH::SMESH_Group::_nil();
1344 //=============================================================================
1346 \brief Create groups of entities from existing groups of superior dimensions
1348 1) extract all nodes from each group,
1349 2) combine all elements of specified dimension laying on these nodes.
1350 \param theGroups list of source groups
1351 \param theElemType dimension of elements
1352 \param theName name of new group
1353 \return pointer on new group
1355 //=============================================================================
1356 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateDimGroup(
1357 const SMESH::ListOfGroups& theGroups,
1358 SMESH::ElementType theElemType,
1359 const char* theName )
1360 throw (SALOME::SALOME_Exception)
1362 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
1364 if ( !theName || !aMeshDS )
1365 return SMESH::SMESH_Group::_nil();
1367 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)theElemType;
1371 // Create map of nodes from all groups
1373 NCollection_Map< int > aNodeMap;
1375 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1377 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1378 if ( CORBA::is_nil( aGrp ) )
1381 SMESH::ElementType aType = aGrp->GetType();
1382 if ( aType == SMESH::ALL )
1384 else if ( aType == SMESH::NODE )
1386 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1387 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1389 int aCurrId = aCurrIds[ i ];
1390 const SMDS_MeshNode* aNode = aMeshDS->FindNode( aCurrId );
1392 aNodeMap.Add( aNode->GetID() );
1397 SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
1398 for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
1400 int aCurrId = aCurrIds[ i ];
1401 const SMDS_MeshElement* anElem = aMeshDS->FindElement( aCurrId );
1404 SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
1405 while( aNodeIter->more() )
1407 const SMDS_MeshNode* aNode =
1408 dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
1410 aNodeMap.Add( aNode->GetID() );
1416 // Get result identifiers
1418 NCollection_Map< int > aResultIds;
1419 if ( theElemType == SMESH::NODE )
1421 NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
1422 for ( ; aNodeIter.More(); aNodeIter.Next() )
1423 aResultIds.Add( aNodeIter.Value() );
1427 // Create list of elements of given dimension constructed on the nodes
1428 NCollection_Map< int > anElemList;
1429 NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
1430 for ( ; aNodeIter.More(); aNodeIter.Next() )
1432 const SMDS_MeshElement* aNode =
1433 dynamic_cast<const SMDS_MeshElement*>( aMeshDS->FindNode( aNodeIter.Value() ) );
1437 SMDS_ElemIteratorPtr anElemIter = aNode->elementsIterator( anElemType );
1438 while( anElemIter->more() )
1440 const SMDS_MeshElement* anElem =
1441 dynamic_cast<const SMDS_MeshElement*>( anElemIter->next() );
1442 if ( anElem && anElem->GetType() == anElemType )
1443 anElemList.Add( anElem->GetID() );
1447 // check whether all nodes of elements are present in nodes map
1448 NCollection_Map< int >::Iterator anIter( anElemList );
1449 for ( ; anIter.More(); anIter.Next() )
1451 const SMDS_MeshElement* anElem = aMeshDS->FindElement( anIter.Value() );
1456 SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
1457 while( aNodeIter->more() )
1459 const SMDS_MeshNode* aNode =
1460 dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
1461 if ( !aNode || !aNodeMap.Contains( aNode->GetID() ) )
1468 aResultIds.Add( anElem->GetID() );
1474 SMESH::SMESH_Group_var aResGrp = CreateGroup( theElemType, theName );
1475 if ( aResGrp->_is_nil() )
1476 return SMESH::SMESH_Group::_nil();
1478 // Create array of identifiers
1479 SMESH::long_array_var aResIds = new SMESH::long_array;
1480 aResIds->length( aResultIds.Extent() );
1482 NCollection_Map< int >::Iterator aResIter( aResultIds );
1483 for ( int i = 0; aResIter.More(); aResIter.Next(), i++ )
1484 aResIds[ i ] = aResIter.Value();
1485 aResGrp->Add( aResIds );
1487 // Remove strings corresponding to group creation
1488 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1489 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1490 _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
1492 // Update Python script
1494 TPythonDump() << aResGrp << " = " << _this() << ".CreateDimGroup( "
1495 << &theGroups << ", " << theElemType << ", '" << theName << "' )";
1497 return aResGrp._retn();
1501 return SMESH::SMESH_Group::_nil();
1505 //================================================================================
1507 * \brief Remember GEOM group data
1509 //================================================================================
1511 void SMESH_Mesh_i::addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
1512 CORBA::Object_ptr theSmeshObj)
1514 if ( CORBA::is_nil( theGeomObj ) || theGeomObj->GetType() != GEOM_GROUP )
1517 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1518 SALOMEDS::SObject_var groupSO = _gen_i->ObjectToSObject( study, theGeomObj );
1519 if ( groupSO->_is_nil() )
1522 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1523 GEOM::GEOM_IGroupOperations_var groupOp =
1524 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1525 GEOM::ListOfLong_var ids = groupOp->GetObjects( theGeomObj );
1528 _geomGroupData.push_back( TGeomGroupData() );
1529 TGeomGroupData & groupData = _geomGroupData.back();
1531 CORBA::String_var entry = groupSO->GetID();
1532 groupData._groupEntry = entry.in();
1534 for ( int i = 0; i < ids->length(); ++i )
1535 groupData._indices.insert( ids[i] );
1537 groupData._smeshObject = theSmeshObj;
1540 //================================================================================
1542 * Remove GEOM group data relating to removed smesh object
1544 //================================================================================
1546 void SMESH_Mesh_i::removeGeomGroupData(CORBA::Object_ptr theSmeshObj)
1548 list<TGeomGroupData>::iterator
1549 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1550 for ( ; data != dataEnd; ++data ) {
1551 if ( theSmeshObj->_is_equivalent( data->_smeshObject )) {
1552 _geomGroupData.erase( data );
1558 //================================================================================
1560 * \brief Return new group contents if it has been changed and update group data
1562 //================================================================================
1564 TopoDS_Shape SMESH_Mesh_i::newGroupShape( TGeomGroupData & groupData)
1566 TopoDS_Shape newShape;
1569 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1570 if ( study->_is_nil() ) return newShape; // means "not changed"
1571 SALOMEDS::SObject_var groupSO = study->FindObjectID( groupData._groupEntry.c_str() );
1572 if ( !groupSO->_is_nil() )
1574 CORBA::Object_var groupObj = _gen_i->SObjectToObject( groupSO );
1575 if ( CORBA::is_nil( groupObj )) return newShape;
1576 GEOM::GEOM_Object_var geomGroup = GEOM::GEOM_Object::_narrow( groupObj );
1578 // get indices of group items
1579 set<int> curIndices;
1580 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1581 GEOM::GEOM_IGroupOperations_var groupOp =
1582 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1583 GEOM::ListOfLong_var ids = groupOp->GetObjects( geomGroup );
1584 for ( int i = 0; i < ids->length(); ++i )
1585 curIndices.insert( ids[i] );
1587 if ( groupData._indices == curIndices )
1588 return newShape; // group not changed
1591 groupData._indices = curIndices;
1593 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1594 if ( !geomClient ) return newShape;
1595 TCollection_AsciiString groupIOR = geomGen->GetStringFromIOR( geomGroup );
1596 geomClient->RemoveShapeFromBuffer( groupIOR );
1597 newShape = _gen_i->GeomObjectToShape( geomGroup );
1600 if ( newShape.IsNull() ) {
1601 // geom group becomes empty - return empty compound
1602 TopoDS_Compound compound;
1603 BRep_Builder().MakeCompound(compound);
1604 newShape = compound;
1610 //=============================================================================
1612 * \brief Storage of shape and index used in CheckGeomGroupModif()
1614 //=============================================================================
1615 struct TIndexedShape {
1617 TopoDS_Shape _shape;
1618 TIndexedShape( int i, const TopoDS_Shape& s ):_index(i), _shape(s) {}
1621 //=============================================================================
1623 * \brief Update objects depending on changed geom groups
1625 * NPAL16168: geometrical group edition from a submesh don't modifiy mesh computation
1626 * issue 0020210: Update of a smesh group after modification of the associated geom group
1628 //=============================================================================
1630 void SMESH_Mesh_i::CheckGeomGroupModif()
1632 if ( !_impl->HasShapeToMesh() ) return;
1634 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1635 if ( study->_is_nil() ) return;
1637 CORBA::Long nbEntities = NbNodes() + NbElements();
1639 // Check if group contents changed
1641 typedef map< string, TopoDS_Shape > TEntry2Geom;
1642 TEntry2Geom newGroupContents;
1644 list<TGeomGroupData>::iterator
1645 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1646 for ( ; data != dataEnd; ++data )
1648 pair< TEntry2Geom::iterator, bool > it_new =
1649 newGroupContents.insert( make_pair( data->_groupEntry, TopoDS_Shape() ));
1650 bool processedGroup = !it_new.second;
1651 TopoDS_Shape& newShape = it_new.first->second;
1652 if ( !processedGroup )
1653 newShape = newGroupShape( *data );
1654 if ( newShape.IsNull() )
1655 continue; // no changes
1657 if ( processedGroup ) { // update group indices
1658 list<TGeomGroupData>::iterator data2 = data;
1659 for ( --data2; data2->_groupEntry != data->_groupEntry; --data2) {}
1660 data->_indices = data2->_indices;
1663 // Update SMESH objects according to new GEOM group contents
1665 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( data->_smeshObject );
1666 if ( !submesh->_is_nil() ) // -------------- Sub mesh ---------------------
1668 int oldID = submesh->GetId();
1669 if ( _mapSubMeshIor.find( oldID ) == _mapSubMeshIor.end() )
1671 TopoDS_Shape oldShape = _mapSubMesh[oldID]->GetSubShape();
1673 // update hypotheses
1674 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldShape);
1675 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1676 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1678 _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
1679 _impl->AddHypothesis ( newShape, (*hypIt)->GetID());
1681 // care of submeshes
1682 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newShape );
1683 int newID = newSubmesh->GetId();
1684 if ( newID != oldID ) {
1685 _mapSubMesh [ newID ] = newSubmesh;
1686 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1687 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1688 _mapSubMesh. erase(oldID);
1689 _mapSubMesh_i. erase(oldID);
1690 _mapSubMeshIor.erase(oldID);
1691 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1696 SMESH::SMESH_GroupOnGeom_var smeshGroup =
1697 SMESH::SMESH_GroupOnGeom::_narrow( data->_smeshObject );
1698 if ( !smeshGroup->_is_nil() ) // ------------ GROUP -----------------------
1700 SMESH_GroupOnGeom_i* group_i = SMESH::DownCast<SMESH_GroupOnGeom_i*>( smeshGroup );
1702 ::SMESH_Group* group = _impl->GetGroup( group_i->GetLocalID() );
1703 SMESHDS_GroupOnGeom* ds = static_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() );
1704 ds->SetShape( newShape );
1709 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( data->_smeshObject );
1710 if ( !mesh->_is_nil() ) // -------------- MESH ----------------------------
1712 // Remove groups and submeshes basing on removed sub-shapes
1714 TopTools_MapOfShape newShapeMap;
1715 TopoDS_Iterator shapeIt( newShape );
1716 for ( ; shapeIt.More(); shapeIt.Next() )
1717 newShapeMap.Add( shapeIt.Value() );
1719 SMESHDS_Mesh* meshDS = _impl->GetMeshDS();
1720 for ( shapeIt.Initialize( meshDS->ShapeToMesh() ); shapeIt.More(); shapeIt.Next() )
1722 if ( newShapeMap.Contains( shapeIt.Value() ))
1724 TopTools_IndexedMapOfShape oldShapeMap;
1725 TopExp::MapShapes( shapeIt.Value(), oldShapeMap );
1726 for ( int i = 1; i <= oldShapeMap.Extent(); ++i )
1728 const TopoDS_Shape& oldShape = oldShapeMap(i);
1729 int oldInd = meshDS->ShapeToIndex( oldShape );
1731 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldInd );
1732 if ( i_smIor != _mapSubMeshIor.end() ) {
1733 RemoveSubMesh( i_smIor->second ); // one submesh per shape index
1736 map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_grp = _mapGroups.begin();
1737 for ( ; i_grp != _mapGroups.end(); ++i_grp )
1739 // check if a group bases on oldInd shape
1740 SMESHDS_GroupOnGeom* grpOnGeom = 0;
1741 if ( ::SMESH_Group* g = _impl->GetGroup( i_grp->first ))
1742 grpOnGeom = dynamic_cast<SMESHDS_GroupOnGeom*>( g->GetGroupDS() );
1743 if ( grpOnGeom && oldShape.IsSame( grpOnGeom->GetShape() ))
1745 RemoveGroup( i_grp->second ); // several groups can base on same shape
1746 i_grp = _mapGroups.begin(); // _mapGroups changed - restart iteration
1751 // Reassign hypotheses and update groups after setting the new shape to mesh
1753 // collect anassigned hypotheses
1754 typedef list< pair< TIndexedShape, list<const SMESHDS_Hypothesis*> > > TShapeHypList;
1755 list <const SMESHDS_Hypothesis * >::const_iterator hypIt;
1756 TShapeHypList assignedHyps;
1757 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
1759 const TopoDS_Shape& oldShape = meshDS->IndexToShape(i);
1760 list<const SMESHDS_Hypothesis*> hyps = meshDS->GetHypothesis( oldShape );// copy
1761 if ( !hyps.empty() ) {
1762 assignedHyps.push_back( make_pair( TIndexedShape(i,oldShape), hyps ));
1763 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1764 _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
1767 // collect shapes supporting groups
1768 typedef list < pair< TIndexedShape, SMDSAbs_ElementType > > TShapeTypeList;
1769 TShapeTypeList groupData;
1770 const set<SMESHDS_GroupBase*>& groups = meshDS->GetGroups();
1771 set<SMESHDS_GroupBase*>::const_iterator grIt = groups.begin();
1772 for ( ; grIt != groups.end(); ++grIt )
1774 if ( SMESHDS_GroupOnGeom* gog = dynamic_cast<SMESHDS_GroupOnGeom*>( *grIt ))
1776 ( make_pair( TIndexedShape( gog->GetID(),gog->GetShape()), gog->GetType()));
1778 // set new shape to mesh -> DS of submeshes and geom groups is deleted
1779 _impl->ShapeToMesh( newShape );
1781 // reassign hypotheses
1782 TShapeHypList::iterator indS_hyps = assignedHyps.begin();
1783 for ( ; indS_hyps != assignedHyps.end(); ++indS_hyps )
1785 TIndexedShape& geom = indS_hyps->first;
1786 list<const SMESHDS_Hypothesis*>& hyps = indS_hyps->second;
1787 int oldID = geom._index;
1788 int newID = meshDS->ShapeToIndex( geom._shape );
1791 if ( oldID == 1 ) { // main shape
1793 geom._shape = newShape;
1795 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1796 _impl->AddHypothesis( geom._shape, (*hypIt)->GetID());
1797 // care of submeshes
1798 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( geom._shape );
1799 if ( newID != oldID ) {
1800 _mapSubMesh [ newID ] = newSubmesh;
1801 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1802 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1803 _mapSubMesh. erase(oldID);
1804 _mapSubMesh_i. erase(oldID);
1805 _mapSubMeshIor.erase(oldID);
1806 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1810 TShapeTypeList::iterator geomType = groupData.begin();
1811 for ( ; geomType != groupData.end(); ++geomType )
1813 const TIndexedShape& geom = geomType->first;
1814 int oldID = geom._index;
1815 if ( _mapGroups.find( oldID ) == _mapGroups.end() )
1818 SALOMEDS::SObject_var groupSO = _gen_i->ObjectToSObject( study,_mapGroups[oldID] );
1819 CORBA::String_var name = groupSO->GetName();
1821 SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>(_mapGroups[oldID] );
1823 if ( group_i && _impl->AddGroup( geomType->second, name.in(), newID, geom._shape ))
1824 group_i->changeLocalId( newID );
1827 break; // everything has been updated
1830 } // loop on group data
1834 CORBA::Long newNbEntities = NbNodes() + NbElements();
1835 list< SALOMEDS::SObject_var > soToUpdateIcons;
1836 if ( newNbEntities != nbEntities )
1838 // Add all SObjects with icons
1839 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, _this() )); // mesh
1841 for (map<int, SMESH::SMESH_subMesh_ptr>::iterator i_sm = _mapSubMeshIor.begin();
1842 i_sm != _mapSubMeshIor.end(); ++i_sm ) // submeshes
1843 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_sm->second ));
1845 for ( map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_gr = _mapGroups.begin();
1846 i_gr != _mapGroups.end(); ++i_gr ) // groups
1847 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_gr->second ));
1850 list< SALOMEDS::SObject_var >::iterator so = soToUpdateIcons.begin();
1851 for ( ; so != soToUpdateIcons.end(); ++so )
1852 _gen_i->SetPixMap( *so, "ICON_SMESH_TREE_MESH_WARN" );
1855 //=============================================================================
1857 * \brief Create standalone group instead if group on geometry
1860 //=============================================================================
1862 SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupOnGeom_ptr theGroup )
1864 SMESH::SMESH_Group_var aGroup;
1865 if ( theGroup->_is_nil() )
1866 return aGroup._retn();
1868 Unexpect aCatch(SALOME_SalomeException);
1870 SMESH_GroupBase_i* aGroupToRem =
1871 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
1873 return aGroup._retn();
1875 int anId = aGroupToRem->GetLocalID();
1876 if ( !_impl->ConvertToStandalone( anId ) )
1877 return aGroup._retn();
1878 removeGeomGroupData( theGroup );
1880 SMESH_GroupBase_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1882 // remove old instance of group from own map
1883 _mapGroups.erase( anId );
1885 SALOMEDS::StudyBuilder_var builder;
1886 SALOMEDS::SObject_var aGroupSO;
1887 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1888 if ( !aStudy->_is_nil() ) {
1889 builder = aStudy->NewBuilder();
1890 aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
1891 if ( !aGroupSO->_is_nil() ) {
1893 // remove reference to geometry
1894 SALOMEDS::ChildIterator_var chItr = aStudy->NewChildIterator(aGroupSO);
1895 for ( ; chItr->More(); chItr->Next() )
1896 // Remove group's child SObject
1897 builder->RemoveObject( chItr->Value() );
1899 // Update Python script
1900 TPythonDump() << aGroupSO << " = " << _this() << ".ConvertToStandalone( "
1901 << aGroupSO << " )";
1905 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1906 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1907 aGroupImpl->Register();
1908 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1910 // remember new group in own map
1911 aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
1912 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1914 // register CORBA object for persistence
1915 //int nextId = _gen_i->RegisterObject( aGroup );
1916 //if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1917 builder->SetIOR( aGroupSO, _gen_i->GetORB()->object_to_string( aGroup ) );
1919 return aGroup._retn();
1922 //=============================================================================
1926 //=============================================================================
1928 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1930 if(MYDEBUG) MESSAGE( "createSubMesh" );
1931 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1933 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1934 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1935 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1936 SMESH::SMESH_subMesh_var subMesh
1937 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1939 _mapSubMesh[subMeshId] = mySubMesh;
1940 _mapSubMesh_i[subMeshId] = subMeshServant;
1941 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1943 // register CORBA object for persistence
1944 int nextId = _gen_i->RegisterObject( subMesh );
1945 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1947 // to track changes of GEOM groups
1948 addGeomGroupData( theSubShapeObject, subMesh );
1950 return subMesh._retn();
1953 //=======================================================================
1954 //function : getSubMesh
1956 //=======================================================================
1958 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1960 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1961 if ( it == _mapSubMeshIor.end() )
1962 return SMESH::SMESH_subMesh::_nil();
1964 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1968 //=============================================================================
1972 //=============================================================================
1974 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1975 GEOM::GEOM_Object_ptr theSubShapeObject )
1977 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1978 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1982 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1983 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1984 removeHypothesis( theSubShapeObject, aHypList[i] );
1987 catch( const SALOME::SALOME_Exception& ) {
1988 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1990 removeGeomGroupData( theSubShapeObject );
1992 int subMeshId = theSubMesh->GetId();
1994 _mapSubMesh.erase(subMeshId);
1995 _mapSubMesh_i.erase(subMeshId);
1996 _mapSubMeshIor.erase(subMeshId);
1997 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
2000 //=============================================================================
2004 //=============================================================================
2006 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
2007 const char* theName,
2008 const TopoDS_Shape& theShape )
2011 SMESH::SMESH_GroupBase_var aGroup;
2012 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
2013 SMESH_GroupBase_i* aGroupImpl;
2014 if ( !theShape.IsNull() )
2015 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2017 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2019 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2020 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2021 aGroupImpl->Register();
2022 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2024 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2025 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
2027 // register CORBA object for persistence
2028 int nextId = _gen_i->RegisterObject( aGroup );
2029 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2031 // to track changes of GEOM groups
2032 if ( !theShape.IsNull() ) {
2033 GEOM::GEOM_Object_var geom = _gen_i->ShapeToGeomObject( theShape );
2034 addGeomGroupData( geom, aGroup );
2037 return aGroup._retn();
2040 //=============================================================================
2042 * SMESH_Mesh_i::removeGroup
2044 * Should be called by ~SMESH_Group_i()
2046 //=============================================================================
2048 void SMESH_Mesh_i::removeGroup( const int theId )
2050 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
2051 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
2052 removeGeomGroupData( _mapGroups[theId] );
2053 _mapGroups.erase( theId );
2054 _impl->RemoveGroup( theId );
2059 //=============================================================================
2063 //=============================================================================
2065 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
2066 throw(SALOME::SALOME_Exception)
2068 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
2070 SMESH::log_array_var aLog;
2072 list < SMESHDS_Command * >logDS = _impl->GetLog();
2073 aLog = new SMESH::log_array;
2075 int lg = logDS.size();
2078 list < SMESHDS_Command * >::iterator its = logDS.begin();
2079 while(its != logDS.end()){
2080 SMESHDS_Command *com = *its;
2081 int comType = com->GetType();
2083 int lgcom = com->GetNumber();
2085 const list < int >&intList = com->GetIndexes();
2086 int inum = intList.size();
2088 list < int >::const_iterator ii = intList.begin();
2089 const list < double >&coordList = com->GetCoords();
2090 int rnum = coordList.size();
2092 list < double >::const_iterator ir = coordList.begin();
2093 aLog[indexLog].commandType = comType;
2094 aLog[indexLog].number = lgcom;
2095 aLog[indexLog].coords.length(rnum);
2096 aLog[indexLog].indexes.length(inum);
2097 for(int i = 0; i < rnum; i++){
2098 aLog[indexLog].coords[i] = *ir;
2099 //MESSAGE(" "<<i<<" "<<ir.Value());
2102 for(int i = 0; i < inum; i++){
2103 aLog[indexLog].indexes[i] = *ii;
2104 //MESSAGE(" "<<i<<" "<<ii.Value());
2113 catch(SALOME_Exception & S_ex){
2114 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
2116 return aLog._retn();
2120 //=============================================================================
2124 //=============================================================================
2126 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
2128 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
2132 //=============================================================================
2136 //=============================================================================
2138 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
2140 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
2144 //=============================================================================
2148 //=============================================================================
2150 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
2155 //=============================================================================
2159 //=============================================================================
2161 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
2163 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
2167 //=============================================================================
2171 //=============================================================================
2173 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
2175 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
2179 //=============================================================================
2181 * Return mesh editor
2183 //=============================================================================
2185 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
2187 // Create MeshEditor
2188 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
2189 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
2191 // Update Python script
2192 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
2194 return aMesh._retn();
2197 //=============================================================================
2199 * Return mesh edition previewer
2201 //=============================================================================
2203 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
2205 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
2206 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
2207 return aMesh._retn();
2210 //=============================================================================
2214 //=============================================================================
2215 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
2217 Unexpect aCatch(SALOME_SalomeException);
2218 _impl->SetAutoColor(theAutoColor);
2221 //=============================================================================
2225 //=============================================================================
2226 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
2228 Unexpect aCatch(SALOME_SalomeException);
2229 return _impl->GetAutoColor();
2233 //=============================================================================
2235 * Export in different formats
2237 //=============================================================================
2239 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
2241 return _impl->HasDuplicatedGroupNamesMED();
2244 void SMESH_Mesh_i::PrepareForWriting (const char* file)
2246 TCollection_AsciiString aFullName ((char*)file);
2247 OSD_Path aPath (aFullName);
2248 OSD_File aFile (aPath);
2249 if (aFile.Exists()) {
2250 // existing filesystem node
2251 if (aFile.KindOfFile() == OSD_FILE) {
2252 if (aFile.IsWriteable()) {
2255 if (aFile.Failed()) {
2256 TCollection_AsciiString msg ("File ");
2257 msg += aFullName + " cannot be replaced.";
2258 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2261 TCollection_AsciiString msg ("File ");
2262 msg += aFullName + " cannot be overwritten.";
2263 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2266 TCollection_AsciiString msg ("Location ");
2267 msg += aFullName + " is not a file.";
2268 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2271 // nonexisting file; check if it can be created
2273 aFile.Build(OSD_WriteOnly, OSD_Protection());
2274 if (aFile.Failed()) {
2275 TCollection_AsciiString msg ("You cannot create the file ");
2276 msg += aFullName + ". Check the directory existance and access rights.";
2277 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2285 void SMESH_Mesh_i::ExportToMED (const char* file,
2286 CORBA::Boolean auto_groups,
2287 SMESH::MED_VERSION theVersion)
2288 throw(SALOME::SALOME_Exception)
2290 Unexpect aCatch(SALOME_SalomeException);
2293 PrepareForWriting(file);
2294 const char* aMeshName = "Mesh";
2295 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2296 if ( !aStudy->_is_nil() ) {
2297 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
2298 if ( !aMeshSO->_is_nil() ) {
2299 aMeshName = aMeshSO->GetName();
2300 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
2301 if ( !aStudy->GetProperties()->IsLocked() )
2303 SALOMEDS::GenericAttribute_var anAttr;
2304 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2305 SALOMEDS::AttributeExternalFileDef_var aFileName;
2306 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
2307 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
2308 ASSERT(!aFileName->_is_nil());
2309 aFileName->SetValue(file);
2310 SALOMEDS::AttributeFileType_var aFileType;
2311 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
2312 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
2313 ASSERT(!aFileType->_is_nil());
2314 aFileType->SetValue("FICHIERMED");
2318 // Update Python script
2319 // set name of mesh before export
2320 TPythonDump() << _gen_i << ".SetName(" << _this() << ", '" << aMeshName << "')";
2322 // check names of groups
2325 TPythonDump() << _this() << ".ExportToMED( '"
2326 << file << "', " << auto_groups << ", " << theVersion << " )";
2328 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
2331 void SMESH_Mesh_i::ExportMED (const char* file,
2332 CORBA::Boolean auto_groups)
2333 throw(SALOME::SALOME_Exception)
2335 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
2338 void SMESH_Mesh_i::ExportDAT (const char *file)
2339 throw(SALOME::SALOME_Exception)
2341 Unexpect aCatch(SALOME_SalomeException);
2343 // Update Python script
2344 // check names of groups
2346 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
2349 PrepareForWriting(file);
2350 _impl->ExportDAT(file);
2353 void SMESH_Mesh_i::ExportUNV (const char *file)
2354 throw(SALOME::SALOME_Exception)
2356 Unexpect aCatch(SALOME_SalomeException);
2358 // Update Python script
2359 // check names of groups
2361 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
2364 PrepareForWriting(file);
2365 _impl->ExportUNV(file);
2368 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
2369 throw(SALOME::SALOME_Exception)
2371 Unexpect aCatch(SALOME_SalomeException);
2373 // Update Python script
2374 // check names of groups
2376 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
2379 PrepareForWriting(file);
2380 _impl->ExportSTL(file, isascii);
2383 //=============================================================================
2387 //=============================================================================
2389 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
2391 Unexpect aCatch(SALOME_SalomeException);
2392 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
2393 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
2394 return aMesh._retn();
2397 //=============================================================================
2401 //=============================================================================
2402 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
2404 Unexpect aCatch(SALOME_SalomeException);
2405 return _impl->NbNodes();
2408 //=============================================================================
2412 //=============================================================================
2413 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
2415 Unexpect aCatch(SALOME_SalomeException);
2416 return NbEdges() + NbFaces() + NbVolumes();
2419 //=============================================================================
2423 //=============================================================================
2424 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
2426 Unexpect aCatch(SALOME_SalomeException);
2427 return _impl->NbEdges();
2430 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
2431 throw(SALOME::SALOME_Exception)
2433 Unexpect aCatch(SALOME_SalomeException);
2434 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
2437 //=============================================================================
2441 //=============================================================================
2442 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
2444 Unexpect aCatch(SALOME_SalomeException);
2445 return _impl->NbFaces();
2448 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
2450 Unexpect aCatch(SALOME_SalomeException);
2451 return _impl->NbTriangles();
2454 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
2456 Unexpect aCatch(SALOME_SalomeException);
2457 return _impl->NbQuadrangles();
2460 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
2462 Unexpect aCatch(SALOME_SalomeException);
2463 return _impl->NbPolygons();
2466 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
2467 throw(SALOME::SALOME_Exception)
2469 Unexpect aCatch(SALOME_SalomeException);
2470 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
2473 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
2474 throw(SALOME::SALOME_Exception)
2476 Unexpect aCatch(SALOME_SalomeException);
2477 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
2480 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
2481 throw(SALOME::SALOME_Exception)
2483 Unexpect aCatch(SALOME_SalomeException);
2484 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
2487 //=============================================================================
2491 //=============================================================================
2492 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
2494 Unexpect aCatch(SALOME_SalomeException);
2495 return _impl->NbVolumes();
2498 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
2500 Unexpect aCatch(SALOME_SalomeException);
2501 return _impl->NbTetras();
2504 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
2506 Unexpect aCatch(SALOME_SalomeException);
2507 return _impl->NbHexas();
2510 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
2512 Unexpect aCatch(SALOME_SalomeException);
2513 return _impl->NbPyramids();
2516 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
2518 Unexpect aCatch(SALOME_SalomeException);
2519 return _impl->NbPrisms();
2522 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
2524 Unexpect aCatch(SALOME_SalomeException);
2525 return _impl->NbPolyhedrons();
2528 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
2529 throw(SALOME::SALOME_Exception)
2531 Unexpect aCatch(SALOME_SalomeException);
2532 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
2535 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
2536 throw(SALOME::SALOME_Exception)
2538 Unexpect aCatch(SALOME_SalomeException);
2539 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
2542 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
2543 throw(SALOME::SALOME_Exception)
2545 Unexpect aCatch(SALOME_SalomeException);
2546 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
2549 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
2550 throw(SALOME::SALOME_Exception)
2552 Unexpect aCatch(SALOME_SalomeException);
2553 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
2556 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
2557 throw(SALOME::SALOME_Exception)
2559 Unexpect aCatch(SALOME_SalomeException);
2560 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
2563 //=============================================================================
2567 //=============================================================================
2568 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
2570 Unexpect aCatch(SALOME_SalomeException);
2571 return _mapSubMesh_i.size();
2574 //=============================================================================
2578 //=============================================================================
2579 char* SMESH_Mesh_i::Dump()
2581 std::ostringstream os;
2583 return CORBA::string_dup( os.str().c_str() );
2586 //=============================================================================
2590 //=============================================================================
2591 SMESH::long_array* SMESH_Mesh_i::GetIDs()
2593 // SMESH::long_array_var aResult = new SMESH::long_array();
2594 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2595 // int aMinId = aSMESHDS_Mesh->MinElementID();
2596 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
2598 // aResult->length(aMaxId - aMinId + 1);
2600 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
2601 // aResult[i++] = id;
2603 // return aResult._retn();
2605 return GetElementsId();
2608 //=============================================================================
2612 //=============================================================================
2614 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
2615 throw (SALOME::SALOME_Exception)
2617 Unexpect aCatch(SALOME_SalomeException);
2618 MESSAGE("SMESH_Mesh_i::GetElementsId");
2619 SMESH::long_array_var aResult = new SMESH::long_array();
2620 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2622 if ( aSMESHDS_Mesh == NULL )
2623 return aResult._retn();
2625 long nbElements = NbElements();
2626 aResult->length( nbElements );
2627 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
2628 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
2629 aResult[i] = anIt->next()->GetID();
2631 return aResult._retn();
2635 //=============================================================================
2639 //=============================================================================
2641 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
2642 throw (SALOME::SALOME_Exception)
2644 Unexpect aCatch(SALOME_SalomeException);
2645 MESSAGE("SMESH_subMesh_i::GetElementsByType");
2646 SMESH::long_array_var aResult = new SMESH::long_array();
2647 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2649 if ( aSMESHDS_Mesh == NULL )
2650 return aResult._retn();
2652 long nbElements = NbElements();
2654 // No sense in returning ids of elements along with ids of nodes:
2655 // when theElemType == SMESH::ALL, return node ids only if
2656 // there are no elements
2657 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
2658 return GetNodesId();
2660 aResult->length( nbElements );
2664 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
2665 while ( i < nbElements && anIt->more() ) {
2666 const SMDS_MeshElement* anElem = anIt->next();
2667 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
2668 aResult[i++] = anElem->GetID();
2671 aResult->length( i );
2673 return aResult._retn();
2676 //=============================================================================
2680 //=============================================================================
2682 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
2683 throw (SALOME::SALOME_Exception)
2685 Unexpect aCatch(SALOME_SalomeException);
2686 MESSAGE("SMESH_subMesh_i::GetNodesId");
2687 SMESH::long_array_var aResult = new SMESH::long_array();
2688 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2690 if ( aSMESHDS_Mesh == NULL )
2691 return aResult._retn();
2693 long nbNodes = NbNodes();
2694 aResult->length( nbNodes );
2695 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
2696 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
2697 aResult[i] = anIt->next()->GetID();
2699 return aResult._retn();
2702 //=============================================================================
2706 //=============================================================================
2708 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
2709 throw (SALOME::SALOME_Exception)
2711 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
2715 //=============================================================================
2717 * Returns ID of elements for given submesh
2719 //=============================================================================
2720 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
2721 throw (SALOME::SALOME_Exception)
2723 SMESH::long_array_var aResult = new SMESH::long_array();
2725 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2726 if(!SM) return aResult._retn();
2728 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2729 if(!SDSM) return aResult._retn();
2731 aResult->length(SDSM->NbElements());
2733 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2735 while ( eIt->more() ) {
2736 aResult[i++] = eIt->next()->GetID();
2739 return aResult._retn();
2743 //=============================================================================
2745 * Returns ID of nodes for given submesh
2746 * If param all==true - returns all nodes, else -
2747 * returns only nodes on shapes.
2749 //=============================================================================
2750 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
2751 throw (SALOME::SALOME_Exception)
2753 SMESH::long_array_var aResult = new SMESH::long_array();
2755 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2756 if(!SM) return aResult._retn();
2758 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2759 if(!SDSM) return aResult._retn();
2762 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
2763 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
2764 while ( nIt->more() ) {
2765 const SMDS_MeshNode* elem = nIt->next();
2766 theElems.insert( elem->GetID() );
2769 else { // all nodes of submesh elements
2770 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2771 while ( eIt->more() ) {
2772 const SMDS_MeshElement* anElem = eIt->next();
2773 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
2774 while ( nIt->more() ) {
2775 const SMDS_MeshElement* elem = nIt->next();
2776 theElems.insert( elem->GetID() );
2781 aResult->length(theElems.size());
2782 set<int>::iterator itElem;
2784 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
2785 aResult[i++] = *itElem;
2787 return aResult._retn();
2791 //=============================================================================
2793 * Returns type of elements for given submesh
2795 //=============================================================================
2796 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2797 throw (SALOME::SALOME_Exception)
2799 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2800 if(!SM) return SMESH::ALL;
2802 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2803 if(!SDSM) return SMESH::ALL;
2805 if(SDSM->NbElements()==0)
2806 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2808 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2809 const SMDS_MeshElement* anElem = eIt->next();
2810 return ( SMESH::ElementType ) anElem->GetType();
2814 //=============================================================================
2818 //=============================================================================
2820 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2822 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2824 MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
2829 //=============================================================================
2831 * Get XYZ coordinates of node as list of double
2832 * If there is not node for given ID - returns empty list
2834 //=============================================================================
2836 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2838 SMESH::double_array_var aResult = new SMESH::double_array();
2839 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2840 if ( aSMESHDS_Mesh == NULL )
2841 return aResult._retn();
2844 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2846 return aResult._retn();
2850 aResult[0] = aNode->X();
2851 aResult[1] = aNode->Y();
2852 aResult[2] = aNode->Z();
2853 return aResult._retn();
2857 //=============================================================================
2859 * For given node returns list of IDs of inverse elements
2860 * If there is not node for given ID - returns empty list
2862 //=============================================================================
2864 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2866 SMESH::long_array_var aResult = new SMESH::long_array();
2867 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2868 if ( aSMESHDS_Mesh == NULL )
2869 return aResult._retn();
2872 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2874 return aResult._retn();
2876 // find inverse elements
2877 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2878 TColStd_SequenceOfInteger IDs;
2879 while(eIt->more()) {
2880 const SMDS_MeshElement* elem = eIt->next();
2881 IDs.Append(elem->GetID());
2883 if(IDs.Length()>0) {
2884 aResult->length(IDs.Length());
2886 for(; i<=IDs.Length(); i++) {
2887 aResult[i-1] = IDs.Value(i);
2890 return aResult._retn();
2893 //=============================================================================
2895 * \brief Return position of a node on shape
2897 //=============================================================================
2899 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2901 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2902 aNodePosition->shapeID = 0;
2903 aNodePosition->shapeType = GEOM::SHAPE;
2905 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2906 if ( !mesh ) return aNodePosition;
2908 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2910 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2912 aNodePosition->shapeID = pos->GetShapeId();
2913 switch ( pos->GetTypeOfPosition() ) {
2915 aNodePosition->shapeType = GEOM::EDGE;
2916 aNodePosition->params.length(1);
2917 aNodePosition->params[0] =
2918 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2921 aNodePosition->shapeType = GEOM::FACE;
2922 aNodePosition->params.length(2);
2923 aNodePosition->params[0] =
2924 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2925 aNodePosition->params[1] =
2926 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2928 case SMDS_TOP_VERTEX:
2929 aNodePosition->shapeType = GEOM::VERTEX;
2931 case SMDS_TOP_3DSPACE:
2932 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2933 aNodePosition->shapeType = GEOM::SOLID;
2934 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2935 aNodePosition->shapeType = GEOM::SHELL;
2941 return aNodePosition;
2944 //=============================================================================
2946 * If given element is node returns IDs of shape from position
2947 * If there is not node for given ID - returns -1
2949 //=============================================================================
2951 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2953 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2954 if ( aSMESHDS_Mesh == NULL )
2958 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2960 SMDS_PositionPtr pos = aNode->GetPosition();
2964 return pos->GetShapeId();
2971 //=============================================================================
2973 * For given element returns ID of result shape after
2974 * ::FindShape() from SMESH_MeshEditor
2975 * If there is not element for given ID - returns -1
2977 //=============================================================================
2979 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2981 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2982 if ( aSMESHDS_Mesh == NULL )
2985 // try to find element
2986 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2990 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2991 ::SMESH_MeshEditor aMeshEditor(_impl);
2992 int index = aMeshEditor.FindShape( elem );
3000 //=============================================================================
3002 * Returns number of nodes for given element
3003 * If there is not element for given ID - returns -1
3005 //=============================================================================
3007 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
3009 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3010 if ( aSMESHDS_Mesh == NULL ) return -1;
3011 // try to find element
3012 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3013 if(!elem) return -1;
3014 return elem->NbNodes();
3018 //=============================================================================
3020 * Returns ID of node by given index for given element
3021 * If there is not element for given ID - returns -1
3022 * If there is not node for given index - returns -2
3024 //=============================================================================
3026 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
3028 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3029 if ( aSMESHDS_Mesh == NULL ) return -1;
3030 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3031 if(!elem) return -1;
3032 if( index>=elem->NbNodes() || index<0 ) return -1;
3033 return elem->GetNode(index)->GetID();
3036 //=============================================================================
3038 * Returns IDs of nodes of given element
3040 //=============================================================================
3042 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
3044 SMESH::long_array_var aResult = new SMESH::long_array();
3045 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
3047 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
3049 aResult->length( elem->NbNodes() );
3050 for ( int i = 0; i < elem->NbNodes(); ++i )
3051 aResult[ i ] = elem->GetNode( i )->GetID();
3054 return aResult._retn();
3057 //=============================================================================
3059 * Returns true if given node is medium node
3060 * in given quadratic element
3062 //=============================================================================
3064 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
3066 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3067 if ( aSMESHDS_Mesh == NULL ) return false;
3069 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
3070 if(!aNode) return false;
3071 // try to find element
3072 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
3073 if(!elem) return false;
3075 return elem->IsMediumNode(aNode);
3079 //=============================================================================
3081 * Returns true if given node is medium node
3082 * in one of quadratic elements
3084 //=============================================================================
3086 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
3087 SMESH::ElementType theElemType)
3089 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3090 if ( aSMESHDS_Mesh == NULL ) return false;
3093 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
3094 if(!aNode) return false;
3096 SMESH_MesherHelper aHelper( *(_impl) );
3098 SMDSAbs_ElementType aType;
3099 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
3100 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
3101 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
3102 else aType = SMDSAbs_All;
3104 return aHelper.IsMedium(aNode,aType);
3108 //=============================================================================
3110 * Returns number of edges for given element
3112 //=============================================================================
3114 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
3116 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3117 if ( aSMESHDS_Mesh == NULL ) return -1;
3118 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3119 if(!elem) return -1;
3120 return elem->NbEdges();
3124 //=============================================================================
3126 * Returns number of faces for given element
3128 //=============================================================================
3130 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
3132 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3133 if ( aSMESHDS_Mesh == NULL ) return -1;
3134 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3135 if(!elem) return -1;
3136 return elem->NbFaces();
3140 //=============================================================================
3142 * Returns true if given element is polygon
3144 //=============================================================================
3146 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
3148 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3149 if ( aSMESHDS_Mesh == NULL ) return false;
3150 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3151 if(!elem) return false;
3152 return elem->IsPoly();
3156 //=============================================================================
3158 * Returns true if given element is quadratic
3160 //=============================================================================
3162 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
3164 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3165 if ( aSMESHDS_Mesh == NULL ) return false;
3166 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3167 if(!elem) return false;
3168 return elem->IsQuadratic();
3172 //=============================================================================
3174 * Returns bary center for given element
3176 //=============================================================================
3178 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
3180 SMESH::double_array_var aResult = new SMESH::double_array();
3181 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3182 if ( aSMESHDS_Mesh == NULL )
3183 return aResult._retn();
3185 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3187 return aResult._retn();
3189 if(elem->GetType()==SMDSAbs_Volume) {
3190 SMDS_VolumeTool aTool;
3191 if(aTool.Set(elem)) {
3193 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
3198 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
3200 double x=0., y=0., z=0.;
3201 for(; anIt->more(); ) {
3203 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
3217 return aResult._retn();
3221 //=============================================================================
3223 * Create and publish group servants if any groups were imported or created anyhow
3225 //=============================================================================
3227 void SMESH_Mesh_i::CreateGroupServants()
3229 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
3231 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
3232 while ( groupIt->more() )
3234 ::SMESH_Group* group = groupIt->next();
3235 int anId = group->GetGroupDS()->GetID();
3237 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
3238 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
3241 SMESH_GroupBase_i* aGroupImpl;
3243 if ( SMESHDS_GroupOnGeom* groupOnGeom =
3244 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
3246 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
3247 shape = groupOnGeom->GetShape();
3250 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
3253 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
3254 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
3255 aGroupImpl->Register();
3257 SMESH::SMESH_GroupBase_var groupVar =
3258 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
3259 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
3261 // register CORBA object for persistence
3262 int nextId = _gen_i->RegisterObject( groupVar );
3263 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
3265 // publishing of the groups in the study
3266 if ( !aStudy->_is_nil() ) {
3267 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
3268 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
3273 //=============================================================================
3275 * \brief Return groups cantained in _mapGroups by their IDs
3277 //=============================================================================
3279 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
3281 int nbGroups = groupIDs.size();
3282 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
3283 aList->length( nbGroups );
3285 list<int>::const_iterator ids = groupIDs.begin();
3286 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
3288 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
3289 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
3290 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
3292 aList->length( nbGroups );
3293 return aList._retn();
3296 //=============================================================================
3298 * \brief Return information about imported file
3300 //=============================================================================
3302 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
3304 SALOME_MED::MedFileInfo_var res( myFileInfo );
3305 if ( !res.operator->() ) {
3306 res = new SALOME_MED::MedFileInfo;
3308 res->fileSize = res->major = res->minor = res->release = -1;
3313 //=============================================================================
3315 * \brief Check and correct names of mesh groups
3317 //=============================================================================
3319 void SMESH_Mesh_i::checkGroupNames()
3321 int nbGrp = NbGroups();
3325 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
3326 if ( aStudy->_is_nil() )
3327 return; // nothing to do
3329 SMESH::ListOfGroups* grpList = 0;
3330 // avoid dump of "GetGroups"
3332 // store python dump into a local variable inside local scope
3333 SMESH::TPythonDump pDump; // do not delete this line of code
3334 grpList = GetGroups();
3337 for ( int gIndx = 0; gIndx < nbGrp; gIndx++ ) {
3338 SMESH::SMESH_GroupBase_ptr aGrp = (*grpList)[ gIndx ];
3341 SALOMEDS::SObject_var aGrpSO = _gen_i->ObjectToSObject( aStudy, aGrp );
3342 if ( aGrpSO->_is_nil() )
3344 // correct name of the mesh group if necessary
3345 const char* guiName = aGrpSO->GetName();
3346 if ( strcmp(guiName, aGrp->GetName()) )
3347 aGrp->SetName( guiName );
3351 //=============================================================================
3353 * \brief Sets list of notebook variables used for Mesh operations separated by ":" symbol
3355 //=============================================================================
3356 void SMESH_Mesh_i::SetParameters(const char* theParameters)
3358 SMESH_Gen_i::GetSMESHGen()->UpdateParameters(SMESH::SMESH_Mesh::_narrow(_this()),
3359 CORBA::string_dup(theParameters));
3362 //=============================================================================
3364 * \brief Returns list of notebook variables used for Mesh operations separated by ":" symbol
3366 //=============================================================================
3367 char* SMESH_Mesh_i::GetParameters()
3369 SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
3370 return CORBA::string_dup(gen->GetParameters(SMESH::SMESH_Mesh::_narrow(_this())));
3373 //=============================================================================
3375 * \brief Returns list of notebook variables used for last Mesh operation
3377 //=============================================================================
3378 SMESH::string_array* SMESH_Mesh_i::GetLastParameters()
3380 SMESH::string_array_var aResult = new SMESH::string_array();
3381 SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
3383 char *aParameters = GetParameters();
3384 SALOMEDS::Study_ptr aStudy = gen->GetCurrentStudy();
3385 if(!aStudy->_is_nil()) {
3386 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
3387 if(aSections->length() > 0) {
3388 SALOMEDS::ListOfStrings aVars = aSections[aSections->length()-1];
3389 aResult->length(aVars.length());
3390 for(int i = 0;i < aVars.length();i++)
3391 aResult[i] = CORBA::string_dup( aVars[i]);
3395 return aResult._retn();