1 // Copyright (C) 2007-2013 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 // File : SMESH_Mesh_i.cxx
23 // Author : Paul RASCLE, EDF
26 #include "SMESH_Mesh_i.hxx"
28 #include "DriverMED_R_SMESHDS_Mesh.h"
29 #include "DriverMED_W_SMESHDS_Mesh.h"
30 #include "MED_Factory.hxx"
31 #include "SMDS_EdgePosition.hxx"
32 #include "SMDS_ElemIterator.hxx"
33 #include "SMDS_FacePosition.hxx"
34 #include "SMDS_IteratorOnIterators.hxx"
35 #include "SMDS_MeshGroup.hxx"
36 #include "SMDS_SetIterator.hxx"
37 #include "SMDS_VolumeTool.hxx"
38 #include "SMESHDS_Command.hxx"
39 #include "SMESHDS_CommandType.hxx"
40 #include "SMESHDS_Group.hxx"
41 #include "SMESHDS_GroupOnGeom.hxx"
42 #include "SMESH_Controls.hxx"
43 #include "SMESH_Filter_i.hxx"
44 #include "SMESH_Gen_i.hxx"
45 #include "SMESH_Group.hxx"
46 #include "SMESH_Group_i.hxx"
47 #include "SMESH_MeshAlgos.hxx"
48 #include "SMESH_MeshEditor.hxx"
49 #include "SMESH_MeshEditor_i.hxx"
50 #include "SMESH_MeshPartDS.hxx"
51 #include "SMESH_MesherHelper.hxx"
52 #include "SMESH_PreMeshInfo.hxx"
53 #include "SMESH_PythonDump.hxx"
54 #include "SMESH_subMesh_i.hxx"
57 #include <SALOMEDS_Attributes_wrap.hxx>
58 #include <SALOMEDS_wrap.hxx>
59 #include <SALOME_NamingService.hxx>
60 #include <Utils_ExceptHandlers.hxx>
61 #include <Utils_SINGLETON.hxx>
62 #include <utilities.h>
64 #include <GEOMImpl_Types.hxx>
65 #include <GEOM_wrap.hxx>
68 #include <BRep_Builder.hxx>
69 #include <OSD_Directory.hxx>
70 #include <OSD_File.hxx>
71 #include <OSD_Path.hxx>
72 #include <OSD_Protection.hxx>
73 #include <Standard_OutOfMemory.hxx>
74 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
75 #include <TColStd_MapOfInteger.hxx>
76 #include <TColStd_SequenceOfInteger.hxx>
77 #include <TCollection_AsciiString.hxx>
79 #include <TopExp_Explorer.hxx>
80 #include <TopTools_MapIteratorOfMapOfShape.hxx>
81 #include <TopTools_MapOfShape.hxx>
82 #include <TopoDS_Compound.hxx>
84 #include "SMESH_TryCatch.hxx" // include after OCCT headers!
95 static int MYDEBUG = 0;
97 static int MYDEBUG = 0;
101 using SMESH::TPythonDump;
103 int SMESH_Mesh_i::_idGenerator = 0;
105 //=============================================================================
109 //=============================================================================
111 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
113 CORBA::Long studyId )
114 : SALOME::GenericObj_i( thePOA )
116 MESSAGE("SMESH_Mesh_i");
119 _id = _idGenerator++;
122 _previewEditor = NULL;
126 //=============================================================================
130 //=============================================================================
132 SMESH_Mesh_i::~SMESH_Mesh_i()
134 MESSAGE("~SMESH_Mesh_i");
137 map<int, SMESH::SMESH_GroupBase_ptr>::iterator itGr;
138 for (itGr = _mapGroups.begin(); itGr != _mapGroups.end(); itGr++)
139 if (SMESH_GroupBase_i* aGroup = SMESH::DownCast<SMESH_GroupBase_i*>(itGr->second))
141 aGroup->UnRegister();
142 SMESH::SMESH_GroupBase_var( itGr->second );
147 map<int, SMESH::SMESH_subMesh_ptr>::iterator itSM;
148 for ( itSM = _mapSubMeshIor.begin(); itSM != _mapSubMeshIor.end(); itSM++ )
149 if ( SMESH_subMesh_i* aSubMesh = SMESH::DownCast<SMESH_subMesh_i*>( itSM->second ))
151 aSubMesh->UnRegister();
152 SMESH::SMESH_subMesh_var( itSM->second );
154 _mapSubMeshIor.clear();
156 // destroy hypotheses. _mapHypo contains all hyps ever been assigned
157 map<int, SMESH::SMESH_Hypothesis_ptr>::iterator itH;
158 for ( itH = _mapHypo.begin(); itH != _mapHypo.end(); itH++ ) {
159 if ( SMESH_Hypothesis_i* hyp_i = SMESH::DownCast<SMESH_Hypothesis_i*>( itH->second ))
160 if ( SMESH_Hypothesis * smHyp = _impl->GetHypothesis( itH->first ))
161 if ( _impl->GetMeshDS()->IsUsedHypothesis( smHyp ))
164 SMESH::SMESH_Hypothesis_var( itH->second ); // decref CORBA object
168 delete _editor; _editor = NULL;
169 delete _previewEditor; _previewEditor = NULL;
170 delete _impl; _impl = NULL;
171 delete _preMeshInfo; _preMeshInfo = NULL;
174 //=============================================================================
178 * Associates <this> mesh with <theShape> and puts a reference
179 * to <theShape> into the current study;
180 * the previous shape is substituted by the new one.
182 //=============================================================================
184 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
185 throw (SALOME::SALOME_Exception)
187 Unexpect aCatch(SALOME_SalomeException);
189 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
191 catch(SALOME_Exception & S_ex) {
192 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
194 // to track changes of GEOM groups
195 SMESH::SMESH_Mesh_var mesh = _this();
196 addGeomGroupData( theShapeObject, mesh );
199 //================================================================================
201 * \brief return true if mesh has a shape to build a shape on
203 //================================================================================
205 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
206 throw (SALOME::SALOME_Exception)
208 Unexpect aCatch(SALOME_SalomeException);
211 res = _impl->HasShapeToMesh();
213 catch(SALOME_Exception & S_ex) {
214 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
219 //=======================================================================
220 //function : GetShapeToMesh
222 //=======================================================================
224 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
225 throw (SALOME::SALOME_Exception)
227 Unexpect aCatch(SALOME_SalomeException);
228 GEOM::GEOM_Object_var aShapeObj;
230 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
232 aShapeObj = _gen_i->ShapeToGeomObject( S );
234 catch(SALOME_Exception & S_ex) {
235 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
237 return aShapeObj._retn();
240 //================================================================================
242 * \brief Return false if the mesh is not yet fully loaded from the study file
244 //================================================================================
246 CORBA::Boolean SMESH_Mesh_i::IsLoaded() throw (SALOME::SALOME_Exception)
248 Unexpect aCatch(SALOME_SalomeException);
249 return !_preMeshInfo;
252 //================================================================================
254 * \brief Load full mesh data from the study file
256 //================================================================================
258 void SMESH_Mesh_i::Load() throw (SALOME::SALOME_Exception)
260 Unexpect aCatch(SALOME_SalomeException);
262 _preMeshInfo->FullLoadFromFile();
265 //================================================================================
267 * \brief Remove all nodes and elements
269 //================================================================================
271 void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
273 Unexpect aCatch(SALOME_SalomeException);
275 _preMeshInfo->ForgetAllData();
279 CheckGeomGroupModif(); // issue 20145
281 catch(SALOME_Exception & S_ex) {
282 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
284 _impl->GetMeshDS()->Modified();
286 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".Clear()";
289 //================================================================================
291 * \brief Remove all nodes and elements for indicated shape
293 //================================================================================
295 void SMESH_Mesh_i::ClearSubMesh(CORBA::Long ShapeID)
296 throw (SALOME::SALOME_Exception)
298 Unexpect aCatch(SALOME_SalomeException);
300 _preMeshInfo->FullLoadFromFile();
303 _impl->ClearSubMesh( ShapeID );
305 catch(SALOME_Exception & S_ex) {
306 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
308 _impl->GetMeshDS()->Modified();
310 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ClearSubMesh( " << ShapeID << " )";
313 //=============================================================================
315 * Convert enum Driver_Mesh::Status to SMESH::DriverMED_ReadStatus
317 //=============================================================================
319 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
321 SMESH::DriverMED_ReadStatus res;
324 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
325 res = SMESH::DRS_OK; break;
326 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
327 res = SMESH::DRS_EMPTY; break;
328 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
329 res = SMESH::DRS_WARN_RENUMBER; break;
330 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
331 res = SMESH::DRS_WARN_SKIP_ELEM; break;
332 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_DESCENDING:
333 res = SMESH::DRS_WARN_DESCENDING; break;
334 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
336 res = SMESH::DRS_FAIL; break;
341 //=============================================================================
343 * Convert ::SMESH_ComputeError to SMESH::ComputeError
345 //=============================================================================
347 static SMESH::ComputeError* ConvertComputeError( SMESH_ComputeErrorPtr errorPtr )
349 SMESH::ComputeError_var errVar = new SMESH::ComputeError();
350 errVar->subShapeID = -1;
351 errVar->hasBadMesh = false;
353 if ( !errorPtr || errorPtr->IsOK() )
355 errVar->code = SMESH::COMPERR_OK;
359 errVar->code = ConvertDriverMEDReadStatus( errorPtr->myName );
360 errVar->comment = errorPtr->myComment.c_str();
362 return errVar._retn();
365 //=============================================================================
369 * Imports mesh data from MED file
371 //=============================================================================
373 SMESH::DriverMED_ReadStatus
374 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
375 throw ( SALOME::SALOME_Exception )
377 Unexpect aCatch(SALOME_SalomeException);
380 status = _impl->MEDToMesh( theFileName, theMeshName );
382 catch( SALOME_Exception& S_ex ) {
383 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
386 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
389 CreateGroupServants();
391 int major, minor, release;
392 if( !MED::getMEDVersion( theFileName, major, minor, release ) )
393 major = minor = release = -1;
394 _medFileInfo = new SMESH::MedFileInfo();
395 _medFileInfo->fileName = theFileName;
396 _medFileInfo->fileSize = 0;
397 _medFileInfo->major = major;
398 _medFileInfo->minor = minor;
399 _medFileInfo->release = release;
402 if ( ::_stati64( theFileName, &d ) != -1 )
405 if ( ::stat64( theFileName, &d ) != -1 )
407 _medFileInfo->fileSize = d.st_size;
409 return ConvertDriverMEDReadStatus(status);
412 //================================================================================
414 * \brief Imports mesh data from the CGNS file
416 //================================================================================
418 SMESH::DriverMED_ReadStatus SMESH_Mesh_i::ImportCGNSFile( const char* theFileName,
419 const int theMeshIndex,
420 std::string& theMeshName )
421 throw ( SALOME::SALOME_Exception )
423 Unexpect aCatch(SALOME_SalomeException);
426 status = _impl->CGNSToMesh( theFileName, theMeshIndex, theMeshName );
428 catch( SALOME_Exception& S_ex ) {
429 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
432 THROW_SALOME_CORBA_EXCEPTION("ImportCGNSFile(): unknown exception", SALOME::BAD_PARAM);
435 CreateGroupServants();
437 return ConvertDriverMEDReadStatus(status);
440 //================================================================================
442 * \brief Return string representation of a MED file version comprising nbDigits
444 //================================================================================
446 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
448 string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
450 return CORBA::string_dup( ver.c_str() );
453 //=============================================================================
457 * Imports mesh data from MED file
459 //=============================================================================
461 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
462 throw ( SALOME::SALOME_Exception )
466 // Read mesh with name = <theMeshName> into SMESH_Mesh
467 _impl->UNVToMesh( theFileName );
469 CreateGroupServants();
471 SMESH_CATCH( SMESH::throwCorbaException );
476 //=============================================================================
480 * Imports mesh data from STL file
482 //=============================================================================
483 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
484 throw ( SALOME::SALOME_Exception )
488 // Read mesh with name = <theMeshName> into SMESH_Mesh
489 _impl->STLToMesh( theFileName );
491 SMESH_CATCH( SMESH::throwCorbaException );
496 //================================================================================
498 * \brief Function used in SMESH_CATCH by ImportGMFFile()
500 //================================================================================
504 SMESH_ComputeErrorPtr exceptionToComputeError(const char* excText)
506 return SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, excText );
510 //================================================================================
512 * \brief Imports data from a GMF file and returns an error description
514 //================================================================================
516 SMESH::ComputeError* SMESH_Mesh_i::ImportGMFFile( const char* theFileName,
517 bool theMakeRequiredGroups )
518 throw (SALOME::SALOME_Exception)
520 SMESH_ComputeErrorPtr error;
523 #define SMESH_CAUGHT error =
526 error = _impl->GMFToMesh( theFileName, theMakeRequiredGroups );
528 SMESH_CATCH( exceptionToComputeError );
532 CreateGroupServants();
534 return ConvertComputeError( error );
537 //=============================================================================
541 //=============================================================================
543 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
545 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
546 (SMESH_Hypothesis::Hypothesis_Status theStatus)
549 RETURNCASE( HYP_OK );
550 RETURNCASE( HYP_MISSING );
551 RETURNCASE( HYP_CONCURENT );
552 RETURNCASE( HYP_BAD_PARAMETER );
553 RETURNCASE( HYP_HIDDEN_ALGO );
554 RETURNCASE( HYP_HIDING_ALGO );
555 RETURNCASE( HYP_UNKNOWN_FATAL );
556 RETURNCASE( HYP_INCOMPATIBLE );
557 RETURNCASE( HYP_NOTCONFORM );
558 RETURNCASE( HYP_ALREADY_EXIST );
559 RETURNCASE( HYP_BAD_DIM );
560 RETURNCASE( HYP_BAD_SUBSHAPE );
561 RETURNCASE( HYP_BAD_GEOMETRY );
562 RETURNCASE( HYP_NEED_SHAPE );
565 return SMESH::HYP_UNKNOWN_FATAL;
568 //=============================================================================
572 * calls internal addHypothesis() and then adds a reference to <anHyp> under
573 * the SObject actually having a reference to <aSubShape>.
574 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
576 //=============================================================================
578 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
579 SMESH::SMESH_Hypothesis_ptr anHyp)
580 throw(SALOME::SALOME_Exception)
582 Unexpect aCatch(SALOME_SalomeException);
584 _preMeshInfo->ForgetOrLoad();
586 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
588 SMESH::SMESH_Mesh_var mesh( _this() );
589 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
591 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
592 _gen_i->AddHypothesisToShape( study, mesh, aSubShapeObject, anHyp );
594 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
596 // Update Python script
597 //if(_impl->HasShapeToMesh())
599 TPythonDump() << "status = " << mesh << ".AddHypothesis( "
600 << aSubShapeObject << ", " << anHyp << " )";
603 // TPythonDump() << "status = " << mesh << ".AddHypothesis( "<< anHyp << " )";
606 return ConvertHypothesisStatus(status);
609 //=============================================================================
613 //=============================================================================
615 SMESH_Hypothesis::Hypothesis_Status
616 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
617 SMESH::SMESH_Hypothesis_ptr anHyp)
619 if(MYDEBUG) MESSAGE("addHypothesis");
621 if (CORBA::is_nil( aSubShapeObject ) && HasShapeToMesh())
622 THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference",SALOME::BAD_PARAM);
624 if (CORBA::is_nil( anHyp ))
625 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",SALOME::BAD_PARAM);
627 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
630 TopoDS_Shape myLocSubShape;
631 //use PseudoShape in case if mesh has no shape
633 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
635 myLocSubShape = _impl->GetShapeToMesh();
637 const int hypId = anHyp->GetId();
638 status = _impl->AddHypothesis(myLocSubShape, hypId);
639 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
640 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( anHyp );
642 // assure there is a corresponding submesh
643 if ( !_impl->IsMainShape( myLocSubShape )) {
644 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
645 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
646 SMESH::SMESH_subMesh_var( createSubMesh( aSubShapeObject ));
650 catch(SALOME_Exception & S_ex)
652 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
657 //=============================================================================
661 //=============================================================================
663 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
664 SMESH::SMESH_Hypothesis_ptr anHyp)
665 throw(SALOME::SALOME_Exception)
667 Unexpect aCatch(SALOME_SalomeException);
669 _preMeshInfo->ForgetOrLoad();
671 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
672 SMESH::SMESH_Mesh_var mesh = _this();
674 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
676 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
677 _gen_i->RemoveHypothesisFromShape( study, mesh, aSubShapeObject, anHyp );
679 // Update Python script
680 if(_impl->HasShapeToMesh())
681 TPythonDump() << "status = " << mesh << ".RemoveHypothesis( "
682 << aSubShapeObject << ", " << anHyp << " )";
684 TPythonDump() << "status = " << mesh << ".RemoveHypothesis( "
687 return ConvertHypothesisStatus(status);
690 //=============================================================================
694 //=============================================================================
696 SMESH_Hypothesis::Hypothesis_Status
697 SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
698 SMESH::SMESH_Hypothesis_ptr anHyp)
700 if(MYDEBUG) MESSAGE("removeHypothesis()");
702 if (CORBA::is_nil( aSubShapeObject ) && HasShapeToMesh())
703 THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference", SALOME::BAD_PARAM);
705 if (CORBA::is_nil( anHyp ))
706 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference", SALOME::BAD_PARAM);
708 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
711 TopoDS_Shape myLocSubShape;
712 //use PseudoShape in case if mesh has no shape
713 if( _impl->HasShapeToMesh() )
714 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject );
716 myLocSubShape = _impl->GetShapeToMesh();
718 const int hypId = anHyp->GetId();
719 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
720 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
722 // _mapHypo.erase( hypId ); EAP: hyp can be used on many sub-shapes
726 catch(SALOME_Exception & S_ex)
728 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
733 //=============================================================================
737 //=============================================================================
739 SMESH::ListOfHypothesis *
740 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
741 throw(SALOME::SALOME_Exception)
743 Unexpect aCatch(SALOME_SalomeException);
744 if (MYDEBUG) MESSAGE("GetHypothesisList");
745 if (_impl->HasShapeToMesh() && CORBA::is_nil(aSubShapeObject))
746 THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference", SALOME::BAD_PARAM);
748 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
751 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
752 if ( myLocSubShape.IsNull() && !_impl->HasShapeToMesh() )
753 myLocSubShape = _impl->GetShapeToMesh();
754 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
755 int i = 0, n = aLocalList.size();
758 list<const SMESHDS_Hypothesis*>::const_iterator aHyp = aLocalList.begin();
759 std::map<int, SMESH::SMESH_Hypothesis_ptr>::iterator id_hypptr;
760 for ( ; i < n && aHyp != aLocalList.end(); aHyp++ )
762 id_hypptr = _mapHypo.find( (*aHyp)->GetID() );
763 if ( id_hypptr != _mapHypo.end() )
764 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( id_hypptr->second );
768 catch(SALOME_Exception & S_ex) {
769 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
772 return aList._retn();
775 SMESH::submesh_array* SMESH_Mesh_i::GetSubMeshes() throw (SALOME::SALOME_Exception)
777 Unexpect aCatch(SALOME_SalomeException);
778 if (MYDEBUG) MESSAGE("GetSubMeshes");
780 SMESH::submesh_array_var aList = new SMESH::submesh_array();
783 TPythonDump aPythonDump;
784 if ( !_mapSubMeshIor.empty() )
788 aList->length( _mapSubMeshIor.size() );
790 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.begin();
791 for ( ; it != _mapSubMeshIor.end(); it++ ) {
792 if ( CORBA::is_nil( it->second )) continue;
793 aList[i++] = SMESH::SMESH_subMesh::_duplicate( it->second );
795 if (i > 1) aPythonDump << ", ";
796 aPythonDump << it->second;
800 catch(SALOME_Exception & S_ex) {
801 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
804 // Update Python script
805 if ( !_mapSubMeshIor.empty() )
806 aPythonDump << " ] = " << SMESH::SMESH_Mesh_var( _this() ) << ".GetSubMeshes()";
808 return aList._retn();
811 //=============================================================================
815 //=============================================================================
817 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
818 const char* theName )
819 throw(SALOME::SALOME_Exception)
821 Unexpect aCatch(SALOME_SalomeException);
822 if (CORBA::is_nil(aSubShapeObject))
823 THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference", SALOME::BAD_PARAM);
825 SMESH::SMESH_subMesh_var subMesh;
826 SMESH::SMESH_Mesh_var aMesh = _this();
828 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
830 //Get or Create the SMESH_subMesh object implementation
832 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
834 if ( !subMeshId && ! _impl->GetMeshDS()->IsGroupOfSubShapes( myLocSubShape ))
836 TopoDS_Iterator it( myLocSubShape );
838 THROW_SALOME_CORBA_EXCEPTION("not sub-shape of the main shape", SALOME::BAD_PARAM);
840 subMesh = getSubMesh( subMeshId );
842 // create a new subMesh object servant if there is none for the shape
843 if ( subMesh->_is_nil() )
844 subMesh = createSubMesh( aSubShapeObject );
845 if ( _gen_i->CanPublishInStudy( subMesh ))
847 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
848 SALOMEDS::SObject_wrap aSO =
849 _gen_i->PublishSubMesh( study, aMesh, subMesh, aSubShapeObject, theName );
850 if ( !aSO->_is_nil()) {
851 // Update Python script
852 TPythonDump() << aSO << " = " << aMesh << ".GetSubMesh( "
853 << aSubShapeObject << ", '" << theName << "' )";
857 catch(SALOME_Exception & S_ex) {
858 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
860 return subMesh._retn();
863 //=============================================================================
867 //=============================================================================
869 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
870 throw (SALOME::SALOME_Exception)
874 if ( theSubMesh->_is_nil() )
877 GEOM::GEOM_Object_var aSubShapeObject;
878 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
879 if ( !aStudy->_is_nil() ) {
880 // Remove submesh's SObject
881 SALOMEDS::SObject_wrap anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
882 if ( !anSO->_is_nil() ) {
883 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
884 SALOMEDS::SObject_wrap anObj, aRef;
885 if ( anSO->FindSubObject( aTag, anObj.inout() ) &&
886 anObj->ReferencedObject( aRef.inout() ))
888 CORBA::Object_var obj = aRef->GetObject();
889 aSubShapeObject = GEOM::GEOM_Object::_narrow( obj );
891 // if ( aSubShapeObject->_is_nil() ) // not published shape (IPAL13617)
892 // aSubShapeObject = theSubMesh->GetSubShape();
894 SALOMEDS::StudyBuilder_var builder = aStudy->NewBuilder();
895 builder->RemoveObjectWithChildren( anSO );
897 // Update Python script
898 TPythonDump() << SMESH::SMESH_Mesh_var( _this() ) << ".RemoveSubMesh( " << anSO << " )";
902 if ( removeSubMesh( theSubMesh, aSubShapeObject.in() ))
904 _preMeshInfo->ForgetOrLoad();
906 SMESH_CATCH( SMESH::throwCorbaException );
909 //=============================================================================
913 //=============================================================================
915 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
916 const char* theName )
917 throw(SALOME::SALOME_Exception)
919 Unexpect aCatch(SALOME_SalomeException);
921 _preMeshInfo->FullLoadFromFile();
923 SMESH::SMESH_Group_var aNewGroup =
924 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
926 if ( _gen_i->CanPublishInStudy( aNewGroup ) )
928 SMESH::SMESH_Mesh_var mesh = _this();
929 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
930 SALOMEDS::SObject_wrap aSO =
931 _gen_i->PublishGroup( study, mesh, aNewGroup, GEOM::GEOM_Object::_nil(), theName);
932 if ( !aSO->_is_nil())
933 // Update Python script
934 TPythonDump() << aSO << " = " << mesh << ".CreateGroup( "
935 << theElemType << ", '" << theName << "' )";
937 return aNewGroup._retn();
940 //=============================================================================
944 //=============================================================================
945 SMESH::SMESH_GroupOnGeom_ptr
946 SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
948 GEOM::GEOM_Object_ptr theGeomObj)
949 throw(SALOME::SALOME_Exception)
951 Unexpect aCatch(SALOME_SalomeException);
953 _preMeshInfo->FullLoadFromFile();
955 SMESH::SMESH_GroupOnGeom_var aNewGroup;
957 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
958 if ( !aShape.IsNull() )
961 SMESH::SMESH_GroupOnGeom::_narrow( createGroup( theElemType, theName, aShape ));
963 if ( _gen_i->CanPublishInStudy( aNewGroup ) )
965 SMESH::SMESH_Mesh_var mesh = _this();
966 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
967 SALOMEDS::SObject_wrap aSO =
968 _gen_i->PublishGroup( study, mesh, aNewGroup, theGeomObj, theName );
969 if ( !aSO->_is_nil())
970 TPythonDump() << aSO << " = " << mesh << ".CreateGroupFromGEOM( "
971 << theElemType << ", '" << theName << "', " << theGeomObj << " )";
975 return aNewGroup._retn();
978 //================================================================================
980 * \brief Creates a group whose contents is defined by filter
981 * \param theElemType - group type
982 * \param theName - group name
983 * \param theFilter - the filter
984 * \retval SMESH::SMESH_GroupOnFilter_ptr - group defined by filter
986 //================================================================================
988 SMESH::SMESH_GroupOnFilter_ptr
989 SMESH_Mesh_i::CreateGroupFromFilter(SMESH::ElementType theElemType,
991 SMESH::Filter_ptr theFilter )
992 throw (SALOME::SALOME_Exception)
994 Unexpect aCatch(SALOME_SalomeException);
996 _preMeshInfo->FullLoadFromFile();
998 if ( CORBA::is_nil( theFilter ))
999 THROW_SALOME_CORBA_EXCEPTION("NULL filter", SALOME::BAD_PARAM);
1001 SMESH_PredicatePtr predicate = SMESH_GroupOnFilter_i::GetPredicate( theFilter );
1003 THROW_SALOME_CORBA_EXCEPTION("Invalid filter", SALOME::BAD_PARAM);
1005 SMESH::SMESH_GroupOnFilter_var aNewGroup = SMESH::SMESH_GroupOnFilter::_narrow
1006 ( createGroup( theElemType, theName, TopoDS_Shape(), predicate ));
1009 if ( !aNewGroup->_is_nil() )
1010 aNewGroup->SetFilter( theFilter );
1012 if ( _gen_i->CanPublishInStudy( aNewGroup ) )
1014 SMESH::SMESH_Mesh_var mesh = _this();
1015 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1016 SALOMEDS::SObject_wrap aSO =
1017 _gen_i->PublishGroup( study, mesh, aNewGroup, GEOM::GEOM_Object::_nil(), theName );
1019 if ( !aSO->_is_nil())
1020 pd << aSO << " = " << mesh << ".CreateGroupFromFilter( "
1021 << theElemType << ", '" << theName << "', " << theFilter << " )";
1023 return aNewGroup._retn();
1026 //=============================================================================
1030 //=============================================================================
1032 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
1033 throw (SALOME::SALOME_Exception)
1035 if ( theGroup->_is_nil() )
1040 SMESH_GroupBase_i* aGroup = SMESH::DownCast<SMESH_GroupBase_i*>( theGroup );
1044 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
1045 if ( !aStudy->_is_nil() )
1047 SALOMEDS::SObject_wrap aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
1048 if ( !aGroupSO->_is_nil() )
1050 // Update Python script
1051 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".RemoveGroup( " << aGroupSO << " )";
1053 // Remove group's SObject
1054 SALOMEDS::StudyBuilder_var builder = aStudy->NewBuilder();
1055 builder->RemoveObjectWithChildren( aGroupSO );
1059 // Remove the group from SMESH data structures
1060 removeGroup( aGroup->GetLocalID() );
1062 SMESH_CATCH( SMESH::throwCorbaException );
1065 //=============================================================================
1067 * Remove group with its contents
1069 //=============================================================================
1071 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
1072 throw (SALOME::SALOME_Exception)
1076 _preMeshInfo->FullLoadFromFile();
1078 if ( theGroup->_is_nil() )
1082 SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( theGroup );
1083 SMDS_ElemIteratorPtr elemIt = GetElements( idSrc, theGroup->GetType() );
1084 while ( elemIt->more() )
1085 _impl->GetMeshDS()->RemoveElement( elemIt->next() );
1087 TPythonDump pyDump; // Supress dump from RemoveGroup()
1089 // Update Python script (theGroup must be alive for this)
1090 pyDump << SMESH::SMESH_Mesh_var(_this())
1091 << ".RemoveGroupWithContents( " << theGroup << " )";
1094 RemoveGroup( theGroup );
1096 SMESH_CATCH( SMESH::throwCorbaException );
1099 //================================================================================
1101 * \brief Get the list of groups existing in the mesh
1102 * \retval SMESH::ListOfGroups * - list of groups
1104 //================================================================================
1106 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
1108 Unexpect aCatch(SALOME_SalomeException);
1109 if (MYDEBUG) MESSAGE("GetGroups");
1111 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
1114 TPythonDump aPythonDump;
1115 if ( !_mapGroups.empty() )
1117 aPythonDump << "[ ";
1119 aList->length( _mapGroups.size() );
1121 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
1122 for ( ; it != _mapGroups.end(); it++ ) {
1123 if ( CORBA::is_nil( it->second )) continue;
1124 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
1126 if (i > 1) aPythonDump << ", ";
1127 aPythonDump << it->second;
1131 catch(SALOME_Exception & S_ex) {
1132 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1134 aPythonDump << " ] = " << SMESH::SMESH_Mesh_var(_this()) << ".GetGroups()";
1136 return aList._retn();
1139 //=============================================================================
1141 * Get number of groups existing in the mesh
1143 //=============================================================================
1145 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
1147 Unexpect aCatch(SALOME_SalomeException);
1148 return _mapGroups.size();
1151 //=============================================================================
1153 * New group including all mesh elements present in initial groups is created.
1155 //=============================================================================
1157 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1158 SMESH::SMESH_GroupBase_ptr theGroup2,
1159 const char* theName )
1160 throw (SALOME::SALOME_Exception)
1162 SMESH::SMESH_Group_var aResGrp;
1166 _preMeshInfo->FullLoadFromFile();
1168 if ( theGroup1->_is_nil() || theGroup2->_is_nil() )
1169 THROW_SALOME_CORBA_EXCEPTION("UnionGroups(): NULL Group",
1171 if ( theGroup1->GetType() != theGroup2->GetType() )
1172 THROW_SALOME_CORBA_EXCEPTION("UnionGroups(): different group types",
1177 aResGrp = CreateGroup( theGroup1->GetType(), theName );
1178 if ( aResGrp->_is_nil() )
1179 return SMESH::SMESH_Group::_nil();
1181 aResGrp->AddFrom( theGroup1 );
1182 aResGrp->AddFrom( theGroup2 );
1184 // Update Python script
1185 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var(_this())
1186 << ".UnionGroups( " << theGroup1 << ", " << theGroup2 << ", '" << theName << "' )";
1188 SMESH_CATCH( SMESH::throwCorbaException );
1190 return aResGrp._retn();
1193 //=============================================================================
1195 * \brief New group including all mesh elements present in initial groups is created.
1196 * \param theGroups list of groups
1197 * \param theName name of group to be created
1198 * \return pointer to the new group
1200 //=============================================================================
1202 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionListOfGroups(const SMESH::ListOfGroups& theGroups,
1203 const char* theName )
1204 throw (SALOME::SALOME_Exception)
1206 SMESH::SMESH_Group_var aResGrp;
1209 _preMeshInfo->FullLoadFromFile();
1212 return SMESH::SMESH_Group::_nil();
1217 SMESH::ElementType aType = SMESH::ALL;
1218 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1220 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1221 if ( CORBA::is_nil( aGrp ) )
1223 if ( aType == SMESH::ALL )
1224 aType = aGrp->GetType();
1225 else if ( aType != aGrp->GetType() )
1226 THROW_SALOME_CORBA_EXCEPTION("UnionListOfGroups(): different group types",
1229 if ( aType == SMESH::ALL )
1230 return SMESH::SMESH_Group::_nil();
1235 aResGrp = CreateGroup( aType, theName );
1236 if ( aResGrp->_is_nil() )
1237 return SMESH::SMESH_Group::_nil();
1239 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var(_this()) << ".UnionListOfGroups([ ";
1240 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1242 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1243 if ( !CORBA::is_nil( aGrp ) )
1245 aResGrp->AddFrom( aGrp );
1246 if ( g > 0 ) pyDump << ", ";
1250 pyDump << " ], '" << theName << "' )";
1252 SMESH_CATCH( SMESH::throwCorbaException );
1254 return aResGrp._retn();
1257 //=============================================================================
1259 * New group is created. All mesh elements that are
1260 * present in both initial groups are added to the new one.
1262 //=============================================================================
1264 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1265 SMESH::SMESH_GroupBase_ptr theGroup2,
1266 const char* theName )
1267 throw (SALOME::SALOME_Exception)
1269 SMESH::SMESH_Group_var aResGrp;
1274 _preMeshInfo->FullLoadFromFile();
1276 if ( theGroup1->_is_nil() || theGroup2->_is_nil() )
1277 THROW_SALOME_CORBA_EXCEPTION("IntersectGroups(): NULL Group",
1279 if ( theGroup1->GetType() != theGroup2->GetType() )
1280 THROW_SALOME_CORBA_EXCEPTION("IntersectGroups(): different group types",
1284 // Create Intersection
1285 aResGrp = CreateGroup( theGroup1->GetType(), theName );
1286 if ( aResGrp->_is_nil() )
1287 return aResGrp._retn();
1289 SMESHDS_GroupBase* groupDS1 = 0;
1290 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup1 ))
1291 groupDS1 = grp_i->GetGroupDS();
1293 SMESHDS_GroupBase* groupDS2 = 0;
1294 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup2 ))
1295 groupDS2 = grp_i->GetGroupDS();
1297 SMESHDS_Group* resGroupDS = 0;
1298 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aResGrp ))
1299 resGroupDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() );
1301 if ( groupDS1 && groupDS2 && resGroupDS && !groupDS2->IsEmpty() )
1303 SMDS_ElemIteratorPtr elemIt1 = groupDS1->GetElements();
1304 while ( elemIt1->more() )
1306 const SMDS_MeshElement* e = elemIt1->next();
1307 if ( groupDS2->Contains( e ))
1308 resGroupDS->SMDSGroup().Add( e );
1311 // Update Python script
1312 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var(_this()) << ".IntersectGroups( "
1313 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
1315 SMESH_CATCH( SMESH::throwCorbaException );
1317 return aResGrp._retn();
1320 //=============================================================================
1322 \brief Intersect list of groups. New group is created. All mesh elements that
1323 are present in all initial groups simultaneously are added to the new one.
1324 \param theGroups list of groups
1325 \param theName name of group to be created
1326 \return pointer on the group
1328 //=============================================================================
1329 SMESH::SMESH_Group_ptr
1330 SMESH_Mesh_i::IntersectListOfGroups(const SMESH::ListOfGroups& theGroups,
1331 const char* theName )
1332 throw (SALOME::SALOME_Exception)
1334 SMESH::SMESH_Group_var aResGrp;
1339 _preMeshInfo->FullLoadFromFile();
1342 return SMESH::SMESH_Group::_nil();
1344 // check types and get SMESHDS_GroupBase's
1345 SMESH::ElementType aType = SMESH::ALL;
1346 vector< SMESHDS_GroupBase* > groupVec;
1347 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1349 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1350 if ( CORBA::is_nil( aGrp ) )
1352 if ( aType == SMESH::ALL )
1353 aType = aGrp->GetType();
1354 else if ( aType != aGrp->GetType() )
1355 THROW_SALOME_CORBA_EXCEPTION("IntersectListOfGroups(): different group types",
1358 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aGrp ))
1359 if ( SMESHDS_GroupBase* grpDS = grp_i->GetGroupDS() )
1361 if ( grpDS->IsEmpty() )
1366 groupVec.push_back( grpDS );
1369 if ( aType == SMESH::ALL ) // all groups are nil
1370 return SMESH::SMESH_Group::_nil();
1375 aResGrp = CreateGroup( aType, theName );
1377 SMESHDS_Group* resGroupDS = 0;
1378 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aResGrp ))
1379 resGroupDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() );
1380 if ( !resGroupDS || groupVec.empty() )
1381 return aResGrp._retn();
1384 size_t i, nb = groupVec.size();
1385 SMDS_ElemIteratorPtr elemIt1 = groupVec[0]->GetElements();
1386 while ( elemIt1->more() )
1388 const SMDS_MeshElement* e = elemIt1->next();
1390 for ( i = 1; ( i < nb && inAll ); ++i )
1391 inAll = groupVec[i]->Contains( e );
1394 resGroupDS->SMDSGroup().Add( e );
1397 // Update Python script
1398 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var( _this() )
1399 << ".IntersectListOfGroups( " << theGroups << ", '" << theName << "' )";
1401 SMESH_CATCH( SMESH::throwCorbaException );
1403 return aResGrp._retn();
1406 //=============================================================================
1408 * New group is created. All mesh elements that are present in
1409 * a main group but is not present in a tool group are added to the new one
1411 //=============================================================================
1413 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1414 SMESH::SMESH_GroupBase_ptr theGroup2,
1415 const char* theName )
1416 throw (SALOME::SALOME_Exception)
1418 SMESH::SMESH_Group_var aResGrp;
1423 _preMeshInfo->FullLoadFromFile();
1425 if ( theGroup1->_is_nil() || theGroup2->_is_nil() )
1426 THROW_SALOME_CORBA_EXCEPTION("CutGroups(): NULL Group",
1428 if ( theGroup1->GetType() != theGroup2->GetType() )
1429 THROW_SALOME_CORBA_EXCEPTION("CutGroups(): different group types",
1433 aResGrp = CreateGroup( theGroup1->GetType(), theName );
1434 if ( aResGrp->_is_nil() )
1435 return aResGrp._retn();
1437 SMESHDS_GroupBase* groupDS1 = 0;
1438 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup1 ))
1439 groupDS1 = grp_i->GetGroupDS();
1441 SMESHDS_GroupBase* groupDS2 = 0;
1442 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup2 ))
1443 groupDS2 = grp_i->GetGroupDS();
1445 SMESHDS_Group* resGroupDS = 0;
1446 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aResGrp ))
1447 resGroupDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() );
1449 if ( groupDS1 && groupDS2 && resGroupDS )
1451 SMDS_ElemIteratorPtr elemIt1 = groupDS1->GetElements();
1452 while ( elemIt1->more() )
1454 const SMDS_MeshElement* e = elemIt1->next();
1455 if ( !groupDS2->Contains( e ))
1456 resGroupDS->SMDSGroup().Add( e );
1459 // Update Python script
1460 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var(_this()) << ".CutGroups( "
1461 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
1463 SMESH_CATCH( SMESH::throwCorbaException );
1465 return aResGrp._retn();
1468 //=============================================================================
1470 \brief Cut lists of groups. New group is created. All mesh elements that are
1471 present in main groups but do not present in tool groups are added to the new one
1472 \param theMainGroups list of main groups
1473 \param theToolGroups list of tool groups
1474 \param theName name of group to be created
1475 \return pointer on the group
1477 //=============================================================================
1478 SMESH::SMESH_Group_ptr
1479 SMESH_Mesh_i::CutListOfGroups(const SMESH::ListOfGroups& theMainGroups,
1480 const SMESH::ListOfGroups& theToolGroups,
1481 const char* theName )
1482 throw (SALOME::SALOME_Exception)
1484 SMESH::SMESH_Group_var aResGrp;
1489 _preMeshInfo->FullLoadFromFile();
1492 return SMESH::SMESH_Group::_nil();
1494 // check types and get SMESHDS_GroupBase's
1495 SMESH::ElementType aType = SMESH::ALL;
1496 vector< SMESHDS_GroupBase* > toolGroupVec;
1497 vector< SMDS_ElemIteratorPtr > mainIterVec;
1499 for ( int g = 0, n = theMainGroups.length(); g < n; g++ )
1501 SMESH::SMESH_GroupBase_var aGrp = theMainGroups[ g ];
1502 if ( CORBA::is_nil( aGrp ) )
1504 if ( aType == SMESH::ALL )
1505 aType = aGrp->GetType();
1506 else if ( aType != aGrp->GetType() )
1507 THROW_SALOME_CORBA_EXCEPTION("UnionListOfGroups(): different group types",
1509 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aGrp ))
1510 if ( SMESHDS_GroupBase* grpDS = grp_i->GetGroupDS() )
1511 if ( !grpDS->IsEmpty() )
1512 mainIterVec.push_back( grpDS->GetElements() );
1514 if ( aType == SMESH::ALL ) // all main groups are nil
1515 return SMESH::SMESH_Group::_nil();
1516 if ( mainIterVec.empty() ) // all main groups are empty
1517 return aResGrp._retn();
1519 for ( int g = 0, n = theToolGroups.length(); g < n; g++ )
1521 SMESH::SMESH_GroupBase_var aGrp = theToolGroups[ g ];
1522 if ( CORBA::is_nil( aGrp ) )
1524 if ( aType != aGrp->GetType() )
1525 THROW_SALOME_CORBA_EXCEPTION("UnionListOfGroups(): different group types",
1527 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aGrp ))
1528 if ( SMESHDS_GroupBase* grpDS = grp_i->GetGroupDS() )
1529 toolGroupVec.push_back( grpDS );
1535 aResGrp = CreateGroup( aType, theName );
1537 SMESHDS_Group* resGroupDS = 0;
1538 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aResGrp ))
1539 resGroupDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() );
1541 return aResGrp._retn();
1544 size_t i, nb = toolGroupVec.size();
1545 SMDS_ElemIteratorPtr mainElemIt
1546 ( new SMDS_IteratorOnIterators
1547 < const SMDS_MeshElement*, vector< SMDS_ElemIteratorPtr > >( mainIterVec ));
1548 while ( mainElemIt->more() )
1550 const SMDS_MeshElement* e = mainElemIt->next();
1552 for ( i = 0; ( i < nb && !isIn ); ++i )
1553 isIn = toolGroupVec[i]->Contains( e );
1556 resGroupDS->SMDSGroup().Add( e );
1559 // Update Python script
1560 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var( _this() )
1561 << ".CutListOfGroups( " << theMainGroups
1562 << theToolGroups << ", '" << theName << "' )";
1564 SMESH_CATCH( SMESH::throwCorbaException );
1566 return aResGrp._retn();
1569 //=============================================================================
1571 \brief Create groups of entities from existing groups of superior dimensions
1573 1) extract all nodes from each group,
1574 2) combine all elements of specified dimension laying on these nodes.
1575 \param theGroups list of source groups
1576 \param theElemType dimension of elements
1577 \param theName name of new group
1578 \return pointer on new group
1582 //=============================================================================
1584 SMESH::SMESH_Group_ptr
1585 SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfGroups& theGroups,
1586 SMESH::ElementType theElemType,
1587 const char* theName )
1588 throw (SALOME::SALOME_Exception)
1590 SMESH::SMESH_Group_var aResGrp;
1594 _preMeshInfo->FullLoadFromFile();
1596 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
1598 if ( !theName || !aMeshDS )
1599 return SMESH::SMESH_Group::_nil();
1601 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)theElemType;
1607 aResGrp = CreateGroup( theElemType, theName );
1608 if ( aResGrp->_is_nil() )
1609 return SMESH::SMESH_Group::_nil();
1611 SMESHDS_GroupBase* groupBaseDS =
1612 SMESH::DownCast<SMESH_GroupBase_i*>( aResGrp )->GetGroupDS();
1613 SMDS_MeshGroup& resGroupCore = static_cast< SMESHDS_Group* >( groupBaseDS )->SMDSGroup();
1615 for ( int g = 0, n = theGroups.length(); g < n; g++ ) // loop on theGroups
1617 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1618 if ( CORBA::is_nil( aGrp ) )
1621 groupBaseDS = SMESH::DownCast<SMESH_GroupBase_i*>( aGrp )->GetGroupDS();
1622 SMDS_ElemIteratorPtr elIt = groupBaseDS->GetElements();
1624 if ( theElemType == SMESH::NODE ) // get all nodes of elements
1626 while ( elIt->more() ) {
1627 const SMDS_MeshElement* el = elIt->next();
1628 SMDS_ElemIteratorPtr nIt = el->nodesIterator();
1629 while ( nIt->more() )
1630 resGroupCore.Add( nIt->next() );
1633 else // get elements of theElemType based on nodes of every element of group
1635 while ( elIt->more() )
1637 const SMDS_MeshElement* el = elIt->next(); // an element of group
1638 TIDSortedElemSet elNodes( el->begin_nodes(), el->end_nodes() );
1639 TIDSortedElemSet checkedElems;
1640 SMDS_ElemIteratorPtr nIt = el->nodesIterator();
1641 while ( nIt->more() )
1643 const SMDS_MeshNode* n = static_cast<const SMDS_MeshNode*>( nIt->next() );
1644 SMDS_ElemIteratorPtr elOfTypeIt = n->GetInverseElementIterator( anElemType );
1645 // check nodes of elements of theElemType around el
1646 while ( elOfTypeIt->more() )
1648 const SMDS_MeshElement* elOfType = elOfTypeIt->next();
1649 if ( !checkedElems.insert( elOfType ).second ) continue;
1651 SMDS_ElemIteratorPtr nIt2 = elOfType->nodesIterator();
1652 bool allNodesOK = true;
1653 while ( nIt2->more() && allNodesOK )
1654 allNodesOK = elNodes.count( nIt2->next() );
1656 resGroupCore.Add( elOfType );
1663 // Update Python script
1664 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var( _this())
1665 << ".CreateDimGroup( "
1666 << theGroups << ", " << theElemType << ", '" << theName << "' )";
1668 SMESH_CATCH( SMESH::throwCorbaException );
1670 return aResGrp._retn();
1673 //================================================================================
1675 * \brief Remember GEOM group data
1677 //================================================================================
1679 void SMESH_Mesh_i::addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
1680 CORBA::Object_ptr theSmeshObj)
1682 if ( CORBA::is_nil( theGeomObj ) || theGeomObj->GetType() != GEOM_GROUP )
1685 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1686 SALOMEDS::SObject_wrap groupSO = _gen_i->ObjectToSObject( study, theGeomObj );
1687 if ( groupSO->_is_nil() )
1690 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1691 GEOM::GEOM_IGroupOperations_wrap groupOp =
1692 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1693 GEOM::ListOfLong_var ids = groupOp->GetObjects( theGeomObj );
1696 _geomGroupData.push_back( TGeomGroupData() );
1697 TGeomGroupData & groupData = _geomGroupData.back();
1699 CORBA::String_var entry = groupSO->GetID();
1700 groupData._groupEntry = entry.in();
1702 for ( int i = 0; i < ids->length(); ++i )
1703 groupData._indices.insert( ids[i] );
1705 groupData._smeshObject = CORBA::Object::_duplicate( theSmeshObj );
1708 //================================================================================
1710 * Remove GEOM group data relating to removed smesh object
1712 //================================================================================
1714 void SMESH_Mesh_i::removeGeomGroupData(CORBA::Object_ptr theSmeshObj)
1716 list<TGeomGroupData>::iterator
1717 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1718 for ( ; data != dataEnd; ++data ) {
1719 if ( theSmeshObj->_is_equivalent( data->_smeshObject )) {
1720 _geomGroupData.erase( data );
1726 //================================================================================
1728 * \brief Return new group contents if it has been changed and update group data
1730 //================================================================================
1732 TopoDS_Shape SMESH_Mesh_i::newGroupShape( TGeomGroupData & groupData)
1734 TopoDS_Shape newShape;
1737 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1738 if ( study->_is_nil() ) return newShape; // means "not changed"
1739 SALOMEDS::SObject_wrap groupSO = study->FindObjectID( groupData._groupEntry.c_str() );
1740 if ( !groupSO->_is_nil() )
1742 CORBA::Object_var groupObj = _gen_i->SObjectToObject( groupSO );
1743 if ( CORBA::is_nil( groupObj )) return newShape;
1744 GEOM::GEOM_Object_var geomGroup = GEOM::GEOM_Object::_narrow( groupObj );
1746 // get indices of group items
1747 set<int> curIndices;
1748 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1749 GEOM::GEOM_IGroupOperations_wrap groupOp =
1750 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1751 GEOM::ListOfLong_var ids = groupOp->GetObjects( geomGroup );
1752 for ( int i = 0; i < ids->length(); ++i )
1753 curIndices.insert( ids[i] );
1755 if ( groupData._indices == curIndices )
1756 return newShape; // group not changed
1759 groupData._indices = curIndices;
1761 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1762 if ( !geomClient ) return newShape;
1763 CORBA::String_var groupIOR = geomGen->GetStringFromIOR( geomGroup );
1764 geomClient->RemoveShapeFromBuffer( groupIOR.in() );
1765 newShape = _gen_i->GeomObjectToShape( geomGroup );
1768 if ( newShape.IsNull() ) {
1769 // geom group becomes empty - return empty compound
1770 TopoDS_Compound compound;
1771 BRep_Builder().MakeCompound(compound);
1772 newShape = compound;
1779 //=============================================================================
1781 * \brief Storage of shape and index used in CheckGeomGroupModif()
1783 //=============================================================================
1784 struct TIndexedShape
1787 TopoDS_Shape _shape;
1788 TIndexedShape( int i, const TopoDS_Shape& s ):_index(i), _shape(s) {}
1791 //=============================================================================
1793 * \brief Update objects depending on changed geom groups
1795 * NPAL16168: geometrical group edition from a submesh don't modifiy mesh computation
1796 * issue 0020210: Update of a smesh group after modification of the associated geom group
1798 //=============================================================================
1800 void SMESH_Mesh_i::CheckGeomGroupModif()
1802 if ( !_impl->HasShapeToMesh() ) return;
1804 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1805 if ( study->_is_nil() ) return;
1807 CORBA::Long nbEntities = NbNodes() + NbElements();
1809 // Check if group contents changed
1811 typedef map< string, TopoDS_Shape > TEntry2Geom;
1812 TEntry2Geom newGroupContents;
1814 list<TGeomGroupData>::iterator
1815 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1816 for ( ; data != dataEnd; ++data )
1818 pair< TEntry2Geom::iterator, bool > it_new =
1819 newGroupContents.insert( make_pair( data->_groupEntry, TopoDS_Shape() ));
1820 bool processedGroup = !it_new.second;
1821 TopoDS_Shape& newShape = it_new.first->second;
1822 if ( !processedGroup )
1823 newShape = newGroupShape( *data );
1824 if ( newShape.IsNull() )
1825 continue; // no changes
1828 _preMeshInfo->ForgetOrLoad();
1830 if ( processedGroup ) { // update group indices
1831 list<TGeomGroupData>::iterator data2 = data;
1832 for ( --data2; data2->_groupEntry != data->_groupEntry; --data2) {}
1833 data->_indices = data2->_indices;
1836 // Update SMESH objects according to new GEOM group contents
1838 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( data->_smeshObject );
1839 if ( !submesh->_is_nil() ) // -------------- Sub mesh ---------------------
1841 int oldID = submesh->GetId();
1842 if ( !_mapSubMeshIor.count( oldID ))
1844 TopoDS_Shape oldShape = _mapSubMesh[oldID]->GetSubShape();
1846 // update hypotheses
1847 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldShape);
1848 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1849 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1851 _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
1852 _impl->AddHypothesis ( newShape, (*hypIt)->GetID());
1854 // care of submeshes
1855 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newShape );
1856 int newID = newSubmesh->GetId();
1857 if ( newID != oldID ) {
1858 _mapSubMesh [ newID ] = newSubmesh;
1859 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1860 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1861 _mapSubMesh. erase(oldID);
1862 _mapSubMesh_i. erase(oldID);
1863 _mapSubMeshIor.erase(oldID);
1864 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1869 SMESH::SMESH_GroupOnGeom_var smeshGroup =
1870 SMESH::SMESH_GroupOnGeom::_narrow( data->_smeshObject );
1871 if ( !smeshGroup->_is_nil() ) // ------------ GROUP -----------------------
1873 SMESH_GroupOnGeom_i* group_i = SMESH::DownCast<SMESH_GroupOnGeom_i*>( smeshGroup );
1875 ::SMESH_Group* group = _impl->GetGroup( group_i->GetLocalID() );
1876 SMESHDS_GroupOnGeom* ds = static_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() );
1877 ds->SetShape( newShape );
1882 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( data->_smeshObject );
1883 if ( !mesh->_is_nil() ) // -------------- MESH ----------------------------
1885 // Remove groups and submeshes basing on removed sub-shapes
1887 TopTools_MapOfShape newShapeMap;
1888 TopoDS_Iterator shapeIt( newShape );
1889 for ( ; shapeIt.More(); shapeIt.Next() )
1890 newShapeMap.Add( shapeIt.Value() );
1892 SMESHDS_Mesh* meshDS = _impl->GetMeshDS();
1893 for ( shapeIt.Initialize( meshDS->ShapeToMesh() ); shapeIt.More(); shapeIt.Next() )
1895 if ( newShapeMap.Contains( shapeIt.Value() ))
1897 TopTools_IndexedMapOfShape oldShapeMap;
1898 TopExp::MapShapes( shapeIt.Value(), oldShapeMap );
1899 for ( int i = 1; i <= oldShapeMap.Extent(); ++i )
1901 const TopoDS_Shape& oldShape = oldShapeMap(i);
1902 int oldInd = meshDS->ShapeToIndex( oldShape );
1904 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldInd );
1905 if ( i_smIor != _mapSubMeshIor.end() ) {
1906 RemoveSubMesh( i_smIor->second ); // one submesh per shape index
1909 map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_grp = _mapGroups.begin();
1910 for ( ; i_grp != _mapGroups.end(); ++i_grp )
1912 // check if a group bases on oldInd shape
1913 SMESHDS_GroupOnGeom* grpOnGeom = 0;
1914 if ( ::SMESH_Group* g = _impl->GetGroup( i_grp->first ))
1915 grpOnGeom = dynamic_cast<SMESHDS_GroupOnGeom*>( g->GetGroupDS() );
1916 if ( grpOnGeom && oldShape.IsSame( grpOnGeom->GetShape() ))
1918 RemoveGroup( i_grp->second ); // several groups can base on same shape
1919 i_grp = _mapGroups.begin(); // _mapGroups changed - restart iteration
1924 // Reassign hypotheses and update groups after setting the new shape to mesh
1926 // collect anassigned hypotheses
1927 typedef list< pair< TIndexedShape, list<const SMESHDS_Hypothesis*> > > TShapeHypList;
1928 list <const SMESHDS_Hypothesis * >::const_iterator hypIt;
1929 TShapeHypList assignedHyps;
1930 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
1932 const TopoDS_Shape& oldShape = meshDS->IndexToShape(i);
1933 list<const SMESHDS_Hypothesis*> hyps = meshDS->GetHypothesis( oldShape );// copy
1934 if ( !hyps.empty() ) {
1935 assignedHyps.push_back( make_pair( TIndexedShape(i,oldShape), hyps ));
1936 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1937 _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
1940 // collect shapes supporting groups
1941 typedef list < pair< TIndexedShape, SMDSAbs_ElementType > > TShapeTypeList;
1942 TShapeTypeList groupData;
1943 const set<SMESHDS_GroupBase*>& groups = meshDS->GetGroups();
1944 set<SMESHDS_GroupBase*>::const_iterator grIt = groups.begin();
1945 for ( ; grIt != groups.end(); ++grIt )
1947 if ( SMESHDS_GroupOnGeom* gog = dynamic_cast<SMESHDS_GroupOnGeom*>( *grIt ))
1949 ( make_pair( TIndexedShape( gog->GetID(),gog->GetShape()), gog->GetType()));
1951 // set new shape to mesh -> DS of submeshes and geom groups is deleted
1952 _impl->ShapeToMesh( newShape );
1954 // reassign hypotheses
1955 TShapeHypList::iterator indS_hyps = assignedHyps.begin();
1956 for ( ; indS_hyps != assignedHyps.end(); ++indS_hyps )
1958 TIndexedShape& geom = indS_hyps->first;
1959 list<const SMESHDS_Hypothesis*>& hyps = indS_hyps->second;
1960 int oldID = geom._index;
1961 int newID = meshDS->ShapeToIndex( geom._shape );
1962 if ( oldID == 1 ) { // main shape
1964 geom._shape = newShape;
1968 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1969 _impl->AddHypothesis( geom._shape, (*hypIt)->GetID());
1970 // care of submeshes
1971 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( geom._shape );
1972 if ( newID != oldID ) {
1973 _mapSubMesh [ newID ] = newSubmesh;
1974 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1975 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1976 _mapSubMesh. erase(oldID);
1977 _mapSubMesh_i. erase(oldID);
1978 _mapSubMeshIor.erase(oldID);
1979 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1983 TShapeTypeList::iterator geomType = groupData.begin();
1984 for ( ; geomType != groupData.end(); ++geomType )
1986 const TIndexedShape& geom = geomType->first;
1987 int oldID = geom._index;
1988 if ( _mapGroups.find( oldID ) == _mapGroups.end() )
1991 SALOMEDS::SObject_wrap groupSO = _gen_i->ObjectToSObject( study,_mapGroups[oldID] );
1992 CORBA::String_var name = groupSO->GetName();
1994 SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>(_mapGroups[oldID] );
1996 if ( group_i && _impl->AddGroup( geomType->second, name.in(), newID, geom._shape ))
1997 group_i->changeLocalId( newID );
2000 break; // everything has been updated
2003 } // loop on group data
2007 CORBA::Long newNbEntities = NbNodes() + NbElements();
2008 list< SALOMEDS::SObject_wrap > soToUpdateIcons;
2009 if ( newNbEntities != nbEntities )
2011 // Add all SObjects with icons to soToUpdateIcons
2012 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, _this() )); // mesh
2014 for (map<int, SMESH::SMESH_subMesh_ptr>::iterator i_sm = _mapSubMeshIor.begin();
2015 i_sm != _mapSubMeshIor.end(); ++i_sm ) // submeshes
2016 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_sm->second ));
2018 for ( map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_gr = _mapGroups.begin();
2019 i_gr != _mapGroups.end(); ++i_gr ) // groups
2020 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_gr->second ));
2023 list< SALOMEDS::SObject_wrap >::iterator so = soToUpdateIcons.begin();
2024 for ( ; so != soToUpdateIcons.end(); ++so )
2025 _gen_i->SetPixMap( *so, "ICON_SMESH_TREE_MESH_WARN" );
2028 //=============================================================================
2030 * \brief Create standalone group from a group on geometry or filter
2032 //=============================================================================
2034 SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupBase_ptr theGroup )
2035 throw (SALOME::SALOME_Exception)
2037 SMESH::SMESH_Group_var aGroup;
2042 _preMeshInfo->FullLoadFromFile();
2044 if ( theGroup->_is_nil() )
2045 return aGroup._retn();
2047 SMESH_GroupBase_i* aGroupToRem = SMESH::DownCast<SMESH_GroupBase_i*>( theGroup );
2049 return aGroup._retn();
2051 const bool isOnFilter = ( SMESH::DownCast< SMESH_GroupOnFilter_i* > ( theGroup ));
2053 const int anId = aGroupToRem->GetLocalID();
2054 if ( !_impl->ConvertToStandalone( anId ) )
2055 return aGroup._retn();
2056 removeGeomGroupData( theGroup );
2058 SMESH_GroupBase_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2060 // remove old instance of group from own map
2061 { SMESH::SMESH_GroupBase_var var( _mapGroups[anId] ); } // decref CORBA object
2062 _mapGroups.erase( anId );
2064 SALOMEDS::StudyBuilder_var builder;
2065 SALOMEDS::SObject_wrap aGroupSO;
2066 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
2067 if ( !aStudy->_is_nil() ) {
2068 builder = aStudy->NewBuilder();
2069 aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
2070 if ( !aGroupSO->_is_nil() )
2072 // remove reference to geometry
2073 SALOMEDS::ChildIterator_wrap chItr = aStudy->NewChildIterator(aGroupSO);
2074 for ( ; chItr->More(); chItr->Next() )
2075 // Remove group's child SObject
2076 builder->RemoveObject( chItr->Value() );
2078 // Update Python script
2079 TPythonDump() << aGroupSO << " = " << SMESH::SMESH_Mesh_var(_this())
2080 << ".ConvertToStandalone( " << aGroupSO << " )";
2082 // change icon of Group on Filter
2085 SMESH::array_of_ElementType_var elemTypes = aGroupImpl->GetTypes();
2086 const int isEmpty = ( elemTypes->length() == 0 );
2089 SALOMEDS::GenericAttribute_wrap anAttr =
2090 builder->FindOrCreateAttribute( aGroupSO, "AttributePixMap" );
2091 SALOMEDS::AttributePixMap_wrap pm = anAttr;
2092 pm->SetPixMap( "ICON_SMESH_TREE_GROUP" );
2098 // remember new group in own map
2099 aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
2100 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
2102 // register CORBA object for persistence
2103 _gen_i->RegisterObject( aGroup );
2105 CORBA::String_var ior = _gen_i->GetORB()->object_to_string( aGroup );
2106 builder->SetIOR( aGroupSO, ior.in() ); // == aGroup->Register();
2107 //aGroup->Register();
2108 aGroupToRem->UnRegister();
2110 SMESH_CATCH( SMESH::throwCorbaException );
2112 return aGroup._retn();
2115 //=============================================================================
2119 //=============================================================================
2121 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
2123 if(MYDEBUG) MESSAGE( "createSubMesh" );
2124 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
2125 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
2126 const int subMeshId = mySubMesh->GetId();
2128 SMESH_subMesh_i * subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
2129 SMESH::SMESH_subMesh_var subMesh = subMeshServant->_this();
2131 _mapSubMesh [subMeshId] = mySubMesh;
2132 _mapSubMesh_i [subMeshId] = subMeshServant;
2133 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate( subMesh );
2135 subMeshServant->Register();
2137 // register CORBA object for persistence
2138 int nextId = _gen_i->RegisterObject( subMesh );
2139 if(MYDEBUG) { MESSAGE( "Add submesh to map with id = "<< nextId); }
2140 else { nextId = 0; } // avoid "unused variable" warning
2142 // to track changes of GEOM groups
2143 addGeomGroupData( theSubShapeObject, subMesh );
2145 return subMesh._retn();
2148 //=======================================================================
2149 //function : getSubMesh
2151 //=======================================================================
2153 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
2155 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
2156 if ( it == _mapSubMeshIor.end() )
2157 return SMESH::SMESH_subMesh::_nil();
2159 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
2162 //=============================================================================
2166 //=============================================================================
2168 bool SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
2169 GEOM::GEOM_Object_ptr theSubShapeObject )
2171 bool isHypChanged = false;
2172 if ( theSubMesh->_is_nil() /*|| theSubShapeObject->_is_nil()*/ )
2173 return isHypChanged;
2175 const int subMeshId = theSubMesh->GetId();
2177 if ( theSubShapeObject->_is_nil() ) // not published shape (IPAL13617)
2179 if ( _mapSubMesh.find( subMeshId ) != _mapSubMesh.end())
2181 TopoDS_Shape S = _mapSubMesh[ subMeshId ]->GetSubShape();
2184 list<const SMESHDS_Hypothesis*> hyps = _impl->GetHypothesisList( S );
2185 isHypChanged = !hyps.empty();
2186 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hyps.begin();
2187 for ( ; hyp != hyps.end(); ++hyp )
2188 _impl->RemoveHypothesis(S, (*hyp)->GetID());
2195 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
2196 isHypChanged = ( aHypList->length() > 0 );
2197 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
2198 removeHypothesis( theSubShapeObject, aHypList[i] );
2201 catch( const SALOME::SALOME_Exception& ) {
2202 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
2204 removeGeomGroupData( theSubShapeObject );
2208 std::map<int, SMESH_subMesh_i*>::iterator id_smi = _mapSubMesh_i.find( subMeshId );
2209 if ( id_smi != _mapSubMesh_i.end() )
2210 id_smi->second->UnRegister();
2212 // remove a CORBA object
2213 std::map<int, SMESH::SMESH_subMesh_ptr>::iterator id_smptr = _mapSubMeshIor.find( subMeshId );
2214 if ( id_smptr != _mapSubMeshIor.end() )
2215 SMESH::SMESH_subMesh_var( id_smptr->second );
2217 _mapSubMesh.erase(subMeshId);
2218 _mapSubMesh_i.erase(subMeshId);
2219 _mapSubMeshIor.erase(subMeshId);
2221 return isHypChanged;
2224 //=============================================================================
2228 //=============================================================================
2230 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
2231 const char* theName,
2232 const TopoDS_Shape& theShape,
2233 const SMESH_PredicatePtr& thePredicate )
2235 std::string newName;
2236 if ( !theName || strlen( theName ) == 0 )
2238 std::set< std::string > presentNames;
2239 std::map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator i_gr = _mapGroups.begin();
2240 for ( ; i_gr != _mapGroups.end(); ++i_gr )
2242 CORBA::String_var name = i_gr->second->GetName();
2243 presentNames.insert( name.in() );
2246 newName = "noname_Group_" + SMESH_Comment( presentNames.size() + 1 );
2247 } while ( !presentNames.insert( newName ).second );
2248 theName = newName.c_str();
2251 SMESH::SMESH_GroupBase_var aGroup;
2252 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape, thePredicate ))
2254 SMESH_GroupBase_i* aGroupImpl;
2255 if ( !theShape.IsNull() )
2256 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2257 else if ( thePredicate )
2258 aGroupImpl = new SMESH_GroupOnFilter_i( SMESH_Gen_i::GetPOA(), this, anId );
2260 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2262 aGroup = aGroupImpl->_this();
2263 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
2264 aGroupImpl->Register();
2266 // register CORBA object for persistence
2267 int nextId = _gen_i->RegisterObject( aGroup );
2268 if(MYDEBUG) { MESSAGE( "Add group to map with id = "<< nextId); }
2269 else { nextId = 0; } // avoid "unused variable" warning in release mode
2271 // to track changes of GEOM groups
2272 if ( !theShape.IsNull() ) {
2273 GEOM::GEOM_Object_var geom = _gen_i->ShapeToGeomObject( theShape );
2274 addGeomGroupData( geom, aGroup );
2277 return aGroup._retn();
2280 //=============================================================================
2282 * SMESH_Mesh_i::removeGroup
2284 * Should be called by ~SMESH_Group_i()
2286 //=============================================================================
2288 void SMESH_Mesh_i::removeGroup( const int theId )
2290 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
2291 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
2292 SMESH::SMESH_GroupBase_var group = _mapGroups[theId];
2293 _mapGroups.erase( theId );
2294 removeGeomGroupData( group );
2295 if ( !_impl->RemoveGroup( theId ))
2297 // it seems to be a call up from _impl caused by hyp modification (issue 0020918)
2298 RemoveGroup( group );
2300 group->UnRegister();
2304 //=============================================================================
2308 //=============================================================================
2310 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
2311 throw(SALOME::SALOME_Exception)
2313 SMESH::log_array_var aLog;
2317 _preMeshInfo->FullLoadFromFile();
2319 list < SMESHDS_Command * >logDS = _impl->GetLog();
2320 aLog = new SMESH::log_array;
2322 int lg = logDS.size();
2325 list < SMESHDS_Command * >::iterator its = logDS.begin();
2326 while(its != logDS.end()){
2327 SMESHDS_Command *com = *its;
2328 int comType = com->GetType();
2330 int lgcom = com->GetNumber();
2332 const list < int >&intList = com->GetIndexes();
2333 int inum = intList.size();
2335 list < int >::const_iterator ii = intList.begin();
2336 const list < double >&coordList = com->GetCoords();
2337 int rnum = coordList.size();
2339 list < double >::const_iterator ir = coordList.begin();
2340 aLog[indexLog].commandType = comType;
2341 aLog[indexLog].number = lgcom;
2342 aLog[indexLog].coords.length(rnum);
2343 aLog[indexLog].indexes.length(inum);
2344 for(int i = 0; i < rnum; i++){
2345 aLog[indexLog].coords[i] = *ir;
2346 //MESSAGE(" "<<i<<" "<<ir.Value());
2349 for(int i = 0; i < inum; i++){
2350 aLog[indexLog].indexes[i] = *ii;
2351 //MESSAGE(" "<<i<<" "<<ii.Value());
2360 SMESH_CATCH( SMESH::throwCorbaException );
2362 return aLog._retn();
2366 //=============================================================================
2370 //=============================================================================
2372 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
2376 SMESH_CATCH( SMESH::throwCorbaException );
2379 //=============================================================================
2383 //=============================================================================
2385 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
2390 //=============================================================================
2394 //=============================================================================
2396 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
2401 //=============================================================================
2404 //!< implementation of struct used to call methods of SMESH_Mesh_i from SMESH_Mesh
2405 // issue 0020918: groups removal is caused by hyp modification
2406 // issue 0021208: to forget not loaded mesh data at hyp modification
2407 struct TCallUp_i : public SMESH_Mesh::TCallUp
2409 SMESH_Mesh_i* _mesh;
2410 TCallUp_i(SMESH_Mesh_i* mesh):_mesh(mesh) {}
2411 virtual void RemoveGroup (const int theGroupID) { _mesh->removeGroup( theGroupID ); }
2412 virtual void HypothesisModified () { _mesh->onHypothesisModified(); }
2413 virtual void Load () { _mesh->Load(); }
2417 //================================================================================
2419 * \brief callback from _impl to forget not loaded mesh data (issue 0021208)
2421 //================================================================================
2423 void SMESH_Mesh_i::onHypothesisModified()
2426 _preMeshInfo->ForgetOrLoad();
2429 //=============================================================================
2433 //=============================================================================
2435 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
2437 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
2440 _impl->SetCallUp( new TCallUp_i(this));
2443 //=============================================================================
2447 //=============================================================================
2449 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
2451 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
2455 //=============================================================================
2457 * Return mesh editor
2459 //=============================================================================
2461 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
2462 throw (SALOME::SALOME_Exception)
2464 SMESH::SMESH_MeshEditor_var aMeshEdVar;
2468 _preMeshInfo->FullLoadFromFile();
2470 // Create MeshEditor
2472 _editor = new SMESH_MeshEditor_i( this, false );
2473 aMeshEdVar = _editor->_this();
2475 // Update Python script
2476 TPythonDump() << _editor << " = "
2477 << SMESH::SMESH_Mesh_var(_this()) << ".GetMeshEditor()";
2479 SMESH_CATCH( SMESH::throwCorbaException );
2481 return aMeshEdVar._retn();
2484 //=============================================================================
2486 * Return mesh edition previewer
2488 //=============================================================================
2490 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
2491 throw (SALOME::SALOME_Exception)
2493 SMESH::SMESH_MeshEditor_var aMeshEdVar;
2497 _preMeshInfo->FullLoadFromFile();
2499 if ( !_previewEditor )
2500 _previewEditor = new SMESH_MeshEditor_i( this, true );
2501 aMeshEdVar = _previewEditor->_this();
2503 SMESH_CATCH( SMESH::throwCorbaException );
2505 return aMeshEdVar._retn();
2508 //================================================================================
2510 * \brief Return true if the mesh has been edited since a last total re-compute
2511 * and those modifications may prevent successful partial re-compute
2513 //================================================================================
2515 CORBA::Boolean SMESH_Mesh_i::HasModificationsToDiscard() throw(SALOME::SALOME_Exception)
2517 Unexpect aCatch(SALOME_SalomeException);
2518 return _impl->HasModificationsToDiscard();
2521 //================================================================================
2523 * \brief Returns a random unique color
2525 //================================================================================
2527 static SALOMEDS::Color getUniqueColor( const std::list<SALOMEDS::Color>& theReservedColors )
2529 const int MAX_ATTEMPTS = 100;
2531 double tolerance = 0.5;
2532 SALOMEDS::Color col;
2536 // generate random color
2537 double red = (double)rand() / RAND_MAX;
2538 double green = (double)rand() / RAND_MAX;
2539 double blue = (double)rand() / RAND_MAX;
2540 // check existence in the list of the existing colors
2541 bool matched = false;
2542 std::list<SALOMEDS::Color>::const_iterator it;
2543 for ( it = theReservedColors.begin(); it != theReservedColors.end() && !matched; ++it ) {
2544 SALOMEDS::Color color = *it;
2545 double tol = fabs( color.R - red ) + fabs( color.G - green ) + fabs( color.B - blue );
2546 matched = tol < tolerance;
2548 if ( (cnt+1) % 20 == 0 ) tolerance = tolerance/2;
2549 ok = ( ++cnt == MAX_ATTEMPTS ) || !matched;
2557 //=============================================================================
2559 * Sets auto-color mode. If it is on, groups get unique random colors
2561 //=============================================================================
2563 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
2565 Unexpect aCatch(SALOME_SalomeException);
2566 _impl->SetAutoColor(theAutoColor);
2568 TPythonDump pyDump; // not to dump group->SetColor() from below code
2569 pyDump << SMESH::SMESH_Mesh_var(_this()) <<".SetAutoColor( "<<theAutoColor<<" )";
2571 std::list<SALOMEDS::Color> aReservedColors;
2572 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
2573 for ( ; it != _mapGroups.end(); it++ ) {
2574 if ( CORBA::is_nil( it->second )) continue;
2575 SALOMEDS::Color aColor = getUniqueColor( aReservedColors );
2576 it->second->SetColor( aColor );
2577 aReservedColors.push_back( aColor );
2581 //=============================================================================
2583 * Returns true if auto-color mode is on
2585 //=============================================================================
2587 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
2589 Unexpect aCatch(SALOME_SalomeException);
2590 return _impl->GetAutoColor();
2593 //=============================================================================
2595 * Checks if there are groups with equal names
2597 //=============================================================================
2599 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
2601 return _impl->HasDuplicatedGroupNamesMED();
2604 //================================================================================
2606 * \brief Care of a file before exporting mesh into it
2608 //================================================================================
2610 void SMESH_Mesh_i::PrepareForWriting (const char* file, bool overwrite)
2612 TCollection_AsciiString aFullName ((char*)file);
2613 OSD_Path aPath (aFullName);
2614 OSD_File aFile (aPath);
2615 if (aFile.Exists()) {
2616 // existing filesystem node
2617 if (aFile.KindOfFile() == OSD_FILE) {
2618 if (aFile.IsWriteable()) {
2623 if (aFile.Failed()) {
2624 TCollection_AsciiString msg ("File ");
2625 msg += aFullName + " cannot be replaced.";
2626 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2629 TCollection_AsciiString msg ("File ");
2630 msg += aFullName + " cannot be overwritten.";
2631 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2634 TCollection_AsciiString msg ("Location ");
2635 msg += aFullName + " is not a file.";
2636 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2639 // nonexisting file; check if it can be created
2641 aFile.Build(OSD_WriteOnly, OSD_Protection());
2642 if (aFile.Failed()) {
2643 TCollection_AsciiString msg ("You cannot create the file ");
2644 msg += aFullName + ". Check the directory existance and access rights.";
2645 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2653 //================================================================================
2655 * \brief Prepares a file for export and pass names of mesh groups from study to mesh DS
2656 * \param file - file name
2657 * \param overwrite - to erase the file or not
2658 * \retval string - mesh name
2660 //================================================================================
2662 string SMESH_Mesh_i::prepareMeshNameAndGroups(const char* file,
2663 CORBA::Boolean overwrite)
2666 PrepareForWriting(file, overwrite);
2667 string aMeshName = "Mesh";
2668 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
2669 if ( !aStudy->_is_nil() ) {
2670 SALOMEDS::SObject_wrap aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
2671 if ( !aMeshSO->_is_nil() ) {
2672 CORBA::String_var name = aMeshSO->GetName();
2674 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
2675 if ( !aStudy->GetProperties()->IsLocked() )
2677 SALOMEDS::GenericAttribute_wrap anAttr;
2678 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2679 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
2680 SALOMEDS::AttributeExternalFileDef_wrap aFileName = anAttr;
2681 ASSERT(!aFileName->_is_nil());
2682 aFileName->SetValue(file);
2683 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
2684 SALOMEDS::AttributeFileType_wrap aFileType = anAttr;
2685 ASSERT(!aFileType->_is_nil());
2686 aFileType->SetValue("FICHIERMED");
2690 // Update Python script
2691 // set name of mesh before export
2692 TPythonDump() << _gen_i << ".SetName("
2693 << SMESH::SMESH_Mesh_var(_this()) << ", '" << aMeshName.c_str() << "')";
2695 // check names of groups
2701 //================================================================================
2703 * \brief Export to med file
2705 //================================================================================
2707 void SMESH_Mesh_i::ExportToMEDX (const char* file,
2708 CORBA::Boolean auto_groups,
2709 SMESH::MED_VERSION theVersion,
2710 CORBA::Boolean overwrite,
2711 CORBA::Boolean autoDimension)
2712 throw(SALOME::SALOME_Exception)
2716 _preMeshInfo->FullLoadFromFile();
2718 string aMeshName = prepareMeshNameAndGroups(file, overwrite);
2719 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportToMEDX( r'"
2720 << file << "', " << auto_groups << ", "
2721 << theVersion << ", " << overwrite << ", "
2722 << autoDimension << " )";
2724 _impl->ExportMED( file, aMeshName.c_str(), auto_groups, theVersion, 0, autoDimension );
2726 SMESH_CATCH( SMESH::throwCorbaException );
2729 //================================================================================
2731 * \brief Export a mesh to a med file
2733 //================================================================================
2735 void SMESH_Mesh_i::ExportToMED (const char* file,
2736 CORBA::Boolean auto_groups,
2737 SMESH::MED_VERSION theVersion)
2738 throw(SALOME::SALOME_Exception)
2740 ExportToMEDX(file,auto_groups,theVersion,true);
2743 //================================================================================
2745 * \brief Export a mesh to a med file
2747 //================================================================================
2749 void SMESH_Mesh_i::ExportMED (const char* file,
2750 CORBA::Boolean auto_groups)
2751 throw(SALOME::SALOME_Exception)
2753 ExportToMEDX(file,auto_groups,SMESH::MED_V2_2,true);
2756 //================================================================================
2758 * \brief Export a mesh to a SAUV file
2760 //================================================================================
2762 void SMESH_Mesh_i::ExportSAUV (const char* file,
2763 CORBA::Boolean auto_groups)
2764 throw(SALOME::SALOME_Exception)
2766 Unexpect aCatch(SALOME_SalomeException);
2768 _preMeshInfo->FullLoadFromFile();
2770 string aMeshName = prepareMeshNameAndGroups(file, true);
2771 TPythonDump() << SMESH::SMESH_Mesh_var( _this())
2772 << ".ExportSAUV( r'" << file << "', " << auto_groups << " )";
2773 _impl->ExportSAUV(file, aMeshName.c_str(), auto_groups);
2777 //================================================================================
2779 * \brief Export a mesh to a DAT file
2781 //================================================================================
2783 void SMESH_Mesh_i::ExportDAT (const char *file)
2784 throw(SALOME::SALOME_Exception)
2786 Unexpect aCatch(SALOME_SalomeException);
2788 _preMeshInfo->FullLoadFromFile();
2790 // Update Python script
2791 // check names of groups
2793 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportDAT( r'" << file << "' )";
2796 PrepareForWriting(file);
2797 _impl->ExportDAT(file);
2800 //================================================================================
2802 * \brief Export a mesh to an UNV file
2804 //================================================================================
2806 void SMESH_Mesh_i::ExportUNV (const char *file)
2807 throw(SALOME::SALOME_Exception)
2809 Unexpect aCatch(SALOME_SalomeException);
2811 _preMeshInfo->FullLoadFromFile();
2813 // Update Python script
2814 // check names of groups
2816 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportUNV( r'" << file << "' )";
2819 PrepareForWriting(file);
2820 _impl->ExportUNV(file);
2823 //================================================================================
2825 * \brief Export a mesh to an STL file
2827 //================================================================================
2829 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
2830 throw(SALOME::SALOME_Exception)
2832 Unexpect aCatch(SALOME_SalomeException);
2834 _preMeshInfo->FullLoadFromFile();
2836 // Update Python script
2837 // check names of groups
2839 TPythonDump() << SMESH::SMESH_Mesh_var(_this())
2840 << ".ExportSTL( r'" << file << "', " << isascii << " )";
2843 PrepareForWriting(file);
2844 _impl->ExportSTL(file, isascii);
2847 //================================================================================
2849 * \brief Export a part of mesh to a med file
2851 //================================================================================
2853 void SMESH_Mesh_i::ExportPartToMED(::SMESH::SMESH_IDSource_ptr meshPart,
2855 CORBA::Boolean auto_groups,
2856 ::SMESH::MED_VERSION version,
2857 ::CORBA::Boolean overwrite,
2858 ::CORBA::Boolean autoDimension)
2859 throw (SALOME::SALOME_Exception)
2861 Unexpect aCatch(SALOME_SalomeException);
2864 if ( SMESH_Mesh_i * mesh = SMESH::DownCast< SMESH_Mesh_i* >( meshPart ))
2866 mesh->ExportToMEDX( file, auto_groups, version, autoDimension );
2871 _preMeshInfo->FullLoadFromFile();
2873 PrepareForWriting(file, overwrite);
2875 string aMeshName = "Mesh";
2876 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
2877 if ( !aStudy->_is_nil() ) {
2878 SALOMEDS::SObject_wrap SO = _gen_i->ObjectToSObject( aStudy, meshPart );
2879 if ( !SO->_is_nil() ) {
2880 CORBA::String_var name = SO->GetName();
2884 SMESH_MeshPartDS partDS( meshPart );
2885 _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, &partDS, autoDimension );
2887 pyDump << SMESH::SMESH_Mesh_var(_this()) << ".ExportPartToMED( "
2888 << meshPart << ", r'" << file << "', "
2889 << auto_groups << ", " << version << ", " << overwrite << ", "
2890 << autoDimension << " )";
2893 //================================================================================
2895 * \brief Export a part of mesh to a DAT file
2897 //================================================================================
2899 void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
2901 throw (SALOME::SALOME_Exception)
2903 Unexpect aCatch(SALOME_SalomeException);
2905 _preMeshInfo->FullLoadFromFile();
2907 PrepareForWriting(file);
2909 SMESH_MeshPartDS partDS( meshPart );
2910 _impl->ExportDAT(file,&partDS);
2912 TPythonDump() << SMESH::SMESH_Mesh_var(_this())
2913 << ".ExportPartToDAT( " << meshPart << ", r'" << file << "' )";
2915 //================================================================================
2917 * \brief Export a part of mesh to an UNV file
2919 //================================================================================
2921 void SMESH_Mesh_i::ExportPartToUNV(::SMESH::SMESH_IDSource_ptr meshPart,
2923 throw (SALOME::SALOME_Exception)
2925 Unexpect aCatch(SALOME_SalomeException);
2927 _preMeshInfo->FullLoadFromFile();
2929 PrepareForWriting(file);
2931 SMESH_MeshPartDS partDS( meshPart );
2932 _impl->ExportUNV(file, &partDS);
2934 TPythonDump() << SMESH::SMESH_Mesh_var(_this())
2935 << ".ExportPartToUNV( " << meshPart<< ", r'" << file << "' )";
2937 //================================================================================
2939 * \brief Export a part of mesh to an STL file
2941 //================================================================================
2943 void SMESH_Mesh_i::ExportPartToSTL(::SMESH::SMESH_IDSource_ptr meshPart,
2945 ::CORBA::Boolean isascii)
2946 throw (SALOME::SALOME_Exception)
2948 Unexpect aCatch(SALOME_SalomeException);
2950 _preMeshInfo->FullLoadFromFile();
2952 PrepareForWriting(file);
2954 SMESH_MeshPartDS partDS( meshPart );
2955 _impl->ExportSTL(file, isascii, &partDS);
2957 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportPartToSTL( "
2958 << meshPart<< ", r'" << file << "', " << isascii << ")";
2961 //================================================================================
2963 * \brief Export a part of mesh to an STL file
2965 //================================================================================
2967 void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
2969 CORBA::Boolean overwrite)
2970 throw (SALOME::SALOME_Exception)
2973 Unexpect aCatch(SALOME_SalomeException);
2975 _preMeshInfo->FullLoadFromFile();
2977 PrepareForWriting(file,overwrite);
2979 SMESH_MeshPartDS partDS( meshPart );
2980 _impl->ExportCGNS(file, &partDS);
2982 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportCGNS( "
2983 << meshPart<< ", r'" << file << "', " << overwrite << ")";
2985 THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
2989 //================================================================================
2991 * \brief Export a part of mesh to a GMF file
2993 //================================================================================
2995 void SMESH_Mesh_i::ExportGMF(::SMESH::SMESH_IDSource_ptr meshPart,
2997 bool withRequiredGroups)
2998 throw (SALOME::SALOME_Exception)
3000 Unexpect aCatch(SALOME_SalomeException);
3002 _preMeshInfo->FullLoadFromFile();
3004 PrepareForWriting(file,/*overwrite=*/true);
3006 SMESH_MeshPartDS partDS( meshPart );
3007 _impl->ExportGMF(file, &partDS, withRequiredGroups);
3009 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportGMF( "
3010 << meshPart<< ", r'"
3012 << withRequiredGroups << ")";
3015 //=============================================================================
3017 * Return computation progress [0.,1]
3019 //=============================================================================
3021 CORBA::Double SMESH_Mesh_i::GetComputeProgress()
3025 return _impl->GetComputeProgress();
3027 SMESH_CATCH( SMESH::doNothing );
3031 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
3033 Unexpect aCatch(SALOME_SalomeException);
3035 return _preMeshInfo->NbNodes();
3037 return _impl->NbNodes();
3040 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
3042 Unexpect aCatch(SALOME_SalomeException);
3044 return _preMeshInfo->NbElements();
3046 return Nb0DElements() + NbEdges() + NbFaces() + NbVolumes() + NbBalls();
3049 CORBA::Long SMESH_Mesh_i::Nb0DElements()throw (SALOME::SALOME_Exception)
3051 Unexpect aCatch(SALOME_SalomeException);
3053 return _preMeshInfo->Nb0DElements();
3055 return _impl->Nb0DElements();
3058 CORBA::Long SMESH_Mesh_i::NbBalls() throw (SALOME::SALOME_Exception)
3060 Unexpect aCatch(SALOME_SalomeException);
3062 return _preMeshInfo->NbBalls();
3064 return _impl->NbBalls();
3067 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
3069 Unexpect aCatch(SALOME_SalomeException);
3071 return _preMeshInfo->NbEdges();
3073 return _impl->NbEdges();
3076 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
3077 throw(SALOME::SALOME_Exception)
3079 Unexpect aCatch(SALOME_SalomeException);
3081 return _preMeshInfo->NbEdges( (SMDSAbs_ElementOrder) order );
3083 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
3086 //=============================================================================
3088 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
3090 Unexpect aCatch(SALOME_SalomeException);
3092 return _preMeshInfo->NbFaces();
3094 return _impl->NbFaces();
3097 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
3099 Unexpect aCatch(SALOME_SalomeException);
3101 return _preMeshInfo->NbTriangles();
3103 return _impl->NbTriangles();
3106 CORBA::Long SMESH_Mesh_i::NbBiQuadTriangles()throw(SALOME::SALOME_Exception)
3108 Unexpect aCatch(SALOME_SalomeException);
3110 return _preMeshInfo->NbBiQuadTriangles();
3112 return _impl->NbBiQuadTriangles();
3115 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
3117 Unexpect aCatch(SALOME_SalomeException);
3119 return _preMeshInfo->NbQuadrangles();
3121 return _impl->NbQuadrangles();
3124 CORBA::Long SMESH_Mesh_i::NbBiQuadQuadrangles()throw(SALOME::SALOME_Exception)
3126 Unexpect aCatch(SALOME_SalomeException);
3128 return _preMeshInfo->NbBiQuadQuadrangles();
3130 return _impl->NbBiQuadQuadrangles();
3133 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
3135 Unexpect aCatch(SALOME_SalomeException);
3137 return _preMeshInfo->NbPolygons();
3139 return _impl->NbPolygons();
3142 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
3143 throw(SALOME::SALOME_Exception)
3145 Unexpect aCatch(SALOME_SalomeException);
3147 return _preMeshInfo->NbFaces( (SMDSAbs_ElementOrder) order );
3149 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
3152 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
3153 throw(SALOME::SALOME_Exception)
3155 Unexpect aCatch(SALOME_SalomeException);
3157 return _preMeshInfo->NbTriangles( (SMDSAbs_ElementOrder) order );
3159 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
3162 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
3163 throw(SALOME::SALOME_Exception)
3165 Unexpect aCatch(SALOME_SalomeException);
3167 return _preMeshInfo->NbQuadrangles( (SMDSAbs_ElementOrder) order );
3169 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
3172 //=============================================================================
3174 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
3176 Unexpect aCatch(SALOME_SalomeException);
3178 return _preMeshInfo->NbVolumes();
3180 return _impl->NbVolumes();
3183 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
3185 Unexpect aCatch(SALOME_SalomeException);
3187 return _preMeshInfo->NbTetras();
3189 return _impl->NbTetras();
3192 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
3194 Unexpect aCatch(SALOME_SalomeException);
3196 return _preMeshInfo->NbHexas();
3198 return _impl->NbHexas();
3201 CORBA::Long SMESH_Mesh_i::NbTriQuadraticHexas()throw(SALOME::SALOME_Exception)
3203 Unexpect aCatch(SALOME_SalomeException);
3205 return _preMeshInfo->NbTriQuadHexas();
3207 return _impl->NbTriQuadraticHexas();
3210 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
3212 Unexpect aCatch(SALOME_SalomeException);
3214 return _preMeshInfo->NbPyramids();
3216 return _impl->NbPyramids();
3219 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
3221 Unexpect aCatch(SALOME_SalomeException);
3223 return _preMeshInfo->NbPrisms();
3225 return _impl->NbPrisms();
3228 CORBA::Long SMESH_Mesh_i::NbHexagonalPrisms()throw(SALOME::SALOME_Exception)
3230 Unexpect aCatch(SALOME_SalomeException);
3232 return _preMeshInfo->NbHexPrisms();
3234 return _impl->NbHexagonalPrisms();
3237 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
3239 Unexpect aCatch(SALOME_SalomeException);
3241 return _preMeshInfo->NbPolyhedrons();
3243 return _impl->NbPolyhedrons();
3246 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
3247 throw(SALOME::SALOME_Exception)
3249 Unexpect aCatch(SALOME_SalomeException);
3251 return _preMeshInfo->NbVolumes( (SMDSAbs_ElementOrder) order );
3253 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
3256 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
3257 throw(SALOME::SALOME_Exception)
3259 Unexpect aCatch(SALOME_SalomeException);