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 );
377 return SMESH::HYP_UNKNOWN_FATAL;
380 //=============================================================================
384 * calls internal addHypothesis() and then adds a reference to <anHyp> under
385 * the SObject actually having a reference to <aSubShape>.
386 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
388 //=============================================================================
390 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
391 SMESH::SMESH_Hypothesis_ptr anHyp)
392 throw(SALOME::SALOME_Exception)
394 Unexpect aCatch(SALOME_SalomeException);
395 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
397 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
398 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
399 aSubShapeObject, anHyp );
401 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
403 // Update Python script
404 if(_impl->HasShapeToMesh()) {
405 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
406 << aSubShapeObject << ", " << anHyp << " )";
409 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
412 return ConvertHypothesisStatus(status);
415 //=============================================================================
419 //=============================================================================
421 SMESH_Hypothesis::Hypothesis_Status
422 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
423 SMESH::SMESH_Hypothesis_ptr anHyp)
425 if(MYDEBUG) MESSAGE("addHypothesis");
427 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
428 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
431 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
432 if (CORBA::is_nil(myHyp))
433 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
436 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
439 TopoDS_Shape myLocSubShape;
440 //use PseudoShape in case if mesh has no shape
442 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
444 myLocSubShape = _impl->GetShapeToMesh();
446 int hypId = myHyp->GetId();
447 status = _impl->AddHypothesis(myLocSubShape, hypId);
448 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
449 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
450 // assure there is a corresponding submesh
451 if ( !_impl->IsMainShape( myLocSubShape )) {
452 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
453 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
454 createSubMesh( aSubShapeObject );
458 catch(SALOME_Exception & S_ex)
460 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
465 //=============================================================================
469 //=============================================================================
471 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
472 SMESH::SMESH_Hypothesis_ptr anHyp)
473 throw(SALOME::SALOME_Exception)
475 Unexpect aCatch(SALOME_SalomeException);
476 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
478 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
479 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
480 aSubShapeObject, anHyp );
482 // Update Python script
483 // Update Python script
484 if(_impl->HasShapeToMesh()) {
485 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
486 << aSubShapeObject << ", " << anHyp << " )";
489 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
493 return ConvertHypothesisStatus(status);
496 //=============================================================================
500 //=============================================================================
502 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
503 SMESH::SMESH_Hypothesis_ptr anHyp)
505 if(MYDEBUG) MESSAGE("removeHypothesis()");
506 // **** proposer liste de subShape (selection multiple)
508 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
509 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
512 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
513 if (CORBA::is_nil(myHyp))
514 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
517 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
520 TopoDS_Shape myLocSubShape;
521 //use PseudoShape in case if mesh has no shape
523 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
525 myLocSubShape = _impl->GetShapeToMesh();
527 int hypId = myHyp->GetId();
528 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
529 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
530 _mapHypo.erase( hypId );
532 catch(SALOME_Exception & S_ex)
534 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
539 //=============================================================================
543 //=============================================================================
545 SMESH::ListOfHypothesis *
546 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
547 throw(SALOME::SALOME_Exception)
549 Unexpect aCatch(SALOME_SalomeException);
550 if (MYDEBUG) MESSAGE("GetHypothesisList");
551 if (CORBA::is_nil(aSubShapeObject))
552 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
555 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
558 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
559 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
560 int i = 0, n = aLocalList.size();
563 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
564 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
565 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
566 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
571 catch(SALOME_Exception & S_ex) {
572 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
575 return aList._retn();
578 //=============================================================================
582 //=============================================================================
583 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
584 const char* theName )
585 throw(SALOME::SALOME_Exception)
587 Unexpect aCatch(SALOME_SalomeException);
588 MESSAGE("SMESH_Mesh_i::GetSubMesh");
589 if (CORBA::is_nil(aSubShapeObject))
590 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
593 SMESH::SMESH_subMesh_var subMesh;
594 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
596 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
598 //Get or Create the SMESH_subMesh object implementation
600 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
601 subMesh = getSubMesh( subMeshId );
603 // create a new subMesh object servant if there is none for the shape
604 if ( subMesh->_is_nil() )
605 subMesh = createSubMesh( aSubShapeObject );
607 if ( _gen_i->CanPublishInStudy( subMesh )) {
608 SALOMEDS::SObject_var aSO =
609 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
610 subMesh, aSubShapeObject, theName );
611 if ( !aSO->_is_nil()) {
612 // Update Python script
613 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
614 << aSubShapeObject << ", '" << theName << "' )";
618 catch(SALOME_Exception & S_ex) {
619 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
621 return subMesh._retn();
624 //=============================================================================
628 //=============================================================================
630 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
631 throw (SALOME::SALOME_Exception)
633 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
634 if ( theSubMesh->_is_nil() )
637 GEOM::GEOM_Object_var aSubShapeObject;
638 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
639 if ( !aStudy->_is_nil() ) {
640 // Remove submesh's SObject
641 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
642 if ( !anSO->_is_nil() ) {
643 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
644 SALOMEDS::SObject_var anObj, aRef;
645 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
646 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
648 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
650 // Update Python script
651 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
655 removeSubMesh( theSubMesh, aSubShapeObject.in() );
658 //=============================================================================
662 //=============================================================================
663 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
664 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
666 switch (theElemType) {
671 CASE2STRING( VOLUME );
677 //=============================================================================
681 //=============================================================================
683 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
684 const char* theName )
685 throw(SALOME::SALOME_Exception)
687 Unexpect aCatch(SALOME_SalomeException);
688 SMESH::SMESH_Group_var aNewGroup =
689 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
691 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
692 SALOMEDS::SObject_var aSO =
693 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
694 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
695 if ( !aSO->_is_nil()) {
696 // Update Python script
697 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
698 << ElementTypeString(theElemType) << ", '" << theName << "' )";
701 return aNewGroup._retn();
705 //=============================================================================
709 //=============================================================================
710 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
712 GEOM::GEOM_Object_ptr theGeomObj)
713 throw(SALOME::SALOME_Exception)
715 Unexpect aCatch(SALOME_SalomeException);
716 SMESH::SMESH_GroupOnGeom_var aNewGroup;
718 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
719 if ( !aShape.IsNull() ) {
720 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
721 ( createGroup( theElemType, theName, aShape ));
722 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
723 SALOMEDS::SObject_var aSO =
724 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
725 aNewGroup, theGeomObj, theName);
726 if ( !aSO->_is_nil()) {
727 // Update Python script
728 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
729 << ElementTypeString(theElemType) << ", '" << theName << "', "
730 << theGeomObj << " )";
735 return aNewGroup._retn();
738 //=============================================================================
742 //=============================================================================
744 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
745 throw (SALOME::SALOME_Exception)
747 if ( theGroup->_is_nil() )
750 SMESH_GroupBase_i* aGroup =
751 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
755 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
756 if ( !aStudy->_is_nil() ) {
757 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
759 if ( !aGroupSO->_is_nil() ) {
760 // Update Python script
761 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
763 // Remove group's SObject
764 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
768 // Remove the group from SMESH data structures
769 removeGroup( aGroup->GetLocalID() );
772 //=============================================================================
773 /*! RemoveGroupWithContents
774 * Remove group with its contents
776 //=============================================================================
777 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
778 throw (SALOME::SALOME_Exception)
780 if ( theGroup->_is_nil() )
783 SMESH_GroupBase_i* aGroup =
784 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
788 SMESH::long_array_var anIds = aGroup->GetListOfID();
789 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
791 // Update Python script
792 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
795 if ( aGroup->GetType() == SMESH::NODE )
796 aMeshEditor->RemoveNodes( anIds );
798 aMeshEditor->RemoveElements( anIds );
801 RemoveGroup( theGroup );
803 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
804 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
805 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
809 //================================================================================
811 * \brief Get the list of groups existing in the mesh
812 * \retval SMESH::ListOfGroups * - list of groups
814 //================================================================================
816 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
818 Unexpect aCatch(SALOME_SalomeException);
819 if (MYDEBUG) MESSAGE("GetGroups");
821 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
824 TPythonDump aPythonDump;
825 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
829 aList->length( _mapGroups.size() );
831 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
832 for ( ; it != _mapGroups.end(); it++ ) {
833 if ( CORBA::is_nil( it->second )) continue;
834 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
836 if (i > 1) aPythonDump << ", ";
837 aPythonDump << it->second;
841 catch(SALOME_Exception & S_ex) {
842 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
845 // Update Python script
846 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
847 aPythonDump << " ] = " << _this() << ".GetGroups()";
849 return aList._retn();
851 //=============================================================================
853 * Get number of groups existing in the mesh
855 //=============================================================================
857 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
859 Unexpect aCatch(SALOME_SalomeException);
860 return _mapGroups.size();
863 //=============================================================================
865 * New group is created. All mesh elements that are
866 * present in initial groups are added to the new one
868 //=============================================================================
869 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
870 SMESH::SMESH_GroupBase_ptr theGroup2,
871 const char* theName )
872 throw (SALOME::SALOME_Exception)
876 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
877 theGroup1->GetType() != theGroup2->GetType() )
878 return SMESH::SMESH_Group::_nil();
881 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
882 if ( aResGrp->_is_nil() )
883 return SMESH::SMESH_Group::_nil();
885 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
886 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
888 TColStd_MapOfInteger aResMap;
890 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
891 aResMap.Add( anIds1[ i1 ] );
893 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
894 aResMap.Add( anIds2[ i2 ] );
896 SMESH::long_array_var aResIds = new SMESH::long_array;
897 aResIds->length( aResMap.Extent() );
900 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
901 for( ; anIter.More(); anIter.Next() )
902 aResIds[ resI++ ] = anIter.Key();
904 aResGrp->Add( aResIds );
906 // Clear python lines, created by CreateGroup() and Add()
907 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
908 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
909 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
911 // Update Python script
912 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
913 << theGroup1 << ", " << theGroup2 << ", '"
916 return aResGrp._retn();
920 return SMESH::SMESH_Group::_nil();
924 //=============================================================================
926 * New group is created. All mesh elements that are
927 * present in both initial groups are added to the new one.
929 //=============================================================================
930 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
931 SMESH::SMESH_GroupBase_ptr theGroup2,
932 const char* theName )
933 throw (SALOME::SALOME_Exception)
935 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
936 theGroup1->GetType() != theGroup2->GetType() )
937 return SMESH::SMESH_Group::_nil();
939 // Create Intersection
940 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
941 if ( aResGrp->_is_nil() )
944 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
945 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
947 TColStd_MapOfInteger aMap1;
949 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
950 aMap1.Add( anIds1[ i1 ] );
952 TColStd_SequenceOfInteger aSeq;
954 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
955 if ( aMap1.Contains( anIds2[ i2 ] ) )
956 aSeq.Append( anIds2[ i2 ] );
958 SMESH::long_array_var aResIds = new SMESH::long_array;
959 aResIds->length( aSeq.Length() );
961 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
962 aResIds[ resI ] = aSeq( resI + 1 );
964 aResGrp->Add( aResIds );
966 // Clear python lines, created by CreateGroup() and Add()
967 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
968 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
969 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
971 // Update Python script
972 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
973 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
975 return aResGrp._retn();
978 //=============================================================================
980 * New group is created. All mesh elements that are present in
981 * main group but do not present in tool group are added to the new one
983 //=============================================================================
984 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
985 SMESH::SMESH_GroupBase_ptr theGroup2,
986 const char* theName )
987 throw (SALOME::SALOME_Exception)
989 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
990 theGroup1->GetType() != theGroup2->GetType() )
991 return SMESH::SMESH_Group::_nil();
994 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
995 if ( aResGrp->_is_nil() )
998 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
999 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1001 TColStd_MapOfInteger aMap2;
1003 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1004 aMap2.Add( anIds2[ i2 ] );
1007 TColStd_SequenceOfInteger aSeq;
1008 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1009 if ( !aMap2.Contains( anIds1[ i1 ] ) )
1010 aSeq.Append( anIds1[ i1 ] );
1012 SMESH::long_array_var aResIds = new SMESH::long_array;
1013 aResIds->length( aSeq.Length() );
1015 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1016 aResIds[ resI ] = aSeq( resI + 1 );
1018 aResGrp->Add( aResIds );
1020 // Clear python lines, created by CreateGroup() and Add()
1021 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1022 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1023 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1025 // Update Python script
1026 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1027 << theGroup1 << ", " << theGroup2 << ", '"
1028 << theName << "' )";
1030 return aResGrp._retn();
1033 //================================================================================
1035 * \brief Return group items of a group present in a study
1037 //================================================================================
1039 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
1040 SMESH_Gen_i* theGen,
1041 list<TopoDS_Shape> & theItems)
1043 GEOM::GEOM_Object_var groupObj;
1044 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
1045 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
1046 if ( study->_is_nil() || geomGen->_is_nil() )
1047 return groupObj._retn();
1049 GEOM::GEOM_IGroupOperations_var groupOp =
1050 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
1051 GEOM::GEOM_IShapesOperations_var shapeOp =
1052 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
1054 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
1055 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
1056 return groupObj._retn();
1057 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
1058 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
1059 return groupObj._retn(); // keep only submeshes on groups
1061 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
1062 if ( anIter->_is_nil() ) return groupObj._retn();
1063 for ( ; anIter->More(); anIter->Next())
1065 SALOMEDS::SObject_var aSObject = anIter->Value();
1066 SALOMEDS::SObject_var aRefSO;
1067 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
1069 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
1070 if ( groupObj->_is_nil() ) break;
1071 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1072 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1073 for ( int i = 0; i < ids->length(); ++i ) {
1074 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1075 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1077 theItems.push_back( S );
1082 return groupObj._retn();
1085 //=============================================================================
1087 * \brief Update hypotheses assigned to geom groups if the latter change
1089 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1091 //=============================================================================
1093 void SMESH_Mesh_i::CheckGeomGroupModif()
1095 if ( !_impl->HasShapeToMesh() ) return;
1097 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1098 if ( study->_is_nil() ) return;
1100 // check if items of groups changed
1101 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1102 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1104 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1105 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1106 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1108 int oldID = i_sm->first;
1109 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1110 if ( i_smIor == _mapSubMeshIor.end() )
1112 list< TopoDS_Shape> newItems;
1113 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1114 if ( groupObj->_is_nil() )
1117 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1118 int nbNewItems = newItems.size();
1119 bool groupChanged = ( nbOldItems != nbNewItems);
1120 if ( !groupChanged ) {
1121 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1122 groupChanged = ( oldGroupShape != newItems.front() );
1125 list<TopoDS_Shape>::iterator item = newItems.begin();
1126 for ( ; item != newItems.end() && !groupChanged; ++item )
1128 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1129 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1133 // update hypotheses and submeshes if necessary
1136 // get a new group shape
1137 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1138 if ( !geomClient ) continue;
1139 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1140 geomClient->RemoveShapeFromBuffer( groupIOR );
1141 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1142 // update hypotheses
1143 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1144 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1145 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1147 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1148 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1150 // care of submeshes
1151 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1152 int newID = newSubmesh->GetId();
1153 if ( newID != oldID ) {
1154 _mapSubMesh [ newID ] = newSubmesh;
1155 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1156 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1157 _mapSubMesh.erase (oldID);
1158 _mapSubMesh_i.erase (oldID);
1159 _mapSubMeshIor.erase(oldID);
1160 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1166 //=============================================================================
1170 //=============================================================================
1172 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1174 if(MYDEBUG) MESSAGE( "createSubMesh" );
1175 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1177 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1178 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1179 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1180 SMESH::SMESH_subMesh_var subMesh
1181 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1183 _mapSubMesh[subMeshId] = mySubMesh;
1184 _mapSubMesh_i[subMeshId] = subMeshServant;
1185 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1187 // register CORBA object for persistence
1188 int nextId = _gen_i->RegisterObject( subMesh );
1189 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1191 return subMesh._retn();
1194 //=======================================================================
1195 //function : getSubMesh
1197 //=======================================================================
1199 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1201 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1202 if ( it == _mapSubMeshIor.end() )
1203 return SMESH::SMESH_subMesh::_nil();
1205 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1209 //=============================================================================
1213 //=============================================================================
1215 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1216 GEOM::GEOM_Object_ptr theSubShapeObject )
1218 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1219 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1223 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1224 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1225 removeHypothesis( theSubShapeObject, aHypList[i] );
1228 catch( const SALOME::SALOME_Exception& ) {
1229 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1232 int subMeshId = theSubMesh->GetId();
1234 _mapSubMesh.erase(subMeshId);
1235 _mapSubMesh_i.erase(subMeshId);
1236 _mapSubMeshIor.erase(subMeshId);
1237 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1240 //=============================================================================
1244 //=============================================================================
1246 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1247 const char* theName,
1248 const TopoDS_Shape& theShape )
1251 SMESH::SMESH_GroupBase_var aGroup;
1252 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1253 SMESH_GroupBase_i* aGroupImpl;
1254 if ( !theShape.IsNull() )
1255 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1257 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1259 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1260 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1261 aGroupImpl->Register();
1262 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1264 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1265 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1267 // register CORBA object for persistence
1268 int nextId = _gen_i->RegisterObject( aGroup );
1269 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1271 return aGroup._retn();
1274 //=============================================================================
1276 * SMESH_Mesh_i::removeGroup
1278 * Should be called by ~SMESH_Group_i()
1280 //=============================================================================
1282 void SMESH_Mesh_i::removeGroup( const int theId )
1284 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1285 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1286 _mapGroups.erase( theId );
1287 _impl->RemoveGroup( theId );
1292 //=============================================================================
1296 //=============================================================================
1298 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1299 throw(SALOME::SALOME_Exception)
1301 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1303 SMESH::log_array_var aLog;
1305 list < SMESHDS_Command * >logDS = _impl->GetLog();
1306 aLog = new SMESH::log_array;
1308 int lg = logDS.size();
1311 list < SMESHDS_Command * >::iterator its = logDS.begin();
1312 while(its != logDS.end()){
1313 SMESHDS_Command *com = *its;
1314 int comType = com->GetType();
1316 int lgcom = com->GetNumber();
1318 const list < int >&intList = com->GetIndexes();
1319 int inum = intList.size();
1321 list < int >::const_iterator ii = intList.begin();
1322 const list < double >&coordList = com->GetCoords();
1323 int rnum = coordList.size();
1325 list < double >::const_iterator ir = coordList.begin();
1326 aLog[indexLog].commandType = comType;
1327 aLog[indexLog].number = lgcom;
1328 aLog[indexLog].coords.length(rnum);
1329 aLog[indexLog].indexes.length(inum);
1330 for(int i = 0; i < rnum; i++){
1331 aLog[indexLog].coords[i] = *ir;
1332 //MESSAGE(" "<<i<<" "<<ir.Value());
1335 for(int i = 0; i < inum; i++){
1336 aLog[indexLog].indexes[i] = *ii;
1337 //MESSAGE(" "<<i<<" "<<ii.Value());
1346 catch(SALOME_Exception & S_ex){
1347 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1349 return aLog._retn();
1353 //=============================================================================
1357 //=============================================================================
1359 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1361 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1365 //=============================================================================
1369 //=============================================================================
1371 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1373 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1377 //=============================================================================
1381 //=============================================================================
1383 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1388 //=============================================================================
1392 //=============================================================================
1394 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1396 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1400 //=============================================================================
1404 //=============================================================================
1406 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1408 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1412 //=============================================================================
1414 * Return mesh editor
1416 //=============================================================================
1418 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1420 // Create MeshEditor
1421 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1422 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1424 // Update Python script
1425 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1427 return aMesh._retn();
1430 //=============================================================================
1432 * Return mesh edition previewer
1434 //=============================================================================
1436 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1438 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1439 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1440 return aMesh._retn();
1443 //=============================================================================
1447 //=============================================================================
1448 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1450 Unexpect aCatch(SALOME_SalomeException);
1451 _impl->SetAutoColor(theAutoColor);
1454 //=============================================================================
1458 //=============================================================================
1459 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1461 Unexpect aCatch(SALOME_SalomeException);
1462 return _impl->GetAutoColor();
1466 //=============================================================================
1468 * Export in different formats
1470 //=============================================================================
1472 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1474 return _impl->HasDuplicatedGroupNamesMED();
1477 void SMESH_Mesh_i::PrepareForWriting (const char* file)
1479 TCollection_AsciiString aFullName ((char*)file);
1480 OSD_Path aPath (aFullName);
1481 OSD_File aFile (aPath);
1482 if (aFile.Exists()) {
1483 // existing filesystem node
1484 if (aFile.KindOfFile() == OSD_FILE) {
1485 if (aFile.IsWriteable()) {
1488 if (aFile.Failed()) {
1489 TCollection_AsciiString msg ("File ");
1490 msg += aFullName + " cannot be replaced.";
1491 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1494 TCollection_AsciiString msg ("File ");
1495 msg += aFullName + " cannot be overwritten.";
1496 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1499 TCollection_AsciiString msg ("Location ");
1500 msg += aFullName + " is not a file.";
1501 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1504 // nonexisting file; check if it can be created
1506 aFile.Build(OSD_WriteOnly, OSD_Protection());
1507 if (aFile.Failed()) {
1508 TCollection_AsciiString msg ("You cannot create the file ");
1509 msg += aFullName + ". Check the directory existance and access rights.";
1510 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1518 void SMESH_Mesh_i::ExportToMED (const char* file,
1519 CORBA::Boolean auto_groups,
1520 SMESH::MED_VERSION theVersion)
1521 throw(SALOME::SALOME_Exception)
1523 Unexpect aCatch(SALOME_SalomeException);
1525 // Update Python script
1526 TPythonDump() << _this() << ".ExportToMED( '"
1527 << file << "', " << auto_groups << ", " << theVersion << " )";
1530 PrepareForWriting(file);
1531 char* aMeshName = "Mesh";
1532 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1533 if ( !aStudy->_is_nil() ) {
1534 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1535 if ( !aMeshSO->_is_nil() ) {
1536 aMeshName = aMeshSO->GetName();
1538 //SCRUTE(aMeshName);
1539 //SCRUTE(aMeshSO->GetID());
1541 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1542 if ( !aStudy->GetProperties()->IsLocked() )
1544 SALOMEDS::GenericAttribute_var anAttr;
1545 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1546 SALOMEDS::AttributeExternalFileDef_var aFileName;
1547 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1548 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1549 ASSERT(!aFileName->_is_nil());
1550 aFileName->SetValue(file);
1551 SALOMEDS::AttributeFileType_var aFileType;
1552 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1553 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1554 ASSERT(!aFileType->_is_nil());
1555 aFileType->SetValue("FICHIERMED");
1559 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1562 void SMESH_Mesh_i::ExportMED (const char* file,
1563 CORBA::Boolean auto_groups)
1564 throw(SALOME::SALOME_Exception)
1566 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1569 void SMESH_Mesh_i::ExportDAT (const char *file)
1570 throw(SALOME::SALOME_Exception)
1572 Unexpect aCatch(SALOME_SalomeException);
1574 // Update Python script
1575 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1578 PrepareForWriting(file);
1579 _impl->ExportDAT(file);
1582 void SMESH_Mesh_i::ExportUNV (const char *file)
1583 throw(SALOME::SALOME_Exception)
1585 Unexpect aCatch(SALOME_SalomeException);
1587 // Update Python script
1588 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1591 PrepareForWriting(file);
1592 _impl->ExportUNV(file);
1595 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1596 throw(SALOME::SALOME_Exception)
1598 Unexpect aCatch(SALOME_SalomeException);
1600 // Update Python script
1601 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1604 PrepareForWriting(file);
1605 _impl->ExportSTL(file, isascii);
1608 //=============================================================================
1612 //=============================================================================
1614 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1616 Unexpect aCatch(SALOME_SalomeException);
1617 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1618 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1619 return aMesh._retn();
1622 //=============================================================================
1626 //=============================================================================
1627 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1629 Unexpect aCatch(SALOME_SalomeException);
1630 return _impl->NbNodes();
1633 //=============================================================================
1637 //=============================================================================
1638 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1640 Unexpect aCatch(SALOME_SalomeException);
1641 return NbEdges() + NbFaces() + NbVolumes();
1644 //=============================================================================
1648 //=============================================================================
1649 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1651 Unexpect aCatch(SALOME_SalomeException);
1652 return _impl->NbEdges();
1655 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1656 throw(SALOME::SALOME_Exception)
1658 Unexpect aCatch(SALOME_SalomeException);
1659 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
1662 //=============================================================================
1666 //=============================================================================
1667 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1669 Unexpect aCatch(SALOME_SalomeException);
1670 return _impl->NbFaces();
1673 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1675 Unexpect aCatch(SALOME_SalomeException);
1676 return _impl->NbTriangles();
1679 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1681 Unexpect aCatch(SALOME_SalomeException);
1682 return _impl->NbQuadrangles();
1685 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1687 Unexpect aCatch(SALOME_SalomeException);
1688 return _impl->NbPolygons();
1691 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1692 throw(SALOME::SALOME_Exception)
1694 Unexpect aCatch(SALOME_SalomeException);
1695 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
1698 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1699 throw(SALOME::SALOME_Exception)
1701 Unexpect aCatch(SALOME_SalomeException);
1702 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
1705 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1706 throw(SALOME::SALOME_Exception)
1708 Unexpect aCatch(SALOME_SalomeException);
1709 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
1712 //=============================================================================
1716 //=============================================================================
1717 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1719 Unexpect aCatch(SALOME_SalomeException);
1720 return _impl->NbVolumes();
1723 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1725 Unexpect aCatch(SALOME_SalomeException);
1726 return _impl->NbTetras();
1729 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1731 Unexpect aCatch(SALOME_SalomeException);
1732 return _impl->NbHexas();
1735 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1737 Unexpect aCatch(SALOME_SalomeException);
1738 return _impl->NbPyramids();
1741 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1743 Unexpect aCatch(SALOME_SalomeException);
1744 return _impl->NbPrisms();
1747 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1749 Unexpect aCatch(SALOME_SalomeException);
1750 return _impl->NbPolyhedrons();
1753 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1754 throw(SALOME::SALOME_Exception)
1756 Unexpect aCatch(SALOME_SalomeException);
1757 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
1760 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1761 throw(SALOME::SALOME_Exception)
1763 Unexpect aCatch(SALOME_SalomeException);
1764 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
1767 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1768 throw(SALOME::SALOME_Exception)
1770 Unexpect aCatch(SALOME_SalomeException);
1771 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
1774 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1775 throw(SALOME::SALOME_Exception)
1777 Unexpect aCatch(SALOME_SalomeException);
1778 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
1781 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1782 throw(SALOME::SALOME_Exception)
1784 Unexpect aCatch(SALOME_SalomeException);
1785 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
1788 //=============================================================================
1792 //=============================================================================
1793 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1795 Unexpect aCatch(SALOME_SalomeException);
1796 return _impl->NbSubMesh();
1799 //=============================================================================
1803 //=============================================================================
1804 char* SMESH_Mesh_i::Dump()
1806 std::ostringstream os;
1808 return CORBA::string_dup( os.str().c_str() );
1811 //=============================================================================
1815 //=============================================================================
1816 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1818 // SMESH::long_array_var aResult = new SMESH::long_array();
1819 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1820 // int aMinId = aSMESHDS_Mesh->MinElementID();
1821 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1823 // aResult->length(aMaxId - aMinId + 1);
1825 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1826 // aResult[i++] = id;
1828 // return aResult._retn();
1830 return GetElementsId();
1833 //=============================================================================
1837 //=============================================================================
1839 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1840 throw (SALOME::SALOME_Exception)
1842 Unexpect aCatch(SALOME_SalomeException);
1843 MESSAGE("SMESH_Mesh_i::GetElementsId");
1844 SMESH::long_array_var aResult = new SMESH::long_array();
1845 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1847 if ( aSMESHDS_Mesh == NULL )
1848 return aResult._retn();
1850 long nbElements = NbElements();
1851 aResult->length( nbElements );
1852 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1853 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1854 aResult[i] = anIt->next()->GetID();
1856 return aResult._retn();
1860 //=============================================================================
1864 //=============================================================================
1866 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1867 throw (SALOME::SALOME_Exception)
1869 Unexpect aCatch(SALOME_SalomeException);
1870 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1871 SMESH::long_array_var aResult = new SMESH::long_array();
1872 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1874 if ( aSMESHDS_Mesh == NULL )
1875 return aResult._retn();
1877 long nbElements = NbElements();
1879 // No sense in returning ids of elements along with ids of nodes:
1880 // when theElemType == SMESH::ALL, return node ids only if
1881 // there are no elements
1882 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1883 return GetNodesId();
1885 aResult->length( nbElements );
1889 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1890 while ( i < nbElements && anIt->more() ) {
1891 const SMDS_MeshElement* anElem = anIt->next();
1892 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1893 aResult[i++] = anElem->GetID();
1896 aResult->length( i );
1898 return aResult._retn();
1901 //=============================================================================
1905 //=============================================================================
1907 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1908 throw (SALOME::SALOME_Exception)
1910 Unexpect aCatch(SALOME_SalomeException);
1911 MESSAGE("SMESH_subMesh_i::GetNodesId");
1912 SMESH::long_array_var aResult = new SMESH::long_array();
1913 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1915 if ( aSMESHDS_Mesh == NULL )
1916 return aResult._retn();
1918 long nbNodes = NbNodes();
1919 aResult->length( nbNodes );
1920 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1921 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1922 aResult[i] = anIt->next()->GetID();
1924 return aResult._retn();
1927 //=============================================================================
1931 //=============================================================================
1933 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1934 throw (SALOME::SALOME_Exception)
1936 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1940 //=============================================================================
1942 * Returns ID of elements for given submesh
1944 //=============================================================================
1945 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1946 throw (SALOME::SALOME_Exception)
1948 SMESH::long_array_var aResult = new SMESH::long_array();
1950 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1951 if(!SM) return aResult._retn();
1953 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1954 if(!SDSM) return aResult._retn();
1956 aResult->length(SDSM->NbElements());
1958 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1960 while ( eIt->more() ) {
1961 aResult[i++] = eIt->next()->GetID();
1964 return aResult._retn();
1968 //=============================================================================
1970 * Returns ID of nodes for given submesh
1971 * If param all==true - returns all nodes, else -
1972 * returns only nodes on shapes.
1974 //=============================================================================
1975 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1976 throw (SALOME::SALOME_Exception)
1978 SMESH::long_array_var aResult = new SMESH::long_array();
1980 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1981 if(!SM) return aResult._retn();
1983 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1984 if(!SDSM) return aResult._retn();
1987 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
1988 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1989 while ( nIt->more() ) {
1990 const SMDS_MeshNode* elem = nIt->next();
1991 theElems.insert( elem->GetID() );
1994 else { // all nodes of submesh elements
1995 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1996 while ( eIt->more() ) {
1997 const SMDS_MeshElement* anElem = eIt->next();
1998 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1999 while ( nIt->more() ) {
2000 const SMDS_MeshElement* elem = nIt->next();
2001 theElems.insert( elem->GetID() );
2006 aResult->length(theElems.size());
2007 set<int>::iterator itElem;
2009 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
2010 aResult[i++] = *itElem;
2012 return aResult._retn();
2016 //=============================================================================
2018 * Returns type of elements for given submesh
2020 //=============================================================================
2021 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2022 throw (SALOME::SALOME_Exception)
2024 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2025 if(!SM) return SMESH::ALL;
2027 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2028 if(!SDSM) return SMESH::ALL;
2030 if(SDSM->NbElements()==0)
2031 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2033 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2034 const SMDS_MeshElement* anElem = eIt->next();
2035 return ( SMESH::ElementType ) anElem->GetType();
2039 //=============================================================================
2043 //=============================================================================
2045 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2047 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2048 cerr << "CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() " << pointeur << endl;
2053 //=============================================================================
2055 * Get XYZ coordinates of node as list of double
2056 * If there is not node for given ID - returns empty list
2058 //=============================================================================
2060 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2062 SMESH::double_array_var aResult = new SMESH::double_array();
2063 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2064 if ( aSMESHDS_Mesh == NULL )
2065 return aResult._retn();
2068 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2070 return aResult._retn();
2074 aResult[0] = aNode->X();
2075 aResult[1] = aNode->Y();
2076 aResult[2] = aNode->Z();
2077 return aResult._retn();
2081 //=============================================================================
2083 * For given node returns list of IDs of inverse elements
2084 * If there is not node for given ID - returns empty list
2086 //=============================================================================
2088 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2090 SMESH::long_array_var aResult = new SMESH::long_array();
2091 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2092 if ( aSMESHDS_Mesh == NULL )
2093 return aResult._retn();
2096 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2098 return aResult._retn();
2100 // find inverse elements
2101 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2102 TColStd_SequenceOfInteger IDs;
2103 while(eIt->more()) {
2104 const SMDS_MeshElement* elem = eIt->next();
2105 IDs.Append(elem->GetID());
2107 if(IDs.Length()>0) {
2108 aResult->length(IDs.Length());
2110 for(; i<=IDs.Length(); i++) {
2111 aResult[i-1] = IDs.Value(i);
2114 return aResult._retn();
2117 //=============================================================================
2119 * \brief Return position of a node on shape
2121 //=============================================================================
2123 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2125 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2126 aNodePosition->shapeID = 0;
2127 aNodePosition->shapeType = GEOM::SHAPE;
2129 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2130 if ( !mesh ) return aNodePosition;
2132 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2134 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2136 aNodePosition->shapeID = pos->GetShapeId();
2137 switch ( pos->GetTypeOfPosition() ) {
2139 aNodePosition->shapeType = GEOM::EDGE;
2140 aNodePosition->params.length(1);
2141 aNodePosition->params[0] =
2142 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2145 aNodePosition->shapeType = GEOM::FACE;
2146 aNodePosition->params.length(2);
2147 aNodePosition->params[0] =
2148 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2149 aNodePosition->params[1] =
2150 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2152 case SMDS_TOP_VERTEX:
2153 aNodePosition->shapeType = GEOM::VERTEX;
2155 case SMDS_TOP_3DSPACE:
2156 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2157 aNodePosition->shapeType = GEOM::SOLID;
2158 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2159 aNodePosition->shapeType = GEOM::SHELL;
2165 return aNodePosition;
2168 //=============================================================================
2170 * If given element is node returns IDs of shape from position
2171 * If there is not node for given ID - returns -1
2173 //=============================================================================
2175 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2177 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2178 if ( aSMESHDS_Mesh == NULL )
2182 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2184 SMDS_PositionPtr pos = aNode->GetPosition();
2188 return pos->GetShapeId();
2195 //=============================================================================
2197 * For given element returns ID of result shape after
2198 * ::FindShape() from SMESH_MeshEditor
2199 * If there is not element for given ID - returns -1
2201 //=============================================================================
2203 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2205 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2206 if ( aSMESHDS_Mesh == NULL )
2209 // try to find element
2210 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2214 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2215 ::SMESH_MeshEditor aMeshEditor(_impl);
2216 int index = aMeshEditor.FindShape( elem );
2224 //=============================================================================
2226 * Returns number of nodes for given element
2227 * If there is not element for given ID - returns -1
2229 //=============================================================================
2231 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2233 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2234 if ( aSMESHDS_Mesh == NULL ) return -1;
2235 // try to find element
2236 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2237 if(!elem) return -1;
2238 return elem->NbNodes();
2242 //=============================================================================
2244 * Returns ID of node by given index for given element
2245 * If there is not element for given ID - returns -1
2246 * If there is not node for given index - returns -2
2248 //=============================================================================
2250 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2252 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2253 if ( aSMESHDS_Mesh == NULL ) return -1;
2254 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2255 if(!elem) return -1;
2256 if( index>=elem->NbNodes() || index<0 ) return -1;
2257 return elem->GetNode(index)->GetID();
2260 //=============================================================================
2262 * Returns IDs of nodes of given element
2264 //=============================================================================
2266 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2268 SMESH::long_array_var aResult = new SMESH::long_array();
2269 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2271 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2273 aResult->length( elem->NbNodes() );
2274 for ( int i = 0; i < elem->NbNodes(); ++i )
2275 aResult[ i ] = elem->GetNode( i )->GetID();
2278 return aResult._retn();
2281 //=============================================================================
2283 * Returns true if given node is medium node
2284 * in given quadratic element
2286 //=============================================================================
2288 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2290 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2291 if ( aSMESHDS_Mesh == NULL ) return false;
2293 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2294 if(!aNode) return false;
2295 // try to find element
2296 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2297 if(!elem) return false;
2299 return elem->IsMediumNode(aNode);
2303 //=============================================================================
2305 * Returns true if given node is medium node
2306 * in one of quadratic elements
2308 //=============================================================================
2310 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2311 SMESH::ElementType theElemType)
2313 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2314 if ( aSMESHDS_Mesh == NULL ) return false;
2317 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2318 if(!aNode) return false;
2320 SMESH_MesherHelper aHelper( *(_impl) );
2322 SMDSAbs_ElementType aType;
2323 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2324 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2325 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2326 else aType = SMDSAbs_All;
2328 return aHelper.IsMedium(aNode,aType);
2332 //=============================================================================
2334 * Returns number of edges for given element
2336 //=============================================================================
2338 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2340 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2341 if ( aSMESHDS_Mesh == NULL ) return -1;
2342 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2343 if(!elem) return -1;
2344 return elem->NbEdges();
2348 //=============================================================================
2350 * Returns number of faces for given element
2352 //=============================================================================
2354 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2356 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2357 if ( aSMESHDS_Mesh == NULL ) return -1;
2358 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2359 if(!elem) return -1;
2360 return elem->NbFaces();
2364 //=============================================================================
2366 * Returns true if given element is polygon
2368 //=============================================================================
2370 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2372 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2373 if ( aSMESHDS_Mesh == NULL ) return false;
2374 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2375 if(!elem) return false;
2376 return elem->IsPoly();
2380 //=============================================================================
2382 * Returns true if given element is quadratic
2384 //=============================================================================
2386 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2388 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2389 if ( aSMESHDS_Mesh == NULL ) return false;
2390 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2391 if(!elem) return false;
2392 return elem->IsQuadratic();
2396 //=============================================================================
2398 * Returns bary center for given element
2400 //=============================================================================
2402 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2404 SMESH::double_array_var aResult = new SMESH::double_array();
2405 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2406 if ( aSMESHDS_Mesh == NULL )
2407 return aResult._retn();
2409 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2411 return aResult._retn();
2413 if(elem->GetType()==SMDSAbs_Volume) {
2414 SMDS_VolumeTool aTool;
2415 if(aTool.Set(elem)) {
2417 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2422 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2424 double x=0., y=0., z=0.;
2425 for(; anIt->more(); ) {
2427 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2441 return aResult._retn();
2445 //=============================================================================
2447 * Create and publish group servants if any groups were imported or created anyhow
2449 //=============================================================================
2451 void SMESH_Mesh_i::CreateGroupServants()
2453 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2455 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2456 while ( groupIt->more() )
2458 ::SMESH_Group* group = groupIt->next();
2459 int anId = group->GetGroupDS()->GetID();
2461 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
2462 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2465 SMESH_GroupBase_i* aGroupImpl;
2467 if ( SMESHDS_GroupOnGeom* groupOnGeom =
2468 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
2470 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2471 shape = groupOnGeom->GetShape();
2474 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2477 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
2478 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2479 aGroupImpl->Register();
2481 SMESH::SMESH_GroupBase_var groupVar =
2482 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2483 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
2485 // register CORBA object for persistence
2486 int nextId = _gen_i->RegisterObject( groupVar );
2487 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2489 // publishing of the groups in the study
2490 if ( !aStudy->_is_nil() ) {
2491 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
2492 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
2497 //=============================================================================
2499 * \brief Return groups cantained in _mapGroups by their IDs
2501 //=============================================================================
2503 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
2505 int nbGroups = groupIDs.size();
2506 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
2507 aList->length( nbGroups );
2509 list<int>::const_iterator ids = groupIDs.begin();
2510 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
2512 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
2513 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2514 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
2516 aList->length( nbGroups );
2517 return aList._retn();
2520 //=============================================================================
2522 * \brief Return information about imported file
2524 //=============================================================================
2526 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
2528 SALOME_MED::MedFileInfo_var res( myFileInfo );
2529 if ( !res.operator->() ) {
2530 res = new SALOME_MED::MedFileInfo;
2532 res->fileSize = res->major = res->minor = res->release = -1;