1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Mesh_i.cxx
25 // Author : Paul RASCLE, EDF
29 #include "SMESH_Mesh_i.hxx"
30 #include "SMESH_subMesh_i.hxx"
31 #include "SMESH_MEDMesh_i.hxx"
32 #include "SMESH_Group_i.hxx"
33 #include "SMESH_Filter_i.hxx"
34 #include "SMESH_PythonDump.hxx"
36 #include "Utils_CorbaException.hxx"
37 #include "Utils_ExceptHandlers.hxx"
38 #include "utilities.h"
40 #include "SALOME_NamingService.hxx"
41 #include "Utils_SINGLETON.hxx"
44 #include "SMESHDS_Command.hxx"
45 #include "SMESHDS_CommandType.hxx"
46 #include "SMESH_MeshEditor_i.hxx"
47 #include "SMESH_Gen_i.hxx"
48 #include "DriverMED_R_SMESHDS_Mesh.h"
49 //#include "SMDS_ElemIterator.hxx"
50 #include "SMDS_VolumeTool.hxx"
51 #include "SMESH_MesherHelper.hxx"
52 #include "SMESH_MeshEditor.hxx"
55 #include <BRep_Builder.hxx>
56 #include <OSD_Path.hxx>
57 #include <OSD_File.hxx>
58 #include <OSD_Directory.hxx>
59 #include <OSD_Protection.hxx>
60 #include <TColStd_MapOfInteger.hxx>
61 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
62 #include <TColStd_SequenceOfInteger.hxx>
63 #include <TCollection_AsciiString.hxx>
64 #include <TopoDS_Compound.hxx>
72 static int MYDEBUG = 0;
74 static int MYDEBUG = 0;
78 using SMESH::TPythonDump;
80 int SMESH_Mesh_i::myIdGenerator = 0;
84 //=============================================================================
88 //=============================================================================
90 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
93 : SALOME::GenericObj_i( thePOA )
95 MESSAGE("SMESH_Mesh_i");
98 _id = myIdGenerator++;
100 thePOA->activate_object( this );
103 //=============================================================================
107 //=============================================================================
109 SMESH_Mesh_i::~SMESH_Mesh_i()
111 INFOS("~SMESH_Mesh_i");
112 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
113 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
114 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
117 // this method is colled from destructor of group (PAL6331)
118 //_impl->RemoveGroup( aGroup->GetLocalID() );
126 //=============================================================================
130 * Associates <this> mesh with <theShape> and puts a reference
131 * to <theShape> into the current study;
132 * the previous shape is substituted by the new one.
134 //=============================================================================
136 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
137 throw (SALOME::SALOME_Exception)
139 Unexpect aCatch(SALOME_SalomeException);
141 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
143 catch(SALOME_Exception & S_ex) {
144 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
148 //================================================================================
150 * \brief return true if mesh has a shape to build a shape on
152 //================================================================================
154 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
155 throw (SALOME::SALOME_Exception)
157 Unexpect aCatch(SALOME_SalomeException);
160 res = _impl->HasShapeToMesh();
162 catch(SALOME_Exception & S_ex) {
163 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
168 //=======================================================================
169 //function : GetShapeToMesh
171 //=======================================================================
173 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
174 throw (SALOME::SALOME_Exception)
176 Unexpect aCatch(SALOME_SalomeException);
177 GEOM::GEOM_Object_var aShapeObj;
179 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
181 aShapeObj = _gen_i->ShapeToGeomObject( S );
183 catch(SALOME_Exception & S_ex) {
184 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
186 return aShapeObj._retn();
189 //=============================================================================
193 //=============================================================================
195 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
197 SMESH::DriverMED_ReadStatus res;
200 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
201 res = SMESH::DRS_OK; break;
202 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
203 res = SMESH::DRS_EMPTY; break;
204 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
205 res = SMESH::DRS_WARN_RENUMBER; break;
206 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
207 res = SMESH::DRS_WARN_SKIP_ELEM; break;
208 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
210 res = SMESH::DRS_FAIL; break;
215 //=============================================================================
219 * Imports mesh data from MED file
221 //=============================================================================
223 SMESH::DriverMED_ReadStatus
224 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
225 throw ( SALOME::SALOME_Exception )
227 Unexpect aCatch(SALOME_SalomeException);
230 status = importMEDFile( theFileName, theMeshName );
232 catch( SALOME_Exception& S_ex ) {
233 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
236 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
239 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
240 if ( !aStudy->_is_nil() ) {
241 // publishing of the groups in the study (sub-meshes are out of scope of MED import)
242 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
243 for (; it != _mapGroups.end(); it++ ) {
244 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
245 _gen_i->PublishGroup( aStudy, _this(), aGroup,
246 GEOM::GEOM_Object::_nil(), aGroup->GetName());
249 return ConvertDriverMEDReadStatus(status);
252 //=============================================================================
256 * Imports mesh data from MED file
258 //=============================================================================
260 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
261 throw ( SALOME::SALOME_Exception )
263 // Read mesh with name = <theMeshName> into SMESH_Mesh
264 _impl->UNVToMesh( theFileName );
266 CreateGroupServants();
268 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
269 if ( !aStudy->_is_nil() ) {
270 // publishing of the groups in the study (sub-meshes are out of scope of UNV import)
271 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
272 for (; it != _mapGroups.end(); it++ ) {
273 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
274 _gen_i->PublishGroup( aStudy, _this(), aGroup,
275 GEOM::GEOM_Object::_nil(), aGroup->GetName());
281 //=============================================================================
285 * Imports mesh data from STL file
287 //=============================================================================
288 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
289 throw ( SALOME::SALOME_Exception )
291 // Read mesh with name = <theMeshName> into SMESH_Mesh
292 _impl->STLToMesh( theFileName );
297 //=============================================================================
301 * Imports mesh data from MED file
303 //=============================================================================
305 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
307 // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
308 int status = _impl->MEDToMesh( theFileName, theMeshName );
309 CreateGroupServants();
314 //=============================================================================
318 //=============================================================================
320 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
322 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
323 (SMESH_Hypothesis::Hypothesis_Status theStatus)
326 RETURNCASE( HYP_OK );
327 RETURNCASE( HYP_MISSING );
328 RETURNCASE( HYP_CONCURENT );
329 RETURNCASE( HYP_BAD_PARAMETER );
330 RETURNCASE( HYP_HIDDEN_ALGO );
331 RETURNCASE( HYP_HIDING_ALGO );
332 RETURNCASE( HYP_UNKNOWN_FATAL );
333 RETURNCASE( HYP_INCOMPATIBLE );
334 RETURNCASE( HYP_NOTCONFORM );
335 RETURNCASE( HYP_ALREADY_EXIST );
336 RETURNCASE( HYP_BAD_DIM );
337 RETURNCASE( HYP_BAD_SUBSHAPE );
338 RETURNCASE( HYP_BAD_GEOMETRY );
341 return SMESH::HYP_UNKNOWN_FATAL;
344 //=============================================================================
348 * calls internal addHypothesis() and then adds a reference to <anHyp> under
349 * the SObject actually having a reference to <aSubShape>.
350 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
352 //=============================================================================
354 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
355 SMESH::SMESH_Hypothesis_ptr anHyp)
356 throw(SALOME::SALOME_Exception)
358 Unexpect aCatch(SALOME_SalomeException);
359 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
361 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
362 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
363 aSubShapeObject, anHyp );
365 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
367 // Update Python script
368 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
369 << aSubShapeObject << ", " << anHyp << " )";
371 return ConvertHypothesisStatus(status);
374 //=============================================================================
378 //=============================================================================
380 SMESH_Hypothesis::Hypothesis_Status
381 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
382 SMESH::SMESH_Hypothesis_ptr anHyp)
384 if(MYDEBUG) MESSAGE("addHypothesis");
386 if (CORBA::is_nil(aSubShapeObject))
387 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
390 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
391 if (CORBA::is_nil(myHyp))
392 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
395 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
398 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
399 int hypId = myHyp->GetId();
400 status = _impl->AddHypothesis(myLocSubShape, hypId);
401 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
402 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
403 // assure there is a corresponding submesh
404 if ( !_impl->IsMainShape( myLocSubShape )) {
405 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
406 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
407 createSubMesh( aSubShapeObject );
411 catch(SALOME_Exception & S_ex)
413 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
418 //=============================================================================
422 //=============================================================================
424 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
425 SMESH::SMESH_Hypothesis_ptr anHyp)
426 throw(SALOME::SALOME_Exception)
428 Unexpect aCatch(SALOME_SalomeException);
429 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
431 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
432 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
433 aSubShapeObject, anHyp );
435 // Update Python script
436 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
437 << aSubShapeObject << ", " << anHyp << " )";
439 return ConvertHypothesisStatus(status);
442 //=============================================================================
446 //=============================================================================
448 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
449 SMESH::SMESH_Hypothesis_ptr anHyp)
451 if(MYDEBUG) MESSAGE("removeHypothesis()");
452 // **** proposer liste de subShape (selection multiple)
454 if (CORBA::is_nil(aSubShapeObject))
455 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
458 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
459 if (CORBA::is_nil(myHyp))
460 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
463 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
466 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
467 int hypId = myHyp->GetId();
468 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
469 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
470 _mapHypo.erase( hypId );
472 catch(SALOME_Exception & S_ex)
474 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
479 //=============================================================================
483 //=============================================================================
485 SMESH::ListOfHypothesis *
486 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
487 throw(SALOME::SALOME_Exception)
489 Unexpect aCatch(SALOME_SalomeException);
490 if (MYDEBUG) MESSAGE("GetHypothesisList");
491 if (CORBA::is_nil(aSubShapeObject))
492 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
495 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
498 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
499 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
500 int i = 0, n = aLocalList.size();
503 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
504 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
505 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
506 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
511 catch(SALOME_Exception & S_ex) {
512 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
515 return aList._retn();
518 //=============================================================================
522 //=============================================================================
523 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
524 const char* theName )
525 throw(SALOME::SALOME_Exception)
527 Unexpect aCatch(SALOME_SalomeException);
528 MESSAGE("SMESH_Mesh_i::GetSubMesh");
529 if (CORBA::is_nil(aSubShapeObject))
530 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
533 SMESH::SMESH_subMesh_var subMesh;
534 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
536 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
538 //Get or Create the SMESH_subMesh object implementation
540 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
541 subMesh = getSubMesh( subMeshId );
543 // create a new subMesh object servant if there is none for the shape
544 if ( subMesh->_is_nil() )
545 subMesh = createSubMesh( aSubShapeObject );
547 if ( _gen_i->CanPublishInStudy( subMesh )) {
548 SALOMEDS::SObject_var aSO =
549 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
550 subMesh, aSubShapeObject, theName );
551 if ( !aSO->_is_nil()) {
552 // Update Python script
553 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
554 << aSubShapeObject << ", '" << theName << "' )";
558 catch(SALOME_Exception & S_ex) {
559 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
561 return subMesh._retn();
564 //=============================================================================
568 //=============================================================================
570 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
571 throw (SALOME::SALOME_Exception)
573 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
574 if ( theSubMesh->_is_nil() )
577 GEOM::GEOM_Object_var aSubShapeObject;
578 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
579 if ( !aStudy->_is_nil() ) {
580 // Remove submesh's SObject
581 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
582 if ( !anSO->_is_nil() ) {
583 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
584 SALOMEDS::SObject_var anObj, aRef;
585 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
586 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
588 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
590 // Update Python script
591 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
595 removeSubMesh( theSubMesh, aSubShapeObject.in() );
598 //=============================================================================
602 //=============================================================================
603 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
604 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
606 switch (theElemType) {
611 CASE2STRING( VOLUME );
617 //=============================================================================
621 //=============================================================================
623 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
624 const char* theName )
625 throw(SALOME::SALOME_Exception)
627 Unexpect aCatch(SALOME_SalomeException);
628 SMESH::SMESH_Group_var aNewGroup =
629 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
631 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
632 SALOMEDS::SObject_var aSO =
633 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
634 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
635 if ( !aSO->_is_nil()) {
636 // Update Python script
637 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
638 << ElementTypeString(theElemType) << ", '" << theName << "' )";
641 return aNewGroup._retn();
645 //=============================================================================
649 //=============================================================================
650 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
652 GEOM::GEOM_Object_ptr theGeomObj)
653 throw(SALOME::SALOME_Exception)
655 Unexpect aCatch(SALOME_SalomeException);
656 SMESH::SMESH_GroupOnGeom_var aNewGroup;
658 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
659 if ( !aShape.IsNull() ) {
660 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
661 ( createGroup( theElemType, theName, aShape ));
662 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
663 SALOMEDS::SObject_var aSO =
664 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
665 aNewGroup, theGeomObj, theName);
666 if ( !aSO->_is_nil()) {
667 // Update Python script
668 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
669 << ElementTypeString(theElemType) << ", '" << theName << "', "
670 << theGeomObj << " )";
675 return aNewGroup._retn();
678 //=============================================================================
682 //=============================================================================
684 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
685 throw (SALOME::SALOME_Exception)
687 if ( theGroup->_is_nil() )
690 SMESH_GroupBase_i* aGroup =
691 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
695 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
696 if ( !aStudy->_is_nil() ) {
697 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
699 if ( !aGroupSO->_is_nil() ) {
700 // Update Python script
701 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
703 // Remove group's SObject
704 aStudy->NewBuilder()->RemoveObject( aGroupSO );
708 // Remove the group from SMESH data structures
709 removeGroup( aGroup->GetLocalID() );
712 //=============================================================================
713 /*! RemoveGroupWithContents
714 * Remove group with its contents
716 //=============================================================================
717 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
718 throw (SALOME::SALOME_Exception)
720 if ( theGroup->_is_nil() )
723 SMESH_GroupBase_i* aGroup =
724 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
728 SMESH::long_array_var anIds = aGroup->GetListOfID();
729 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
731 // Update Python script
732 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
735 if ( aGroup->GetType() == SMESH::NODE )
736 aMeshEditor->RemoveNodes( anIds );
738 aMeshEditor->RemoveElements( anIds );
741 RemoveGroup( theGroup );
743 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
744 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
745 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
749 //================================================================================
751 * \brief Get the list of groups existing in the mesh
752 * \retval SMESH::ListOfGroups * - list of groups
754 //================================================================================
756 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
758 Unexpect aCatch(SALOME_SalomeException);
759 if (MYDEBUG) MESSAGE("GetGroups");
761 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
764 TPythonDump aPythonDump;
765 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
769 aList->length( _mapGroups.size() );
771 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
772 for ( ; it != _mapGroups.end(); it++ ) {
773 if ( CORBA::is_nil( it->second )) continue;
774 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
776 if (i > 1) aPythonDump << ", ";
777 aPythonDump << it->second;
781 catch(SALOME_Exception & S_ex) {
782 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
785 // Update Python script
786 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
787 aPythonDump << " ] = " << _this() << ".GetGroups()";
789 return aList._retn();
792 //=============================================================================
794 * New group is created. All mesh elements that are
795 * present in initial groups are added to the new one
797 //=============================================================================
798 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
799 SMESH::SMESH_GroupBase_ptr theGroup2,
800 const char* theName )
801 throw (SALOME::SALOME_Exception)
805 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
806 theGroup1->GetType() != theGroup2->GetType() )
807 return SMESH::SMESH_Group::_nil();
810 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
811 if ( aResGrp->_is_nil() )
812 return SMESH::SMESH_Group::_nil();
814 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
815 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
817 TColStd_MapOfInteger aResMap;
819 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
820 aResMap.Add( anIds1[ i1 ] );
822 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
823 aResMap.Add( anIds2[ i2 ] );
825 SMESH::long_array_var aResIds = new SMESH::long_array;
826 aResIds->length( aResMap.Extent() );
829 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
830 for( ; anIter.More(); anIter.Next() )
831 aResIds[ resI++ ] = anIter.Key();
833 aResGrp->Add( aResIds );
835 // Clear python lines, created by CreateGroup() and Add()
836 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
837 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
838 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
840 // Update Python script
841 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
842 << theGroup1 << ", " << theGroup2 << ", '"
845 return aResGrp._retn();
849 return SMESH::SMESH_Group::_nil();
853 //=============================================================================
855 * New group is created. All mesh elements that are
856 * present in both initial groups are added to the new one.
858 //=============================================================================
859 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
860 SMESH::SMESH_GroupBase_ptr theGroup2,
861 const char* theName )
862 throw (SALOME::SALOME_Exception)
864 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
865 theGroup1->GetType() != theGroup2->GetType() )
866 return SMESH::SMESH_Group::_nil();
868 // Create Intersection
869 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
870 if ( aResGrp->_is_nil() )
873 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
874 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
876 TColStd_MapOfInteger aMap1;
878 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
879 aMap1.Add( anIds1[ i1 ] );
881 TColStd_SequenceOfInteger aSeq;
883 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
884 if ( aMap1.Contains( anIds2[ i2 ] ) )
885 aSeq.Append( anIds2[ i2 ] );
887 SMESH::long_array_var aResIds = new SMESH::long_array;
888 aResIds->length( aSeq.Length() );
890 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
891 aResIds[ resI ] = aSeq( resI + 1 );
893 aResGrp->Add( aResIds );
895 // Clear python lines, created by CreateGroup() and Add()
896 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
897 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
898 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
900 // Update Python script
901 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
902 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
904 return aResGrp._retn();
907 //=============================================================================
909 * New group is created. All mesh elements that are present in
910 * main group but do not present in tool group are added to the new one
912 //=============================================================================
913 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
914 SMESH::SMESH_GroupBase_ptr theGroup2,
915 const char* theName )
916 throw (SALOME::SALOME_Exception)
918 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
919 theGroup1->GetType() != theGroup2->GetType() )
920 return SMESH::SMESH_Group::_nil();
923 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
924 if ( aResGrp->_is_nil() )
927 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
928 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
930 TColStd_MapOfInteger aMap2;
932 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
933 aMap2.Add( anIds2[ i2 ] );
936 TColStd_SequenceOfInteger aSeq;
937 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
938 if ( !aMap2.Contains( anIds1[ i1 ] ) )
939 aSeq.Append( anIds1[ i1 ] );
941 SMESH::long_array_var aResIds = new SMESH::long_array;
942 aResIds->length( aSeq.Length() );
944 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
945 aResIds[ resI ] = aSeq( resI + 1 );
947 aResGrp->Add( aResIds );
949 // Clear python lines, created by CreateGroup() and Add()
950 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
951 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
952 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
954 // Update Python script
955 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
956 << theGroup1 << ", " << theGroup2 << ", '"
959 return aResGrp._retn();
962 //================================================================================
964 * \brief Return group items of a group present in a study
966 //================================================================================
968 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
970 list<TopoDS_Shape> & theItems)
972 GEOM::GEOM_Object_var groupObj;
973 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
974 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
975 if ( study->_is_nil() || geomGen->_is_nil() )
976 return groupObj._retn();
978 GEOM::GEOM_IGroupOperations_var groupOp =
979 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
980 GEOM::GEOM_IShapesOperations_var shapeOp =
981 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
983 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
984 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
985 return groupObj._retn();
986 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
987 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
988 return groupObj._retn(); // keep only submeshes on groups
990 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
991 if ( anIter->_is_nil() ) return groupObj._retn();
992 for ( ; anIter->More(); anIter->Next())
994 SALOMEDS::SObject_var aSObject = anIter->Value();
995 SALOMEDS::SObject_var aRefSO;
996 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
998 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
999 if ( groupObj->_is_nil() ) break;
1000 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1001 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1002 for ( int i = 0; i < ids->length(); ++i ) {
1003 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1004 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1006 theItems.push_back( S );
1011 return groupObj._retn();
1014 //=============================================================================
1016 * \brief Update hypotheses assigned to geom groups if the latter change
1018 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1020 //=============================================================================
1022 void SMESH_Mesh_i::CheckGeomGroupModif()
1024 if ( !_impl->HasShapeToMesh() ) return;
1026 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1027 if ( study->_is_nil() ) return;
1029 // check if items of groups changed
1030 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1031 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1033 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1034 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1035 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1037 int oldID = i_sm->first;
1038 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1039 if ( i_smIor == _mapSubMeshIor.end() )
1041 list< TopoDS_Shape> newItems;
1042 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1043 if ( groupObj->_is_nil() )
1046 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1047 int nbNewItems = newItems.size();
1048 bool groupChanged = ( nbOldItems != nbNewItems);
1049 if ( !groupChanged ) {
1050 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1051 groupChanged = ( oldGroupShape != newItems.front() );
1054 list<TopoDS_Shape>::iterator item = newItems.begin();
1055 for ( ; item != newItems.end() && !groupChanged; ++item )
1057 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1058 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1062 // update hypotheses and submeshes if necessary
1065 // get a new group shape
1066 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1067 if ( !geomClient ) continue;
1068 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1069 geomClient->RemoveShapeFromBuffer( groupIOR );
1070 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1071 // update hypotheses
1072 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1073 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1074 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1076 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1077 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1079 // care of submeshes
1080 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1081 int newID = newSubmesh->GetId();
1082 if ( newID != oldID ) {
1083 _mapSubMesh [ newID ] = newSubmesh;
1084 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1085 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1086 _mapSubMesh.erase (oldID);
1087 _mapSubMesh_i.erase (oldID);
1088 _mapSubMeshIor.erase(oldID);
1089 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1095 //=============================================================================
1099 //=============================================================================
1101 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1103 if(MYDEBUG) MESSAGE( "createSubMesh" );
1104 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1106 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1107 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1108 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1109 SMESH::SMESH_subMesh_var subMesh
1110 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1112 _mapSubMesh[subMeshId] = mySubMesh;
1113 _mapSubMesh_i[subMeshId] = subMeshServant;
1114 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1116 // register CORBA object for persistence
1117 int nextId = _gen_i->RegisterObject( subMesh );
1118 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1120 return subMesh._retn();
1123 //=======================================================================
1124 //function : getSubMesh
1126 //=======================================================================
1128 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1130 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1131 if ( it == _mapSubMeshIor.end() )
1132 return SMESH::SMESH_subMesh::_nil();
1134 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1138 //=============================================================================
1142 //=============================================================================
1144 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1145 GEOM::GEOM_Object_ptr theSubShapeObject )
1147 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1148 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1152 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1153 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1154 removeHypothesis( theSubShapeObject, aHypList[i] );
1157 catch( const SALOME::SALOME_Exception& ) {
1158 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1161 int subMeshId = theSubMesh->GetId();
1163 _mapSubMesh.erase(subMeshId);
1164 _mapSubMesh_i.erase(subMeshId);
1165 _mapSubMeshIor.erase(subMeshId);
1166 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1169 //=============================================================================
1173 //=============================================================================
1175 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1176 const char* theName,
1177 const TopoDS_Shape& theShape )
1180 SMESH::SMESH_GroupBase_var aGroup;
1181 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1182 SMESH_GroupBase_i* aGroupImpl;
1183 if ( !theShape.IsNull() )
1184 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1186 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1188 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1189 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1190 aGroupImpl->Register();
1191 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1193 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1194 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1196 // register CORBA object for persistence
1197 int nextId = _gen_i->RegisterObject( aGroup );
1198 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1200 return aGroup._retn();
1203 //=============================================================================
1205 * SMESH_Mesh_i::removeGroup
1207 * Should be called by ~SMESH_Group_i()
1209 //=============================================================================
1211 void SMESH_Mesh_i::removeGroup( const int theId )
1213 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1214 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1215 _mapGroups.erase( theId );
1216 _impl->RemoveGroup( theId );
1221 //=============================================================================
1225 //=============================================================================
1227 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1228 throw(SALOME::SALOME_Exception)
1230 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1232 SMESH::log_array_var aLog;
1234 list < SMESHDS_Command * >logDS = _impl->GetLog();
1235 aLog = new SMESH::log_array;
1237 int lg = logDS.size();
1240 list < SMESHDS_Command * >::iterator its = logDS.begin();
1241 while(its != logDS.end()){
1242 SMESHDS_Command *com = *its;
1243 int comType = com->GetType();
1245 int lgcom = com->GetNumber();
1247 const list < int >&intList = com->GetIndexes();
1248 int inum = intList.size();
1250 list < int >::const_iterator ii = intList.begin();
1251 const list < double >&coordList = com->GetCoords();
1252 int rnum = coordList.size();
1254 list < double >::const_iterator ir = coordList.begin();
1255 aLog[indexLog].commandType = comType;
1256 aLog[indexLog].number = lgcom;
1257 aLog[indexLog].coords.length(rnum);
1258 aLog[indexLog].indexes.length(inum);
1259 for(int i = 0; i < rnum; i++){
1260 aLog[indexLog].coords[i] = *ir;
1261 //MESSAGE(" "<<i<<" "<<ir.Value());
1264 for(int i = 0; i < inum; i++){
1265 aLog[indexLog].indexes[i] = *ii;
1266 //MESSAGE(" "<<i<<" "<<ii.Value());
1275 catch(SALOME_Exception & S_ex){
1276 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1278 return aLog._retn();
1282 //=============================================================================
1286 //=============================================================================
1288 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1290 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1294 //=============================================================================
1298 //=============================================================================
1300 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1302 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1306 //=============================================================================
1310 //=============================================================================
1312 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1317 //=============================================================================
1321 //=============================================================================
1323 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1325 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1329 //=============================================================================
1333 //=============================================================================
1335 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1337 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1341 //=============================================================================
1343 * Return mesh editor
1345 //=============================================================================
1347 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1349 // Create MeshEditor
1350 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl, false );
1351 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1353 // Update Python script
1354 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1356 return aMesh._retn();
1359 //=============================================================================
1361 * Return mesh edition previewer
1363 //=============================================================================
1365 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1367 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl, true );
1368 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1369 return aMesh._retn();
1372 //=============================================================================
1374 * Export in different formats
1376 //=============================================================================
1378 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1380 return _impl->HasDuplicatedGroupNamesMED();
1383 static void PrepareForWriting (const char* file)
1385 TCollection_AsciiString aFullName ((char*)file);
1386 OSD_Path aPath (aFullName);
1387 OSD_File aFile (aPath);
1388 if (aFile.Exists()) {
1389 // existing filesystem node
1390 if (aFile.KindOfFile() == OSD_FILE) {
1391 if (aFile.IsWriteable()) {
1394 if (aFile.Failed()) {
1395 TCollection_AsciiString msg ("File ");
1396 msg += aFullName + " cannot be replaced.";
1397 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1400 TCollection_AsciiString msg ("File ");
1401 msg += aFullName + " cannot be overwritten.";
1402 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1405 TCollection_AsciiString msg ("Location ");
1406 msg += aFullName + " is not a file.";
1407 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1410 // nonexisting file; check if it can be created
1412 aFile.Build(OSD_WriteOnly, OSD_Protection());
1413 if (aFile.Failed()) {
1414 TCollection_AsciiString msg ("You cannot create the file ");
1415 msg += aFullName + ". Check the directory existance and access rights.";
1416 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1424 void SMESH_Mesh_i::ExportToMED (const char* file,
1425 CORBA::Boolean auto_groups,
1426 SMESH::MED_VERSION theVersion)
1427 throw(SALOME::SALOME_Exception)
1429 Unexpect aCatch(SALOME_SalomeException);
1431 // Update Python script
1432 TPythonDump() << _this() << ".ExportToMED( '"
1433 << file << "', " << auto_groups << ", " << theVersion << " )";
1436 PrepareForWriting(file);
1437 char* aMeshName = "Mesh";
1438 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1439 if ( !aStudy->_is_nil() ) {
1440 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1441 if ( !aMeshSO->_is_nil() ) {
1442 aMeshName = aMeshSO->GetName();
1444 //SCRUTE(aMeshName);
1445 //SCRUTE(aMeshSO->GetID());
1447 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1448 if ( !aStudy->GetProperties()->IsLocked() )
1450 SALOMEDS::GenericAttribute_var anAttr;
1451 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1452 SALOMEDS::AttributeExternalFileDef_var aFileName;
1453 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1454 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1455 ASSERT(!aFileName->_is_nil());
1456 aFileName->SetValue(file);
1457 SALOMEDS::AttributeFileType_var aFileType;
1458 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1459 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1460 ASSERT(!aFileType->_is_nil());
1461 aFileType->SetValue("FICHIERMED");
1465 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1468 void SMESH_Mesh_i::ExportMED (const char* file,
1469 CORBA::Boolean auto_groups)
1470 throw(SALOME::SALOME_Exception)
1472 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1475 void SMESH_Mesh_i::ExportDAT (const char *file)
1476 throw(SALOME::SALOME_Exception)
1478 Unexpect aCatch(SALOME_SalomeException);
1480 // Update Python script
1481 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1484 PrepareForWriting(file);
1485 _impl->ExportDAT(file);
1488 void SMESH_Mesh_i::ExportUNV (const char *file)
1489 throw(SALOME::SALOME_Exception)
1491 Unexpect aCatch(SALOME_SalomeException);
1493 // Update Python script
1494 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1497 PrepareForWriting(file);
1498 _impl->ExportUNV(file);
1501 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1502 throw(SALOME::SALOME_Exception)
1504 Unexpect aCatch(SALOME_SalomeException);
1506 // Update Python script
1507 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1510 PrepareForWriting(file);
1511 _impl->ExportSTL(file, isascii);
1514 //=============================================================================
1518 //=============================================================================
1520 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1522 Unexpect aCatch(SALOME_SalomeException);
1523 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1524 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1525 return aMesh._retn();
1528 //=============================================================================
1532 //=============================================================================
1533 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1535 Unexpect aCatch(SALOME_SalomeException);
1536 return _impl->NbNodes();
1539 //=============================================================================
1543 //=============================================================================
1544 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1546 Unexpect aCatch(SALOME_SalomeException);
1547 return NbEdges() + NbFaces() + NbVolumes();
1550 //=============================================================================
1554 //=============================================================================
1555 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1557 Unexpect aCatch(SALOME_SalomeException);
1558 return _impl->NbEdges();
1561 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1562 throw(SALOME::SALOME_Exception)
1564 Unexpect aCatch(SALOME_SalomeException);
1565 return _impl->NbEdges( (::SMESH_Mesh::ElementOrder) order);
1568 //=============================================================================
1572 //=============================================================================
1573 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1575 Unexpect aCatch(SALOME_SalomeException);
1576 return _impl->NbFaces();
1579 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1581 Unexpect aCatch(SALOME_SalomeException);
1582 return _impl->NbTriangles();
1585 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1587 Unexpect aCatch(SALOME_SalomeException);
1588 return _impl->NbQuadrangles();
1591 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1593 Unexpect aCatch(SALOME_SalomeException);
1594 return _impl->NbPolygons();
1597 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1598 throw(SALOME::SALOME_Exception)
1600 Unexpect aCatch(SALOME_SalomeException);
1601 return _impl->NbFaces( (::SMESH_Mesh::ElementOrder) order);
1604 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1605 throw(SALOME::SALOME_Exception)
1607 Unexpect aCatch(SALOME_SalomeException);
1608 return _impl->NbTriangles( (::SMESH_Mesh::ElementOrder) order);
1611 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1612 throw(SALOME::SALOME_Exception)
1614 Unexpect aCatch(SALOME_SalomeException);
1615 return _impl->NbQuadrangles( (::SMESH_Mesh::ElementOrder) order);
1618 //=============================================================================
1622 //=============================================================================
1623 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1625 Unexpect aCatch(SALOME_SalomeException);
1626 return _impl->NbVolumes();
1629 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1631 Unexpect aCatch(SALOME_SalomeException);
1632 return _impl->NbTetras();
1635 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1637 Unexpect aCatch(SALOME_SalomeException);
1638 return _impl->NbHexas();
1641 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1643 Unexpect aCatch(SALOME_SalomeException);
1644 return _impl->NbPyramids();
1647 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1649 Unexpect aCatch(SALOME_SalomeException);
1650 return _impl->NbPrisms();
1653 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1655 Unexpect aCatch(SALOME_SalomeException);
1656 return _impl->NbPolyhedrons();
1659 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1660 throw(SALOME::SALOME_Exception)
1662 Unexpect aCatch(SALOME_SalomeException);
1663 return _impl->NbVolumes( (::SMESH_Mesh::ElementOrder) order);
1666 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1667 throw(SALOME::SALOME_Exception)
1669 Unexpect aCatch(SALOME_SalomeException);
1670 return _impl->NbTetras( (::SMESH_Mesh::ElementOrder) order);
1673 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1674 throw(SALOME::SALOME_Exception)
1676 Unexpect aCatch(SALOME_SalomeException);
1677 return _impl->NbHexas( (::SMESH_Mesh::ElementOrder) order);
1680 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1681 throw(SALOME::SALOME_Exception)
1683 Unexpect aCatch(SALOME_SalomeException);
1684 return _impl->NbPyramids( (::SMESH_Mesh::ElementOrder) order);
1687 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1688 throw(SALOME::SALOME_Exception)
1690 Unexpect aCatch(SALOME_SalomeException);
1691 return _impl->NbPrisms( (::SMESH_Mesh::ElementOrder) order);
1694 //=============================================================================
1698 //=============================================================================
1699 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1701 Unexpect aCatch(SALOME_SalomeException);
1702 return _impl->NbSubMesh();
1705 //=============================================================================
1709 //=============================================================================
1710 char* SMESH_Mesh_i::Dump()
1712 std::ostringstream os;
1714 return CORBA::string_dup( os.str().c_str() );
1717 //=============================================================================
1721 //=============================================================================
1722 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1724 // SMESH::long_array_var aResult = new SMESH::long_array();
1725 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1726 // int aMinId = aSMESHDS_Mesh->MinElementID();
1727 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1729 // aResult->length(aMaxId - aMinId + 1);
1731 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1732 // aResult[i++] = id;
1734 // return aResult._retn();
1736 return GetElementsId();
1739 //=============================================================================
1743 //=============================================================================
1745 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1746 throw (SALOME::SALOME_Exception)
1748 Unexpect aCatch(SALOME_SalomeException);
1749 MESSAGE("SMESH_Mesh_i::GetElementsId");
1750 SMESH::long_array_var aResult = new SMESH::long_array();
1751 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1753 if ( aSMESHDS_Mesh == NULL )
1754 return aResult._retn();
1756 long nbElements = NbElements();
1757 aResult->length( nbElements );
1758 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1759 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1760 aResult[i] = anIt->next()->GetID();
1762 return aResult._retn();
1766 //=============================================================================
1770 //=============================================================================
1772 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1773 throw (SALOME::SALOME_Exception)
1775 Unexpect aCatch(SALOME_SalomeException);
1776 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1777 SMESH::long_array_var aResult = new SMESH::long_array();
1778 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1780 if ( aSMESHDS_Mesh == NULL )
1781 return aResult._retn();
1783 long nbElements = NbElements();
1785 // No sense in returning ids of elements along with ids of nodes:
1786 // when theElemType == SMESH::ALL, return node ids only if
1787 // there are no elements
1788 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1789 return GetNodesId();
1791 aResult->length( nbElements );
1795 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1796 while ( i < nbElements && anIt->more() ) {
1797 const SMDS_MeshElement* anElem = anIt->next();
1798 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1799 aResult[i++] = anElem->GetID();
1802 aResult->length( i );
1804 return aResult._retn();
1807 //=============================================================================
1811 //=============================================================================
1813 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1814 throw (SALOME::SALOME_Exception)
1816 Unexpect aCatch(SALOME_SalomeException);
1817 MESSAGE("SMESH_subMesh_i::GetNodesId");
1818 SMESH::long_array_var aResult = new SMESH::long_array();
1819 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1821 if ( aSMESHDS_Mesh == NULL )
1822 return aResult._retn();
1824 long nbNodes = NbNodes();
1825 aResult->length( nbNodes );
1826 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1827 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1828 aResult[i] = anIt->next()->GetID();
1830 return aResult._retn();
1833 //=============================================================================
1837 //=============================================================================
1839 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1840 throw (SALOME::SALOME_Exception)
1842 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1846 //=============================================================================
1848 * Returns ID of elements for given submesh
1850 //=============================================================================
1851 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1852 throw (SALOME::SALOME_Exception)
1854 SMESH::long_array_var aResult = new SMESH::long_array();
1856 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1857 if(!SM) return aResult._retn();
1859 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1860 if(!SDSM) return aResult._retn();
1862 aResult->length(SDSM->NbElements());
1864 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1866 while ( eIt->more() ) {
1867 aResult[i++] = eIt->next()->GetID();
1870 return aResult._retn();
1874 //=============================================================================
1876 * Returns ID of nodes for given submesh
1877 * If param all==true - returns all nodes, else -
1878 * returns only nodes on shapes.
1880 //=============================================================================
1881 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1882 throw (SALOME::SALOME_Exception)
1884 SMESH::long_array_var aResult = new SMESH::long_array();
1886 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1887 if(!SM) return aResult._retn();
1889 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1890 if(!SDSM) return aResult._retn();
1892 map<int,const SMDS_MeshElement*> theElems;
1893 if( !all || (SDSM->NbElements()==0 && SDSM->NbNodes()==1) ) {
1894 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1895 while ( nIt->more() ) {
1896 const SMDS_MeshNode* elem = nIt->next();
1897 theElems.insert( make_pair(elem->GetID(),elem) );
1900 else { // all nodes of submesh elements
1901 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1902 while ( eIt->more() ) {
1903 const SMDS_MeshElement* anElem = eIt->next();
1904 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1905 while ( nIt->more() ) {
1906 const SMDS_MeshElement* elem = nIt->next();
1907 theElems.insert( make_pair(elem->GetID(),elem) );
1912 aResult->length(theElems.size());
1913 map<int, const SMDS_MeshElement * >::iterator itElem;
1915 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1916 aResult[i++] = (*itElem).first;
1918 return aResult._retn();
1922 //=============================================================================
1924 * Returns type of elements for given submesh
1926 //=============================================================================
1927 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
1928 throw (SALOME::SALOME_Exception)
1930 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1931 if(!SM) return SMESH::ALL;
1933 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1934 if(!SDSM) return SMESH::ALL;
1936 if(SDSM->NbElements()==0)
1937 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
1939 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1940 const SMDS_MeshElement* anElem = eIt->next();
1941 return ( SMESH::ElementType ) anElem->GetType();
1945 //=============================================================================
1949 //=============================================================================
1951 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
1953 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
1954 cerr << "CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() " << pointeur << endl;
1959 //=============================================================================
1961 * Get XYZ coordinates of node as list of double
1962 * If there is not node for given ID - returns empty list
1964 //=============================================================================
1966 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
1968 SMESH::double_array_var aResult = new SMESH::double_array();
1969 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1970 if ( aSMESHDS_Mesh == NULL )
1971 return aResult._retn();
1974 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1976 return aResult._retn();
1980 aResult[0] = aNode->X();
1981 aResult[1] = aNode->Y();
1982 aResult[2] = aNode->Z();
1983 return aResult._retn();
1987 //=============================================================================
1989 * For given node returns list of IDs of inverse elements
1990 * If there is not node for given ID - returns empty list
1992 //=============================================================================
1994 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
1996 SMESH::long_array_var aResult = new SMESH::long_array();
1997 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1998 if ( aSMESHDS_Mesh == NULL )
1999 return aResult._retn();
2002 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2004 return aResult._retn();
2006 // find inverse elements
2007 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2008 TColStd_SequenceOfInteger IDs;
2009 while(eIt->more()) {
2010 const SMDS_MeshElement* elem = eIt->next();
2011 IDs.Append(elem->GetID());
2013 if(IDs.Length()>0) {
2014 aResult->length(IDs.Length());
2016 for(; i<=IDs.Length(); i++) {
2017 aResult[i-1] = IDs.Value(i);
2020 return aResult._retn();
2024 //=============================================================================
2026 * If given element is node returns IDs of shape from position
2027 * If there is not node for given ID - returns -1
2029 //=============================================================================
2031 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2033 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2034 if ( aSMESHDS_Mesh == NULL )
2038 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2040 SMDS_PositionPtr pos = aNode->GetPosition();
2044 return pos->GetShapeId();
2051 //=============================================================================
2053 * For given element returns ID of result shape after
2054 * ::FindShape() from SMESH_MeshEditor
2055 * If there is not element for given ID - returns -1
2057 //=============================================================================
2059 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2061 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2062 if ( aSMESHDS_Mesh == NULL )
2065 // try to find element
2066 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2070 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2071 ::SMESH_MeshEditor aMeshEditor(_impl);
2072 int index = aMeshEditor.FindShape( elem );
2080 //=============================================================================
2082 * Returns number of nodes for given element
2083 * If there is not element for given ID - returns -1
2085 //=============================================================================
2087 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2089 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2090 if ( aSMESHDS_Mesh == NULL ) return -1;
2091 // try to find element
2092 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2093 if(!elem) return -1;
2094 return elem->NbNodes();
2098 //=============================================================================
2100 * Returns ID of node by given index for given element
2101 * If there is not element for given ID - returns -1
2102 * If there is not node for given index - returns -2
2104 //=============================================================================
2106 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2108 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2109 if ( aSMESHDS_Mesh == NULL ) return -1;
2110 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2111 if(!elem) return -1;
2112 if( index>=elem->NbNodes() || index<0 ) return -1;
2113 return elem->GetNode(index)->GetID();
2116 //=============================================================================
2118 * Returns IDs of nodes of given element
2120 //=============================================================================
2122 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2124 SMESH::long_array_var aResult = new SMESH::long_array();
2125 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2127 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2129 aResult->length( elem->NbNodes() );
2130 for ( int i = 0; i < elem->NbNodes(); ++i )
2131 aResult[ i ] = elem->GetNode( i )->GetID();
2134 return aResult._retn();
2137 //=============================================================================
2139 * Returns true if given node is medium node
2140 * in given quadratic element
2142 //=============================================================================
2144 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2146 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2147 if ( aSMESHDS_Mesh == NULL ) return false;
2149 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2150 if(!aNode) return false;
2151 // try to find element
2152 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2153 if(!elem) return false;
2155 return elem->IsMediumNode(aNode);
2159 //=============================================================================
2161 * Returns true if given node is medium node
2162 * in one of quadratic elements
2164 //=============================================================================
2166 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2167 SMESH::ElementType theElemType)
2169 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2170 if ( aSMESHDS_Mesh == NULL ) return false;
2173 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2174 if(!aNode) return false;
2176 SMESH_MesherHelper aHelper( *(_impl) );
2178 SMDSAbs_ElementType aType;
2179 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2180 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2181 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2182 else aType = SMDSAbs_All;
2184 return aHelper.IsMedium(aNode,aType);
2188 //=============================================================================
2190 * Returns number of edges for given element
2192 //=============================================================================
2194 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2196 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2197 if ( aSMESHDS_Mesh == NULL ) return -1;
2198 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2199 if(!elem) return -1;
2200 return elem->NbEdges();
2204 //=============================================================================
2206 * Returns number of faces for given element
2208 //=============================================================================
2210 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2212 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2213 if ( aSMESHDS_Mesh == NULL ) return -1;
2214 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2215 if(!elem) return -1;
2216 return elem->NbFaces();
2220 //=============================================================================
2222 * Returns true if given element is polygon
2224 //=============================================================================
2226 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2228 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2229 if ( aSMESHDS_Mesh == NULL ) return false;
2230 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2231 if(!elem) return false;
2232 return elem->IsPoly();
2236 //=============================================================================
2238 * Returns true if given element is quadratic
2240 //=============================================================================
2242 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2244 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2245 if ( aSMESHDS_Mesh == NULL ) return false;
2246 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2247 if(!elem) return false;
2248 return elem->IsQuadratic();
2252 //=============================================================================
2254 * Returns bary center for given element
2256 //=============================================================================
2258 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2260 SMESH::double_array_var aResult = new SMESH::double_array();
2261 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2262 if ( aSMESHDS_Mesh == NULL )
2263 return aResult._retn();
2265 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2267 return aResult._retn();
2269 if(elem->GetType()==SMDSAbs_Volume) {
2270 // use SMDS_VolumeTool
2271 SMDS_VolumeTool aTool;
2272 if(aTool.Set(elem)) {
2273 double x=0., y=0., z=0.;
2274 if(aTool.GetBaryCenter(x,y,z)) {
2284 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2286 double x=0., y=0., z=0.;
2287 for(; anIt->more(); ) {
2289 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2303 return aResult._retn();
2307 //=============================================================================
2311 //=============================================================================
2312 void SMESH_Mesh_i::CreateGroupServants()
2314 // Create group servants, if any groups were imported
2315 list<int> aGroupIds = _impl->GetGroupIds();
2316 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
2317 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
2319 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2320 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2321 aGroupImpl->Register();
2322 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
2324 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
2325 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
2327 // register CORBA object for persistence
2328 int nextId = _gen_i->RegisterObject( aGroup );
2329 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);