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;
323 res = SMESH::HYP_UNKNOWN_FATAL;
328 //=============================================================================
332 * calls internal addHypothesis() and then adds a reference to <anHyp> under
333 * the SObject actually having a reference to <aSubShape>.
334 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
336 //=============================================================================
338 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
339 SMESH::SMESH_Hypothesis_ptr anHyp)
340 throw(SALOME::SALOME_Exception)
342 Unexpect aCatch(SALOME_SalomeException);
343 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
345 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
346 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
347 aSubShapeObject, anHyp );
349 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
351 // Update Python script
352 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
353 << aSubShapeObject << ", " << anHyp << " )";
355 return ConvertHypothesisStatus(status);
358 //=============================================================================
362 //=============================================================================
364 SMESH_Hypothesis::Hypothesis_Status
365 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
366 SMESH::SMESH_Hypothesis_ptr anHyp)
368 if(MYDEBUG) MESSAGE("addHypothesis");
370 if (CORBA::is_nil(aSubShapeObject))
371 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
374 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
375 if (CORBA::is_nil(myHyp))
376 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
379 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
382 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
383 int hypId = myHyp->GetId();
384 status = _impl->AddHypothesis(myLocSubShape, hypId);
385 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
386 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
387 // assure there is a corresponding submesh
388 if ( !_impl->IsMainShape( myLocSubShape )) {
389 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
390 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
391 createSubMesh( aSubShapeObject );
395 catch(SALOME_Exception & S_ex)
397 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
402 //=============================================================================
406 //=============================================================================
408 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
409 SMESH::SMESH_Hypothesis_ptr anHyp)
410 throw(SALOME::SALOME_Exception)
412 Unexpect aCatch(SALOME_SalomeException);
413 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
415 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
416 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
417 aSubShapeObject, anHyp );
419 // Update Python script
420 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
421 << aSubShapeObject << ", " << anHyp << " )";
423 return ConvertHypothesisStatus(status);
426 //=============================================================================
430 //=============================================================================
432 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
433 SMESH::SMESH_Hypothesis_ptr anHyp)
435 if(MYDEBUG) MESSAGE("removeHypothesis()");
436 // **** proposer liste de subShape (selection multiple)
438 if (CORBA::is_nil(aSubShapeObject))
439 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
442 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
443 if (CORBA::is_nil(myHyp))
444 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
447 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
450 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
451 int hypId = myHyp->GetId();
452 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
453 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
454 _mapHypo.erase( hypId );
456 catch(SALOME_Exception & S_ex)
458 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
463 //=============================================================================
467 //=============================================================================
469 SMESH::ListOfHypothesis *
470 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
471 throw(SALOME::SALOME_Exception)
473 Unexpect aCatch(SALOME_SalomeException);
474 if (MYDEBUG) MESSAGE("GetHypothesisList");
475 if (CORBA::is_nil(aSubShapeObject))
476 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
479 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
482 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
483 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
484 int i = 0, n = aLocalList.size();
487 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
488 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
489 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
490 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
495 catch(SALOME_Exception & S_ex) {
496 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
499 return aList._retn();
502 //=============================================================================
506 //=============================================================================
507 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
508 const char* theName )
509 throw(SALOME::SALOME_Exception)
511 Unexpect aCatch(SALOME_SalomeException);
512 MESSAGE("SMESH_Mesh_i::GetSubMesh");
513 if (CORBA::is_nil(aSubShapeObject))
514 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
517 SMESH::SMESH_subMesh_var subMesh;
518 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
520 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
522 //Get or Create the SMESH_subMesh object implementation
524 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
525 subMesh = getSubMesh( subMeshId );
527 // create a new subMesh object servant if there is none for the shape
528 if ( subMesh->_is_nil() )
529 subMesh = createSubMesh( aSubShapeObject );
531 if ( _gen_i->CanPublishInStudy( subMesh )) {
532 SALOMEDS::SObject_var aSO =
533 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
534 subMesh, aSubShapeObject, theName );
535 if ( !aSO->_is_nil()) {
536 // Update Python script
537 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
538 << aSubShapeObject << ", '" << theName << "' )";
542 catch(SALOME_Exception & S_ex) {
543 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
545 return subMesh._retn();
548 //=============================================================================
552 //=============================================================================
554 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
555 throw (SALOME::SALOME_Exception)
557 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
558 if ( theSubMesh->_is_nil() )
561 GEOM::GEOM_Object_var aSubShapeObject;
562 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
563 if ( !aStudy->_is_nil() ) {
564 // Remove submesh's SObject
565 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
566 if ( !anSO->_is_nil() ) {
567 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
568 SALOMEDS::SObject_var anObj, aRef;
569 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
570 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
572 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
574 // Update Python script
575 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
579 removeSubMesh( theSubMesh, aSubShapeObject.in() );
582 //=============================================================================
586 //=============================================================================
587 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
588 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
590 switch (theElemType) {
595 CASE2STRING( VOLUME );
601 //=============================================================================
605 //=============================================================================
607 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
608 const char* theName )
609 throw(SALOME::SALOME_Exception)
611 Unexpect aCatch(SALOME_SalomeException);
612 SMESH::SMESH_Group_var aNewGroup =
613 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
615 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
616 SALOMEDS::SObject_var aSO =
617 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
618 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
619 if ( !aSO->_is_nil()) {
620 // Update Python script
621 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
622 << ElementTypeString(theElemType) << ", '" << theName << "' )";
625 return aNewGroup._retn();
629 //=============================================================================
633 //=============================================================================
634 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
636 GEOM::GEOM_Object_ptr theGeomObj)
637 throw(SALOME::SALOME_Exception)
639 Unexpect aCatch(SALOME_SalomeException);
640 SMESH::SMESH_GroupOnGeom_var aNewGroup;
642 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
643 if ( !aShape.IsNull() ) {
644 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
645 ( createGroup( theElemType, theName, aShape ));
646 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
647 SALOMEDS::SObject_var aSO =
648 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
649 aNewGroup, theGeomObj, theName);
650 if ( !aSO->_is_nil()) {
651 // Update Python script
652 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
653 << ElementTypeString(theElemType) << ", '" << theName << "', "
654 << theGeomObj << " )";
659 return aNewGroup._retn();
662 //=============================================================================
666 //=============================================================================
668 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
669 throw (SALOME::SALOME_Exception)
671 if ( theGroup->_is_nil() )
674 SMESH_GroupBase_i* aGroup =
675 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
679 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
680 if ( !aStudy->_is_nil() ) {
681 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
683 if ( !aGroupSO->_is_nil() ) {
684 // Update Python script
685 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
687 // Remove group's SObject
688 aStudy->NewBuilder()->RemoveObject( aGroupSO );
692 // Remove the group from SMESH data structures
693 removeGroup( aGroup->GetLocalID() );
696 //=============================================================================
697 /*! RemoveGroupWithContents
698 * Remove group with its contents
700 //=============================================================================
701 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
702 throw (SALOME::SALOME_Exception)
704 if ( theGroup->_is_nil() )
707 SMESH_GroupBase_i* aGroup =
708 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
712 SMESH::long_array_var anIds = aGroup->GetListOfID();
713 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
715 // Update Python script
716 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
719 if ( aGroup->GetType() == SMESH::NODE )
720 aMeshEditor->RemoveNodes( anIds );
722 aMeshEditor->RemoveElements( anIds );
725 RemoveGroup( theGroup );
727 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
728 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
729 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
733 //================================================================================
735 * \brief Get the list of groups existing in the mesh
736 * \retval SMESH::ListOfGroups * - list of groups
738 //================================================================================
740 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
742 Unexpect aCatch(SALOME_SalomeException);
743 if (MYDEBUG) MESSAGE("GetGroups");
745 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
747 TPythonDump aPythonDump;
751 aList->length( _mapGroups.size() );
753 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
754 for ( ; it != _mapGroups.end(); it++ ) {
755 if ( CORBA::is_nil( it->second )) continue;
756 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
758 if (i > 1) aPythonDump << ", ";
759 aPythonDump << it->second;
763 catch(SALOME_Exception & S_ex) {
764 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
767 // Update Python script
768 aPythonDump << " ] = " << _this() << ".GetGroups()";
770 return aList._retn();
773 //=============================================================================
775 * New group is created. All mesh elements that are
776 * present in initial groups are added to the new one
778 //=============================================================================
779 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
780 SMESH::SMESH_GroupBase_ptr theGroup2,
781 const char* theName )
782 throw (SALOME::SALOME_Exception)
786 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
787 theGroup1->GetType() != theGroup2->GetType() )
788 return SMESH::SMESH_Group::_nil();
791 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
792 if ( aResGrp->_is_nil() )
793 return SMESH::SMESH_Group::_nil();
795 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
796 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
798 TColStd_MapOfInteger aResMap;
800 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
801 aResMap.Add( anIds1[ i1 ] );
803 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
804 aResMap.Add( anIds2[ i2 ] );
806 SMESH::long_array_var aResIds = new SMESH::long_array;
807 aResIds->length( aResMap.Extent() );
810 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
811 for( ; anIter.More(); anIter.Next() )
812 aResIds[ resI++ ] = anIter.Key();
814 aResGrp->Add( aResIds );
816 // Clear python lines, created by CreateGroup() and Add()
817 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
818 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
819 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
821 // Update Python script
822 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
823 << theGroup1 << ", " << theGroup2 << ", '"
826 return aResGrp._retn();
830 return SMESH::SMESH_Group::_nil();
834 //=============================================================================
836 * New group is created. All mesh elements that are
837 * present in both initial groups are added to the new one.
839 //=============================================================================
840 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
841 SMESH::SMESH_GroupBase_ptr theGroup2,
842 const char* theName )
843 throw (SALOME::SALOME_Exception)
845 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
846 theGroup1->GetType() != theGroup2->GetType() )
847 return SMESH::SMESH_Group::_nil();
849 // Create Intersection
850 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
851 if ( aResGrp->_is_nil() )
854 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
855 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
857 TColStd_MapOfInteger aMap1;
859 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
860 aMap1.Add( anIds1[ i1 ] );
862 TColStd_SequenceOfInteger aSeq;
864 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
865 if ( aMap1.Contains( anIds2[ i2 ] ) )
866 aSeq.Append( anIds2[ i2 ] );
868 SMESH::long_array_var aResIds = new SMESH::long_array;
869 aResIds->length( aSeq.Length() );
871 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
872 aResIds[ resI ] = aSeq( resI + 1 );
874 aResGrp->Add( aResIds );
876 // Clear python lines, created by CreateGroup() and Add()
877 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
878 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
879 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
881 // Update Python script
882 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
883 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
885 return aResGrp._retn();
888 //=============================================================================
890 * New group is created. All mesh elements that are present in
891 * main group but do not present in tool group are added to the new one
893 //=============================================================================
894 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
895 SMESH::SMESH_GroupBase_ptr theGroup2,
896 const char* theName )
897 throw (SALOME::SALOME_Exception)
899 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
900 theGroup1->GetType() != theGroup2->GetType() )
901 return SMESH::SMESH_Group::_nil();
904 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
905 if ( aResGrp->_is_nil() )
908 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
909 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
911 TColStd_MapOfInteger aMap2;
913 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
914 aMap2.Add( anIds2[ i2 ] );
917 TColStd_SequenceOfInteger aSeq;
918 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
919 if ( !aMap2.Contains( anIds1[ i1 ] ) )
920 aSeq.Append( anIds1[ i1 ] );
922 SMESH::long_array_var aResIds = new SMESH::long_array;
923 aResIds->length( aSeq.Length() );
925 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
926 aResIds[ resI ] = aSeq( resI + 1 );
928 aResGrp->Add( aResIds );
930 // Clear python lines, created by CreateGroup() and Add()
931 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
932 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
933 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
935 // Update Python script
936 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
937 << theGroup1 << ", " << theGroup2 << ", '"
940 return aResGrp._retn();
943 //=============================================================================
947 //=============================================================================
949 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
951 if(MYDEBUG) MESSAGE( "createSubMesh" );
952 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
954 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
955 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
956 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
957 SMESH::SMESH_subMesh_var subMesh
958 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
960 _mapSubMesh[subMeshId] = mySubMesh;
961 _mapSubMesh_i[subMeshId] = subMeshServant;
962 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
964 // register CORBA object for persistence
965 int nextId = _gen_i->RegisterObject( subMesh );
966 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
968 return subMesh._retn();
971 //=======================================================================
972 //function : getSubMesh
974 //=======================================================================
976 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
978 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
979 if ( it == _mapSubMeshIor.end() )
980 return SMESH::SMESH_subMesh::_nil();
982 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
986 //=============================================================================
990 //=============================================================================
992 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
993 GEOM::GEOM_Object_ptr theSubShapeObject )
995 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
996 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1000 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1001 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1002 removeHypothesis( theSubShapeObject, aHypList[i] );
1005 catch( const SALOME::SALOME_Exception& ) {
1006 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1009 int subMeshId = theSubMesh->GetId();
1011 _mapSubMesh.erase(subMeshId);
1012 _mapSubMesh_i.erase(subMeshId);
1013 _mapSubMeshIor.erase(subMeshId);
1014 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1017 //=============================================================================
1021 //=============================================================================
1023 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1024 const char* theName,
1025 const TopoDS_Shape& theShape )
1028 SMESH::SMESH_GroupBase_var aGroup;
1029 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1030 SMESH_GroupBase_i* aGroupImpl;
1031 if ( !theShape.IsNull() )
1032 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1034 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1036 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1037 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1038 aGroupImpl->Register();
1039 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1041 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1042 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1044 // register CORBA object for persistence
1045 int nextId = _gen_i->RegisterObject( aGroup );
1046 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1048 return aGroup._retn();
1051 //=============================================================================
1053 * SMESH_Mesh_i::removeGroup
1055 * Should be called by ~SMESH_Group_i()
1057 //=============================================================================
1059 void SMESH_Mesh_i::removeGroup( const int theId )
1061 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1062 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1063 _mapGroups.erase( theId );
1064 _impl->RemoveGroup( theId );
1069 //=============================================================================
1073 //=============================================================================
1075 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1076 throw(SALOME::SALOME_Exception)
1078 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1080 SMESH::log_array_var aLog;
1082 list < SMESHDS_Command * >logDS = _impl->GetLog();
1083 aLog = new SMESH::log_array;
1085 int lg = logDS.size();
1088 list < SMESHDS_Command * >::iterator its = logDS.begin();
1089 while(its != logDS.end()){
1090 SMESHDS_Command *com = *its;
1091 int comType = com->GetType();
1093 int lgcom = com->GetNumber();
1095 const list < int >&intList = com->GetIndexes();
1096 int inum = intList.size();
1098 list < int >::const_iterator ii = intList.begin();
1099 const list < double >&coordList = com->GetCoords();
1100 int rnum = coordList.size();
1102 list < double >::const_iterator ir = coordList.begin();
1103 aLog[indexLog].commandType = comType;
1104 aLog[indexLog].number = lgcom;
1105 aLog[indexLog].coords.length(rnum);
1106 aLog[indexLog].indexes.length(inum);
1107 for(int i = 0; i < rnum; i++){
1108 aLog[indexLog].coords[i] = *ir;
1109 //MESSAGE(" "<<i<<" "<<ir.Value());
1112 for(int i = 0; i < inum; i++){
1113 aLog[indexLog].indexes[i] = *ii;
1114 //MESSAGE(" "<<i<<" "<<ii.Value());
1123 catch(SALOME_Exception & S_ex){
1124 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1126 return aLog._retn();
1130 //=============================================================================
1134 //=============================================================================
1136 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1138 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1142 //=============================================================================
1146 //=============================================================================
1148 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1150 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1154 //=============================================================================
1158 //=============================================================================
1160 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1165 //=============================================================================
1169 //=============================================================================
1171 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1173 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1177 //=============================================================================
1181 //=============================================================================
1183 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1185 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1190 //=============================================================================
1194 //=============================================================================
1196 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1198 // Create MeshEditor
1199 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );
1200 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1202 // Update Python script
1203 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1205 return aMesh._retn();
1208 //=============================================================================
1210 * Export in different formats
1212 //=============================================================================
1214 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1216 return _impl->HasDuplicatedGroupNamesMED();
1219 static void PrepareForWriting (const char* file)
1221 TCollection_AsciiString aFullName ((char*)file);
1222 OSD_Path aPath (aFullName);
1223 OSD_File aFile (aPath);
1224 if (aFile.Exists()) {
1225 // existing filesystem node
1226 if (aFile.KindOfFile() == OSD_FILE) {
1227 if (aFile.IsWriteable()) {
1230 if (aFile.Failed()) {
1231 TCollection_AsciiString msg ("File ");
1232 msg += aFullName + " cannot be replaced.";
1233 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1236 TCollection_AsciiString msg ("File ");
1237 msg += aFullName + " cannot be overwritten.";
1238 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1241 TCollection_AsciiString msg ("Location ");
1242 msg += aFullName + " is not a file.";
1243 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1246 // nonexisting file; check if it can be created
1248 aFile.Build(OSD_WriteOnly, OSD_Protection());
1249 if (aFile.Failed()) {
1250 TCollection_AsciiString msg ("You cannot create the file ");
1251 msg += aFullName + ". Check the directory existance and access rights.";
1252 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1260 void SMESH_Mesh_i::ExportToMED (const char* file,
1261 CORBA::Boolean auto_groups,
1262 SMESH::MED_VERSION theVersion)
1263 throw(SALOME::SALOME_Exception)
1265 Unexpect aCatch(SALOME_SalomeException);
1267 // Update Python script
1268 TPythonDump() << _this() << ".ExportToMED( '"
1269 << file << "', " << auto_groups << ", " << theVersion << " )";
1272 PrepareForWriting(file);
1273 char* aMeshName = "Mesh";
1274 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1275 if ( !aStudy->_is_nil() ) {
1276 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1277 if ( !aMeshSO->_is_nil() ) {
1278 aMeshName = aMeshSO->GetName();
1280 //SCRUTE(aMeshName);
1281 //SCRUTE(aMeshSO->GetID());
1283 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1284 if ( !aStudy->GetProperties()->IsLocked() )
1286 SALOMEDS::GenericAttribute_var anAttr;
1287 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1288 SALOMEDS::AttributeExternalFileDef_var aFileName;
1289 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1290 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1291 ASSERT(!aFileName->_is_nil());
1292 aFileName->SetValue(file);
1293 SALOMEDS::AttributeFileType_var aFileType;
1294 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1295 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1296 ASSERT(!aFileType->_is_nil());
1297 aFileType->SetValue("FICHIERMED");
1301 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1304 void SMESH_Mesh_i::ExportMED (const char* file,
1305 CORBA::Boolean auto_groups)
1306 throw(SALOME::SALOME_Exception)
1308 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1311 void SMESH_Mesh_i::ExportDAT (const char *file)
1312 throw(SALOME::SALOME_Exception)
1314 Unexpect aCatch(SALOME_SalomeException);
1316 // Update Python script
1317 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1320 PrepareForWriting(file);
1321 _impl->ExportDAT(file);
1324 void SMESH_Mesh_i::ExportUNV (const char *file)
1325 throw(SALOME::SALOME_Exception)
1327 Unexpect aCatch(SALOME_SalomeException);
1329 // Update Python script
1330 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1333 PrepareForWriting(file);
1334 _impl->ExportUNV(file);
1337 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1338 throw(SALOME::SALOME_Exception)
1340 Unexpect aCatch(SALOME_SalomeException);
1342 // Update Python script
1343 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1346 PrepareForWriting(file);
1347 _impl->ExportSTL(file, isascii);
1350 //=============================================================================
1354 //=============================================================================
1356 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1358 Unexpect aCatch(SALOME_SalomeException);
1359 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1360 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1361 return aMesh._retn();
1364 //=============================================================================
1368 //=============================================================================
1369 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1371 Unexpect aCatch(SALOME_SalomeException);
1372 return _impl->NbNodes();
1375 //=============================================================================
1379 //=============================================================================
1380 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1382 Unexpect aCatch(SALOME_SalomeException);
1383 return NbEdges() + NbFaces() + NbVolumes();
1386 //=============================================================================
1390 //=============================================================================
1391 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1393 Unexpect aCatch(SALOME_SalomeException);
1394 return _impl->NbEdges();
1397 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1398 throw(SALOME::SALOME_Exception)
1400 Unexpect aCatch(SALOME_SalomeException);
1401 return _impl->NbEdges( (::SMESH_Mesh::ElementOrder) order);
1404 //=============================================================================
1408 //=============================================================================
1409 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1411 Unexpect aCatch(SALOME_SalomeException);
1412 return _impl->NbFaces();
1415 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1417 Unexpect aCatch(SALOME_SalomeException);
1418 return _impl->NbTriangles();
1421 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1423 Unexpect aCatch(SALOME_SalomeException);
1424 return _impl->NbQuadrangles();
1427 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1429 Unexpect aCatch(SALOME_SalomeException);
1430 return _impl->NbPolygons();
1433 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1434 throw(SALOME::SALOME_Exception)
1436 Unexpect aCatch(SALOME_SalomeException);
1437 return _impl->NbFaces( (::SMESH_Mesh::ElementOrder) order);
1440 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1441 throw(SALOME::SALOME_Exception)
1443 Unexpect aCatch(SALOME_SalomeException);
1444 return _impl->NbTriangles( (::SMESH_Mesh::ElementOrder) order);
1447 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1448 throw(SALOME::SALOME_Exception)
1450 Unexpect aCatch(SALOME_SalomeException);
1451 return _impl->NbQuadrangles( (::SMESH_Mesh::ElementOrder) order);
1454 //=============================================================================
1458 //=============================================================================
1459 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1461 Unexpect aCatch(SALOME_SalomeException);
1462 return _impl->NbVolumes();
1465 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1467 Unexpect aCatch(SALOME_SalomeException);
1468 return _impl->NbTetras();
1471 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1473 Unexpect aCatch(SALOME_SalomeException);
1474 return _impl->NbHexas();
1477 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1479 Unexpect aCatch(SALOME_SalomeException);
1480 return _impl->NbPyramids();
1483 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1485 Unexpect aCatch(SALOME_SalomeException);
1486 return _impl->NbPrisms();
1489 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1491 Unexpect aCatch(SALOME_SalomeException);
1492 return _impl->NbPolyhedrons();
1495 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1496 throw(SALOME::SALOME_Exception)
1498 Unexpect aCatch(SALOME_SalomeException);
1499 return _impl->NbVolumes( (::SMESH_Mesh::ElementOrder) order);
1502 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1503 throw(SALOME::SALOME_Exception)
1505 Unexpect aCatch(SALOME_SalomeException);
1506 return _impl->NbTetras( (::SMESH_Mesh::ElementOrder) order);
1509 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1510 throw(SALOME::SALOME_Exception)
1512 Unexpect aCatch(SALOME_SalomeException);
1513 return _impl->NbHexas( (::SMESH_Mesh::ElementOrder) order);
1516 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1517 throw(SALOME::SALOME_Exception)
1519 Unexpect aCatch(SALOME_SalomeException);
1520 return _impl->NbPyramids( (::SMESH_Mesh::ElementOrder) order);
1523 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1524 throw(SALOME::SALOME_Exception)
1526 Unexpect aCatch(SALOME_SalomeException);
1527 return _impl->NbPrisms( (::SMESH_Mesh::ElementOrder) order);
1530 //=============================================================================
1534 //=============================================================================
1535 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1537 Unexpect aCatch(SALOME_SalomeException);
1538 return _impl->NbSubMesh();
1541 //=============================================================================
1545 //=============================================================================
1546 char* SMESH_Mesh_i::Dump()
1548 std::ostringstream os;
1550 return CORBA::string_dup( os.str().c_str() );
1553 //=============================================================================
1557 //=============================================================================
1558 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1560 // SMESH::long_array_var aResult = new SMESH::long_array();
1561 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1562 // int aMinId = aSMESHDS_Mesh->MinElementID();
1563 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1565 // aResult->length(aMaxId - aMinId + 1);
1567 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1568 // aResult[i++] = id;
1570 // return aResult._retn();
1572 return GetElementsId();
1575 //=============================================================================
1579 //=============================================================================
1581 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1582 throw (SALOME::SALOME_Exception)
1584 Unexpect aCatch(SALOME_SalomeException);
1585 MESSAGE("SMESH_Mesh_i::GetElementsId");
1586 SMESH::long_array_var aResult = new SMESH::long_array();
1587 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1589 if ( aSMESHDS_Mesh == NULL )
1590 return aResult._retn();
1592 long nbElements = NbElements();
1593 aResult->length( nbElements );
1594 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1595 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1596 aResult[i] = anIt->next()->GetID();
1598 return aResult._retn();
1602 //=============================================================================
1606 //=============================================================================
1608 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1609 throw (SALOME::SALOME_Exception)
1611 Unexpect aCatch(SALOME_SalomeException);
1612 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1613 SMESH::long_array_var aResult = new SMESH::long_array();
1614 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1616 if ( aSMESHDS_Mesh == NULL )
1617 return aResult._retn();
1619 long nbElements = NbElements();
1621 // No sense in returning ids of elements along with ids of nodes:
1622 // when theElemType == SMESH::ALL, return node ids only if
1623 // there are no elements
1624 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1625 return GetNodesId();
1627 aResult->length( nbElements );
1631 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1632 while ( i < nbElements && anIt->more() ) {
1633 const SMDS_MeshElement* anElem = anIt->next();
1634 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1635 aResult[i++] = anElem->GetID();
1638 aResult->length( i );
1640 return aResult._retn();
1643 //=============================================================================
1647 //=============================================================================
1649 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1650 throw (SALOME::SALOME_Exception)
1652 Unexpect aCatch(SALOME_SalomeException);
1653 MESSAGE("SMESH_subMesh_i::GetNodesId");
1654 SMESH::long_array_var aResult = new SMESH::long_array();
1655 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1657 if ( aSMESHDS_Mesh == NULL )
1658 return aResult._retn();
1660 long nbNodes = NbNodes();
1661 aResult->length( nbNodes );
1662 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1663 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1664 aResult[i] = anIt->next()->GetID();
1666 return aResult._retn();
1669 //=============================================================================
1673 //=============================================================================
1675 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1676 throw (SALOME::SALOME_Exception)
1678 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1682 //=============================================================================
1684 * Returns ID of elements for given submesh
1686 //=============================================================================
1687 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1688 throw (SALOME::SALOME_Exception)
1690 SMESH::long_array_var aResult = new SMESH::long_array();
1692 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1693 if(!SM) return aResult._retn();
1695 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1696 if(!SDSM) return aResult._retn();
1698 aResult->length(SDSM->NbElements());
1700 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1702 while ( eIt->more() ) {
1703 aResult[i++] = eIt->next()->GetID();
1706 return aResult._retn();
1710 //=============================================================================
1712 * Returns ID of nodes for given submesh
1713 * If param all==true - returns all nodes, else -
1714 * returns only nodes on shapes.
1716 //=============================================================================
1717 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1718 throw (SALOME::SALOME_Exception)
1720 SMESH::long_array_var aResult = new SMESH::long_array();
1722 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1723 if(!SM) return aResult._retn();
1725 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1726 if(!SDSM) return aResult._retn();
1728 map<int,const SMDS_MeshElement*> theElems;
1729 if( !all || (SDSM->NbElements()==0 && SDSM->NbNodes()==1) ) {
1730 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1731 while ( nIt->more() ) {
1732 const SMDS_MeshNode* elem = nIt->next();
1733 theElems.insert( make_pair(elem->GetID(),elem) );
1736 else { // all nodes of submesh elements
1737 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1738 while ( eIt->more() ) {
1739 const SMDS_MeshElement* anElem = eIt->next();
1740 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1741 while ( nIt->more() ) {
1742 const SMDS_MeshElement* elem = nIt->next();
1743 theElems.insert( make_pair(elem->GetID(),elem) );
1748 aResult->length(theElems.size());
1749 map<int, const SMDS_MeshElement * >::iterator itElem;
1751 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1752 aResult[i++] = (*itElem).first;
1754 return aResult._retn();
1758 //=============================================================================
1760 * Returns type of elements for given submesh
1762 //=============================================================================
1763 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
1764 throw (SALOME::SALOME_Exception)
1766 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1767 if(!SM) return SMESH::ALL;
1769 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1770 if(!SDSM) return SMESH::ALL;
1772 if(SDSM->NbElements()==0)
1773 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
1775 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1776 const SMDS_MeshElement* anElem = eIt->next();
1777 return ( SMESH::ElementType ) anElem->GetType();
1781 //=============================================================================
1785 //=============================================================================
1787 CORBA::Long SMESH_Mesh_i::GetMeshPtr()
1789 return CORBA::Long(size_t(_impl));
1793 //=============================================================================
1795 * Get XYZ coordinates of node as list of double
1796 * If there is not node for given ID - returns empty list
1798 //=============================================================================
1800 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
1802 SMESH::double_array_var aResult = new SMESH::double_array();
1803 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1804 if ( aSMESHDS_Mesh == NULL )
1805 return aResult._retn();
1808 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1810 return aResult._retn();
1814 aResult[0] = aNode->X();
1815 aResult[1] = aNode->Y();
1816 aResult[2] = aNode->Z();
1817 return aResult._retn();
1821 //=============================================================================
1823 * For given node returns list of IDs of inverse elements
1824 * If there is not node for given ID - returns empty list
1826 //=============================================================================
1828 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
1830 SMESH::long_array_var aResult = new SMESH::long_array();
1831 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1832 if ( aSMESHDS_Mesh == NULL )
1833 return aResult._retn();
1836 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1838 return aResult._retn();
1840 // find inverse elements
1841 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
1842 TColStd_SequenceOfInteger IDs;
1843 while(eIt->more()) {
1844 const SMDS_MeshElement* elem = eIt->next();
1845 IDs.Append(elem->GetID());
1847 if(IDs.Length()>0) {
1848 aResult->length(IDs.Length());
1850 for(; i<=IDs.Length(); i++) {
1851 aResult[i-1] = IDs.Value(i);
1854 return aResult._retn();
1858 //=============================================================================
1860 * If given element is node returns IDs of shape from position
1861 * If there is not node for given ID - returns -1
1863 //=============================================================================
1865 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
1867 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1868 if ( aSMESHDS_Mesh == NULL )
1872 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1874 SMDS_PositionPtr pos = aNode->GetPosition();
1878 return pos->GetShapeId();
1885 //=============================================================================
1887 * For given element returns ID of result shape after
1888 * ::FindShape() from SMESH_MeshEditor
1889 * If there is not element for given ID - returns -1
1891 //=============================================================================
1893 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
1895 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1896 if ( aSMESHDS_Mesh == NULL )
1899 // try to find element
1900 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1904 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
1905 ::SMESH_MeshEditor aMeshEditor(_impl);
1906 int index = aMeshEditor.FindShape( elem );
1914 //=============================================================================
1916 * Returns number of nodes for given element
1917 * If there is not element for given ID - returns -1
1919 //=============================================================================
1921 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
1923 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1924 if ( aSMESHDS_Mesh == NULL ) return -1;
1925 // try to find element
1926 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1927 if(!elem) return -1;
1928 return elem->NbNodes();
1932 //=============================================================================
1934 * Returns ID of node by given index for given element
1935 * If there is not element for given ID - returns -1
1936 * If there is not node for given index - returns -2
1938 //=============================================================================
1940 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
1942 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1943 if ( aSMESHDS_Mesh == NULL ) return -1;
1944 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1945 if(!elem) return -1;
1946 if( index>=elem->NbNodes() || index<0 ) return -1;
1947 return elem->GetNode(index)->GetID();
1951 //=============================================================================
1953 * Returns true if given node is medium node
1954 * in given quadratic element
1956 //=============================================================================
1958 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
1960 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1961 if ( aSMESHDS_Mesh == NULL ) return false;
1963 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
1964 if(!aNode) return false;
1965 // try to find element
1966 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
1967 if(!elem) return false;
1969 return elem->IsMediumNode(aNode);
1973 //=============================================================================
1975 * Returns true if given node is medium node
1976 * in one of quadratic elements
1978 //=============================================================================
1980 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
1981 SMESH::ElementType theElemType)
1983 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1984 if ( aSMESHDS_Mesh == NULL ) return false;
1987 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
1988 if(!aNode) return false;
1990 SMESH_MesherHelper aHelper( *(_impl) );
1992 SMDSAbs_ElementType aType;
1993 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
1994 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
1995 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
1996 else aType = SMDSAbs_All;
1998 return aHelper.IsMedium(aNode,aType);
2002 //=============================================================================
2004 * Returns number of edges for given element
2006 //=============================================================================
2008 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2010 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2011 if ( aSMESHDS_Mesh == NULL ) return -1;
2012 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2013 if(!elem) return -1;
2014 return elem->NbEdges();
2018 //=============================================================================
2020 * Returns number of faces for given element
2022 //=============================================================================
2024 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2026 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2027 if ( aSMESHDS_Mesh == NULL ) return -1;
2028 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2029 if(!elem) return -1;
2030 return elem->NbFaces();
2034 //=============================================================================
2036 * Returns true if given element is polygon
2038 //=============================================================================
2040 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2042 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2043 if ( aSMESHDS_Mesh == NULL ) return false;
2044 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2045 if(!elem) return false;
2046 return elem->IsPoly();
2050 //=============================================================================
2052 * Returns true if given element is quadratic
2054 //=============================================================================
2056 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2058 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2059 if ( aSMESHDS_Mesh == NULL ) return false;
2060 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2061 if(!elem) return false;
2062 return elem->IsQuadratic();
2066 //=============================================================================
2068 * Returns bary center for given element
2070 //=============================================================================
2072 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2074 SMESH::double_array_var aResult = new SMESH::double_array();
2075 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2076 if ( aSMESHDS_Mesh == NULL )
2077 return aResult._retn();
2079 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2081 return aResult._retn();
2083 if(elem->GetType()==SMDSAbs_Volume) {
2084 // use SMDS_VolumeTool
2085 SMDS_VolumeTool aTool;
2086 if(aTool.Set(elem)) {
2087 double x=0., y=0., z=0.;
2088 if(aTool.GetBaryCenter(x,y,z)) {
2098 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2100 double x=0., y=0., z=0.;
2101 for(; anIt->more(); ) {
2103 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2117 return aResult._retn();
2121 //=============================================================================
2125 //=============================================================================
2126 void SMESH_Mesh_i::CreateGroupServants()
2128 // Create group servants, if any groups were imported
2129 list<int> aGroupIds = _impl->GetGroupIds();
2130 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
2131 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
2133 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2134 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2135 aGroupImpl->Register();
2136 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2138 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
2139 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
2141 // register CORBA object for persistence
2142 int nextId = _gen_i->RegisterObject( aGroup );
2143 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);