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>
67 #include <TopExp_Explorer.hxx>
68 #include <TopoDS_Compound.hxx>
77 static int MYDEBUG = 0;
79 static int MYDEBUG = 0;
83 using SMESH::TPythonDump;
85 int SMESH_Mesh_i::myIdGenerator = 0;
89 //=============================================================================
93 //=============================================================================
95 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
98 : SALOME::GenericObj_i( thePOA )
100 MESSAGE("SMESH_Mesh_i");
103 _id = myIdGenerator++;
107 //=============================================================================
111 //=============================================================================
113 SMESH_Mesh_i::~SMESH_Mesh_i()
115 INFOS("~SMESH_Mesh_i");
116 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
117 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
118 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
120 // this method is colled from destructor of group (PAL6331)
121 //_impl->RemoveGroup( aGroup->GetLocalID() );
129 //=============================================================================
133 * Associates <this> mesh with <theShape> and puts a reference
134 * to <theShape> into the current study;
135 * the previous shape is substituted by the new one.
137 //=============================================================================
139 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
140 throw (SALOME::SALOME_Exception)
142 Unexpect aCatch(SALOME_SalomeException);
144 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
146 catch(SALOME_Exception & S_ex) {
147 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
149 // to track changes of GEOM groups
150 addGeomGroupData( theShapeObject, _this() );
153 //================================================================================
155 * \brief return true if mesh has a shape to build a shape on
157 //================================================================================
159 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
160 throw (SALOME::SALOME_Exception)
162 Unexpect aCatch(SALOME_SalomeException);
165 res = _impl->HasShapeToMesh();
167 catch(SALOME_Exception & S_ex) {
168 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
173 //=======================================================================
174 //function : GetShapeToMesh
176 //=======================================================================
178 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
179 throw (SALOME::SALOME_Exception)
181 Unexpect aCatch(SALOME_SalomeException);
182 GEOM::GEOM_Object_var aShapeObj;
184 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
186 aShapeObj = _gen_i->ShapeToGeomObject( S );
188 catch(SALOME_Exception & S_ex) {
189 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
191 return aShapeObj._retn();
194 //================================================================================
196 * \brief Remove all nodes and elements
198 //================================================================================
200 void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
202 Unexpect aCatch(SALOME_SalomeException);
206 catch(SALOME_Exception & S_ex) {
207 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
209 TPythonDump() << _this() << ".Clear()";
212 //=============================================================================
216 //=============================================================================
218 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
220 SMESH::DriverMED_ReadStatus res;
223 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
224 res = SMESH::DRS_OK; break;
225 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
226 res = SMESH::DRS_EMPTY; break;
227 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
228 res = SMESH::DRS_WARN_RENUMBER; break;
229 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
230 res = SMESH::DRS_WARN_SKIP_ELEM; break;
231 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
233 res = SMESH::DRS_FAIL; break;
238 //=============================================================================
242 * Imports mesh data from MED file
244 //=============================================================================
246 SMESH::DriverMED_ReadStatus
247 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
248 throw ( SALOME::SALOME_Exception )
250 Unexpect aCatch(SALOME_SalomeException);
253 status = _impl->MEDToMesh( theFileName, theMeshName );
255 catch( SALOME_Exception& S_ex ) {
256 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
259 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
262 CreateGroupServants();
264 int major, minor, release;
265 if( !MED::getMEDVersion( theFileName, major, minor, release ) )
266 major = minor = release = -1;
267 myFileInfo = new SALOME_MED::MedFileInfo();
268 myFileInfo->fileName = theFileName;
269 myFileInfo->fileSize = 0;
272 if ( ::_stati64( theFileName, &d ) != -1 )
275 if ( ::stat64( theFileName, &d ) != -1 )
277 myFileInfo->fileSize = d.st_size;
278 myFileInfo->major = major;
279 myFileInfo->minor = minor;
280 myFileInfo->release = release;
282 return ConvertDriverMEDReadStatus(status);
285 //================================================================================
287 * \brief Return string representation of a MED file version comprising nbDigits
289 //================================================================================
291 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
293 std::string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
295 return CORBA::string_dup( ver.c_str() );
298 //=============================================================================
302 * Imports mesh data from MED file
304 //=============================================================================
306 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
307 throw ( SALOME::SALOME_Exception )
309 // Read mesh with name = <theMeshName> into SMESH_Mesh
310 _impl->UNVToMesh( theFileName );
312 CreateGroupServants();
317 //=============================================================================
321 * Imports mesh data from STL file
323 //=============================================================================
324 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
325 throw ( SALOME::SALOME_Exception )
327 // Read mesh with name = <theMeshName> into SMESH_Mesh
328 _impl->STLToMesh( theFileName );
333 //=============================================================================
337 * Imports mesh data from MED file
339 //=============================================================================
341 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
343 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
344 // int status = _impl->MEDToMesh( theFileName, theMeshName );
345 // CreateGroupServants();
350 //=============================================================================
354 //=============================================================================
356 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
358 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
359 (SMESH_Hypothesis::Hypothesis_Status theStatus)
362 RETURNCASE( HYP_OK );
363 RETURNCASE( HYP_MISSING );
364 RETURNCASE( HYP_CONCURENT );
365 RETURNCASE( HYP_BAD_PARAMETER );
366 RETURNCASE( HYP_HIDDEN_ALGO );
367 RETURNCASE( HYP_HIDING_ALGO );
368 RETURNCASE( HYP_UNKNOWN_FATAL );
369 RETURNCASE( HYP_INCOMPATIBLE );
370 RETURNCASE( HYP_NOTCONFORM );
371 RETURNCASE( HYP_ALREADY_EXIST );
372 RETURNCASE( HYP_BAD_DIM );
373 RETURNCASE( HYP_BAD_SUBSHAPE );
374 RETURNCASE( HYP_BAD_GEOMETRY );
375 RETURNCASE( HYP_NEED_SHAPE );
378 return SMESH::HYP_UNKNOWN_FATAL;
381 //=============================================================================
385 * calls internal addHypothesis() and then adds a reference to <anHyp> under
386 * the SObject actually having a reference to <aSubShape>.
387 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
389 //=============================================================================
391 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
392 SMESH::SMESH_Hypothesis_ptr anHyp)
393 throw(SALOME::SALOME_Exception)
395 Unexpect aCatch(SALOME_SalomeException);
396 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
398 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
399 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
400 aSubShapeObject, anHyp );
402 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
404 // Update Python script
405 if(_impl->HasShapeToMesh()) {
406 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
407 << aSubShapeObject << ", " << anHyp << " )";
410 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
413 return ConvertHypothesisStatus(status);
416 //=============================================================================
420 //=============================================================================
422 SMESH_Hypothesis::Hypothesis_Status
423 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
424 SMESH::SMESH_Hypothesis_ptr anHyp)
426 if(MYDEBUG) MESSAGE("addHypothesis");
428 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
429 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
432 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
433 if (CORBA::is_nil(myHyp))
434 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
437 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
440 TopoDS_Shape myLocSubShape;
441 //use PseudoShape in case if mesh has no shape
443 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
445 myLocSubShape = _impl->GetShapeToMesh();
447 int hypId = myHyp->GetId();
448 status = _impl->AddHypothesis(myLocSubShape, hypId);
449 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
450 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
451 // assure there is a corresponding submesh
452 if ( !_impl->IsMainShape( myLocSubShape )) {
453 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
454 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
455 createSubMesh( aSubShapeObject );
459 catch(SALOME_Exception & S_ex)
461 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
466 //=============================================================================
470 //=============================================================================
472 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
473 SMESH::SMESH_Hypothesis_ptr anHyp)
474 throw(SALOME::SALOME_Exception)
476 Unexpect aCatch(SALOME_SalomeException);
477 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
479 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
480 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
481 aSubShapeObject, anHyp );
483 // Update Python script
484 // Update Python script
485 if(_impl->HasShapeToMesh()) {
486 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
487 << aSubShapeObject << ", " << anHyp << " )";
490 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
494 return ConvertHypothesisStatus(status);
497 //=============================================================================
501 //=============================================================================
503 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
504 SMESH::SMESH_Hypothesis_ptr anHyp)
506 if(MYDEBUG) MESSAGE("removeHypothesis()");
507 // **** proposer liste de subShape (selection multiple)
509 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
510 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
513 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
514 if (CORBA::is_nil(myHyp))
515 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
518 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
521 TopoDS_Shape myLocSubShape;
522 //use PseudoShape in case if mesh has no shape
524 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
526 myLocSubShape = _impl->GetShapeToMesh();
528 int hypId = myHyp->GetId();
529 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
530 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
531 _mapHypo.erase( hypId );
533 catch(SALOME_Exception & S_ex)
535 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
540 //=============================================================================
544 //=============================================================================
546 SMESH::ListOfHypothesis *
547 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
548 throw(SALOME::SALOME_Exception)
550 Unexpect aCatch(SALOME_SalomeException);
551 if (MYDEBUG) MESSAGE("GetHypothesisList");
552 if (_impl->HasShapeToMesh() && CORBA::is_nil(aSubShapeObject))
553 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
556 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
559 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
560 if ( myLocSubShape.IsNull() && !_impl->HasShapeToMesh() )
561 myLocSubShape = _impl->GetShapeToMesh();
562 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
563 int i = 0, n = aLocalList.size();
566 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
567 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
568 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
569 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
574 catch(SALOME_Exception & S_ex) {
575 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
578 return aList._retn();
581 //=============================================================================
585 //=============================================================================
586 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
587 const char* theName )
588 throw(SALOME::SALOME_Exception)
590 Unexpect aCatch(SALOME_SalomeException);
591 MESSAGE("SMESH_Mesh_i::GetSubMesh");
592 if (CORBA::is_nil(aSubShapeObject))
593 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
596 SMESH::SMESH_subMesh_var subMesh;
597 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
599 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
601 //Get or Create the SMESH_subMesh object implementation
603 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
604 subMesh = getSubMesh( subMeshId );
606 // create a new subMesh object servant if there is none for the shape
607 if ( subMesh->_is_nil() )
608 subMesh = createSubMesh( aSubShapeObject );
609 if ( _gen_i->CanPublishInStudy( subMesh )) {
610 SALOMEDS::SObject_var aSO =
611 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
612 subMesh, aSubShapeObject, theName );
613 if ( !aSO->_is_nil()) {
614 // Update Python script
615 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
616 << aSubShapeObject << ", '" << theName << "' )";
620 catch(SALOME_Exception & S_ex) {
621 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
623 return subMesh._retn();
626 //=============================================================================
630 //=============================================================================
632 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
633 throw (SALOME::SALOME_Exception)
635 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
636 if ( theSubMesh->_is_nil() )
639 GEOM::GEOM_Object_var aSubShapeObject;
640 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
641 if ( !aStudy->_is_nil() ) {
642 // Remove submesh's SObject
643 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
644 if ( !anSO->_is_nil() ) {
645 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
646 SALOMEDS::SObject_var anObj, aRef;
647 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
648 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
650 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
652 // Update Python script
653 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
657 removeSubMesh( theSubMesh, aSubShapeObject.in() );
660 //=============================================================================
664 //=============================================================================
665 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
666 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
668 switch (theElemType) {
673 CASE2STRING( VOLUME );
679 //=============================================================================
683 //=============================================================================
685 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
686 const char* theName )
687 throw(SALOME::SALOME_Exception)
689 Unexpect aCatch(SALOME_SalomeException);
690 SMESH::SMESH_Group_var aNewGroup =
691 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
693 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
694 SALOMEDS::SObject_var aSO =
695 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
696 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
697 if ( !aSO->_is_nil()) {
698 // Update Python script
699 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
700 << ElementTypeString(theElemType) << ", '" << theName << "' )";
703 return aNewGroup._retn();
707 //=============================================================================
711 //=============================================================================
712 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
714 GEOM::GEOM_Object_ptr theGeomObj)
715 throw(SALOME::SALOME_Exception)
717 Unexpect aCatch(SALOME_SalomeException);
718 SMESH::SMESH_GroupOnGeom_var aNewGroup;
720 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
721 if ( !aShape.IsNull() )
723 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
724 ( createGroup( theElemType, theName, aShape ));
726 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
727 SALOMEDS::SObject_var aSO =
728 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
729 aNewGroup, theGeomObj, theName);
730 if ( !aSO->_is_nil()) {
731 // Update Python script
732 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
733 << ElementTypeString(theElemType) << ", '" << theName << "', "
734 << theGeomObj << " )";
739 return aNewGroup._retn();
742 //=============================================================================
746 //=============================================================================
748 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
749 throw (SALOME::SALOME_Exception)
751 if ( theGroup->_is_nil() )
754 SMESH_GroupBase_i* aGroup =
755 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
759 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
760 if ( !aStudy->_is_nil() ) {
761 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
763 if ( !aGroupSO->_is_nil() ) {
764 // Update Python script
765 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
767 // Remove group's SObject
768 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
772 // Remove the group from SMESH data structures
773 removeGroup( aGroup->GetLocalID() );
776 //=============================================================================
777 /*! RemoveGroupWithContents
778 * Remove group with its contents
780 //=============================================================================
781 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
782 throw (SALOME::SALOME_Exception)
784 if ( theGroup->_is_nil() )
787 SMESH_GroupBase_i* aGroup =
788 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
792 SMESH::long_array_var anIds = aGroup->GetListOfID();
793 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
795 // Update Python script
796 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
799 if ( aGroup->GetType() == SMESH::NODE )
800 aMeshEditor->RemoveNodes( anIds );
802 aMeshEditor->RemoveElements( anIds );
805 RemoveGroup( theGroup );
807 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
808 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
809 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
813 //================================================================================
815 * \brief Get the list of groups existing in the mesh
816 * \retval SMESH::ListOfGroups * - list of groups
818 //================================================================================
820 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
822 Unexpect aCatch(SALOME_SalomeException);
823 if (MYDEBUG) MESSAGE("GetGroups");
825 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
828 TPythonDump aPythonDump;
829 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
833 aList->length( _mapGroups.size() );
835 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
836 for ( ; it != _mapGroups.end(); it++ ) {
837 if ( CORBA::is_nil( it->second )) continue;
838 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
840 if (i > 1) aPythonDump << ", ";
841 aPythonDump << it->second;
845 catch(SALOME_Exception & S_ex) {
846 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
849 // Update Python script
850 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
851 aPythonDump << " ] = " << _this() << ".GetGroups()";
853 return aList._retn();
855 //=============================================================================
857 * Get number of groups existing in the mesh
859 //=============================================================================
861 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
863 Unexpect aCatch(SALOME_SalomeException);
864 return _mapGroups.size();
867 //=============================================================================
869 * New group is created. All mesh elements that are
870 * present in initial groups are added to the new one
872 //=============================================================================
873 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
874 SMESH::SMESH_GroupBase_ptr theGroup2,
875 const char* theName )
876 throw (SALOME::SALOME_Exception)
880 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
881 theGroup1->GetType() != theGroup2->GetType() )
882 return SMESH::SMESH_Group::_nil();
885 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
886 if ( aResGrp->_is_nil() )
887 return SMESH::SMESH_Group::_nil();
889 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
890 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
892 TColStd_MapOfInteger aResMap;
894 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
895 aResMap.Add( anIds1[ i1 ] );
897 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
898 aResMap.Add( anIds2[ i2 ] );
900 SMESH::long_array_var aResIds = new SMESH::long_array;
901 aResIds->length( aResMap.Extent() );
904 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
905 for( ; anIter.More(); anIter.Next() )
906 aResIds[ resI++ ] = anIter.Key();
908 aResGrp->Add( aResIds );
910 // Clear python lines, created by CreateGroup() and Add()
911 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
912 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
913 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
915 // Update Python script
916 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
917 << theGroup1 << ", " << theGroup2 << ", '"
920 return aResGrp._retn();
924 return SMESH::SMESH_Group::_nil();
928 //=============================================================================
930 * New group is created. All mesh elements that are
931 * present in both initial groups are added to the new one.
933 //=============================================================================
934 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
935 SMESH::SMESH_GroupBase_ptr theGroup2,
936 const char* theName )
937 throw (SALOME::SALOME_Exception)
939 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
940 theGroup1->GetType() != theGroup2->GetType() )
941 return SMESH::SMESH_Group::_nil();
943 // Create Intersection
944 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
945 if ( aResGrp->_is_nil() )
948 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
949 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
951 TColStd_MapOfInteger aMap1;
953 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
954 aMap1.Add( anIds1[ i1 ] );
956 TColStd_SequenceOfInteger aSeq;
958 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
959 if ( aMap1.Contains( anIds2[ i2 ] ) )
960 aSeq.Append( anIds2[ i2 ] );
962 SMESH::long_array_var aResIds = new SMESH::long_array;
963 aResIds->length( aSeq.Length() );
965 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
966 aResIds[ resI ] = aSeq( resI + 1 );
968 aResGrp->Add( aResIds );
970 // Clear python lines, created by CreateGroup() and Add()
971 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
972 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
973 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
975 // Update Python script
976 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
977 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
979 return aResGrp._retn();
982 //=============================================================================
984 * New group is created. All mesh elements that are present in
985 * main group but do not present in tool group are added to the new one
987 //=============================================================================
988 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
989 SMESH::SMESH_GroupBase_ptr theGroup2,
990 const char* theName )
991 throw (SALOME::SALOME_Exception)
993 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
994 theGroup1->GetType() != theGroup2->GetType() )
995 return SMESH::SMESH_Group::_nil();
998 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
999 if ( aResGrp->_is_nil() )
1002 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1003 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1005 TColStd_MapOfInteger aMap2;
1007 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1008 aMap2.Add( anIds2[ i2 ] );
1010 TColStd_SequenceOfInteger aSeq;
1011 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1012 if ( !aMap2.Contains( anIds1[ i1 ] ) )
1013 aSeq.Append( anIds1[ i1 ] );
1015 SMESH::long_array_var aResIds = new SMESH::long_array;
1016 aResIds->length( aSeq.Length() );
1018 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1019 aResIds[ resI ] = aSeq( resI + 1 );
1021 aResGrp->Add( aResIds );
1023 // Clear python lines, created by CreateGroup() and Add()
1024 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1025 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1026 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1028 // Update Python script
1029 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1030 << theGroup1 << ", " << theGroup2 << ", '"
1031 << theName << "' )";
1033 return aResGrp._retn();
1036 //================================================================================
1038 * \brief Remember GEOM group data
1040 //================================================================================
1042 void SMESH_Mesh_i::addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
1043 CORBA::Object_ptr theSmeshObj)
1045 if ( CORBA::is_nil( theGeomObj ) || theGeomObj->GetType() != GEOM_GROUP )
1048 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1049 SALOMEDS::SObject_var groupSO = _gen_i->ObjectToSObject( study, theGeomObj );
1050 if ( groupSO->_is_nil() )
1053 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1054 GEOM::GEOM_IGroupOperations_var groupOp =
1055 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1056 GEOM::ListOfLong_var ids = groupOp->GetObjects( theGeomObj );
1059 _geomGroupData.push_back( TGeomGroupData() );
1060 TGeomGroupData & groupData = _geomGroupData.back();
1062 CORBA::String_var entry = groupSO->GetID();
1063 groupData._groupEntry = entry.in();
1065 for ( int i = 0; i < ids->length(); ++i )
1066 groupData._indices.insert( ids[i] );
1068 groupData._smeshObject = theSmeshObj;
1071 //================================================================================
1073 * Remove GEOM group data relating to removed smesh object
1075 //================================================================================
1077 void SMESH_Mesh_i::removeGeomGroupData(CORBA::Object_ptr theSmeshObj)
1079 list<TGeomGroupData>::iterator
1080 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1081 for ( ; data != dataEnd; ++data ) {
1082 if ( theSmeshObj->_is_equivalent( data->_smeshObject )) {
1083 _geomGroupData.erase( data );
1089 //================================================================================
1091 * \brief Return new group contents if it has been changed and update group data
1093 //================================================================================
1095 TopoDS_Shape SMESH_Mesh_i::newGroupShape( TGeomGroupData & groupData)
1097 TopoDS_Shape newShape;
1100 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1101 if ( study->_is_nil() ) return newShape; // means "not changed"
1102 SALOMEDS::SObject_var groupSO = study->FindObjectID( groupData._groupEntry.c_str() );
1103 if ( !groupSO->_is_nil() )
1105 CORBA::Object_var groupObj = _gen_i->SObjectToObject( groupSO );
1106 if ( CORBA::is_nil( groupObj )) return newShape;
1107 GEOM::GEOM_Object_var geomGroup = GEOM::GEOM_Object::_narrow( groupObj );
1109 // get indices of group items
1110 set<int> curIndices;
1111 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1112 GEOM::GEOM_IGroupOperations_var groupOp =
1113 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1114 GEOM::ListOfLong_var ids = groupOp->GetObjects( geomGroup );
1115 for ( int i = 0; i < ids->length(); ++i )
1116 curIndices.insert( ids[i] );
1118 if ( groupData._indices == curIndices )
1119 return newShape; // group not changed
1122 groupData._indices = curIndices;
1124 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1125 if ( !geomClient ) return newShape;
1126 TCollection_AsciiString groupIOR = geomGen->GetStringFromIOR( geomGroup );
1127 geomClient->RemoveShapeFromBuffer( groupIOR );
1128 newShape = _gen_i->GeomObjectToShape( geomGroup );
1131 if ( newShape.IsNull() ) {
1132 // geom group becomes empty - return empty compound
1133 TopoDS_Compound compound;
1134 BRep_Builder builder;
1135 builder.MakeCompound(compound);
1136 newShape = compound;
1141 //=============================================================================
1143 * \brief Update objects depending on changed geom groups
1145 * NPAL16168: geometrical group edition from a submesh don't modifiy mesh computation
1146 * issue 0020210: Update of a smesh group after modification of the associated geom group
1148 //=============================================================================
1150 void SMESH_Mesh_i::CheckGeomGroupModif()
1152 if ( !_impl->HasShapeToMesh() ) return;
1154 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1155 if ( study->_is_nil() ) return;
1157 CORBA::Long nbEntities = NbNodes() + NbElements();
1159 // Check if group contents changed
1161 typedef map< string, TopoDS_Shape > TEntry2Geom;
1162 TEntry2Geom newGroupContents;
1164 list<TGeomGroupData>::iterator
1165 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1166 for ( ; data != dataEnd; ++data )
1168 pair< TEntry2Geom::iterator, bool > it_new =
1169 newGroupContents.insert( make_pair( data->_groupEntry, TopoDS_Shape() ));
1170 bool processedGroup = !it_new.second;
1171 TopoDS_Shape& newShape = it_new.first->second;
1172 if ( !processedGroup )
1173 newShape = newGroupShape( *data );
1174 if ( newShape.IsNull() )
1175 continue; // no changes
1177 if ( processedGroup ) { // update group indices
1178 list<TGeomGroupData>::iterator data2 = data;
1179 for ( --data2; data2->_groupEntry != data->_groupEntry; --data2)
1180 data->_indices = data2->_indices;
1183 // Update SMESH objects according to new GEOM group contents
1185 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( data->_smeshObject );
1186 if ( !mesh->_is_nil() ) // -------------- MESH ----------------------------
1192 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( data->_smeshObject );
1193 if ( !submesh->_is_nil() ) // -------------- Sub mesh ---------------------
1195 int oldID = submesh->GetId();
1196 if ( _mapSubMeshIor.find( oldID ) == _mapSubMeshIor.end() )
1198 TopoDS_Shape oldShape = _mapSubMesh[oldID]->GetSubShape();
1200 // update hypotheses
1201 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldShape);
1202 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1203 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1205 _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
1206 _impl->AddHypothesis ( newShape, (*hypIt)->GetID());
1208 // care of submeshes
1209 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newShape );
1210 int newID = newSubmesh->GetId();
1211 if ( newID != oldID ) {
1212 _mapSubMesh [ newID ] = newSubmesh;
1213 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1214 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1215 _mapSubMesh. erase(oldID);
1216 _mapSubMesh_i. erase(oldID);
1217 _mapSubMeshIor.erase(oldID);
1218 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1223 SMESH::SMESH_GroupOnGeom_var smeshGroup =
1224 SMESH::SMESH_GroupOnGeom::_narrow( data->_smeshObject );
1225 if ( !smeshGroup->_is_nil() ) // ------------ GROUP -----------------------
1227 SMESH_GroupOnGeom_i* group_i = SMESH::DownCast<SMESH_GroupOnGeom_i*>( smeshGroup );
1229 ::SMESH_Group* group = _impl->GetGroup( group_i->GetLocalID() );
1230 SMESHDS_GroupOnGeom* ds = static_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() );
1231 ds->SetShape( newShape );
1239 CORBA::Long newNbEntities = NbNodes() + NbElements();
1240 list< SALOMEDS::SObject_var > soToUpdateIcons;
1241 if ( newNbEntities != nbEntities )
1243 // Add all SObjects with icons
1244 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, _this() )); // mesh
1246 for (map<int, SMESH::SMESH_subMesh_ptr>::iterator i_sm = _mapSubMeshIor.begin();
1247 i_sm != _mapSubMeshIor.end(); ++i_sm ) // submeshes
1248 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_sm->second ));
1250 for ( map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_gr = _mapGroups.begin();
1251 i_gr != _mapGroups.end(); ++i_gr ) // groups
1252 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_gr->second ));
1255 list< SALOMEDS::SObject_var >::iterator so = soToUpdateIcons.begin();
1256 for ( ; so != soToUpdateIcons.end(); ++so )
1257 _gen_i->SetPixMap( *so, "ICON_SMESH_TREE_MESH_WARN" );
1260 //=============================================================================
1264 //=============================================================================
1266 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1268 if(MYDEBUG) MESSAGE( "createSubMesh" );
1269 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1271 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1272 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1273 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1274 SMESH::SMESH_subMesh_var subMesh
1275 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1277 _mapSubMesh[subMeshId] = mySubMesh;
1278 _mapSubMesh_i[subMeshId] = subMeshServant;
1279 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1281 // register CORBA object for persistence
1282 int nextId = _gen_i->RegisterObject( subMesh );
1283 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1285 // to track changes of GEOM groups
1286 addGeomGroupData( theSubShapeObject, subMesh );
1288 return subMesh._retn();
1291 //=======================================================================
1292 //function : getSubMesh
1294 //=======================================================================
1296 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1298 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1299 if ( it == _mapSubMeshIor.end() )
1300 return SMESH::SMESH_subMesh::_nil();
1302 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1306 //=============================================================================
1310 //=============================================================================
1312 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1313 GEOM::GEOM_Object_ptr theSubShapeObject )
1315 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1316 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1320 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1321 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1322 removeHypothesis( theSubShapeObject, aHypList[i] );
1325 catch( const SALOME::SALOME_Exception& ) {
1326 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1328 removeGeomGroupData( theSubShapeObject );
1330 int subMeshId = theSubMesh->GetId();
1332 _mapSubMesh.erase(subMeshId);
1333 _mapSubMesh_i.erase(subMeshId);
1334 _mapSubMeshIor.erase(subMeshId);
1335 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1338 //=============================================================================
1342 //=============================================================================
1344 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1345 const char* theName,
1346 const TopoDS_Shape& theShape )
1349 SMESH::SMESH_GroupBase_var aGroup;
1350 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1351 SMESH_GroupBase_i* aGroupImpl;
1352 if ( !theShape.IsNull() )
1353 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1355 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1357 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1358 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1359 aGroupImpl->Register();
1360 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1362 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1363 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1365 // register CORBA object for persistence
1366 int nextId = _gen_i->RegisterObject( aGroup );
1367 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1369 // to track changes of GEOM groups
1370 if ( !theShape.IsNull() ) {
1371 GEOM::GEOM_Object_var geom = _gen_i->ShapeToGeomObject( theShape );
1372 addGeomGroupData( geom, aGroup );
1375 return aGroup._retn();
1378 //=============================================================================
1380 * SMESH_Mesh_i::removeGroup
1382 * Should be called by ~SMESH_Group_i()
1384 //=============================================================================
1386 void SMESH_Mesh_i::removeGroup( const int theId )
1388 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1389 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1390 removeGeomGroupData( _mapGroups[theId] );
1391 _mapGroups.erase( theId );
1392 _impl->RemoveGroup( theId );
1397 //=============================================================================
1401 //=============================================================================
1403 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1404 throw(SALOME::SALOME_Exception)
1406 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1408 SMESH::log_array_var aLog;
1410 list < SMESHDS_Command * >logDS = _impl->GetLog();
1411 aLog = new SMESH::log_array;
1413 int lg = logDS.size();
1416 list < SMESHDS_Command * >::iterator its = logDS.begin();
1417 while(its != logDS.end()){
1418 SMESHDS_Command *com = *its;
1419 int comType = com->GetType();
1421 int lgcom = com->GetNumber();
1423 const list < int >&intList = com->GetIndexes();
1424 int inum = intList.size();
1426 list < int >::const_iterator ii = intList.begin();
1427 const list < double >&coordList = com->GetCoords();
1428 int rnum = coordList.size();
1430 list < double >::const_iterator ir = coordList.begin();
1431 aLog[indexLog].commandType = comType;
1432 aLog[indexLog].number = lgcom;
1433 aLog[indexLog].coords.length(rnum);
1434 aLog[indexLog].indexes.length(inum);
1435 for(int i = 0; i < rnum; i++){
1436 aLog[indexLog].coords[i] = *ir;
1437 //MESSAGE(" "<<i<<" "<<ir.Value());
1440 for(int i = 0; i < inum; i++){
1441 aLog[indexLog].indexes[i] = *ii;
1442 //MESSAGE(" "<<i<<" "<<ii.Value());
1451 catch(SALOME_Exception & S_ex){
1452 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1454 return aLog._retn();
1458 //=============================================================================
1462 //=============================================================================
1464 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1466 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1470 //=============================================================================
1474 //=============================================================================
1476 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1478 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1482 //=============================================================================
1486 //=============================================================================
1488 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1493 //=============================================================================
1497 //=============================================================================
1499 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1501 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1505 //=============================================================================
1509 //=============================================================================
1511 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1513 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1517 //=============================================================================
1519 * Return mesh editor
1521 //=============================================================================
1523 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1525 // Create MeshEditor
1526 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1527 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1529 // Update Python script
1530 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1532 return aMesh._retn();
1535 //=============================================================================
1537 * Return mesh edition previewer
1539 //=============================================================================
1541 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1543 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1544 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1545 return aMesh._retn();
1548 //=============================================================================
1552 //=============================================================================
1553 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1555 Unexpect aCatch(SALOME_SalomeException);
1556 _impl->SetAutoColor(theAutoColor);
1559 //=============================================================================
1563 //=============================================================================
1564 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1566 Unexpect aCatch(SALOME_SalomeException);
1567 return _impl->GetAutoColor();
1571 //=============================================================================
1573 * Export in different formats
1575 //=============================================================================
1577 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1579 return _impl->HasDuplicatedGroupNamesMED();
1582 void SMESH_Mesh_i::PrepareForWriting (const char* file)
1584 TCollection_AsciiString aFullName ((char*)file);
1585 OSD_Path aPath (aFullName);
1586 OSD_File aFile (aPath);
1587 if (aFile.Exists()) {
1588 // existing filesystem node
1589 if (aFile.KindOfFile() == OSD_FILE) {
1590 if (aFile.IsWriteable()) {
1593 if (aFile.Failed()) {
1594 TCollection_AsciiString msg ("File ");
1595 msg += aFullName + " cannot be replaced.";
1596 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1599 TCollection_AsciiString msg ("File ");
1600 msg += aFullName + " cannot be overwritten.";
1601 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1604 TCollection_AsciiString msg ("Location ");
1605 msg += aFullName + " is not a file.";
1606 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1609 // nonexisting file; check if it can be created
1611 aFile.Build(OSD_WriteOnly, OSD_Protection());
1612 if (aFile.Failed()) {
1613 TCollection_AsciiString msg ("You cannot create the file ");
1614 msg += aFullName + ". Check the directory existance and access rights.";
1615 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1623 void SMESH_Mesh_i::ExportToMED (const char* file,
1624 CORBA::Boolean auto_groups,
1625 SMESH::MED_VERSION theVersion)
1626 throw(SALOME::SALOME_Exception)
1628 Unexpect aCatch(SALOME_SalomeException);
1630 // Update Python script
1631 TPythonDump() << _this() << ".ExportToMED( '"
1632 << file << "', " << auto_groups << ", " << theVersion << " )";
1635 PrepareForWriting(file);
1636 char* aMeshName = "Mesh";
1637 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1638 if ( !aStudy->_is_nil() ) {
1639 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1640 if ( !aMeshSO->_is_nil() ) {
1641 aMeshName = aMeshSO->GetName();
1643 //SCRUTE(aMeshName);
1644 //SCRUTE(aMeshSO->GetID());
1646 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1647 if ( !aStudy->GetProperties()->IsLocked() )
1649 SALOMEDS::GenericAttribute_var anAttr;
1650 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1651 SALOMEDS::AttributeExternalFileDef_var aFileName;
1652 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1653 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1654 ASSERT(!aFileName->_is_nil());
1655 aFileName->SetValue(file);
1656 SALOMEDS::AttributeFileType_var aFileType;
1657 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1658 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1659 ASSERT(!aFileType->_is_nil());
1660 aFileType->SetValue("FICHIERMED");
1664 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1667 void SMESH_Mesh_i::ExportMED (const char* file,
1668 CORBA::Boolean auto_groups)
1669 throw(SALOME::SALOME_Exception)
1671 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1674 void SMESH_Mesh_i::ExportDAT (const char *file)
1675 throw(SALOME::SALOME_Exception)
1677 Unexpect aCatch(SALOME_SalomeException);
1679 // Update Python script
1680 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1683 PrepareForWriting(file);
1684 _impl->ExportDAT(file);
1687 void SMESH_Mesh_i::ExportUNV (const char *file)
1688 throw(SALOME::SALOME_Exception)
1690 Unexpect aCatch(SALOME_SalomeException);
1692 // Update Python script
1693 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1696 PrepareForWriting(file);
1697 _impl->ExportUNV(file);
1700 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1701 throw(SALOME::SALOME_Exception)
1703 Unexpect aCatch(SALOME_SalomeException);
1705 // Update Python script
1706 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1709 PrepareForWriting(file);
1710 _impl->ExportSTL(file, isascii);
1713 //=============================================================================
1717 //=============================================================================
1719 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1721 Unexpect aCatch(SALOME_SalomeException);
1722 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1723 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1724 return aMesh._retn();
1727 //=============================================================================
1731 //=============================================================================
1732 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1734 Unexpect aCatch(SALOME_SalomeException);
1735 return _impl->NbNodes();
1738 //=============================================================================
1742 //=============================================================================
1743 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1745 Unexpect aCatch(SALOME_SalomeException);
1746 return NbEdges() + NbFaces() + NbVolumes();
1749 //=============================================================================
1753 //=============================================================================
1754 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1756 Unexpect aCatch(SALOME_SalomeException);
1757 return _impl->NbEdges();
1760 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1761 throw(SALOME::SALOME_Exception)
1763 Unexpect aCatch(SALOME_SalomeException);
1764 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
1767 //=============================================================================
1771 //=============================================================================
1772 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1774 Unexpect aCatch(SALOME_SalomeException);
1775 return _impl->NbFaces();
1778 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1780 Unexpect aCatch(SALOME_SalomeException);
1781 return _impl->NbTriangles();
1784 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1786 Unexpect aCatch(SALOME_SalomeException);
1787 return _impl->NbQuadrangles();
1790 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1792 Unexpect aCatch(SALOME_SalomeException);
1793 return _impl->NbPolygons();
1796 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1797 throw(SALOME::SALOME_Exception)
1799 Unexpect aCatch(SALOME_SalomeException);
1800 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
1803 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1804 throw(SALOME::SALOME_Exception)
1806 Unexpect aCatch(SALOME_SalomeException);
1807 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
1810 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1811 throw(SALOME::SALOME_Exception)
1813 Unexpect aCatch(SALOME_SalomeException);
1814 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
1817 //=============================================================================
1821 //=============================================================================
1822 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1824 Unexpect aCatch(SALOME_SalomeException);
1825 return _impl->NbVolumes();
1828 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1830 Unexpect aCatch(SALOME_SalomeException);
1831 return _impl->NbTetras();
1834 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1836 Unexpect aCatch(SALOME_SalomeException);
1837 return _impl->NbHexas();
1840 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1842 Unexpect aCatch(SALOME_SalomeException);
1843 return _impl->NbPyramids();
1846 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1848 Unexpect aCatch(SALOME_SalomeException);
1849 return _impl->NbPrisms();
1852 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1854 Unexpect aCatch(SALOME_SalomeException);
1855 return _impl->NbPolyhedrons();
1858 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1859 throw(SALOME::SALOME_Exception)
1861 Unexpect aCatch(SALOME_SalomeException);
1862 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
1865 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1866 throw(SALOME::SALOME_Exception)
1868 Unexpect aCatch(SALOME_SalomeException);
1869 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
1872 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1873 throw(SALOME::SALOME_Exception)
1875 Unexpect aCatch(SALOME_SalomeException);
1876 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
1879 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1880 throw(SALOME::SALOME_Exception)
1882 Unexpect aCatch(SALOME_SalomeException);
1883 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
1886 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1887 throw(SALOME::SALOME_Exception)
1889 Unexpect aCatch(SALOME_SalomeException);
1890 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
1893 //=============================================================================
1897 //=============================================================================
1898 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1900 Unexpect aCatch(SALOME_SalomeException);
1901 return _mapSubMesh_i.size();
1904 //=============================================================================
1908 //=============================================================================
1909 char* SMESH_Mesh_i::Dump()
1911 std::ostringstream os;
1913 return CORBA::string_dup( os.str().c_str() );
1916 //=============================================================================
1920 //=============================================================================
1921 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1923 // SMESH::long_array_var aResult = new SMESH::long_array();
1924 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1925 // int aMinId = aSMESHDS_Mesh->MinElementID();
1926 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1928 // aResult->length(aMaxId - aMinId + 1);
1930 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1931 // aResult[i++] = id;
1933 // return aResult._retn();
1935 return GetElementsId();
1938 //=============================================================================
1942 //=============================================================================
1944 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1945 throw (SALOME::SALOME_Exception)
1947 Unexpect aCatch(SALOME_SalomeException);
1948 MESSAGE("SMESH_Mesh_i::GetElementsId");
1949 SMESH::long_array_var aResult = new SMESH::long_array();
1950 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1952 if ( aSMESHDS_Mesh == NULL )
1953 return aResult._retn();
1955 long nbElements = NbElements();
1956 aResult->length( nbElements );
1957 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1958 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1959 aResult[i] = anIt->next()->GetID();
1961 return aResult._retn();
1965 //=============================================================================
1969 //=============================================================================
1971 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1972 throw (SALOME::SALOME_Exception)
1974 Unexpect aCatch(SALOME_SalomeException);
1975 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1976 SMESH::long_array_var aResult = new SMESH::long_array();
1977 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1979 if ( aSMESHDS_Mesh == NULL )
1980 return aResult._retn();
1982 long nbElements = NbElements();
1984 // No sense in returning ids of elements along with ids of nodes:
1985 // when theElemType == SMESH::ALL, return node ids only if
1986 // there are no elements
1987 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1988 return GetNodesId();
1990 aResult->length( nbElements );
1994 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1995 while ( i < nbElements && anIt->more() ) {
1996 const SMDS_MeshElement* anElem = anIt->next();
1997 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1998 aResult[i++] = anElem->GetID();
2001 aResult->length( i );
2003 return aResult._retn();
2006 //=============================================================================
2010 //=============================================================================
2012 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
2013 throw (SALOME::SALOME_Exception)
2015 Unexpect aCatch(SALOME_SalomeException);
2016 MESSAGE("SMESH_subMesh_i::GetNodesId");
2017 SMESH::long_array_var aResult = new SMESH::long_array();
2018 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2020 if ( aSMESHDS_Mesh == NULL )
2021 return aResult._retn();
2023 long nbNodes = NbNodes();
2024 aResult->length( nbNodes );
2025 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
2026 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
2027 aResult[i] = anIt->next()->GetID();
2029 return aResult._retn();
2032 //=============================================================================
2036 //=============================================================================
2038 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
2039 throw (SALOME::SALOME_Exception)
2041 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
2045 //=============================================================================
2047 * Returns ID of elements for given submesh
2049 //=============================================================================
2050 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
2051 throw (SALOME::SALOME_Exception)
2053 SMESH::long_array_var aResult = new SMESH::long_array();
2055 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2056 if(!SM) return aResult._retn();
2058 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2059 if(!SDSM) return aResult._retn();
2061 aResult->length(SDSM->NbElements());
2063 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2065 while ( eIt->more() ) {
2066 aResult[i++] = eIt->next()->GetID();
2069 return aResult._retn();
2073 //=============================================================================
2075 * Returns ID of nodes for given submesh
2076 * If param all==true - returns all nodes, else -
2077 * returns only nodes on shapes.
2079 //=============================================================================
2080 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
2081 throw (SALOME::SALOME_Exception)
2083 SMESH::long_array_var aResult = new SMESH::long_array();
2085 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2086 if(!SM) return aResult._retn();
2088 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2089 if(!SDSM) return aResult._retn();
2092 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
2093 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
2094 while ( nIt->more() ) {
2095 const SMDS_MeshNode* elem = nIt->next();
2096 theElems.insert( elem->GetID() );
2099 else { // all nodes of submesh elements
2100 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2101 while ( eIt->more() ) {
2102 const SMDS_MeshElement* anElem = eIt->next();
2103 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
2104 while ( nIt->more() ) {
2105 const SMDS_MeshElement* elem = nIt->next();
2106 theElems.insert( elem->GetID() );
2111 aResult->length(theElems.size());
2112 set<int>::iterator itElem;
2114 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
2115 aResult[i++] = *itElem;
2117 return aResult._retn();
2121 //=============================================================================
2123 * Returns type of elements for given submesh
2125 //=============================================================================
2126 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2127 throw (SALOME::SALOME_Exception)
2129 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2130 if(!SM) return SMESH::ALL;
2132 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2133 if(!SDSM) return SMESH::ALL;
2135 if(SDSM->NbElements()==0)
2136 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2138 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2139 const SMDS_MeshElement* anElem = eIt->next();
2140 return ( SMESH::ElementType ) anElem->GetType();
2144 //=============================================================================
2148 //=============================================================================
2150 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2152 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2154 MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
2159 //=============================================================================
2161 * Get XYZ coordinates of node as list of double
2162 * If there is not node for given ID - returns empty list
2164 //=============================================================================
2166 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2168 SMESH::double_array_var aResult = new SMESH::double_array();
2169 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2170 if ( aSMESHDS_Mesh == NULL )
2171 return aResult._retn();
2174 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2176 return aResult._retn();
2180 aResult[0] = aNode->X();
2181 aResult[1] = aNode->Y();
2182 aResult[2] = aNode->Z();
2183 return aResult._retn();
2187 //=============================================================================
2189 * For given node returns list of IDs of inverse elements
2190 * If there is not node for given ID - returns empty list
2192 //=============================================================================
2194 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2196 SMESH::long_array_var aResult = new SMESH::long_array();
2197 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2198 if ( aSMESHDS_Mesh == NULL )
2199 return aResult._retn();
2202 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2204 return aResult._retn();
2206 // find inverse elements
2207 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2208 TColStd_SequenceOfInteger IDs;
2209 while(eIt->more()) {
2210 const SMDS_MeshElement* elem = eIt->next();
2211 IDs.Append(elem->GetID());
2213 if(IDs.Length()>0) {
2214 aResult->length(IDs.Length());
2216 for(; i<=IDs.Length(); i++) {
2217 aResult[i-1] = IDs.Value(i);
2220 return aResult._retn();
2223 //=============================================================================
2225 * \brief Return position of a node on shape
2227 //=============================================================================
2229 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2231 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2232 aNodePosition->shapeID = 0;
2233 aNodePosition->shapeType = GEOM::SHAPE;
2235 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2236 if ( !mesh ) return aNodePosition;
2238 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2240 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2242 aNodePosition->shapeID = pos->GetShapeId();
2243 switch ( pos->GetTypeOfPosition() ) {
2245 aNodePosition->shapeType = GEOM::EDGE;
2246 aNodePosition->params.length(1);
2247 aNodePosition->params[0] =
2248 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2251 aNodePosition->shapeType = GEOM::FACE;
2252 aNodePosition->params.length(2);
2253 aNodePosition->params[0] =
2254 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2255 aNodePosition->params[1] =
2256 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2258 case SMDS_TOP_VERTEX:
2259 aNodePosition->shapeType = GEOM::VERTEX;
2261 case SMDS_TOP_3DSPACE:
2262 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2263 aNodePosition->shapeType = GEOM::SOLID;
2264 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2265 aNodePosition->shapeType = GEOM::SHELL;
2271 return aNodePosition;
2274 //=============================================================================
2276 * If given element is node returns IDs of shape from position
2277 * If there is not node for given ID - returns -1
2279 //=============================================================================
2281 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2283 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2284 if ( aSMESHDS_Mesh == NULL )
2288 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2290 SMDS_PositionPtr pos = aNode->GetPosition();
2294 return pos->GetShapeId();
2301 //=============================================================================
2303 * For given element returns ID of result shape after
2304 * ::FindShape() from SMESH_MeshEditor
2305 * If there is not element for given ID - returns -1
2307 //=============================================================================
2309 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2311 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2312 if ( aSMESHDS_Mesh == NULL )
2315 // try to find element
2316 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2320 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2321 ::SMESH_MeshEditor aMeshEditor(_impl);
2322 int index = aMeshEditor.FindShape( elem );
2330 //=============================================================================
2332 * Returns number of nodes for given element
2333 * If there is not element for given ID - returns -1
2335 //=============================================================================
2337 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2339 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2340 if ( aSMESHDS_Mesh == NULL ) return -1;
2341 // try to find element
2342 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2343 if(!elem) return -1;
2344 return elem->NbNodes();
2348 //=============================================================================
2350 * Returns ID of node by given index for given element
2351 * If there is not element for given ID - returns -1
2352 * If there is not node for given index - returns -2
2354 //=============================================================================
2356 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2358 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2359 if ( aSMESHDS_Mesh == NULL ) return -1;
2360 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2361 if(!elem) return -1;
2362 if( index>=elem->NbNodes() || index<0 ) return -1;
2363 return elem->GetNode(index)->GetID();
2366 //=============================================================================
2368 * Returns IDs of nodes of given element
2370 //=============================================================================
2372 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2374 SMESH::long_array_var aResult = new SMESH::long_array();
2375 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2377 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2379 aResult->length( elem->NbNodes() );
2380 for ( int i = 0; i < elem->NbNodes(); ++i )
2381 aResult[ i ] = elem->GetNode( i )->GetID();
2384 return aResult._retn();
2387 //=============================================================================
2389 * Returns true if given node is medium node
2390 * in given quadratic element
2392 //=============================================================================
2394 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2396 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2397 if ( aSMESHDS_Mesh == NULL ) return false;
2399 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2400 if(!aNode) return false;
2401 // try to find element
2402 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2403 if(!elem) return false;
2405 return elem->IsMediumNode(aNode);
2409 //=============================================================================
2411 * Returns true if given node is medium node
2412 * in one of quadratic elements
2414 //=============================================================================
2416 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2417 SMESH::ElementType theElemType)
2419 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2420 if ( aSMESHDS_Mesh == NULL ) return false;
2423 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2424 if(!aNode) return false;
2426 SMESH_MesherHelper aHelper( *(_impl) );
2428 SMDSAbs_ElementType aType;
2429 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2430 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2431 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2432 else aType = SMDSAbs_All;
2434 return aHelper.IsMedium(aNode,aType);
2438 //=============================================================================
2440 * Returns number of edges for given element
2442 //=============================================================================
2444 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2446 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2447 if ( aSMESHDS_Mesh == NULL ) return -1;
2448 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2449 if(!elem) return -1;
2450 return elem->NbEdges();
2454 //=============================================================================
2456 * Returns number of faces for given element
2458 //=============================================================================
2460 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2462 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2463 if ( aSMESHDS_Mesh == NULL ) return -1;
2464 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2465 if(!elem) return -1;
2466 return elem->NbFaces();
2470 //=============================================================================
2472 * Returns true if given element is polygon
2474 //=============================================================================
2476 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2478 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2479 if ( aSMESHDS_Mesh == NULL ) return false;
2480 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2481 if(!elem) return false;
2482 return elem->IsPoly();
2486 //=============================================================================
2488 * Returns true if given element is quadratic
2490 //=============================================================================
2492 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2494 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2495 if ( aSMESHDS_Mesh == NULL ) return false;
2496 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2497 if(!elem) return false;
2498 return elem->IsQuadratic();
2502 //=============================================================================
2504 * Returns bary center for given element
2506 //=============================================================================
2508 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2510 SMESH::double_array_var aResult = new SMESH::double_array();
2511 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2512 if ( aSMESHDS_Mesh == NULL )
2513 return aResult._retn();
2515 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2517 return aResult._retn();
2519 if(elem->GetType()==SMDSAbs_Volume) {
2520 SMDS_VolumeTool aTool;
2521 if(aTool.Set(elem)) {
2523 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2528 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2530 double x=0., y=0., z=0.;
2531 for(; anIt->more(); ) {
2533 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2547 return aResult._retn();
2551 //=============================================================================
2553 * Create and publish group servants if any groups were imported or created anyhow
2555 //=============================================================================
2557 void SMESH_Mesh_i::CreateGroupServants()
2559 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2561 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2562 while ( groupIt->more() )
2564 ::SMESH_Group* group = groupIt->next();
2565 int anId = group->GetGroupDS()->GetID();
2567 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
2568 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2571 SMESH_GroupBase_i* aGroupImpl;
2573 if ( SMESHDS_GroupOnGeom* groupOnGeom =
2574 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
2576 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2577 shape = groupOnGeom->GetShape();
2580 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2583 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
2584 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2585 aGroupImpl->Register();
2587 SMESH::SMESH_GroupBase_var groupVar =
2588 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2589 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
2591 // register CORBA object for persistence
2592 int nextId = _gen_i->RegisterObject( groupVar );
2593 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2595 // publishing of the groups in the study
2596 if ( !aStudy->_is_nil() ) {
2597 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
2598 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
2603 //=============================================================================
2605 * \brief Return groups cantained in _mapGroups by their IDs
2607 //=============================================================================
2609 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
2611 int nbGroups = groupIDs.size();
2612 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
2613 aList->length( nbGroups );
2615 list<int>::const_iterator ids = groupIDs.begin();
2616 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
2618 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
2619 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2620 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
2622 aList->length( nbGroups );
2623 return aList._retn();
2626 //=============================================================================
2628 * \brief Return information about imported file
2630 //=============================================================================
2632 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
2634 SALOME_MED::MedFileInfo_var res( myFileInfo );
2635 if ( !res.operator->() ) {
2636 res = new SALOME_MED::MedFileInfo;
2638 res->fileSize = res->major = res->minor = res->release = -1;