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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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"
54 #include <OSD_Path.hxx>
55 #include <OSD_File.hxx>
56 #include <OSD_Directory.hxx>
57 #include <OSD_Protection.hxx>
58 #include <TColStd_MapOfInteger.hxx>
59 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
60 #include <TColStd_SequenceOfInteger.hxx>
61 #include "TCollection_AsciiString.hxx"
69 static int MYDEBUG = 0;
71 static int MYDEBUG = 0;
75 using SMESH::TPythonDump;
77 int SMESH_Mesh_i::myIdGenerator = 0;
81 //=============================================================================
85 //=============================================================================
87 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
90 : SALOME::GenericObj_i( thePOA )
92 INFOS("SMESH_Mesh_i");
95 _id = myIdGenerator++;
97 thePOA->activate_object( this );
100 //=============================================================================
104 //=============================================================================
106 SMESH_Mesh_i::~SMESH_Mesh_i()
108 INFOS("~SMESH_Mesh_i");
109 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
110 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
111 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
114 // this method is colled from destructor of group (PAL6331)
115 //_impl->RemoveGroup( aGroup->GetLocalID() );
123 //=============================================================================
127 * Associates <this> mesh with <theShape> and puts a reference
128 * to <theShape> into the current study;
129 * the previous shape is substituted by the new one.
131 //=============================================================================
133 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
134 throw (SALOME::SALOME_Exception)
136 Unexpect aCatch(SALOME_SalomeException);
138 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
140 catch(SALOME_Exception & S_ex) {
141 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
145 //=======================================================================
146 //function : GetShapeToMesh
148 //=======================================================================
150 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
151 throw (SALOME::SALOME_Exception)
153 Unexpect aCatch(SALOME_SalomeException);
154 GEOM::GEOM_Object_var aShapeObj;
156 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
158 aShapeObj = _gen_i->ShapeToGeomObject( S );
160 catch(SALOME_Exception & S_ex) {
161 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
163 return aShapeObj._retn();
166 //=============================================================================
170 //=============================================================================
172 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
174 SMESH::DriverMED_ReadStatus res;
177 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
178 res = SMESH::DRS_OK; break;
179 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
180 res = SMESH::DRS_EMPTY; break;
181 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
182 res = SMESH::DRS_WARN_RENUMBER; break;
183 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
184 res = SMESH::DRS_WARN_SKIP_ELEM; break;
185 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
187 res = SMESH::DRS_FAIL; break;
192 //=============================================================================
196 * Imports mesh data from MED file
198 //=============================================================================
200 SMESH::DriverMED_ReadStatus
201 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
202 throw ( SALOME::SALOME_Exception )
204 Unexpect aCatch(SALOME_SalomeException);
207 status = importMEDFile( theFileName, theMeshName );
209 catch( SALOME_Exception& S_ex ) {
210 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
213 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
216 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
217 if ( !aStudy->_is_nil() ) {
218 // publishing of the groups in the study (sub-meshes are out of scope of MED import)
219 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
220 for (; it != _mapGroups.end(); it++ ) {
221 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
222 _gen_i->PublishGroup( aStudy, _this(), aGroup,
223 GEOM::GEOM_Object::_nil(), aGroup->GetName());
226 return ConvertDriverMEDReadStatus(status);
229 //=============================================================================
233 * Imports mesh data from MED file
235 //=============================================================================
237 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
238 throw ( SALOME::SALOME_Exception )
240 // Read mesh with name = <theMeshName> into SMESH_Mesh
241 _impl->UNVToMesh( theFileName );
243 CreateGroupServants();
245 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
246 if ( !aStudy->_is_nil() ) {
247 // publishing of the groups in the study (sub-meshes are out of scope of UNV import)
248 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
249 for (; it != _mapGroups.end(); it++ ) {
250 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
251 _gen_i->PublishGroup( aStudy, _this(), aGroup,
252 GEOM::GEOM_Object::_nil(), aGroup->GetName());
258 //=============================================================================
262 * Imports mesh data from STL file
264 //=============================================================================
265 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
266 throw ( SALOME::SALOME_Exception )
268 // Read mesh with name = <theMeshName> into SMESH_Mesh
269 _impl->STLToMesh( theFileName );
274 //=============================================================================
278 * Imports mesh data from MED file
280 //=============================================================================
282 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
284 // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
285 int status = _impl->MEDToMesh( theFileName, theMeshName );
286 CreateGroupServants();
291 //=============================================================================
295 //=============================================================================
297 static SMESH::Hypothesis_Status ConvertHypothesisStatus
298 (SMESH_Hypothesis::Hypothesis_Status theStatus)
300 SMESH::Hypothesis_Status res;
303 case SMESH_Hypothesis::HYP_OK:
304 res = SMESH::HYP_OK; break;
305 case SMESH_Hypothesis::HYP_MISSING:
306 res = SMESH::HYP_MISSING; break;
307 case SMESH_Hypothesis::HYP_CONCURENT:
308 res = SMESH::HYP_CONCURENT; break;
309 case SMESH_Hypothesis::HYP_BAD_PARAMETER:
310 res = SMESH::HYP_BAD_PARAMETER; break;
311 case SMESH_Hypothesis::HYP_INCOMPATIBLE:
312 res = SMESH::HYP_INCOMPATIBLE; break;
313 case SMESH_Hypothesis::HYP_NOTCONFORM:
314 res = SMESH::HYP_NOTCONFORM; break;
315 case SMESH_Hypothesis::HYP_ALREADY_EXIST:
316 res = SMESH::HYP_ALREADY_EXIST; break;
317 case SMESH_Hypothesis::HYP_BAD_DIM:
318 res = SMESH::HYP_BAD_DIM; break;
319 case SMESH_Hypothesis::HYP_BAD_SUBSHAPE:
320 res = SMESH::HYP_BAD_SUBSHAPE; break;
322 res = SMESH::HYP_UNKNOWN_FATAL;
327 //=============================================================================
331 * calls internal addHypothesis() and then adds a reference to <anHyp> under
332 * the SObject actually having a reference to <aSubShape>.
333 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
335 //=============================================================================
337 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
338 SMESH::SMESH_Hypothesis_ptr anHyp)
339 throw(SALOME::SALOME_Exception)
341 Unexpect aCatch(SALOME_SalomeException);
342 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
344 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
345 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
346 aSubShapeObject, anHyp );
348 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
350 // Update Python script
351 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
352 << aSubShapeObject << ", " << anHyp << " )";
354 return ConvertHypothesisStatus(status);
357 //=============================================================================
361 //=============================================================================
363 SMESH_Hypothesis::Hypothesis_Status
364 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
365 SMESH::SMESH_Hypothesis_ptr anHyp)
367 if(MYDEBUG) MESSAGE("addHypothesis");
369 if (CORBA::is_nil(aSubShapeObject))
370 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
373 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
374 if (CORBA::is_nil(myHyp))
375 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
378 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
381 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
382 int hypId = myHyp->GetId();
383 status = _impl->AddHypothesis(myLocSubShape, hypId);
384 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
385 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
386 // assure there is a corresponding submesh
387 if ( !_impl->IsMainShape( myLocSubShape )) {
388 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
389 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
390 createSubMesh( aSubShapeObject );
394 catch(SALOME_Exception & S_ex)
396 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
401 //=============================================================================
405 //=============================================================================
407 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
408 SMESH::SMESH_Hypothesis_ptr anHyp)
409 throw(SALOME::SALOME_Exception)
411 Unexpect aCatch(SALOME_SalomeException);
412 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
414 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
415 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
416 aSubShapeObject, anHyp );
418 // Update Python script
419 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
420 << aSubShapeObject << ", " << anHyp << " )";
422 return ConvertHypothesisStatus(status);
425 //=============================================================================
429 //=============================================================================
431 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
432 SMESH::SMESH_Hypothesis_ptr anHyp)
434 if(MYDEBUG) MESSAGE("removeHypothesis()");
435 // **** proposer liste de subShape (selection multiple)
437 if (CORBA::is_nil(aSubShapeObject))
438 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
441 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
442 if (CORBA::is_nil(myHyp))
443 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
446 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
449 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
450 int hypId = myHyp->GetId();
451 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
452 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
453 _mapHypo.erase( hypId );
455 catch(SALOME_Exception & S_ex)
457 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
462 //=============================================================================
466 //=============================================================================
468 SMESH::ListOfHypothesis *
469 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
470 throw(SALOME::SALOME_Exception)
472 Unexpect aCatch(SALOME_SalomeException);
473 if (MYDEBUG) MESSAGE("GetHypothesisList");
474 if (CORBA::is_nil(aSubShapeObject))
475 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
478 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
481 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
482 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
483 int i = 0, n = aLocalList.size();
486 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
487 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
488 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
489 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
494 catch(SALOME_Exception & S_ex) {
495 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
498 return aList._retn();
501 //=============================================================================
505 //=============================================================================
506 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
507 const char* theName )
508 throw(SALOME::SALOME_Exception)
510 Unexpect aCatch(SALOME_SalomeException);
511 MESSAGE("SMESH_Mesh_i::GetSubMesh");
512 if (CORBA::is_nil(aSubShapeObject))
513 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
516 SMESH::SMESH_subMesh_var subMesh;
517 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
519 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
521 //Get or Create the SMESH_subMesh object implementation
523 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
524 subMesh = getSubMesh( subMeshId );
526 // create a new subMesh object servant if there is none for the shape
527 if ( subMesh->_is_nil() )
528 subMesh = createSubMesh( aSubShapeObject );
530 if ( _gen_i->CanPublishInStudy( subMesh )) {
531 SALOMEDS::SObject_var aSO =
532 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
533 subMesh, aSubShapeObject, theName );
534 if ( !aSO->_is_nil()) {
535 // Update Python script
536 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
537 << aSubShapeObject << ", '" << theName << "' )";
541 catch(SALOME_Exception & S_ex) {
542 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
544 return subMesh._retn();
547 //=============================================================================
551 //=============================================================================
553 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
554 throw (SALOME::SALOME_Exception)
556 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
557 if ( theSubMesh->_is_nil() )
560 GEOM::GEOM_Object_var aSubShapeObject;
561 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
562 if ( !aStudy->_is_nil() ) {
563 // Remove submesh's SObject
564 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
565 if ( !anSO->_is_nil() ) {
566 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
567 SALOMEDS::SObject_var anObj, aRef;
568 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
569 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
571 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
573 // Update Python script
574 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
578 removeSubMesh( theSubMesh, aSubShapeObject.in() );
581 //=============================================================================
585 //=============================================================================
586 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
587 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
589 switch (theElemType) {
594 CASE2STRING( VOLUME );
600 //=============================================================================
604 //=============================================================================
606 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
607 const char* theName )
608 throw(SALOME::SALOME_Exception)
610 Unexpect aCatch(SALOME_SalomeException);
611 SMESH::SMESH_Group_var aNewGroup =
612 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
614 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
615 SALOMEDS::SObject_var aSO =
616 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
617 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
618 if ( !aSO->_is_nil()) {
619 // Update Python script
620 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
621 << ElementTypeString(theElemType) << ", '" << theName << "' )";
624 return aNewGroup._retn();
628 //=============================================================================
632 //=============================================================================
633 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
635 GEOM::GEOM_Object_ptr theGeomObj)
636 throw(SALOME::SALOME_Exception)
638 Unexpect aCatch(SALOME_SalomeException);
639 SMESH::SMESH_GroupOnGeom_var aNewGroup;
641 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
642 if ( !aShape.IsNull() ) {
643 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
644 ( createGroup( theElemType, theName, aShape ));
645 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
646 SALOMEDS::SObject_var aSO =
647 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
648 aNewGroup, theGeomObj, theName);
649 if ( !aSO->_is_nil()) {
650 // Update Python script
651 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
652 << ElementTypeString(theElemType) << ", '" << theName << "', "
653 << theGeomObj << " )";
658 return aNewGroup._retn();
661 //=============================================================================
665 //=============================================================================
667 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
668 throw (SALOME::SALOME_Exception)
670 if ( theGroup->_is_nil() )
673 SMESH_GroupBase_i* aGroup =
674 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
678 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
679 if ( !aStudy->_is_nil() ) {
680 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
682 if ( !aGroupSO->_is_nil() ) {
683 // Update Python script
684 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
686 // Remove group's SObject
687 aStudy->NewBuilder()->RemoveObject( aGroupSO );
691 // Remove the group from SMESH data structures
692 removeGroup( aGroup->GetLocalID() );
695 //=============================================================================
696 /*! RemoveGroupWithContents
697 * Remove group with its contents
699 //=============================================================================
700 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
701 throw (SALOME::SALOME_Exception)
703 if ( theGroup->_is_nil() )
706 SMESH_GroupBase_i* aGroup =
707 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
711 SMESH::long_array_var anIds = aGroup->GetListOfID();
712 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
714 // Update Python script
715 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
718 if ( aGroup->GetType() == SMESH::NODE )
719 aMeshEditor->RemoveNodes( anIds );
721 aMeshEditor->RemoveElements( anIds );
724 RemoveGroup( theGroup );
726 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
727 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
728 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
732 //================================================================================
734 * \brief Get the list of groups existing in the mesh
735 * \retval SMESH::ListOfGroups * - list of groups
737 //================================================================================
739 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
741 Unexpect aCatch(SALOME_SalomeException);
742 if (MYDEBUG) MESSAGE("GetGroups");
744 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
746 TPythonDump aPythonDump;
750 aList->length( _mapGroups.size() );
752 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
753 for ( ; it != _mapGroups.end(); it++ ) {
754 if ( CORBA::is_nil( it->second )) continue;
755 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
757 if (i > 1) aPythonDump << ", ";
758 aPythonDump << it->second;
762 catch(SALOME_Exception & S_ex) {
763 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
766 // Update Python script
767 aPythonDump << " ] = " << _this() << ".GetGroups()";
769 return aList._retn();
772 //=============================================================================
774 * New group is created. All mesh elements that are
775 * present in initial groups are added to the new one
777 //=============================================================================
778 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
779 SMESH::SMESH_GroupBase_ptr theGroup2,
780 const char* theName )
781 throw (SALOME::SALOME_Exception)
785 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
786 theGroup1->GetType() != theGroup2->GetType() )
787 return SMESH::SMESH_Group::_nil();
790 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
791 if ( aResGrp->_is_nil() )
792 return SMESH::SMESH_Group::_nil();
794 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
795 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
797 TColStd_MapOfInteger aResMap;
799 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
800 aResMap.Add( anIds1[ i1 ] );
802 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
803 aResMap.Add( anIds2[ i2 ] );
805 SMESH::long_array_var aResIds = new SMESH::long_array;
806 aResIds->length( aResMap.Extent() );
809 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
810 for( ; anIter.More(); anIter.Next() )
811 aResIds[ resI++ ] = anIter.Key();
813 aResGrp->Add( aResIds );
815 // Clear python lines, created by CreateGroup() and Add()
816 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
817 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
818 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
820 // Update Python script
821 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
822 << theGroup1 << ", " << theGroup2 << ", '"
825 return aResGrp._retn();
829 return SMESH::SMESH_Group::_nil();
833 //=============================================================================
835 * New group is created. All mesh elements that are
836 * present in both initial groups are added to the new one.
838 //=============================================================================
839 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
840 SMESH::SMESH_GroupBase_ptr theGroup2,
841 const char* theName )
842 throw (SALOME::SALOME_Exception)
844 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
845 theGroup1->GetType() != theGroup2->GetType() )
846 return SMESH::SMESH_Group::_nil();
848 // Create Intersection
849 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
850 if ( aResGrp->_is_nil() )
853 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
854 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
856 TColStd_MapOfInteger aMap1;
858 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
859 aMap1.Add( anIds1[ i1 ] );
861 TColStd_SequenceOfInteger aSeq;
863 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
864 if ( aMap1.Contains( anIds2[ i2 ] ) )
865 aSeq.Append( anIds2[ i2 ] );
867 SMESH::long_array_var aResIds = new SMESH::long_array;
868 aResIds->length( aSeq.Length() );
870 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
871 aResIds[ resI ] = aSeq( resI + 1 );
873 aResGrp->Add( aResIds );
875 // Clear python lines, created by CreateGroup() and Add()
876 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
877 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
878 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
880 // Update Python script
881 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
882 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
884 return aResGrp._retn();
887 //=============================================================================
889 * New group is created. All mesh elements that are present in
890 * main group but do not present in tool group are added to the new one
892 //=============================================================================
893 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
894 SMESH::SMESH_GroupBase_ptr theGroup2,
895 const char* theName )
896 throw (SALOME::SALOME_Exception)
898 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
899 theGroup1->GetType() != theGroup2->GetType() )
900 return SMESH::SMESH_Group::_nil();
903 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
904 if ( aResGrp->_is_nil() )
907 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
908 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
910 TColStd_MapOfInteger aMap2;
912 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
913 aMap2.Add( anIds2[ i2 ] );
916 TColStd_SequenceOfInteger aSeq;
917 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
918 if ( !aMap2.Contains( anIds1[ i1 ] ) )
919 aSeq.Append( anIds1[ i1 ] );
921 SMESH::long_array_var aResIds = new SMESH::long_array;
922 aResIds->length( aSeq.Length() );
924 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
925 aResIds[ resI ] = aSeq( resI + 1 );
927 aResGrp->Add( aResIds );
929 // Clear python lines, created by CreateGroup() and Add()
930 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
931 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
932 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
934 // Update Python script
935 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
936 << theGroup1 << ", " << theGroup2 << ", '"
939 return aResGrp._retn();
942 //=============================================================================
946 //=============================================================================
948 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
950 if(MYDEBUG) MESSAGE( "createSubMesh" );
951 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
953 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
954 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
955 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
956 SMESH::SMESH_subMesh_var subMesh
957 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
959 _mapSubMesh[subMeshId] = mySubMesh;
960 _mapSubMesh_i[subMeshId] = subMeshServant;
961 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
963 // register CORBA object for persistence
964 int nextId = _gen_i->RegisterObject( subMesh );
965 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
967 return subMesh._retn();
970 //=======================================================================
971 //function : getSubMesh
973 //=======================================================================
975 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
977 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
978 if ( it == _mapSubMeshIor.end() )
979 return SMESH::SMESH_subMesh::_nil();
981 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
985 //=============================================================================
989 //=============================================================================
991 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
992 GEOM::GEOM_Object_ptr theSubShapeObject )
994 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
995 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
999 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1000 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1001 removeHypothesis( theSubShapeObject, aHypList[i] );
1004 catch( const SALOME::SALOME_Exception& ) {
1005 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1008 int subMeshId = theSubMesh->GetId();
1010 _mapSubMesh.erase(subMeshId);
1011 _mapSubMesh_i.erase(subMeshId);
1012 _mapSubMeshIor.erase(subMeshId);
1013 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1016 //=============================================================================
1020 //=============================================================================
1022 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1023 const char* theName,
1024 const TopoDS_Shape& theShape )
1027 SMESH::SMESH_GroupBase_var aGroup;
1028 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1029 SMESH_GroupBase_i* aGroupImpl;
1030 if ( !theShape.IsNull() )
1031 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1033 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1035 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1036 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1037 aGroupImpl->Register();
1038 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1040 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1041 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1043 // register CORBA object for persistence
1044 int nextId = _gen_i->RegisterObject( aGroup );
1045 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1047 return aGroup._retn();
1050 //=============================================================================
1052 * SMESH_Mesh_i::removeGroup
1054 * Should be called by ~SMESH_Group_i()
1056 //=============================================================================
1058 void SMESH_Mesh_i::removeGroup( const int theId )
1060 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1061 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1062 _mapGroups.erase( theId );
1063 _impl->RemoveGroup( theId );
1068 //=============================================================================
1072 //=============================================================================
1074 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1075 throw(SALOME::SALOME_Exception)
1077 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1079 SMESH::log_array_var aLog;
1081 list < SMESHDS_Command * >logDS = _impl->GetLog();
1082 aLog = new SMESH::log_array;
1084 int lg = logDS.size();
1087 list < SMESHDS_Command * >::iterator its = logDS.begin();
1088 while(its != logDS.end()){
1089 SMESHDS_Command *com = *its;
1090 int comType = com->GetType();
1092 int lgcom = com->GetNumber();
1094 const list < int >&intList = com->GetIndexes();
1095 int inum = intList.size();
1097 list < int >::const_iterator ii = intList.begin();
1098 const list < double >&coordList = com->GetCoords();
1099 int rnum = coordList.size();
1101 list < double >::const_iterator ir = coordList.begin();
1102 aLog[indexLog].commandType = comType;
1103 aLog[indexLog].number = lgcom;
1104 aLog[indexLog].coords.length(rnum);
1105 aLog[indexLog].indexes.length(inum);
1106 for(int i = 0; i < rnum; i++){
1107 aLog[indexLog].coords[i] = *ir;
1108 //MESSAGE(" "<<i<<" "<<ir.Value());
1111 for(int i = 0; i < inum; i++){
1112 aLog[indexLog].indexes[i] = *ii;
1113 //MESSAGE(" "<<i<<" "<<ii.Value());
1122 catch(SALOME_Exception & S_ex){
1123 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1125 return aLog._retn();
1129 //=============================================================================
1133 //=============================================================================
1135 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1137 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1141 //=============================================================================
1145 //=============================================================================
1147 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1149 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1153 //=============================================================================
1157 //=============================================================================
1159 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1164 //=============================================================================
1168 //=============================================================================
1170 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1172 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1176 //=============================================================================
1180 //=============================================================================
1182 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1184 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1189 //=============================================================================
1193 //=============================================================================
1195 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1197 // Create MeshEditor
1198 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );
1199 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1201 // Update Python script
1202 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1204 return aMesh._retn();
1207 //=============================================================================
1209 * Export in different formats
1211 //=============================================================================
1213 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1215 return _impl->HasDuplicatedGroupNamesMED();
1218 static void PrepareForWriting (const char* file)
1220 TCollection_AsciiString aFullName ((char*)file);
1221 OSD_Path aPath (aFullName);
1222 OSD_File aFile (aPath);
1223 if (aFile.Exists()) {
1224 // existing filesystem node
1225 if (aFile.KindOfFile() == OSD_FILE) {
1226 if (aFile.IsWriteable()) {
1229 if (aFile.Failed()) {
1230 TCollection_AsciiString msg ("File ");
1231 msg += aFullName + " cannot be replaced.";
1232 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1235 TCollection_AsciiString msg ("File ");
1236 msg += aFullName + " cannot be overwritten.";
1237 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1240 TCollection_AsciiString msg ("Location ");
1241 msg += aFullName + " is not a file.";
1242 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1245 // nonexisting file; check if it can be created
1247 aFile.Build(OSD_WriteOnly, OSD_Protection());
1248 if (aFile.Failed()) {
1249 TCollection_AsciiString msg ("You cannot create the file ");
1250 msg += aFullName + ". Check the directory existance and access rights.";
1251 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1259 void SMESH_Mesh_i::ExportToMED (const char* file,
1260 CORBA::Boolean auto_groups,
1261 SMESH::MED_VERSION theVersion)
1262 throw(SALOME::SALOME_Exception)
1264 Unexpect aCatch(SALOME_SalomeException);
1266 // Update Python script
1267 TPythonDump() << _this() << ".ExportToMED( '"
1268 << file << "', " << auto_groups << ", " << theVersion << " )";
1271 PrepareForWriting(file);
1272 char* aMeshName = "Mesh";
1273 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1274 if ( !aStudy->_is_nil() ) {
1275 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1276 if ( !aMeshSO->_is_nil() ) {
1277 aMeshName = aMeshSO->GetName();
1279 //SCRUTE(aMeshName);
1280 //SCRUTE(aMeshSO->GetID());
1282 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1283 if ( !aStudy->GetProperties()->IsLocked() )
1285 SALOMEDS::GenericAttribute_var anAttr;
1286 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1287 SALOMEDS::AttributeExternalFileDef_var aFileName;
1288 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1289 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1290 ASSERT(!aFileName->_is_nil());
1291 aFileName->SetValue(file);
1292 SALOMEDS::AttributeFileType_var aFileType;
1293 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1294 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1295 ASSERT(!aFileType->_is_nil());
1296 aFileType->SetValue("FICHIERMED");
1300 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1303 void SMESH_Mesh_i::ExportMED (const char* file,
1304 CORBA::Boolean auto_groups)
1305 throw(SALOME::SALOME_Exception)
1307 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1310 void SMESH_Mesh_i::ExportDAT (const char *file)
1311 throw(SALOME::SALOME_Exception)
1313 Unexpect aCatch(SALOME_SalomeException);
1315 // Update Python script
1316 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1319 PrepareForWriting(file);
1320 _impl->ExportDAT(file);
1323 void SMESH_Mesh_i::ExportUNV (const char *file)
1324 throw(SALOME::SALOME_Exception)
1326 Unexpect aCatch(SALOME_SalomeException);
1328 // Update Python script
1329 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1332 PrepareForWriting(file);
1333 _impl->ExportUNV(file);
1336 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1337 throw(SALOME::SALOME_Exception)
1339 Unexpect aCatch(SALOME_SalomeException);
1341 // Update Python script
1342 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1345 PrepareForWriting(file);
1346 _impl->ExportSTL(file, isascii);
1349 //=============================================================================
1353 //=============================================================================
1355 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1357 Unexpect aCatch(SALOME_SalomeException);
1358 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1359 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1360 return aMesh._retn();
1363 //=============================================================================
1367 //=============================================================================
1368 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1370 Unexpect aCatch(SALOME_SalomeException);
1371 return _impl->NbNodes();
1374 //=============================================================================
1378 //=============================================================================
1379 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1381 Unexpect aCatch(SALOME_SalomeException);
1382 return NbEdges() + NbFaces() + NbVolumes();
1385 //=============================================================================
1389 //=============================================================================
1390 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1392 Unexpect aCatch(SALOME_SalomeException);
1393 return _impl->NbEdges();
1396 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1397 throw(SALOME::SALOME_Exception)
1399 Unexpect aCatch(SALOME_SalomeException);
1400 return _impl->NbEdges( (::SMESH_Mesh::ElementOrder) order);
1403 //=============================================================================
1407 //=============================================================================
1408 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1410 Unexpect aCatch(SALOME_SalomeException);
1411 return _impl->NbFaces();
1414 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1416 Unexpect aCatch(SALOME_SalomeException);
1417 return _impl->NbTriangles();
1420 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1422 Unexpect aCatch(SALOME_SalomeException);
1423 return _impl->NbQuadrangles();
1426 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1428 Unexpect aCatch(SALOME_SalomeException);
1429 return _impl->NbPolygons();
1432 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1433 throw(SALOME::SALOME_Exception)
1435 Unexpect aCatch(SALOME_SalomeException);
1436 return _impl->NbFaces( (::SMESH_Mesh::ElementOrder) order);
1439 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1440 throw(SALOME::SALOME_Exception)
1442 Unexpect aCatch(SALOME_SalomeException);
1443 return _impl->NbTriangles( (::SMESH_Mesh::ElementOrder) order);
1446 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1447 throw(SALOME::SALOME_Exception)
1449 Unexpect aCatch(SALOME_SalomeException);
1450 return _impl->NbQuadrangles( (::SMESH_Mesh::ElementOrder) order);
1453 //=============================================================================
1457 //=============================================================================
1458 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1460 Unexpect aCatch(SALOME_SalomeException);
1461 return _impl->NbVolumes();
1464 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1466 Unexpect aCatch(SALOME_SalomeException);
1467 return _impl->NbTetras();
1470 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1472 Unexpect aCatch(SALOME_SalomeException);
1473 return _impl->NbHexas();
1476 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1478 Unexpect aCatch(SALOME_SalomeException);
1479 return _impl->NbPyramids();
1482 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1484 Unexpect aCatch(SALOME_SalomeException);
1485 return _impl->NbPrisms();
1488 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1490 Unexpect aCatch(SALOME_SalomeException);
1491 return _impl->NbPolyhedrons();
1494 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1495 throw(SALOME::SALOME_Exception)
1497 Unexpect aCatch(SALOME_SalomeException);
1498 return _impl->NbVolumes( (::SMESH_Mesh::ElementOrder) order);
1501 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1502 throw(SALOME::SALOME_Exception)
1504 Unexpect aCatch(SALOME_SalomeException);
1505 return _impl->NbTetras( (::SMESH_Mesh::ElementOrder) order);
1508 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1509 throw(SALOME::SALOME_Exception)
1511 Unexpect aCatch(SALOME_SalomeException);
1512 return _impl->NbHexas( (::SMESH_Mesh::ElementOrder) order);
1515 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1516 throw(SALOME::SALOME_Exception)
1518 Unexpect aCatch(SALOME_SalomeException);
1519 return _impl->NbPyramids( (::SMESH_Mesh::ElementOrder) order);
1522 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1523 throw(SALOME::SALOME_Exception)
1525 Unexpect aCatch(SALOME_SalomeException);
1526 return _impl->NbPrisms( (::SMESH_Mesh::ElementOrder) order);
1529 //=============================================================================
1533 //=============================================================================
1534 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1536 Unexpect aCatch(SALOME_SalomeException);
1537 return _impl->NbSubMesh();
1540 //=============================================================================
1544 //=============================================================================
1545 char* SMESH_Mesh_i::Dump()
1547 std::ostringstream os;
1549 return CORBA::string_dup( os.str().c_str() );
1552 //=============================================================================
1556 //=============================================================================
1557 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1559 SMESH::long_array_var aResult = new SMESH::long_array();
1560 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1561 int aMinId = aSMESHDS_Mesh->MinElementID();
1562 int aMaxId = aSMESHDS_Mesh->MaxElementID();
1564 aResult->length(aMaxId - aMinId + 1);
1566 for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1569 return aResult._retn();
1572 //=============================================================================
1576 //=============================================================================
1578 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1579 throw (SALOME::SALOME_Exception)
1581 Unexpect aCatch(SALOME_SalomeException);
1582 MESSAGE("SMESH_Mesh_i::GetElementsId");
1583 SMESH::long_array_var aResult = new SMESH::long_array();
1584 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1586 if ( aSMESHDS_Mesh == NULL )
1587 return aResult._retn();
1589 long nbElements = NbElements();
1590 aResult->length( nbElements );
1591 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1592 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1593 aResult[i] = anIt->next()->GetID();
1595 return aResult._retn();
1599 //=============================================================================
1603 //=============================================================================
1605 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1606 throw (SALOME::SALOME_Exception)
1608 Unexpect aCatch(SALOME_SalomeException);
1609 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1610 SMESH::long_array_var aResult = new SMESH::long_array();
1611 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1613 if ( aSMESHDS_Mesh == NULL )
1614 return aResult._retn();
1616 long nbElements = NbElements();
1618 // No sense in returning ids of elements along with ids of nodes:
1619 // when theElemType == SMESH::ALL, return node ids only if
1620 // there are no elements
1621 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1622 return GetNodesId();
1624 aResult->length( nbElements );
1628 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1629 while ( i < nbElements && anIt->more() ) {
1630 const SMDS_MeshElement* anElem = anIt->next();
1631 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1632 aResult[i++] = anElem->GetID();
1635 aResult->length( i );
1637 return aResult._retn();
1640 //=============================================================================
1644 //=============================================================================
1646 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1647 throw (SALOME::SALOME_Exception)
1649 Unexpect aCatch(SALOME_SalomeException);
1650 MESSAGE("SMESH_subMesh_i::GetNodesId");
1651 SMESH::long_array_var aResult = new SMESH::long_array();
1652 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1654 if ( aSMESHDS_Mesh == NULL )
1655 return aResult._retn();
1657 long nbNodes = NbNodes();
1658 aResult->length( nbNodes );
1659 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1660 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1661 aResult[i] = anIt->next()->GetID();
1663 return aResult._retn();
1666 //=============================================================================
1670 //=============================================================================
1672 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1673 throw (SALOME::SALOME_Exception)
1675 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1679 //=============================================================================
1681 * Returns ID of elements for given submesh
1683 //=============================================================================
1684 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1685 throw (SALOME::SALOME_Exception)
1687 SMESH::long_array_var aResult = new SMESH::long_array();
1689 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1690 if(!SM) return aResult._retn();
1692 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1693 if(!SDSM) return aResult._retn();
1695 aResult->length(SDSM->NbElements());
1697 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1699 while ( eIt->more() ) {
1700 aResult[i++] = eIt->next()->GetID();
1703 return aResult._retn();
1707 //=============================================================================
1709 * Returns ID of nodes for given submesh
1710 * If param all==true - returns all nodes, else -
1711 * returns only nodes on shapes.
1713 //=============================================================================
1714 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1715 throw (SALOME::SALOME_Exception)
1717 SMESH::long_array_var aResult = new SMESH::long_array();
1719 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1720 if(!SM) return aResult._retn();
1722 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1723 if(!SDSM) return aResult._retn();
1725 map<int,const SMDS_MeshElement*> theElems;
1726 if( !all || (SDSM->NbElements()==0 && SDSM->NbNodes()==1) ) {
1727 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1728 while ( nIt->more() ) {
1729 const SMDS_MeshNode* elem = nIt->next();
1730 theElems.insert( make_pair(elem->GetID(),elem) );
1733 else { // all nodes of submesh elements
1734 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1735 while ( eIt->more() ) {
1736 const SMDS_MeshElement* anElem = eIt->next();
1737 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1738 while ( nIt->more() ) {
1739 const SMDS_MeshElement* elem = nIt->next();
1740 theElems.insert( make_pair(elem->GetID(),elem) );
1745 aResult->length(theElems.size());
1746 map<int, const SMDS_MeshElement * >::iterator itElem;
1748 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1749 aResult[i++] = (*itElem).first;
1751 return aResult._retn();
1755 //=============================================================================
1757 * Returns type of elements for given submesh
1759 //=============================================================================
1760 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
1761 throw (SALOME::SALOME_Exception)
1763 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1764 if(!SM) return SMESH::ALL;
1766 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1767 if(!SDSM) return SMESH::ALL;
1769 if(SDSM->NbElements()==0)
1770 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
1772 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1773 const SMDS_MeshElement* anElem = eIt->next();
1774 return ( SMESH::ElementType ) anElem->GetType();
1778 //=============================================================================
1782 //=============================================================================
1784 CORBA::Long SMESH_Mesh_i::GetMeshPtr()
1786 return CORBA::Long(size_t(_impl));
1790 //=============================================================================
1792 * Get XYZ coordinates of node as list of double
1793 * If there is not node for given ID - returns empty list
1795 //=============================================================================
1797 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
1799 SMESH::double_array_var aResult = new SMESH::double_array();
1800 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1801 if ( aSMESHDS_Mesh == NULL )
1802 return aResult._retn();
1805 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1807 return aResult._retn();
1811 aResult[0] = aNode->X();
1812 aResult[1] = aNode->Y();
1813 aResult[2] = aNode->Z();
1814 return aResult._retn();
1818 //=============================================================================
1820 * For given node returns list of IDs of inverse elements
1821 * If there is not node for given ID - returns empty list
1823 //=============================================================================
1825 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
1827 SMESH::long_array_var aResult = new SMESH::long_array();
1828 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1829 if ( aSMESHDS_Mesh == NULL )
1830 return aResult._retn();
1833 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1835 return aResult._retn();
1837 // find inverse elements
1838 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
1839 TColStd_SequenceOfInteger IDs;
1840 while(eIt->more()) {
1841 const SMDS_MeshElement* elem = eIt->next();
1842 IDs.Append(elem->GetID());
1844 if(IDs.Length()>0) {
1845 aResult->length(IDs.Length());
1847 for(; i<=IDs.Length(); i++) {
1848 aResult[i-1] = IDs.Value(i);
1851 return aResult._retn();
1855 //=============================================================================
1857 * If given element is node returns IDs of shape from position
1858 * else - return ID of result shape after ::FindShape()
1859 * from SMESH_MeshEditor
1860 * If there is not element for given ID - returns -1
1862 //=============================================================================
1864 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
1866 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1867 if ( aSMESHDS_Mesh == NULL )
1871 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1873 SMDS_PositionPtr pos = aNode->GetPosition();
1877 return pos->GetShapeId();
1880 // try to find element
1881 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1885 // need implementation???????????????????????????????????????????????
1890 //=============================================================================
1892 * Returns number of nodes for given element
1893 * If there is not element for given ID - returns -1
1895 //=============================================================================
1897 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
1899 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1900 if ( aSMESHDS_Mesh == NULL ) return -1;
1901 // try to find element
1902 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1903 if(!elem) return -1;
1904 return elem->NbNodes();
1908 //=============================================================================
1910 * Returns ID of node by given index for given element
1911 * If there is not element for given ID - returns -1
1912 * If there is not node for given index - returns -2
1914 //=============================================================================
1916 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
1918 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1919 if ( aSMESHDS_Mesh == NULL ) return -1;
1920 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1921 if(!elem) return -1;
1922 if( index>=elem->NbNodes() || index<0 ) return -1;
1923 return elem->GetNode(index)->GetID();
1927 //=============================================================================
1929 * Returns true if given node is medium node
1930 * in given quadratic element
1932 //=============================================================================
1934 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
1936 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1937 if ( aSMESHDS_Mesh == NULL ) return false;
1939 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
1940 if(!aNode) return false;
1941 // try to find element
1942 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
1943 if(!elem) return false;
1945 return elem->IsMediumNode(aNode);
1949 //=============================================================================
1951 * Returns true if given node is medium node
1952 * in one of quadratic elements
1954 //=============================================================================
1956 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
1957 SMESH::ElementType theElemType)
1959 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1960 if ( aSMESHDS_Mesh == NULL ) return false;
1963 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
1964 if(!aNode) return false;
1966 SMESH_MesherHelper aHelper( *(_impl) );
1968 SMDSAbs_ElementType aType;
1969 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
1970 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
1971 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
1972 else aType = SMDSAbs_All;
1974 return aHelper.IsMedium(aNode,aType);
1978 //=============================================================================
1980 * Returns number of edges for given element
1982 //=============================================================================
1984 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
1986 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1987 if ( aSMESHDS_Mesh == NULL ) return -1;
1988 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1989 if(!elem) return -1;
1990 return elem->NbEdges();
1994 //=============================================================================
1996 * Returns number of faces for given element
1998 //=============================================================================
2000 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2002 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2003 if ( aSMESHDS_Mesh == NULL ) return -1;
2004 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2005 if(!elem) return -1;
2006 return elem->NbFaces();
2010 //=============================================================================
2012 * Returns true if given element is polygon
2014 //=============================================================================
2016 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2018 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2019 if ( aSMESHDS_Mesh == NULL ) return false;
2020 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2021 if(!elem) return false;
2022 return elem->IsPoly();
2026 //=============================================================================
2028 * Returns true if given element is quadratic
2030 //=============================================================================
2032 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2034 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2035 if ( aSMESHDS_Mesh == NULL ) return false;
2036 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2037 if(!elem) return false;
2038 return elem->IsQuadratic();
2042 //=============================================================================
2044 * Returns bary center for given element
2046 //=============================================================================
2048 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2050 SMESH::double_array_var aResult = new SMESH::double_array();
2051 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2052 if ( aSMESHDS_Mesh == NULL )
2053 return aResult._retn();
2055 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2057 return aResult._retn();
2059 if(elem->GetType()==SMDSAbs_Volume) {
2060 // use SMDS_VolumeTool
2061 SMDS_VolumeTool aTool;
2062 if(aTool.Set(elem)) {
2063 double x=0., y=0., z=0.;
2064 if(aTool.GetBaryCenter(x,y,z)) {
2074 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2076 double x=0., y=0., z=0.;
2077 for(; anIt->more(); ) {
2079 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2093 return aResult._retn();
2097 //=============================================================================
2101 //=============================================================================
2102 void SMESH_Mesh_i::CreateGroupServants()
2104 // Create group servants, if any groups were imported
2105 list<int> aGroupIds = _impl->GetGroupIds();
2106 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
2107 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
2109 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2110 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2111 aGroupImpl->Register();
2112 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2114 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
2115 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
2117 // register CORBA object for persistence
2118 int nextId = _gen_i->RegisterObject( aGroup );
2119 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);