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>
77 static int MYDEBUG = 0;
79 static int MYDEBUG = 0;
83 using SMESH::TPythonDump;
85 int SMESH_Mesh_i::myIdGenerator = 0;
89 //=============================================================================
93 //=============================================================================
95 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
98 : SALOME::GenericObj_i( thePOA )
100 MESSAGE("SMESH_Mesh_i");
103 _id = myIdGenerator++;
107 //=============================================================================
111 //=============================================================================
113 SMESH_Mesh_i::~SMESH_Mesh_i()
115 INFOS("~SMESH_Mesh_i");
116 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
117 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
118 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
121 // this method is colled from destructor of group (PAL6331)
122 //_impl->RemoveGroup( aGroup->GetLocalID() );
130 //=============================================================================
134 * Associates <this> mesh with <theShape> and puts a reference
135 * to <theShape> into the current study;
136 * the previous shape is substituted by the new one.
138 //=============================================================================
140 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
141 throw (SALOME::SALOME_Exception)
143 Unexpect aCatch(SALOME_SalomeException);
145 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
147 catch(SALOME_Exception & S_ex) {
148 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
152 //================================================================================
154 * \brief return true if mesh has a shape to build a shape on
156 //================================================================================
158 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
159 throw (SALOME::SALOME_Exception)
161 Unexpect aCatch(SALOME_SalomeException);
164 res = _impl->HasShapeToMesh();
166 catch(SALOME_Exception & S_ex) {
167 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
172 //=======================================================================
173 //function : GetShapeToMesh
175 //=======================================================================
177 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
178 throw (SALOME::SALOME_Exception)
180 Unexpect aCatch(SALOME_SalomeException);
181 GEOM::GEOM_Object_var aShapeObj;
183 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
185 aShapeObj = _gen_i->ShapeToGeomObject( S );
187 catch(SALOME_Exception & S_ex) {
188 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
190 return aShapeObj._retn();
193 //================================================================================
195 * \brief Remove all nodes and elements
197 //================================================================================
199 void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
201 Unexpect aCatch(SALOME_SalomeException);
205 catch(SALOME_Exception & S_ex) {
206 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
208 TPythonDump() << _this() << ".Clear()";
211 //=============================================================================
215 //=============================================================================
217 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
219 SMESH::DriverMED_ReadStatus res;
222 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
223 res = SMESH::DRS_OK; break;
224 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
225 res = SMESH::DRS_EMPTY; break;
226 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
227 res = SMESH::DRS_WARN_RENUMBER; break;
228 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
229 res = SMESH::DRS_WARN_SKIP_ELEM; break;
230 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
232 res = SMESH::DRS_FAIL; break;
237 //=============================================================================
241 * Imports mesh data from MED file
243 //=============================================================================
245 SMESH::DriverMED_ReadStatus
246 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
247 throw ( SALOME::SALOME_Exception )
249 Unexpect aCatch(SALOME_SalomeException);
252 status = _impl->MEDToMesh( theFileName, theMeshName );
254 catch( SALOME_Exception& S_ex ) {
255 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
258 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
261 CreateGroupServants();
263 int major, minor, release;
264 if( !MED::getMEDVersion( theFileName, major, minor, release ) )
265 major = minor = release = -1;
266 myFileInfo = new SALOME_MED::MedFileInfo();
267 myFileInfo->fileName = theFileName;
268 myFileInfo->fileSize = 0;
269 myFileInfo->major = major;
270 myFileInfo->minor = minor;
271 myFileInfo->release = release;
273 return ConvertDriverMEDReadStatus(status);
276 //================================================================================
278 * \brief Return string representation of a MED file version comprising nbDigits
280 //================================================================================
282 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
284 std::string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
286 return CORBA::string_dup( ver.c_str() );
289 //=============================================================================
293 * Imports mesh data from MED file
295 //=============================================================================
297 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
298 throw ( SALOME::SALOME_Exception )
300 // Read mesh with name = <theMeshName> into SMESH_Mesh
301 _impl->UNVToMesh( theFileName );
303 CreateGroupServants();
308 //=============================================================================
312 * Imports mesh data from STL file
314 //=============================================================================
315 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
316 throw ( SALOME::SALOME_Exception )
318 // Read mesh with name = <theMeshName> into SMESH_Mesh
319 _impl->STLToMesh( theFileName );
324 //=============================================================================
328 * Imports mesh data from MED file
330 //=============================================================================
332 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
334 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
335 // int status = _impl->MEDToMesh( theFileName, theMeshName );
336 // CreateGroupServants();
341 //=============================================================================
345 //=============================================================================
347 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
349 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
350 (SMESH_Hypothesis::Hypothesis_Status theStatus)
353 RETURNCASE( HYP_OK );
354 RETURNCASE( HYP_MISSING );
355 RETURNCASE( HYP_CONCURENT );
356 RETURNCASE( HYP_BAD_PARAMETER );
357 RETURNCASE( HYP_HIDDEN_ALGO );
358 RETURNCASE( HYP_HIDING_ALGO );
359 RETURNCASE( HYP_UNKNOWN_FATAL );
360 RETURNCASE( HYP_INCOMPATIBLE );
361 RETURNCASE( HYP_NOTCONFORM );
362 RETURNCASE( HYP_ALREADY_EXIST );
363 RETURNCASE( HYP_BAD_DIM );
364 RETURNCASE( HYP_BAD_SUBSHAPE );
365 RETURNCASE( HYP_BAD_GEOMETRY );
368 return SMESH::HYP_UNKNOWN_FATAL;
371 //=============================================================================
375 * calls internal addHypothesis() and then adds a reference to <anHyp> under
376 * the SObject actually having a reference to <aSubShape>.
377 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
379 //=============================================================================
381 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
382 SMESH::SMESH_Hypothesis_ptr anHyp)
383 throw(SALOME::SALOME_Exception)
385 Unexpect aCatch(SALOME_SalomeException);
386 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
388 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
389 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
390 aSubShapeObject, anHyp );
392 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
394 // Update Python script
395 if(_impl->HasShapeToMesh()) {
396 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
397 << aSubShapeObject << ", " << anHyp << " )";
400 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
403 return ConvertHypothesisStatus(status);
406 //=============================================================================
410 //=============================================================================
412 SMESH_Hypothesis::Hypothesis_Status
413 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
414 SMESH::SMESH_Hypothesis_ptr anHyp)
416 if(MYDEBUG) MESSAGE("addHypothesis");
418 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
419 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
422 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
423 if (CORBA::is_nil(myHyp))
424 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
427 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
430 TopoDS_Shape myLocSubShape;
431 //use PseudoShape in case if mesh has no shape
433 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
435 myLocSubShape = _impl->GetShapeToMesh();
437 int hypId = myHyp->GetId();
438 status = _impl->AddHypothesis(myLocSubShape, hypId);
439 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
440 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
441 // assure there is a corresponding submesh
442 if ( !_impl->IsMainShape( myLocSubShape )) {
443 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
444 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
445 createSubMesh( aSubShapeObject );
449 catch(SALOME_Exception & S_ex)
451 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
456 //=============================================================================
460 //=============================================================================
462 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
463 SMESH::SMESH_Hypothesis_ptr anHyp)
464 throw(SALOME::SALOME_Exception)
466 Unexpect aCatch(SALOME_SalomeException);
467 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
469 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
470 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
471 aSubShapeObject, anHyp );
473 // Update Python script
474 // Update Python script
475 if(_impl->HasShapeToMesh()) {
476 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
477 << aSubShapeObject << ", " << anHyp << " )";
480 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
484 return ConvertHypothesisStatus(status);
487 //=============================================================================
491 //=============================================================================
493 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
494 SMESH::SMESH_Hypothesis_ptr anHyp)
496 if(MYDEBUG) MESSAGE("removeHypothesis()");
497 // **** proposer liste de subShape (selection multiple)
499 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
500 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
503 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
504 if (CORBA::is_nil(myHyp))
505 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
508 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
511 TopoDS_Shape myLocSubShape;
512 //use PseudoShape in case if mesh has no shape
514 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
516 myLocSubShape = _impl->GetShapeToMesh();
518 int hypId = myHyp->GetId();
519 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
520 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
521 _mapHypo.erase( hypId );
523 catch(SALOME_Exception & S_ex)
525 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
530 //=============================================================================
534 //=============================================================================
536 SMESH::ListOfHypothesis *
537 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
538 throw(SALOME::SALOME_Exception)
540 Unexpect aCatch(SALOME_SalomeException);
541 if (MYDEBUG) MESSAGE("GetHypothesisList");
542 if (CORBA::is_nil(aSubShapeObject))
543 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
546 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
549 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
550 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
551 int i = 0, n = aLocalList.size();
554 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
555 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
556 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
557 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
562 catch(SALOME_Exception & S_ex) {
563 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
566 return aList._retn();
569 //=============================================================================
573 //=============================================================================
574 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
575 const char* theName )
576 throw(SALOME::SALOME_Exception)
578 Unexpect aCatch(SALOME_SalomeException);
579 MESSAGE("SMESH_Mesh_i::GetSubMesh");
580 if (CORBA::is_nil(aSubShapeObject))
581 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
584 SMESH::SMESH_subMesh_var subMesh;
585 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
587 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
589 //Get or Create the SMESH_subMesh object implementation
591 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
592 subMesh = getSubMesh( subMeshId );
594 // create a new subMesh object servant if there is none for the shape
595 if ( subMesh->_is_nil() )
596 subMesh = createSubMesh( aSubShapeObject );
598 if ( _gen_i->CanPublishInStudy( subMesh )) {
599 SALOMEDS::SObject_var aSO =
600 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
601 subMesh, aSubShapeObject, theName );
602 if ( !aSO->_is_nil()) {
603 // Update Python script
604 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
605 << aSubShapeObject << ", '" << theName << "' )";
609 catch(SALOME_Exception & S_ex) {
610 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
612 return subMesh._retn();
615 //=============================================================================
619 //=============================================================================
621 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
622 throw (SALOME::SALOME_Exception)
624 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
625 if ( theSubMesh->_is_nil() )
628 GEOM::GEOM_Object_var aSubShapeObject;
629 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
630 if ( !aStudy->_is_nil() ) {
631 // Remove submesh's SObject
632 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
633 if ( !anSO->_is_nil() ) {
634 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
635 SALOMEDS::SObject_var anObj, aRef;
636 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
637 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
639 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
641 // Update Python script
642 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
646 removeSubMesh( theSubMesh, aSubShapeObject.in() );
649 //=============================================================================
653 //=============================================================================
654 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
655 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
657 switch (theElemType) {
662 CASE2STRING( VOLUME );
668 //=============================================================================
672 //=============================================================================
674 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
675 const char* theName )
676 throw(SALOME::SALOME_Exception)
678 Unexpect aCatch(SALOME_SalomeException);
679 SMESH::SMESH_Group_var aNewGroup =
680 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
682 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
683 SALOMEDS::SObject_var aSO =
684 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
685 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
686 if ( !aSO->_is_nil()) {
687 // Update Python script
688 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
689 << ElementTypeString(theElemType) << ", '" << theName << "' )";
692 return aNewGroup._retn();
696 //=============================================================================
700 //=============================================================================
701 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
703 GEOM::GEOM_Object_ptr theGeomObj)
704 throw(SALOME::SALOME_Exception)
706 Unexpect aCatch(SALOME_SalomeException);
707 SMESH::SMESH_GroupOnGeom_var aNewGroup;
709 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
710 if ( !aShape.IsNull() ) {
711 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
712 ( createGroup( theElemType, theName, aShape ));
713 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
714 SALOMEDS::SObject_var aSO =
715 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
716 aNewGroup, theGeomObj, theName);
717 if ( !aSO->_is_nil()) {
718 // Update Python script
719 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
720 << ElementTypeString(theElemType) << ", '" << theName << "', "
721 << theGeomObj << " )";
726 return aNewGroup._retn();
729 //=============================================================================
733 //=============================================================================
735 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
736 throw (SALOME::SALOME_Exception)
738 if ( theGroup->_is_nil() )
741 SMESH_GroupBase_i* aGroup =
742 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
746 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
747 if ( !aStudy->_is_nil() ) {
748 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
750 if ( !aGroupSO->_is_nil() ) {
751 // Update Python script
752 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
754 // Remove group's SObject
755 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
759 // Remove the group from SMESH data structures
760 removeGroup( aGroup->GetLocalID() );
763 //=============================================================================
764 /*! RemoveGroupWithContents
765 * Remove group with its contents
767 //=============================================================================
768 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
769 throw (SALOME::SALOME_Exception)
771 if ( theGroup->_is_nil() )
774 SMESH_GroupBase_i* aGroup =
775 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
779 SMESH::long_array_var anIds = aGroup->GetListOfID();
780 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
782 // Update Python script
783 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
786 if ( aGroup->GetType() == SMESH::NODE )
787 aMeshEditor->RemoveNodes( anIds );
789 aMeshEditor->RemoveElements( anIds );
792 RemoveGroup( theGroup );
794 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
795 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
796 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
800 //================================================================================
802 * \brief Get the list of groups existing in the mesh
803 * \retval SMESH::ListOfGroups * - list of groups
805 //================================================================================
807 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
809 Unexpect aCatch(SALOME_SalomeException);
810 if (MYDEBUG) MESSAGE("GetGroups");
812 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
815 TPythonDump aPythonDump;
816 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
820 aList->length( _mapGroups.size() );
822 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
823 for ( ; it != _mapGroups.end(); it++ ) {
824 if ( CORBA::is_nil( it->second )) continue;
825 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
827 if (i > 1) aPythonDump << ", ";
828 aPythonDump << it->second;
832 catch(SALOME_Exception & S_ex) {
833 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
836 // Update Python script
837 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
838 aPythonDump << " ] = " << _this() << ".GetGroups()";
840 return aList._retn();
842 //=============================================================================
844 * Get number of groups existing in the mesh
846 //=============================================================================
848 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
850 Unexpect aCatch(SALOME_SalomeException);
851 return _mapGroups.size();
854 //=============================================================================
856 * New group is created. All mesh elements that are
857 * present in initial groups are added to the new one
859 //=============================================================================
860 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
861 SMESH::SMESH_GroupBase_ptr theGroup2,
862 const char* theName )
863 throw (SALOME::SALOME_Exception)
867 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
868 theGroup1->GetType() != theGroup2->GetType() )
869 return SMESH::SMESH_Group::_nil();
872 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
873 if ( aResGrp->_is_nil() )
874 return SMESH::SMESH_Group::_nil();
876 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
877 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
879 TColStd_MapOfInteger aResMap;
881 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
882 aResMap.Add( anIds1[ i1 ] );
884 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
885 aResMap.Add( anIds2[ i2 ] );
887 SMESH::long_array_var aResIds = new SMESH::long_array;
888 aResIds->length( aResMap.Extent() );
891 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
892 for( ; anIter.More(); anIter.Next() )
893 aResIds[ resI++ ] = anIter.Key();
895 aResGrp->Add( aResIds );
897 // Clear python lines, created by CreateGroup() and Add()
898 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
899 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
900 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
902 // Update Python script
903 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
904 << theGroup1 << ", " << theGroup2 << ", '"
907 return aResGrp._retn();
911 return SMESH::SMESH_Group::_nil();
915 //=============================================================================
917 * New group is created. All mesh elements that are
918 * present in both initial groups are added to the new one.
920 //=============================================================================
921 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
922 SMESH::SMESH_GroupBase_ptr theGroup2,
923 const char* theName )
924 throw (SALOME::SALOME_Exception)
926 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
927 theGroup1->GetType() != theGroup2->GetType() )
928 return SMESH::SMESH_Group::_nil();
930 // Create Intersection
931 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
932 if ( aResGrp->_is_nil() )
935 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
936 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
938 TColStd_MapOfInteger aMap1;
940 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
941 aMap1.Add( anIds1[ i1 ] );
943 TColStd_SequenceOfInteger aSeq;
945 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
946 if ( aMap1.Contains( anIds2[ i2 ] ) )
947 aSeq.Append( anIds2[ i2 ] );
949 SMESH::long_array_var aResIds = new SMESH::long_array;
950 aResIds->length( aSeq.Length() );
952 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
953 aResIds[ resI ] = aSeq( resI + 1 );
955 aResGrp->Add( aResIds );
957 // Clear python lines, created by CreateGroup() and Add()
958 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
959 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
960 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
962 // Update Python script
963 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
964 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
966 return aResGrp._retn();
969 //=============================================================================
971 * New group is created. All mesh elements that are present in
972 * main group but do not present in tool group are added to the new one
974 //=============================================================================
975 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
976 SMESH::SMESH_GroupBase_ptr theGroup2,
977 const char* theName )
978 throw (SALOME::SALOME_Exception)
980 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
981 theGroup1->GetType() != theGroup2->GetType() )
982 return SMESH::SMESH_Group::_nil();
985 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
986 if ( aResGrp->_is_nil() )
989 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
990 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
992 TColStd_MapOfInteger aMap2;
994 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
995 aMap2.Add( anIds2[ i2 ] );
998 TColStd_SequenceOfInteger aSeq;
999 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1000 if ( !aMap2.Contains( anIds1[ i1 ] ) )
1001 aSeq.Append( anIds1[ i1 ] );
1003 SMESH::long_array_var aResIds = new SMESH::long_array;
1004 aResIds->length( aSeq.Length() );
1006 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1007 aResIds[ resI ] = aSeq( resI + 1 );
1009 aResGrp->Add( aResIds );
1011 // Clear python lines, created by CreateGroup() and Add()
1012 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1013 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1014 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1016 // Update Python script
1017 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1018 << theGroup1 << ", " << theGroup2 << ", '"
1019 << theName << "' )";
1021 return aResGrp._retn();
1024 //================================================================================
1026 * \brief Return group items of a group present in a study
1028 //================================================================================
1030 static GEOM::GEOM_Object_ptr getGroupItemsFromStudy(CORBA::Object_ptr theMesh,
1031 SMESH_Gen_i* theGen,
1032 list<TopoDS_Shape> & theItems)
1034 GEOM::GEOM_Object_var groupObj;
1035 SALOMEDS::Study_var study = theGen->GetCurrentStudy();
1036 GEOM::GEOM_Gen_var geomGen = theGen->GetGeomEngine();
1037 if ( study->_is_nil() || geomGen->_is_nil() )
1038 return groupObj._retn();
1040 GEOM::GEOM_IGroupOperations_var groupOp =
1041 geomGen->GetIGroupOperations( theGen->GetCurrentStudyID() );
1042 GEOM::GEOM_IShapesOperations_var shapeOp =
1043 geomGen->GetIShapesOperations( theGen->GetCurrentStudyID() );
1045 SALOMEDS::SObject_var meshOS = theGen->ObjectToSObject(study, theMesh);
1046 if ( meshOS->_is_nil() || groupOp->_is_nil() || shapeOp->_is_nil() )
1047 return groupObj._retn();
1048 SALOMEDS::SObject_var fatherSO = meshOS->GetFather();
1049 if ( fatherSO->_is_nil() || fatherSO->Tag() != theGen->GetSubMeshOnCompoundTag() )
1050 return groupObj._retn(); // keep only submeshes on groups
1052 SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(meshOS);
1053 if ( anIter->_is_nil() ) return groupObj._retn();
1054 for ( ; anIter->More(); anIter->Next())
1056 SALOMEDS::SObject_var aSObject = anIter->Value();
1057 SALOMEDS::SObject_var aRefSO;
1058 if ( !aSObject->_is_nil() && aSObject->ReferencedObject(aRefSO) )
1060 groupObj = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
1061 if ( groupObj->_is_nil() ) break;
1062 GEOM::ListOfLong_var ids = groupOp->GetObjects( groupObj );
1063 GEOM::GEOM_Object_var mainShape = groupObj->GetMainShape();
1064 for ( int i = 0; i < ids->length(); ++i ) {
1065 GEOM::GEOM_Object_var subShape = shapeOp->GetSubShape( mainShape, ids[i] );
1066 TopoDS_Shape S = theGen->GeomObjectToShape( subShape );
1068 theItems.push_back( S );
1073 return groupObj._retn();
1076 //=============================================================================
1078 * \brief Update hypotheses assigned to geom groups if the latter change
1080 * NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1082 //=============================================================================
1084 void SMESH_Mesh_i::CheckGeomGroupModif()
1086 if ( !_impl->HasShapeToMesh() ) return;
1088 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1089 if ( study->_is_nil() ) return;
1091 // check if items of groups changed
1092 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
1093 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
1095 const TopoDS_Shape & oldGroupShape = i_sm->second->GetSubShape();
1096 SMESHDS_SubMesh * oldDS = i_sm->second->GetSubMeshDS();
1097 if ( !oldDS /*|| !oldDS->IsComplexSubmesh()*/ )
1099 int oldID = i_sm->first;
1100 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldID );
1101 if ( i_smIor == _mapSubMeshIor.end() )
1103 list< TopoDS_Shape> newItems;
1104 GEOM::GEOM_Object_var groupObj = getGroupItemsFromStudy ( i_smIor->second, _gen_i, newItems );
1105 if ( groupObj->_is_nil() )
1108 int nbOldItems = oldDS->IsComplexSubmesh() ? oldDS->NbSubMeshes() : 1;
1109 int nbNewItems = newItems.size();
1110 bool groupChanged = ( nbOldItems != nbNewItems);
1111 if ( !groupChanged ) {
1112 if ( !oldDS->IsComplexSubmesh() ) { // old group has one item
1113 groupChanged = ( oldGroupShape != newItems.front() );
1116 list<TopoDS_Shape>::iterator item = newItems.begin();
1117 for ( ; item != newItems.end() && !groupChanged; ++item )
1119 SMESHDS_SubMesh * itemDS = _impl->GetMeshDS()->MeshElements( *item );
1120 groupChanged = ( !itemDS || !oldDS->ContainsSubMesh( itemDS ));
1124 // update hypotheses and submeshes if necessary
1127 // get a new group shape
1128 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1129 if ( !geomClient ) continue;
1130 TCollection_AsciiString groupIOR = _gen_i->GetGeomEngine()->GetStringFromIOR( groupObj );
1131 geomClient->RemoveShapeFromBuffer( groupIOR );
1132 TopoDS_Shape newGroupShape = _gen_i->GeomObjectToShape( groupObj );
1133 // update hypotheses
1134 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldGroupShape);
1135 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1136 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1138 _impl->RemoveHypothesis( oldGroupShape, (*hypIt)->GetID());
1139 _impl->AddHypothesis ( newGroupShape, (*hypIt)->GetID());
1141 // care of submeshes
1142 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newGroupShape );
1143 int newID = newSubmesh->GetId();
1144 if ( newID != oldID ) {
1145 _mapSubMesh [ newID ] = newSubmesh;
1146 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1147 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1148 _mapSubMesh.erase (oldID);
1149 _mapSubMesh_i.erase (oldID);
1150 _mapSubMeshIor.erase(oldID);
1151 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1157 //=============================================================================
1161 //=============================================================================
1163 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1165 if(MYDEBUG) MESSAGE( "createSubMesh" );
1166 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1168 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1169 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1170 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1171 SMESH::SMESH_subMesh_var subMesh
1172 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1174 _mapSubMesh[subMeshId] = mySubMesh;
1175 _mapSubMesh_i[subMeshId] = subMeshServant;
1176 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1178 // register CORBA object for persistence
1179 int nextId = _gen_i->RegisterObject( subMesh );
1180 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1182 return subMesh._retn();
1185 //=======================================================================
1186 //function : getSubMesh
1188 //=======================================================================
1190 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1192 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1193 if ( it == _mapSubMeshIor.end() )
1194 return SMESH::SMESH_subMesh::_nil();
1196 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1200 //=============================================================================
1204 //=============================================================================
1206 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1207 GEOM::GEOM_Object_ptr theSubShapeObject )
1209 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1210 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1214 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1215 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1216 removeHypothesis( theSubShapeObject, aHypList[i] );
1219 catch( const SALOME::SALOME_Exception& ) {
1220 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1223 int subMeshId = theSubMesh->GetId();
1225 _mapSubMesh.erase(subMeshId);
1226 _mapSubMesh_i.erase(subMeshId);
1227 _mapSubMeshIor.erase(subMeshId);
1228 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1231 //=============================================================================
1235 //=============================================================================
1237 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1238 const char* theName,
1239 const TopoDS_Shape& theShape )
1242 SMESH::SMESH_GroupBase_var aGroup;
1243 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1244 SMESH_GroupBase_i* aGroupImpl;
1245 if ( !theShape.IsNull() )
1246 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1248 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1250 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1251 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1252 aGroupImpl->Register();
1253 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1255 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1256 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1258 // register CORBA object for persistence
1259 int nextId = _gen_i->RegisterObject( aGroup );
1260 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1262 return aGroup._retn();
1265 //=============================================================================
1267 * SMESH_Mesh_i::removeGroup
1269 * Should be called by ~SMESH_Group_i()
1271 //=============================================================================
1273 void SMESH_Mesh_i::removeGroup( const int theId )
1275 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1276 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1277 _mapGroups.erase( theId );
1278 _impl->RemoveGroup( theId );
1283 //=============================================================================
1287 //=============================================================================
1289 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1290 throw(SALOME::SALOME_Exception)
1292 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1294 SMESH::log_array_var aLog;
1296 list < SMESHDS_Command * >logDS = _impl->GetLog();
1297 aLog = new SMESH::log_array;
1299 int lg = logDS.size();
1302 list < SMESHDS_Command * >::iterator its = logDS.begin();
1303 while(its != logDS.end()){
1304 SMESHDS_Command *com = *its;
1305 int comType = com->GetType();
1307 int lgcom = com->GetNumber();
1309 const list < int >&intList = com->GetIndexes();
1310 int inum = intList.size();
1312 list < int >::const_iterator ii = intList.begin();
1313 const list < double >&coordList = com->GetCoords();
1314 int rnum = coordList.size();
1316 list < double >::const_iterator ir = coordList.begin();
1317 aLog[indexLog].commandType = comType;
1318 aLog[indexLog].number = lgcom;
1319 aLog[indexLog].coords.length(rnum);
1320 aLog[indexLog].indexes.length(inum);
1321 for(int i = 0; i < rnum; i++){
1322 aLog[indexLog].coords[i] = *ir;
1323 //MESSAGE(" "<<i<<" "<<ir.Value());
1326 for(int i = 0; i < inum; i++){
1327 aLog[indexLog].indexes[i] = *ii;
1328 //MESSAGE(" "<<i<<" "<<ii.Value());
1337 catch(SALOME_Exception & S_ex){
1338 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1340 return aLog._retn();
1344 //=============================================================================
1348 //=============================================================================
1350 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1352 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1356 //=============================================================================
1360 //=============================================================================
1362 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1364 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1368 //=============================================================================
1372 //=============================================================================
1374 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1379 //=============================================================================
1383 //=============================================================================
1385 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1387 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1391 //=============================================================================
1395 //=============================================================================
1397 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1399 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1403 //=============================================================================
1405 * Return mesh editor
1407 //=============================================================================
1409 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1411 // Create MeshEditor
1412 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1413 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1415 // Update Python script
1416 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1418 return aMesh._retn();
1421 //=============================================================================
1423 * Return mesh edition previewer
1425 //=============================================================================
1427 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1429 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1430 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1431 return aMesh._retn();
1434 //=============================================================================
1438 //=============================================================================
1439 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1441 Unexpect aCatch(SALOME_SalomeException);
1442 _impl->SetAutoColor(theAutoColor);
1445 //=============================================================================
1449 //=============================================================================
1450 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1452 Unexpect aCatch(SALOME_SalomeException);
1453 return _impl->GetAutoColor();
1457 //=============================================================================
1459 * Export in different formats
1461 //=============================================================================
1463 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1465 return _impl->HasDuplicatedGroupNamesMED();
1468 void SMESH_Mesh_i::PrepareForWriting (const char* file)
1470 TCollection_AsciiString aFullName ((char*)file);
1471 OSD_Path aPath (aFullName);
1472 OSD_File aFile (aPath);
1473 if (aFile.Exists()) {
1474 // existing filesystem node
1475 if (aFile.KindOfFile() == OSD_FILE) {
1476 if (aFile.IsWriteable()) {
1479 if (aFile.Failed()) {
1480 TCollection_AsciiString msg ("File ");
1481 msg += aFullName + " cannot be replaced.";
1482 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1485 TCollection_AsciiString msg ("File ");
1486 msg += aFullName + " cannot be overwritten.";
1487 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1490 TCollection_AsciiString msg ("Location ");
1491 msg += aFullName + " is not a file.";
1492 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1495 // nonexisting file; check if it can be created
1497 aFile.Build(OSD_WriteOnly, OSD_Protection());
1498 if (aFile.Failed()) {
1499 TCollection_AsciiString msg ("You cannot create the file ");
1500 msg += aFullName + ". Check the directory existance and access rights.";
1501 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1509 void SMESH_Mesh_i::ExportToMED (const char* file,
1510 CORBA::Boolean auto_groups,
1511 SMESH::MED_VERSION theVersion)
1512 throw(SALOME::SALOME_Exception)
1514 Unexpect aCatch(SALOME_SalomeException);
1516 // Update Python script
1517 TPythonDump() << _this() << ".ExportToMED( '"
1518 << file << "', " << auto_groups << ", " << theVersion << " )";
1521 PrepareForWriting(file);
1522 char* aMeshName = "Mesh";
1523 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1524 if ( !aStudy->_is_nil() ) {
1525 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1526 if ( !aMeshSO->_is_nil() ) {
1527 aMeshName = aMeshSO->GetName();
1529 //SCRUTE(aMeshName);
1530 //SCRUTE(aMeshSO->GetID());
1532 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1533 if ( !aStudy->GetProperties()->IsLocked() )
1535 SALOMEDS::GenericAttribute_var anAttr;
1536 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1537 SALOMEDS::AttributeExternalFileDef_var aFileName;
1538 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1539 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1540 ASSERT(!aFileName->_is_nil());
1541 aFileName->SetValue(file);
1542 SALOMEDS::AttributeFileType_var aFileType;
1543 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1544 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1545 ASSERT(!aFileType->_is_nil());
1546 aFileType->SetValue("FICHIERMED");
1550 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1553 void SMESH_Mesh_i::ExportMED (const char* file,
1554 CORBA::Boolean auto_groups)
1555 throw(SALOME::SALOME_Exception)
1557 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1560 void SMESH_Mesh_i::ExportDAT (const char *file)
1561 throw(SALOME::SALOME_Exception)
1563 Unexpect aCatch(SALOME_SalomeException);
1565 // Update Python script
1566 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1569 PrepareForWriting(file);
1570 _impl->ExportDAT(file);
1573 void SMESH_Mesh_i::ExportUNV (const char *file)
1574 throw(SALOME::SALOME_Exception)
1576 Unexpect aCatch(SALOME_SalomeException);
1578 // Update Python script
1579 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1582 PrepareForWriting(file);
1583 _impl->ExportUNV(file);
1586 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1587 throw(SALOME::SALOME_Exception)
1589 Unexpect aCatch(SALOME_SalomeException);
1591 // Update Python script
1592 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1595 PrepareForWriting(file);
1596 _impl->ExportSTL(file, isascii);
1599 //=============================================================================
1603 //=============================================================================
1605 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1607 Unexpect aCatch(SALOME_SalomeException);
1608 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1609 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1610 return aMesh._retn();
1613 //=============================================================================
1617 //=============================================================================
1618 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1620 Unexpect aCatch(SALOME_SalomeException);
1621 return _impl->NbNodes();
1624 //=============================================================================
1628 //=============================================================================
1629 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1631 Unexpect aCatch(SALOME_SalomeException);
1632 return NbEdges() + NbFaces() + NbVolumes();
1635 //=============================================================================
1639 //=============================================================================
1640 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1642 Unexpect aCatch(SALOME_SalomeException);
1643 return _impl->NbEdges();
1646 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1647 throw(SALOME::SALOME_Exception)
1649 Unexpect aCatch(SALOME_SalomeException);
1650 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
1653 //=============================================================================
1657 //=============================================================================
1658 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1660 Unexpect aCatch(SALOME_SalomeException);
1661 return _impl->NbFaces();
1664 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1666 Unexpect aCatch(SALOME_SalomeException);
1667 return _impl->NbTriangles();
1670 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1672 Unexpect aCatch(SALOME_SalomeException);
1673 return _impl->NbQuadrangles();
1676 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1678 Unexpect aCatch(SALOME_SalomeException);
1679 return _impl->NbPolygons();
1682 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1683 throw(SALOME::SALOME_Exception)
1685 Unexpect aCatch(SALOME_SalomeException);
1686 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
1689 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1690 throw(SALOME::SALOME_Exception)
1692 Unexpect aCatch(SALOME_SalomeException);
1693 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
1696 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1697 throw(SALOME::SALOME_Exception)
1699 Unexpect aCatch(SALOME_SalomeException);
1700 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
1703 //=============================================================================
1707 //=============================================================================
1708 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1710 Unexpect aCatch(SALOME_SalomeException);
1711 return _impl->NbVolumes();
1714 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1716 Unexpect aCatch(SALOME_SalomeException);
1717 return _impl->NbTetras();
1720 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1722 Unexpect aCatch(SALOME_SalomeException);
1723 return _impl->NbHexas();
1726 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1728 Unexpect aCatch(SALOME_SalomeException);
1729 return _impl->NbPyramids();
1732 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1734 Unexpect aCatch(SALOME_SalomeException);
1735 return _impl->NbPrisms();
1738 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1740 Unexpect aCatch(SALOME_SalomeException);
1741 return _impl->NbPolyhedrons();
1744 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1745 throw(SALOME::SALOME_Exception)
1747 Unexpect aCatch(SALOME_SalomeException);
1748 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
1751 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1752 throw(SALOME::SALOME_Exception)
1754 Unexpect aCatch(SALOME_SalomeException);
1755 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
1758 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1759 throw(SALOME::SALOME_Exception)
1761 Unexpect aCatch(SALOME_SalomeException);
1762 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
1765 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1766 throw(SALOME::SALOME_Exception)
1768 Unexpect aCatch(SALOME_SalomeException);
1769 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
1772 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1773 throw(SALOME::SALOME_Exception)
1775 Unexpect aCatch(SALOME_SalomeException);
1776 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
1779 //=============================================================================
1783 //=============================================================================
1784 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1786 Unexpect aCatch(SALOME_SalomeException);
1787 return _impl->NbSubMesh();
1790 //=============================================================================
1794 //=============================================================================
1795 char* SMESH_Mesh_i::Dump()
1797 std::ostringstream os;
1799 return CORBA::string_dup( os.str().c_str() );
1802 //=============================================================================
1806 //=============================================================================
1807 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1809 // SMESH::long_array_var aResult = new SMESH::long_array();
1810 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1811 // int aMinId = aSMESHDS_Mesh->MinElementID();
1812 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1814 // aResult->length(aMaxId - aMinId + 1);
1816 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1817 // aResult[i++] = id;
1819 // return aResult._retn();
1821 return GetElementsId();
1824 //=============================================================================
1828 //=============================================================================
1830 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1831 throw (SALOME::SALOME_Exception)
1833 Unexpect aCatch(SALOME_SalomeException);
1834 MESSAGE("SMESH_Mesh_i::GetElementsId");
1835 SMESH::long_array_var aResult = new SMESH::long_array();
1836 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1838 if ( aSMESHDS_Mesh == NULL )
1839 return aResult._retn();
1841 long nbElements = NbElements();
1842 aResult->length( nbElements );
1843 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1844 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1845 aResult[i] = anIt->next()->GetID();
1847 return aResult._retn();
1851 //=============================================================================
1855 //=============================================================================
1857 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1858 throw (SALOME::SALOME_Exception)
1860 Unexpect aCatch(SALOME_SalomeException);
1861 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1862 SMESH::long_array_var aResult = new SMESH::long_array();
1863 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1865 if ( aSMESHDS_Mesh == NULL )
1866 return aResult._retn();
1868 long nbElements = NbElements();
1870 // No sense in returning ids of elements along with ids of nodes:
1871 // when theElemType == SMESH::ALL, return node ids only if
1872 // there are no elements
1873 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1874 return GetNodesId();
1876 aResult->length( nbElements );
1880 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1881 while ( i < nbElements && anIt->more() ) {
1882 const SMDS_MeshElement* anElem = anIt->next();
1883 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1884 aResult[i++] = anElem->GetID();
1887 aResult->length( i );
1889 return aResult._retn();
1892 //=============================================================================
1896 //=============================================================================
1898 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1899 throw (SALOME::SALOME_Exception)
1901 Unexpect aCatch(SALOME_SalomeException);
1902 MESSAGE("SMESH_subMesh_i::GetNodesId");
1903 SMESH::long_array_var aResult = new SMESH::long_array();
1904 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1906 if ( aSMESHDS_Mesh == NULL )
1907 return aResult._retn();
1909 long nbNodes = NbNodes();
1910 aResult->length( nbNodes );
1911 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1912 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1913 aResult[i] = anIt->next()->GetID();
1915 return aResult._retn();
1918 //=============================================================================
1922 //=============================================================================
1924 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1925 throw (SALOME::SALOME_Exception)
1927 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1931 //=============================================================================
1933 * Returns ID of elements for given submesh
1935 //=============================================================================
1936 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
1937 throw (SALOME::SALOME_Exception)
1939 SMESH::long_array_var aResult = new SMESH::long_array();
1941 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1942 if(!SM) return aResult._retn();
1944 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1945 if(!SDSM) return aResult._retn();
1947 aResult->length(SDSM->NbElements());
1949 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1951 while ( eIt->more() ) {
1952 aResult[i++] = eIt->next()->GetID();
1955 return aResult._retn();
1959 //=============================================================================
1961 * Returns ID of nodes for given submesh
1962 * If param all==true - returns all nodes, else -
1963 * returns only nodes on shapes.
1965 //=============================================================================
1966 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
1967 throw (SALOME::SALOME_Exception)
1969 SMESH::long_array_var aResult = new SMESH::long_array();
1971 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
1972 if(!SM) return aResult._retn();
1974 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
1975 if(!SDSM) return aResult._retn();
1978 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
1979 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
1980 while ( nIt->more() ) {
1981 const SMDS_MeshNode* elem = nIt->next();
1982 theElems.insert( elem->GetID() );
1985 else { // all nodes of submesh elements
1986 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
1987 while ( eIt->more() ) {
1988 const SMDS_MeshElement* anElem = eIt->next();
1989 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
1990 while ( nIt->more() ) {
1991 const SMDS_MeshElement* elem = nIt->next();
1992 theElems.insert( elem->GetID() );
1997 aResult->length(theElems.size());
1998 set<int>::iterator itElem;
2000 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
2001 aResult[i++] = *itElem;
2003 return aResult._retn();
2007 //=============================================================================
2009 * Returns type of elements for given submesh
2011 //=============================================================================
2012 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2013 throw (SALOME::SALOME_Exception)
2015 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2016 if(!SM) return SMESH::ALL;
2018 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2019 if(!SDSM) return SMESH::ALL;
2021 if(SDSM->NbElements()==0)
2022 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2024 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2025 const SMDS_MeshElement* anElem = eIt->next();
2026 return ( SMESH::ElementType ) anElem->GetType();
2030 //=============================================================================
2034 //=============================================================================
2036 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2038 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2039 cerr << "CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() " << pointeur << endl;
2044 //=============================================================================
2046 * Get XYZ coordinates of node as list of double
2047 * If there is not node for given ID - returns empty list
2049 //=============================================================================
2051 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2053 SMESH::double_array_var aResult = new SMESH::double_array();
2054 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2055 if ( aSMESHDS_Mesh == NULL )
2056 return aResult._retn();
2059 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2061 return aResult._retn();
2065 aResult[0] = aNode->X();
2066 aResult[1] = aNode->Y();
2067 aResult[2] = aNode->Z();
2068 return aResult._retn();
2072 //=============================================================================
2074 * For given node returns list of IDs of inverse elements
2075 * If there is not node for given ID - returns empty list
2077 //=============================================================================
2079 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2081 SMESH::long_array_var aResult = new SMESH::long_array();
2082 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2083 if ( aSMESHDS_Mesh == NULL )
2084 return aResult._retn();
2087 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2089 return aResult._retn();
2091 // find inverse elements
2092 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2093 TColStd_SequenceOfInteger IDs;
2094 while(eIt->more()) {
2095 const SMDS_MeshElement* elem = eIt->next();
2096 IDs.Append(elem->GetID());
2098 if(IDs.Length()>0) {
2099 aResult->length(IDs.Length());
2101 for(; i<=IDs.Length(); i++) {
2102 aResult[i-1] = IDs.Value(i);
2105 return aResult._retn();
2108 //=============================================================================
2110 * \brief Return position of a node on shape
2112 //=============================================================================
2114 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2116 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2117 aNodePosition->shapeID = 0;
2118 aNodePosition->shapeType = GEOM::SHAPE;
2120 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2121 if ( !mesh ) return aNodePosition;
2123 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2125 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2127 aNodePosition->shapeID = pos->GetShapeId();
2128 switch ( pos->GetTypeOfPosition() ) {
2130 aNodePosition->shapeType = GEOM::EDGE;
2131 aNodePosition->params.length(1);
2132 aNodePosition->params[0] =
2133 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2136 aNodePosition->shapeType = GEOM::FACE;
2137 aNodePosition->params.length(2);
2138 aNodePosition->params[0] =
2139 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2140 aNodePosition->params[1] =
2141 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2143 case SMDS_TOP_VERTEX:
2144 aNodePosition->shapeType = GEOM::VERTEX;
2146 case SMDS_TOP_3DSPACE:
2147 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2148 aNodePosition->shapeType = GEOM::SOLID;
2149 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2150 aNodePosition->shapeType = GEOM::SHELL;
2156 return aNodePosition;
2159 //=============================================================================
2161 * If given element is node returns IDs of shape from position
2162 * If there is not node for given ID - returns -1
2164 //=============================================================================
2166 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2168 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2169 if ( aSMESHDS_Mesh == NULL )
2173 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2175 SMDS_PositionPtr pos = aNode->GetPosition();
2179 return pos->GetShapeId();
2186 //=============================================================================
2188 * For given element returns ID of result shape after
2189 * ::FindShape() from SMESH_MeshEditor
2190 * If there is not element for given ID - returns -1
2192 //=============================================================================
2194 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2196 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2197 if ( aSMESHDS_Mesh == NULL )
2200 // try to find element
2201 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2205 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2206 ::SMESH_MeshEditor aMeshEditor(_impl);
2207 int index = aMeshEditor.FindShape( elem );
2215 //=============================================================================
2217 * Returns number of nodes for given element
2218 * If there is not element for given ID - returns -1
2220 //=============================================================================
2222 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2224 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2225 if ( aSMESHDS_Mesh == NULL ) return -1;
2226 // try to find element
2227 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2228 if(!elem) return -1;
2229 return elem->NbNodes();
2233 //=============================================================================
2235 * Returns ID of node by given index for given element
2236 * If there is not element for given ID - returns -1
2237 * If there is not node for given index - returns -2
2239 //=============================================================================
2241 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
2243 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2244 if ( aSMESHDS_Mesh == NULL ) return -1;
2245 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2246 if(!elem) return -1;
2247 if( index>=elem->NbNodes() || index<0 ) return -1;
2248 return elem->GetNode(index)->GetID();
2251 //=============================================================================
2253 * Returns IDs of nodes of given element
2255 //=============================================================================
2257 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2259 SMESH::long_array_var aResult = new SMESH::long_array();
2260 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2262 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2264 aResult->length( elem->NbNodes() );
2265 for ( int i = 0; i < elem->NbNodes(); ++i )
2266 aResult[ i ] = elem->GetNode( i )->GetID();
2269 return aResult._retn();
2272 //=============================================================================
2274 * Returns true if given node is medium node
2275 * in given quadratic element
2277 //=============================================================================
2279 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2281 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2282 if ( aSMESHDS_Mesh == NULL ) return false;
2284 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2285 if(!aNode) return false;
2286 // try to find element
2287 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2288 if(!elem) return false;
2290 return elem->IsMediumNode(aNode);
2294 //=============================================================================
2296 * Returns true if given node is medium node
2297 * in one of quadratic elements
2299 //=============================================================================
2301 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2302 SMESH::ElementType theElemType)
2304 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2305 if ( aSMESHDS_Mesh == NULL ) return false;
2308 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2309 if(!aNode) return false;
2311 SMESH_MesherHelper aHelper( *(_impl) );
2313 SMDSAbs_ElementType aType;
2314 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2315 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2316 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2317 else aType = SMDSAbs_All;
2319 return aHelper.IsMedium(aNode,aType);
2323 //=============================================================================
2325 * Returns number of edges for given element
2327 //=============================================================================
2329 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2331 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2332 if ( aSMESHDS_Mesh == NULL ) return -1;
2333 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2334 if(!elem) return -1;
2335 return elem->NbEdges();
2339 //=============================================================================
2341 * Returns number of faces for given element
2343 //=============================================================================
2345 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2347 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2348 if ( aSMESHDS_Mesh == NULL ) return -1;
2349 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2350 if(!elem) return -1;
2351 return elem->NbFaces();
2355 //=============================================================================
2357 * Returns true if given element is polygon
2359 //=============================================================================
2361 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2363 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2364 if ( aSMESHDS_Mesh == NULL ) return false;
2365 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2366 if(!elem) return false;
2367 return elem->IsPoly();
2371 //=============================================================================
2373 * Returns true if given element is quadratic
2375 //=============================================================================
2377 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2379 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2380 if ( aSMESHDS_Mesh == NULL ) return false;
2381 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2382 if(!elem) return false;
2383 return elem->IsQuadratic();
2387 //=============================================================================
2389 * Returns bary center for given element
2391 //=============================================================================
2393 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2395 SMESH::double_array_var aResult = new SMESH::double_array();
2396 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2397 if ( aSMESHDS_Mesh == NULL )
2398 return aResult._retn();
2400 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2402 return aResult._retn();
2404 if(elem->GetType()==SMDSAbs_Volume) {
2405 SMDS_VolumeTool aTool;
2406 if(aTool.Set(elem)) {
2408 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2413 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2415 double x=0., y=0., z=0.;
2416 for(; anIt->more(); ) {
2418 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2432 return aResult._retn();
2436 //=============================================================================
2438 * Create and publish group servants if any groups were imported or created anyhow
2440 //=============================================================================
2442 void SMESH_Mesh_i::CreateGroupServants()
2444 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2446 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2447 while ( groupIt->more() )
2449 ::SMESH_Group* group = groupIt->next();
2450 int anId = group->GetGroupDS()->GetID();
2452 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
2453 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2456 SMESH_GroupBase_i* aGroupImpl;
2458 if ( SMESHDS_GroupOnGeom* groupOnGeom =
2459 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
2461 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2462 shape = groupOnGeom->GetShape();
2465 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2468 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
2469 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2470 aGroupImpl->Register();
2472 SMESH::SMESH_GroupBase_var groupVar =
2473 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2474 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
2476 // register CORBA object for persistence
2477 int nextId = _gen_i->RegisterObject( groupVar );
2478 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2480 // publishing of the groups in the study
2481 if ( !aStudy->_is_nil() ) {
2482 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
2483 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
2488 //=============================================================================
2490 * \brief Return groups cantained in _mapGroups by their IDs
2492 //=============================================================================
2494 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
2496 int nbGroups = groupIDs.size();
2497 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
2498 aList->length( nbGroups );
2500 list<int>::const_iterator ids = groupIDs.begin();
2501 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
2503 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
2504 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2505 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
2507 aList->length( nbGroups );
2508 return aList._retn();
2511 //=============================================================================
2513 * \brief Return information about imported file
2515 //=============================================================================
2517 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
2519 SALOME_MED::MedFileInfo_var res( myFileInfo );
2520 if ( !res.operator->() ) {
2521 res = new SALOME_MED::MedFileInfo;
2523 res->fileSize = res->major = res->minor = res->release = -1;