1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_Mesh_i.cxx
24 // Author : Paul RASCLE, EDF
27 #include "SMESH_Mesh_i.hxx"
29 #include "SMESH_Filter_i.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Group_i.hxx"
32 #include "SMESH_MEDMesh_i.hxx"
33 #include "SMESH_MeshEditor_i.hxx"
34 #include "SMESH_PythonDump.hxx"
35 #include "SMESH_subMesh_i.hxx"
37 #include "DriverMED_R_SMESHDS_Mesh.h"
38 #include "DriverMED_W_SMESHDS_Mesh.h"
39 #include "SMDS_VolumeTool.hxx"
40 #include "SMESHDS_Command.hxx"
41 #include "SMESHDS_CommandType.hxx"
42 #include "SMESHDS_GroupOnGeom.hxx"
43 #include "SMESH_Group.hxx"
44 #include "SMESH_MeshEditor.hxx"
45 #include "SMESH_MesherHelper.hxx"
46 #include "SMDS_EdgePosition.hxx"
47 #include "SMDS_FacePosition.hxx"
50 #include "SALOME_NamingService.hxx"
51 #include "Utils_CorbaException.hxx"
52 #include "Utils_ExceptHandlers.hxx"
53 #include "Utils_SINGLETON.hxx"
54 #include "utilities.h"
55 #include "GEOMImpl_Types.hxx"
58 #include <BRep_Builder.hxx>
59 #include <OSD_Directory.hxx>
60 #include <OSD_File.hxx>
61 #include <OSD_Path.hxx>
62 #include <OSD_Protection.hxx>
63 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
64 #include <TColStd_MapOfInteger.hxx>
65 #include <TColStd_SequenceOfInteger.hxx>
66 #include <TCollection_AsciiString.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopoDS_Compound.hxx>
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() );
120 // this method is colled from destructor of group (PAL6331)
121 //_impl->RemoveGroup( aGroup->GetLocalID() );
129 //=============================================================================
133 * Associates <this> mesh with <theShape> and puts a reference
134 * to <theShape> into the current study;
135 * the previous shape is substituted by the new one.
137 //=============================================================================
139 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
140 throw (SALOME::SALOME_Exception)
142 Unexpect aCatch(SALOME_SalomeException);
144 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
146 catch(SALOME_Exception & S_ex) {
147 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
149 // to track changes of GEOM groups
150 addGeomGroupData( theShapeObject, _this() );
153 //================================================================================
155 * \brief return true if mesh has a shape to build a shape on
157 //================================================================================
159 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
160 throw (SALOME::SALOME_Exception)
162 Unexpect aCatch(SALOME_SalomeException);
165 res = _impl->HasShapeToMesh();
167 catch(SALOME_Exception & S_ex) {
168 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
173 //=======================================================================
174 //function : GetShapeToMesh
176 //=======================================================================
178 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
179 throw (SALOME::SALOME_Exception)
181 Unexpect aCatch(SALOME_SalomeException);
182 GEOM::GEOM_Object_var aShapeObj;
184 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
186 aShapeObj = _gen_i->ShapeToGeomObject( S );
188 catch(SALOME_Exception & S_ex) {
189 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
191 return aShapeObj._retn();
194 //================================================================================
196 * \brief Remove all nodes and elements
198 //================================================================================
200 void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
202 Unexpect aCatch(SALOME_SalomeException);
206 catch(SALOME_Exception & S_ex) {
207 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
209 TPythonDump() << _this() << ".Clear()";
212 //=============================================================================
216 //=============================================================================
218 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
220 SMESH::DriverMED_ReadStatus res;
223 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
224 res = SMESH::DRS_OK; break;
225 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
226 res = SMESH::DRS_EMPTY; break;
227 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
228 res = SMESH::DRS_WARN_RENUMBER; break;
229 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
230 res = SMESH::DRS_WARN_SKIP_ELEM; break;
231 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
233 res = SMESH::DRS_FAIL; break;
238 //=============================================================================
242 * Imports mesh data from MED file
244 //=============================================================================
246 SMESH::DriverMED_ReadStatus
247 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
248 throw ( SALOME::SALOME_Exception )
250 Unexpect aCatch(SALOME_SalomeException);
253 status = _impl->MEDToMesh( theFileName, theMeshName );
255 catch( SALOME_Exception& S_ex ) {
256 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
259 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
262 CreateGroupServants();
264 int major, minor, release;
265 if( !MED::getMEDVersion( theFileName, major, minor, release ) )
266 major = minor = release = -1;
267 myFileInfo = new SALOME_MED::MedFileInfo();
268 myFileInfo->fileName = theFileName;
269 myFileInfo->fileSize = 0;
272 if ( ::_stati64( theFileName, &d ) != -1 )
275 if ( ::stat64( theFileName, &d ) != -1 )
277 myFileInfo->fileSize = d.st_size;
278 myFileInfo->major = major;
279 myFileInfo->minor = minor;
280 myFileInfo->release = release;
282 return ConvertDriverMEDReadStatus(status);
285 //================================================================================
287 * \brief Return string representation of a MED file version comprising nbDigits
289 //================================================================================
291 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
293 std::string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
295 return CORBA::string_dup( ver.c_str() );
298 //=============================================================================
302 * Imports mesh data from MED file
304 //=============================================================================
306 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
307 throw ( SALOME::SALOME_Exception )
309 // Read mesh with name = <theMeshName> into SMESH_Mesh
310 _impl->UNVToMesh( theFileName );
312 CreateGroupServants();
317 //=============================================================================
321 * Imports mesh data from STL file
323 //=============================================================================
324 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
325 throw ( SALOME::SALOME_Exception )
327 // Read mesh with name = <theMeshName> into SMESH_Mesh
328 _impl->STLToMesh( theFileName );
333 //=============================================================================
337 * Imports mesh data from MED file
339 //=============================================================================
341 // int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
343 // // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
344 // int status = _impl->MEDToMesh( theFileName, theMeshName );
345 // CreateGroupServants();
350 //=============================================================================
354 //=============================================================================
356 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
358 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
359 (SMESH_Hypothesis::Hypothesis_Status theStatus)
362 RETURNCASE( HYP_OK );
363 RETURNCASE( HYP_MISSING );
364 RETURNCASE( HYP_CONCURENT );
365 RETURNCASE( HYP_BAD_PARAMETER );
366 RETURNCASE( HYP_HIDDEN_ALGO );
367 RETURNCASE( HYP_HIDING_ALGO );
368 RETURNCASE( HYP_UNKNOWN_FATAL );
369 RETURNCASE( HYP_INCOMPATIBLE );
370 RETURNCASE( HYP_NOTCONFORM );
371 RETURNCASE( HYP_ALREADY_EXIST );
372 RETURNCASE( HYP_BAD_DIM );
373 RETURNCASE( HYP_BAD_SUBSHAPE );
374 RETURNCASE( HYP_BAD_GEOMETRY );
375 RETURNCASE( HYP_NEED_SHAPE );
378 return SMESH::HYP_UNKNOWN_FATAL;
381 //=============================================================================
385 * calls internal addHypothesis() and then adds a reference to <anHyp> under
386 * the SObject actually having a reference to <aSubShape>.
387 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
389 //=============================================================================
391 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
392 SMESH::SMESH_Hypothesis_ptr anHyp)
393 throw(SALOME::SALOME_Exception)
395 Unexpect aCatch(SALOME_SalomeException);
396 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
398 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
399 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
400 aSubShapeObject, anHyp );
402 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
404 // Update Python script
405 if(_impl->HasShapeToMesh()) {
406 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
407 << aSubShapeObject << ", " << anHyp << " )";
410 TPythonDump() << "status = " << _this() << ".AddHypothesis( "<< anHyp << " )";
413 return ConvertHypothesisStatus(status);
416 //=============================================================================
420 //=============================================================================
422 SMESH_Hypothesis::Hypothesis_Status
423 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
424 SMESH::SMESH_Hypothesis_ptr anHyp)
426 if(MYDEBUG) MESSAGE("addHypothesis");
428 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
429 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
432 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
433 if (CORBA::is_nil(myHyp))
434 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
437 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
440 TopoDS_Shape myLocSubShape;
441 //use PseudoShape in case if mesh has no shape
443 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
445 myLocSubShape = _impl->GetShapeToMesh();
447 int hypId = myHyp->GetId();
448 status = _impl->AddHypothesis(myLocSubShape, hypId);
449 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
450 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
451 // assure there is a corresponding submesh
452 if ( !_impl->IsMainShape( myLocSubShape )) {
453 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
454 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
455 createSubMesh( aSubShapeObject );
459 catch(SALOME_Exception & S_ex)
461 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
466 //=============================================================================
470 //=============================================================================
472 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
473 SMESH::SMESH_Hypothesis_ptr anHyp)
474 throw(SALOME::SALOME_Exception)
476 Unexpect aCatch(SALOME_SalomeException);
477 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
479 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
480 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
481 aSubShapeObject, anHyp );
483 // Update Python script
484 // Update Python script
485 if(_impl->HasShapeToMesh()) {
486 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
487 << aSubShapeObject << ", " << anHyp << " )";
490 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
494 return ConvertHypothesisStatus(status);
497 //=============================================================================
501 //=============================================================================
503 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
504 SMESH::SMESH_Hypothesis_ptr anHyp)
506 if(MYDEBUG) MESSAGE("removeHypothesis()");
507 // **** proposer liste de subShape (selection multiple)
509 if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
510 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
513 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
514 if (CORBA::is_nil(myHyp))
515 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
518 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
521 TopoDS_Shape myLocSubShape;
522 //use PseudoShape in case if mesh has no shape
524 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
526 myLocSubShape = _impl->GetShapeToMesh();
528 int hypId = myHyp->GetId();
529 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
530 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
531 _mapHypo.erase( hypId );
533 catch(SALOME_Exception & S_ex)
535 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
540 //=============================================================================
544 //=============================================================================
546 SMESH::ListOfHypothesis *
547 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
548 throw(SALOME::SALOME_Exception)
550 Unexpect aCatch(SALOME_SalomeException);
551 if (MYDEBUG) MESSAGE("GetHypothesisList");
552 if (CORBA::is_nil(aSubShapeObject))
553 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
556 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
559 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
560 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
561 int i = 0, n = aLocalList.size();
564 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
565 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
566 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
567 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
572 catch(SALOME_Exception & S_ex) {
573 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
576 return aList._retn();
579 //=============================================================================
583 //=============================================================================
584 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
585 const char* theName )
586 throw(SALOME::SALOME_Exception)
588 Unexpect aCatch(SALOME_SalomeException);
589 MESSAGE("SMESH_Mesh_i::GetSubMesh");
590 if (CORBA::is_nil(aSubShapeObject))
591 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
594 SMESH::SMESH_subMesh_var subMesh;
595 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
597 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
599 //Get or Create the SMESH_subMesh object implementation
601 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
602 subMesh = getSubMesh( subMeshId );
604 // create a new subMesh object servant if there is none for the shape
605 if ( subMesh->_is_nil() )
606 subMesh = createSubMesh( aSubShapeObject );
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() )
721 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
722 ( createGroup( theElemType, theName, aShape ));
724 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
725 SALOMEDS::SObject_var aSO =
726 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
727 aNewGroup, theGeomObj, theName);
728 if ( !aSO->_is_nil()) {
729 // Update Python script
730 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
731 << ElementTypeString(theElemType) << ", '" << theName << "', "
732 << theGeomObj << " )";
737 return aNewGroup._retn();
740 //=============================================================================
744 //=============================================================================
746 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
747 throw (SALOME::SALOME_Exception)
749 if ( theGroup->_is_nil() )
752 SMESH_GroupBase_i* aGroup =
753 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
757 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
758 if ( !aStudy->_is_nil() ) {
759 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
761 if ( !aGroupSO->_is_nil() ) {
762 // Update Python script
763 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
765 // Remove group's SObject
766 aStudy->NewBuilder()->RemoveObjectWithChildren( aGroupSO );
770 // Remove the group from SMESH data structures
771 removeGroup( aGroup->GetLocalID() );
774 //=============================================================================
775 /*! RemoveGroupWithContents
776 * Remove group with its contents
778 //=============================================================================
779 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
780 throw (SALOME::SALOME_Exception)
782 if ( theGroup->_is_nil() )
785 SMESH_GroupBase_i* aGroup =
786 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
790 SMESH::long_array_var anIds = aGroup->GetListOfID();
791 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
793 // Update Python script
794 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
797 if ( aGroup->GetType() == SMESH::NODE )
798 aMeshEditor->RemoveNodes( anIds );
800 aMeshEditor->RemoveElements( anIds );
803 RemoveGroup( theGroup );
805 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
806 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
807 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
811 //================================================================================
813 * \brief Get the list of groups existing in the mesh
814 * \retval SMESH::ListOfGroups * - list of groups
816 //================================================================================
818 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
820 Unexpect aCatch(SALOME_SalomeException);
821 if (MYDEBUG) MESSAGE("GetGroups");
823 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
826 TPythonDump aPythonDump;
827 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
831 aList->length( _mapGroups.size() );
833 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
834 for ( ; it != _mapGroups.end(); it++ ) {
835 if ( CORBA::is_nil( it->second )) continue;
836 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
838 if (i > 1) aPythonDump << ", ";
839 aPythonDump << it->second;
843 catch(SALOME_Exception & S_ex) {
844 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
847 // Update Python script
848 if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
849 aPythonDump << " ] = " << _this() << ".GetGroups()";
851 return aList._retn();
853 //=============================================================================
855 * Get number of groups existing in the mesh
857 //=============================================================================
859 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
861 Unexpect aCatch(SALOME_SalomeException);
862 return _mapGroups.size();
865 //=============================================================================
867 * New group is created. All mesh elements that are
868 * present in initial groups are added to the new one
870 //=============================================================================
871 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
872 SMESH::SMESH_GroupBase_ptr theGroup2,
873 const char* theName )
874 throw (SALOME::SALOME_Exception)
878 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
879 theGroup1->GetType() != theGroup2->GetType() )
880 return SMESH::SMESH_Group::_nil();
883 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
884 if ( aResGrp->_is_nil() )
885 return SMESH::SMESH_Group::_nil();
887 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
888 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
890 TColStd_MapOfInteger aResMap;
892 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
893 aResMap.Add( anIds1[ i1 ] );
895 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
896 aResMap.Add( anIds2[ i2 ] );
898 SMESH::long_array_var aResIds = new SMESH::long_array;
899 aResIds->length( aResMap.Extent() );
902 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
903 for( ; anIter.More(); anIter.Next() )
904 aResIds[ resI++ ] = anIter.Key();
906 aResGrp->Add( aResIds );
908 // Clear python lines, created by CreateGroup() and Add()
909 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
910 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
911 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
913 // Update Python script
914 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
915 << theGroup1 << ", " << theGroup2 << ", '"
918 return aResGrp._retn();
922 return SMESH::SMESH_Group::_nil();
926 //=============================================================================
928 * New group is created. All mesh elements that are
929 * present in both initial groups are added to the new one.
931 //=============================================================================
932 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
933 SMESH::SMESH_GroupBase_ptr theGroup2,
934 const char* theName )
935 throw (SALOME::SALOME_Exception)
937 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
938 theGroup1->GetType() != theGroup2->GetType() )
939 return SMESH::SMESH_Group::_nil();
941 // Create Intersection
942 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
943 if ( aResGrp->_is_nil() )
946 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
947 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
949 TColStd_MapOfInteger aMap1;
951 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
952 aMap1.Add( anIds1[ i1 ] );
954 TColStd_SequenceOfInteger aSeq;
956 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
957 if ( aMap1.Contains( anIds2[ i2 ] ) )
958 aSeq.Append( anIds2[ i2 ] );
960 SMESH::long_array_var aResIds = new SMESH::long_array;
961 aResIds->length( aSeq.Length() );
963 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
964 aResIds[ resI ] = aSeq( resI + 1 );
966 aResGrp->Add( aResIds );
968 // Clear python lines, created by CreateGroup() and Add()
969 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
970 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
971 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
973 // Update Python script
974 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
975 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
977 return aResGrp._retn();
980 //=============================================================================
982 * New group is created. All mesh elements that are present in
983 * main group but do not present in tool group are added to the new one
985 //=============================================================================
986 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
987 SMESH::SMESH_GroupBase_ptr theGroup2,
988 const char* theName )
989 throw (SALOME::SALOME_Exception)
991 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
992 theGroup1->GetType() != theGroup2->GetType() )
993 return SMESH::SMESH_Group::_nil();
996 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
997 if ( aResGrp->_is_nil() )
1000 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
1001 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
1003 TColStd_MapOfInteger aMap2;
1005 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
1006 aMap2.Add( anIds2[ i2 ] );
1008 TColStd_SequenceOfInteger aSeq;
1009 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
1010 if ( !aMap2.Contains( anIds1[ i1 ] ) )
1011 aSeq.Append( anIds1[ i1 ] );
1013 SMESH::long_array_var aResIds = new SMESH::long_array;
1014 aResIds->length( aSeq.Length() );
1016 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
1017 aResIds[ resI ] = aSeq( resI + 1 );
1019 aResGrp->Add( aResIds );
1021 // Clear python lines, created by CreateGroup() and Add()
1022 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1023 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1024 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
1026 // Update Python script
1027 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
1028 << theGroup1 << ", " << theGroup2 << ", '"
1029 << theName << "' )";
1031 return aResGrp._retn();
1034 //================================================================================
1036 * \brief Remember GEOM group data
1038 //================================================================================
1040 void SMESH_Mesh_i::addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
1041 CORBA::Object_ptr theSmeshObj)
1043 if ( CORBA::is_nil( theGeomObj ) || theGeomObj->GetType() != GEOM_GROUP )
1046 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1047 SALOMEDS::SObject_var groupSO = _gen_i->ObjectToSObject( study, theGeomObj );
1048 if ( groupSO->_is_nil() )
1051 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1052 GEOM::GEOM_IGroupOperations_var groupOp =
1053 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1054 GEOM::ListOfLong_var ids = groupOp->GetObjects( theGeomObj );
1057 _geomGroupData.push_back( TGeomGroupData() );
1058 TGeomGroupData & groupData = _geomGroupData.back();
1060 CORBA::String_var entry = groupSO->GetID();
1061 groupData._groupEntry = entry.in();
1063 for ( int i = 0; i < ids->length(); ++i )
1064 groupData._indices.insert( ids[i] );
1066 groupData._smeshObject = theSmeshObj;
1069 //================================================================================
1071 * Remove GEOM group data relating to removed smesh object
1073 //================================================================================
1075 void SMESH_Mesh_i::removeGeomGroupData(CORBA::Object_ptr theSmeshObj)
1077 list<TGeomGroupData>::iterator
1078 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1079 for ( ; data != dataEnd; ++data ) {
1080 if ( theSmeshObj->_is_equivalent( data->_smeshObject )) {
1081 _geomGroupData.erase( data );
1087 //================================================================================
1089 * \brief Return new group contents if it has been changed and update group data
1091 //================================================================================
1093 TopoDS_Shape SMESH_Mesh_i::newGroupShape( TGeomGroupData & groupData)
1095 TopoDS_Shape newShape;
1098 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1099 if ( study->_is_nil() ) return newShape; // means "not changed"
1100 SALOMEDS::SObject_var groupSO = study->FindObjectID( groupData._groupEntry.c_str() );
1101 if ( !groupSO->_is_nil() )
1103 CORBA::Object_var groupObj = _gen_i->SObjectToObject( groupSO );
1104 if ( CORBA::is_nil( groupObj )) return newShape;
1105 GEOM::GEOM_Object_var geomGroup = GEOM::GEOM_Object::_narrow( groupObj );
1107 // get indices of group items
1108 set<int> curIndices;
1109 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1110 GEOM::GEOM_IGroupOperations_var groupOp =
1111 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1112 GEOM::ListOfLong_var ids = groupOp->GetObjects( geomGroup );
1113 for ( int i = 0; i < ids->length(); ++i )
1114 curIndices.insert( ids[i] );
1116 if ( groupData._indices == curIndices )
1117 return newShape; // group not changed
1120 groupData._indices = curIndices;
1122 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1123 if ( !geomClient ) return newShape;
1124 TCollection_AsciiString groupIOR = geomGen->GetStringFromIOR( geomGroup );
1125 geomClient->RemoveShapeFromBuffer( groupIOR );
1126 newShape = _gen_i->GeomObjectToShape( geomGroup );
1129 if ( newShape.IsNull() ) {
1130 // geom group becomes empty - return empty compound
1131 TopoDS_Compound compound;
1132 BRep_Builder builder;
1133 builder.MakeCompound(compound);
1134 newShape = compound;
1139 //=============================================================================
1141 * \brief Update objects depending on changed geom groups
1143 * NPAL16168: geometrical group edition from a submesh don't modifiy mesh computation
1144 * issue 0020210: Update of a smesh group after modification of the associated geom group
1146 //=============================================================================
1148 void SMESH_Mesh_i::CheckGeomGroupModif()
1150 if ( !_impl->HasShapeToMesh() ) return;
1152 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1153 if ( study->_is_nil() ) return;
1155 CORBA::Long nbEntities = NbNodes() + NbElements();
1157 // Check if group contents changed
1159 typedef map< string, TopoDS_Shape > TEntry2Geom;
1160 TEntry2Geom newGroupContents;
1162 list<TGeomGroupData>::iterator
1163 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1164 for ( ; data != dataEnd; ++data )
1166 pair< TEntry2Geom::iterator, bool > it_new =
1167 newGroupContents.insert( make_pair( data->_groupEntry, TopoDS_Shape() ));
1168 bool processedGroup = !it_new.second;
1169 TopoDS_Shape& newShape = it_new.first->second;
1170 if ( !processedGroup )
1171 newShape = newGroupShape( *data );
1172 if ( newShape.IsNull() )
1173 continue; // no changes
1175 if ( processedGroup ) { // update group indices
1176 list<TGeomGroupData>::iterator data2 = data;
1177 for ( --data2; data2->_groupEntry != data->_groupEntry; --data2)
1178 data->_indices = data2->_indices;
1181 // Update SMESH objects according to new GEOM group contents
1183 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( data->_smeshObject );
1184 if ( !mesh->_is_nil() ) // -------------- MESH ----------------------------
1190 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( data->_smeshObject );
1191 if ( !submesh->_is_nil() ) // -------------- Sub mesh ---------------------
1193 int oldID = submesh->GetId();
1194 if ( _mapSubMeshIor.find( oldID ) == _mapSubMeshIor.end() )
1196 TopoDS_Shape oldShape = _mapSubMesh[oldID]->GetSubShape();
1198 // update hypotheses
1199 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldShape);
1200 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1201 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1203 _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
1204 _impl->AddHypothesis ( newShape, (*hypIt)->GetID());
1206 // care of submeshes
1207 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newShape );
1208 int newID = newSubmesh->GetId();
1209 if ( newID != oldID ) {
1210 _mapSubMesh [ newID ] = newSubmesh;
1211 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1212 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1213 _mapSubMesh. erase(oldID);
1214 _mapSubMesh_i. erase(oldID);
1215 _mapSubMeshIor.erase(oldID);
1216 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1221 SMESH::SMESH_GroupOnGeom_var smeshGroup =
1222 SMESH::SMESH_GroupOnGeom::_narrow( data->_smeshObject );
1223 if ( !smeshGroup->_is_nil() ) // ------------ GROUP -----------------------
1225 SMESH_GroupOnGeom_i* group_i = SMESH::DownCast<SMESH_GroupOnGeom_i*>( smeshGroup );
1227 ::SMESH_Group* group = _impl->GetGroup( group_i->GetLocalID() );
1228 SMESHDS_GroupOnGeom* ds = static_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() );
1229 ds->SetShape( newShape );
1237 CORBA::Long newNbEntities = NbNodes() + NbElements();
1238 list< SALOMEDS::SObject_var > soToUpdateIcons;
1239 if ( newNbEntities != nbEntities )
1241 // Add all SObjects with icons
1242 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, _this() )); // mesh
1244 for (map<int, SMESH::SMESH_subMesh_ptr>::iterator i_sm = _mapSubMeshIor.begin();
1245 i_sm != _mapSubMeshIor.end(); ++i_sm ) // submeshes
1246 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_sm->second ));
1248 for ( map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_gr = _mapGroups.begin();
1249 i_gr != _mapGroups.end(); ++i_gr ) // groups
1250 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_gr->second ));
1253 list< SALOMEDS::SObject_var >::iterator so = soToUpdateIcons.begin();
1254 for ( ; so != soToUpdateIcons.end(); ++so )
1255 _gen_i->SetPixMap( *so, "ICON_SMESH_TREE_MESH_WARN" );
1258 //=============================================================================
1262 //=============================================================================
1264 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
1266 if(MYDEBUG) MESSAGE( "createSubMesh" );
1267 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
1269 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
1270 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
1271 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
1272 SMESH::SMESH_subMesh_var subMesh
1273 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
1275 _mapSubMesh[subMeshId] = mySubMesh;
1276 _mapSubMesh_i[subMeshId] = subMeshServant;
1277 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
1279 // register CORBA object for persistence
1280 int nextId = _gen_i->RegisterObject( subMesh );
1281 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
1283 // to track changes of GEOM groups
1284 addGeomGroupData( theSubShapeObject, subMesh );
1286 return subMesh._retn();
1289 //=======================================================================
1290 //function : getSubMesh
1292 //=======================================================================
1294 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
1296 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
1297 if ( it == _mapSubMeshIor.end() )
1298 return SMESH::SMESH_subMesh::_nil();
1300 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1304 //=============================================================================
1308 //=============================================================================
1310 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1311 GEOM::GEOM_Object_ptr theSubShapeObject )
1313 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1314 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1318 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1319 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1320 removeHypothesis( theSubShapeObject, aHypList[i] );
1323 catch( const SALOME::SALOME_Exception& ) {
1324 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1326 removeGeomGroupData( theSubShapeObject );
1328 int subMeshId = theSubMesh->GetId();
1330 _mapSubMesh.erase(subMeshId);
1331 _mapSubMesh_i.erase(subMeshId);
1332 _mapSubMeshIor.erase(subMeshId);
1333 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1336 //=============================================================================
1340 //=============================================================================
1342 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1343 const char* theName,
1344 const TopoDS_Shape& theShape )
1347 SMESH::SMESH_GroupBase_var aGroup;
1348 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1349 SMESH_GroupBase_i* aGroupImpl;
1350 if ( !theShape.IsNull() )
1351 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1353 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1355 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1356 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1357 aGroupImpl->Register();
1358 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1360 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1361 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1363 // register CORBA object for persistence
1364 int nextId = _gen_i->RegisterObject( aGroup );
1365 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1367 // to track changes of GEOM groups
1368 if ( !theShape.IsNull() ) {
1369 GEOM::GEOM_Object_var geom = _gen_i->ShapeToGeomObject( theShape );
1370 addGeomGroupData( geom, aGroup );
1373 return aGroup._retn();
1376 //=============================================================================
1378 * SMESH_Mesh_i::removeGroup
1380 * Should be called by ~SMESH_Group_i()
1382 //=============================================================================
1384 void SMESH_Mesh_i::removeGroup( const int theId )
1386 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1387 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1388 removeGeomGroupData( _mapGroups[theId] );
1389 _mapGroups.erase( theId );
1390 _impl->RemoveGroup( theId );
1395 //=============================================================================
1399 //=============================================================================
1401 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1402 throw(SALOME::SALOME_Exception)
1404 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1406 SMESH::log_array_var aLog;
1408 list < SMESHDS_Command * >logDS = _impl->GetLog();
1409 aLog = new SMESH::log_array;
1411 int lg = logDS.size();
1414 list < SMESHDS_Command * >::iterator its = logDS.begin();
1415 while(its != logDS.end()){
1416 SMESHDS_Command *com = *its;
1417 int comType = com->GetType();
1419 int lgcom = com->GetNumber();
1421 const list < int >&intList = com->GetIndexes();
1422 int inum = intList.size();
1424 list < int >::const_iterator ii = intList.begin();
1425 const list < double >&coordList = com->GetCoords();
1426 int rnum = coordList.size();
1428 list < double >::const_iterator ir = coordList.begin();
1429 aLog[indexLog].commandType = comType;
1430 aLog[indexLog].number = lgcom;
1431 aLog[indexLog].coords.length(rnum);
1432 aLog[indexLog].indexes.length(inum);
1433 for(int i = 0; i < rnum; i++){
1434 aLog[indexLog].coords[i] = *ir;
1435 //MESSAGE(" "<<i<<" "<<ir.Value());
1438 for(int i = 0; i < inum; i++){
1439 aLog[indexLog].indexes[i] = *ii;
1440 //MESSAGE(" "<<i<<" "<<ii.Value());
1449 catch(SALOME_Exception & S_ex){
1450 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1452 return aLog._retn();
1456 //=============================================================================
1460 //=============================================================================
1462 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1464 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1468 //=============================================================================
1472 //=============================================================================
1474 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1476 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1480 //=============================================================================
1484 //=============================================================================
1486 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1491 //=============================================================================
1495 //=============================================================================
1497 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1499 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1503 //=============================================================================
1507 //=============================================================================
1509 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1511 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1515 //=============================================================================
1517 * Return mesh editor
1519 //=============================================================================
1521 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1523 // Create MeshEditor
1524 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
1525 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1527 // Update Python script
1528 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1530 return aMesh._retn();
1533 //=============================================================================
1535 * Return mesh edition previewer
1537 //=============================================================================
1539 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
1541 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
1542 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1543 return aMesh._retn();
1546 //=============================================================================
1550 //=============================================================================
1551 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
1553 Unexpect aCatch(SALOME_SalomeException);
1554 _impl->SetAutoColor(theAutoColor);
1557 //=============================================================================
1561 //=============================================================================
1562 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
1564 Unexpect aCatch(SALOME_SalomeException);
1565 return _impl->GetAutoColor();
1569 //=============================================================================
1571 * Export in different formats
1573 //=============================================================================
1575 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1577 return _impl->HasDuplicatedGroupNamesMED();
1580 void SMESH_Mesh_i::PrepareForWriting (const char* file)
1582 TCollection_AsciiString aFullName ((char*)file);
1583 OSD_Path aPath (aFullName);
1584 OSD_File aFile (aPath);
1585 if (aFile.Exists()) {
1586 // existing filesystem node
1587 if (aFile.KindOfFile() == OSD_FILE) {
1588 if (aFile.IsWriteable()) {
1591 if (aFile.Failed()) {
1592 TCollection_AsciiString msg ("File ");
1593 msg += aFullName + " cannot be replaced.";
1594 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1597 TCollection_AsciiString msg ("File ");
1598 msg += aFullName + " cannot be overwritten.";
1599 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1602 TCollection_AsciiString msg ("Location ");
1603 msg += aFullName + " is not a file.";
1604 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1607 // nonexisting file; check if it can be created
1609 aFile.Build(OSD_WriteOnly, OSD_Protection());
1610 if (aFile.Failed()) {
1611 TCollection_AsciiString msg ("You cannot create the file ");
1612 msg += aFullName + ". Check the directory existance and access rights.";
1613 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1621 void SMESH_Mesh_i::ExportToMED (const char* file,
1622 CORBA::Boolean auto_groups,
1623 SMESH::MED_VERSION theVersion)
1624 throw(SALOME::SALOME_Exception)
1626 Unexpect aCatch(SALOME_SalomeException);
1628 // Update Python script
1629 TPythonDump() << _this() << ".ExportToMED( '"
1630 << file << "', " << auto_groups << ", " << theVersion << " )";
1633 PrepareForWriting(file);
1634 char* aMeshName = "Mesh";
1635 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1636 if ( !aStudy->_is_nil() ) {
1637 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1638 if ( !aMeshSO->_is_nil() ) {
1639 aMeshName = aMeshSO->GetName();
1641 //SCRUTE(aMeshName);
1642 //SCRUTE(aMeshSO->GetID());
1644 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1645 if ( !aStudy->GetProperties()->IsLocked() )
1647 SALOMEDS::GenericAttribute_var anAttr;
1648 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1649 SALOMEDS::AttributeExternalFileDef_var aFileName;
1650 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1651 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1652 ASSERT(!aFileName->_is_nil());
1653 aFileName->SetValue(file);
1654 SALOMEDS::AttributeFileType_var aFileType;
1655 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1656 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1657 ASSERT(!aFileType->_is_nil());
1658 aFileType->SetValue("FICHIERMED");
1662 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1665 void SMESH_Mesh_i::ExportMED (const char* file,
1666 CORBA::Boolean auto_groups)
1667 throw(SALOME::SALOME_Exception)
1669 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1672 void SMESH_Mesh_i::ExportDAT (const char *file)
1673 throw(SALOME::SALOME_Exception)
1675 Unexpect aCatch(SALOME_SalomeException);
1677 // Update Python script
1678 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1681 PrepareForWriting(file);
1682 _impl->ExportDAT(file);
1685 void SMESH_Mesh_i::ExportUNV (const char *file)
1686 throw(SALOME::SALOME_Exception)
1688 Unexpect aCatch(SALOME_SalomeException);
1690 // Update Python script
1691 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1694 PrepareForWriting(file);
1695 _impl->ExportUNV(file);
1698 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1699 throw(SALOME::SALOME_Exception)
1701 Unexpect aCatch(SALOME_SalomeException);
1703 // Update Python script
1704 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1707 PrepareForWriting(file);
1708 _impl->ExportSTL(file, isascii);
1711 //=============================================================================
1715 //=============================================================================
1717 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1719 Unexpect aCatch(SALOME_SalomeException);
1720 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1721 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1722 return aMesh._retn();
1725 //=============================================================================
1729 //=============================================================================
1730 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1732 Unexpect aCatch(SALOME_SalomeException);
1733 return _impl->NbNodes();
1736 //=============================================================================
1740 //=============================================================================
1741 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1743 Unexpect aCatch(SALOME_SalomeException);
1744 return NbEdges() + NbFaces() + NbVolumes();
1747 //=============================================================================
1751 //=============================================================================
1752 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1754 Unexpect aCatch(SALOME_SalomeException);
1755 return _impl->NbEdges();
1758 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1759 throw(SALOME::SALOME_Exception)
1761 Unexpect aCatch(SALOME_SalomeException);
1762 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
1765 //=============================================================================
1769 //=============================================================================
1770 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1772 Unexpect aCatch(SALOME_SalomeException);
1773 return _impl->NbFaces();
1776 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1778 Unexpect aCatch(SALOME_SalomeException);
1779 return _impl->NbTriangles();
1782 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1784 Unexpect aCatch(SALOME_SalomeException);
1785 return _impl->NbQuadrangles();
1788 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1790 Unexpect aCatch(SALOME_SalomeException);
1791 return _impl->NbPolygons();
1794 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1795 throw(SALOME::SALOME_Exception)
1797 Unexpect aCatch(SALOME_SalomeException);
1798 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
1801 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1802 throw(SALOME::SALOME_Exception)
1804 Unexpect aCatch(SALOME_SalomeException);
1805 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
1808 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1809 throw(SALOME::SALOME_Exception)
1811 Unexpect aCatch(SALOME_SalomeException);
1812 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
1815 //=============================================================================
1819 //=============================================================================
1820 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1822 Unexpect aCatch(SALOME_SalomeException);
1823 return _impl->NbVolumes();
1826 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1828 Unexpect aCatch(SALOME_SalomeException);
1829 return _impl->NbTetras();
1832 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1834 Unexpect aCatch(SALOME_SalomeException);
1835 return _impl->NbHexas();
1838 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1840 Unexpect aCatch(SALOME_SalomeException);
1841 return _impl->NbPyramids();
1844 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1846 Unexpect aCatch(SALOME_SalomeException);
1847 return _impl->NbPrisms();
1850 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1852 Unexpect aCatch(SALOME_SalomeException);
1853 return _impl->NbPolyhedrons();
1856 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1857 throw(SALOME::SALOME_Exception)
1859 Unexpect aCatch(SALOME_SalomeException);
1860 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
1863 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1864 throw(SALOME::SALOME_Exception)
1866 Unexpect aCatch(SALOME_SalomeException);
1867 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
1870 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1871 throw(SALOME::SALOME_Exception)
1873 Unexpect aCatch(SALOME_SalomeException);
1874 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
1877 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1878 throw(SALOME::SALOME_Exception)
1880 Unexpect aCatch(SALOME_SalomeException);
1881 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
1884 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1885 throw(SALOME::SALOME_Exception)
1887 Unexpect aCatch(SALOME_SalomeException);
1888 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
1891 //=============================================================================
1895 //=============================================================================
1896 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1898 Unexpect aCatch(SALOME_SalomeException);
1899 return _mapSubMesh_i.size();
1902 //=============================================================================
1906 //=============================================================================
1907 char* SMESH_Mesh_i::Dump()
1909 std::ostringstream os;
1911 return CORBA::string_dup( os.str().c_str() );
1914 //=============================================================================
1918 //=============================================================================
1919 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1921 // SMESH::long_array_var aResult = new SMESH::long_array();
1922 // SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1923 // int aMinId = aSMESHDS_Mesh->MinElementID();
1924 // int aMaxId = aSMESHDS_Mesh->MaxElementID();
1926 // aResult->length(aMaxId - aMinId + 1);
1928 // for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1929 // aResult[i++] = id;
1931 // return aResult._retn();
1933 return GetElementsId();
1936 //=============================================================================
1940 //=============================================================================
1942 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1943 throw (SALOME::SALOME_Exception)
1945 Unexpect aCatch(SALOME_SalomeException);
1946 MESSAGE("SMESH_Mesh_i::GetElementsId");
1947 SMESH::long_array_var aResult = new SMESH::long_array();
1948 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1950 if ( aSMESHDS_Mesh == NULL )
1951 return aResult._retn();
1953 long nbElements = NbElements();
1954 aResult->length( nbElements );
1955 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1956 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1957 aResult[i] = anIt->next()->GetID();
1959 return aResult._retn();
1963 //=============================================================================
1967 //=============================================================================
1969 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1970 throw (SALOME::SALOME_Exception)
1972 Unexpect aCatch(SALOME_SalomeException);
1973 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1974 SMESH::long_array_var aResult = new SMESH::long_array();
1975 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1977 if ( aSMESHDS_Mesh == NULL )
1978 return aResult._retn();
1980 long nbElements = NbElements();
1982 // No sense in returning ids of elements along with ids of nodes:
1983 // when theElemType == SMESH::ALL, return node ids only if
1984 // there are no elements
1985 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1986 return GetNodesId();
1988 aResult->length( nbElements );
1992 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1993 while ( i < nbElements && anIt->more() ) {
1994 const SMDS_MeshElement* anElem = anIt->next();
1995 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1996 aResult[i++] = anElem->GetID();
1999 aResult->length( i );
2001 return aResult._retn();
2004 //=============================================================================
2008 //=============================================================================
2010 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
2011 throw (SALOME::SALOME_Exception)
2013 Unexpect aCatch(SALOME_SalomeException);
2014 MESSAGE("SMESH_subMesh_i::GetNodesId");
2015 SMESH::long_array_var aResult = new SMESH::long_array();
2016 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2018 if ( aSMESHDS_Mesh == NULL )
2019 return aResult._retn();
2021 long nbNodes = NbNodes();
2022 aResult->length( nbNodes );
2023 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
2024 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
2025 aResult[i] = anIt->next()->GetID();
2027 return aResult._retn();
2030 //=============================================================================
2034 //=============================================================================
2036 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
2037 throw (SALOME::SALOME_Exception)
2039 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
2043 //=============================================================================
2045 * Returns ID of elements for given submesh
2047 //=============================================================================
2048 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
2049 throw (SALOME::SALOME_Exception)
2051 SMESH::long_array_var aResult = new SMESH::long_array();
2053 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2054 if(!SM) return aResult._retn();
2056 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2057 if(!SDSM) return aResult._retn();
2059 aResult->length(SDSM->NbElements());
2061 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2063 while ( eIt->more() ) {
2064 aResult[i++] = eIt->next()->GetID();
2067 return aResult._retn();
2071 //=============================================================================
2073 * Returns ID of nodes for given submesh
2074 * If param all==true - returns all nodes, else -
2075 * returns only nodes on shapes.
2077 //=============================================================================
2078 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all)
2079 throw (SALOME::SALOME_Exception)
2081 SMESH::long_array_var aResult = new SMESH::long_array();
2083 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2084 if(!SM) return aResult._retn();
2086 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2087 if(!SDSM) return aResult._retn();
2090 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
2091 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
2092 while ( nIt->more() ) {
2093 const SMDS_MeshNode* elem = nIt->next();
2094 theElems.insert( elem->GetID() );
2097 else { // all nodes of submesh elements
2098 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2099 while ( eIt->more() ) {
2100 const SMDS_MeshElement* anElem = eIt->next();
2101 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
2102 while ( nIt->more() ) {
2103 const SMDS_MeshElement* elem = nIt->next();
2104 theElems.insert( elem->GetID() );
2109 aResult->length(theElems.size());
2110 set<int>::iterator itElem;
2112 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
2113 aResult[i++] = *itElem;
2115 return aResult._retn();
2119 //=============================================================================
2121 * Returns type of elements for given submesh
2123 //=============================================================================
2124 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
2125 throw (SALOME::SALOME_Exception)
2127 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
2128 if(!SM) return SMESH::ALL;
2130 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
2131 if(!SDSM) return SMESH::ALL;
2133 if(SDSM->NbElements()==0)
2134 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
2136 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
2137 const SMDS_MeshElement* anElem = eIt->next();
2138 return ( SMESH::ElementType ) anElem->GetType();
2142 //=============================================================================
2146 //=============================================================================
2148 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
2150 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
2152 MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
2157 //=============================================================================
2159 * Get XYZ coordinates of node as list of double
2160 * If there is not node for given ID - returns empty list
2162 //=============================================================================
2164 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
2166 SMESH::double_array_var aResult = new SMESH::double_array();
2167 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2168 if ( aSMESHDS_Mesh == NULL )
2169 return aResult._retn();
2172 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2174 return aResult._retn();
2178 aResult[0] = aNode->X();
2179 aResult[1] = aNode->Y();
2180 aResult[2] = aNode->Z();
2181 return aResult._retn();
2185 //=============================================================================
2187 * For given node returns list of IDs of inverse elements
2188 * If there is not node for given ID - returns empty list
2190 //=============================================================================
2192 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
2194 SMESH::long_array_var aResult = new SMESH::long_array();
2195 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2196 if ( aSMESHDS_Mesh == NULL )
2197 return aResult._retn();
2200 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2202 return aResult._retn();
2204 // find inverse elements
2205 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
2206 TColStd_SequenceOfInteger IDs;
2207 while(eIt->more()) {
2208 const SMDS_MeshElement* elem = eIt->next();
2209 IDs.Append(elem->GetID());
2211 if(IDs.Length()>0) {
2212 aResult->length(IDs.Length());
2214 for(; i<=IDs.Length(); i++) {
2215 aResult[i-1] = IDs.Value(i);
2218 return aResult._retn();
2221 //=============================================================================
2223 * \brief Return position of a node on shape
2225 //=============================================================================
2227 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
2229 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
2230 aNodePosition->shapeID = 0;
2231 aNodePosition->shapeType = GEOM::SHAPE;
2233 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
2234 if ( !mesh ) return aNodePosition;
2236 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
2238 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
2240 aNodePosition->shapeID = pos->GetShapeId();
2241 switch ( pos->GetTypeOfPosition() ) {
2243 aNodePosition->shapeType = GEOM::EDGE;
2244 aNodePosition->params.length(1);
2245 aNodePosition->params[0] =
2246 static_cast<SMDS_EdgePosition*>( pos.get() )->GetUParameter();
2249 aNodePosition->shapeType = GEOM::FACE;
2250 aNodePosition->params.length(2);
2251 aNodePosition->params[0] =
2252 static_cast<SMDS_FacePosition*>( pos.get() )->GetUParameter();
2253 aNodePosition->params[1] =
2254 static_cast<SMDS_FacePosition*>( pos.get() )->GetVParameter();
2256 case SMDS_TOP_VERTEX:
2257 aNodePosition->shapeType = GEOM::VERTEX;
2259 case SMDS_TOP_3DSPACE:
2260 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
2261 aNodePosition->shapeType = GEOM::SOLID;
2262 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
2263 aNodePosition->shapeType = GEOM::SHELL;
2269 return aNodePosition;
2272 //=============================================================================
2274 * If given element is node returns IDs of shape from position
2275 * If there is not node for given ID - returns -1
2277 //=============================================================================
2279 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
2281 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2282 if ( aSMESHDS_Mesh == NULL )
2286 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
2288 SMDS_PositionPtr pos = aNode->GetPosition();
2292 return pos->GetShapeId();
2299 //=============================================================================
2301 * For given element returns ID of result shape after
2302 * ::FindShape() from SMESH_MeshEditor
2303 * If there is not element for given ID - returns -1
2305 //=============================================================================
2307 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
2309 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2310 if ( aSMESHDS_Mesh == NULL )
2313 // try to find element
2314 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2318 //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
2319 ::SMESH_MeshEditor aMeshEditor(_impl);
2320 int index = aMeshEditor.FindShape( elem );
2328 //=============================================================================
2330 * Returns number of nodes for given element
2331 * If there is not element for given ID - returns -1
2333 //=============================================================================
2335 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
2337 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2338 if ( aSMESHDS_Mesh == NULL ) return -1;
2339 // try to find element
2340 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2341 if(!elem) return -1;
2342 return elem->NbNodes();
2346 //=============================================================================
2348 * Returns ID of node by given index for given element
2349 * If there is not element for given ID - returns -1
2350 * If there is not node for given index - returns -2
2352 //=============================================================================
2354 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
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 if( index>=elem->NbNodes() || index<0 ) return -1;
2361 return elem->GetNode(index)->GetID();
2364 //=============================================================================
2366 * Returns IDs of nodes of given element
2368 //=============================================================================
2370 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
2372 SMESH::long_array_var aResult = new SMESH::long_array();
2373 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
2375 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
2377 aResult->length( elem->NbNodes() );
2378 for ( int i = 0; i < elem->NbNodes(); ++i )
2379 aResult[ i ] = elem->GetNode( i )->GetID();
2382 return aResult._retn();
2385 //=============================================================================
2387 * Returns true if given node is medium node
2388 * in given quadratic element
2390 //=============================================================================
2392 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
2394 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2395 if ( aSMESHDS_Mesh == NULL ) return false;
2397 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2398 if(!aNode) return false;
2399 // try to find element
2400 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
2401 if(!elem) return false;
2403 return elem->IsMediumNode(aNode);
2407 //=============================================================================
2409 * Returns true if given node is medium node
2410 * in one of quadratic elements
2412 //=============================================================================
2414 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
2415 SMESH::ElementType theElemType)
2417 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2418 if ( aSMESHDS_Mesh == NULL ) return false;
2421 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
2422 if(!aNode) return false;
2424 SMESH_MesherHelper aHelper( *(_impl) );
2426 SMDSAbs_ElementType aType;
2427 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
2428 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
2429 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
2430 else aType = SMDSAbs_All;
2432 return aHelper.IsMedium(aNode,aType);
2436 //=============================================================================
2438 * Returns number of edges for given element
2440 //=============================================================================
2442 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
2444 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2445 if ( aSMESHDS_Mesh == NULL ) return -1;
2446 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2447 if(!elem) return -1;
2448 return elem->NbEdges();
2452 //=============================================================================
2454 * Returns number of faces for given element
2456 //=============================================================================
2458 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
2460 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2461 if ( aSMESHDS_Mesh == NULL ) return -1;
2462 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2463 if(!elem) return -1;
2464 return elem->NbFaces();
2468 //=============================================================================
2470 * Returns true if given element is polygon
2472 //=============================================================================
2474 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
2476 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2477 if ( aSMESHDS_Mesh == NULL ) return false;
2478 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2479 if(!elem) return false;
2480 return elem->IsPoly();
2484 //=============================================================================
2486 * Returns true if given element is quadratic
2488 //=============================================================================
2490 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
2492 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2493 if ( aSMESHDS_Mesh == NULL ) return false;
2494 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2495 if(!elem) return false;
2496 return elem->IsQuadratic();
2500 //=============================================================================
2502 * Returns bary center for given element
2504 //=============================================================================
2506 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
2508 SMESH::double_array_var aResult = new SMESH::double_array();
2509 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
2510 if ( aSMESHDS_Mesh == NULL )
2511 return aResult._retn();
2513 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
2515 return aResult._retn();
2517 if(elem->GetType()==SMDSAbs_Volume) {
2518 SMDS_VolumeTool aTool;
2519 if(aTool.Set(elem)) {
2521 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
2526 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
2528 double x=0., y=0., z=0.;
2529 for(; anIt->more(); ) {
2531 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
2545 return aResult._retn();
2549 //=============================================================================
2551 * Create and publish group servants if any groups were imported or created anyhow
2553 //=============================================================================
2555 void SMESH_Mesh_i::CreateGroupServants()
2557 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
2559 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
2560 while ( groupIt->more() )
2562 ::SMESH_Group* group = groupIt->next();
2563 int anId = group->GetGroupDS()->GetID();
2565 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
2566 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2569 SMESH_GroupBase_i* aGroupImpl;
2571 if ( SMESHDS_GroupOnGeom* groupOnGeom =
2572 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
2574 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2575 shape = groupOnGeom->GetShape();
2578 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2581 // To ensure correct mapping of servant and correct reference counting in GenericObj_i
2582 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
2583 aGroupImpl->Register();
2585 SMESH::SMESH_GroupBase_var groupVar =
2586 SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
2587 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
2589 // register CORBA object for persistence
2590 int nextId = _gen_i->RegisterObject( groupVar );
2591 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
2593 // publishing of the groups in the study
2594 if ( !aStudy->_is_nil() ) {
2595 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
2596 _gen_i->PublishGroup( aStudy, _this(), groupVar, shapeVar, groupVar->GetName());
2601 //=============================================================================
2603 * \brief Return groups cantained in _mapGroups by their IDs
2605 //=============================================================================
2607 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
2609 int nbGroups = groupIDs.size();
2610 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
2611 aList->length( nbGroups );
2613 list<int>::const_iterator ids = groupIDs.begin();
2614 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
2616 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
2617 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
2618 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
2620 aList->length( nbGroups );
2621 return aList._retn();
2624 //=============================================================================
2626 * \brief Return information about imported file
2628 //=============================================================================
2630 SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
2632 SALOME_MED::MedFileInfo_var res( myFileInfo );
2633 if ( !res.operator->() ) {
2634 res = new SALOME_MED::MedFileInfo;
2636 res->fileSize = res->major = res->minor = res->release = -1;