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"
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++ )
1567 // aResult[i++] = id;
1569 // return aResult._retn();
1571 return GetElementsId();
1574 //=============================================================================
1578 //=============================================================================
1580 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1581 throw (SALOME::SALOME_Exception)
1583 Unexpect aCatch(SALOME_SalomeException);
1584 MESSAGE("SMESH_Mesh_i::GetElementsId");
1585 SMESH::long_array_var aResult = new SMESH::long_array();
1586 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1588 if ( aSMESHDS_Mesh == NULL )
1589 return aResult._retn();
1591 long nbElements = NbElements();
1592 aResult->length( nbElements );
1593 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1594 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1595 aResult[i] = anIt->next()->GetID();
1597 return aResult._retn();
1601 //=============================================================================
1605 //=============================================================================
1607 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1608 throw (SALOME::SALOME_Exception)
1610 Unexpect aCatch(SALOME_SalomeException);
1611 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1612 SMESH::long_array_var aResult = new SMESH::long_array();
1613 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1615 if ( aSMESHDS_Mesh == NULL )
1616 return aResult._retn();
1618 long nbElements = NbElements();
1620 // No sense in returning ids of elements along with ids of nodes:
1621 // when theElemType == SMESH::ALL, return node ids only if
1622 // there are no elements
1623 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1624 return GetNodesId();
1626 aResult->length( nbElements );
1630 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1631 while ( i < nbElements && anIt->more() ) {
1632 const SMDS_MeshElement* anElem = anIt->next();
1633 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1634 aResult[i++] = anElem->GetID();
1637 aResult->length( i );
1639 return aResult._retn();
1642 //=============================================================================
1646 //=============================================================================
1648 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1649 throw (SALOME::SALOME_Exception)
1651 Unexpect aCatch(SALOME_SalomeException);
1652 MESSAGE("SMESH_subMesh_i::GetNodesId");
1653 SMESH::long_array_var aResult = new SMESH::long_array();
1654 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1656 if ( aSMESHDS_Mesh == NULL )
1657 return aResult._retn();
1659 long nbNodes = NbNodes();
1660 aResult->length( nbNodes );
1661 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1662 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1663 aResult[i] = anIt->next()->GetID();
1665 return aResult._retn();
1668 //=============================================================================
1672 //=============================================================================
1674 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1675 throw (SALOME::SALOME_Exception)
1677 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1681 //=============================================================================
1683 * Returns ID of elements for given submesh
1685 //=============================================================================
1686 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1687 throw (SALOME::SALOME_Exception)
1689 SMESH::long_array_var aResult = new SMESH::long_array();
1691 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1692 if(!SM) return aResult._retn();
1694 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1695 if(!SDSM) return aResult._retn();
1697 aResult->length(SDSM->NbElements());
1699 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1701 while ( eIt->more() ) {
1702 aResult[i++] = eIt->next()->GetID();
1705 return aResult._retn();
1709 //=============================================================================
1711 * Returns ID of nodes for given submesh
1712 * If param all==true - returns all nodes, else -
1713 * returns only nodes on shapes.
1715 //=============================================================================
1716 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1717 throw (SALOME::SALOME_Exception)
1719 SMESH::long_array_var aResult = new SMESH::long_array();
1721 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1722 if(!SM) return aResult._retn();
1724 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1725 if(!SDSM) return aResult._retn();
1727 map<int,const SMDS_MeshElement*> theElems;
1728 if( !all || (SDSM->NbElements()==0 && SDSM->NbNodes()==1) ) {
1729 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1730 while ( nIt->more() ) {
1731 const SMDS_MeshNode* elem = nIt->next();
1732 theElems.insert( make_pair(elem->GetID(),elem) );
1735 else { // all nodes of submesh elements
1736 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1737 while ( eIt->more() ) {
1738 const SMDS_MeshElement* anElem = eIt->next();
1739 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1740 while ( nIt->more() ) {
1741 const SMDS_MeshElement* elem = nIt->next();
1742 theElems.insert( make_pair(elem->GetID(),elem) );
1747 aResult->length(theElems.size());
1748 map<int, const SMDS_MeshElement * >::iterator itElem;
1750 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1751 aResult[i++] = (*itElem).first;
1753 return aResult._retn();
1757 //=============================================================================
1759 * Returns type of elements for given submesh
1761 //=============================================================================
1762 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
1763 throw (SALOME::SALOME_Exception)
1765 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1766 if(!SM) return SMESH::ALL;
1768 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1769 if(!SDSM) return SMESH::ALL;
1771 if(SDSM->NbElements()==0)
1772 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
1774 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1775 const SMDS_MeshElement* anElem = eIt->next();
1776 return ( SMESH::ElementType ) anElem->GetType();
1780 //=============================================================================
1784 //=============================================================================
1786 CORBA::Long SMESH_Mesh_i::GetMeshPtr()
1788 return CORBA::Long(size_t(_impl));
1792 //=============================================================================
1794 * Get XYZ coordinates of node as list of double
1795 * If there is not node for given ID - returns empty list
1797 //=============================================================================
1799 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
1801 SMESH::double_array_var aResult = new SMESH::double_array();
1802 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1803 if ( aSMESHDS_Mesh == NULL )
1804 return aResult._retn();
1807 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1809 return aResult._retn();
1813 aResult[0] = aNode->X();
1814 aResult[1] = aNode->Y();
1815 aResult[2] = aNode->Z();
1816 return aResult._retn();
1820 //=============================================================================
1822 * For given node returns list of IDs of inverse elements
1823 * If there is not node for given ID - returns empty list
1825 //=============================================================================
1827 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
1829 SMESH::long_array_var aResult = new SMESH::long_array();
1830 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1831 if ( aSMESHDS_Mesh == NULL )
1832 return aResult._retn();
1835 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1837 return aResult._retn();
1839 // find inverse elements
1840 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
1841 TColStd_SequenceOfInteger IDs;
1842 while(eIt->more()) {
1843 const SMDS_MeshElement* elem = eIt->next();
1844 IDs.Append(elem->GetID());
1846 if(IDs.Length()>0) {
1847 aResult->length(IDs.Length());
1849 for(; i<=IDs.Length(); i++) {
1850 aResult[i-1] = IDs.Value(i);
1853 return aResult._retn();
1857 //=============================================================================
1859 * If given element is node returns IDs of shape from position
1860 * else - return ID of result shape after ::FindShape()
1861 * from SMESH_MeshEditor
1862 * If there is not element for given ID - returns -1
1864 //=============================================================================
1866 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
1868 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1869 if ( aSMESHDS_Mesh == NULL )
1873 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1875 SMDS_PositionPtr pos = aNode->GetPosition();
1879 return pos->GetShapeId();
1882 // try to find element
1883 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1887 // need implementation???????????????????????????????????????????????
1892 //=============================================================================
1894 * Returns number of nodes for given element
1895 * If there is not element for given ID - returns -1
1897 //=============================================================================
1899 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
1901 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1902 if ( aSMESHDS_Mesh == NULL ) return -1;
1903 // try to find element
1904 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1905 if(!elem) return -1;
1906 return elem->NbNodes();
1910 //=============================================================================
1912 * Returns ID of node by given index for given element
1913 * If there is not element for given ID - returns -1
1914 * If there is not node for given index - returns -2
1916 //=============================================================================
1918 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
1920 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1921 if ( aSMESHDS_Mesh == NULL ) return -1;
1922 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1923 if(!elem) return -1;
1924 if( index>=elem->NbNodes() || index<0 ) return -1;
1925 return elem->GetNode(index)->GetID();
1929 //=============================================================================
1931 * Returns true if given node is medium node
1932 * in given quadratic element
1934 //=============================================================================
1936 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
1938 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1939 if ( aSMESHDS_Mesh == NULL ) return false;
1941 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
1942 if(!aNode) return false;
1943 // try to find element
1944 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
1945 if(!elem) return false;
1947 return elem->IsMediumNode(aNode);
1951 //=============================================================================
1953 * Returns true if given node is medium node
1954 * in one of quadratic elements
1956 //=============================================================================
1958 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
1959 SMESH::ElementType theElemType)
1961 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1962 if ( aSMESHDS_Mesh == NULL ) return false;
1965 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
1966 if(!aNode) return false;
1968 SMESH_MesherHelper aHelper( *(_impl) );
1970 SMDSAbs_ElementType aType;
1971 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
1972 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
1973 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
1974 else aType = SMDSAbs_All;
1976 return aHelper.IsMedium(aNode,aType);
1980 //=============================================================================
1982 * Returns number of edges for given element
1984 //=============================================================================
1986 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
1988 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1989 if ( aSMESHDS_Mesh == NULL ) return -1;
1990 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
1991 if(!elem) return -1;
1992 return elem->NbEdges();
1996 //=============================================================================
1998 * Returns number of faces for given element
2000 //=============================================================================
2002 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2004 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2005 if ( aSMESHDS_Mesh == NULL ) return -1;
2006 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2007 if(!elem) return -1;
2008 return elem->NbFaces();
2012 //=============================================================================
2014 * Returns true if given element is polygon
2016 //=============================================================================
2018 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2020 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2021 if ( aSMESHDS_Mesh == NULL ) return false;
2022 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2023 if(!elem) return false;
2024 return elem->IsPoly();
2028 //=============================================================================
2030 * Returns true if given element is quadratic
2032 //=============================================================================
2034 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2036 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2037 if ( aSMESHDS_Mesh == NULL ) return false;
2038 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2039 if(!elem) return false;
2040 return elem->IsQuadratic();
2044 //=============================================================================
2046 * Returns bary center for given element
2048 //=============================================================================
2050 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2052 SMESH::double_array_var aResult = new SMESH::double_array();
2053 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2054 if ( aSMESHDS_Mesh == NULL )
2055 return aResult._retn();
2057 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2059 return aResult._retn();
2061 if(elem->GetType()==SMDSAbs_Volume) {
2062 // use SMDS_VolumeTool
2063 SMDS_VolumeTool aTool;
2064 if(aTool.Set(elem)) {
2065 double x=0., y=0., z=0.;
2066 if(aTool.GetBaryCenter(x,y,z)) {
2076 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2078 double x=0., y=0., z=0.;
2079 for(; anIt->more(); ) {
2081 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2095 return aResult._retn();
2099 //=============================================================================
2103 //=============================================================================
2104 void SMESH_Mesh_i::CreateGroupServants()
2106 // Create group servants, if any groups were imported
2107 list<int> aGroupIds = _impl->GetGroupIds();
2108 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
2109 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
2111 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2112 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2113 aGroupImpl->Register();
2114 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2116 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
2117 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
2119 // register CORBA object for persistence
2120 int nextId = _gen_i->RegisterObject( aGroup );
2121 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);