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"
31 #include "SMESH_Filter_i.hxx"
32 #include "SMESH_Gen_i.hxx"
33 #include "SMESH_Group_i.hxx"
34 #include "SMESH_MEDMesh_i.hxx"
35 #include "SMESH_MeshEditor_i.hxx"
36 #include "SMESH_PythonDump.hxx"
37 #include "SMESH_subMesh_i.hxx"
39 #include "DriverMED_R_SMESHDS_Mesh.h"
40 #include "SMDS_VolumeTool.hxx"
41 #include "SMESHDS_Command.hxx"
42 #include "SMESHDS_CommandType.hxx"
43 #include "SMESHDS_GroupOnGeom.hxx"
44 #include "SMESH_Group.hxx"
45 #include "SMESH_MeshEditor.hxx"
46 #include "SMESH_MesherHelper.hxx"
49 #include "SALOME_NamingService.hxx"
50 #include "Utils_CorbaException.hxx"
51 #include "Utils_ExceptHandlers.hxx"
52 #include "Utils_SINGLETON.hxx"
53 #include "utilities.h"
56 #include <BRep_Builder.hxx>
57 #include <OSD_Path.hxx>
58 #include <OSD_File.hxx>
59 #include <OSD_Directory.hxx>
60 #include <OSD_Protection.hxx>
61 #include <TColStd_MapOfInteger.hxx>
62 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
63 #include <TColStd_SequenceOfInteger.hxx>
64 #include <TCollection_AsciiString.hxx>
65 #include <TopoDS_Compound.hxx>
73 static int MYDEBUG = 0;
75 static int MYDEBUG = 0;
79 using SMESH::TPythonDump;
81 int SMESH_Mesh_i::myIdGenerator = 0;
85 //=============================================================================
89 //=============================================================================
91 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
94 : SALOME::GenericObj_i( thePOA )
96 MESSAGE("SMESH_Mesh_i");
99 _id = myIdGenerator++;
101 thePOA->activate_object( this );
104 //=============================================================================
108 //=============================================================================
110 SMESH_Mesh_i::~SMESH_Mesh_i()
112 INFOS("~SMESH_Mesh_i");
113 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
114 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
115 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
118 // this method is colled from destructor of group (PAL6331)
119 //_impl->RemoveGroup( aGroup->GetLocalID() );
127 //=============================================================================
131 * Associates <this> mesh with <theShape> and puts a reference
132 * to <theShape> into the current study;
133 * the previous shape is substituted by the new one.
135 //=============================================================================
137 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
138 throw (SALOME::SALOME_Exception)
140 Unexpect aCatch(SALOME_SalomeException);
142 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
144 catch(SALOME_Exception & S_ex) {
145 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
149 //================================================================================
151 * \brief return true if mesh has a shape to build a shape on
153 //================================================================================
155 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
156 throw (SALOME::SALOME_Exception)
158 Unexpect aCatch(SALOME_SalomeException);
161 res = _impl->HasShapeToMesh();
163 catch(SALOME_Exception & S_ex) {
164 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
169 //=======================================================================
170 //function : GetShapeToMesh
172 //=======================================================================
174 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
175 throw (SALOME::SALOME_Exception)
177 Unexpect aCatch(SALOME_SalomeException);
178 GEOM::GEOM_Object_var aShapeObj;
180 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
182 aShapeObj = _gen_i->ShapeToGeomObject( S );
184 catch(SALOME_Exception & S_ex) {
185 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
187 return aShapeObj._retn();
190 //=============================================================================
194 //=============================================================================
196 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
198 SMESH::DriverMED_ReadStatus res;
201 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
202 res = SMESH::DRS_OK; break;
203 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
204 res = SMESH::DRS_EMPTY; break;
205 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
206 res = SMESH::DRS_WARN_RENUMBER; break;
207 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
208 res = SMESH::DRS_WARN_SKIP_ELEM; break;
209 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
211 res = SMESH::DRS_FAIL; break;
216 //=============================================================================
220 * Imports mesh data from MED file
222 //=============================================================================
224 SMESH::DriverMED_ReadStatus
225 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
226 throw ( SALOME::SALOME_Exception )
228 Unexpect aCatch(SALOME_SalomeException);
231 status = _impl->MEDToMesh( theFileName, theMeshName );
233 catch( SALOME_Exception& S_ex ) {
234 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
237 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
240 CreateGroupServants();
242 return ConvertDriverMEDReadStatus(status);
245 //=============================================================================
249 * Imports mesh data from MED file
251 //=============================================================================
253 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
254 throw ( SALOME::SALOME_Exception )
256 // Read mesh with name = <theMeshName> into SMESH_Mesh
257 _impl->UNVToMesh( theFileName );
259 CreateGroupServants();
264 //=============================================================================
268 * Imports mesh data from STL file
270 //=============================================================================
271 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
272 throw ( SALOME::SALOME_Exception )
274 // Read mesh with name = <theMeshName> into SMESH_Mesh
275 _impl->STLToMesh( theFileName );
280 //=============================================================================
284 * Imports mesh data from MED file
286 //=============================================================================
288 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
290 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
291 // int status = _impl->MEDToMesh( theFileName, theMeshName );
292 // CreateGroupServants();
297 //=============================================================================
301 //=============================================================================
303 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
305 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
306 (SMESH_Hypothesis::Hypothesis_Status theStatus)
309 RETURNCASE( HYP_OK );
310 RETURNCASE( HYP_MISSING );
311 RETURNCASE( HYP_CONCURENT );
312 RETURNCASE( HYP_BAD_PARAMETER );
313 RETURNCASE( HYP_HIDDEN_ALGO );
314 RETURNCASE( HYP_HIDING_ALGO );
315 RETURNCASE( HYP_UNKNOWN_FATAL );
316 RETURNCASE( HYP_INCOMPATIBLE );
317 RETURNCASE( HYP_NOTCONFORM );
318 RETURNCASE( HYP_ALREADY_EXIST );
319 RETURNCASE( HYP_BAD_DIM );
320 RETURNCASE( HYP_BAD_SUBSHAPE );
321 RETURNCASE( HYP_BAD_GEOMETRY );
324 return 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();
747 TPythonDump aPythonDump;
748 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
752 aList->length( _mapGroups.size() );
754 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
755 for ( ; it != _mapGroups.end(); it++ ) {
756 if ( CORBA::is_nil( it->second )) continue;
757 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
759 if (i > 1) aPythonDump << ", ";
760 aPythonDump << it->second;
764 catch(SALOME_Exception & S_ex) {
765 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
768 // Update Python script
769 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
770 aPythonDump << " ] = " << _this() << ".GetGroups()";
772 return aList._retn();
774 //=============================================================================
776 * Get number of groups existing in the mesh
778 //=============================================================================
780 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
782 Unexpect aCatch(SALOME_SalomeException);
783 return _mapGroups.size();
786 //=============================================================================
788 * New group is created. All mesh elements that are
789 * present in initial groups are added to the new one
791 //=============================================================================
792 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
793 SMESH::SMESH_GroupBase_ptr theGroup2,
794 const char* theName )
795 throw (SALOME::SALOME_Exception)
799 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
800 theGroup1->GetType() != theGroup2->GetType() )
801 return SMESH::SMESH_Group::_nil();
804 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
805 if ( aResGrp->_is_nil() )
806 return SMESH::SMESH_Group::_nil();
808 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
809 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
811 TColStd_MapOfInteger aResMap;
813 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
814 aResMap.Add( anIds1[ i1 ] );
816 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
817 aResMap.Add( anIds2[ i2 ] );
819 SMESH::long_array_var aResIds = new SMESH::long_array;
820 aResIds->length( aResMap.Extent() );
823 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
824 for( ; anIter.More(); anIter.Next() )
825 aResIds[ resI++ ] = anIter.Key();
827 aResGrp->Add( aResIds );
829 // Clear python lines, created by CreateGroup() and Add()
830 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
831 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
832 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
834 // Update Python script
835 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
836 << theGroup1 << ", " << theGroup2 << ", '"
839 return aResGrp._retn();
843 return SMESH::SMESH_Group::_nil();
847 //=============================================================================
849 * New group is created. All mesh elements that are
850 * present in both initial groups are added to the new one.
852 //=============================================================================
853 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
854 SMESH::SMESH_GroupBase_ptr theGroup2,
855 const char* theName )
856 throw (SALOME::SALOME_Exception)
858 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
859 theGroup1->GetType() != theGroup2->GetType() )
860 return SMESH::SMESH_Group::_nil();
862 // Create Intersection
863 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
864 if ( aResGrp->_is_nil() )
867 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
868 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
870 TColStd_MapOfInteger aMap1;
872 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
873 aMap1.Add( anIds1[ i1 ] );
875 TColStd_SequenceOfInteger aSeq;
877 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
878 if ( aMap1.Contains( anIds2[ i2 ] ) )
879 aSeq.Append( anIds2[ i2 ] );
881 SMESH::long_array_var aResIds = new SMESH::long_array;
882 aResIds->length( aSeq.Length() );
884 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
885 aResIds[ resI ] = aSeq( resI + 1 );
887 aResGrp->Add( aResIds );
889 // Clear python lines, created by CreateGroup() and Add()
890 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
891 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
892 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
894 // Update Python script
895 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
896 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
898 return aResGrp._retn();
901 //=============================================================================
903 * New group is created. All mesh elements that are present in
904 * main group but do not present in tool group are added to the new one
906 //=============================================================================
907 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
908 SMESH::SMESH_GroupBase_ptr theGroup2,
909 const char* theName )
910 throw (SALOME::SALOME_Exception)
912 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
913 theGroup1->GetType() != theGroup2->GetType() )
914 return SMESH::SMESH_Group::_nil();
917 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
918 if ( aResGrp->_is_nil() )
921 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
922 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
924 TColStd_MapOfInteger aMap2;
926 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
927 aMap2.Add( anIds2[ i2 ] );
930 TColStd_SequenceOfInteger aSeq;
931 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
932 if ( !aMap2.Contains( anIds1[ i1 ] ) )
933 aSeq.Append( anIds1[ i1 ] );
935 SMESH::long_array_var aResIds = new SMESH::long_array;
936 aResIds->length( aSeq.Length() );
938 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
939 aResIds[ resI ] = aSeq( resI + 1 );
941 aResGrp->Add( aResIds );
943 // Clear python lines, created by CreateGroup() and Add()
944 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
945 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
946 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
948 // Update Python script
949 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
950 << theGroup1 << ", " << theGroup2 << ", '"
953 return aResGrp._retn();
956 //================================================================================
958 * \brief Return group items of a group present in a study
960 //================================================================================
962 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
964 list<TopoDS_Shape> & theItems)
966 GEOM::GEOM_Object_var groupObj;
967 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
968 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
969 if ( study->_is_nil() || geomGen->_is_nil() )
970 return groupObj._retn();
972 GEOM::GEOM_IGroupOperations_var groupOp =
973 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
974 GEOM::GEOM_IShapesOperations_var shapeOp =
975 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
977 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
978 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
979 return groupObj._retn();
980 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
981 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
982 return groupObj._retn(); // keep only submeshes on groups
984 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
985 if ( anIter->_is_nil() ) return groupObj._retn();
986 for ( ; anIter->More(); anIter->Next())
988 SALOMEDS::SObject_var aSObject = anIter->Value();
989 SALOMEDS::SObject_var aRefSO;
990 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
992 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
993 if ( groupObj->_is_nil() ) break;
994 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
995 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
996 for ( int i = 0; i < ids->length(); ++i ) {
997 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
998 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1000 theItems.push_back( S );
1005 return groupObj._retn();
1008 //=============================================================================
1010 * \brief Update hypotheses assigned to geom groups if the latter change
1012 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1014 //=============================================================================
1016 void SMESH_Mesh_i::CheckGeomGroupModif()
1018 if ( !_impl->HasShapeToMesh() ) return;
1020 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1021 if ( study->_is_nil() ) return;
1023 // check if items of groups changed
1024 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1025 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1027 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1028 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1029 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1031 int oldID = i_sm->first;
1032 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1033 if ( i_smIor == _mapSubMeshIor.end() )
1035 list< TopoDS_Shape> newItems;
1036 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1037 if ( groupObj->_is_nil() )
1040 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1041 int nbNewItems = newItems.size();
1042 bool groupChanged = ( nbOldItems != nbNewItems);
1043 if ( !groupChanged ) {
1044 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1045 groupChanged = ( oldGroupShape != newItems.front() );
1048 list<TopoDS_Shape>::iterator item = newItems.begin();
1049 for ( ; item != newItems.end() && !groupChanged; ++item )
1051 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1052 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1056 // update hypotheses and submeshes if necessary
1059 // get a new group shape
1060 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1061 if ( !geomClient ) continue;
1062 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1063 geomClient->RemoveShapeFromBuffer( groupIOR );
1064 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1065 // update hypotheses
1066 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1067 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1068 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1070 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1071 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1073 // care of submeshes
1074 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1075 int newID = newSubmesh->GetId();
1076 if ( newID != oldID ) {
1077 _mapSubMesh [ newID ] = newSubmesh;
1078 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1079 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1080 _mapSubMesh.erase (oldID);
1081 _mapSubMesh_i.erase (oldID);
1082 _mapSubMeshIor.erase(oldID);
1083 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1089 //=============================================================================
1093 //=============================================================================
1095 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1097 if(MYDEBUG) MESSAGE( "createSubMesh" );
1098 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1100 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1101 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1102 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1103 SMESH::SMESH_subMesh_var subMesh
1104 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1106 _mapSubMesh[subMeshId] = mySubMesh;
1107 _mapSubMesh_i[subMeshId] = subMeshServant;
1108 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1110 // register CORBA object for persistence
1111 int nextId = _gen_i->RegisterObject( subMesh );
1112 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1114 return subMesh._retn();
1117 //=======================================================================
1118 //function : getSubMesh
1120 //=======================================================================
1122 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1124 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1125 if ( it == _mapSubMeshIor.end() )
1126 return SMESH::SMESH_subMesh::_nil();
1128 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1132 //=============================================================================
1136 //=============================================================================
1138 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1139 GEOM::GEOM_Object_ptr theSubShapeObject )
1141 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1142 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1146 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1147 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1148 removeHypothesis( theSubShapeObject, aHypList[i] );
1151 catch( const SALOME::SALOME_Exception& ) {
1152 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1155 int subMeshId = theSubMesh->GetId();
1157 _mapSubMesh.erase(subMeshId);
1158 _mapSubMesh_i.erase(subMeshId);
1159 _mapSubMeshIor.erase(subMeshId);
1160 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1163 //=============================================================================
1167 //=============================================================================
1169 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1170 const char* theName,
1171 const TopoDS_Shape& theShape )
1174 SMESH::SMESH_GroupBase_var aGroup;
1175 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1176 SMESH_GroupBase_i* aGroupImpl;
1177 if ( !theShape.IsNull() )
1178 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1180 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1182 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1183 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1184 aGroupImpl->Register();
1185 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1187 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1188 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1190 // register CORBA object for persistence
1191 int nextId = _gen_i->RegisterObject( aGroup );
1192 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1194 return aGroup._retn();
1197 //=============================================================================
1199 * SMESH_Mesh_i::removeGroup
1201 * Should be called by ~SMESH_Group_i()
1203 //=============================================================================
1205 void SMESH_Mesh_i::removeGroup( const int theId )
1207 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1208 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1209 _mapGroups.erase( theId );
1210 _impl->RemoveGroup( theId );
1215 //=============================================================================
1219 //=============================================================================
1221 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1222 throw(SALOME::SALOME_Exception)
1224 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1226 SMESH::log_array_var aLog;
1228 list < SMESHDS_Command * >logDS = _impl->GetLog();
1229 aLog = new SMESH::log_array;
1231 int lg = logDS.size();
1234 list < SMESHDS_Command * >::iterator its = logDS.begin();
1235 while(its != logDS.end()){
1236 SMESHDS_Command *com = *its;
1237 int comType = com->GetType();
1239 int lgcom = com->GetNumber();
1241 const list < int >&intList = com->GetIndexes();
1242 int inum = intList.size();
1244 list < int >::const_iterator ii = intList.begin();
1245 const list < double >&coordList = com->GetCoords();
1246 int rnum = coordList.size();
1248 list < double >::const_iterator ir = coordList.begin();
1249 aLog[indexLog].commandType = comType;
1250 aLog[indexLog].number = lgcom;
1251 aLog[indexLog].coords.length(rnum);
1252 aLog[indexLog].indexes.length(inum);
1253 for(int i = 0; i < rnum; i++){
1254 aLog[indexLog].coords[i] = *ir;
1255 //MESSAGE(" "<<i<<" "<<ir.Value());
1258 for(int i = 0; i < inum; i++){
1259 aLog[indexLog].indexes[i] = *ii;
1260 //MESSAGE(" "<<i<<" "<<ii.Value());
1269 catch(SALOME_Exception & S_ex){
1270 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1272 return aLog._retn();
1276 //=============================================================================
1280 //=============================================================================
1282 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1284 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1288 //=============================================================================
1292 //=============================================================================
1294 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1296 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1300 //=============================================================================
1304 //=============================================================================
1306 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1311 //=============================================================================
1315 //=============================================================================
1317 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1319 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1323 //=============================================================================
1327 //=============================================================================
1329 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1331 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1335 //=============================================================================
1337 * Return mesh editor
1339 //=============================================================================
1341 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1343 // Create MeshEditor
1344 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1345 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1347 // Update Python script
1348 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1350 return aMesh._retn();
1353 //=============================================================================
1355 * Return mesh edition previewer
1357 //=============================================================================
1359 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1361 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1362 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1363 return aMesh._retn();
1366 //=============================================================================
1368 * Export in different formats
1370 //=============================================================================
1372 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1374 return _impl->HasDuplicatedGroupNamesMED();
1377 static void PrepareForWriting (const char* file)
1379 TCollection_AsciiString aFullName ((char*)file);
1380 OSD_Path aPath (aFullName);
1381 OSD_File aFile (aPath);
1382 if (aFile.Exists()) {
1383 // existing filesystem node
1384 if (aFile.KindOfFile() == OSD_FILE) {
1385 if (aFile.IsWriteable()) {
1388 if (aFile.Failed()) {
1389 TCollection_AsciiString msg ("File ");
1390 msg += aFullName + " cannot be replaced.";
1391 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1394 TCollection_AsciiString msg ("File ");
1395 msg += aFullName + " cannot be overwritten.";
1396 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1399 TCollection_AsciiString msg ("Location ");
1400 msg += aFullName + " is not a file.";
1401 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1404 // nonexisting file; check if it can be created
1406 aFile.Build(OSD_WriteOnly, OSD_Protection());
1407 if (aFile.Failed()) {
1408 TCollection_AsciiString msg ("You cannot create the file ");
1409 msg += aFullName + ". Check the directory existance and access rights.";
1410 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1418 void SMESH_Mesh_i::ExportToMED (const char* file,
1419 CORBA::Boolean auto_groups,
1420 SMESH::MED_VERSION theVersion)
1421 throw(SALOME::SALOME_Exception)
1423 Unexpect aCatch(SALOME_SalomeException);
1425 // Update Python script
1426 TPythonDump() << _this() << ".ExportToMED( '"
1427 << file << "', " << auto_groups << ", " << theVersion << " )";
1430 PrepareForWriting(file);
1431 char* aMeshName = "Mesh";
1432 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1433 if ( !aStudy->_is_nil() ) {
1434 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1435 if ( !aMeshSO->_is_nil() ) {
1436 aMeshName = aMeshSO->GetName();
1438 //SCRUTE(aMeshName);
1439 //SCRUTE(aMeshSO->GetID());
1441 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1442 if ( !aStudy->GetProperties()->IsLocked() )
1444 SALOMEDS::GenericAttribute_var anAttr;
1445 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1446 SALOMEDS::AttributeExternalFileDef_var aFileName;
1447 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1448 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1449 ASSERT(!aFileName->_is_nil());
1450 aFileName->SetValue(file);
1451 SALOMEDS::AttributeFileType_var aFileType;
1452 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1453 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1454 ASSERT(!aFileType->_is_nil());
1455 aFileType->SetValue("FICHIERMED");
1459 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1462 void SMESH_Mesh_i::ExportMED (const char* file,
1463 CORBA::Boolean auto_groups)
1464 throw(SALOME::SALOME_Exception)
1466 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1469 void SMESH_Mesh_i::ExportDAT (const char *file)
1470 throw(SALOME::SALOME_Exception)
1472 Unexpect aCatch(SALOME_SalomeException);
1474 // Update Python script
1475 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1478 PrepareForWriting(file);
1479 _impl->ExportDAT(file);
1482 void SMESH_Mesh_i::ExportUNV (const char *file)
1483 throw(SALOME::SALOME_Exception)
1485 Unexpect aCatch(SALOME_SalomeException);
1487 // Update Python script
1488 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1491 PrepareForWriting(file);
1492 _impl->ExportUNV(file);
1495 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1496 throw(SALOME::SALOME_Exception)
1498 Unexpect aCatch(SALOME_SalomeException);
1500 // Update Python script
1501 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1504 PrepareForWriting(file);
1505 _impl->ExportSTL(file, isascii);
1508 //=============================================================================
1512 //=============================================================================
1514 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1516 Unexpect aCatch(SALOME_SalomeException);
1517 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1518 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1519 return aMesh._retn();
1522 //=============================================================================
1526 //=============================================================================
1527 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1529 Unexpect aCatch(SALOME_SalomeException);
1530 return _impl->NbNodes();
1533 //=============================================================================
1537 //=============================================================================
1538 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1540 Unexpect aCatch(SALOME_SalomeException);
1541 return NbEdges() + NbFaces() + NbVolumes();
1544 //=============================================================================
1548 //=============================================================================
1549 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1551 Unexpect aCatch(SALOME_SalomeException);
1552 return _impl->NbEdges();
1555 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1556 throw(SALOME::SALOME_Exception)
1558 Unexpect aCatch(SALOME_SalomeException);
1559 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
1562 //=============================================================================
1566 //=============================================================================
1567 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1569 Unexpect aCatch(SALOME_SalomeException);
1570 return _impl->NbFaces();
1573 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1575 Unexpect aCatch(SALOME_SalomeException);
1576 return _impl->NbTriangles();
1579 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1581 Unexpect aCatch(SALOME_SalomeException);
1582 return _impl->NbQuadrangles();
1585 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1587 Unexpect aCatch(SALOME_SalomeException);
1588 return _impl->NbPolygons();
1591 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1592 throw(SALOME::SALOME_Exception)
1594 Unexpect aCatch(SALOME_SalomeException);
1595 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
1598 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1599 throw(SALOME::SALOME_Exception)
1601 Unexpect aCatch(SALOME_SalomeException);
1602 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
1605 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1606 throw(SALOME::SALOME_Exception)
1608 Unexpect aCatch(SALOME_SalomeException);
1609 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
1612 //=============================================================================
1616 //=============================================================================
1617 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1619 Unexpect aCatch(SALOME_SalomeException);
1620 return _impl->NbVolumes();
1623 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1625 Unexpect aCatch(SALOME_SalomeException);
1626 return _impl->NbTetras();
1629 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1631 Unexpect aCatch(SALOME_SalomeException);
1632 return _impl->NbHexas();
1635 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1637 Unexpect aCatch(SALOME_SalomeException);
1638 return _impl->NbPyramids();
1641 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1643 Unexpect aCatch(SALOME_SalomeException);
1644 return _impl->NbPrisms();
1647 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1649 Unexpect aCatch(SALOME_SalomeException);
1650 return _impl->NbPolyhedrons();
1653 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1654 throw(SALOME::SALOME_Exception)
1656 Unexpect aCatch(SALOME_SalomeException);
1657 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
1660 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1661 throw(SALOME::SALOME_Exception)
1663 Unexpect aCatch(SALOME_SalomeException);
1664 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
1667 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1668 throw(SALOME::SALOME_Exception)
1670 Unexpect aCatch(SALOME_SalomeException);
1671 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
1674 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1675 throw(SALOME::SALOME_Exception)
1677 Unexpect aCatch(SALOME_SalomeException);
1678 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
1681 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1682 throw(SALOME::SALOME_Exception)
1684 Unexpect aCatch(SALOME_SalomeException);
1685 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
1688 //=============================================================================
1692 //=============================================================================
1693 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1695 Unexpect aCatch(SALOME_SalomeException);
1696 return _impl->NbSubMesh();
1699 //=============================================================================
1703 //=============================================================================
1704 char* SMESH_Mesh_i::Dump()
1706 std::ostringstream os;
1708 return CORBA::string_dup( os.str().c_str() );
1711 //=============================================================================
1715 //=============================================================================
1716 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1718 // SMESH::long_array_var aResult = new SMESH::long_array();
1719 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1720 // int aMinId = aSMESHDS_Mesh->MinElementID();
1721 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1723 // aResult->length(aMaxId - aMinId + 1);
1725 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1726 // aResult[i++] = id;
1728 // return aResult._retn();
1730 return GetElementsId();
1733 //=============================================================================
1737 //=============================================================================
1739 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1740 throw (SALOME::SALOME_Exception)
1742 Unexpect aCatch(SALOME_SalomeException);
1743 MESSAGE("SMESH_Mesh_i::GetElementsId");
1744 SMESH::long_array_var aResult = new SMESH::long_array();
1745 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1747 if ( aSMESHDS_Mesh == NULL )
1748 return aResult._retn();
1750 long nbElements = NbElements();
1751 aResult->length( nbElements );
1752 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1753 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1754 aResult[i] = anIt->next()->GetID();
1756 return aResult._retn();
1760 //=============================================================================
1764 //=============================================================================
1766 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1767 throw (SALOME::SALOME_Exception)
1769 Unexpect aCatch(SALOME_SalomeException);
1770 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1771 SMESH::long_array_var aResult = new SMESH::long_array();
1772 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1774 if ( aSMESHDS_Mesh == NULL )
1775 return aResult._retn();
1777 long nbElements = NbElements();
1779 // No sense in returning ids of elements along with ids of nodes:
1780 // when theElemType == SMESH::ALL, return node ids only if
1781 // there are no elements
1782 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1783 return GetNodesId();
1785 aResult->length( nbElements );
1789 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1790 while ( i < nbElements && anIt->more() ) {
1791 const SMDS_MeshElement* anElem = anIt->next();
1792 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1793 aResult[i++] = anElem->GetID();
1796 aResult->length( i );
1798 return aResult._retn();
1801 //=============================================================================
1805 //=============================================================================
1807 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1808 throw (SALOME::SALOME_Exception)
1810 Unexpect aCatch(SALOME_SalomeException);
1811 MESSAGE("SMESH_subMesh_i::GetNodesId");
1812 SMESH::long_array_var aResult = new SMESH::long_array();
1813 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1815 if ( aSMESHDS_Mesh == NULL )
1816 return aResult._retn();
1818 long nbNodes = NbNodes();
1819 aResult->length( nbNodes );
1820 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1821 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1822 aResult[i] = anIt->next()->GetID();
1824 return aResult._retn();
1827 //=============================================================================
1831 //=============================================================================
1833 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1834 throw (SALOME::SALOME_Exception)
1836 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1840 //=============================================================================
1842 * Returns ID of elements for given submesh
1844 //=============================================================================
1845 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1846 throw (SALOME::SALOME_Exception)
1848 SMESH::long_array_var aResult = new SMESH::long_array();
1850 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1851 if(!SM) return aResult._retn();
1853 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1854 if(!SDSM) return aResult._retn();
1856 aResult->length(SDSM->NbElements());
1858 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1860 while ( eIt->more() ) {
1861 aResult[i++] = eIt->next()->GetID();
1864 return aResult._retn();
1868 //=============================================================================
1870 * Returns ID of nodes for given submesh
1871 * If param all==true - returns all nodes, else -
1872 * returns only nodes on shapes.
1874 //=============================================================================
1875 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1876 throw (SALOME::SALOME_Exception)
1878 SMESH::long_array_var aResult = new SMESH::long_array();
1880 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1881 if(!SM) return aResult._retn();
1883 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1884 if(!SDSM) return aResult._retn();
1886 map<int,const SMDS_MeshElement*> theElems;
1887 if( !all || (SDSM->NbElements()==0 && SDSM->NbNodes()==1) ) {
1888 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1889 while ( nIt->more() ) {
1890 const SMDS_MeshNode* elem = nIt->next();
1891 theElems.insert( make_pair(elem->GetID(),elem) );
1894 else { // all nodes of submesh elements
1895 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1896 while ( eIt->more() ) {
1897 const SMDS_MeshElement* anElem = eIt->next();
1898 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1899 while ( nIt->more() ) {
1900 const SMDS_MeshElement* elem = nIt->next();
1901 theElems.insert( make_pair(elem->GetID(),elem) );
1906 aResult->length(theElems.size());
1907 map<int, const SMDS_MeshElement * >::iterator itElem;
1909 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1910 aResult[i++] = (*itElem).first;
1912 return aResult._retn();
1916 //=============================================================================
1918 * Returns type of elements for given submesh
1920 //=============================================================================
1921 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
1922 throw (SALOME::SALOME_Exception)
1924 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1925 if(!SM) return SMESH::ALL;
1927 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1928 if(!SDSM) return SMESH::ALL;
1930 if(SDSM->NbElements()==0)
1931 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
1933 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1934 const SMDS_MeshElement* anElem = eIt->next();
1935 return ( SMESH::ElementType ) anElem->GetType();
1939 //=============================================================================
1943 //=============================================================================
1945 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
1947 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
1948 cerr << "CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() " << pointeur << endl;
1953 //=============================================================================
1955 * Get XYZ coordinates of node as list of double
1956 * If there is not node for given ID - returns empty list
1958 //=============================================================================
1960 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
1962 SMESH::double_array_var aResult = new SMESH::double_array();
1963 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1964 if ( aSMESHDS_Mesh == NULL )
1965 return aResult._retn();
1968 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1970 return aResult._retn();
1974 aResult[0] = aNode->X();
1975 aResult[1] = aNode->Y();
1976 aResult[2] = aNode->Z();
1977 return aResult._retn();
1981 //=============================================================================
1983 * For given node returns list of IDs of inverse elements
1984 * If there is not node for given ID - returns empty list
1986 //=============================================================================
1988 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
1990 SMESH::long_array_var aResult = new SMESH::long_array();
1991 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1992 if ( aSMESHDS_Mesh == NULL )
1993 return aResult._retn();
1996 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
1998 return aResult._retn();
2000 // find inverse elements
2001 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2002 TColStd_SequenceOfInteger IDs;
2003 while(eIt->more()) {
2004 const SMDS_MeshElement* elem = eIt->next();
2005 IDs.Append(elem->GetID());
2007 if(IDs.Length()>0) {
2008 aResult->length(IDs.Length());
2010 for(; i<=IDs.Length(); i++) {
2011 aResult[i-1] = IDs.Value(i);
2014 return aResult._retn();
2018 //=============================================================================
2020 * If given element is node returns IDs of shape from position
2021 * If there is not node for given ID - returns -1
2023 //=============================================================================
2025 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2027 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2028 if ( aSMESHDS_Mesh == NULL )
2032 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2034 SMDS_PositionPtr pos = aNode->GetPosition();
2038 return pos->GetShapeId();
2045 //=============================================================================
2047 * For given element returns ID of result shape after
2048 * ::FindShape() from SMESH_MeshEditor
2049 * If there is not element for given ID - returns -1
2051 //=============================================================================
2053 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2055 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2056 if ( aSMESHDS_Mesh == NULL )
2059 // try to find element
2060 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2064 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2065 ::SMESH_MeshEditor aMeshEditor(_impl);
2066 int index = aMeshEditor.FindShape( elem );
2074 //=============================================================================
2076 * Returns number of nodes for given element
2077 * If there is not element for given ID - returns -1
2079 //=============================================================================
2081 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2083 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2084 if ( aSMESHDS_Mesh == NULL ) return -1;
2085 // try to find element
2086 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2087 if(!elem) return -1;
2088 return elem->NbNodes();
2092 //=============================================================================
2094 * Returns ID of node by given index for given element
2095 * If there is not element for given ID - returns -1
2096 * If there is not node for given index - returns -2
2098 //=============================================================================
2100 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2102 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2103 if ( aSMESHDS_Mesh == NULL ) return -1;
2104 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2105 if(!elem) return -1;
2106 if( index>=elem->NbNodes() || index<0 ) return -1;
2107 return elem->GetNode(index)->GetID();
2110 //=============================================================================
2112 * Returns IDs of nodes of given element
2114 //=============================================================================
2116 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2118 SMESH::long_array_var aResult = new SMESH::long_array();
2119 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2121 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2123 aResult->length( elem->NbNodes() );
2124 for ( int i = 0; i < elem->NbNodes(); ++i )
2125 aResult[ i ] = elem->GetNode( i )->GetID();
2128 return aResult._retn();
2131 //=============================================================================
2133 * Returns true if given node is medium node
2134 * in given quadratic element
2136 //=============================================================================
2138 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2140 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2141 if ( aSMESHDS_Mesh == NULL ) return false;
2143 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2144 if(!aNode) return false;
2145 // try to find element
2146 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2147 if(!elem) return false;
2149 return elem->IsMediumNode(aNode);
2153 //=============================================================================
2155 * Returns true if given node is medium node
2156 * in one of quadratic elements
2158 //=============================================================================
2160 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2161 SMESH::ElementType theElemType)
2163 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2164 if ( aSMESHDS_Mesh == NULL ) return false;
2167 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2168 if(!aNode) return false;
2170 SMESH_MesherHelper aHelper( *(_impl) );
2172 SMDSAbs_ElementType aType;
2173 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2174 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2175 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2176 else aType = SMDSAbs_All;
2178 return aHelper.IsMedium(aNode,aType);
2182 //=============================================================================
2184 * Returns number of edges for given element
2186 //=============================================================================
2188 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2190 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2191 if ( aSMESHDS_Mesh == NULL ) return -1;
2192 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2193 if(!elem) return -1;
2194 return elem->NbEdges();
2198 //=============================================================================
2200 * Returns number of faces for given element
2202 //=============================================================================
2204 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2206 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2207 if ( aSMESHDS_Mesh == NULL ) return -1;
2208 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2209 if(!elem) return -1;
2210 return elem->NbFaces();
2214 //=============================================================================
2216 * Returns true if given element is polygon
2218 //=============================================================================
2220 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2222 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2223 if ( aSMESHDS_Mesh == NULL ) return false;
2224 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2225 if(!elem) return false;
2226 return elem->IsPoly();
2230 //=============================================================================
2232 * Returns true if given element is quadratic
2234 //=============================================================================
2236 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2238 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2239 if ( aSMESHDS_Mesh == NULL ) return false;
2240 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2241 if(!elem) return false;
2242 return elem->IsQuadratic();
2246 //=============================================================================
2248 * Returns bary center for given element
2250 //=============================================================================
2252 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2254 SMESH::double_array_var aResult = new SMESH::double_array();
2255 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2256 if ( aSMESHDS_Mesh == NULL )
2257 return aResult._retn();
2259 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2261 return aResult._retn();
2263 if(elem->GetType()==SMDSAbs_Volume) {
2264 SMDS_VolumeTool aTool;
2265 if(aTool.Set(elem)) {
2267 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2272 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2274 double x=0., y=0., z=0.;
2275 for(; anIt->more(); ) {
2277 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2291 return aResult._retn();
2295 //=============================================================================
2297 * Create and publish group servants if any groups were imported or created anyhow
2299 //=============================================================================
2301 void SMESH_Mesh_i::CreateGroupServants()
2303 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2305 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2306 while ( groupIt->more() )
2308 ::SMESH_Group* group = groupIt->next();
2309 int anId = group->GetGroupDS()->GetID();
2311 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
2312 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2315 SMESH_GroupBase_i* aGroupImpl;
2317 if ( SMESHDS_GroupOnGeom* groupOnGeom =
2318 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
2320 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2321 shape = groupOnGeom->GetShape();
2324 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2327 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
2328 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2329 aGroupImpl->Register();
2331 SMESH::SMESH_GroupBase_var groupVar =
2332 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2333 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
2335 // register CORBA object for persistence
2336 int nextId = _gen_i->RegisterObject( groupVar );
2337 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2339 // publishing of the groups in the study
2340 if ( !aStudy->_is_nil() ) {
2341 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
2342 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
2347 //=============================================================================
2349 * \brief Return groups cantained in _mapGroups by their IDs
2351 //=============================================================================
2353 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
2355 int nbGroups = groupIDs.size();
2356 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
2357 aList->length( nbGroups );
2359 list<int>::const_iterator ids = groupIDs.begin();
2360 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
2362 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
2363 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2364 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
2366 aList->length( nbGroups );
2367 return aList._retn();