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"
47 #include "SMDS_EdgePosition.hxx"
48 #include "SMDS_FacePosition.hxx"
51 #include "SALOME_NamingService.hxx"
52 #include "Utils_CorbaException.hxx"
53 #include "Utils_ExceptHandlers.hxx"
54 #include "Utils_SINGLETON.hxx"
55 #include "utilities.h"
58 #include <BRep_Builder.hxx>
59 #include <OSD_Directory.hxx>
60 #include <OSD_File.hxx>
61 #include <OSD_Path.hxx>
62 #include <OSD_Protection.hxx>
63 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
64 #include <TColStd_MapOfInteger.hxx>
65 #include <TColStd_SequenceOfInteger.hxx>
66 #include <TCollection_AsciiString.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopoDS_Compound.hxx>
76 static int MYDEBUG = 0;
78 static int MYDEBUG = 0;
82 using SMESH::TPythonDump;
84 int SMESH_Mesh_i::myIdGenerator = 0;
88 //=============================================================================
92 //=============================================================================
94 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
97 : SALOME::GenericObj_i( thePOA )
99 MESSAGE("SMESH_Mesh_i");
102 _id = myIdGenerator++;
106 //=============================================================================
110 //=============================================================================
112 SMESH_Mesh_i::~SMESH_Mesh_i()
114 INFOS("~SMESH_Mesh_i");
115 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
116 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
117 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
120 // this method is colled from destructor of group (PAL6331)
121 //_impl->RemoveGroup( aGroup->GetLocalID() );
129 //=============================================================================
133 * Associates <this> mesh with <theShape> and puts a reference
134 * to <theShape> into the current study;
135 * the previous shape is substituted by the new one.
137 //=============================================================================
139 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
140 throw (SALOME::SALOME_Exception)
142 Unexpect aCatch(SALOME_SalomeException);
144 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
146 catch(SALOME_Exception & S_ex) {
147 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
151 //================================================================================
153 * \brief return true if mesh has a shape to build a shape on
155 //================================================================================
157 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
158 throw (SALOME::SALOME_Exception)
160 Unexpect aCatch(SALOME_SalomeException);
163 res = _impl->HasShapeToMesh();
165 catch(SALOME_Exception & S_ex) {
166 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
171 //=======================================================================
172 //function : GetShapeToMesh
174 //=======================================================================
176 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
177 throw (SALOME::SALOME_Exception)
179 Unexpect aCatch(SALOME_SalomeException);
180 GEOM::GEOM_Object_var aShapeObj;
182 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
184 aShapeObj = _gen_i->ShapeToGeomObject( S );
186 catch(SALOME_Exception & S_ex) {
187 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
189 return aShapeObj._retn();
192 //=============================================================================
196 //=============================================================================
198 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
200 SMESH::DriverMED_ReadStatus res;
203 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
204 res = SMESH::DRS_OK; break;
205 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
206 res = SMESH::DRS_EMPTY; break;
207 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
208 res = SMESH::DRS_WARN_RENUMBER; break;
209 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
210 res = SMESH::DRS_WARN_SKIP_ELEM; break;
211 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
213 res = SMESH::DRS_FAIL; break;
218 //=============================================================================
222 * Imports mesh data from MED file
224 //=============================================================================
226 SMESH::DriverMED_ReadStatus
227 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
228 throw ( SALOME::SALOME_Exception )
230 Unexpect aCatch(SALOME_SalomeException);
233 status = _impl->MEDToMesh( theFileName, theMeshName );
235 catch( SALOME_Exception& S_ex ) {
236 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
239 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
242 CreateGroupServants();
244 return ConvertDriverMEDReadStatus(status);
247 //=============================================================================
251 * Imports mesh data from MED file
253 //=============================================================================
255 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
256 throw ( SALOME::SALOME_Exception )
258 // Read mesh with name = <theMeshName> into SMESH_Mesh
259 _impl->UNVToMesh( theFileName );
261 CreateGroupServants();
266 //=============================================================================
270 * Imports mesh data from STL file
272 //=============================================================================
273 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
274 throw ( SALOME::SALOME_Exception )
276 // Read mesh with name = <theMeshName> into SMESH_Mesh
277 _impl->STLToMesh( theFileName );
282 //=============================================================================
286 * Imports mesh data from MED file
288 //=============================================================================
290 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
292 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
293 // int status = _impl->MEDToMesh( theFileName, theMeshName );
294 // CreateGroupServants();
299 //=============================================================================
303 //=============================================================================
305 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
307 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
308 (SMESH_Hypothesis::Hypothesis_Status theStatus)
311 RETURNCASE( HYP_OK );
312 RETURNCASE( HYP_MISSING );
313 RETURNCASE( HYP_CONCURENT );
314 RETURNCASE( HYP_BAD_PARAMETER );
315 RETURNCASE( HYP_HIDDEN_ALGO );
316 RETURNCASE( HYP_HIDING_ALGO );
317 RETURNCASE( HYP_UNKNOWN_FATAL );
318 RETURNCASE( HYP_INCOMPATIBLE );
319 RETURNCASE( HYP_NOTCONFORM );
320 RETURNCASE( HYP_ALREADY_EXIST );
321 RETURNCASE( HYP_BAD_DIM );
322 RETURNCASE( HYP_BAD_SUBSHAPE );
323 RETURNCASE( HYP_BAD_GEOMETRY );
326 return SMESH::HYP_UNKNOWN_FATAL;
329 //=============================================================================
333 * calls internal addHypothesis() and then adds a reference to <anHyp> under
334 * the SObject actually having a reference to <aSubShape>.
335 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
337 //=============================================================================
339 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
340 SMESH::SMESH_Hypothesis_ptr anHyp)
341 throw(SALOME::SALOME_Exception)
343 Unexpect aCatch(SALOME_SalomeException);
344 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
346 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
347 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
348 aSubShapeObject, anHyp );
350 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
352 // Update Python script
353 if(_impl->HasShapeToMesh()) {
354 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
355 << aSubShapeObject << ", " << anHyp << " )";
358 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
361 return ConvertHypothesisStatus(status);
364 //=============================================================================
368 //=============================================================================
370 SMESH_Hypothesis::Hypothesis_Status
371 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
372 SMESH::SMESH_Hypothesis_ptr anHyp)
374 if(MYDEBUG) MESSAGE("addHypothesis");
376 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
377 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
380 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
381 if (CORBA::is_nil(myHyp))
382 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
385 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
388 TopoDS_Shape myLocSubShape;
389 //use PseudoShape in case if mesh has no shape
391 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
393 myLocSubShape = _impl->GetShapeToMesh();
395 int hypId = myHyp->GetId();
396 status = _impl->AddHypothesis(myLocSubShape, hypId);
397 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
398 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
399 // assure there is a corresponding submesh
400 if ( !_impl->IsMainShape( myLocSubShape )) {
401 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
402 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
403 createSubMesh( aSubShapeObject );
407 catch(SALOME_Exception & S_ex)
409 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
414 //=============================================================================
418 //=============================================================================
420 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
421 SMESH::SMESH_Hypothesis_ptr anHyp)
422 throw(SALOME::SALOME_Exception)
424 Unexpect aCatch(SALOME_SalomeException);
425 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
427 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
428 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
429 aSubShapeObject, anHyp );
431 // Update Python script
432 // Update Python script
433 if(_impl->HasShapeToMesh()) {
434 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
435 << aSubShapeObject << ", " << anHyp << " )";
438 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
442 return ConvertHypothesisStatus(status);
445 //=============================================================================
449 //=============================================================================
451 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
452 SMESH::SMESH_Hypothesis_ptr anHyp)
454 if(MYDEBUG) MESSAGE("removeHypothesis()");
455 // **** proposer liste de subShape (selection multiple)
457 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
458 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
461 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
462 if (CORBA::is_nil(myHyp))
463 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
466 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
469 TopoDS_Shape myLocSubShape;
470 //use PseudoShape in case if mesh has no shape
472 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
474 myLocSubShape = _impl->GetShapeToMesh();
476 int hypId = myHyp->GetId();
477 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
478 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
479 _mapHypo.erase( hypId );
481 catch(SALOME_Exception & S_ex)
483 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
488 //=============================================================================
492 //=============================================================================
494 SMESH::ListOfHypothesis *
495 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
496 throw(SALOME::SALOME_Exception)
498 Unexpect aCatch(SALOME_SalomeException);
499 if (MYDEBUG) MESSAGE("GetHypothesisList");
500 if (CORBA::is_nil(aSubShapeObject))
501 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
504 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
507 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
508 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
509 int i = 0, n = aLocalList.size();
512 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
513 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
514 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
515 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
520 catch(SALOME_Exception & S_ex) {
521 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
524 return aList._retn();
527 //=============================================================================
531 //=============================================================================
532 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
533 const char* theName )
534 throw(SALOME::SALOME_Exception)
536 Unexpect aCatch(SALOME_SalomeException);
537 MESSAGE("SMESH_Mesh_i::GetSubMesh");
538 if (CORBA::is_nil(aSubShapeObject))
539 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
542 SMESH::SMESH_subMesh_var subMesh;
543 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
545 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
547 //Get or Create the SMESH_subMesh object implementation
549 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
550 subMesh = getSubMesh( subMeshId );
552 // create a new subMesh object servant if there is none for the shape
553 if ( subMesh->_is_nil() )
554 subMesh = createSubMesh( aSubShapeObject );
556 if ( _gen_i->CanPublishInStudy( subMesh )) {
557 SALOMEDS::SObject_var aSO =
558 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
559 subMesh, aSubShapeObject, theName );
560 if ( !aSO->_is_nil()) {
561 // Update Python script
562 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
563 << aSubShapeObject << ", '" << theName << "' )";
567 catch(SALOME_Exception & S_ex) {
568 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
570 return subMesh._retn();
573 //=============================================================================
577 //=============================================================================
579 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
580 throw (SALOME::SALOME_Exception)
582 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
583 if ( theSubMesh->_is_nil() )
586 GEOM::GEOM_Object_var aSubShapeObject;
587 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
588 if ( !aStudy->_is_nil() ) {
589 // Remove submesh's SObject
590 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
591 if ( !anSO->_is_nil() ) {
592 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
593 SALOMEDS::SObject_var anObj, aRef;
594 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
595 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
597 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
599 // Update Python script
600 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
604 removeSubMesh( theSubMesh, aSubShapeObject.in() );
607 //=============================================================================
611 //=============================================================================
612 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
613 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
615 switch (theElemType) {
620 CASE2STRING( VOLUME );
626 //=============================================================================
630 //=============================================================================
632 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
633 const char* theName )
634 throw(SALOME::SALOME_Exception)
636 Unexpect aCatch(SALOME_SalomeException);
637 SMESH::SMESH_Group_var aNewGroup =
638 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
640 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
641 SALOMEDS::SObject_var aSO =
642 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
643 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
644 if ( !aSO->_is_nil()) {
645 // Update Python script
646 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
647 << ElementTypeString(theElemType) << ", '" << theName << "' )";
650 return aNewGroup._retn();
654 //=============================================================================
658 //=============================================================================
659 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
661 GEOM::GEOM_Object_ptr theGeomObj)
662 throw(SALOME::SALOME_Exception)
664 Unexpect aCatch(SALOME_SalomeException);
665 SMESH::SMESH_GroupOnGeom_var aNewGroup;
667 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
668 if ( !aShape.IsNull() ) {
669 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
670 ( createGroup( theElemType, theName, aShape ));
671 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
672 SALOMEDS::SObject_var aSO =
673 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
674 aNewGroup, theGeomObj, theName);
675 if ( !aSO->_is_nil()) {
676 // Update Python script
677 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
678 << ElementTypeString(theElemType) << ", '" << theName << "', "
679 << theGeomObj << " )";
684 return aNewGroup._retn();
687 //=============================================================================
691 //=============================================================================
693 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
694 throw (SALOME::SALOME_Exception)
696 if ( theGroup->_is_nil() )
699 SMESH_GroupBase_i* aGroup =
700 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
704 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
705 if ( !aStudy->_is_nil() ) {
706 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
708 if ( !aGroupSO->_is_nil() ) {
709 // Update Python script
710 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
712 // Remove group's SObject
713 aStudy->NewBuilder()->RemoveObject( aGroupSO );
717 // Remove the group from SMESH data structures
718 removeGroup( aGroup->GetLocalID() );
721 //=============================================================================
722 /*! RemoveGroupWithContents
723 * Remove group with its contents
725 //=============================================================================
726 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
727 throw (SALOME::SALOME_Exception)
729 if ( theGroup->_is_nil() )
732 SMESH_GroupBase_i* aGroup =
733 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
737 SMESH::long_array_var anIds = aGroup->GetListOfID();
738 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
740 // Update Python script
741 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
744 if ( aGroup->GetType() == SMESH::NODE )
745 aMeshEditor->RemoveNodes( anIds );
747 aMeshEditor->RemoveElements( anIds );
750 RemoveGroup( theGroup );
752 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
753 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
754 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
758 //================================================================================
760 * \brief Get the list of groups existing in the mesh
761 * \retval SMESH::ListOfGroups * - list of groups
763 //================================================================================
765 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
767 Unexpect aCatch(SALOME_SalomeException);
768 if (MYDEBUG) MESSAGE("GetGroups");
770 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
773 TPythonDump aPythonDump;
774 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
778 aList->length( _mapGroups.size() );
780 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
781 for ( ; it != _mapGroups.end(); it++ ) {
782 if ( CORBA::is_nil( it->second )) continue;
783 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
785 if (i > 1) aPythonDump << ", ";
786 aPythonDump << it->second;
790 catch(SALOME_Exception & S_ex) {
791 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
794 // Update Python script
795 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
796 aPythonDump << " ] = " << _this() << ".GetGroups()";
798 return aList._retn();
800 //=============================================================================
802 * Get number of groups existing in the mesh
804 //=============================================================================
806 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
808 Unexpect aCatch(SALOME_SalomeException);
809 return _mapGroups.size();
812 //=============================================================================
814 * New group is created. All mesh elements that are
815 * present in initial groups are added to the new one
817 //=============================================================================
818 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
819 SMESH::SMESH_GroupBase_ptr theGroup2,
820 const char* theName )
821 throw (SALOME::SALOME_Exception)
825 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
826 theGroup1->GetType() != theGroup2->GetType() )
827 return SMESH::SMESH_Group::_nil();
830 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
831 if ( aResGrp->_is_nil() )
832 return SMESH::SMESH_Group::_nil();
834 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
835 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
837 TColStd_MapOfInteger aResMap;
839 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
840 aResMap.Add( anIds1[ i1 ] );
842 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
843 aResMap.Add( anIds2[ i2 ] );
845 SMESH::long_array_var aResIds = new SMESH::long_array;
846 aResIds->length( aResMap.Extent() );
849 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
850 for( ; anIter.More(); anIter.Next() )
851 aResIds[ resI++ ] = anIter.Key();
853 aResGrp->Add( aResIds );
855 // Clear python lines, created by CreateGroup() and Add()
856 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
857 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
858 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
860 // Update Python script
861 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
862 << theGroup1 << ", " << theGroup2 << ", '"
865 return aResGrp._retn();
869 return SMESH::SMESH_Group::_nil();
873 //=============================================================================
875 * New group is created. All mesh elements that are
876 * present in both initial groups are added to the new one.
878 //=============================================================================
879 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
880 SMESH::SMESH_GroupBase_ptr theGroup2,
881 const char* theName )
882 throw (SALOME::SALOME_Exception)
884 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
885 theGroup1->GetType() != theGroup2->GetType() )
886 return SMESH::SMESH_Group::_nil();
888 // Create Intersection
889 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
890 if ( aResGrp->_is_nil() )
893 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
894 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
896 TColStd_MapOfInteger aMap1;
898 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
899 aMap1.Add( anIds1[ i1 ] );
901 TColStd_SequenceOfInteger aSeq;
903 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
904 if ( aMap1.Contains( anIds2[ i2 ] ) )
905 aSeq.Append( anIds2[ i2 ] );
907 SMESH::long_array_var aResIds = new SMESH::long_array;
908 aResIds->length( aSeq.Length() );
910 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
911 aResIds[ resI ] = aSeq( resI + 1 );
913 aResGrp->Add( aResIds );
915 // Clear python lines, created by CreateGroup() and Add()
916 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
917 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
918 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
920 // Update Python script
921 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
922 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
924 return aResGrp._retn();
927 //=============================================================================
929 * New group is created. All mesh elements that are present in
930 * main group but do not present in tool group are added to the new one
932 //=============================================================================
933 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
934 SMESH::SMESH_GroupBase_ptr theGroup2,
935 const char* theName )
936 throw (SALOME::SALOME_Exception)
938 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
939 theGroup1->GetType() != theGroup2->GetType() )
940 return SMESH::SMESH_Group::_nil();
943 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
944 if ( aResGrp->_is_nil() )
947 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
948 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
950 TColStd_MapOfInteger aMap2;
952 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
953 aMap2.Add( anIds2[ i2 ] );
956 TColStd_SequenceOfInteger aSeq;
957 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
958 if ( !aMap2.Contains( anIds1[ i1 ] ) )
959 aSeq.Append( anIds1[ i1 ] );
961 SMESH::long_array_var aResIds = new SMESH::long_array;
962 aResIds->length( aSeq.Length() );
964 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
965 aResIds[ resI ] = aSeq( resI + 1 );
967 aResGrp->Add( aResIds );
969 // Clear python lines, created by CreateGroup() and Add()
970 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
971 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
972 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
974 // Update Python script
975 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
976 << theGroup1 << ", " << theGroup2 << ", '"
979 return aResGrp._retn();
982 //================================================================================
984 * \brief Return group items of a group present in a study
986 //================================================================================
988 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
990 list<TopoDS_Shape> & theItems)
992 GEOM::GEOM_Object_var groupObj;
993 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
994 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
995 if ( study->_is_nil() || geomGen->_is_nil() )
996 return groupObj._retn();
998 GEOM::GEOM_IGroupOperations_var groupOp =
999 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
1000 GEOM::GEOM_IShapesOperations_var shapeOp =
1001 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
1003 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
1004 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
1005 return groupObj._retn();
1006 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
1007 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
1008 return groupObj._retn(); // keep only submeshes on groups
1010 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
1011 if ( anIter->_is_nil() ) return groupObj._retn();
1012 for ( ; anIter->More(); anIter->Next())
1014 SALOMEDS::SObject_var aSObject = anIter->Value();
1015 SALOMEDS::SObject_var aRefSO;
1016 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
1018 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
1019 if ( groupObj->_is_nil() ) break;
1020 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1021 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1022 for ( int i = 0; i < ids->length(); ++i ) {
1023 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1024 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1026 theItems.push_back( S );
1031 return groupObj._retn();
1034 //=============================================================================
1036 * \brief Update hypotheses assigned to geom groups if the latter change
1038 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1040 //=============================================================================
1042 void SMESH_Mesh_i::CheckGeomGroupModif()
1044 if ( !_impl->HasShapeToMesh() ) return;
1046 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1047 if ( study->_is_nil() ) return;
1049 // check if items of groups changed
1050 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1051 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1053 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1054 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1055 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1057 int oldID = i_sm->first;
1058 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1059 if ( i_smIor == _mapSubMeshIor.end() )
1061 list< TopoDS_Shape> newItems;
1062 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1063 if ( groupObj->_is_nil() )
1066 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1067 int nbNewItems = newItems.size();
1068 bool groupChanged = ( nbOldItems != nbNewItems);
1069 if ( !groupChanged ) {
1070 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1071 groupChanged = ( oldGroupShape != newItems.front() );
1074 list<TopoDS_Shape>::iterator item = newItems.begin();
1075 for ( ; item != newItems.end() && !groupChanged; ++item )
1077 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1078 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1082 // update hypotheses and submeshes if necessary
1085 // get a new group shape
1086 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1087 if ( !geomClient ) continue;
1088 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1089 geomClient->RemoveShapeFromBuffer( groupIOR );
1090 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1091 // update hypotheses
1092 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1093 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1094 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1096 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1097 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1099 // care of submeshes
1100 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1101 int newID = newSubmesh->GetId();
1102 if ( newID != oldID ) {
1103 _mapSubMesh [ newID ] = newSubmesh;
1104 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1105 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1106 _mapSubMesh.erase (oldID);
1107 _mapSubMesh_i.erase (oldID);
1108 _mapSubMeshIor.erase(oldID);
1109 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1115 //=============================================================================
1119 //=============================================================================
1121 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1123 if(MYDEBUG) MESSAGE( "createSubMesh" );
1124 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1126 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1127 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1128 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1129 SMESH::SMESH_subMesh_var subMesh
1130 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1132 _mapSubMesh[subMeshId] = mySubMesh;
1133 _mapSubMesh_i[subMeshId] = subMeshServant;
1134 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1136 // register CORBA object for persistence
1137 int nextId = _gen_i->RegisterObject( subMesh );
1138 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1140 return subMesh._retn();
1143 //=======================================================================
1144 //function : getSubMesh
1146 //=======================================================================
1148 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1150 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1151 if ( it == _mapSubMeshIor.end() )
1152 return SMESH::SMESH_subMesh::_nil();
1154 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1158 //=============================================================================
1162 //=============================================================================
1164 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1165 GEOM::GEOM_Object_ptr theSubShapeObject )
1167 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1168 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1172 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1173 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1174 removeHypothesis( theSubShapeObject, aHypList[i] );
1177 catch( const SALOME::SALOME_Exception& ) {
1178 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1181 int subMeshId = theSubMesh->GetId();
1183 _mapSubMesh.erase(subMeshId);
1184 _mapSubMesh_i.erase(subMeshId);
1185 _mapSubMeshIor.erase(subMeshId);
1186 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1189 //=============================================================================
1193 //=============================================================================
1195 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1196 const char* theName,
1197 const TopoDS_Shape& theShape )
1200 SMESH::SMESH_GroupBase_var aGroup;
1201 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1202 SMESH_GroupBase_i* aGroupImpl;
1203 if ( !theShape.IsNull() )
1204 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1206 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1208 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1209 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1210 aGroupImpl->Register();
1211 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1213 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1214 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1216 // register CORBA object for persistence
1217 int nextId = _gen_i->RegisterObject( aGroup );
1218 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1220 return aGroup._retn();
1223 //=============================================================================
1225 * SMESH_Mesh_i::removeGroup
1227 * Should be called by ~SMESH_Group_i()
1229 //=============================================================================
1231 void SMESH_Mesh_i::removeGroup( const int theId )
1233 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1234 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1235 _mapGroups.erase( theId );
1236 _impl->RemoveGroup( theId );
1241 //=============================================================================
1245 //=============================================================================
1247 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1248 throw(SALOME::SALOME_Exception)
1250 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1252 SMESH::log_array_var aLog;
1254 list < SMESHDS_Command * >logDS = _impl->GetLog();
1255 aLog = new SMESH::log_array;
1257 int lg = logDS.size();
1260 list < SMESHDS_Command * >::iterator its = logDS.begin();
1261 while(its != logDS.end()){
1262 SMESHDS_Command *com = *its;
1263 int comType = com->GetType();
1265 int lgcom = com->GetNumber();
1267 const list < int >&intList = com->GetIndexes();
1268 int inum = intList.size();
1270 list < int >::const_iterator ii = intList.begin();
1271 const list < double >&coordList = com->GetCoords();
1272 int rnum = coordList.size();
1274 list < double >::const_iterator ir = coordList.begin();
1275 aLog[indexLog].commandType = comType;
1276 aLog[indexLog].number = lgcom;
1277 aLog[indexLog].coords.length(rnum);
1278 aLog[indexLog].indexes.length(inum);
1279 for(int i = 0; i < rnum; i++){
1280 aLog[indexLog].coords[i] = *ir;
1281 //MESSAGE(" "<<i<<" "<<ir.Value());
1284 for(int i = 0; i < inum; i++){
1285 aLog[indexLog].indexes[i] = *ii;
1286 //MESSAGE(" "<<i<<" "<<ii.Value());
1295 catch(SALOME_Exception & S_ex){
1296 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1298 return aLog._retn();
1302 //=============================================================================
1306 //=============================================================================
1308 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1310 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1314 //=============================================================================
1318 //=============================================================================
1320 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1322 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1326 //=============================================================================
1330 //=============================================================================
1332 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1337 //=============================================================================
1341 //=============================================================================
1343 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1345 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1349 //=============================================================================
1353 //=============================================================================
1355 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1357 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1361 //=============================================================================
1363 * Return mesh editor
1365 //=============================================================================
1367 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1369 // Create MeshEditor
1370 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1371 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1373 // Update Python script
1374 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1376 return aMesh._retn();
1379 //=============================================================================
1381 * Return mesh edition previewer
1383 //=============================================================================
1385 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1387 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1388 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1389 return aMesh._retn();
1392 //=============================================================================
1396 //=============================================================================
1397 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1399 Unexpect aCatch(SALOME_SalomeException);
1400 _impl->SetAutoColor(theAutoColor);
1403 //=============================================================================
1407 //=============================================================================
1408 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1410 Unexpect aCatch(SALOME_SalomeException);
1411 return _impl->GetAutoColor();
1415 //=============================================================================
1417 * Export in different formats
1419 //=============================================================================
1421 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1423 return _impl->HasDuplicatedGroupNamesMED();
1426 static void PrepareForWriting (const char* file)
1428 TCollection_AsciiString aFullName ((char*)file);
1429 OSD_Path aPath (aFullName);
1430 OSD_File aFile (aPath);
1431 if (aFile.Exists()) {
1432 // existing filesystem node
1433 if (aFile.KindOfFile() == OSD_FILE) {
1434 if (aFile.IsWriteable()) {
1437 if (aFile.Failed()) {
1438 TCollection_AsciiString msg ("File ");
1439 msg += aFullName + " cannot be replaced.";
1440 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1443 TCollection_AsciiString msg ("File ");
1444 msg += aFullName + " cannot be overwritten.";
1445 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1448 TCollection_AsciiString msg ("Location ");
1449 msg += aFullName + " is not a file.";
1450 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1453 // nonexisting file; check if it can be created
1455 aFile.Build(OSD_WriteOnly, OSD_Protection());
1456 if (aFile.Failed()) {
1457 TCollection_AsciiString msg ("You cannot create the file ");
1458 msg += aFullName + ". Check the directory existance and access rights.";
1459 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1467 void SMESH_Mesh_i::ExportToMED (const char* file,
1468 CORBA::Boolean auto_groups,
1469 SMESH::MED_VERSION theVersion)
1470 throw(SALOME::SALOME_Exception)
1472 Unexpect aCatch(SALOME_SalomeException);
1474 // Update Python script
1475 TPythonDump() << _this() << ".ExportToMED( '"
1476 << file << "', " << auto_groups << ", " << theVersion << " )";
1479 PrepareForWriting(file);
1480 char* aMeshName = "Mesh";
1481 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1482 if ( !aStudy->_is_nil() ) {
1483 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1484 if ( !aMeshSO->_is_nil() ) {
1485 aMeshName = aMeshSO->GetName();
1487 //SCRUTE(aMeshName);
1488 //SCRUTE(aMeshSO->GetID());
1490 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1491 if ( !aStudy->GetProperties()->IsLocked() )
1493 SALOMEDS::GenericAttribute_var anAttr;
1494 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1495 SALOMEDS::AttributeExternalFileDef_var aFileName;
1496 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1497 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1498 ASSERT(!aFileName->_is_nil());
1499 aFileName->SetValue(file);
1500 SALOMEDS::AttributeFileType_var aFileType;
1501 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1502 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1503 ASSERT(!aFileType->_is_nil());
1504 aFileType->SetValue("FICHIERMED");
1508 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1511 void SMESH_Mesh_i::ExportMED (const char* file,
1512 CORBA::Boolean auto_groups)
1513 throw(SALOME::SALOME_Exception)
1515 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1518 void SMESH_Mesh_i::ExportDAT (const char *file)
1519 throw(SALOME::SALOME_Exception)
1521 Unexpect aCatch(SALOME_SalomeException);
1523 // Update Python script
1524 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1527 PrepareForWriting(file);
1528 _impl->ExportDAT(file);
1531 void SMESH_Mesh_i::ExportUNV (const char *file)
1532 throw(SALOME::SALOME_Exception)
1534 Unexpect aCatch(SALOME_SalomeException);
1536 // Update Python script
1537 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1540 PrepareForWriting(file);
1541 _impl->ExportUNV(file);
1544 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1545 throw(SALOME::SALOME_Exception)
1547 Unexpect aCatch(SALOME_SalomeException);
1549 // Update Python script
1550 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1553 PrepareForWriting(file);
1554 _impl->ExportSTL(file, isascii);
1557 //=============================================================================
1561 //=============================================================================
1563 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1565 Unexpect aCatch(SALOME_SalomeException);
1566 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1567 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1568 return aMesh._retn();
1571 //=============================================================================
1575 //=============================================================================
1576 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1578 Unexpect aCatch(SALOME_SalomeException);
1579 return _impl->NbNodes();
1582 //=============================================================================
1586 //=============================================================================
1587 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1589 Unexpect aCatch(SALOME_SalomeException);
1590 return NbEdges() + NbFaces() + NbVolumes();
1593 //=============================================================================
1597 //=============================================================================
1598 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1600 Unexpect aCatch(SALOME_SalomeException);
1601 return _impl->NbEdges();
1604 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1605 throw(SALOME::SALOME_Exception)
1607 Unexpect aCatch(SALOME_SalomeException);
1608 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
1611 //=============================================================================
1615 //=============================================================================
1616 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1618 Unexpect aCatch(SALOME_SalomeException);
1619 return _impl->NbFaces();
1622 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1624 Unexpect aCatch(SALOME_SalomeException);
1625 return _impl->NbTriangles();
1628 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1630 Unexpect aCatch(SALOME_SalomeException);
1631 return _impl->NbQuadrangles();
1634 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1636 Unexpect aCatch(SALOME_SalomeException);
1637 return _impl->NbPolygons();
1640 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1641 throw(SALOME::SALOME_Exception)
1643 Unexpect aCatch(SALOME_SalomeException);
1644 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
1647 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1648 throw(SALOME::SALOME_Exception)
1650 Unexpect aCatch(SALOME_SalomeException);
1651 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
1654 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1655 throw(SALOME::SALOME_Exception)
1657 Unexpect aCatch(SALOME_SalomeException);
1658 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
1661 //=============================================================================
1665 //=============================================================================
1666 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1668 Unexpect aCatch(SALOME_SalomeException);
1669 return _impl->NbVolumes();
1672 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1674 Unexpect aCatch(SALOME_SalomeException);
1675 return _impl->NbTetras();
1678 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1680 Unexpect aCatch(SALOME_SalomeException);
1681 return _impl->NbHexas();
1684 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1686 Unexpect aCatch(SALOME_SalomeException);
1687 return _impl->NbPyramids();
1690 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1692 Unexpect aCatch(SALOME_SalomeException);
1693 return _impl->NbPrisms();
1696 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1698 Unexpect aCatch(SALOME_SalomeException);
1699 return _impl->NbPolyhedrons();
1702 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1703 throw(SALOME::SALOME_Exception)
1705 Unexpect aCatch(SALOME_SalomeException);
1706 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
1709 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1710 throw(SALOME::SALOME_Exception)
1712 Unexpect aCatch(SALOME_SalomeException);
1713 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
1716 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1717 throw(SALOME::SALOME_Exception)
1719 Unexpect aCatch(SALOME_SalomeException);
1720 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
1723 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1724 throw(SALOME::SALOME_Exception)
1726 Unexpect aCatch(SALOME_SalomeException);
1727 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
1730 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1731 throw(SALOME::SALOME_Exception)
1733 Unexpect aCatch(SALOME_SalomeException);
1734 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
1737 //=============================================================================
1741 //=============================================================================
1742 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1744 Unexpect aCatch(SALOME_SalomeException);
1745 return _impl->NbSubMesh();
1748 //=============================================================================
1752 //=============================================================================
1753 char* SMESH_Mesh_i::Dump()
1755 std::ostringstream os;
1757 return CORBA::string_dup( os.str().c_str() );
1760 //=============================================================================
1764 //=============================================================================
1765 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1767 // SMESH::long_array_var aResult = new SMESH::long_array();
1768 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1769 // int aMinId = aSMESHDS_Mesh->MinElementID();
1770 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1772 // aResult->length(aMaxId - aMinId + 1);
1774 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1775 // aResult[i++] = id;
1777 // return aResult._retn();
1779 return GetElementsId();
1782 //=============================================================================
1786 //=============================================================================
1788 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1789 throw (SALOME::SALOME_Exception)
1791 Unexpect aCatch(SALOME_SalomeException);
1792 MESSAGE("SMESH_Mesh_i::GetElementsId");
1793 SMESH::long_array_var aResult = new SMESH::long_array();
1794 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1796 if ( aSMESHDS_Mesh == NULL )
1797 return aResult._retn();
1799 long nbElements = NbElements();
1800 aResult->length( nbElements );
1801 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1802 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1803 aResult[i] = anIt->next()->GetID();
1805 return aResult._retn();
1809 //=============================================================================
1813 //=============================================================================
1815 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1816 throw (SALOME::SALOME_Exception)
1818 Unexpect aCatch(SALOME_SalomeException);
1819 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1820 SMESH::long_array_var aResult = new SMESH::long_array();
1821 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1823 if ( aSMESHDS_Mesh == NULL )
1824 return aResult._retn();
1826 long nbElements = NbElements();
1828 // No sense in returning ids of elements along with ids of nodes:
1829 // when theElemType == SMESH::ALL, return node ids only if
1830 // there are no elements
1831 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1832 return GetNodesId();
1834 aResult->length( nbElements );
1838 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1839 while ( i < nbElements && anIt->more() ) {
1840 const SMDS_MeshElement* anElem = anIt->next();
1841 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1842 aResult[i++] = anElem->GetID();
1845 aResult->length( i );
1847 return aResult._retn();
1850 //=============================================================================
1854 //=============================================================================
1856 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1857 throw (SALOME::SALOME_Exception)
1859 Unexpect aCatch(SALOME_SalomeException);
1860 MESSAGE("SMESH_subMesh_i::GetNodesId");
1861 SMESH::long_array_var aResult = new SMESH::long_array();
1862 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1864 if ( aSMESHDS_Mesh == NULL )
1865 return aResult._retn();
1867 long nbNodes = NbNodes();
1868 aResult->length( nbNodes );
1869 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1870 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1871 aResult[i] = anIt->next()->GetID();
1873 return aResult._retn();
1876 //=============================================================================
1880 //=============================================================================
1882 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1883 throw (SALOME::SALOME_Exception)
1885 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1889 //=============================================================================
1891 * Returns ID of elements for given submesh
1893 //=============================================================================
1894 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1895 throw (SALOME::SALOME_Exception)
1897 SMESH::long_array_var aResult = new SMESH::long_array();
1899 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1900 if(!SM) return aResult._retn();
1902 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1903 if(!SDSM) return aResult._retn();
1905 aResult->length(SDSM->NbElements());
1907 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1909 while ( eIt->more() ) {
1910 aResult[i++] = eIt->next()->GetID();
1913 return aResult._retn();
1917 //=============================================================================
1919 * Returns ID of nodes for given submesh
1920 * If param all==true - returns all nodes, else -
1921 * returns only nodes on shapes.
1923 //=============================================================================
1924 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1925 throw (SALOME::SALOME_Exception)
1927 SMESH::long_array_var aResult = new SMESH::long_array();
1929 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1930 if(!SM) return aResult._retn();
1932 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1933 if(!SDSM) return aResult._retn();
1935 map<int,const SMDS_MeshElement*> theElems;
1936 if( !all || (SDSM->NbElements()==0 && SDSM->NbNodes()==1) ) {
1937 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1938 while ( nIt->more() ) {
1939 const SMDS_MeshNode* elem = nIt->next();
1940 theElems.insert( make_pair(elem->GetID(),elem) );
1943 else { // all nodes of submesh elements
1944 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1945 while ( eIt->more() ) {
1946 const SMDS_MeshElement* anElem = eIt->next();
1947 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1948 while ( nIt->more() ) {
1949 const SMDS_MeshElement* elem = nIt->next();
1950 theElems.insert( make_pair(elem->GetID(),elem) );
1955 aResult->length(theElems.size());
1956 map<int, const SMDS_MeshElement * >::iterator itElem;
1958 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
1959 aResult[i++] = (*itElem).first;
1961 return aResult._retn();
1965 //=============================================================================
1967 * Returns type of elements for given submesh
1969 //=============================================================================
1970 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
1971 throw (SALOME::SALOME_Exception)
1973 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1974 if(!SM) return SMESH::ALL;
1976 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1977 if(!SDSM) return SMESH::ALL;
1979 if(SDSM->NbElements()==0)
1980 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
1982 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1983 const SMDS_MeshElement* anElem = eIt->next();
1984 return ( SMESH::ElementType ) anElem->GetType();
1988 //=============================================================================
1992 //=============================================================================
1994 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
1996 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
1997 cerr << "CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() " << pointeur << endl;
2002 //=============================================================================
2004 * Get XYZ coordinates of node as list of double
2005 * If there is not node for given ID - returns empty list
2007 //=============================================================================
2009 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2011 SMESH::double_array_var aResult = new SMESH::double_array();
2012 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2013 if ( aSMESHDS_Mesh == NULL )
2014 return aResult._retn();
2017 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2019 return aResult._retn();
2023 aResult[0] = aNode->X();
2024 aResult[1] = aNode->Y();
2025 aResult[2] = aNode->Z();
2026 return aResult._retn();
2030 //=============================================================================
2032 * For given node returns list of IDs of inverse elements
2033 * If there is not node for given ID - returns empty list
2035 //=============================================================================
2037 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2039 SMESH::long_array_var aResult = new SMESH::long_array();
2040 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2041 if ( aSMESHDS_Mesh == NULL )
2042 return aResult._retn();
2045 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2047 return aResult._retn();
2049 // find inverse elements
2050 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2051 TColStd_SequenceOfInteger IDs;
2052 while(eIt->more()) {
2053 const SMDS_MeshElement* elem = eIt->next();
2054 IDs.Append(elem->GetID());
2056 if(IDs.Length()>0) {
2057 aResult->length(IDs.Length());
2059 for(; i<=IDs.Length(); i++) {
2060 aResult[i-1] = IDs.Value(i);
2063 return aResult._retn();
2066 //=============================================================================
2068 * \brief Return position of a node on shape
2070 //=============================================================================
2072 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2074 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2075 aNodePosition->shapeID = 0;
2076 aNodePosition->shapeType = GEOM::SHAPE;
2078 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2079 if ( !mesh ) return aNodePosition;
2081 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2083 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2085 aNodePosition->shapeID = pos->GetShapeId();
2086 switch ( pos->GetTypeOfPosition() ) {
2088 aNodePosition->shapeType = GEOM::EDGE;
2089 aNodePosition->params.length(1);
2090 aNodePosition->params[0] =
2091 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2094 aNodePosition->shapeType = GEOM::FACE;
2095 aNodePosition->params.length(2);
2096 aNodePosition->params[0] =
2097 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2098 aNodePosition->params[1] =
2099 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2101 case SMDS_TOP_VERTEX:
2102 aNodePosition->shapeType = GEOM::VERTEX;
2104 case SMDS_TOP_3DSPACE:
2105 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2106 aNodePosition->shapeType = GEOM::SOLID;
2107 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2108 aNodePosition->shapeType = GEOM::SHELL;
2114 return aNodePosition;
2117 //=============================================================================
2119 * If given element is node returns IDs of shape from position
2120 * If there is not node for given ID - returns -1
2122 //=============================================================================
2124 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2126 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2127 if ( aSMESHDS_Mesh == NULL )
2131 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2133 SMDS_PositionPtr pos = aNode->GetPosition();
2137 return pos->GetShapeId();
2144 //=============================================================================
2146 * For given element returns ID of result shape after
2147 * ::FindShape() from SMESH_MeshEditor
2148 * If there is not element for given ID - returns -1
2150 //=============================================================================
2152 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2154 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2155 if ( aSMESHDS_Mesh == NULL )
2158 // try to find element
2159 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2163 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2164 ::SMESH_MeshEditor aMeshEditor(_impl);
2165 int index = aMeshEditor.FindShape( elem );
2173 //=============================================================================
2175 * Returns number of nodes for given element
2176 * If there is not element for given ID - returns -1
2178 //=============================================================================
2180 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2182 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2183 if ( aSMESHDS_Mesh == NULL ) return -1;
2184 // try to find element
2185 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2186 if(!elem) return -1;
2187 return elem->NbNodes();
2191 //=============================================================================
2193 * Returns ID of node by given index for given element
2194 * If there is not element for given ID - returns -1
2195 * If there is not node for given index - returns -2
2197 //=============================================================================
2199 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2201 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2202 if ( aSMESHDS_Mesh == NULL ) return -1;
2203 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2204 if(!elem) return -1;
2205 if( index>=elem->NbNodes() || index<0 ) return -1;
2206 return elem->GetNode(index)->GetID();
2209 //=============================================================================
2211 * Returns IDs of nodes of given element
2213 //=============================================================================
2215 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2217 SMESH::long_array_var aResult = new SMESH::long_array();
2218 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2220 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2222 aResult->length( elem->NbNodes() );
2223 for ( int i = 0; i < elem->NbNodes(); ++i )
2224 aResult[ i ] = elem->GetNode( i )->GetID();
2227 return aResult._retn();
2230 //=============================================================================
2232 * Returns true if given node is medium node
2233 * in given quadratic element
2235 //=============================================================================
2237 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2239 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2240 if ( aSMESHDS_Mesh == NULL ) return false;
2242 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2243 if(!aNode) return false;
2244 // try to find element
2245 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2246 if(!elem) return false;
2248 return elem->IsMediumNode(aNode);
2252 //=============================================================================
2254 * Returns true if given node is medium node
2255 * in one of quadratic elements
2257 //=============================================================================
2259 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2260 SMESH::ElementType theElemType)
2262 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2263 if ( aSMESHDS_Mesh == NULL ) return false;
2266 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2267 if(!aNode) return false;
2269 SMESH_MesherHelper aHelper( *(_impl) );
2271 SMDSAbs_ElementType aType;
2272 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2273 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2274 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2275 else aType = SMDSAbs_All;
2277 return aHelper.IsMedium(aNode,aType);
2281 //=============================================================================
2283 * Returns number of edges for given element
2285 //=============================================================================
2287 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2289 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2290 if ( aSMESHDS_Mesh == NULL ) return -1;
2291 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2292 if(!elem) return -1;
2293 return elem->NbEdges();
2297 //=============================================================================
2299 * Returns number of faces for given element
2301 //=============================================================================
2303 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2305 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2306 if ( aSMESHDS_Mesh == NULL ) return -1;
2307 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2308 if(!elem) return -1;
2309 return elem->NbFaces();
2313 //=============================================================================
2315 * Returns true if given element is polygon
2317 //=============================================================================
2319 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2321 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2322 if ( aSMESHDS_Mesh == NULL ) return false;
2323 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2324 if(!elem) return false;
2325 return elem->IsPoly();
2329 //=============================================================================
2331 * Returns true if given element is quadratic
2333 //=============================================================================
2335 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2337 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2338 if ( aSMESHDS_Mesh == NULL ) return false;
2339 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2340 if(!elem) return false;
2341 return elem->IsQuadratic();
2345 //=============================================================================
2347 * Returns bary center for given element
2349 //=============================================================================
2351 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2353 SMESH::double_array_var aResult = new SMESH::double_array();
2354 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2355 if ( aSMESHDS_Mesh == NULL )
2356 return aResult._retn();
2358 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2360 return aResult._retn();
2362 if(elem->GetType()==SMDSAbs_Volume) {
2363 SMDS_VolumeTool aTool;
2364 if(aTool.Set(elem)) {
2366 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2371 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2373 double x=0., y=0., z=0.;
2374 for(; anIt->more(); ) {
2376 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2390 return aResult._retn();
2394 //=============================================================================
2396 * Create and publish group servants if any groups were imported or created anyhow
2398 //=============================================================================
2400 void SMESH_Mesh_i::CreateGroupServants()
2402 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2404 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2405 while ( groupIt->more() )
2407 ::SMESH_Group* group = groupIt->next();
2408 int anId = group->GetGroupDS()->GetID();
2410 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
2411 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2414 SMESH_GroupBase_i* aGroupImpl;
2416 if ( SMESHDS_GroupOnGeom* groupOnGeom =
2417 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
2419 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2420 shape = groupOnGeom->GetShape();
2423 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2426 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
2427 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2428 aGroupImpl->Register();
2430 SMESH::SMESH_GroupBase_var groupVar =
2431 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2432 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
2434 // register CORBA object for persistence
2435 int nextId = _gen_i->RegisterObject( groupVar );
2436 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2438 // publishing of the groups in the study
2439 if ( !aStudy->_is_nil() ) {
2440 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
2441 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
2446 //=============================================================================
2448 * \brief Return groups cantained in _mapGroups by their IDs
2450 //=============================================================================
2452 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
2454 int nbGroups = groupIDs.size();
2455 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
2456 aList->length( nbGroups );
2458 list<int>::const_iterator ids = groupIDs.begin();
2459 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
2461 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
2462 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2463 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
2465 aList->length( nbGroups );
2466 return aList._retn();