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 "DriverMED_W_SMESHDS_Mesh.h"
41 #include "SMDS_VolumeTool.hxx"
42 #include "SMESHDS_Command.hxx"
43 #include "SMESHDS_CommandType.hxx"
44 #include "SMESHDS_GroupOnGeom.hxx"
45 #include "SMESH_Group.hxx"
46 #include "SMESH_MeshEditor.hxx"
47 #include "SMESH_MesherHelper.hxx"
48 #include "SMDS_EdgePosition.hxx"
49 #include "SMDS_FacePosition.hxx"
52 #include "SALOME_NamingService.hxx"
53 #include "Utils_CorbaException.hxx"
54 #include "Utils_ExceptHandlers.hxx"
55 #include "Utils_SINGLETON.hxx"
56 #include "utilities.h"
59 #include <BRep_Builder.hxx>
60 #include <OSD_Directory.hxx>
61 #include <OSD_File.hxx>
62 #include <OSD_Path.hxx>
63 #include <OSD_Protection.hxx>
64 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
65 #include <TColStd_MapOfInteger.hxx>
66 #include <TColStd_SequenceOfInteger.hxx>
67 #include <TCollection_AsciiString.hxx>
68 #include <TopExp_Explorer.hxx>
69 #include <TopoDS_Compound.hxx>
78 static int MYDEBUG = 0;
80 static int MYDEBUG = 0;
84 using SMESH::TPythonDump;
86 int SMESH_Mesh_i::myIdGenerator = 0;
90 //=============================================================================
94 //=============================================================================
96 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
99 : SALOME::GenericObj_i( thePOA )
101 MESSAGE("SMESH_Mesh_i");
104 _id = myIdGenerator++;
108 //=============================================================================
112 //=============================================================================
114 SMESH_Mesh_i::~SMESH_Mesh_i()
116 INFOS("~SMESH_Mesh_i");
117 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
118 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
119 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
122 // this method is colled from destructor of group (PAL6331)
123 //_impl->RemoveGroup( aGroup->GetLocalID() );
131 //=============================================================================
135 * Associates <this> mesh with <theShape> and puts a reference
136 * to <theShape> into the current study;
137 * the previous shape is substituted by the new one.
139 //=============================================================================
141 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
142 throw (SALOME::SALOME_Exception)
144 Unexpect aCatch(SALOME_SalomeException);
146 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
148 catch(SALOME_Exception & S_ex) {
149 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
153 //================================================================================
155 * \brief return true if mesh has a shape to build a shape on
157 //================================================================================
159 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
160 throw (SALOME::SALOME_Exception)
162 Unexpect aCatch(SALOME_SalomeException);
165 res = _impl->HasShapeToMesh();
167 catch(SALOME_Exception & S_ex) {
168 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
173 //=======================================================================
174 //function : GetShapeToMesh
176 //=======================================================================
178 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
179 throw (SALOME::SALOME_Exception)
181 Unexpect aCatch(SALOME_SalomeException);
182 GEOM::GEOM_Object_var aShapeObj;
184 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
186 aShapeObj = _gen_i->ShapeToGeomObject( S );
188 catch(SALOME_Exception & S_ex) {
189 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
191 return aShapeObj._retn();
194 //================================================================================
196 * \brief Remove all nodes and elements
198 //================================================================================
200 void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
202 Unexpect aCatch(SALOME_SalomeException);
206 catch(SALOME_Exception & S_ex) {
207 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
209 TPythonDump() << _this() << ".Clear()";
212 //=============================================================================
216 //=============================================================================
218 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
220 SMESH::DriverMED_ReadStatus res;
223 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
224 res = SMESH::DRS_OK; break;
225 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
226 res = SMESH::DRS_EMPTY; break;
227 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
228 res = SMESH::DRS_WARN_RENUMBER; break;
229 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
230 res = SMESH::DRS_WARN_SKIP_ELEM; break;
231 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
233 res = SMESH::DRS_FAIL; break;
238 //=============================================================================
242 * Imports mesh data from MED file
244 //=============================================================================
246 SMESH::DriverMED_ReadStatus
247 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
248 throw ( SALOME::SALOME_Exception )
250 Unexpect aCatch(SALOME_SalomeException);
253 status = _impl->MEDToMesh( theFileName, theMeshName );
255 catch( SALOME_Exception& S_ex ) {
256 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
259 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
262 CreateGroupServants();
264 int major, minor, release;
265 if( !MED::getMEDVersion( theFileName, major, minor, release ) )
266 major = minor = release = -1;
267 myFileInfo = new SALOME_MED::MedFileInfo();
268 myFileInfo->fileName = theFileName;
269 myFileInfo->fileSize = 0;
272 if ( ::_stati64( theFileName, &d ) != -1 )
275 if ( ::stat64( theFileName, &d ) != -1 )
277 myFileInfo->fileSize = d.st_size;
278 myFileInfo->major = major;
279 myFileInfo->minor = minor;
280 myFileInfo->release = release;
282 return ConvertDriverMEDReadStatus(status);
285 //================================================================================
287 * \brief Return string representation of a MED file version comprising nbDigits
289 //================================================================================
291 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
293 std::string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
295 return CORBA::string_dup( ver.c_str() );
298 //=============================================================================
302 * Imports mesh data from MED file
304 //=============================================================================
306 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
307 throw ( SALOME::SALOME_Exception )
309 // Read mesh with name = <theMeshName> into SMESH_Mesh
310 _impl->UNVToMesh( theFileName );
312 CreateGroupServants();
317 //=============================================================================
321 * Imports mesh data from STL file
323 //=============================================================================
324 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
325 throw ( SALOME::SALOME_Exception )
327 // Read mesh with name = <theMeshName> into SMESH_Mesh
328 _impl->STLToMesh( theFileName );
333 //=============================================================================
337 * Imports mesh data from MED file
339 //=============================================================================
341 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
343 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
344 // int status = _impl->MEDToMesh( theFileName, theMeshName );
345 // CreateGroupServants();
350 //=============================================================================
354 //=============================================================================
356 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
358 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
359 (SMESH_Hypothesis::Hypothesis_Status theStatus)
362 RETURNCASE( HYP_OK );
363 RETURNCASE( HYP_MISSING );
364 RETURNCASE( HYP_CONCURENT );
365 RETURNCASE( HYP_BAD_PARAMETER );
366 RETURNCASE( HYP_HIDDEN_ALGO );
367 RETURNCASE( HYP_HIDING_ALGO );
368 RETURNCASE( HYP_UNKNOWN_FATAL );
369 RETURNCASE( HYP_INCOMPATIBLE );
370 RETURNCASE( HYP_NOTCONFORM );
371 RETURNCASE( HYP_ALREADY_EXIST );
372 RETURNCASE( HYP_BAD_DIM );
373 RETURNCASE( HYP_BAD_SUBSHAPE );
374 RETURNCASE( HYP_BAD_GEOMETRY );
375 RETURNCASE( HYP_NEED_SHAPE );
378 return SMESH::HYP_UNKNOWN_FATAL;
381 //=============================================================================
385 * calls internal addHypothesis() and then adds a reference to <anHyp> under
386 * the SObject actually having a reference to <aSubShape>.
387 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
389 //=============================================================================
391 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
392 SMESH::SMESH_Hypothesis_ptr anHyp)
393 throw(SALOME::SALOME_Exception)
395 Unexpect aCatch(SALOME_SalomeException);
396 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
398 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
399 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
400 aSubShapeObject, anHyp );
402 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
404 // Update Python script
405 if(_impl->HasShapeToMesh()) {
406 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
407 << aSubShapeObject << ", " << anHyp << " )";
410 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
413 return ConvertHypothesisStatus(status);
416 //=============================================================================
420 //=============================================================================
422 SMESH_Hypothesis::Hypothesis_Status
423 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
424 SMESH::SMESH_Hypothesis_ptr anHyp)
426 if(MYDEBUG) MESSAGE("addHypothesis");
428 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
429 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
432 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
433 if (CORBA::is_nil(myHyp))
434 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
437 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
440 TopoDS_Shape myLocSubShape;
441 //use PseudoShape in case if mesh has no shape
443 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
445 myLocSubShape = _impl->GetShapeToMesh();
447 int hypId = myHyp->GetId();
448 status = _impl->AddHypothesis(myLocSubShape, hypId);
449 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
450 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
451 // assure there is a corresponding submesh
452 if ( !_impl->IsMainShape( myLocSubShape )) {
453 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
454 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
455 createSubMesh( aSubShapeObject );
459 catch(SALOME_Exception & S_ex)
461 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
466 //=============================================================================
470 //=============================================================================
472 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
473 SMESH::SMESH_Hypothesis_ptr anHyp)
474 throw(SALOME::SALOME_Exception)
476 Unexpect aCatch(SALOME_SalomeException);
477 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
479 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
480 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
481 aSubShapeObject, anHyp );
483 // Update Python script
484 // Update Python script
485 if(_impl->HasShapeToMesh()) {
486 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
487 << aSubShapeObject << ", " << anHyp << " )";
490 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
494 return ConvertHypothesisStatus(status);
497 //=============================================================================
501 //=============================================================================
503 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
504 SMESH::SMESH_Hypothesis_ptr anHyp)
506 if(MYDEBUG) MESSAGE("removeHypothesis()");
507 // **** proposer liste de subShape (selection multiple)
509 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
510 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
513 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
514 if (CORBA::is_nil(myHyp))
515 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
518 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
521 TopoDS_Shape myLocSubShape;
522 //use PseudoShape in case if mesh has no shape
524 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
526 myLocSubShape = _impl->GetShapeToMesh();
528 int hypId = myHyp->GetId();
529 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
530 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
531 _mapHypo.erase( hypId );
533 catch(SALOME_Exception & S_ex)
535 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
540 //=============================================================================
544 //=============================================================================
546 SMESH::ListOfHypothesis *
547 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
548 throw(SALOME::SALOME_Exception)
550 Unexpect aCatch(SALOME_SalomeException);
551 if (MYDEBUG) MESSAGE("GetHypothesisList");
552 if (CORBA::is_nil(aSubShapeObject))
553 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
556 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
559 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
560 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
561 int i = 0, n = aLocalList.size();
564 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
565 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
566 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
567 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
572 catch(SALOME_Exception & S_ex) {
573 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
576 return aList._retn();
579 //=============================================================================
583 //=============================================================================
584 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
585 const char* theName )
586 throw(SALOME::SALOME_Exception)
588 Unexpect aCatch(SALOME_SalomeException);
589 MESSAGE("SMESH_Mesh_i::GetSubMesh");
590 if (CORBA::is_nil(aSubShapeObject))
591 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
594 SMESH::SMESH_subMesh_var subMesh;
595 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
597 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
599 //Get or Create the SMESH_subMesh object implementation
601 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
602 subMesh = getSubMesh( subMeshId );
604 // create a new subMesh object servant if there is none for the shape
605 if ( subMesh->_is_nil() )
606 subMesh = createSubMesh( aSubShapeObject );
608 if ( _gen_i->CanPublishInStudy( subMesh )) {
609 SALOMEDS::SObject_var aSO =
610 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
611 subMesh, aSubShapeObject, theName );
612 if ( !aSO->_is_nil()) {
613 // Update Python script
614 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
615 << aSubShapeObject << ", '" << theName << "' )";
619 catch(SALOME_Exception & S_ex) {
620 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
622 return subMesh._retn();
625 //=============================================================================
629 //=============================================================================
631 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
632 throw (SALOME::SALOME_Exception)
634 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
635 if ( theSubMesh->_is_nil() )
638 GEOM::GEOM_Object_var aSubShapeObject;
639 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
640 if ( !aStudy->_is_nil() ) {
641 // Remove submesh's SObject
642 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
643 if ( !anSO->_is_nil() ) {
644 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
645 SALOMEDS::SObject_var anObj, aRef;
646 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
647 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
649 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
651 // Update Python script
652 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
656 removeSubMesh( theSubMesh, aSubShapeObject.in() );
659 //=============================================================================
663 //=============================================================================
664 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
665 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
667 switch (theElemType) {
672 CASE2STRING( VOLUME );
678 //=============================================================================
682 //=============================================================================
684 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
685 const char* theName )
686 throw(SALOME::SALOME_Exception)
688 Unexpect aCatch(SALOME_SalomeException);
689 SMESH::SMESH_Group_var aNewGroup =
690 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
692 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
693 SALOMEDS::SObject_var aSO =
694 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
695 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
696 if ( !aSO->_is_nil()) {
697 // Update Python script
698 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
699 << ElementTypeString(theElemType) << ", '" << theName << "' )";
702 return aNewGroup._retn();
706 //=============================================================================
710 //=============================================================================
711 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
713 GEOM::GEOM_Object_ptr theGeomObj)
714 throw(SALOME::SALOME_Exception)
716 Unexpect aCatch(SALOME_SalomeException);
717 SMESH::SMESH_GroupOnGeom_var aNewGroup;
719 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
720 if ( !aShape.IsNull() ) {
721 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
722 ( createGroup( theElemType, theName, aShape ));
723 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
724 SALOMEDS::SObject_var aSO =
725 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
726 aNewGroup, theGeomObj, theName);
727 if ( !aSO->_is_nil()) {
728 // Update Python script
729 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
730 << ElementTypeString(theElemType) << ", '" << theName << "', "
731 << theGeomObj << " )";
736 return aNewGroup._retn();
739 //=============================================================================
743 //=============================================================================
745 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
746 throw (SALOME::SALOME_Exception)
748 if ( theGroup->_is_nil() )
751 SMESH_GroupBase_i* aGroup =
752 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
756 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
757 if ( !aStudy->_is_nil() ) {
758 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
760 if ( !aGroupSO->_is_nil() ) {
761 // Update Python script
762 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
764 // Remove group's SObject
765 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
769 // Remove the group from SMESH data structures
770 removeGroup( aGroup->GetLocalID() );
773 //=============================================================================
774 /*! RemoveGroupWithContents
775 * Remove group with its contents
777 //=============================================================================
778 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
779 throw (SALOME::SALOME_Exception)
781 if ( theGroup->_is_nil() )
784 SMESH_GroupBase_i* aGroup =
785 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
789 SMESH::long_array_var anIds = aGroup->GetListOfID();
790 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
792 // Update Python script
793 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
796 if ( aGroup->GetType() == SMESH::NODE )
797 aMeshEditor->RemoveNodes( anIds );
799 aMeshEditor->RemoveElements( anIds );
802 RemoveGroup( theGroup );
804 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
805 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
806 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
810 //================================================================================
812 * \brief Get the list of groups existing in the mesh
813 * \retval SMESH::ListOfGroups * - list of groups
815 //================================================================================
817 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
819 Unexpect aCatch(SALOME_SalomeException);
820 if (MYDEBUG) MESSAGE("GetGroups");
822 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
825 TPythonDump aPythonDump;
826 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
830 aList->length( _mapGroups.size() );
832 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
833 for ( ; it != _mapGroups.end(); it++ ) {
834 if ( CORBA::is_nil( it->second )) continue;
835 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
837 if (i > 1) aPythonDump << ", ";
838 aPythonDump << it->second;
842 catch(SALOME_Exception & S_ex) {
843 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
846 // Update Python script
847 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
848 aPythonDump << " ] = " << _this() << ".GetGroups()";
850 return aList._retn();
852 //=============================================================================
854 * Get number of groups existing in the mesh
856 //=============================================================================
858 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
860 Unexpect aCatch(SALOME_SalomeException);
861 return _mapGroups.size();
864 //=============================================================================
866 * New group is created. All mesh elements that are
867 * present in initial groups are added to the new one
869 //=============================================================================
870 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
871 SMESH::SMESH_GroupBase_ptr theGroup2,
872 const char* theName )
873 throw (SALOME::SALOME_Exception)
877 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
878 theGroup1->GetType() != theGroup2->GetType() )
879 return SMESH::SMESH_Group::_nil();
882 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
883 if ( aResGrp->_is_nil() )
884 return SMESH::SMESH_Group::_nil();
886 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
887 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
889 TColStd_MapOfInteger aResMap;
891 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
892 aResMap.Add( anIds1[ i1 ] );
894 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
895 aResMap.Add( anIds2[ i2 ] );
897 SMESH::long_array_var aResIds = new SMESH::long_array;
898 aResIds->length( aResMap.Extent() );
901 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
902 for( ; anIter.More(); anIter.Next() )
903 aResIds[ resI++ ] = anIter.Key();
905 aResGrp->Add( aResIds );
907 // Clear python lines, created by CreateGroup() and Add()
908 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
909 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
910 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
912 // Update Python script
913 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
914 << theGroup1 << ", " << theGroup2 << ", '"
917 return aResGrp._retn();
921 return SMESH::SMESH_Group::_nil();
925 //=============================================================================
927 * New group is created. All mesh elements that are
928 * present in both initial groups are added to the new one.
930 //=============================================================================
931 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
932 SMESH::SMESH_GroupBase_ptr theGroup2,
933 const char* theName )
934 throw (SALOME::SALOME_Exception)
936 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
937 theGroup1->GetType() != theGroup2->GetType() )
938 return SMESH::SMESH_Group::_nil();
940 // Create Intersection
941 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
942 if ( aResGrp->_is_nil() )
945 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
946 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
948 TColStd_MapOfInteger aMap1;
950 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
951 aMap1.Add( anIds1[ i1 ] );
953 TColStd_SequenceOfInteger aSeq;
955 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
956 if ( aMap1.Contains( anIds2[ i2 ] ) )
957 aSeq.Append( anIds2[ i2 ] );
959 SMESH::long_array_var aResIds = new SMESH::long_array;
960 aResIds->length( aSeq.Length() );
962 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
963 aResIds[ resI ] = aSeq( resI + 1 );
965 aResGrp->Add( aResIds );
967 // Clear python lines, created by CreateGroup() and Add()
968 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
969 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
970 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
972 // Update Python script
973 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
974 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
976 return aResGrp._retn();
979 //=============================================================================
981 * New group is created. All mesh elements that are present in
982 * main group but do not present in tool group are added to the new one
984 //=============================================================================
985 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
986 SMESH::SMESH_GroupBase_ptr theGroup2,
987 const char* theName )
988 throw (SALOME::SALOME_Exception)
990 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
991 theGroup1->GetType() != theGroup2->GetType() )
992 return SMESH::SMESH_Group::_nil();
995 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
996 if ( aResGrp->_is_nil() )
999 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1000 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1002 TColStd_MapOfInteger aMap2;
1004 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1005 aMap2.Add( anIds2[ i2 ] );
1008 TColStd_SequenceOfInteger aSeq;
1009 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1010 if ( !aMap2.Contains( anIds1[ i1 ] ) )
1011 aSeq.Append( anIds1[ i1 ] );
1013 SMESH::long_array_var aResIds = new SMESH::long_array;
1014 aResIds->length( aSeq.Length() );
1016 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1017 aResIds[ resI ] = aSeq( resI + 1 );
1019 aResGrp->Add( aResIds );
1021 // Clear python lines, created by CreateGroup() and Add()
1022 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1023 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1024 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1026 // Update Python script
1027 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1028 << theGroup1 << ", " << theGroup2 << ", '"
1029 << theName << "' )";
1031 return aResGrp._retn();
1034 //================================================================================
1036 * \brief Return group items of a group present in a study
1038 //================================================================================
1040 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
1041 SMESH_Gen_i* theGen,
1042 list<TopoDS_Shape> & theItems)
1044 GEOM::GEOM_Object_var groupObj;
1045 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
1046 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
1047 if ( study->_is_nil() || geomGen->_is_nil() )
1048 return groupObj._retn();
1050 GEOM::GEOM_IGroupOperations_var groupOp =
1051 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
1052 GEOM::GEOM_IShapesOperations_var shapeOp =
1053 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
1055 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
1056 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
1057 return groupObj._retn();
1058 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
1059 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
1060 return groupObj._retn(); // keep only submeshes on groups
1062 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
1063 if ( anIter->_is_nil() ) return groupObj._retn();
1064 for ( ; anIter->More(); anIter->Next())
1066 SALOMEDS::SObject_var aSObject = anIter->Value();
1067 SALOMEDS::SObject_var aRefSO;
1068 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
1070 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
1071 if ( groupObj->_is_nil() ) break;
1072 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1073 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1074 for ( int i = 0; i < ids->length(); ++i ) {
1075 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1076 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1078 theItems.push_back( S );
1083 return groupObj._retn();
1086 //=============================================================================
1088 * \brief Update hypotheses assigned to geom groups if the latter change
1090 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1092 //=============================================================================
1094 void SMESH_Mesh_i::CheckGeomGroupModif()
1096 if ( !_impl->HasShapeToMesh() ) return;
1098 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1099 if ( study->_is_nil() ) return;
1101 // check if items of groups changed
1102 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1103 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1105 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1106 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1107 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1109 int oldID = i_sm->first;
1110 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1111 if ( i_smIor == _mapSubMeshIor.end() )
1113 list< TopoDS_Shape> newItems;
1114 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1115 if ( groupObj->_is_nil() )
1118 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1119 int nbNewItems = newItems.size();
1120 bool groupChanged = ( nbOldItems != nbNewItems);
1121 if ( !groupChanged ) {
1122 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1123 groupChanged = ( oldGroupShape != newItems.front() );
1126 list<TopoDS_Shape>::iterator item = newItems.begin();
1127 for ( ; item != newItems.end() && !groupChanged; ++item )
1129 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1130 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1134 // update hypotheses and submeshes if necessary
1137 // get a new group shape
1138 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1139 if ( !geomClient ) continue;
1140 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1141 geomClient->RemoveShapeFromBuffer( groupIOR );
1142 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1143 // update hypotheses
1144 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1145 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1146 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1148 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1149 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1151 // care of submeshes
1152 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1153 int newID = newSubmesh->GetId();
1154 if ( newID != oldID ) {
1155 _mapSubMesh [ newID ] = newSubmesh;
1156 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1157 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1158 _mapSubMesh.erase (oldID);
1159 _mapSubMesh_i.erase (oldID);
1160 _mapSubMeshIor.erase(oldID);
1161 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1167 //=============================================================================
1171 //=============================================================================
1173 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1175 if(MYDEBUG) MESSAGE( "createSubMesh" );
1176 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1178 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1179 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1180 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1181 SMESH::SMESH_subMesh_var subMesh
1182 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1184 _mapSubMesh[subMeshId] = mySubMesh;
1185 _mapSubMesh_i[subMeshId] = subMeshServant;
1186 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1188 // register CORBA object for persistence
1189 int nextId = _gen_i->RegisterObject( subMesh );
1190 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1192 return subMesh._retn();
1195 //=======================================================================
1196 //function : getSubMesh
1198 //=======================================================================
1200 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1202 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1203 if ( it == _mapSubMeshIor.end() )
1204 return SMESH::SMESH_subMesh::_nil();
1206 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1210 //=============================================================================
1214 //=============================================================================
1216 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1217 GEOM::GEOM_Object_ptr theSubShapeObject )
1219 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1220 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1224 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1225 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1226 removeHypothesis( theSubShapeObject, aHypList[i] );
1229 catch( const SALOME::SALOME_Exception& ) {
1230 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1233 int subMeshId = theSubMesh->GetId();
1235 _mapSubMesh.erase(subMeshId);
1236 _mapSubMesh_i.erase(subMeshId);
1237 _mapSubMeshIor.erase(subMeshId);
1238 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1241 //=============================================================================
1245 //=============================================================================
1247 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1248 const char* theName,
1249 const TopoDS_Shape& theShape )
1252 SMESH::SMESH_GroupBase_var aGroup;
1253 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1254 SMESH_GroupBase_i* aGroupImpl;
1255 if ( !theShape.IsNull() )
1256 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1258 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1260 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1261 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1262 aGroupImpl->Register();
1263 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1265 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1266 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1268 // register CORBA object for persistence
1269 int nextId = _gen_i->RegisterObject( aGroup );
1270 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1272 return aGroup._retn();
1275 //=============================================================================
1277 * SMESH_Mesh_i::removeGroup
1279 * Should be called by ~SMESH_Group_i()
1281 //=============================================================================
1283 void SMESH_Mesh_i::removeGroup( const int theId )
1285 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1286 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1287 _mapGroups.erase( theId );
1288 _impl->RemoveGroup( theId );
1293 //=============================================================================
1297 //=============================================================================
1299 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1300 throw(SALOME::SALOME_Exception)
1302 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1304 SMESH::log_array_var aLog;
1306 list < SMESHDS_Command * >logDS = _impl->GetLog();
1307 aLog = new SMESH::log_array;
1309 int lg = logDS.size();
1312 list < SMESHDS_Command * >::iterator its = logDS.begin();
1313 while(its != logDS.end()){
1314 SMESHDS_Command *com = *its;
1315 int comType = com->GetType();
1317 int lgcom = com->GetNumber();
1319 const list < int >&intList = com->GetIndexes();
1320 int inum = intList.size();
1322 list < int >::const_iterator ii = intList.begin();
1323 const list < double >&coordList = com->GetCoords();
1324 int rnum = coordList.size();
1326 list < double >::const_iterator ir = coordList.begin();
1327 aLog[indexLog].commandType = comType;
1328 aLog[indexLog].number = lgcom;
1329 aLog[indexLog].coords.length(rnum);
1330 aLog[indexLog].indexes.length(inum);
1331 for(int i = 0; i < rnum; i++){
1332 aLog[indexLog].coords[i] = *ir;
1333 //MESSAGE(" "<<i<<" "<<ir.Value());
1336 for(int i = 0; i < inum; i++){
1337 aLog[indexLog].indexes[i] = *ii;
1338 //MESSAGE(" "<<i<<" "<<ii.Value());
1347 catch(SALOME_Exception & S_ex){
1348 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1350 return aLog._retn();
1354 //=============================================================================
1358 //=============================================================================
1360 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1362 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1366 //=============================================================================
1370 //=============================================================================
1372 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1374 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1378 //=============================================================================
1382 //=============================================================================
1384 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1389 //=============================================================================
1393 //=============================================================================
1395 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1397 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1401 //=============================================================================
1405 //=============================================================================
1407 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1409 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1413 //=============================================================================
1415 * Return mesh editor
1417 //=============================================================================
1419 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1421 // Create MeshEditor
1422 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1423 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1425 // Update Python script
1426 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1428 return aMesh._retn();
1431 //=============================================================================
1433 * Return mesh edition previewer
1435 //=============================================================================
1437 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1439 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1440 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1441 return aMesh._retn();
1444 //=============================================================================
1448 //=============================================================================
1449 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1451 Unexpect aCatch(SALOME_SalomeException);
1452 _impl->SetAutoColor(theAutoColor);
1455 //=============================================================================
1459 //=============================================================================
1460 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1462 Unexpect aCatch(SALOME_SalomeException);
1463 return _impl->GetAutoColor();
1467 //=============================================================================
1469 * Export in different formats
1471 //=============================================================================
1473 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1475 return _impl->HasDuplicatedGroupNamesMED();
1478 void SMESH_Mesh_i::PrepareForWriting (const char* file)
1480 TCollection_AsciiString aFullName ((char*)file);
1481 OSD_Path aPath (aFullName);
1482 OSD_File aFile (aPath);
1483 if (aFile.Exists()) {
1484 // existing filesystem node
1485 if (aFile.KindOfFile() == OSD_FILE) {
1486 if (aFile.IsWriteable()) {
1489 if (aFile.Failed()) {
1490 TCollection_AsciiString msg ("File ");
1491 msg += aFullName + " cannot be replaced.";
1492 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1495 TCollection_AsciiString msg ("File ");
1496 msg += aFullName + " cannot be overwritten.";
1497 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1500 TCollection_AsciiString msg ("Location ");
1501 msg += aFullName + " is not a file.";
1502 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1505 // nonexisting file; check if it can be created
1507 aFile.Build(OSD_WriteOnly, OSD_Protection());
1508 if (aFile.Failed()) {
1509 TCollection_AsciiString msg ("You cannot create the file ");
1510 msg += aFullName + ". Check the directory existance and access rights.";
1511 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1519 void SMESH_Mesh_i::ExportToMED (const char* file,
1520 CORBA::Boolean auto_groups,
1521 SMESH::MED_VERSION theVersion)
1522 throw(SALOME::SALOME_Exception)
1524 Unexpect aCatch(SALOME_SalomeException);
1526 // Update Python script
1527 TPythonDump() << _this() << ".ExportToMED( '"
1528 << file << "', " << auto_groups << ", " << theVersion << " )";
1531 PrepareForWriting(file);
1532 char* aMeshName = "Mesh";
1533 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1534 if ( !aStudy->_is_nil() ) {
1535 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1536 if ( !aMeshSO->_is_nil() ) {
1537 aMeshName = aMeshSO->GetName();
1539 //SCRUTE(aMeshName);
1540 //SCRUTE(aMeshSO->GetID());
1542 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1543 if ( !aStudy->GetProperties()->IsLocked() )
1545 SALOMEDS::GenericAttribute_var anAttr;
1546 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1547 SALOMEDS::AttributeExternalFileDef_var aFileName;
1548 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1549 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1550 ASSERT(!aFileName->_is_nil());
1551 aFileName->SetValue(file);
1552 SALOMEDS::AttributeFileType_var aFileType;
1553 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1554 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1555 ASSERT(!aFileType->_is_nil());
1556 aFileType->SetValue("FICHIERMED");
1560 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1563 void SMESH_Mesh_i::ExportMED (const char* file,
1564 CORBA::Boolean auto_groups)
1565 throw(SALOME::SALOME_Exception)
1567 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1570 void SMESH_Mesh_i::ExportDAT (const char *file)
1571 throw(SALOME::SALOME_Exception)
1573 Unexpect aCatch(SALOME_SalomeException);
1575 // Update Python script
1576 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1579 PrepareForWriting(file);
1580 _impl->ExportDAT(file);
1583 void SMESH_Mesh_i::ExportUNV (const char *file)
1584 throw(SALOME::SALOME_Exception)
1586 Unexpect aCatch(SALOME_SalomeException);
1588 // Update Python script
1589 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1592 PrepareForWriting(file);
1593 _impl->ExportUNV(file);
1596 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1597 throw(SALOME::SALOME_Exception)
1599 Unexpect aCatch(SALOME_SalomeException);
1601 // Update Python script
1602 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1605 PrepareForWriting(file);
1606 _impl->ExportSTL(file, isascii);
1609 //=============================================================================
1613 //=============================================================================
1615 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1617 Unexpect aCatch(SALOME_SalomeException);
1618 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1619 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1620 return aMesh._retn();
1623 //=============================================================================
1627 //=============================================================================
1628 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1630 Unexpect aCatch(SALOME_SalomeException);
1631 return _impl->NbNodes();
1634 //=============================================================================
1638 //=============================================================================
1639 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1641 Unexpect aCatch(SALOME_SalomeException);
1642 return NbEdges() + NbFaces() + NbVolumes();
1645 //=============================================================================
1649 //=============================================================================
1650 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1652 Unexpect aCatch(SALOME_SalomeException);
1653 return _impl->NbEdges();
1656 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1657 throw(SALOME::SALOME_Exception)
1659 Unexpect aCatch(SALOME_SalomeException);
1660 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
1663 //=============================================================================
1667 //=============================================================================
1668 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1670 Unexpect aCatch(SALOME_SalomeException);
1671 return _impl->NbFaces();
1674 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1676 Unexpect aCatch(SALOME_SalomeException);
1677 return _impl->NbTriangles();
1680 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1682 Unexpect aCatch(SALOME_SalomeException);
1683 return _impl->NbQuadrangles();
1686 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1688 Unexpect aCatch(SALOME_SalomeException);
1689 return _impl->NbPolygons();
1692 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1693 throw(SALOME::SALOME_Exception)
1695 Unexpect aCatch(SALOME_SalomeException);
1696 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
1699 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1700 throw(SALOME::SALOME_Exception)
1702 Unexpect aCatch(SALOME_SalomeException);
1703 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
1706 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1707 throw(SALOME::SALOME_Exception)
1709 Unexpect aCatch(SALOME_SalomeException);
1710 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
1713 //=============================================================================
1717 //=============================================================================
1718 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1720 Unexpect aCatch(SALOME_SalomeException);
1721 return _impl->NbVolumes();
1724 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1726 Unexpect aCatch(SALOME_SalomeException);
1727 return _impl->NbTetras();
1730 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1732 Unexpect aCatch(SALOME_SalomeException);
1733 return _impl->NbHexas();
1736 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1738 Unexpect aCatch(SALOME_SalomeException);
1739 return _impl->NbPyramids();
1742 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1744 Unexpect aCatch(SALOME_SalomeException);
1745 return _impl->NbPrisms();
1748 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1750 Unexpect aCatch(SALOME_SalomeException);
1751 return _impl->NbPolyhedrons();
1754 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1755 throw(SALOME::SALOME_Exception)
1757 Unexpect aCatch(SALOME_SalomeException);
1758 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
1761 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1762 throw(SALOME::SALOME_Exception)
1764 Unexpect aCatch(SALOME_SalomeException);
1765 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
1768 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1769 throw(SALOME::SALOME_Exception)
1771 Unexpect aCatch(SALOME_SalomeException);
1772 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
1775 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1776 throw(SALOME::SALOME_Exception)
1778 Unexpect aCatch(SALOME_SalomeException);
1779 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
1782 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1783 throw(SALOME::SALOME_Exception)
1785 Unexpect aCatch(SALOME_SalomeException);
1786 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
1789 //=============================================================================
1793 //=============================================================================
1794 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1796 Unexpect aCatch(SALOME_SalomeException);
1797 return _impl->NbSubMesh();
1800 //=============================================================================
1804 //=============================================================================
1805 char* SMESH_Mesh_i::Dump()
1807 std::ostringstream os;
1809 return CORBA::string_dup( os.str().c_str() );
1812 //=============================================================================
1816 //=============================================================================
1817 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1819 // SMESH::long_array_var aResult = new SMESH::long_array();
1820 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1821 // int aMinId = aSMESHDS_Mesh->MinElementID();
1822 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1824 // aResult->length(aMaxId - aMinId + 1);
1826 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1827 // aResult[i++] = id;
1829 // return aResult._retn();
1831 return GetElementsId();
1834 //=============================================================================
1838 //=============================================================================
1840 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1841 throw (SALOME::SALOME_Exception)
1843 Unexpect aCatch(SALOME_SalomeException);
1844 MESSAGE("SMESH_Mesh_i::GetElementsId");
1845 SMESH::long_array_var aResult = new SMESH::long_array();
1846 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1848 if ( aSMESHDS_Mesh == NULL )
1849 return aResult._retn();
1851 long nbElements = NbElements();
1852 aResult->length( nbElements );
1853 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1854 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1855 aResult[i] = anIt->next()->GetID();
1857 return aResult._retn();
1861 //=============================================================================
1865 //=============================================================================
1867 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1868 throw (SALOME::SALOME_Exception)
1870 Unexpect aCatch(SALOME_SalomeException);
1871 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1872 SMESH::long_array_var aResult = new SMESH::long_array();
1873 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1875 if ( aSMESHDS_Mesh == NULL )
1876 return aResult._retn();
1878 long nbElements = NbElements();
1880 // No sense in returning ids of elements along with ids of nodes:
1881 // when theElemType == SMESH::ALL, return node ids only if
1882 // there are no elements
1883 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1884 return GetNodesId();
1886 aResult->length( nbElements );
1890 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1891 while ( i < nbElements && anIt->more() ) {
1892 const SMDS_MeshElement* anElem = anIt->next();
1893 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1894 aResult[i++] = anElem->GetID();
1897 aResult->length( i );
1899 return aResult._retn();
1902 //=============================================================================
1906 //=============================================================================
1908 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1909 throw (SALOME::SALOME_Exception)
1911 Unexpect aCatch(SALOME_SalomeException);
1912 MESSAGE("SMESH_subMesh_i::GetNodesId");
1913 SMESH::long_array_var aResult = new SMESH::long_array();
1914 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1916 if ( aSMESHDS_Mesh == NULL )
1917 return aResult._retn();
1919 long nbNodes = NbNodes();
1920 aResult->length( nbNodes );
1921 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1922 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1923 aResult[i] = anIt->next()->GetID();
1925 return aResult._retn();
1928 //=============================================================================
1932 //=============================================================================
1934 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1935 throw (SALOME::SALOME_Exception)
1937 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1941 //=============================================================================
1943 * Returns ID of elements for given submesh
1945 //=============================================================================
1946 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1947 throw (SALOME::SALOME_Exception)
1949 SMESH::long_array_var aResult = new SMESH::long_array();
1951 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1952 if(!SM) return aResult._retn();
1954 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1955 if(!SDSM) return aResult._retn();
1957 aResult->length(SDSM->NbElements());
1959 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1961 while ( eIt->more() ) {
1962 aResult[i++] = eIt->next()->GetID();
1965 return aResult._retn();
1969 //=============================================================================
1971 * Returns ID of nodes for given submesh
1972 * If param all==true - returns all nodes, else -
1973 * returns only nodes on shapes.
1975 //=============================================================================
1976 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1977 throw (SALOME::SALOME_Exception)
1979 SMESH::long_array_var aResult = new SMESH::long_array();
1981 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1982 if(!SM) return aResult._retn();
1984 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1985 if(!SDSM) return aResult._retn();
1988 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
1989 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1990 while ( nIt->more() ) {
1991 const SMDS_MeshNode* elem = nIt->next();
1992 theElems.insert( elem->GetID() );
1995 else { // all nodes of submesh elements
1996 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1997 while ( eIt->more() ) {
1998 const SMDS_MeshElement* anElem = eIt->next();
1999 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
2000 while ( nIt->more() ) {
2001 const SMDS_MeshElement* elem = nIt->next();
2002 theElems.insert( elem->GetID() );
2007 aResult->length(theElems.size());
2008 set<int>::iterator itElem;
2010 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
2011 aResult[i++] = *itElem;
2013 return aResult._retn();
2017 //=============================================================================
2019 * Returns type of elements for given submesh
2021 //=============================================================================
2022 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2023 throw (SALOME::SALOME_Exception)
2025 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2026 if(!SM) return SMESH::ALL;
2028 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2029 if(!SDSM) return SMESH::ALL;
2031 if(SDSM->NbElements()==0)
2032 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2034 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2035 const SMDS_MeshElement* anElem = eIt->next();
2036 return ( SMESH::ElementType ) anElem->GetType();
2040 //=============================================================================
2044 //=============================================================================
2046 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2048 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2050 MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
2055 //=============================================================================
2057 * Get XYZ coordinates of node as list of double
2058 * If there is not node for given ID - returns empty list
2060 //=============================================================================
2062 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2064 SMESH::double_array_var aResult = new SMESH::double_array();
2065 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2066 if ( aSMESHDS_Mesh == NULL )
2067 return aResult._retn();
2070 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2072 return aResult._retn();
2076 aResult[0] = aNode->X();
2077 aResult[1] = aNode->Y();
2078 aResult[2] = aNode->Z();
2079 return aResult._retn();
2083 //=============================================================================
2085 * For given node returns list of IDs of inverse elements
2086 * If there is not node for given ID - returns empty list
2088 //=============================================================================
2090 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2092 SMESH::long_array_var aResult = new SMESH::long_array();
2093 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2094 if ( aSMESHDS_Mesh == NULL )
2095 return aResult._retn();
2098 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2100 return aResult._retn();
2102 // find inverse elements
2103 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2104 TColStd_SequenceOfInteger IDs;
2105 while(eIt->more()) {
2106 const SMDS_MeshElement* elem = eIt->next();
2107 IDs.Append(elem->GetID());
2109 if(IDs.Length()>0) {
2110 aResult->length(IDs.Length());
2112 for(; i<=IDs.Length(); i++) {
2113 aResult[i-1] = IDs.Value(i);
2116 return aResult._retn();
2119 //=============================================================================
2121 * \brief Return position of a node on shape
2123 //=============================================================================
2125 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2127 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2128 aNodePosition->shapeID = 0;
2129 aNodePosition->shapeType = GEOM::SHAPE;
2131 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2132 if ( !mesh ) return aNodePosition;
2134 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2136 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2138 aNodePosition->shapeID = pos->GetShapeId();
2139 switch ( pos->GetTypeOfPosition() ) {
2141 aNodePosition->shapeType = GEOM::EDGE;
2142 aNodePosition->params.length(1);
2143 aNodePosition->params[0] =
2144 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2147 aNodePosition->shapeType = GEOM::FACE;
2148 aNodePosition->params.length(2);
2149 aNodePosition->params[0] =
2150 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2151 aNodePosition->params[1] =
2152 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2154 case SMDS_TOP_VERTEX:
2155 aNodePosition->shapeType = GEOM::VERTEX;
2157 case SMDS_TOP_3DSPACE:
2158 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2159 aNodePosition->shapeType = GEOM::SOLID;
2160 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2161 aNodePosition->shapeType = GEOM::SHELL;
2167 return aNodePosition;
2170 //=============================================================================
2172 * If given element is node returns IDs of shape from position
2173 * If there is not node for given ID - returns -1
2175 //=============================================================================
2177 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2179 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2180 if ( aSMESHDS_Mesh == NULL )
2184 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2186 SMDS_PositionPtr pos = aNode->GetPosition();
2190 return pos->GetShapeId();
2197 //=============================================================================
2199 * For given element returns ID of result shape after
2200 * ::FindShape() from SMESH_MeshEditor
2201 * If there is not element for given ID - returns -1
2203 //=============================================================================
2205 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2207 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2208 if ( aSMESHDS_Mesh == NULL )
2211 // try to find element
2212 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2216 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2217 ::SMESH_MeshEditor aMeshEditor(_impl);
2218 int index = aMeshEditor.FindShape( elem );
2226 //=============================================================================
2228 * Returns number of nodes for given element
2229 * If there is not element for given ID - returns -1
2231 //=============================================================================
2233 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2235 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2236 if ( aSMESHDS_Mesh == NULL ) return -1;
2237 // try to find element
2238 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2239 if(!elem) return -1;
2240 return elem->NbNodes();
2244 //=============================================================================
2246 * Returns ID of node by given index for given element
2247 * If there is not element for given ID - returns -1
2248 * If there is not node for given index - returns -2
2250 //=============================================================================
2252 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2254 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2255 if ( aSMESHDS_Mesh == NULL ) return -1;
2256 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2257 if(!elem) return -1;
2258 if( index>=elem->NbNodes() || index<0 ) return -1;
2259 return elem->GetNode(index)->GetID();
2262 //=============================================================================
2264 * Returns IDs of nodes of given element
2266 //=============================================================================
2268 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2270 SMESH::long_array_var aResult = new SMESH::long_array();
2271 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2273 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2275 aResult->length( elem->NbNodes() );
2276 for ( int i = 0; i < elem->NbNodes(); ++i )
2277 aResult[ i ] = elem->GetNode( i )->GetID();
2280 return aResult._retn();
2283 //=============================================================================
2285 * Returns true if given node is medium node
2286 * in given quadratic element
2288 //=============================================================================
2290 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2292 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2293 if ( aSMESHDS_Mesh == NULL ) return false;
2295 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2296 if(!aNode) return false;
2297 // try to find element
2298 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2299 if(!elem) return false;
2301 return elem->IsMediumNode(aNode);
2305 //=============================================================================
2307 * Returns true if given node is medium node
2308 * in one of quadratic elements
2310 //=============================================================================
2312 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2313 SMESH::ElementType theElemType)
2315 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2316 if ( aSMESHDS_Mesh == NULL ) return false;
2319 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2320 if(!aNode) return false;
2322 SMESH_MesherHelper aHelper( *(_impl) );
2324 SMDSAbs_ElementType aType;
2325 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2326 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2327 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2328 else aType = SMDSAbs_All;
2330 return aHelper.IsMedium(aNode,aType);
2334 //=============================================================================
2336 * Returns number of edges for given element
2338 //=============================================================================
2340 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2342 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2343 if ( aSMESHDS_Mesh == NULL ) return -1;
2344 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2345 if(!elem) return -1;
2346 return elem->NbEdges();
2350 //=============================================================================
2352 * Returns number of faces for given element
2354 //=============================================================================
2356 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2358 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2359 if ( aSMESHDS_Mesh == NULL ) return -1;
2360 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2361 if(!elem) return -1;
2362 return elem->NbFaces();
2366 //=============================================================================
2368 * Returns true if given element is polygon
2370 //=============================================================================
2372 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2374 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2375 if ( aSMESHDS_Mesh == NULL ) return false;
2376 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2377 if(!elem) return false;
2378 return elem->IsPoly();
2382 //=============================================================================
2384 * Returns true if given element is quadratic
2386 //=============================================================================
2388 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2390 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2391 if ( aSMESHDS_Mesh == NULL ) return false;
2392 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2393 if(!elem) return false;
2394 return elem->IsQuadratic();
2398 //=============================================================================
2400 * Returns bary center for given element
2402 //=============================================================================
2404 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2406 SMESH::double_array_var aResult = new SMESH::double_array();
2407 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2408 if ( aSMESHDS_Mesh == NULL )
2409 return aResult._retn();
2411 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2413 return aResult._retn();
2415 if(elem->GetType()==SMDSAbs_Volume) {
2416 SMDS_VolumeTool aTool;
2417 if(aTool.Set(elem)) {
2419 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2424 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2426 double x=0., y=0., z=0.;
2427 for(; anIt->more(); ) {
2429 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2443 return aResult._retn();
2447 //=============================================================================
2449 * Create and publish group servants if any groups were imported or created anyhow
2451 //=============================================================================
2453 void SMESH_Mesh_i::CreateGroupServants()
2455 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2457 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2458 while ( groupIt->more() )
2460 ::SMESH_Group* group = groupIt->next();
2461 int anId = group->GetGroupDS()->GetID();
2463 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
2464 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2467 SMESH_GroupBase_i* aGroupImpl;
2469 if ( SMESHDS_GroupOnGeom* groupOnGeom =
2470 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
2472 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2473 shape = groupOnGeom->GetShape();
2476 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2479 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
2480 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2481 aGroupImpl->Register();
2483 SMESH::SMESH_GroupBase_var groupVar =
2484 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2485 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
2487 // register CORBA object for persistence
2488 int nextId = _gen_i->RegisterObject( groupVar );
2489 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2491 // publishing of the groups in the study
2492 if ( !aStudy->_is_nil() ) {
2493 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
2494 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
2499 //=============================================================================
2501 * \brief Return groups cantained in _mapGroups by their IDs
2503 //=============================================================================
2505 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
2507 int nbGroups = groupIDs.size();
2508 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
2509 aList->length( nbGroups );
2511 list<int>::const_iterator ids = groupIDs.begin();
2512 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
2514 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
2515 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2516 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
2518 aList->length( nbGroups );
2519 return aList._retn();
2522 //=============================================================================
2524 * \brief Return information about imported file
2526 //=============================================================================
2528 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
2530 SALOME_MED::MedFileInfo_var res( myFileInfo );
2531 if ( !res.operator->() ) {
2532 res = new SALOME_MED::MedFileInfo;
2534 res->fileSize = res->major = res->minor = res->release = -1;