1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Mesh_i.cxx
25 // Author : Paul RASCLE, EDF
29 #include "SMESH_Mesh_i.hxx"
30 #include "SMESH_subMesh_i.hxx"
31 #include "SMESH_MEDMesh_i.hxx"
32 #include "SMESH_Group_i.hxx"
33 #include "SMESH_Filter_i.hxx"
34 #include "SMESH_PythonDump.hxx"
36 #include "Utils_CorbaException.hxx"
37 #include "Utils_ExceptHandlers.hxx"
38 #include "utilities.h"
40 #include "SALOME_NamingService.hxx"
41 #include "Utils_SINGLETON.hxx"
44 #include "SMESHDS_Command.hxx"
45 #include "SMESHDS_CommandType.hxx"
46 #include "SMESH_MeshEditor_i.hxx"
47 #include "SMESH_Gen_i.hxx"
48 #include "DriverMED_R_SMESHDS_Mesh.h"
49 //#include "SMDS_ElemIterator.hxx"
50 #include "SMDS_VolumeTool.hxx"
51 #include "SMESH_MesherHelper.hxx"
52 #include "SMESH_MeshEditor.hxx"
55 #include <OSD_Path.hxx>
56 #include <OSD_File.hxx>
57 #include <OSD_Directory.hxx>
58 #include <OSD_Protection.hxx>
59 #include <TColStd_MapOfInteger.hxx>
60 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
61 #include <TColStd_SequenceOfInteger.hxx>
62 #include "TCollection_AsciiString.hxx"
70 static int MYDEBUG = 0;
72 static int MYDEBUG = 0;
76 using SMESH::TPythonDump;
78 int SMESH_Mesh_i::myIdGenerator = 0;
82 //=============================================================================
86 //=============================================================================
88 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
91 : SALOME::GenericObj_i( thePOA )
93 INFOS("SMESH_Mesh_i");
96 _id = myIdGenerator++;
98 thePOA->activate_object( this );
101 //=============================================================================
105 //=============================================================================
107 SMESH_Mesh_i::~SMESH_Mesh_i()
109 INFOS("~SMESH_Mesh_i");
110 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
111 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
112 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
115 // this method is colled from destructor of group (PAL6331)
116 //_impl->RemoveGroup( aGroup->GetLocalID() );
124 //=============================================================================
128 * Associates <this> mesh with <theShape> and puts a reference
129 * to <theShape> into the current study;
130 * the previous shape is substituted by the new one.
132 //=============================================================================
134 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
135 throw (SALOME::SALOME_Exception)
137 Unexpect aCatch(SALOME_SalomeException);
139 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
141 catch(SALOME_Exception & S_ex) {
142 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
146 //=======================================================================
147 //function : GetShapeToMesh
149 //=======================================================================
151 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
152 throw (SALOME::SALOME_Exception)
154 Unexpect aCatch(SALOME_SalomeException);
155 GEOM::GEOM_Object_var aShapeObj;
157 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
159 aShapeObj = _gen_i->ShapeToGeomObject( S );
161 catch(SALOME_Exception & S_ex) {
162 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
164 return aShapeObj._retn();
167 //=============================================================================
171 //=============================================================================
173 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
175 SMESH::DriverMED_ReadStatus res;
178 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
179 res = SMESH::DRS_OK; break;
180 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
181 res = SMESH::DRS_EMPTY; break;
182 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
183 res = SMESH::DRS_WARN_RENUMBER; break;
184 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
185 res = SMESH::DRS_WARN_SKIP_ELEM; break;
186 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
188 res = SMESH::DRS_FAIL; break;
193 //=============================================================================
197 * Imports mesh data from MED file
199 //=============================================================================
201 SMESH::DriverMED_ReadStatus
202 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
203 throw ( SALOME::SALOME_Exception )
205 Unexpect aCatch(SALOME_SalomeException);
208 status = importMEDFile( theFileName, theMeshName );
210 catch( SALOME_Exception& S_ex ) {
211 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
214 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
217 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
218 if ( !aStudy->_is_nil() ) {
219 // publishing of the groups in the study (sub-meshes are out of scope of MED import)
220 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
221 for (; it != _mapGroups.end(); it++ ) {
222 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
223 _gen_i->PublishGroup( aStudy, _this(), aGroup,
224 GEOM::GEOM_Object::_nil(), aGroup->GetName());
227 return ConvertDriverMEDReadStatus(status);
230 //=============================================================================
234 * Imports mesh data from MED file
236 //=============================================================================
238 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
239 throw ( SALOME::SALOME_Exception )
241 // Read mesh with name = <theMeshName> into SMESH_Mesh
242 _impl->UNVToMesh( theFileName );
244 CreateGroupServants();
246 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
247 if ( !aStudy->_is_nil() ) {
248 // publishing of the groups in the study (sub-meshes are out of scope of UNV import)
249 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
250 for (; it != _mapGroups.end(); it++ ) {
251 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
252 _gen_i->PublishGroup( aStudy, _this(), aGroup,
253 GEOM::GEOM_Object::_nil(), aGroup->GetName());
259 //=============================================================================
263 * Imports mesh data from STL file
265 //=============================================================================
266 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
267 throw ( SALOME::SALOME_Exception )
269 // Read mesh with name = <theMeshName> into SMESH_Mesh
270 _impl->STLToMesh( theFileName );
275 //=============================================================================
279 * Imports mesh data from MED file
281 //=============================================================================
283 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
285 // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
286 int status = _impl->MEDToMesh( theFileName, theMeshName );
287 CreateGroupServants();
292 //=============================================================================
296 //=============================================================================
298 static SMESH::Hypothesis_Status ConvertHypothesisStatus
299 (SMESH_Hypothesis::Hypothesis_Status theStatus)
301 SMESH::Hypothesis_Status res;
304 case SMESH_Hypothesis::HYP_OK:
305 res = SMESH::HYP_OK; break;
306 case SMESH_Hypothesis::HYP_MISSING:
307 res = SMESH::HYP_MISSING; break;
308 case SMESH_Hypothesis::HYP_CONCURENT:
309 res = SMESH::HYP_CONCURENT; break;
310 case SMESH_Hypothesis::HYP_BAD_PARAMETER:
311 res = SMESH::HYP_BAD_PARAMETER; break;
312 case SMESH_Hypothesis::HYP_INCOMPATIBLE:
313 res = SMESH::HYP_INCOMPATIBLE; break;
314 case SMESH_Hypothesis::HYP_NOTCONFORM:
315 res = SMESH::HYP_NOTCONFORM; break;
316 case SMESH_Hypothesis::HYP_ALREADY_EXIST:
317 res = SMESH::HYP_ALREADY_EXIST; break;
318 case SMESH_Hypothesis::HYP_BAD_DIM:
319 res = SMESH::HYP_BAD_DIM; break;
320 case SMESH_Hypothesis::HYP_BAD_SUBSHAPE:
321 res = SMESH::HYP_BAD_SUBSHAPE; break;
322 case SMESH_Hypothesis::HYP_BAD_GEOMETRY:
323 res = SMESH::HYP_BAD_GEOMETRY; break;
325 res = SMESH::HYP_UNKNOWN_FATAL;
330 //=============================================================================
334 * calls internal addHypothesis() and then adds a reference to <anHyp> under
335 * the SObject actually having a reference to <aSubShape>.
336 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
338 //=============================================================================
340 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
341 SMESH::SMESH_Hypothesis_ptr anHyp)
342 throw(SALOME::SALOME_Exception)
344 Unexpect aCatch(SALOME_SalomeException);
345 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
347 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
348 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
349 aSubShapeObject, anHyp );
351 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
353 // Update Python script
354 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
355 << aSubShapeObject << ", " << anHyp << " )";
357 return ConvertHypothesisStatus(status);
360 //=============================================================================
364 //=============================================================================
366 SMESH_Hypothesis::Hypothesis_Status
367 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
368 SMESH::SMESH_Hypothesis_ptr anHyp)
370 if(MYDEBUG) MESSAGE("addHypothesis");
372 if (CORBA::is_nil(aSubShapeObject))
373 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
376 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
377 if (CORBA::is_nil(myHyp))
378 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
381 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
384 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
385 int hypId = myHyp->GetId();
386 status = _impl->AddHypothesis(myLocSubShape, hypId);
387 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
388 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
389 // assure there is a corresponding submesh
390 if ( !_impl->IsMainShape( myLocSubShape )) {
391 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
392 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
393 createSubMesh( aSubShapeObject );
397 catch(SALOME_Exception & S_ex)
399 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
404 //=============================================================================
408 //=============================================================================
410 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
411 SMESH::SMESH_Hypothesis_ptr anHyp)
412 throw(SALOME::SALOME_Exception)
414 Unexpect aCatch(SALOME_SalomeException);
415 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
417 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
418 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
419 aSubShapeObject, anHyp );
421 // Update Python script
422 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
423 << aSubShapeObject << ", " << anHyp << " )";
425 return ConvertHypothesisStatus(status);
428 //=============================================================================
432 //=============================================================================
434 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
435 SMESH::SMESH_Hypothesis_ptr anHyp)
437 if(MYDEBUG) MESSAGE("removeHypothesis()");
438 // **** proposer liste de subShape (selection multiple)
440 if (CORBA::is_nil(aSubShapeObject))
441 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
444 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
445 if (CORBA::is_nil(myHyp))
446 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
449 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
452 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
453 int hypId = myHyp->GetId();
454 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
455 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
456 _mapHypo.erase( hypId );
458 catch(SALOME_Exception & S_ex)
460 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
465 //=============================================================================
469 //=============================================================================
471 SMESH::ListOfHypothesis *
472 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
473 throw(SALOME::SALOME_Exception)
475 Unexpect aCatch(SALOME_SalomeException);
476 if (MYDEBUG) MESSAGE("GetHypothesisList");
477 if (CORBA::is_nil(aSubShapeObject))
478 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
481 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
484 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
485 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
486 int i = 0, n = aLocalList.size();
489 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
490 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
491 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
492 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
497 catch(SALOME_Exception & S_ex) {
498 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
501 return aList._retn();
504 //=============================================================================
508 //=============================================================================
509 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
510 const char* theName )
511 throw(SALOME::SALOME_Exception)
513 Unexpect aCatch(SALOME_SalomeException);
514 MESSAGE("SMESH_Mesh_i::GetSubMesh");
515 if (CORBA::is_nil(aSubShapeObject))
516 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
519 SMESH::SMESH_subMesh_var subMesh;
520 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
522 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
524 //Get or Create the SMESH_subMesh object implementation
526 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
527 subMesh = getSubMesh( subMeshId );
529 // create a new subMesh object servant if there is none for the shape
530 if ( subMesh->_is_nil() )
531 subMesh = createSubMesh( aSubShapeObject );
533 if ( _gen_i->CanPublishInStudy( subMesh )) {
534 SALOMEDS::SObject_var aSO =
535 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
536 subMesh, aSubShapeObject, theName );
537 if ( !aSO->_is_nil()) {
538 // Update Python script
539 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
540 << aSubShapeObject << ", '" << theName << "' )";
544 catch(SALOME_Exception & S_ex) {
545 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
547 return subMesh._retn();
550 //=============================================================================
554 //=============================================================================
556 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
557 throw (SALOME::SALOME_Exception)
559 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
560 if ( theSubMesh->_is_nil() )
563 GEOM::GEOM_Object_var aSubShapeObject;
564 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
565 if ( !aStudy->_is_nil() ) {
566 // Remove submesh's SObject
567 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
568 if ( !anSO->_is_nil() ) {
569 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
570 SALOMEDS::SObject_var anObj, aRef;
571 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
572 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
574 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
576 // Update Python script
577 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
581 removeSubMesh( theSubMesh, aSubShapeObject.in() );
584 //=============================================================================
588 //=============================================================================
589 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
590 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
592 switch (theElemType) {
597 CASE2STRING( VOLUME );
603 //=============================================================================
607 //=============================================================================
609 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
610 const char* theName )
611 throw(SALOME::SALOME_Exception)
613 Unexpect aCatch(SALOME_SalomeException);
614 SMESH::SMESH_Group_var aNewGroup =
615 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
617 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
618 SALOMEDS::SObject_var aSO =
619 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
620 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
621 if ( !aSO->_is_nil()) {
622 // Update Python script
623 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
624 << ElementTypeString(theElemType) << ", '" << theName << "' )";
627 return aNewGroup._retn();
631 //=============================================================================
635 //=============================================================================
636 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
638 GEOM::GEOM_Object_ptr theGeomObj)
639 throw(SALOME::SALOME_Exception)
641 Unexpect aCatch(SALOME_SalomeException);
642 SMESH::SMESH_GroupOnGeom_var aNewGroup;
644 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
645 if ( !aShape.IsNull() ) {
646 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
647 ( createGroup( theElemType, theName, aShape ));
648 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
649 SALOMEDS::SObject_var aSO =
650 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
651 aNewGroup, theGeomObj, theName);
652 if ( !aSO->_is_nil()) {
653 // Update Python script
654 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
655 << ElementTypeString(theElemType) << ", '" << theName << "', "
656 << theGeomObj << " )";
661 return aNewGroup._retn();
664 //=============================================================================
668 //=============================================================================
670 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
671 throw (SALOME::SALOME_Exception)
673 if ( theGroup->_is_nil() )
676 SMESH_GroupBase_i* aGroup =
677 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
681 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
682 if ( !aStudy->_is_nil() ) {
683 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
685 if ( !aGroupSO->_is_nil() ) {
686 // Update Python script
687 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
689 // Remove group's SObject
690 aStudy->NewBuilder()->RemoveObject( aGroupSO );
694 // Remove the group from SMESH data structures
695 removeGroup( aGroup->GetLocalID() );
698 //=============================================================================
699 /*! RemoveGroupWithContents
700 * Remove group with its contents
702 //=============================================================================
703 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
704 throw (SALOME::SALOME_Exception)
706 if ( theGroup->_is_nil() )
709 SMESH_GroupBase_i* aGroup =
710 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
714 SMESH::long_array_var anIds = aGroup->GetListOfID();
715 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
717 // Update Python script
718 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
721 if ( aGroup->GetType() == SMESH::NODE )
722 aMeshEditor->RemoveNodes( anIds );
724 aMeshEditor->RemoveElements( anIds );
727 RemoveGroup( theGroup );
729 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
730 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
731 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
735 //================================================================================
737 * \brief Get the list of groups existing in the mesh
738 * \retval SMESH::ListOfGroups * - list of groups
740 //================================================================================
742 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
744 Unexpect aCatch(SALOME_SalomeException);
745 if (MYDEBUG) MESSAGE("GetGroups");
747 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
749 TPythonDump aPythonDump;
753 aList->length( _mapGroups.size() );
755 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
756 for ( ; it != _mapGroups.end(); it++ ) {
757 if ( CORBA::is_nil( it->second )) continue;
758 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
760 if (i > 1) aPythonDump << ", ";
761 aPythonDump << it->second;
765 catch(SALOME_Exception & S_ex) {
766 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
769 // Update Python script
770 aPythonDump << " ] = " << _this() << ".GetGroups()";
772 return aList._retn();
775 //=============================================================================
777 * New group is created. All mesh elements that are
778 * present in initial groups are added to the new one
780 //=============================================================================
781 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
782 SMESH::SMESH_GroupBase_ptr theGroup2,
783 const char* theName )
784 throw (SALOME::SALOME_Exception)
788 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
789 theGroup1->GetType() != theGroup2->GetType() )
790 return SMESH::SMESH_Group::_nil();
793 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
794 if ( aResGrp->_is_nil() )
795 return SMESH::SMESH_Group::_nil();
797 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
798 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
800 TColStd_MapOfInteger aResMap;
802 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
803 aResMap.Add( anIds1[ i1 ] );
805 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
806 aResMap.Add( anIds2[ i2 ] );
808 SMESH::long_array_var aResIds = new SMESH::long_array;
809 aResIds->length( aResMap.Extent() );
812 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
813 for( ; anIter.More(); anIter.Next() )
814 aResIds[ resI++ ] = anIter.Key();
816 aResGrp->Add( aResIds );
818 // Clear python lines, created by CreateGroup() and Add()
819 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
820 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
821 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
823 // Update Python script
824 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
825 << theGroup1 << ", " << theGroup2 << ", '"
828 return aResGrp._retn();
832 return SMESH::SMESH_Group::_nil();
836 //=============================================================================
838 * New group is created. All mesh elements that are
839 * present in both initial groups are added to the new one.
841 //=============================================================================
842 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
843 SMESH::SMESH_GroupBase_ptr theGroup2,
844 const char* theName )
845 throw (SALOME::SALOME_Exception)
847 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
848 theGroup1->GetType() != theGroup2->GetType() )
849 return SMESH::SMESH_Group::_nil();
851 // Create Intersection
852 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
853 if ( aResGrp->_is_nil() )
856 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
857 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
859 TColStd_MapOfInteger aMap1;
861 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
862 aMap1.Add( anIds1[ i1 ] );
864 TColStd_SequenceOfInteger aSeq;
866 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
867 if ( aMap1.Contains( anIds2[ i2 ] ) )
868 aSeq.Append( anIds2[ i2 ] );
870 SMESH::long_array_var aResIds = new SMESH::long_array;
871 aResIds->length( aSeq.Length() );
873 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
874 aResIds[ resI ] = aSeq( resI + 1 );
876 aResGrp->Add( aResIds );
878 // Clear python lines, created by CreateGroup() and Add()
879 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
880 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
881 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
883 // Update Python script
884 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
885 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
887 return aResGrp._retn();
890 //=============================================================================
892 * New group is created. All mesh elements that are present in
893 * main group but do not present in tool group are added to the new one
895 //=============================================================================
896 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
897 SMESH::SMESH_GroupBase_ptr theGroup2,
898 const char* theName )
899 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() )
910 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
911 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
913 TColStd_MapOfInteger aMap2;
915 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
916 aMap2.Add( anIds2[ i2 ] );
919 TColStd_SequenceOfInteger aSeq;
920 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
921 if ( !aMap2.Contains( anIds1[ i1 ] ) )
922 aSeq.Append( anIds1[ i1 ] );
924 SMESH::long_array_var aResIds = new SMESH::long_array;
925 aResIds->length( aSeq.Length() );
927 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
928 aResIds[ resI ] = aSeq( resI + 1 );
930 aResGrp->Add( aResIds );
932 // Clear python lines, created by CreateGroup() and Add()
933 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
934 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
935 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
937 // Update Python script
938 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
939 << theGroup1 << ", " << theGroup2 << ", '"
942 return aResGrp._retn();
945 //=============================================================================
949 //=============================================================================
951 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
953 if(MYDEBUG) MESSAGE( "createSubMesh" );
954 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
956 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
957 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
958 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
959 SMESH::SMESH_subMesh_var subMesh
960 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
962 _mapSubMesh[subMeshId] = mySubMesh;
963 _mapSubMesh_i[subMeshId] = subMeshServant;
964 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
966 // register CORBA object for persistence
967 int nextId = _gen_i->RegisterObject( subMesh );
968 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
970 return subMesh._retn();
973 //=======================================================================
974 //function : getSubMesh
976 //=======================================================================
978 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
980 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
981 if ( it == _mapSubMeshIor.end() )
982 return SMESH::SMESH_subMesh::_nil();
984 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
988 //=============================================================================
992 //=============================================================================
994 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
995 GEOM::GEOM_Object_ptr theSubShapeObject )
997 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
998 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1002 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1003 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1004 removeHypothesis( theSubShapeObject, aHypList[i] );
1007 catch( const SALOME::SALOME_Exception& ) {
1008 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1011 int subMeshId = theSubMesh->GetId();
1013 _mapSubMesh.erase(subMeshId);
1014 _mapSubMesh_i.erase(subMeshId);
1015 _mapSubMeshIor.erase(subMeshId);
1016 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1019 //=============================================================================
1023 //=============================================================================
1025 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1026 const char* theName,
1027 const TopoDS_Shape& theShape )
1030 SMESH::SMESH_GroupBase_var aGroup;
1031 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1032 SMESH_GroupBase_i* aGroupImpl;
1033 if ( !theShape.IsNull() )
1034 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1036 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1038 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1039 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1040 aGroupImpl->Register();
1041 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1043 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1044 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1046 // register CORBA object for persistence
1047 int nextId = _gen_i->RegisterObject( aGroup );
1048 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1050 return aGroup._retn();
1053 //=============================================================================
1055 * SMESH_Mesh_i::removeGroup
1057 * Should be called by ~SMESH_Group_i()
1059 //=============================================================================
1061 void SMESH_Mesh_i::removeGroup( const int theId )
1063 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1064 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1065 _mapGroups.erase( theId );
1066 _impl->RemoveGroup( theId );
1071 //=============================================================================
1075 //=============================================================================
1077 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1078 throw(SALOME::SALOME_Exception)
1080 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1082 SMESH::log_array_var aLog;
1084 list < SMESHDS_Command * >logDS = _impl->GetLog();
1085 aLog = new SMESH::log_array;
1087 int lg = logDS.size();
1090 list < SMESHDS_Command * >::iterator its = logDS.begin();
1091 while(its != logDS.end()){
1092 SMESHDS_Command *com = *its;
1093 int comType = com->GetType();
1095 int lgcom = com->GetNumber();
1097 const list < int >&intList = com->GetIndexes();
1098 int inum = intList.size();
1100 list < int >::const_iterator ii = intList.begin();
1101 const list < double >&coordList = com->GetCoords();
1102 int rnum = coordList.size();
1104 list < double >::const_iterator ir = coordList.begin();
1105 aLog[indexLog].commandType = comType;
1106 aLog[indexLog].number = lgcom;
1107 aLog[indexLog].coords.length(rnum);
1108 aLog[indexLog].indexes.length(inum);
1109 for(int i = 0; i < rnum; i++){
1110 aLog[indexLog].coords[i] = *ir;
1111 //MESSAGE(" "<<i<<" "<<ir.Value());
1114 for(int i = 0; i < inum; i++){
1115 aLog[indexLog].indexes[i] = *ii;
1116 //MESSAGE(" "<<i<<" "<<ii.Value());
1125 catch(SALOME_Exception & S_ex){
1126 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1128 return aLog._retn();
1132 //=============================================================================
1136 //=============================================================================
1138 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1140 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1144 //=============================================================================
1148 //=============================================================================
1150 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1152 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1156 //=============================================================================
1160 //=============================================================================
1162 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1167 //=============================================================================
1171 //=============================================================================
1173 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1175 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1179 //=============================================================================
1183 //=============================================================================
1185 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1187 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1192 //=============================================================================
1196 //=============================================================================
1198 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1200 // Create MeshEditor
1201 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );
1202 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1204 // Update Python script
1205 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1207 return aMesh._retn();
1210 //=============================================================================
1212 * Export in different formats
1214 //=============================================================================
1216 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1218 return _impl->HasDuplicatedGroupNamesMED();
1221 static void PrepareForWriting (const char* file)
1223 TCollection_AsciiString aFullName ((char*)file);
1224 OSD_Path aPath (aFullName);
1225 OSD_File aFile (aPath);
1226 if (aFile.Exists()) {
1227 // existing filesystem node
1228 if (aFile.KindOfFile() == OSD_FILE) {
1229 if (aFile.IsWriteable()) {
1232 if (aFile.Failed()) {
1233 TCollection_AsciiString msg ("File ");
1234 msg += aFullName + " cannot be replaced.";
1235 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1238 TCollection_AsciiString msg ("File ");
1239 msg += aFullName + " cannot be overwritten.";
1240 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1243 TCollection_AsciiString msg ("Location ");
1244 msg += aFullName + " is not a file.";
1245 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1248 // nonexisting file; check if it can be created
1250 aFile.Build(OSD_WriteOnly, OSD_Protection());
1251 if (aFile.Failed()) {
1252 TCollection_AsciiString msg ("You cannot create the file ");
1253 msg += aFullName + ". Check the directory existance and access rights.";
1254 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1262 void SMESH_Mesh_i::ExportToMED (const char* file,
1263 CORBA::Boolean auto_groups,
1264 SMESH::MED_VERSION theVersion)
1265 throw(SALOME::SALOME_Exception)
1267 Unexpect aCatch(SALOME_SalomeException);
1269 // Update Python script
1270 TPythonDump() << _this() << ".ExportToMED( '"
1271 << file << "', " << auto_groups << ", " << theVersion << " )";
1274 PrepareForWriting(file);
1275 char* aMeshName = "Mesh";
1276 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1277 if ( !aStudy->_is_nil() ) {
1278 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1279 if ( !aMeshSO->_is_nil() ) {
1280 aMeshName = aMeshSO->GetName();
1282 //SCRUTE(aMeshName);
1283 //SCRUTE(aMeshSO->GetID());
1285 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1286 if ( !aStudy->GetProperties()->IsLocked() )
1288 SALOMEDS::GenericAttribute_var anAttr;
1289 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1290 SALOMEDS::AttributeExternalFileDef_var aFileName;
1291 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1292 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1293 ASSERT(!aFileName->_is_nil());
1294 aFileName->SetValue(file);
1295 SALOMEDS::AttributeFileType_var aFileType;
1296 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1297 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1298 ASSERT(!aFileType->_is_nil());
1299 aFileType->SetValue("FICHIERMED");
1303 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1306 void SMESH_Mesh_i::ExportMED (const char* file,
1307 CORBA::Boolean auto_groups)
1308 throw(SALOME::SALOME_Exception)
1310 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1313 void SMESH_Mesh_i::ExportDAT (const char *file)
1314 throw(SALOME::SALOME_Exception)
1316 Unexpect aCatch(SALOME_SalomeException);
1318 // Update Python script
1319 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1322 PrepareForWriting(file);
1323 _impl->ExportDAT(file);
1326 void SMESH_Mesh_i::ExportUNV (const char *file)
1327 throw(SALOME::SALOME_Exception)
1329 Unexpect aCatch(SALOME_SalomeException);
1331 // Update Python script
1332 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1335 PrepareForWriting(file);
1336 _impl->ExportUNV(file);
1339 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1340 throw(SALOME::SALOME_Exception)
1342 Unexpect aCatch(SALOME_SalomeException);
1344 // Update Python script
1345 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1348 PrepareForWriting(file);
1349 _impl->ExportSTL(file, isascii);
1352 //=============================================================================
1356 //=============================================================================
1358 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1360 Unexpect aCatch(SALOME_SalomeException);
1361 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1362 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1363 return aMesh._retn();
1366 //=============================================================================
1370 //=============================================================================
1371 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1373 Unexpect aCatch(SALOME_SalomeException);
1374 return _impl->NbNodes();
1377 //=============================================================================
1381 //=============================================================================
1382 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1384 Unexpect aCatch(SALOME_SalomeException);
1385 return NbEdges() + NbFaces() + NbVolumes();
1388 //=============================================================================
1392 //=============================================================================
1393 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1395 Unexpect aCatch(SALOME_SalomeException);
1396 return _impl->NbEdges();
1399 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1400 throw(SALOME::SALOME_Exception)
1402 Unexpect aCatch(SALOME_SalomeException);
1403 return _impl->NbEdges( (::SMESH_Mesh::ElementOrder) order);
1406 //=============================================================================
1410 //=============================================================================
1411 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1413 Unexpect aCatch(SALOME_SalomeException);
1414 return _impl->NbFaces();
1417 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1419 Unexpect aCatch(SALOME_SalomeException);
1420 return _impl->NbTriangles();
1423 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1425 Unexpect aCatch(SALOME_SalomeException);
1426 return _impl->NbQuadrangles();
1429 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1431 Unexpect aCatch(SALOME_SalomeException);
1432 return _impl->NbPolygons();
1435 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1436 throw(SALOME::SALOME_Exception)
1438 Unexpect aCatch(SALOME_SalomeException);
1439 return _impl->NbFaces( (::SMESH_Mesh::ElementOrder) order);
1442 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1443 throw(SALOME::SALOME_Exception)
1445 Unexpect aCatch(SALOME_SalomeException);
1446 return _impl->NbTriangles( (::SMESH_Mesh::ElementOrder) order);
1449 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1450 throw(SALOME::SALOME_Exception)
1452 Unexpect aCatch(SALOME_SalomeException);
1453 return _impl->NbQuadrangles( (::SMESH_Mesh::ElementOrder) order);
1456 //=============================================================================
1460 //=============================================================================
1461 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1463 Unexpect aCatch(SALOME_SalomeException);
1464 return _impl->NbVolumes();
1467 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1469 Unexpect aCatch(SALOME_SalomeException);
1470 return _impl->NbTetras();
1473 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1475 Unexpect aCatch(SALOME_SalomeException);
1476 return _impl->NbHexas();
1479 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1481 Unexpect aCatch(SALOME_SalomeException);
1482 return _impl->NbPyramids();
1485 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1487 Unexpect aCatch(SALOME_SalomeException);
1488 return _impl->NbPrisms();
1491 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1493 Unexpect aCatch(SALOME_SalomeException);
1494 return _impl->NbPolyhedrons();
1497 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1498 throw(SALOME::SALOME_Exception)
1500 Unexpect aCatch(SALOME_SalomeException);
1501 return _impl->NbVolumes( (::SMESH_Mesh::ElementOrder) order);
1504 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1505 throw(SALOME::SALOME_Exception)
1507 Unexpect aCatch(SALOME_SalomeException);
1508 return _impl->NbTetras( (::SMESH_Mesh::ElementOrder) order);
1511 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1512 throw(SALOME::SALOME_Exception)
1514 Unexpect aCatch(SALOME_SalomeException);
1515 return _impl->NbHexas( (::SMESH_Mesh::ElementOrder) order);
1518 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1519 throw(SALOME::SALOME_Exception)
1521 Unexpect aCatch(SALOME_SalomeException);
1522 return _impl->NbPyramids( (::SMESH_Mesh::ElementOrder) order);
1525 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1526 throw(SALOME::SALOME_Exception)
1528 Unexpect aCatch(SALOME_SalomeException);
1529 return _impl->NbPrisms( (::SMESH_Mesh::ElementOrder) order);
1532 //=============================================================================
1536 //=============================================================================
1537 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1539 Unexpect aCatch(SALOME_SalomeException);
1540 return _impl->NbSubMesh();
1543 //=============================================================================
1547 //=============================================================================
1548 char* SMESH_Mesh_i::Dump()
1550 std::ostringstream os;
1552 return CORBA::string_dup( os.str().c_str() );
1555 //=============================================================================
1559 //=============================================================================
1560 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1562 // SMESH::long_array_var aResult = new SMESH::long_array();
1563 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1564 // int aMinId = aSMESHDS_Mesh->MinElementID();
1565 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1567 // aResult->length(aMaxId - aMinId + 1);
1569 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1570 // aResult[i++] = id;
1572 // return aResult._retn();
1574 return GetElementsId();
1577 //=============================================================================
1581 //=============================================================================
1583 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1584 throw (SALOME::SALOME_Exception)
1586 Unexpect aCatch(SALOME_SalomeException);
1587 MESSAGE("SMESH_Mesh_i::GetElementsId");
1588 SMESH::long_array_var aResult = new SMESH::long_array();
1589 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1591 if ( aSMESHDS_Mesh == NULL )
1592 return aResult._retn();
1594 long nbElements = NbElements();
1595 aResult->length( nbElements );
1596 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1597 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1598 aResult[i] = anIt->next()->GetID();
1600 return aResult._retn();
1604 //=============================================================================
1608 //=============================================================================
1610 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1611 throw (SALOME::SALOME_Exception)
1613 Unexpect aCatch(SALOME_SalomeException);
1614 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1615 SMESH::long_array_var aResult = new SMESH::long_array();
1616 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1618 if ( aSMESHDS_Mesh == NULL )
1619 return aResult._retn();
1621 long nbElements = NbElements();
1623 // No sense in returning ids of elements along with ids of nodes:
1624 // when theElemType == SMESH::ALL, return node ids only if
1625 // there are no elements
1626 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1627 return GetNodesId();
1629 aResult->length( nbElements );
1633 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1634 while ( i < nbElements && anIt->more() ) {
1635 const SMDS_MeshElement* anElem = anIt->next();
1636 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1637 aResult[i++] = anElem->GetID();
1640 aResult->length( i );
1642 return aResult._retn();
1645 //=============================================================================
1649 //=============================================================================
1651 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1652 throw (SALOME::SALOME_Exception)
1654 Unexpect aCatch(SALOME_SalomeException);
1655 MESSAGE("SMESH_subMesh_i::GetNodesId");
1656 SMESH::long_array_var aResult = new SMESH::long_array();
1657 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1659 if ( aSMESHDS_Mesh == NULL )
1660 return aResult._retn();
1662 long nbNodes = NbNodes();
1663 aResult->length( nbNodes );
1664 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1665 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1666 aResult[i] = anIt->next()->GetID();
1668 return aResult._retn();
1671 //=============================================================================
1675 //=============================================================================
1677 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1678 throw (SALOME::SALOME_Exception)
1680 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1684 //=============================================================================
1686 * Returns ID of elements for given submesh
1688 //=============================================================================
1689 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1690 throw (SALOME::SALOME_Exception)
1692 SMESH::long_array_var aResult = new SMESH::long_array();
1694 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1695 if(!SM) return aResult._retn();
1697 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1698 if(!SDSM) return aResult._retn();
1700 aResult->length(SDSM->NbElements());
1702 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1704 while ( eIt->more() ) {
1705 aResult[i++] = eIt->next()->GetID();
1708 return aResult._retn();
1712 //=============================================================================
1714 * Returns ID of nodes for given submesh
1715 * If param all==true - returns all nodes, else -
1716 * returns only nodes on shapes.
1718 //=============================================================================
1719 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1720 throw (SALOME::SALOME_Exception)
1722 SMESH::long_array_var aResult = new SMESH::long_array();
1724 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1725 if(!SM) return aResult._retn();
1727 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1728 if(!SDSM) return aResult._retn();
1730 map<int,const SMDS_MeshElement*> theElems;
1731 if( !all || (SDSM->NbElements()==0 && SDSM->NbNodes()==1) ) {
1732 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1733 while ( nIt->more() ) {
1734 const SMDS_MeshNode* elem = nIt->next();
1735 theElems.insert( make_pair(elem->GetID(),elem) );
1738 else { // all nodes of submesh elements
1739 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1740 while ( eIt->more() ) {
1741 const SMDS_MeshElement* anElem = eIt->next();
1742 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1743 while ( nIt->more() ) {
1744 const SMDS_MeshElement* elem = nIt->next();
1745 theElems.insert( make_pair(elem->GetID(),elem) );
1750 aResult->length(theElems.size());
1751 map<int, const SMDS_MeshElement * >::iterator itElem;
1753 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1754 aResult[i++] = (*itElem).first;
1756 return aResult._retn();
1760 //=============================================================================
1762 * Returns type of elements for given submesh
1764 //=============================================================================
1765 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
1766 throw (SALOME::SALOME_Exception)
1768 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1769 if(!SM) return SMESH::ALL;
1771 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1772 if(!SDSM) return SMESH::ALL;
1774 if(SDSM->NbElements()==0)
1775 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
1777 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1778 const SMDS_MeshElement* anElem = eIt->next();
1779 return ( SMESH::ElementType ) anElem->GetType();
1783 //=============================================================================
1787 //=============================================================================
1789 CORBA::Long SMESH_Mesh_i::GetMeshPtr()
1791 return CORBA::Long(size_t(_impl));
1795 //=============================================================================
1797 * Get XYZ coordinates of node as list of double
1798 * If there is not node for given ID - returns empty list
1800 //=============================================================================
1802 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
1804 SMESH::double_array_var aResult = new SMESH::double_array();
1805 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1806 if ( aSMESHDS_Mesh == NULL )
1807 return aResult._retn();
1810 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1812 return aResult._retn();
1816 aResult[0] = aNode->X();
1817 aResult[1] = aNode->Y();
1818 aResult[2] = aNode->Z();
1819 return aResult._retn();
1823 //=============================================================================
1825 * For given node returns list of IDs of inverse elements
1826 * If there is not node for given ID - returns empty list
1828 //=============================================================================
1830 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
1832 SMESH::long_array_var aResult = new SMESH::long_array();
1833 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1834 if ( aSMESHDS_Mesh == NULL )
1835 return aResult._retn();
1838 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1840 return aResult._retn();
1842 // find inverse elements
1843 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
1844 TColStd_SequenceOfInteger IDs;
1845 while(eIt->more()) {
1846 const SMDS_MeshElement* elem = eIt->next();
1847 IDs.Append(elem->GetID());
1849 if(IDs.Length()>0) {
1850 aResult->length(IDs.Length());
1852 for(; i<=IDs.Length(); i++) {
1853 aResult[i-1] = IDs.Value(i);
1856 return aResult._retn();
1860 //=============================================================================
1862 * If given element is node returns IDs of shape from position
1863 * If there is not node for given ID - returns -1
1865 //=============================================================================
1867 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
1869 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1870 if ( aSMESHDS_Mesh == NULL )
1874 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1876 SMDS_PositionPtr pos = aNode->GetPosition();
1880 return pos->GetShapeId();
1887 //=============================================================================
1889 * For given element returns ID of result shape after
1890 * ::FindShape() from SMESH_MeshEditor
1891 * If there is not element for given ID - returns -1
1893 //=============================================================================
1895 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
1897 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1898 if ( aSMESHDS_Mesh == NULL )
1901 // try to find element
1902 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1906 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
1907 ::SMESH_MeshEditor aMeshEditor(_impl);
1908 int index = aMeshEditor.FindShape( elem );
1916 //=============================================================================
1918 * Returns number of nodes for given element
1919 * If there is not element for given ID - returns -1
1921 //=============================================================================
1923 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
1925 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1926 if ( aSMESHDS_Mesh == NULL ) return -1;
1927 // try to find element
1928 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1929 if(!elem) return -1;
1930 return elem->NbNodes();
1934 //=============================================================================
1936 * Returns ID of node by given index for given element
1937 * If there is not element for given ID - returns -1
1938 * If there is not node for given index - returns -2
1940 //=============================================================================
1942 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
1944 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1945 if ( aSMESHDS_Mesh == NULL ) return -1;
1946 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1947 if(!elem) return -1;
1948 if( index>=elem->NbNodes() || index<0 ) return -1;
1949 return elem->GetNode(index)->GetID();
1952 //=============================================================================
1954 * Returns IDs of nodes of given element
1956 //=============================================================================
1958 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
1960 SMESH::long_array_var aResult = new SMESH::long_array();
1961 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
1963 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
1965 aResult->length( elem->NbNodes() );
1966 for ( int i = 0; i < elem->NbNodes(); ++i )
1967 aResult[ i ] = elem->GetNode( i )->GetID();
1970 return aResult._retn();
1973 //=============================================================================
1975 * Returns true if given node is medium node
1976 * in given quadratic element
1978 //=============================================================================
1980 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
1982 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1983 if ( aSMESHDS_Mesh == NULL ) return false;
1985 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
1986 if(!aNode) return false;
1987 // try to find element
1988 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
1989 if(!elem) return false;
1991 return elem->IsMediumNode(aNode);
1995 //=============================================================================
1997 * Returns true if given node is medium node
1998 * in one of quadratic elements
2000 //=============================================================================
2002 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2003 SMESH::ElementType theElemType)
2005 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2006 if ( aSMESHDS_Mesh == NULL ) return false;
2009 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2010 if(!aNode) return false;
2012 SMESH_MesherHelper aHelper( *(_impl) );
2014 SMDSAbs_ElementType aType;
2015 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2016 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2017 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2018 else aType = SMDSAbs_All;
2020 return aHelper.IsMedium(aNode,aType);
2024 //=============================================================================
2026 * Returns number of edges for given element
2028 //=============================================================================
2030 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2032 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2033 if ( aSMESHDS_Mesh == NULL ) return -1;
2034 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2035 if(!elem) return -1;
2036 return elem->NbEdges();
2040 //=============================================================================
2042 * Returns number of faces for given element
2044 //=============================================================================
2046 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2048 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2049 if ( aSMESHDS_Mesh == NULL ) return -1;
2050 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2051 if(!elem) return -1;
2052 return elem->NbFaces();
2056 //=============================================================================
2058 * Returns true if given element is polygon
2060 //=============================================================================
2062 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2064 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2065 if ( aSMESHDS_Mesh == NULL ) return false;
2066 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2067 if(!elem) return false;
2068 return elem->IsPoly();
2072 //=============================================================================
2074 * Returns true if given element is quadratic
2076 //=============================================================================
2078 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2080 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2081 if ( aSMESHDS_Mesh == NULL ) return false;
2082 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2083 if(!elem) return false;
2084 return elem->IsQuadratic();
2088 //=============================================================================
2090 * Returns bary center for given element
2092 //=============================================================================
2094 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2096 SMESH::double_array_var aResult = new SMESH::double_array();
2097 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2098 if ( aSMESHDS_Mesh == NULL )
2099 return aResult._retn();
2101 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2103 return aResult._retn();
2105 if(elem->GetType()==SMDSAbs_Volume) {
2106 // use SMDS_VolumeTool
2107 SMDS_VolumeTool aTool;
2108 if(aTool.Set(elem)) {
2109 double x=0., y=0., z=0.;
2110 if(aTool.GetBaryCenter(x,y,z)) {
2120 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2122 double x=0., y=0., z=0.;
2123 for(; anIt->more(); ) {
2125 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2139 return aResult._retn();
2143 //=============================================================================
2147 //=============================================================================
2148 void SMESH_Mesh_i::CreateGroupServants()
2150 // Create group servants, if any groups were imported
2151 list<int> aGroupIds = _impl->GetGroupIds();
2152 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
2153 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
2155 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2156 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2157 aGroupImpl->Register();
2158 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2160 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
2161 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
2163 // register CORBA object for persistence
2164 int nextId = _gen_i->RegisterObject( aGroup );
2165 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);