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 MESSAGE("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 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
300 static SMESH::Hypothesis_Status ConvertHypothesisStatus
301 (SMESH_Hypothesis::Hypothesis_Status theStatus)
304 RETURNCASE( HYP_OK );
305 RETURNCASE( HYP_MISSING );
306 RETURNCASE( HYP_CONCURENT );
307 RETURNCASE( HYP_BAD_PARAMETER );
308 RETURNCASE( HYP_HIDDEN_ALGO );
309 RETURNCASE( HYP_HIDING_ALGO );
310 RETURNCASE( HYP_UNKNOWN_FATAL );
311 RETURNCASE( HYP_INCOMPATIBLE );
312 RETURNCASE( HYP_NOTCONFORM );
313 RETURNCASE( HYP_ALREADY_EXIST );
314 RETURNCASE( HYP_BAD_DIM );
315 RETURNCASE( HYP_BAD_SUBSHAPE );
316 RETURNCASE( HYP_BAD_GEOMETRY );
319 return SMESH::HYP_UNKNOWN_FATAL;
322 //=============================================================================
326 * calls internal addHypothesis() and then adds a reference to <anHyp> under
327 * the SObject actually having a reference to <aSubShape>.
328 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
330 //=============================================================================
332 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
333 SMESH::SMESH_Hypothesis_ptr anHyp)
334 throw(SALOME::SALOME_Exception)
336 Unexpect aCatch(SALOME_SalomeException);
337 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
339 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
340 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
341 aSubShapeObject, anHyp );
343 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
345 // Update Python script
346 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
347 << aSubShapeObject << ", " << anHyp << " )";
349 return ConvertHypothesisStatus(status);
352 //=============================================================================
356 //=============================================================================
358 SMESH_Hypothesis::Hypothesis_Status
359 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
360 SMESH::SMESH_Hypothesis_ptr anHyp)
362 if(MYDEBUG) MESSAGE("addHypothesis");
364 if (CORBA::is_nil(aSubShapeObject))
365 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
368 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
369 if (CORBA::is_nil(myHyp))
370 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
373 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
376 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
377 int hypId = myHyp->GetId();
378 status = _impl->AddHypothesis(myLocSubShape, hypId);
379 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
380 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
381 // assure there is a corresponding submesh
382 if ( !_impl->IsMainShape( myLocSubShape )) {
383 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
384 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
385 createSubMesh( aSubShapeObject );
389 catch(SALOME_Exception & S_ex)
391 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
396 //=============================================================================
400 //=============================================================================
402 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
403 SMESH::SMESH_Hypothesis_ptr anHyp)
404 throw(SALOME::SALOME_Exception)
406 Unexpect aCatch(SALOME_SalomeException);
407 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
409 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
410 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
411 aSubShapeObject, anHyp );
413 // Update Python script
414 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
415 << aSubShapeObject << ", " << anHyp << " )";
417 return ConvertHypothesisStatus(status);
420 //=============================================================================
424 //=============================================================================
426 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
427 SMESH::SMESH_Hypothesis_ptr anHyp)
429 if(MYDEBUG) MESSAGE("removeHypothesis()");
430 // **** proposer liste de subShape (selection multiple)
432 if (CORBA::is_nil(aSubShapeObject))
433 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
436 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
437 if (CORBA::is_nil(myHyp))
438 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
441 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
444 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
445 int hypId = myHyp->GetId();
446 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
447 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
448 _mapHypo.erase( hypId );
450 catch(SALOME_Exception & S_ex)
452 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
457 //=============================================================================
461 //=============================================================================
463 SMESH::ListOfHypothesis *
464 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
465 throw(SALOME::SALOME_Exception)
467 Unexpect aCatch(SALOME_SalomeException);
468 if (MYDEBUG) MESSAGE("GetHypothesisList");
469 if (CORBA::is_nil(aSubShapeObject))
470 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
473 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
476 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
477 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
478 int i = 0, n = aLocalList.size();
481 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
482 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
483 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
484 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
489 catch(SALOME_Exception & S_ex) {
490 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
493 return aList._retn();
496 //=============================================================================
500 //=============================================================================
501 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
502 const char* theName )
503 throw(SALOME::SALOME_Exception)
505 Unexpect aCatch(SALOME_SalomeException);
506 MESSAGE("SMESH_Mesh_i::GetSubMesh");
507 if (CORBA::is_nil(aSubShapeObject))
508 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
511 SMESH::SMESH_subMesh_var subMesh;
512 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
514 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
516 //Get or Create the SMESH_subMesh object implementation
518 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
519 subMesh = getSubMesh( subMeshId );
521 // create a new subMesh object servant if there is none for the shape
522 if ( subMesh->_is_nil() )
523 subMesh = createSubMesh( aSubShapeObject );
525 if ( _gen_i->CanPublishInStudy( subMesh )) {
526 SALOMEDS::SObject_var aSO =
527 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
528 subMesh, aSubShapeObject, theName );
529 if ( !aSO->_is_nil()) {
530 // Update Python script
531 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
532 << aSubShapeObject << ", '" << theName << "' )";
536 catch(SALOME_Exception & S_ex) {
537 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
539 return subMesh._retn();
542 //=============================================================================
546 //=============================================================================
548 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
549 throw (SALOME::SALOME_Exception)
551 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
552 if ( theSubMesh->_is_nil() )
555 GEOM::GEOM_Object_var aSubShapeObject;
556 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
557 if ( !aStudy->_is_nil() ) {
558 // Remove submesh's SObject
559 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
560 if ( !anSO->_is_nil() ) {
561 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
562 SALOMEDS::SObject_var anObj, aRef;
563 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
564 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
566 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
568 // Update Python script
569 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
573 removeSubMesh( theSubMesh, aSubShapeObject.in() );
576 //=============================================================================
580 //=============================================================================
581 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
582 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
584 switch (theElemType) {
589 CASE2STRING( VOLUME );
595 //=============================================================================
599 //=============================================================================
601 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
602 const char* theName )
603 throw(SALOME::SALOME_Exception)
605 Unexpect aCatch(SALOME_SalomeException);
606 SMESH::SMESH_Group_var aNewGroup =
607 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
609 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
610 SALOMEDS::SObject_var aSO =
611 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
612 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
613 if ( !aSO->_is_nil()) {
614 // Update Python script
615 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
616 << ElementTypeString(theElemType) << ", '" << theName << "' )";
619 return aNewGroup._retn();
623 //=============================================================================
627 //=============================================================================
628 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
630 GEOM::GEOM_Object_ptr theGeomObj)
631 throw(SALOME::SALOME_Exception)
633 Unexpect aCatch(SALOME_SalomeException);
634 SMESH::SMESH_GroupOnGeom_var aNewGroup;
636 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
637 if ( !aShape.IsNull() ) {
638 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
639 ( createGroup( theElemType, theName, aShape ));
640 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
641 SALOMEDS::SObject_var aSO =
642 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
643 aNewGroup, theGeomObj, theName);
644 if ( !aSO->_is_nil()) {
645 // Update Python script
646 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
647 << ElementTypeString(theElemType) << ", '" << theName << "', "
648 << theGeomObj << " )";
653 return aNewGroup._retn();
656 //=============================================================================
660 //=============================================================================
662 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
663 throw (SALOME::SALOME_Exception)
665 if ( theGroup->_is_nil() )
668 SMESH_GroupBase_i* aGroup =
669 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
673 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
674 if ( !aStudy->_is_nil() ) {
675 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
677 if ( !aGroupSO->_is_nil() ) {
678 // Update Python script
679 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
681 // Remove group's SObject
682 aStudy->NewBuilder()->RemoveObject( aGroupSO );
686 // Remove the group from SMESH data structures
687 removeGroup( aGroup->GetLocalID() );
690 //=============================================================================
691 /*! RemoveGroupWithContents
692 * Remove group with its contents
694 //=============================================================================
695 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
696 throw (SALOME::SALOME_Exception)
698 if ( theGroup->_is_nil() )
701 SMESH_GroupBase_i* aGroup =
702 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
706 SMESH::long_array_var anIds = aGroup->GetListOfID();
707 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
709 // Update Python script
710 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
713 if ( aGroup->GetType() == SMESH::NODE )
714 aMeshEditor->RemoveNodes( anIds );
716 aMeshEditor->RemoveElements( anIds );
719 RemoveGroup( theGroup );
721 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
722 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
723 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
727 //================================================================================
729 * \brief Get the list of groups existing in the mesh
730 * \retval SMESH::ListOfGroups * - list of groups
732 //================================================================================
734 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
736 Unexpect aCatch(SALOME_SalomeException);
737 if (MYDEBUG) MESSAGE("GetGroups");
739 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
741 TPythonDump aPythonDump;
745 aList->length( _mapGroups.size() );
747 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
748 for ( ; it != _mapGroups.end(); it++ ) {
749 if ( CORBA::is_nil( it->second )) continue;
750 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
752 if (i > 1) aPythonDump << ", ";
753 aPythonDump << it->second;
757 catch(SALOME_Exception & S_ex) {
758 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
761 // Update Python script
762 aPythonDump << " ] = " << _this() << ".GetGroups()";
764 return aList._retn();
767 //=============================================================================
769 * New group is created. All mesh elements that are
770 * present in initial groups are added to the new one
772 //=============================================================================
773 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
774 SMESH::SMESH_GroupBase_ptr theGroup2,
775 const char* theName )
776 throw (SALOME::SALOME_Exception)
780 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
781 theGroup1->GetType() != theGroup2->GetType() )
782 return SMESH::SMESH_Group::_nil();
785 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
786 if ( aResGrp->_is_nil() )
787 return SMESH::SMESH_Group::_nil();
789 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
790 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
792 TColStd_MapOfInteger aResMap;
794 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
795 aResMap.Add( anIds1[ i1 ] );
797 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
798 aResMap.Add( anIds2[ i2 ] );
800 SMESH::long_array_var aResIds = new SMESH::long_array;
801 aResIds->length( aResMap.Extent() );
804 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
805 for( ; anIter.More(); anIter.Next() )
806 aResIds[ resI++ ] = anIter.Key();
808 aResGrp->Add( aResIds );
810 // Clear python lines, created by CreateGroup() and Add()
811 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
812 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
813 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
815 // Update Python script
816 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
817 << theGroup1 << ", " << theGroup2 << ", '"
820 return aResGrp._retn();
824 return SMESH::SMESH_Group::_nil();
828 //=============================================================================
830 * New group is created. All mesh elements that are
831 * present in both initial groups are added to the new one.
833 //=============================================================================
834 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
835 SMESH::SMESH_GroupBase_ptr theGroup2,
836 const char* theName )
837 throw (SALOME::SALOME_Exception)
839 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
840 theGroup1->GetType() != theGroup2->GetType() )
841 return SMESH::SMESH_Group::_nil();
843 // Create Intersection
844 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
845 if ( aResGrp->_is_nil() )
848 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
849 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
851 TColStd_MapOfInteger aMap1;
853 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
854 aMap1.Add( anIds1[ i1 ] );
856 TColStd_SequenceOfInteger aSeq;
858 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
859 if ( aMap1.Contains( anIds2[ i2 ] ) )
860 aSeq.Append( anIds2[ i2 ] );
862 SMESH::long_array_var aResIds = new SMESH::long_array;
863 aResIds->length( aSeq.Length() );
865 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
866 aResIds[ resI ] = aSeq( resI + 1 );
868 aResGrp->Add( aResIds );
870 // Clear python lines, created by CreateGroup() and Add()
871 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
872 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
873 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
875 // Update Python script
876 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
877 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
879 return aResGrp._retn();
882 //=============================================================================
884 * New group is created. All mesh elements that are present in
885 * main group but do not present in tool group are added to the new one
887 //=============================================================================
888 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
889 SMESH::SMESH_GroupBase_ptr theGroup2,
890 const char* theName )
891 throw (SALOME::SALOME_Exception)
893 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
894 theGroup1->GetType() != theGroup2->GetType() )
895 return SMESH::SMESH_Group::_nil();
898 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
899 if ( aResGrp->_is_nil() )
902 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
903 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
905 TColStd_MapOfInteger aMap2;
907 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
908 aMap2.Add( anIds2[ i2 ] );
911 TColStd_SequenceOfInteger aSeq;
912 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
913 if ( !aMap2.Contains( anIds1[ i1 ] ) )
914 aSeq.Append( anIds1[ i1 ] );
916 SMESH::long_array_var aResIds = new SMESH::long_array;
917 aResIds->length( aSeq.Length() );
919 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
920 aResIds[ resI ] = aSeq( resI + 1 );
922 aResGrp->Add( aResIds );
924 // Clear python lines, created by CreateGroup() and Add()
925 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
926 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
927 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
929 // Update Python script
930 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
931 << theGroup1 << ", " << theGroup2 << ", '"
934 return aResGrp._retn();
937 //=============================================================================
941 //=============================================================================
943 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
945 if(MYDEBUG) MESSAGE( "createSubMesh" );
946 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
948 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
949 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
950 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
951 SMESH::SMESH_subMesh_var subMesh
952 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
954 _mapSubMesh[subMeshId] = mySubMesh;
955 _mapSubMesh_i[subMeshId] = subMeshServant;
956 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
958 // register CORBA object for persistence
959 int nextId = _gen_i->RegisterObject( subMesh );
960 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
962 return subMesh._retn();
965 //=======================================================================
966 //function : getSubMesh
968 //=======================================================================
970 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
972 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
973 if ( it == _mapSubMeshIor.end() )
974 return SMESH::SMESH_subMesh::_nil();
976 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
980 //=============================================================================
984 //=============================================================================
986 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
987 GEOM::GEOM_Object_ptr theSubShapeObject )
989 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
990 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
994 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
995 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
996 removeHypothesis( theSubShapeObject, aHypList[i] );
999 catch( const SALOME::SALOME_Exception& ) {
1000 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1003 int subMeshId = theSubMesh->GetId();
1005 _mapSubMesh.erase(subMeshId);
1006 _mapSubMesh_i.erase(subMeshId);
1007 _mapSubMeshIor.erase(subMeshId);
1008 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1011 //=============================================================================
1015 //=============================================================================
1017 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1018 const char* theName,
1019 const TopoDS_Shape& theShape )
1022 SMESH::SMESH_GroupBase_var aGroup;
1023 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1024 SMESH_GroupBase_i* aGroupImpl;
1025 if ( !theShape.IsNull() )
1026 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1028 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1030 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1031 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1032 aGroupImpl->Register();
1033 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1035 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1036 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1038 // register CORBA object for persistence
1039 int nextId = _gen_i->RegisterObject( aGroup );
1040 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1042 return aGroup._retn();
1045 //=============================================================================
1047 * SMESH_Mesh_i::removeGroup
1049 * Should be called by ~SMESH_Group_i()
1051 //=============================================================================
1053 void SMESH_Mesh_i::removeGroup( const int theId )
1055 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1056 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1057 _mapGroups.erase( theId );
1058 _impl->RemoveGroup( theId );
1063 //=============================================================================
1067 //=============================================================================
1069 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1070 throw(SALOME::SALOME_Exception)
1072 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1074 SMESH::log_array_var aLog;
1076 list < SMESHDS_Command * >logDS = _impl->GetLog();
1077 aLog = new SMESH::log_array;
1079 int lg = logDS.size();
1082 list < SMESHDS_Command * >::iterator its = logDS.begin();
1083 while(its != logDS.end()){
1084 SMESHDS_Command *com = *its;
1085 int comType = com->GetType();
1087 int lgcom = com->GetNumber();
1089 const list < int >&intList = com->GetIndexes();
1090 int inum = intList.size();
1092 list < int >::const_iterator ii = intList.begin();
1093 const list < double >&coordList = com->GetCoords();
1094 int rnum = coordList.size();
1096 list < double >::const_iterator ir = coordList.begin();
1097 aLog[indexLog].commandType = comType;
1098 aLog[indexLog].number = lgcom;
1099 aLog[indexLog].coords.length(rnum);
1100 aLog[indexLog].indexes.length(inum);
1101 for(int i = 0; i < rnum; i++){
1102 aLog[indexLog].coords[i] = *ir;
1103 //MESSAGE(" "<<i<<" "<<ir.Value());
1106 for(int i = 0; i < inum; i++){
1107 aLog[indexLog].indexes[i] = *ii;
1108 //MESSAGE(" "<<i<<" "<<ii.Value());
1117 catch(SALOME_Exception & S_ex){
1118 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1120 return aLog._retn();
1124 //=============================================================================
1128 //=============================================================================
1130 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1132 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1136 //=============================================================================
1140 //=============================================================================
1142 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1144 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1148 //=============================================================================
1152 //=============================================================================
1154 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1159 //=============================================================================
1163 //=============================================================================
1165 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1167 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1171 //=============================================================================
1175 //=============================================================================
1177 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1179 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1184 //=============================================================================
1188 //=============================================================================
1190 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1192 // Create MeshEditor
1193 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );
1194 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1196 // Update Python script
1197 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1199 return aMesh._retn();
1202 //=============================================================================
1204 * Export in different formats
1206 //=============================================================================
1208 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1210 return _impl->HasDuplicatedGroupNamesMED();
1213 static void PrepareForWriting (const char* file)
1215 TCollection_AsciiString aFullName ((char*)file);
1216 OSD_Path aPath (aFullName);
1217 OSD_File aFile (aPath);
1218 if (aFile.Exists()) {
1219 // existing filesystem node
1220 if (aFile.KindOfFile() == OSD_FILE) {
1221 if (aFile.IsWriteable()) {
1224 if (aFile.Failed()) {
1225 TCollection_AsciiString msg ("File ");
1226 msg += aFullName + " cannot be replaced.";
1227 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1230 TCollection_AsciiString msg ("File ");
1231 msg += aFullName + " cannot be overwritten.";
1232 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1235 TCollection_AsciiString msg ("Location ");
1236 msg += aFullName + " is not a file.";
1237 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1240 // nonexisting file; check if it can be created
1242 aFile.Build(OSD_WriteOnly, OSD_Protection());
1243 if (aFile.Failed()) {
1244 TCollection_AsciiString msg ("You cannot create the file ");
1245 msg += aFullName + ". Check the directory existance and access rights.";
1246 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1254 void SMESH_Mesh_i::ExportToMED (const char* file,
1255 CORBA::Boolean auto_groups,
1256 SMESH::MED_VERSION theVersion)
1257 throw(SALOME::SALOME_Exception)
1259 Unexpect aCatch(SALOME_SalomeException);
1261 // Update Python script
1262 TPythonDump() << _this() << ".ExportToMED( '"
1263 << file << "', " << auto_groups << ", " << theVersion << " )";
1266 PrepareForWriting(file);
1267 char* aMeshName = "Mesh";
1268 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1269 if ( !aStudy->_is_nil() ) {
1270 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1271 if ( !aMeshSO->_is_nil() ) {
1272 aMeshName = aMeshSO->GetName();
1274 //SCRUTE(aMeshName);
1275 //SCRUTE(aMeshSO->GetID());
1277 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1278 if ( !aStudy->GetProperties()->IsLocked() )
1280 SALOMEDS::GenericAttribute_var anAttr;
1281 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1282 SALOMEDS::AttributeExternalFileDef_var aFileName;
1283 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1284 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1285 ASSERT(!aFileName->_is_nil());
1286 aFileName->SetValue(file);
1287 SALOMEDS::AttributeFileType_var aFileType;
1288 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1289 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1290 ASSERT(!aFileType->_is_nil());
1291 aFileType->SetValue("FICHIERMED");
1295 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1298 void SMESH_Mesh_i::ExportMED (const char* file,
1299 CORBA::Boolean auto_groups)
1300 throw(SALOME::SALOME_Exception)
1302 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1305 void SMESH_Mesh_i::ExportDAT (const char *file)
1306 throw(SALOME::SALOME_Exception)
1308 Unexpect aCatch(SALOME_SalomeException);
1310 // Update Python script
1311 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1314 PrepareForWriting(file);
1315 _impl->ExportDAT(file);
1318 void SMESH_Mesh_i::ExportUNV (const char *file)
1319 throw(SALOME::SALOME_Exception)
1321 Unexpect aCatch(SALOME_SalomeException);
1323 // Update Python script
1324 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1327 PrepareForWriting(file);
1328 _impl->ExportUNV(file);
1331 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1332 throw(SALOME::SALOME_Exception)
1334 Unexpect aCatch(SALOME_SalomeException);
1336 // Update Python script
1337 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1340 PrepareForWriting(file);
1341 _impl->ExportSTL(file, isascii);
1344 //=============================================================================
1348 //=============================================================================
1350 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1352 Unexpect aCatch(SALOME_SalomeException);
1353 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1354 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1355 return aMesh._retn();
1358 //=============================================================================
1362 //=============================================================================
1363 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1365 Unexpect aCatch(SALOME_SalomeException);
1366 return _impl->NbNodes();
1369 //=============================================================================
1373 //=============================================================================
1374 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1376 Unexpect aCatch(SALOME_SalomeException);
1377 return NbEdges() + NbFaces() + NbVolumes();
1380 //=============================================================================
1384 //=============================================================================
1385 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1387 Unexpect aCatch(SALOME_SalomeException);
1388 return _impl->NbEdges();
1391 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1392 throw(SALOME::SALOME_Exception)
1394 Unexpect aCatch(SALOME_SalomeException);
1395 return _impl->NbEdges( (::SMESH_Mesh::ElementOrder) order);
1398 //=============================================================================
1402 //=============================================================================
1403 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1405 Unexpect aCatch(SALOME_SalomeException);
1406 return _impl->NbFaces();
1409 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1411 Unexpect aCatch(SALOME_SalomeException);
1412 return _impl->NbTriangles();
1415 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1417 Unexpect aCatch(SALOME_SalomeException);
1418 return _impl->NbQuadrangles();
1421 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1423 Unexpect aCatch(SALOME_SalomeException);
1424 return _impl->NbPolygons();
1427 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1428 throw(SALOME::SALOME_Exception)
1430 Unexpect aCatch(SALOME_SalomeException);
1431 return _impl->NbFaces( (::SMESH_Mesh::ElementOrder) order);
1434 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1435 throw(SALOME::SALOME_Exception)
1437 Unexpect aCatch(SALOME_SalomeException);
1438 return _impl->NbTriangles( (::SMESH_Mesh::ElementOrder) order);
1441 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1442 throw(SALOME::SALOME_Exception)
1444 Unexpect aCatch(SALOME_SalomeException);
1445 return _impl->NbQuadrangles( (::SMESH_Mesh::ElementOrder) order);
1448 //=============================================================================
1452 //=============================================================================
1453 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1455 Unexpect aCatch(SALOME_SalomeException);
1456 return _impl->NbVolumes();
1459 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1461 Unexpect aCatch(SALOME_SalomeException);
1462 return _impl->NbTetras();
1465 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1467 Unexpect aCatch(SALOME_SalomeException);
1468 return _impl->NbHexas();
1471 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1473 Unexpect aCatch(SALOME_SalomeException);
1474 return _impl->NbPyramids();
1477 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1479 Unexpect aCatch(SALOME_SalomeException);
1480 return _impl->NbPrisms();
1483 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1485 Unexpect aCatch(SALOME_SalomeException);
1486 return _impl->NbPolyhedrons();
1489 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1490 throw(SALOME::SALOME_Exception)
1492 Unexpect aCatch(SALOME_SalomeException);
1493 return _impl->NbVolumes( (::SMESH_Mesh::ElementOrder) order);
1496 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1497 throw(SALOME::SALOME_Exception)
1499 Unexpect aCatch(SALOME_SalomeException);
1500 return _impl->NbTetras( (::SMESH_Mesh::ElementOrder) order);
1503 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1504 throw(SALOME::SALOME_Exception)
1506 Unexpect aCatch(SALOME_SalomeException);
1507 return _impl->NbHexas( (::SMESH_Mesh::ElementOrder) order);
1510 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1511 throw(SALOME::SALOME_Exception)
1513 Unexpect aCatch(SALOME_SalomeException);
1514 return _impl->NbPyramids( (::SMESH_Mesh::ElementOrder) order);
1517 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1518 throw(SALOME::SALOME_Exception)
1520 Unexpect aCatch(SALOME_SalomeException);
1521 return _impl->NbPrisms( (::SMESH_Mesh::ElementOrder) order);
1524 //=============================================================================
1528 //=============================================================================
1529 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1531 Unexpect aCatch(SALOME_SalomeException);
1532 return _impl->NbSubMesh();
1535 //=============================================================================
1539 //=============================================================================
1540 char* SMESH_Mesh_i::Dump()
1542 std::ostringstream os;
1544 return CORBA::string_dup( os.str().c_str() );
1547 //=============================================================================
1551 //=============================================================================
1552 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1554 // SMESH::long_array_var aResult = new SMESH::long_array();
1555 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1556 // int aMinId = aSMESHDS_Mesh->MinElementID();
1557 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1559 // aResult->length(aMaxId - aMinId + 1);
1561 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1562 // aResult[i++] = id;
1564 // return aResult._retn();
1566 return GetElementsId();
1569 //=============================================================================
1573 //=============================================================================
1575 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1576 throw (SALOME::SALOME_Exception)
1578 Unexpect aCatch(SALOME_SalomeException);
1579 MESSAGE("SMESH_Mesh_i::GetElementsId");
1580 SMESH::long_array_var aResult = new SMESH::long_array();
1581 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1583 if ( aSMESHDS_Mesh == NULL )
1584 return aResult._retn();
1586 long nbElements = NbElements();
1587 aResult->length( nbElements );
1588 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1589 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1590 aResult[i] = anIt->next()->GetID();
1592 return aResult._retn();
1596 //=============================================================================
1600 //=============================================================================
1602 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1603 throw (SALOME::SALOME_Exception)
1605 Unexpect aCatch(SALOME_SalomeException);
1606 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1607 SMESH::long_array_var aResult = new SMESH::long_array();
1608 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1610 if ( aSMESHDS_Mesh == NULL )
1611 return aResult._retn();
1613 long nbElements = NbElements();
1615 // No sense in returning ids of elements along with ids of nodes:
1616 // when theElemType == SMESH::ALL, return node ids only if
1617 // there are no elements
1618 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1619 return GetNodesId();
1621 aResult->length( nbElements );
1625 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1626 while ( i < nbElements && anIt->more() ) {
1627 const SMDS_MeshElement* anElem = anIt->next();
1628 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1629 aResult[i++] = anElem->GetID();
1632 aResult->length( i );
1634 return aResult._retn();
1637 //=============================================================================
1641 //=============================================================================
1643 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1644 throw (SALOME::SALOME_Exception)
1646 Unexpect aCatch(SALOME_SalomeException);
1647 MESSAGE("SMESH_subMesh_i::GetNodesId");
1648 SMESH::long_array_var aResult = new SMESH::long_array();
1649 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1651 if ( aSMESHDS_Mesh == NULL )
1652 return aResult._retn();
1654 long nbNodes = NbNodes();
1655 aResult->length( nbNodes );
1656 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1657 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1658 aResult[i] = anIt->next()->GetID();
1660 return aResult._retn();
1663 //=============================================================================
1667 //=============================================================================
1669 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1670 throw (SALOME::SALOME_Exception)
1672 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1676 //=============================================================================
1678 * Returns ID of elements for given submesh
1680 //=============================================================================
1681 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1682 throw (SALOME::SALOME_Exception)
1684 SMESH::long_array_var aResult = new SMESH::long_array();
1686 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1687 if(!SM) return aResult._retn();
1689 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1690 if(!SDSM) return aResult._retn();
1692 aResult->length(SDSM->NbElements());
1694 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1696 while ( eIt->more() ) {
1697 aResult[i++] = eIt->next()->GetID();
1700 return aResult._retn();
1704 //=============================================================================
1706 * Returns ID of nodes for given submesh
1707 * If param all==true - returns all nodes, else -
1708 * returns only nodes on shapes.
1710 //=============================================================================
1711 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1712 throw (SALOME::SALOME_Exception)
1714 SMESH::long_array_var aResult = new SMESH::long_array();
1716 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1717 if(!SM) return aResult._retn();
1719 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1720 if(!SDSM) return aResult._retn();
1722 map<int,const SMDS_MeshElement*> theElems;
1723 if( !all || (SDSM->NbElements()==0 && SDSM->NbNodes()==1) ) {
1724 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1725 while ( nIt->more() ) {
1726 const SMDS_MeshNode* elem = nIt->next();
1727 theElems.insert( make_pair(elem->GetID(),elem) );
1730 else { // all nodes of submesh elements
1731 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1732 while ( eIt->more() ) {
1733 const SMDS_MeshElement* anElem = eIt->next();
1734 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1735 while ( nIt->more() ) {
1736 const SMDS_MeshElement* elem = nIt->next();
1737 theElems.insert( make_pair(elem->GetID(),elem) );
1742 aResult->length(theElems.size());
1743 map<int, const SMDS_MeshElement * >::iterator itElem;
1745 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1746 aResult[i++] = (*itElem).first;
1748 return aResult._retn();
1752 //=============================================================================
1754 * Returns type of elements for given submesh
1756 //=============================================================================
1757 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
1758 throw (SALOME::SALOME_Exception)
1760 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1761 if(!SM) return SMESH::ALL;
1763 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1764 if(!SDSM) return SMESH::ALL;
1766 if(SDSM->NbElements()==0)
1767 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
1769 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1770 const SMDS_MeshElement* anElem = eIt->next();
1771 return ( SMESH::ElementType ) anElem->GetType();
1775 //=============================================================================
1779 //=============================================================================
1781 CORBA::Long SMESH_Mesh_i::GetMeshPtr()
1783 return CORBA::Long(size_t(_impl));
1787 //=============================================================================
1789 * Get XYZ coordinates of node as list of double
1790 * If there is not node for given ID - returns empty list
1792 //=============================================================================
1794 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
1796 SMESH::double_array_var aResult = new SMESH::double_array();
1797 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1798 if ( aSMESHDS_Mesh == NULL )
1799 return aResult._retn();
1802 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1804 return aResult._retn();
1808 aResult[0] = aNode->X();
1809 aResult[1] = aNode->Y();
1810 aResult[2] = aNode->Z();
1811 return aResult._retn();
1815 //=============================================================================
1817 * For given node returns list of IDs of inverse elements
1818 * If there is not node for given ID - returns empty list
1820 //=============================================================================
1822 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
1824 SMESH::long_array_var aResult = new SMESH::long_array();
1825 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1826 if ( aSMESHDS_Mesh == NULL )
1827 return aResult._retn();
1830 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1832 return aResult._retn();
1834 // find inverse elements
1835 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
1836 TColStd_SequenceOfInteger IDs;
1837 while(eIt->more()) {
1838 const SMDS_MeshElement* elem = eIt->next();
1839 IDs.Append(elem->GetID());
1841 if(IDs.Length()>0) {
1842 aResult->length(IDs.Length());
1844 for(; i<=IDs.Length(); i++) {
1845 aResult[i-1] = IDs.Value(i);
1848 return aResult._retn();
1852 //=============================================================================
1854 * If given element is node returns IDs of shape from position
1855 * If there is not node for given ID - returns -1
1857 //=============================================================================
1859 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
1861 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1862 if ( aSMESHDS_Mesh == NULL )
1866 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1868 SMDS_PositionPtr pos = aNode->GetPosition();
1872 return pos->GetShapeId();
1879 //=============================================================================
1881 * For given element returns ID of result shape after
1882 * ::FindShape() from SMESH_MeshEditor
1883 * If there is not element for given ID - returns -1
1885 //=============================================================================
1887 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
1889 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1890 if ( aSMESHDS_Mesh == NULL )
1893 // try to find element
1894 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1898 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
1899 ::SMESH_MeshEditor aMeshEditor(_impl);
1900 int index = aMeshEditor.FindShape( elem );
1908 //=============================================================================
1910 * Returns number of nodes for given element
1911 * If there is not element for given ID - returns -1
1913 //=============================================================================
1915 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
1917 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1918 if ( aSMESHDS_Mesh == NULL ) return -1;
1919 // try to find element
1920 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1921 if(!elem) return -1;
1922 return elem->NbNodes();
1926 //=============================================================================
1928 * Returns ID of node by given index for given element
1929 * If there is not element for given ID - returns -1
1930 * If there is not node for given index - returns -2
1932 //=============================================================================
1934 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
1936 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1937 if ( aSMESHDS_Mesh == NULL ) return -1;
1938 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1939 if(!elem) return -1;
1940 if( index>=elem->NbNodes() || index<0 ) return -1;
1941 return elem->GetNode(index)->GetID();
1944 //=============================================================================
1946 * Returns IDs of nodes of given element
1948 //=============================================================================
1950 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
1952 SMESH::long_array_var aResult = new SMESH::long_array();
1953 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
1955 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
1957 aResult->length( elem->NbNodes() );
1958 for ( int i = 0; i < elem->NbNodes(); ++i )
1959 aResult[ i ] = elem->GetNode( i )->GetID();
1962 return aResult._retn();
1965 //=============================================================================
1967 * Returns true if given node is medium node
1968 * in given quadratic element
1970 //=============================================================================
1972 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
1974 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1975 if ( aSMESHDS_Mesh == NULL ) return false;
1977 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
1978 if(!aNode) return false;
1979 // try to find element
1980 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
1981 if(!elem) return false;
1983 return elem->IsMediumNode(aNode);
1987 //=============================================================================
1989 * Returns true if given node is medium node
1990 * in one of quadratic elements
1992 //=============================================================================
1994 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
1995 SMESH::ElementType theElemType)
1997 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1998 if ( aSMESHDS_Mesh == NULL ) return false;
2001 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2002 if(!aNode) return false;
2004 SMESH_MesherHelper aHelper( *(_impl) );
2006 SMDSAbs_ElementType aType;
2007 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2008 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2009 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2010 else aType = SMDSAbs_All;
2012 return aHelper.IsMedium(aNode,aType);
2016 //=============================================================================
2018 * Returns number of edges for given element
2020 //=============================================================================
2022 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2024 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2025 if ( aSMESHDS_Mesh == NULL ) return -1;
2026 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2027 if(!elem) return -1;
2028 return elem->NbEdges();
2032 //=============================================================================
2034 * Returns number of faces for given element
2036 //=============================================================================
2038 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2040 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2041 if ( aSMESHDS_Mesh == NULL ) return -1;
2042 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2043 if(!elem) return -1;
2044 return elem->NbFaces();
2048 //=============================================================================
2050 * Returns true if given element is polygon
2052 //=============================================================================
2054 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2056 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2057 if ( aSMESHDS_Mesh == NULL ) return false;
2058 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2059 if(!elem) return false;
2060 return elem->IsPoly();
2064 //=============================================================================
2066 * Returns true if given element is quadratic
2068 //=============================================================================
2070 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2072 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2073 if ( aSMESHDS_Mesh == NULL ) return false;
2074 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2075 if(!elem) return false;
2076 return elem->IsQuadratic();
2080 //=============================================================================
2082 * Returns bary center for given element
2084 //=============================================================================
2086 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2088 SMESH::double_array_var aResult = new SMESH::double_array();
2089 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2090 if ( aSMESHDS_Mesh == NULL )
2091 return aResult._retn();
2093 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2095 return aResult._retn();
2097 if(elem->GetType()==SMDSAbs_Volume) {
2098 // use SMDS_VolumeTool
2099 SMDS_VolumeTool aTool;
2100 if(aTool.Set(elem)) {
2101 double x=0., y=0., z=0.;
2102 if(aTool.GetBaryCenter(x,y,z)) {
2112 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2114 double x=0., y=0., z=0.;
2115 for(; anIt->more(); ) {
2117 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2131 return aResult._retn();
2135 //=============================================================================
2139 //=============================================================================
2140 void SMESH_Mesh_i::CreateGroupServants()
2142 // Create group servants, if any groups were imported
2143 list<int> aGroupIds = _impl->GetGroupIds();
2144 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
2145 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
2147 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2148 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2149 aGroupImpl->Register();
2150 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2152 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
2153 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
2155 // register CORBA object for persistence
2156 int nextId = _gen_i->RegisterObject( aGroup );
2157 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);