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_MeshEditor.hxx"
48 #include "SMESH_MeshEditor_i.hxx"
49 #include "SMESH_MeshPartDS.hxx"
50 #include "SMESH_MesherHelper.hxx"
51 #include "SMESH_PreMeshInfo.hxx"
52 #include "SMESH_PythonDump.hxx"
53 #include "SMESH_subMesh_i.hxx"
56 #include <SALOMEDS_Attributes_wrap.hxx>
57 #include <SALOMEDS_wrap.hxx>
58 #include <SALOME_NamingService.hxx>
59 #include <Utils_ExceptHandlers.hxx>
60 #include <Utils_SINGLETON.hxx>
61 #include <utilities.h>
63 #include <GEOMImpl_Types.hxx>
64 #include <GEOM_wrap.hxx>
67 #include <BRep_Builder.hxx>
68 #include <OSD_Directory.hxx>
69 #include <OSD_File.hxx>
70 #include <OSD_Path.hxx>
71 #include <OSD_Protection.hxx>
72 #include <Standard_OutOfMemory.hxx>
73 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
74 #include <TColStd_MapOfInteger.hxx>
75 #include <TColStd_SequenceOfInteger.hxx>
76 #include <TCollection_AsciiString.hxx>
78 #include <TopExp_Explorer.hxx>
79 #include <TopTools_MapIteratorOfMapOfShape.hxx>
80 #include <TopTools_MapOfShape.hxx>
81 #include <TopoDS_Compound.hxx>
83 #include "SMESH_TryCatch.hxx" // include after OCCT headers!
94 static int MYDEBUG = 0;
96 static int MYDEBUG = 0;
100 using SMESH::TPythonDump;
102 int SMESH_Mesh_i::_idGenerator = 0;
104 //=============================================================================
108 //=============================================================================
110 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
112 CORBA::Long studyId )
113 : SALOME::GenericObj_i( thePOA )
115 MESSAGE("SMESH_Mesh_i");
118 _id = _idGenerator++;
121 _previewEditor = NULL;
125 //=============================================================================
129 //=============================================================================
131 SMESH_Mesh_i::~SMESH_Mesh_i()
133 MESSAGE("~SMESH_Mesh_i");
136 map<int, SMESH::SMESH_GroupBase_ptr>::iterator itGr;
137 for (itGr = _mapGroups.begin(); itGr != _mapGroups.end(); itGr++)
138 if (SMESH_GroupBase_i* aGroup = SMESH::DownCast<SMESH_GroupBase_i*>(itGr->second))
140 aGroup->UnRegister();
141 SMESH::SMESH_GroupBase_var( itGr->second );
146 map<int, SMESH::SMESH_subMesh_ptr>::iterator itSM;
147 for ( itSM = _mapSubMeshIor.begin(); itSM != _mapSubMeshIor.end(); itSM++ )
148 if ( SMESH_subMesh_i* aSubMesh = SMESH::DownCast<SMESH_subMesh_i*>( itSM->second ))
150 aSubMesh->UnRegister();
151 SMESH::SMESH_subMesh_var( itSM->second );
153 _mapSubMeshIor.clear();
155 // destroy hypotheses. _mapHypo contains all hyps ever been assigned
156 map<int, SMESH::SMESH_Hypothesis_ptr>::iterator itH;
157 for ( itH = _mapHypo.begin(); itH != _mapHypo.end(); itH++ ) {
158 if ( SMESH_Hypothesis_i* hyp_i = SMESH::DownCast<SMESH_Hypothesis_i*>( itH->second ))
159 if ( SMESH_Hypothesis * smHyp = _impl->GetHypothesis( itH->first ))
160 if ( _impl->GetMeshDS()->IsUsedHypothesis( smHyp ))
163 SMESH::SMESH_Hypothesis_var( itH->second ); // decref CORBA object
167 delete _editor; _editor = NULL;
168 delete _previewEditor; _previewEditor = NULL;
169 delete _impl; _impl = NULL;
170 delete _preMeshInfo; _preMeshInfo = NULL;
173 //=============================================================================
177 * Associates <this> mesh with <theShape> and puts a reference
178 * to <theShape> into the current study;
179 * the previous shape is substituted by the new one.
181 //=============================================================================
183 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
184 throw (SALOME::SALOME_Exception)
186 Unexpect aCatch(SALOME_SalomeException);
188 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
190 catch(SALOME_Exception & S_ex) {
191 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
193 // to track changes of GEOM groups
194 SMESH::SMESH_Mesh_var mesh = _this();
195 addGeomGroupData( theShapeObject, mesh );
198 //================================================================================
200 * \brief return true if mesh has a shape to build a shape on
202 //================================================================================
204 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
205 throw (SALOME::SALOME_Exception)
207 Unexpect aCatch(SALOME_SalomeException);
210 res = _impl->HasShapeToMesh();
212 catch(SALOME_Exception & S_ex) {
213 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
218 //=======================================================================
219 //function : GetShapeToMesh
221 //=======================================================================
223 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
224 throw (SALOME::SALOME_Exception)
226 Unexpect aCatch(SALOME_SalomeException);
227 GEOM::GEOM_Object_var aShapeObj;
229 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
231 aShapeObj = _gen_i->ShapeToGeomObject( S );
233 catch(SALOME_Exception & S_ex) {
234 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
236 return aShapeObj._retn();
239 //================================================================================
241 * \brief Return false if the mesh is not yet fully loaded from the study file
243 //================================================================================
245 CORBA::Boolean SMESH_Mesh_i::IsLoaded() throw (SALOME::SALOME_Exception)
247 Unexpect aCatch(SALOME_SalomeException);
248 return !_preMeshInfo;
251 //================================================================================
253 * \brief Load full mesh data from the study file
255 //================================================================================
257 void SMESH_Mesh_i::Load() throw (SALOME::SALOME_Exception)
259 Unexpect aCatch(SALOME_SalomeException);
261 _preMeshInfo->FullLoadFromFile();
264 //================================================================================
266 * \brief Remove all nodes and elements
268 //================================================================================
270 void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
272 Unexpect aCatch(SALOME_SalomeException);
274 _preMeshInfo->ForgetAllData();
278 CheckGeomGroupModif(); // issue 20145
280 catch(SALOME_Exception & S_ex) {
281 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
283 _impl->GetMeshDS()->Modified();
285 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".Clear()";
288 //================================================================================
290 * \brief Remove all nodes and elements for indicated shape
292 //================================================================================
294 void SMESH_Mesh_i::ClearSubMesh(CORBA::Long ShapeID)
295 throw (SALOME::SALOME_Exception)
297 Unexpect aCatch(SALOME_SalomeException);
299 _preMeshInfo->FullLoadFromFile();
302 _impl->ClearSubMesh( ShapeID );
304 catch(SALOME_Exception & S_ex) {
305 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
307 _impl->GetMeshDS()->Modified();
309 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ClearSubMesh( " << ShapeID << " )";
312 //=============================================================================
314 * Convert enum Driver_Mesh::Status to SMESH::DriverMED_ReadStatus
316 //=============================================================================
318 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
320 SMESH::DriverMED_ReadStatus res;
323 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
324 res = SMESH::DRS_OK; break;
325 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
326 res = SMESH::DRS_EMPTY; break;
327 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
328 res = SMESH::DRS_WARN_RENUMBER; break;
329 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
330 res = SMESH::DRS_WARN_SKIP_ELEM; break;
331 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_DESCENDING:
332 res = SMESH::DRS_WARN_DESCENDING; break;
333 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
335 res = SMESH::DRS_FAIL; break;
340 //=============================================================================
342 * Convert ::SMESH_ComputeError to SMESH::ComputeError
344 //=============================================================================
346 static SMESH::ComputeError* ConvertComputeError( SMESH_ComputeErrorPtr errorPtr )
348 SMESH::ComputeError_var errVar = new SMESH::ComputeError();
349 errVar->subShapeID = -1;
350 errVar->hasBadMesh = false;
352 if ( !errorPtr || errorPtr->IsOK() )
354 errVar->code = SMESH::COMPERR_OK;
358 errVar->code = ConvertDriverMEDReadStatus( errorPtr->myName );
359 errVar->comment = errorPtr->myComment.c_str();
361 return errVar._retn();
364 //=============================================================================
368 * Imports mesh data from MED file
370 //=============================================================================
372 SMESH::DriverMED_ReadStatus
373 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
374 throw ( SALOME::SALOME_Exception )
376 Unexpect aCatch(SALOME_SalomeException);
379 status = _impl->MEDToMesh( theFileName, theMeshName );
381 catch( SALOME_Exception& S_ex ) {
382 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
385 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
388 CreateGroupServants();
390 int major, minor, release;
391 if( !MED::getMEDVersion( theFileName, major, minor, release ) )
392 major = minor = release = -1;
393 _medFileInfo = new SMESH::MedFileInfo();
394 _medFileInfo->fileName = theFileName;
395 _medFileInfo->fileSize = 0;
396 _medFileInfo->major = major;
397 _medFileInfo->minor = minor;
398 _medFileInfo->release = release;
401 if ( ::_stati64( theFileName, &d ) != -1 )
404 if ( ::stat64( theFileName, &d ) != -1 )
406 _medFileInfo->fileSize = d.st_size;
408 return ConvertDriverMEDReadStatus(status);
411 //================================================================================
413 * \brief Imports mesh data from the CGNS file
415 //================================================================================
417 SMESH::DriverMED_ReadStatus SMESH_Mesh_i::ImportCGNSFile( const char* theFileName,
418 const int theMeshIndex,
419 std::string& theMeshName )
420 throw ( SALOME::SALOME_Exception )
422 Unexpect aCatch(SALOME_SalomeException);
425 status = _impl->CGNSToMesh( theFileName, theMeshIndex, theMeshName );
427 catch( SALOME_Exception& S_ex ) {
428 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
431 THROW_SALOME_CORBA_EXCEPTION("ImportCGNSFile(): unknown exception", SALOME::BAD_PARAM);
434 CreateGroupServants();
436 return ConvertDriverMEDReadStatus(status);
439 //================================================================================
441 * \brief Return string representation of a MED file version comprising nbDigits
443 //================================================================================
445 char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits)
447 string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(MED::EVersion(version),
449 return CORBA::string_dup( ver.c_str() );
452 //=============================================================================
456 * Imports mesh data from MED file
458 //=============================================================================
460 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
461 throw ( SALOME::SALOME_Exception )
465 // Read mesh with name = <theMeshName> into SMESH_Mesh
466 _impl->UNVToMesh( theFileName );
468 CreateGroupServants();
470 SMESH_CATCH( SMESH::throwCorbaException );
475 //=============================================================================
479 * Imports mesh data from STL file
481 //=============================================================================
482 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
483 throw ( SALOME::SALOME_Exception )
487 // Read mesh with name = <theMeshName> into SMESH_Mesh
488 _impl->STLToMesh( theFileName );
490 SMESH_CATCH( SMESH::throwCorbaException );
495 //================================================================================
497 * \brief Function used in SMESH_CATCH by ImportGMFFile()
499 //================================================================================
503 SMESH_ComputeErrorPtr exceptionToComputeError(const char* excText)
505 return SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, excText );
509 //================================================================================
511 * \brief Imports data from a GMF file and returns an error description
513 //================================================================================
515 SMESH::ComputeError* SMESH_Mesh_i::ImportGMFFile( const char* theFileName,
516 bool theMakeRequiredGroups )
517 throw (SALOME::SALOME_Exception)
519 SMESH_ComputeErrorPtr error;
522 #define SMESH_CAUGHT error =
525 error = _impl->GMFToMesh( theFileName, theMakeRequiredGroups );
527 SMESH_CATCH( exceptionToComputeError );
531 CreateGroupServants();
533 return ConvertComputeError( error );
536 //=============================================================================
540 //=============================================================================
542 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
544 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
545 (SMESH_Hypothesis::Hypothesis_Status theStatus)
548 RETURNCASE( HYP_OK );
549 RETURNCASE( HYP_MISSING );
550 RETURNCASE( HYP_CONCURENT );
551 RETURNCASE( HYP_BAD_PARAMETER );
552 RETURNCASE( HYP_HIDDEN_ALGO );
553 RETURNCASE( HYP_HIDING_ALGO );
554 RETURNCASE( HYP_UNKNOWN_FATAL );
555 RETURNCASE( HYP_INCOMPATIBLE );
556 RETURNCASE( HYP_NOTCONFORM );
557 RETURNCASE( HYP_ALREADY_EXIST );
558 RETURNCASE( HYP_BAD_DIM );
559 RETURNCASE( HYP_BAD_SUBSHAPE );
560 RETURNCASE( HYP_BAD_GEOMETRY );
561 RETURNCASE( HYP_NEED_SHAPE );
564 return SMESH::HYP_UNKNOWN_FATAL;
567 //=============================================================================
571 * calls internal addHypothesis() and then adds a reference to <anHyp> under
572 * the SObject actually having a reference to <aSubShape>.
573 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
575 //=============================================================================
577 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
578 SMESH::SMESH_Hypothesis_ptr anHyp)
579 throw(SALOME::SALOME_Exception)
581 Unexpect aCatch(SALOME_SalomeException);
583 _preMeshInfo->ForgetOrLoad();
585 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
587 SMESH::SMESH_Mesh_var mesh( _this() );
588 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
590 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
591 _gen_i->AddHypothesisToShape( study, mesh, aSubShapeObject, anHyp );
593 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
595 // Update Python script
596 //if(_impl->HasShapeToMesh())
598 TPythonDump() << "status = " << mesh << ".AddHypothesis( "
599 << aSubShapeObject << ", " << anHyp << " )";
602 // TPythonDump() << "status = " << mesh << ".AddHypothesis( "<< anHyp << " )";
605 return ConvertHypothesisStatus(status);
608 //=============================================================================
612 //=============================================================================
614 SMESH_Hypothesis::Hypothesis_Status
615 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
616 SMESH::SMESH_Hypothesis_ptr anHyp)
618 if(MYDEBUG) MESSAGE("addHypothesis");
620 if (CORBA::is_nil( aSubShapeObject ) && HasShapeToMesh())
621 THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference",SALOME::BAD_PARAM);
623 if (CORBA::is_nil( anHyp ))
624 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",SALOME::BAD_PARAM);
626 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
629 TopoDS_Shape myLocSubShape;
630 //use PseudoShape in case if mesh has no shape
632 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
634 myLocSubShape = _impl->GetShapeToMesh();
636 const int hypId = anHyp->GetId();
637 status = _impl->AddHypothesis(myLocSubShape, hypId);
638 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
639 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( anHyp );
641 // assure there is a corresponding submesh
642 if ( !_impl->IsMainShape( myLocSubShape )) {
643 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
644 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
645 SMESH::SMESH_subMesh_var( createSubMesh( aSubShapeObject ));
649 catch(SALOME_Exception & S_ex)
651 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
656 //=============================================================================
660 //=============================================================================
662 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
663 SMESH::SMESH_Hypothesis_ptr anHyp)
664 throw(SALOME::SALOME_Exception)
666 Unexpect aCatch(SALOME_SalomeException);
668 _preMeshInfo->ForgetOrLoad();
670 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
671 SMESH::SMESH_Mesh_var mesh = _this();
673 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
675 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
676 _gen_i->RemoveHypothesisFromShape( study, mesh, aSubShapeObject, anHyp );
678 // Update Python script
679 if(_impl->HasShapeToMesh())
680 TPythonDump() << "status = " << mesh << ".RemoveHypothesis( "
681 << aSubShapeObject << ", " << anHyp << " )";
683 TPythonDump() << "status = " << mesh << ".RemoveHypothesis( "
686 return ConvertHypothesisStatus(status);
689 //=============================================================================
693 //=============================================================================
695 SMESH_Hypothesis::Hypothesis_Status
696 SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
697 SMESH::SMESH_Hypothesis_ptr anHyp)
699 if(MYDEBUG) MESSAGE("removeHypothesis()");
701 if (CORBA::is_nil( aSubShapeObject ) && HasShapeToMesh())
702 THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference", SALOME::BAD_PARAM);
704 if (CORBA::is_nil( anHyp ))
705 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference", SALOME::BAD_PARAM);
707 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
710 TopoDS_Shape myLocSubShape;
711 //use PseudoShape in case if mesh has no shape
712 if( _impl->HasShapeToMesh() )
713 myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject );
715 myLocSubShape = _impl->GetShapeToMesh();
717 const int hypId = anHyp->GetId();
718 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
719 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
721 // _mapHypo.erase( hypId ); EAP: hyp can be used on many sub-shapes
725 catch(SALOME_Exception & S_ex)
727 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
732 //=============================================================================
736 //=============================================================================
738 SMESH::ListOfHypothesis *
739 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
740 throw(SALOME::SALOME_Exception)
742 Unexpect aCatch(SALOME_SalomeException);
743 if (MYDEBUG) MESSAGE("GetHypothesisList");
744 if (_impl->HasShapeToMesh() && CORBA::is_nil(aSubShapeObject))
745 THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference", SALOME::BAD_PARAM);
747 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
750 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
751 if ( myLocSubShape.IsNull() && !_impl->HasShapeToMesh() )
752 myLocSubShape = _impl->GetShapeToMesh();
753 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
754 int i = 0, n = aLocalList.size();
757 list<const SMESHDS_Hypothesis*>::const_iterator aHyp = aLocalList.begin();
758 std::map<int, SMESH::SMESH_Hypothesis_ptr>::iterator id_hypptr;
759 for ( ; i < n && aHyp != aLocalList.end(); aHyp++ )
761 id_hypptr = _mapHypo.find( (*aHyp)->GetID() );
762 if ( id_hypptr != _mapHypo.end() )
763 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( id_hypptr->second );
767 catch(SALOME_Exception & S_ex) {
768 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
771 return aList._retn();
774 SMESH::submesh_array* SMESH_Mesh_i::GetSubMeshes() throw (SALOME::SALOME_Exception)
776 Unexpect aCatch(SALOME_SalomeException);
777 if (MYDEBUG) MESSAGE("GetSubMeshes");
779 SMESH::submesh_array_var aList = new SMESH::submesh_array();
782 TPythonDump aPythonDump;
783 if ( !_mapSubMeshIor.empty() )
787 aList->length( _mapSubMeshIor.size() );
789 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.begin();
790 for ( ; it != _mapSubMeshIor.end(); it++ ) {
791 if ( CORBA::is_nil( it->second )) continue;
792 aList[i++] = SMESH::SMESH_subMesh::_duplicate( it->second );
794 if (i > 1) aPythonDump << ", ";
795 aPythonDump << it->second;
799 catch(SALOME_Exception & S_ex) {
800 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
803 // Update Python script
804 if ( !_mapSubMeshIor.empty() )
805 aPythonDump << " ] = " << SMESH::SMESH_Mesh_var( _this() ) << ".GetSubMeshes()";
807 return aList._retn();
810 //=============================================================================
814 //=============================================================================
816 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
817 const char* theName )
818 throw(SALOME::SALOME_Exception)
820 Unexpect aCatch(SALOME_SalomeException);
821 if (CORBA::is_nil(aSubShapeObject))
822 THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference", SALOME::BAD_PARAM);
824 SMESH::SMESH_subMesh_var subMesh;
825 SMESH::SMESH_Mesh_var aMesh = _this();
827 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
829 //Get or Create the SMESH_subMesh object implementation
831 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
833 if ( !subMeshId && ! _impl->GetMeshDS()->IsGroupOfSubShapes( myLocSubShape ))
835 TopoDS_Iterator it( myLocSubShape );
837 THROW_SALOME_CORBA_EXCEPTION("not sub-shape of the main shape", SALOME::BAD_PARAM);
839 subMesh = getSubMesh( subMeshId );
841 // create a new subMesh object servant if there is none for the shape
842 if ( subMesh->_is_nil() )
843 subMesh = createSubMesh( aSubShapeObject );
844 if ( _gen_i->CanPublishInStudy( subMesh ))
846 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
847 SALOMEDS::SObject_wrap aSO =
848 _gen_i->PublishSubMesh( study, aMesh, subMesh, aSubShapeObject, theName );
849 if ( !aSO->_is_nil()) {
850 // Update Python script
851 TPythonDump() << aSO << " = " << aMesh << ".GetSubMesh( "
852 << aSubShapeObject << ", '" << theName << "' )";
856 catch(SALOME_Exception & S_ex) {
857 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
859 return subMesh._retn();
862 //=============================================================================
866 //=============================================================================
868 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
869 throw (SALOME::SALOME_Exception)
873 if ( theSubMesh->_is_nil() )
876 GEOM::GEOM_Object_var aSubShapeObject;
877 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
878 if ( !aStudy->_is_nil() ) {
879 // Remove submesh's SObject
880 SALOMEDS::SObject_wrap anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
881 if ( !anSO->_is_nil() ) {
882 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
883 SALOMEDS::SObject_wrap anObj, aRef;
884 if ( anSO->FindSubObject( aTag, anObj.inout() ) &&
885 anObj->ReferencedObject( aRef.inout() ))
887 CORBA::Object_var obj = aRef->GetObject();
888 aSubShapeObject = GEOM::GEOM_Object::_narrow( obj );
890 // if ( aSubShapeObject->_is_nil() ) // not published shape (IPAL13617)
891 // aSubShapeObject = theSubMesh->GetSubShape();
893 SALOMEDS::StudyBuilder_var builder = aStudy->NewBuilder();
894 builder->RemoveObjectWithChildren( anSO );
896 // Update Python script
897 TPythonDump() << SMESH::SMESH_Mesh_var( _this() ) << ".RemoveSubMesh( " << anSO << " )";
901 if ( removeSubMesh( theSubMesh, aSubShapeObject.in() ))
903 _preMeshInfo->ForgetOrLoad();
905 SMESH_CATCH( SMESH::throwCorbaException );
908 //=============================================================================
912 //=============================================================================
914 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
915 const char* theName )
916 throw(SALOME::SALOME_Exception)
918 Unexpect aCatch(SALOME_SalomeException);
920 _preMeshInfo->FullLoadFromFile();
922 SMESH::SMESH_Group_var aNewGroup =
923 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
925 if ( _gen_i->CanPublishInStudy( aNewGroup ) )
927 SMESH::SMESH_Mesh_var mesh = _this();
928 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
929 SALOMEDS::SObject_wrap aSO =
930 _gen_i->PublishGroup( study, mesh, aNewGroup, GEOM::GEOM_Object::_nil(), theName);
931 if ( !aSO->_is_nil())
932 // Update Python script
933 TPythonDump() << aSO << " = " << mesh << ".CreateGroup( "
934 << theElemType << ", '" << theName << "' )";
936 return aNewGroup._retn();
939 //=============================================================================
943 //=============================================================================
944 SMESH::SMESH_GroupOnGeom_ptr
945 SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
947 GEOM::GEOM_Object_ptr theGeomObj)
948 throw(SALOME::SALOME_Exception)
950 Unexpect aCatch(SALOME_SalomeException);
952 _preMeshInfo->FullLoadFromFile();
954 SMESH::SMESH_GroupOnGeom_var aNewGroup;
956 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
957 if ( !aShape.IsNull() )
960 SMESH::SMESH_GroupOnGeom::_narrow( createGroup( theElemType, theName, aShape ));
962 if ( _gen_i->CanPublishInStudy( aNewGroup ) )
964 SMESH::SMESH_Mesh_var mesh = _this();
965 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
966 SALOMEDS::SObject_wrap aSO =
967 _gen_i->PublishGroup( study, mesh, aNewGroup, theGeomObj, theName );
968 if ( !aSO->_is_nil())
969 TPythonDump() << aSO << " = " << mesh << ".CreateGroupFromGEOM( "
970 << theElemType << ", '" << theName << "', " << theGeomObj << " )";
974 return aNewGroup._retn();
977 //================================================================================
979 * \brief Creates a group whose contents is defined by filter
980 * \param theElemType - group type
981 * \param theName - group name
982 * \param theFilter - the filter
983 * \retval SMESH::SMESH_GroupOnFilter_ptr - group defined by filter
985 //================================================================================
987 SMESH::SMESH_GroupOnFilter_ptr
988 SMESH_Mesh_i::CreateGroupFromFilter(SMESH::ElementType theElemType,
990 SMESH::Filter_ptr theFilter )
991 throw (SALOME::SALOME_Exception)
993 Unexpect aCatch(SALOME_SalomeException);
995 _preMeshInfo->FullLoadFromFile();
997 if ( CORBA::is_nil( theFilter ))
998 THROW_SALOME_CORBA_EXCEPTION("NULL filter", SALOME::BAD_PARAM);
1000 SMESH_PredicatePtr predicate = SMESH_GroupOnFilter_i::GetPredicate( theFilter );
1002 THROW_SALOME_CORBA_EXCEPTION("Invalid filter", SALOME::BAD_PARAM);
1004 SMESH::SMESH_GroupOnFilter_var aNewGroup = SMESH::SMESH_GroupOnFilter::_narrow
1005 ( createGroup( theElemType, theName, TopoDS_Shape(), predicate ));
1008 if ( !aNewGroup->_is_nil() )
1009 aNewGroup->SetFilter( theFilter );
1011 if ( _gen_i->CanPublishInStudy( aNewGroup ) )
1013 SMESH::SMESH_Mesh_var mesh = _this();
1014 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1015 SALOMEDS::SObject_wrap aSO =
1016 _gen_i->PublishGroup( study, mesh, aNewGroup, GEOM::GEOM_Object::_nil(), theName );
1018 if ( !aSO->_is_nil())
1019 pd << aSO << " = " << mesh << ".CreateGroupFromFilter( "
1020 << theElemType << ", '" << theName << "', " << theFilter << " )";
1022 return aNewGroup._retn();
1025 //=============================================================================
1029 //=============================================================================
1031 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
1032 throw (SALOME::SALOME_Exception)
1034 if ( theGroup->_is_nil() )
1039 SMESH_GroupBase_i* aGroup = SMESH::DownCast<SMESH_GroupBase_i*>( theGroup );
1043 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
1044 if ( !aStudy->_is_nil() )
1046 SALOMEDS::SObject_wrap aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
1047 if ( !aGroupSO->_is_nil() )
1049 // Update Python script
1050 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".RemoveGroup( " << aGroupSO << " )";
1052 // Remove group's SObject
1053 SALOMEDS::StudyBuilder_var builder = aStudy->NewBuilder();
1054 builder->RemoveObjectWithChildren( aGroupSO );
1058 // Remove the group from SMESH data structures
1059 removeGroup( aGroup->GetLocalID() );
1061 SMESH_CATCH( SMESH::throwCorbaException );
1064 //=============================================================================
1066 * Remove group with its contents
1068 //=============================================================================
1070 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
1071 throw (SALOME::SALOME_Exception)
1075 _preMeshInfo->FullLoadFromFile();
1077 if ( theGroup->_is_nil() )
1081 SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( theGroup );
1082 SMDS_ElemIteratorPtr elemIt = GetElements( idSrc, theGroup->GetType() );
1083 while ( elemIt->more() )
1084 _impl->GetMeshDS()->RemoveElement( elemIt->next() );
1086 TPythonDump pyDump; // Supress dump from RemoveGroup()
1088 // Update Python script (theGroup must be alive for this)
1089 pyDump << SMESH::SMESH_Mesh_var(_this())
1090 << ".RemoveGroupWithContents( " << theGroup << " )";
1093 RemoveGroup( theGroup );
1095 SMESH_CATCH( SMESH::throwCorbaException );
1098 //================================================================================
1100 * \brief Get the list of groups existing in the mesh
1101 * \retval SMESH::ListOfGroups * - list of groups
1103 //================================================================================
1105 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
1107 Unexpect aCatch(SALOME_SalomeException);
1108 if (MYDEBUG) MESSAGE("GetGroups");
1110 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
1113 TPythonDump aPythonDump;
1114 if ( !_mapGroups.empty() )
1116 aPythonDump << "[ ";
1118 aList->length( _mapGroups.size() );
1120 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
1121 for ( ; it != _mapGroups.end(); it++ ) {
1122 if ( CORBA::is_nil( it->second )) continue;
1123 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
1125 if (i > 1) aPythonDump << ", ";
1126 aPythonDump << it->second;
1130 catch(SALOME_Exception & S_ex) {
1131 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1133 aPythonDump << " ] = " << SMESH::SMESH_Mesh_var(_this()) << ".GetGroups()";
1135 return aList._retn();
1138 //=============================================================================
1140 * Get number of groups existing in the mesh
1142 //=============================================================================
1144 CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
1146 Unexpect aCatch(SALOME_SalomeException);
1147 return _mapGroups.size();
1150 //=============================================================================
1152 * New group including all mesh elements present in initial groups is created.
1154 //=============================================================================
1156 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1157 SMESH::SMESH_GroupBase_ptr theGroup2,
1158 const char* theName )
1159 throw (SALOME::SALOME_Exception)
1161 SMESH::SMESH_Group_var aResGrp;
1165 _preMeshInfo->FullLoadFromFile();
1167 if ( theGroup1->_is_nil() || theGroup2->_is_nil() )
1168 THROW_SALOME_CORBA_EXCEPTION("UnionGroups(): NULL Group",
1170 if ( theGroup1->GetType() != theGroup2->GetType() )
1171 THROW_SALOME_CORBA_EXCEPTION("UnionGroups(): different group types",
1176 aResGrp = CreateGroup( theGroup1->GetType(), theName );
1177 if ( aResGrp->_is_nil() )
1178 return SMESH::SMESH_Group::_nil();
1180 aResGrp->AddFrom( theGroup1 );
1181 aResGrp->AddFrom( theGroup2 );
1183 // Update Python script
1184 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var(_this())
1185 << ".UnionGroups( " << theGroup1 << ", " << theGroup2 << ", '" << theName << "' )";
1187 SMESH_CATCH( SMESH::throwCorbaException );
1189 return aResGrp._retn();
1192 //=============================================================================
1194 * \brief New group including all mesh elements present in initial groups is created.
1195 * \param theGroups list of groups
1196 * \param theName name of group to be created
1197 * \return pointer to the new group
1199 //=============================================================================
1201 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionListOfGroups(const SMESH::ListOfGroups& theGroups,
1202 const char* theName )
1203 throw (SALOME::SALOME_Exception)
1205 SMESH::SMESH_Group_var aResGrp;
1208 _preMeshInfo->FullLoadFromFile();
1211 return SMESH::SMESH_Group::_nil();
1216 SMESH::ElementType aType = SMESH::ALL;
1217 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1219 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1220 if ( CORBA::is_nil( aGrp ) )
1222 if ( aType == SMESH::ALL )
1223 aType = aGrp->GetType();
1224 else if ( aType != aGrp->GetType() )
1225 THROW_SALOME_CORBA_EXCEPTION("UnionListOfGroups(): different group types",
1228 if ( aType == SMESH::ALL )
1229 return SMESH::SMESH_Group::_nil();
1234 aResGrp = CreateGroup( aType, theName );
1235 if ( aResGrp->_is_nil() )
1236 return SMESH::SMESH_Group::_nil();
1238 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var(_this()) << ".UnionListOfGroups([ ";
1239 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1241 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1242 if ( !CORBA::is_nil( aGrp ) )
1244 aResGrp->AddFrom( aGrp );
1245 if ( g > 0 ) pyDump << ", ";
1249 pyDump << " ], '" << theName << "' )";
1251 SMESH_CATCH( SMESH::throwCorbaException );
1253 return aResGrp._retn();
1256 //=============================================================================
1258 * New group is created. All mesh elements that are
1259 * present in both initial groups are added to the new one.
1261 //=============================================================================
1263 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1264 SMESH::SMESH_GroupBase_ptr theGroup2,
1265 const char* theName )
1266 throw (SALOME::SALOME_Exception)
1268 SMESH::SMESH_Group_var aResGrp;
1273 _preMeshInfo->FullLoadFromFile();
1275 if ( theGroup1->_is_nil() || theGroup2->_is_nil() )
1276 THROW_SALOME_CORBA_EXCEPTION("IntersectGroups(): NULL Group",
1278 if ( theGroup1->GetType() != theGroup2->GetType() )
1279 THROW_SALOME_CORBA_EXCEPTION("IntersectGroups(): different group types",
1283 // Create Intersection
1284 aResGrp = CreateGroup( theGroup1->GetType(), theName );
1285 if ( aResGrp->_is_nil() )
1286 return aResGrp._retn();
1288 SMESHDS_GroupBase* groupDS1 = 0;
1289 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup1 ))
1290 groupDS1 = grp_i->GetGroupDS();
1292 SMESHDS_GroupBase* groupDS2 = 0;
1293 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup2 ))
1294 groupDS2 = grp_i->GetGroupDS();
1296 SMESHDS_Group* resGroupDS = 0;
1297 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aResGrp ))
1298 resGroupDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() );
1300 if ( groupDS1 && groupDS2 && resGroupDS && !groupDS2->IsEmpty() )
1302 SMDS_ElemIteratorPtr elemIt1 = groupDS1->GetElements();
1303 while ( elemIt1->more() )
1305 const SMDS_MeshElement* e = elemIt1->next();
1306 if ( groupDS2->Contains( e ))
1307 resGroupDS->SMDSGroup().Add( e );
1310 // Update Python script
1311 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var(_this()) << ".IntersectGroups( "
1312 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
1314 SMESH_CATCH( SMESH::throwCorbaException );
1316 return aResGrp._retn();
1319 //=============================================================================
1321 \brief Intersect list of groups. New group is created. All mesh elements that
1322 are present in all initial groups simultaneously are added to the new one.
1323 \param theGroups list of groups
1324 \param theName name of group to be created
1325 \return pointer on the group
1327 //=============================================================================
1328 SMESH::SMESH_Group_ptr
1329 SMESH_Mesh_i::IntersectListOfGroups(const SMESH::ListOfGroups& theGroups,
1330 const char* theName )
1331 throw (SALOME::SALOME_Exception)
1333 SMESH::SMESH_Group_var aResGrp;
1338 _preMeshInfo->FullLoadFromFile();
1341 return SMESH::SMESH_Group::_nil();
1343 // check types and get SMESHDS_GroupBase's
1344 SMESH::ElementType aType = SMESH::ALL;
1345 vector< SMESHDS_GroupBase* > groupVec;
1346 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1348 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1349 if ( CORBA::is_nil( aGrp ) )
1351 if ( aType == SMESH::ALL )
1352 aType = aGrp->GetType();
1353 else if ( aType != aGrp->GetType() )
1354 THROW_SALOME_CORBA_EXCEPTION("IntersectListOfGroups(): different group types",
1357 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aGrp ))
1358 if ( SMESHDS_GroupBase* grpDS = grp_i->GetGroupDS() )
1360 if ( grpDS->IsEmpty() )
1365 groupVec.push_back( grpDS );
1368 if ( aType == SMESH::ALL ) // all groups are nil
1369 return SMESH::SMESH_Group::_nil();
1374 aResGrp = CreateGroup( aType, theName );
1376 SMESHDS_Group* resGroupDS = 0;
1377 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aResGrp ))
1378 resGroupDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() );
1379 if ( !resGroupDS || groupVec.empty() )
1380 return aResGrp._retn();
1383 size_t i, nb = groupVec.size();
1384 SMDS_ElemIteratorPtr elemIt1 = groupVec[0]->GetElements();
1385 while ( elemIt1->more() )
1387 const SMDS_MeshElement* e = elemIt1->next();
1389 for ( i = 1; ( i < nb && inAll ); ++i )
1390 inAll = groupVec[i]->Contains( e );
1393 resGroupDS->SMDSGroup().Add( e );
1396 // Update Python script
1397 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var( _this() )
1398 << ".IntersectListOfGroups( " << theGroups << ", '" << theName << "' )";
1400 SMESH_CATCH( SMESH::throwCorbaException );
1402 return aResGrp._retn();
1405 //=============================================================================
1407 * New group is created. All mesh elements that are present in
1408 * a main group but is not present in a tool group are added to the new one
1410 //=============================================================================
1412 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1413 SMESH::SMESH_GroupBase_ptr theGroup2,
1414 const char* theName )
1415 throw (SALOME::SALOME_Exception)
1417 SMESH::SMESH_Group_var aResGrp;
1422 _preMeshInfo->FullLoadFromFile();
1424 if ( theGroup1->_is_nil() || theGroup2->_is_nil() )
1425 THROW_SALOME_CORBA_EXCEPTION("CutGroups(): NULL Group",
1427 if ( theGroup1->GetType() != theGroup2->GetType() )
1428 THROW_SALOME_CORBA_EXCEPTION("CutGroups(): different group types",
1432 aResGrp = CreateGroup( theGroup1->GetType(), theName );
1433 if ( aResGrp->_is_nil() )
1434 return aResGrp._retn();
1436 SMESHDS_GroupBase* groupDS1 = 0;
1437 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup1 ))
1438 groupDS1 = grp_i->GetGroupDS();
1440 SMESHDS_GroupBase* groupDS2 = 0;
1441 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup2 ))
1442 groupDS2 = grp_i->GetGroupDS();
1444 SMESHDS_Group* resGroupDS = 0;
1445 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aResGrp ))
1446 resGroupDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() );
1448 if ( groupDS1 && groupDS2 && resGroupDS )
1450 SMDS_ElemIteratorPtr elemIt1 = groupDS1->GetElements();
1451 while ( elemIt1->more() )
1453 const SMDS_MeshElement* e = elemIt1->next();
1454 if ( !groupDS2->Contains( e ))
1455 resGroupDS->SMDSGroup().Add( e );
1458 // Update Python script
1459 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var(_this()) << ".CutGroups( "
1460 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
1462 SMESH_CATCH( SMESH::throwCorbaException );
1464 return aResGrp._retn();
1467 //=============================================================================
1469 \brief Cut lists of groups. New group is created. All mesh elements that are
1470 present in main groups but do not present in tool groups are added to the new one
1471 \param theMainGroups list of main groups
1472 \param theToolGroups list of tool groups
1473 \param theName name of group to be created
1474 \return pointer on the group
1476 //=============================================================================
1477 SMESH::SMESH_Group_ptr
1478 SMESH_Mesh_i::CutListOfGroups(const SMESH::ListOfGroups& theMainGroups,
1479 const SMESH::ListOfGroups& theToolGroups,
1480 const char* theName )
1481 throw (SALOME::SALOME_Exception)
1483 SMESH::SMESH_Group_var aResGrp;
1488 _preMeshInfo->FullLoadFromFile();
1491 return SMESH::SMESH_Group::_nil();
1493 // check types and get SMESHDS_GroupBase's
1494 SMESH::ElementType aType = SMESH::ALL;
1495 vector< SMESHDS_GroupBase* > toolGroupVec;
1496 vector< SMDS_ElemIteratorPtr > mainIterVec;
1498 for ( int g = 0, n = theMainGroups.length(); g < n; g++ )
1500 SMESH::SMESH_GroupBase_var aGrp = theMainGroups[ g ];
1501 if ( CORBA::is_nil( aGrp ) )
1503 if ( aType == SMESH::ALL )
1504 aType = aGrp->GetType();
1505 else if ( aType != aGrp->GetType() )
1506 THROW_SALOME_CORBA_EXCEPTION("UnionListOfGroups(): different group types",
1508 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aGrp ))
1509 if ( SMESHDS_GroupBase* grpDS = grp_i->GetGroupDS() )
1510 if ( !grpDS->IsEmpty() )
1511 mainIterVec.push_back( grpDS->GetElements() );
1513 if ( aType == SMESH::ALL ) // all main groups are nil
1514 return SMESH::SMESH_Group::_nil();
1515 if ( mainIterVec.empty() ) // all main groups are empty
1516 return aResGrp._retn();
1518 for ( int g = 0, n = theToolGroups.length(); g < n; g++ )
1520 SMESH::SMESH_GroupBase_var aGrp = theToolGroups[ g ];
1521 if ( CORBA::is_nil( aGrp ) )
1523 if ( aType != aGrp->GetType() )
1524 THROW_SALOME_CORBA_EXCEPTION("UnionListOfGroups(): different group types",
1526 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aGrp ))
1527 if ( SMESHDS_GroupBase* grpDS = grp_i->GetGroupDS() )
1528 toolGroupVec.push_back( grpDS );
1534 aResGrp = CreateGroup( aType, theName );
1536 SMESHDS_Group* resGroupDS = 0;
1537 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aResGrp ))
1538 resGroupDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() );
1540 return aResGrp._retn();
1543 size_t i, nb = toolGroupVec.size();
1544 SMDS_ElemIteratorPtr mainElemIt
1545 ( new SMDS_IteratorOnIterators
1546 < const SMDS_MeshElement*, vector< SMDS_ElemIteratorPtr > >( mainIterVec ));
1547 while ( mainElemIt->more() )
1549 const SMDS_MeshElement* e = mainElemIt->next();
1551 for ( i = 0; ( i < nb && !isIn ); ++i )
1552 isIn = toolGroupVec[i]->Contains( e );
1555 resGroupDS->SMDSGroup().Add( e );
1558 // Update Python script
1559 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var( _this() )
1560 << ".CutListOfGroups( " << theMainGroups
1561 << theToolGroups << ", '" << theName << "' )";
1563 SMESH_CATCH( SMESH::throwCorbaException );
1565 return aResGrp._retn();
1568 //=============================================================================
1570 \brief Create groups of entities from existing groups of superior dimensions
1572 1) extract all nodes from each group,
1573 2) combine all elements of specified dimension laying on these nodes.
1574 \param theGroups list of source groups
1575 \param theElemType dimension of elements
1576 \param theName name of new group
1577 \return pointer on new group
1581 //=============================================================================
1583 SMESH::SMESH_Group_ptr
1584 SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfGroups& theGroups,
1585 SMESH::ElementType theElemType,
1586 const char* theName )
1587 throw (SALOME::SALOME_Exception)
1589 SMESH::SMESH_Group_var aResGrp;
1593 _preMeshInfo->FullLoadFromFile();
1595 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
1597 if ( !theName || !aMeshDS )
1598 return SMESH::SMESH_Group::_nil();
1600 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)theElemType;
1606 aResGrp = CreateGroup( theElemType, theName );
1607 if ( aResGrp->_is_nil() )
1608 return SMESH::SMESH_Group::_nil();
1610 SMESHDS_GroupBase* groupBaseDS =
1611 SMESH::DownCast<SMESH_GroupBase_i*>( aResGrp )->GetGroupDS();
1612 SMDS_MeshGroup& resGroupCore = static_cast< SMESHDS_Group* >( groupBaseDS )->SMDSGroup();
1614 for ( int g = 0, n = theGroups.length(); g < n; g++ ) // loop on theGroups
1616 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1617 if ( CORBA::is_nil( aGrp ) )
1620 groupBaseDS = SMESH::DownCast<SMESH_GroupBase_i*>( aGrp )->GetGroupDS();
1621 SMDS_ElemIteratorPtr elIt = groupBaseDS->GetElements();
1623 if ( theElemType == SMESH::NODE ) // get all nodes of elements
1625 while ( elIt->more() ) {
1626 const SMDS_MeshElement* el = elIt->next();
1627 SMDS_ElemIteratorPtr nIt = el->nodesIterator();
1628 while ( nIt->more() )
1629 resGroupCore.Add( nIt->next() );
1632 else // get elements of theElemType based on nodes of every element of group
1634 while ( elIt->more() )
1636 const SMDS_MeshElement* el = elIt->next(); // an element of group
1637 TIDSortedElemSet elNodes( el->begin_nodes(), el->end_nodes() );
1638 TIDSortedElemSet checkedElems;
1639 SMDS_ElemIteratorPtr nIt = el->nodesIterator();
1640 while ( nIt->more() )
1642 const SMDS_MeshNode* n = static_cast<const SMDS_MeshNode*>( nIt->next() );
1643 SMDS_ElemIteratorPtr elOfTypeIt = n->GetInverseElementIterator( anElemType );
1644 // check nodes of elements of theElemType around el
1645 while ( elOfTypeIt->more() )
1647 const SMDS_MeshElement* elOfType = elOfTypeIt->next();
1648 if ( !checkedElems.insert( elOfType ).second ) continue;
1650 SMDS_ElemIteratorPtr nIt2 = elOfType->nodesIterator();
1651 bool allNodesOK = true;
1652 while ( nIt2->more() && allNodesOK )
1653 allNodesOK = elNodes.count( nIt2->next() );
1655 resGroupCore.Add( elOfType );
1662 // Update Python script
1663 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var( _this())
1664 << ".CreateDimGroup( "
1665 << theGroups << ", " << theElemType << ", '" << theName << "' )";
1667 SMESH_CATCH( SMESH::throwCorbaException );
1669 return aResGrp._retn();
1672 //================================================================================
1674 * \brief Remember GEOM group data
1676 //================================================================================
1678 void SMESH_Mesh_i::addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
1679 CORBA::Object_ptr theSmeshObj)
1681 if ( CORBA::is_nil( theGeomObj ) || theGeomObj->GetType() != GEOM_GROUP )
1684 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1685 SALOMEDS::SObject_wrap groupSO = _gen_i->ObjectToSObject( study, theGeomObj );
1686 if ( groupSO->_is_nil() )
1689 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1690 GEOM::GEOM_IGroupOperations_wrap groupOp =
1691 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1692 GEOM::ListOfLong_var ids = groupOp->GetObjects( theGeomObj );
1695 _geomGroupData.push_back( TGeomGroupData() );
1696 TGeomGroupData & groupData = _geomGroupData.back();
1698 CORBA::String_var entry = groupSO->GetID();
1699 groupData._groupEntry = entry.in();
1701 for ( int i = 0; i < ids->length(); ++i )
1702 groupData._indices.insert( ids[i] );
1704 groupData._smeshObject = CORBA::Object::_duplicate( theSmeshObj );
1707 //================================================================================
1709 * Remove GEOM group data relating to removed smesh object
1711 //================================================================================
1713 void SMESH_Mesh_i::removeGeomGroupData(CORBA::Object_ptr theSmeshObj)
1715 list<TGeomGroupData>::iterator
1716 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1717 for ( ; data != dataEnd; ++data ) {
1718 if ( theSmeshObj->_is_equivalent( data->_smeshObject )) {
1719 _geomGroupData.erase( data );
1725 //================================================================================
1727 * \brief Return new group contents if it has been changed and update group data
1729 //================================================================================
1731 TopoDS_Shape SMESH_Mesh_i::newGroupShape( TGeomGroupData & groupData)
1733 TopoDS_Shape newShape;
1736 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1737 if ( study->_is_nil() ) return newShape; // means "not changed"
1738 SALOMEDS::SObject_wrap groupSO = study->FindObjectID( groupData._groupEntry.c_str() );
1739 if ( !groupSO->_is_nil() )
1741 CORBA::Object_var groupObj = _gen_i->SObjectToObject( groupSO );
1742 if ( CORBA::is_nil( groupObj )) return newShape;
1743 GEOM::GEOM_Object_var geomGroup = GEOM::GEOM_Object::_narrow( groupObj );
1745 // get indices of group items
1746 set<int> curIndices;
1747 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
1748 GEOM::GEOM_IGroupOperations_wrap groupOp =
1749 geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
1750 GEOM::ListOfLong_var ids = groupOp->GetObjects( geomGroup );
1751 for ( int i = 0; i < ids->length(); ++i )
1752 curIndices.insert( ids[i] );
1754 if ( groupData._indices == curIndices )
1755 return newShape; // group not changed
1758 groupData._indices = curIndices;
1760 GEOM_Client* geomClient = _gen_i->GetShapeReader();
1761 if ( !geomClient ) return newShape;
1762 CORBA::String_var groupIOR = geomGen->GetStringFromIOR( geomGroup );
1763 geomClient->RemoveShapeFromBuffer( groupIOR.in() );
1764 newShape = _gen_i->GeomObjectToShape( geomGroup );
1767 if ( newShape.IsNull() ) {
1768 // geom group becomes empty - return empty compound
1769 TopoDS_Compound compound;
1770 BRep_Builder().MakeCompound(compound);
1771 newShape = compound;
1778 //=============================================================================
1780 * \brief Storage of shape and index used in CheckGeomGroupModif()
1782 //=============================================================================
1783 struct TIndexedShape
1786 TopoDS_Shape _shape;
1787 TIndexedShape( int i, const TopoDS_Shape& s ):_index(i), _shape(s) {}
1790 //=============================================================================
1792 * \brief Update objects depending on changed geom groups
1794 * NPAL16168: geometrical group edition from a submesh don't modifiy mesh computation
1795 * issue 0020210: Update of a smesh group after modification of the associated geom group
1797 //=============================================================================
1799 void SMESH_Mesh_i::CheckGeomGroupModif()
1801 if ( !_impl->HasShapeToMesh() ) return;
1803 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
1804 if ( study->_is_nil() ) return;
1806 CORBA::Long nbEntities = NbNodes() + NbElements();
1808 // Check if group contents changed
1810 typedef map< string, TopoDS_Shape > TEntry2Geom;
1811 TEntry2Geom newGroupContents;
1813 list<TGeomGroupData>::iterator
1814 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
1815 for ( ; data != dataEnd; ++data )
1817 pair< TEntry2Geom::iterator, bool > it_new =
1818 newGroupContents.insert( make_pair( data->_groupEntry, TopoDS_Shape() ));
1819 bool processedGroup = !it_new.second;
1820 TopoDS_Shape& newShape = it_new.first->second;
1821 if ( !processedGroup )
1822 newShape = newGroupShape( *data );
1823 if ( newShape.IsNull() )
1824 continue; // no changes
1827 _preMeshInfo->ForgetOrLoad();
1829 if ( processedGroup ) { // update group indices
1830 list<TGeomGroupData>::iterator data2 = data;
1831 for ( --data2; data2->_groupEntry != data->_groupEntry; --data2) {}
1832 data->_indices = data2->_indices;
1835 // Update SMESH objects according to new GEOM group contents
1837 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( data->_smeshObject );
1838 if ( !submesh->_is_nil() ) // -------------- Sub mesh ---------------------
1840 int oldID = submesh->GetId();
1841 if ( !_mapSubMeshIor.count( oldID ))
1843 TopoDS_Shape oldShape = _mapSubMesh[oldID]->GetSubShape();
1845 // update hypotheses
1846 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldShape);
1847 list <const SMESHDS_Hypothesis * >::iterator hypIt;
1848 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1850 _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
1851 _impl->AddHypothesis ( newShape, (*hypIt)->GetID());
1853 // care of submeshes
1854 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newShape );
1855 int newID = newSubmesh->GetId();
1856 if ( newID != oldID ) {
1857 _mapSubMesh [ newID ] = newSubmesh;
1858 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1859 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1860 _mapSubMesh. erase(oldID);
1861 _mapSubMesh_i. erase(oldID);
1862 _mapSubMeshIor.erase(oldID);
1863 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1868 SMESH::SMESH_GroupOnGeom_var smeshGroup =
1869 SMESH::SMESH_GroupOnGeom::_narrow( data->_smeshObject );
1870 if ( !smeshGroup->_is_nil() ) // ------------ GROUP -----------------------
1872 SMESH_GroupOnGeom_i* group_i = SMESH::DownCast<SMESH_GroupOnGeom_i*>( smeshGroup );
1874 ::SMESH_Group* group = _impl->GetGroup( group_i->GetLocalID() );
1875 SMESHDS_GroupOnGeom* ds = static_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() );
1876 ds->SetShape( newShape );
1881 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( data->_smeshObject );
1882 if ( !mesh->_is_nil() ) // -------------- MESH ----------------------------
1884 // Remove groups and submeshes basing on removed sub-shapes
1886 TopTools_MapOfShape newShapeMap;
1887 TopoDS_Iterator shapeIt( newShape );
1888 for ( ; shapeIt.More(); shapeIt.Next() )
1889 newShapeMap.Add( shapeIt.Value() );
1891 SMESHDS_Mesh* meshDS = _impl->GetMeshDS();
1892 for ( shapeIt.Initialize( meshDS->ShapeToMesh() ); shapeIt.More(); shapeIt.Next() )
1894 if ( newShapeMap.Contains( shapeIt.Value() ))
1896 TopTools_IndexedMapOfShape oldShapeMap;
1897 TopExp::MapShapes( shapeIt.Value(), oldShapeMap );
1898 for ( int i = 1; i <= oldShapeMap.Extent(); ++i )
1900 const TopoDS_Shape& oldShape = oldShapeMap(i);
1901 int oldInd = meshDS->ShapeToIndex( oldShape );
1903 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldInd );
1904 if ( i_smIor != _mapSubMeshIor.end() ) {
1905 RemoveSubMesh( i_smIor->second ); // one submesh per shape index
1908 map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_grp = _mapGroups.begin();
1909 for ( ; i_grp != _mapGroups.end(); ++i_grp )
1911 // check if a group bases on oldInd shape
1912 SMESHDS_GroupOnGeom* grpOnGeom = 0;
1913 if ( ::SMESH_Group* g = _impl->GetGroup( i_grp->first ))
1914 grpOnGeom = dynamic_cast<SMESHDS_GroupOnGeom*>( g->GetGroupDS() );
1915 if ( grpOnGeom && oldShape.IsSame( grpOnGeom->GetShape() ))
1917 RemoveGroup( i_grp->second ); // several groups can base on same shape
1918 i_grp = _mapGroups.begin(); // _mapGroups changed - restart iteration
1923 // Reassign hypotheses and update groups after setting the new shape to mesh
1925 // collect anassigned hypotheses
1926 typedef list< pair< TIndexedShape, list<const SMESHDS_Hypothesis*> > > TShapeHypList;
1927 list <const SMESHDS_Hypothesis * >::const_iterator hypIt;
1928 TShapeHypList assignedHyps;
1929 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
1931 const TopoDS_Shape& oldShape = meshDS->IndexToShape(i);
1932 list<const SMESHDS_Hypothesis*> hyps = meshDS->GetHypothesis( oldShape );// copy
1933 if ( !hyps.empty() ) {
1934 assignedHyps.push_back( make_pair( TIndexedShape(i,oldShape), hyps ));
1935 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1936 _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
1939 // collect shapes supporting groups
1940 typedef list < pair< TIndexedShape, SMDSAbs_ElementType > > TShapeTypeList;
1941 TShapeTypeList groupData;
1942 const set<SMESHDS_GroupBase*>& groups = meshDS->GetGroups();
1943 set<SMESHDS_GroupBase*>::const_iterator grIt = groups.begin();
1944 for ( ; grIt != groups.end(); ++grIt )
1946 if ( SMESHDS_GroupOnGeom* gog = dynamic_cast<SMESHDS_GroupOnGeom*>( *grIt ))
1948 ( make_pair( TIndexedShape( gog->GetID(),gog->GetShape()), gog->GetType()));
1950 // set new shape to mesh -> DS of submeshes and geom groups is deleted
1951 _impl->ShapeToMesh( newShape );
1953 // reassign hypotheses
1954 TShapeHypList::iterator indS_hyps = assignedHyps.begin();
1955 for ( ; indS_hyps != assignedHyps.end(); ++indS_hyps )
1957 TIndexedShape& geom = indS_hyps->first;
1958 list<const SMESHDS_Hypothesis*>& hyps = indS_hyps->second;
1959 int oldID = geom._index;
1960 int newID = meshDS->ShapeToIndex( geom._shape );
1961 if ( oldID == 1 ) { // main shape
1963 geom._shape = newShape;
1967 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
1968 _impl->AddHypothesis( geom._shape, (*hypIt)->GetID());
1969 // care of submeshes
1970 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( geom._shape );
1971 if ( newID != oldID ) {
1972 _mapSubMesh [ newID ] = newSubmesh;
1973 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
1974 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
1975 _mapSubMesh. erase(oldID);
1976 _mapSubMesh_i. erase(oldID);
1977 _mapSubMeshIor.erase(oldID);
1978 _mapSubMesh_i [ newID ]->changeLocalId( newID );
1982 TShapeTypeList::iterator geomType = groupData.begin();
1983 for ( ; geomType != groupData.end(); ++geomType )
1985 const TIndexedShape& geom = geomType->first;
1986 int oldID = geom._index;
1987 if ( _mapGroups.find( oldID ) == _mapGroups.end() )
1990 SALOMEDS::SObject_wrap groupSO = _gen_i->ObjectToSObject( study,_mapGroups[oldID] );
1991 CORBA::String_var name = groupSO->GetName();
1993 SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>(_mapGroups[oldID] );
1995 if ( group_i && _impl->AddGroup( geomType->second, name.in(), newID, geom._shape ))
1996 group_i->changeLocalId( newID );
1999 break; // everything has been updated
2002 } // loop on group data
2006 CORBA::Long newNbEntities = NbNodes() + NbElements();
2007 list< SALOMEDS::SObject_wrap > soToUpdateIcons;
2008 if ( newNbEntities != nbEntities )
2010 // Add all SObjects with icons to soToUpdateIcons
2011 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, _this() )); // mesh
2013 for (map<int, SMESH::SMESH_subMesh_ptr>::iterator i_sm = _mapSubMeshIor.begin();
2014 i_sm != _mapSubMeshIor.end(); ++i_sm ) // submeshes
2015 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_sm->second ));
2017 for ( map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_gr = _mapGroups.begin();
2018 i_gr != _mapGroups.end(); ++i_gr ) // groups
2019 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_gr->second ));
2022 list< SALOMEDS::SObject_wrap >::iterator so = soToUpdateIcons.begin();
2023 for ( ; so != soToUpdateIcons.end(); ++so )
2024 _gen_i->SetPixMap( *so, "ICON_SMESH_TREE_MESH_WARN" );
2027 //=============================================================================
2029 * \brief Create standalone group from a group on geometry or filter
2031 //=============================================================================
2033 SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupBase_ptr theGroup )
2034 throw (SALOME::SALOME_Exception)
2036 SMESH::SMESH_Group_var aGroup;
2041 _preMeshInfo->FullLoadFromFile();
2043 if ( theGroup->_is_nil() )
2044 return aGroup._retn();
2046 SMESH_GroupBase_i* aGroupToRem = SMESH::DownCast<SMESH_GroupBase_i*>( theGroup );
2048 return aGroup._retn();
2050 const bool isOnFilter = ( SMESH::DownCast< SMESH_GroupOnFilter_i* > ( theGroup ));
2052 const int anId = aGroupToRem->GetLocalID();
2053 if ( !_impl->ConvertToStandalone( anId ) )
2054 return aGroup._retn();
2055 removeGeomGroupData( theGroup );
2057 SMESH_GroupBase_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2059 // remove old instance of group from own map
2060 { SMESH::SMESH_GroupBase_var var( _mapGroups[anId] ); } // decref CORBA object
2061 _mapGroups.erase( anId );
2063 SALOMEDS::StudyBuilder_var builder;
2064 SALOMEDS::SObject_wrap aGroupSO;
2065 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
2066 if ( !aStudy->_is_nil() ) {
2067 builder = aStudy->NewBuilder();
2068 aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
2069 if ( !aGroupSO->_is_nil() )
2071 // remove reference to geometry
2072 SALOMEDS::ChildIterator_wrap chItr = aStudy->NewChildIterator(aGroupSO);
2073 for ( ; chItr->More(); chItr->Next() )
2074 // Remove group's child SObject
2075 builder->RemoveObject( chItr->Value() );
2077 // Update Python script
2078 TPythonDump() << aGroupSO << " = " << SMESH::SMESH_Mesh_var(_this())
2079 << ".ConvertToStandalone( " << aGroupSO << " )";
2081 // change icon of Group on Filter
2084 SMESH::array_of_ElementType_var elemTypes = aGroupImpl->GetTypes();
2085 const int isEmpty = ( elemTypes->length() == 0 );
2088 SALOMEDS::GenericAttribute_wrap anAttr =
2089 builder->FindOrCreateAttribute( aGroupSO, "AttributePixMap" );
2090 SALOMEDS::AttributePixMap_wrap pm = anAttr;
2091 pm->SetPixMap( "ICON_SMESH_TREE_GROUP" );
2097 // remember new group in own map
2098 aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
2099 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
2101 // register CORBA object for persistence
2102 _gen_i->RegisterObject( aGroup );
2104 CORBA::String_var ior = _gen_i->GetORB()->object_to_string( aGroup );
2105 builder->SetIOR( aGroupSO, ior.in() ); // == aGroup->Register();
2106 //aGroup->Register();
2107 aGroupToRem->UnRegister();
2109 SMESH_CATCH( SMESH::throwCorbaException );
2111 return aGroup._retn();
2114 //=============================================================================
2118 //=============================================================================
2120 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
2122 if(MYDEBUG) MESSAGE( "createSubMesh" );
2123 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
2124 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
2125 const int subMeshId = mySubMesh->GetId();
2127 SMESH_subMesh_i * subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
2128 SMESH::SMESH_subMesh_var subMesh = subMeshServant->_this();
2130 _mapSubMesh [subMeshId] = mySubMesh;
2131 _mapSubMesh_i [subMeshId] = subMeshServant;
2132 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate( subMesh );
2134 subMeshServant->Register();
2136 // register CORBA object for persistence
2137 int nextId = _gen_i->RegisterObject( subMesh );
2138 if(MYDEBUG) { MESSAGE( "Add submesh to map with id = "<< nextId); }
2139 else { nextId = 0; } // avoid "unused variable" warning
2141 // to track changes of GEOM groups
2142 addGeomGroupData( theSubShapeObject, subMesh );
2144 return subMesh._retn();
2147 //=======================================================================
2148 //function : getSubMesh
2150 //=======================================================================
2152 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
2154 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
2155 if ( it == _mapSubMeshIor.end() )
2156 return SMESH::SMESH_subMesh::_nil();
2158 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
2161 //=============================================================================
2165 //=============================================================================
2167 bool SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
2168 GEOM::GEOM_Object_ptr theSubShapeObject )
2170 bool isHypChanged = false;
2171 if ( theSubMesh->_is_nil() /*|| theSubShapeObject->_is_nil()*/ )
2172 return isHypChanged;
2174 const int subMeshId = theSubMesh->GetId();
2176 if ( theSubShapeObject->_is_nil() ) // not published shape (IPAL13617)
2178 if ( _mapSubMesh.find( subMeshId ) != _mapSubMesh.end())
2180 TopoDS_Shape S = _mapSubMesh[ subMeshId ]->GetSubShape();
2183 list<const SMESHDS_Hypothesis*> hyps = _impl->GetHypothesisList( S );
2184 isHypChanged = !hyps.empty();
2185 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hyps.begin();
2186 for ( ; hyp != hyps.end(); ++hyp )
2187 _impl->RemoveHypothesis(S, (*hyp)->GetID());
2194 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
2195 isHypChanged = ( aHypList->length() > 0 );
2196 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
2197 removeHypothesis( theSubShapeObject, aHypList[i] );
2200 catch( const SALOME::SALOME_Exception& ) {
2201 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
2203 removeGeomGroupData( theSubShapeObject );
2207 std::map<int, SMESH_subMesh_i*>::iterator id_smi = _mapSubMesh_i.find( subMeshId );
2208 if ( id_smi != _mapSubMesh_i.end() )
2209 id_smi->second->UnRegister();
2211 // remove a CORBA object
2212 std::map<int, SMESH::SMESH_subMesh_ptr>::iterator id_smptr = _mapSubMeshIor.find( subMeshId );
2213 if ( id_smptr != _mapSubMeshIor.end() )
2214 SMESH::SMESH_subMesh_var( id_smptr->second );
2216 _mapSubMesh.erase(subMeshId);
2217 _mapSubMesh_i.erase(subMeshId);
2218 _mapSubMeshIor.erase(subMeshId);
2220 return isHypChanged;
2223 //=============================================================================
2227 //=============================================================================
2229 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
2230 const char* theName,
2231 const TopoDS_Shape& theShape,
2232 const SMESH_PredicatePtr& thePredicate )
2234 std::string newName;
2235 if ( !theName || strlen( theName ) == 0 )
2237 std::set< std::string > presentNames;
2238 std::map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator i_gr = _mapGroups.begin();
2239 for ( ; i_gr != _mapGroups.end(); ++i_gr )
2241 CORBA::String_var name = i_gr->second->GetName();
2242 presentNames.insert( name.in() );
2245 newName = "noname_Group_" + SMESH_Comment( presentNames.size() + 1 );
2246 } while ( !presentNames.insert( newName ).second );
2247 theName = newName.c_str();
2250 SMESH::SMESH_GroupBase_var aGroup;
2251 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape, thePredicate ))
2253 SMESH_GroupBase_i* aGroupImpl;
2254 if ( !theShape.IsNull() )
2255 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
2256 else if ( thePredicate )
2257 aGroupImpl = new SMESH_GroupOnFilter_i( SMESH_Gen_i::GetPOA(), this, anId );
2259 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
2261 aGroup = aGroupImpl->_this();
2262 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
2263 aGroupImpl->Register();
2265 // register CORBA object for persistence
2266 int nextId = _gen_i->RegisterObject( aGroup );
2267 if(MYDEBUG) { MESSAGE( "Add group to map with id = "<< nextId); }
2268 else { nextId = 0; } // avoid "unused variable" warning in release mode
2270 // to track changes of GEOM groups
2271 if ( !theShape.IsNull() ) {
2272 GEOM::GEOM_Object_var geom = _gen_i->ShapeToGeomObject( theShape );
2273 addGeomGroupData( geom, aGroup );
2276 return aGroup._retn();
2279 //=============================================================================
2281 * SMESH_Mesh_i::removeGroup
2283 * Should be called by ~SMESH_Group_i()
2285 //=============================================================================
2287 void SMESH_Mesh_i::removeGroup( const int theId )
2289 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
2290 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
2291 SMESH::SMESH_GroupBase_var group = _mapGroups[theId];
2292 _mapGroups.erase( theId );
2293 removeGeomGroupData( group );
2294 if ( !_impl->RemoveGroup( theId ))
2296 // it seems to be a call up from _impl caused by hyp modification (issue 0020918)
2297 RemoveGroup( group );
2299 group->UnRegister();
2303 //=============================================================================
2307 //=============================================================================
2309 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
2310 throw(SALOME::SALOME_Exception)
2312 SMESH::log_array_var aLog;
2316 _preMeshInfo->FullLoadFromFile();
2318 list < SMESHDS_Command * >logDS = _impl->GetLog();
2319 aLog = new SMESH::log_array;
2321 int lg = logDS.size();
2324 list < SMESHDS_Command * >::iterator its = logDS.begin();
2325 while(its != logDS.end()){
2326 SMESHDS_Command *com = *its;
2327 int comType = com->GetType();
2329 int lgcom = com->GetNumber();
2331 const list < int >&intList = com->GetIndexes();
2332 int inum = intList.size();
2334 list < int >::const_iterator ii = intList.begin();
2335 const list < double >&coordList = com->GetCoords();
2336 int rnum = coordList.size();
2338 list < double >::const_iterator ir = coordList.begin();
2339 aLog[indexLog].commandType = comType;
2340 aLog[indexLog].number = lgcom;
2341 aLog[indexLog].coords.length(rnum);
2342 aLog[indexLog].indexes.length(inum);
2343 for(int i = 0; i < rnum; i++){
2344 aLog[indexLog].coords[i] = *ir;
2345 //MESSAGE(" "<<i<<" "<<ir.Value());
2348 for(int i = 0; i < inum; i++){
2349 aLog[indexLog].indexes[i] = *ii;
2350 //MESSAGE(" "<<i<<" "<<ii.Value());
2359 SMESH_CATCH( SMESH::throwCorbaException );
2361 return aLog._retn();
2365 //=============================================================================
2369 //=============================================================================
2371 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
2375 SMESH_CATCH( SMESH::throwCorbaException );
2378 //=============================================================================
2382 //=============================================================================
2384 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
2389 //=============================================================================
2393 //=============================================================================
2395 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
2400 //=============================================================================
2403 //!< implementation of struct used to call methods of SMESH_Mesh_i from SMESH_Mesh
2404 // issue 0020918: groups removal is caused by hyp modification
2405 // issue 0021208: to forget not loaded mesh data at hyp modification
2406 struct TCallUp_i : public SMESH_Mesh::TCallUp
2408 SMESH_Mesh_i* _mesh;
2409 TCallUp_i(SMESH_Mesh_i* mesh):_mesh(mesh) {}
2410 virtual void RemoveGroup (const int theGroupID) { _mesh->removeGroup( theGroupID ); }
2411 virtual void HypothesisModified () { _mesh->onHypothesisModified(); }
2412 virtual void Load () { _mesh->Load(); }
2416 //================================================================================
2418 * \brief callback from _impl to forget not loaded mesh data (issue 0021208)
2420 //================================================================================
2422 void SMESH_Mesh_i::onHypothesisModified()
2425 _preMeshInfo->ForgetOrLoad();
2428 //=============================================================================
2432 //=============================================================================
2434 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
2436 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
2439 _impl->SetCallUp( new TCallUp_i(this));
2442 //=============================================================================
2446 //=============================================================================
2448 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
2450 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
2454 //=============================================================================
2456 * Return mesh editor
2458 //=============================================================================
2460 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
2461 throw (SALOME::SALOME_Exception)
2463 SMESH::SMESH_MeshEditor_var aMeshEdVar;
2467 _preMeshInfo->FullLoadFromFile();
2469 // Create MeshEditor
2471 _editor = new SMESH_MeshEditor_i( this, false );
2472 aMeshEdVar = _editor->_this();
2474 // Update Python script
2475 TPythonDump() << _editor << " = "
2476 << SMESH::SMESH_Mesh_var(_this()) << ".GetMeshEditor()";
2478 SMESH_CATCH( SMESH::throwCorbaException );
2480 return aMeshEdVar._retn();
2483 //=============================================================================
2485 * Return mesh edition previewer
2487 //=============================================================================
2489 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
2490 throw (SALOME::SALOME_Exception)
2492 SMESH::SMESH_MeshEditor_var aMeshEdVar;
2496 _preMeshInfo->FullLoadFromFile();
2498 if ( !_previewEditor )
2499 _previewEditor = new SMESH_MeshEditor_i( this, true );
2500 aMeshEdVar = _previewEditor->_this();
2502 SMESH_CATCH( SMESH::throwCorbaException );
2504 return aMeshEdVar._retn();
2507 //================================================================================
2509 * \brief Return true if the mesh has been edited since a last total re-compute
2510 * and those modifications may prevent successful partial re-compute
2512 //================================================================================
2514 CORBA::Boolean SMESH_Mesh_i::HasModificationsToDiscard() throw(SALOME::SALOME_Exception)
2516 Unexpect aCatch(SALOME_SalomeException);
2517 return _impl->HasModificationsToDiscard();
2520 //================================================================================
2522 * \brief Returns a random unique color
2524 //================================================================================
2526 static SALOMEDS::Color getUniqueColor( const std::list<SALOMEDS::Color>& theReservedColors )
2528 const int MAX_ATTEMPTS = 100;
2530 double tolerance = 0.5;
2531 SALOMEDS::Color col;
2535 // generate random color
2536 double red = (double)rand() / RAND_MAX;
2537 double green = (double)rand() / RAND_MAX;
2538 double blue = (double)rand() / RAND_MAX;
2539 // check existence in the list of the existing colors
2540 bool matched = false;
2541 std::list<SALOMEDS::Color>::const_iterator it;
2542 for ( it = theReservedColors.begin(); it != theReservedColors.end() && !matched; ++it ) {
2543 SALOMEDS::Color color = *it;
2544 double tol = fabs( color.R - red ) + fabs( color.G - green ) + fabs( color.B - blue );
2545 matched = tol < tolerance;
2547 if ( (cnt+1) % 20 == 0 ) tolerance = tolerance/2;
2548 ok = ( ++cnt == MAX_ATTEMPTS ) || !matched;
2556 //=============================================================================
2558 * Sets auto-color mode. If it is on, groups get unique random colors
2560 //=============================================================================
2562 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
2564 Unexpect aCatch(SALOME_SalomeException);
2565 _impl->SetAutoColor(theAutoColor);
2567 TPythonDump pyDump; // not to dump group->SetColor() from below code
2568 pyDump << SMESH::SMESH_Mesh_var(_this()) <<".SetAutoColor( "<<theAutoColor<<" )";
2570 std::list<SALOMEDS::Color> aReservedColors;
2571 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
2572 for ( ; it != _mapGroups.end(); it++ ) {
2573 if ( CORBA::is_nil( it->second )) continue;
2574 SALOMEDS::Color aColor = getUniqueColor( aReservedColors );
2575 it->second->SetColor( aColor );
2576 aReservedColors.push_back( aColor );
2580 //=============================================================================
2582 * Returns true if auto-color mode is on
2584 //=============================================================================
2586 CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
2588 Unexpect aCatch(SALOME_SalomeException);
2589 return _impl->GetAutoColor();
2592 //=============================================================================
2594 * Checks if there are groups with equal names
2596 //=============================================================================
2598 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
2600 return _impl->HasDuplicatedGroupNamesMED();
2603 //================================================================================
2605 * \brief Care of a file before exporting mesh into it
2607 //================================================================================
2609 void SMESH_Mesh_i::PrepareForWriting (const char* file, bool overwrite)
2611 TCollection_AsciiString aFullName ((char*)file);
2612 OSD_Path aPath (aFullName);
2613 OSD_File aFile (aPath);
2614 if (aFile.Exists()) {
2615 // existing filesystem node
2616 if (aFile.KindOfFile() == OSD_FILE) {
2617 if (aFile.IsWriteable()) {
2622 if (aFile.Failed()) {
2623 TCollection_AsciiString msg ("File ");
2624 msg += aFullName + " cannot be replaced.";
2625 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2628 TCollection_AsciiString msg ("File ");
2629 msg += aFullName + " cannot be overwritten.";
2630 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2633 TCollection_AsciiString msg ("Location ");
2634 msg += aFullName + " is not a file.";
2635 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2638 // nonexisting file; check if it can be created
2640 aFile.Build(OSD_WriteOnly, OSD_Protection());
2641 if (aFile.Failed()) {
2642 TCollection_AsciiString msg ("You cannot create the file ");
2643 msg += aFullName + ". Check the directory existance and access rights.";
2644 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
2652 //================================================================================
2654 * \brief Prepares a file for export and pass names of mesh groups from study to mesh DS
2655 * \param file - file name
2656 * \param overwrite - to erase the file or not
2657 * \retval string - mesh name
2659 //================================================================================
2661 string SMESH_Mesh_i::prepareMeshNameAndGroups(const char* file,
2662 CORBA::Boolean overwrite)
2665 PrepareForWriting(file, overwrite);
2666 string aMeshName = "Mesh";
2667 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
2668 if ( !aStudy->_is_nil() ) {
2669 SALOMEDS::SObject_wrap aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
2670 if ( !aMeshSO->_is_nil() ) {
2671 CORBA::String_var name = aMeshSO->GetName();
2673 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
2674 if ( !aStudy->GetProperties()->IsLocked() )
2676 SALOMEDS::GenericAttribute_wrap anAttr;
2677 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2678 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
2679 SALOMEDS::AttributeExternalFileDef_wrap aFileName = anAttr;
2680 ASSERT(!aFileName->_is_nil());
2681 aFileName->SetValue(file);
2682 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
2683 SALOMEDS::AttributeFileType_wrap aFileType = anAttr;
2684 ASSERT(!aFileType->_is_nil());
2685 aFileType->SetValue("FICHIERMED");
2689 // Update Python script
2690 // set name of mesh before export
2691 TPythonDump() << _gen_i << ".SetName("
2692 << SMESH::SMESH_Mesh_var(_this()) << ", '" << aMeshName.c_str() << "')";
2694 // check names of groups
2700 //================================================================================
2702 * \brief Export to med file
2704 //================================================================================
2706 void SMESH_Mesh_i::ExportToMEDX (const char* file,
2707 CORBA::Boolean auto_groups,
2708 SMESH::MED_VERSION theVersion,
2709 CORBA::Boolean overwrite,
2710 CORBA::Boolean autoDimension)
2711 throw(SALOME::SALOME_Exception)
2713 Unexpect aCatch(SALOME_SalomeException);
2715 _preMeshInfo->FullLoadFromFile();
2717 string aMeshName = prepareMeshNameAndGroups(file, overwrite);
2718 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportToMEDX( r'"
2719 << file << "', " << auto_groups << ", "
2720 << theVersion << ", " << overwrite << ", "
2721 << autoDimension << " )";
2723 _impl->ExportMED( file, aMeshName.c_str(), auto_groups, theVersion, 0, autoDimension );
2726 //================================================================================
2728 * \brief Export a mesh to a med file
2730 //================================================================================
2732 void SMESH_Mesh_i::ExportToMED (const char* file,
2733 CORBA::Boolean auto_groups,
2734 SMESH::MED_VERSION theVersion)
2735 throw(SALOME::SALOME_Exception)
2737 ExportToMEDX(file,auto_groups,theVersion,true);
2740 //================================================================================
2742 * \brief Export a mesh to a med file
2744 //================================================================================
2746 void SMESH_Mesh_i::ExportMED (const char* file,
2747 CORBA::Boolean auto_groups)
2748 throw(SALOME::SALOME_Exception)
2750 ExportToMEDX(file,auto_groups,SMESH::MED_V2_2,true);
2753 //================================================================================
2755 * \brief Export a mesh to a SAUV file
2757 //================================================================================
2759 void SMESH_Mesh_i::ExportSAUV (const char* file,
2760 CORBA::Boolean auto_groups)
2761 throw(SALOME::SALOME_Exception)
2763 Unexpect aCatch(SALOME_SalomeException);
2765 _preMeshInfo->FullLoadFromFile();
2767 string aMeshName = prepareMeshNameAndGroups(file, true);
2768 TPythonDump() << SMESH::SMESH_Mesh_var( _this())
2769 << ".ExportSAUV( r'" << file << "', " << auto_groups << " )";
2770 _impl->ExportSAUV(file, aMeshName.c_str(), auto_groups);
2774 //================================================================================
2776 * \brief Export a mesh to a DAT file
2778 //================================================================================
2780 void SMESH_Mesh_i::ExportDAT (const char *file)
2781 throw(SALOME::SALOME_Exception)
2783 Unexpect aCatch(SALOME_SalomeException);
2785 _preMeshInfo->FullLoadFromFile();
2787 // Update Python script
2788 // check names of groups
2790 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportDAT( r'" << file << "' )";
2793 PrepareForWriting(file);
2794 _impl->ExportDAT(file);
2797 //================================================================================
2799 * \brief Export a mesh to an UNV file
2801 //================================================================================
2803 void SMESH_Mesh_i::ExportUNV (const char *file)
2804 throw(SALOME::SALOME_Exception)
2806 Unexpect aCatch(SALOME_SalomeException);
2808 _preMeshInfo->FullLoadFromFile();
2810 // Update Python script
2811 // check names of groups
2813 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportUNV( r'" << file << "' )";
2816 PrepareForWriting(file);
2817 _impl->ExportUNV(file);
2820 //================================================================================
2822 * \brief Export a mesh to an STL file
2824 //================================================================================
2826 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
2827 throw(SALOME::SALOME_Exception)
2829 Unexpect aCatch(SALOME_SalomeException);
2831 _preMeshInfo->FullLoadFromFile();
2833 // Update Python script
2834 // check names of groups
2836 TPythonDump() << SMESH::SMESH_Mesh_var(_this())
2837 << ".ExportSTL( r'" << file << "', " << isascii << " )";
2840 PrepareForWriting(file);
2841 _impl->ExportSTL(file, isascii);
2844 //================================================================================
2846 * \brief Export a part of mesh to a med file
2848 //================================================================================
2850 void SMESH_Mesh_i::ExportPartToMED(::SMESH::SMESH_IDSource_ptr meshPart,
2852 CORBA::Boolean auto_groups,
2853 ::SMESH::MED_VERSION version,
2854 ::CORBA::Boolean overwrite,
2855 ::CORBA::Boolean autoDimension)
2856 throw (SALOME::SALOME_Exception)
2858 Unexpect aCatch(SALOME_SalomeException);
2861 if ( SMESH_Mesh_i * mesh = SMESH::DownCast< SMESH_Mesh_i* >( meshPart ))
2863 mesh->ExportToMEDX( file, auto_groups, version, autoDimension );
2868 _preMeshInfo->FullLoadFromFile();
2870 PrepareForWriting(file, overwrite);
2872 string aMeshName = "Mesh";
2873 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
2874 if ( !aStudy->_is_nil() ) {
2875 SALOMEDS::SObject_wrap SO = _gen_i->ObjectToSObject( aStudy, meshPart );
2876 if ( !SO->_is_nil() ) {
2877 CORBA::String_var name = SO->GetName();
2881 SMESH_MeshPartDS partDS( meshPart );
2882 _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, &partDS, autoDimension );
2884 pyDump << SMESH::SMESH_Mesh_var(_this()) << ".ExportPartToMED( "
2885 << meshPart << ", r'" << file << "', "
2886 << auto_groups << ", " << version << ", " << overwrite << ", "
2887 << autoDimension << " )";
2890 //================================================================================
2892 * \brief Export a part of mesh to a DAT file
2894 //================================================================================
2896 void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
2898 throw (SALOME::SALOME_Exception)
2900 Unexpect aCatch(SALOME_SalomeException);
2902 _preMeshInfo->FullLoadFromFile();
2904 PrepareForWriting(file);
2906 SMESH_MeshPartDS partDS( meshPart );
2907 _impl->ExportDAT(file,&partDS);
2909 TPythonDump() << SMESH::SMESH_Mesh_var(_this())
2910 << ".ExportPartToDAT( " << meshPart << ", r'" << file << "' )";
2912 //================================================================================
2914 * \brief Export a part of mesh to an UNV file
2916 //================================================================================
2918 void SMESH_Mesh_i::ExportPartToUNV(::SMESH::SMESH_IDSource_ptr meshPart,
2920 throw (SALOME::SALOME_Exception)
2922 Unexpect aCatch(SALOME_SalomeException);
2924 _preMeshInfo->FullLoadFromFile();
2926 PrepareForWriting(file);
2928 SMESH_MeshPartDS partDS( meshPart );
2929 _impl->ExportUNV(file, &partDS);
2931 TPythonDump() << SMESH::SMESH_Mesh_var(_this())
2932 << ".ExportPartToUNV( " << meshPart<< ", r'" << file << "' )";
2934 //================================================================================
2936 * \brief Export a part of mesh to an STL file
2938 //================================================================================
2940 void SMESH_Mesh_i::ExportPartToSTL(::SMESH::SMESH_IDSource_ptr meshPart,
2942 ::CORBA::Boolean isascii)
2943 throw (SALOME::SALOME_Exception)
2945 Unexpect aCatch(SALOME_SalomeException);
2947 _preMeshInfo->FullLoadFromFile();
2949 PrepareForWriting(file);
2951 SMESH_MeshPartDS partDS( meshPart );
2952 _impl->ExportSTL(file, isascii, &partDS);
2954 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportPartToSTL( "
2955 << meshPart<< ", r'" << file << "', " << isascii << ")";
2958 //================================================================================
2960 * \brief Export a part of mesh to an STL file
2962 //================================================================================
2964 void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
2966 CORBA::Boolean overwrite)
2967 throw (SALOME::SALOME_Exception)
2970 Unexpect aCatch(SALOME_SalomeException);
2972 _preMeshInfo->FullLoadFromFile();
2974 PrepareForWriting(file,overwrite);
2976 SMESH_MeshPartDS partDS( meshPart );
2977 _impl->ExportCGNS(file, &partDS);
2979 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportCGNS( "
2980 << meshPart<< ", r'" << file << "', " << overwrite << ")";
2982 THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
2986 //================================================================================
2988 * \brief Export a part of mesh to a GMF file
2990 //================================================================================
2992 void SMESH_Mesh_i::ExportGMF(::SMESH::SMESH_IDSource_ptr meshPart,
2994 bool withRequiredGroups)
2995 throw (SALOME::SALOME_Exception)
2997 Unexpect aCatch(SALOME_SalomeException);
2999 _preMeshInfo->FullLoadFromFile();
3001 PrepareForWriting(file,/*overwrite=*/true);
3003 SMESH_MeshPartDS partDS( meshPart );
3004 _impl->ExportGMF(file, &partDS, withRequiredGroups);
3006 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportGMF( "
3007 << meshPart<< ", r'"
3009 << withRequiredGroups << ")";
3012 //=============================================================================
3014 * Return computation progress [0.,1]
3016 //=============================================================================
3018 CORBA::Double SMESH_Mesh_i::GetComputeProgress()
3022 return _impl->GetComputeProgress();
3024 SMESH_CATCH( SMESH::doNothing );
3028 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
3030 Unexpect aCatch(SALOME_SalomeException);
3032 return _preMeshInfo->NbNodes();
3034 return _impl->NbNodes();
3037 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
3039 Unexpect aCatch(SALOME_SalomeException);
3041 return _preMeshInfo->NbElements();
3043 return Nb0DElements() + NbEdges() + NbFaces() + NbVolumes() + NbBalls();
3046 CORBA::Long SMESH_Mesh_i::Nb0DElements()throw (SALOME::SALOME_Exception)
3048 Unexpect aCatch(SALOME_SalomeException);
3050 return _preMeshInfo->Nb0DElements();
3052 return _impl->Nb0DElements();
3055 CORBA::Long SMESH_Mesh_i::NbBalls() throw (SALOME::SALOME_Exception)
3057 Unexpect aCatch(SALOME_SalomeException);
3059 return _preMeshInfo->NbBalls();
3061 return _impl->NbBalls();
3064 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
3066 Unexpect aCatch(SALOME_SalomeException);
3068 return _preMeshInfo->NbEdges();
3070 return _impl->NbEdges();
3073 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
3074 throw(SALOME::SALOME_Exception)
3076 Unexpect aCatch(SALOME_SalomeException);
3078 return _preMeshInfo->NbEdges( (SMDSAbs_ElementOrder) order );
3080 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
3083 //=============================================================================
3085 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
3087 Unexpect aCatch(SALOME_SalomeException);
3089 return _preMeshInfo->NbFaces();
3091 return _impl->NbFaces();
3094 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
3096 Unexpect aCatch(SALOME_SalomeException);
3098 return _preMeshInfo->NbTriangles();
3100 return _impl->NbTriangles();
3103 CORBA::Long SMESH_Mesh_i::NbBiQuadTriangles()throw(SALOME::SALOME_Exception)
3105 Unexpect aCatch(SALOME_SalomeException);
3107 return _preMeshInfo->NbBiQuadTriangles();
3109 return _impl->NbBiQuadTriangles();
3112 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
3114 Unexpect aCatch(SALOME_SalomeException);
3116 return _preMeshInfo->NbQuadrangles();
3118 return _impl->NbQuadrangles();
3121 CORBA::Long SMESH_Mesh_i::NbBiQuadQuadrangles()throw(SALOME::SALOME_Exception)
3123 Unexpect aCatch(SALOME_SalomeException);
3125 return _preMeshInfo->NbBiQuadQuadrangles();
3127 return _impl->NbBiQuadQuadrangles();
3130 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
3132 Unexpect aCatch(SALOME_SalomeException);
3134 return _preMeshInfo->NbPolygons();
3136 return _impl->NbPolygons();
3139 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
3140 throw(SALOME::SALOME_Exception)
3142 Unexpect aCatch(SALOME_SalomeException);
3144 return _preMeshInfo->NbFaces( (SMDSAbs_ElementOrder) order );
3146 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
3149 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
3150 throw(SALOME::SALOME_Exception)
3152 Unexpect aCatch(SALOME_SalomeException);
3154 return _preMeshInfo->NbTriangles( (SMDSAbs_ElementOrder) order );
3156 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
3159 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
3160 throw(SALOME::SALOME_Exception)
3162 Unexpect aCatch(SALOME_SalomeException);
3164 return _preMeshInfo->NbQuadrangles( (SMDSAbs_ElementOrder) order );
3166 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
3169 //=============================================================================
3171 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
3173 Unexpect aCatch(SALOME_SalomeException);
3175 return _preMeshInfo->NbVolumes();
3177 return _impl->NbVolumes();
3180 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
3182 Unexpect aCatch(SALOME_SalomeException);
3184 return _preMeshInfo->NbTetras();
3186 return _impl->NbTetras();
3189 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
3191 Unexpect aCatch(SALOME_SalomeException);
3193 return _preMeshInfo->NbHexas();
3195 return _impl->NbHexas();
3198 CORBA::Long SMESH_Mesh_i::NbTriQuadraticHexas()throw(SALOME::SALOME_Exception)
3200 Unexpect aCatch(SALOME_SalomeException);
3202 return _preMeshInfo->NbTriQuadHexas();
3204 return _impl->NbTriQuadraticHexas();
3207 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
3209 Unexpect aCatch(SALOME_SalomeException);
3211 return _preMeshInfo->NbPyramids();
3213 return _impl->NbPyramids();
3216 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
3218 Unexpect aCatch(SALOME_SalomeException);
3220 return _preMeshInfo->NbPrisms();
3222 return _impl->NbPrisms();
3225 CORBA::Long SMESH_Mesh_i::NbHexagonalPrisms()throw(SALOME::SALOME_Exception)
3227 Unexpect aCatch(SALOME_SalomeException);
3229 return _preMeshInfo->NbHexPrisms();
3231 return _impl->NbHexagonalPrisms();
3234 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
3236 Unexpect aCatch(SALOME_SalomeException);
3238 return _preMeshInfo->NbPolyhedrons();
3240 return _impl->NbPolyhedrons();
3243 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
3244 throw(SALOME::SALOME_Exception)
3246 Unexpect aCatch(SALOME_SalomeException);
3248 return _preMeshInfo->NbVolumes( (SMDSAbs_ElementOrder) order );
3250 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
3253 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
3254 throw(SALOME::SALOME_Exception)
3256 Unexpect aCatch(SALOME_SalomeException);
3258 return _preMeshInfo->NbTetras( (SMDSAbs_ElementOrder) order);
3260 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
3263 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
3264 throw(SALOME::SALOME_Exception)
3266 Unexpect aCatch(SALOME_SalomeException);
3268 return _preMeshInfo->NbHexas( (SMDSAbs_ElementOrder) order);
3270 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
3273 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
3274 throw(SALOME::SALOME_Exception)
3276 Unexpect aCatch(SALOME_SalomeException);
3278 return _preMeshInfo->NbPyramids( (SMDSAbs_ElementOrder) order);
3280 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
3283 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
3284 throw(SALOME::SALOME_Exception)
3286 Unexpect aCatch(SALOME_SalomeException);
3288 return _preMeshInfo->NbPrisms( (SMDSAbs_ElementOrder) order);
3290 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
3293 //=============================================================================
3295 * Returns nb of published sub-meshes
3297 //=============================================================================
3299 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
3301 Unexpect aCatch(SALOME_SalomeException);
3302 return _mapSubMesh_i.size();
3305 //=============================================================================
3307 * Dumps mesh into a string
3309 //=============================================================================
3311 char* SMESH_Mesh_i::Dump()
3315 return CORBA::string_dup( os.str().c_str() );
3318 //=============================================================================
3320 * Method of SMESH_IDSource interface
3322 //=============================================================================
3324 SMESH::long_array* SMESH_Mesh_i::GetIDs()
3326 return GetElementsId();
3329 //=============================================================================
3331 * Returns ids of all elements
3333 //=============================================================================
3335 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
3336 throw (SALOME::SALOME_Exception)
3338 Unexpect aCatch(SALOME_SalomeException);
3340 _preMeshInfo->FullLoadFromFile();
3342 SMESH::long_array_var aResult = new SMESH::long_array();
3343 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3345 if ( aSMESHDS_Mesh == NULL )
3346 return aResult._retn();
3348 long nbElements = NbElements();
3349 aResult->length( nbElements );
3350 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
3351 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
3352 aResult[i] = anIt->next()->GetID();
3354 return aResult._retn();
3358 //=============================================================================
3360 * Returns ids of all elements of given type
3362 //=============================================================================
3364 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
3365 throw (SALOME::SALOME_Exception)
3367 Unexpect aCatch(SALOME_SalomeException);
3369 _preMeshInfo->FullLoadFromFile();
3371 SMESH::long_array_var aResult = new SMESH::long_array();
3372 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3374 if ( aSMESHDS_Mesh == NULL )
3375 return aResult._retn();
3377 long nbElements = NbElements();
3379 // No sense in returning ids of elements along with ids of nodes:
3380 // when theElemType == SMESH::ALL, return node ids only if
3381 // there are no elements
3382 if ( theElemType == SMESH::NODE || (theElemType == SMESH::ALL && nbElements == 0) )
3383 return GetNodesId();
3385 aResult->length( nbElements );
3389 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator( (SMDSAbs_ElementType)theElemType );
3390 while ( i < nbElements && anIt->more() )
3391 aResult[i++] = anIt->next()->GetID();
3393 aResult->length( i );
3395 return aResult._retn();
3398 //=============================================================================
3400 * Returns ids of all nodes
3402 //=============================================================================
3404 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
3405 throw (SALOME::SALOME_Exception)
3407 Unexpect aCatch(SALOME_SalomeException);
3409 _preMeshInfo->FullLoadFromFile();
3411 SMESH::long_array_var aResult = new SMESH::long_array();
3412 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3414 if ( aSMESHDS_Mesh == NULL )
3415 return aResult._retn();
3417 long nbNodes = NbNodes();
3418 aResult->length( nbNodes );
3419 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator(/*idInceasingOrder=*/true);
3420 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
3421 aResult[i] = anIt->next()->GetID();
3423 return aResult._retn();
3426 //=============================================================================
3430 //=============================================================================
3432 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
3433 throw (SALOME::SALOME_Exception)
3435 SMESH::ElementType type;
3439 _preMeshInfo->FullLoadFromFile();
3441 type = ( SMESH::ElementType ) _impl->GetElementType( id, iselem );
3443 SMESH_CATCH( SMESH::throwCorbaException );
3448 //=============================================================================
3452 //=============================================================================
3454 SMESH::EntityType SMESH_Mesh_i::GetElementGeomType( const CORBA::Long id )
3455 throw (SALOME::SALOME_Exception)
3458 _preMeshInfo->FullLoadFromFile();
3460 const SMDS_MeshElement* e = _impl->GetMeshDS()->FindElement(id);
3462 THROW_SALOME_CORBA_EXCEPTION( "invalid element id", SALOME::BAD_PARAM );
3464 return ( SMESH::EntityType ) e->GetEntityType();
3467 //=============================================================================
3469 * Returns ID of elements for given submesh
3471 //=============================================================================
3472 SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
3473 throw (SALOME::SALOME_Exception)
3475 SMESH::long_array_var aResult = new SMESH::long_array();
3479 _preMeshInfo->FullLoadFromFile();
3481 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
3482 if(!SM) return aResult._retn();
3484 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
3485 if(!SDSM) return aResult._retn();
3487 aResult->length(SDSM->NbElements());
3489 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
3491 while ( eIt->more() ) {
3492 aResult[i++] = eIt->next()->GetID();
3495 SMESH_CATCH( SMESH::throwCorbaException );
3497 return aResult._retn();
3500 //=============================================================================
3502 * Returns ID of nodes for given submesh
3503 * If param all==true - returns all nodes, else -
3504 * returns only nodes on shapes.
3506 //=============================================================================
3508 SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID,
3510 throw (SALOME::SALOME_Exception)
3512 SMESH::long_array_var aResult = new SMESH::long_array();
3516 _preMeshInfo->FullLoadFromFile();
3518 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
3519 if(!SM) return aResult._retn();
3521 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
3522 if(!SDSM) return aResult._retn();
3525 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
3526 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
3527 while ( nIt->more() ) {
3528 const SMDS_MeshNode* elem = nIt->next();
3529 theElems.insert( elem->GetID() );
3532 else { // all nodes of submesh elements
3533 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
3534 while ( eIt->more() ) {
3535 const SMDS_MeshElement* anElem = eIt->next();
3536 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
3537 while ( nIt->more() ) {
3538 const SMDS_MeshElement* elem = nIt->next();
3539 theElems.insert( elem->GetID() );
3544 aResult->length(theElems.size());
3545 set<int>::iterator itElem;
3547 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
3548 aResult[i++] = *itElem;
3550 SMESH_CATCH( SMESH::throwCorbaException );
3552 return aResult._retn();
3555 //=============================================================================
3557 * Returns type of elements for given submesh
3559 //=============================================================================
3561 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
3562 throw (SALOME::SALOME_Exception)
3564 SMESH::ElementType type;
3568 _preMeshInfo->FullLoadFromFile();
3570 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
3571 if(!SM) return SMESH::ALL;
3573 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
3574 if(!SDSM) return SMESH::ALL;
3576 if(SDSM->NbElements()==0)
3577 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
3579 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
3580 const SMDS_MeshElement* anElem = eIt->next();
3582 type = ( SMESH::ElementType ) anElem->GetType();
3584 SMESH_CATCH( SMESH::throwCorbaException );
3590 //=============================================================================
3592 * Returns pointer to _impl as an integer value. Is called from constructor of SMESH_Client
3594 //=============================================================================
3596 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
3599 _preMeshInfo->FullLoadFromFile();
3601 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
3603 MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
3608 //=============================================================================
3610 * Get XYZ coordinates of node as list of double
3611 * If there is not node for given ID - returns empty list
3613 //=============================================================================
3615 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
3618 _preMeshInfo->FullLoadFromFile();
3620 SMESH::double_array_var aResult = new SMESH::double_array();
3621 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3622 if ( aSMESHDS_Mesh == NULL )
3623 return aResult._retn();
3626 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
3628 return aResult._retn();
3632 aResult[0] = aNode->X();
3633 aResult[1] = aNode->Y();
3634 aResult[2] = aNode->Z();
3635 return aResult._retn();
3639 //=============================================================================
3641 * For given node returns list of IDs of inverse elements
3642 * If there is not node for given ID - returns empty list
3644 //=============================================================================
3646 SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
3649 _preMeshInfo->FullLoadFromFile();
3651 SMESH::long_array_var aResult = new SMESH::long_array();
3652 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3653 if ( aSMESHDS_Mesh == NULL )
3654 return aResult._retn();
3657 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
3659 return aResult._retn();
3661 // find inverse elements
3662 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
3663 TColStd_SequenceOfInteger IDs;
3664 while(eIt->more()) {
3665 const SMDS_MeshElement* elem = eIt->next();
3666 IDs.Append(elem->GetID());
3668 if(IDs.Length()>0) {
3669 aResult->length(IDs.Length());
3671 for(; i<=IDs.Length(); i++) {
3672 aResult[i-1] = IDs.Value(i);
3675 return aResult._retn();
3678 //=============================================================================
3680 * \brief Return position of a node on shape
3682 //=============================================================================
3684 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
3687 _preMeshInfo->FullLoadFromFile();
3689 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
3690 aNodePosition->shapeID = 0;
3691 aNodePosition->shapeType = GEOM::SHAPE;
3693 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
3694 if ( !mesh ) return aNodePosition;
3696 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
3698 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
3700 aNodePosition->shapeID = aNode->getshapeId();
3701 switch ( pos->GetTypeOfPosition() ) {
3703 aNodePosition->shapeType = GEOM::EDGE;
3704 aNodePosition->params.length(1);
3705 aNodePosition->params[0] =
3706 static_cast<SMDS_EdgePosition*>( pos )->GetUParameter();
3709 aNodePosition->shapeType = GEOM::FACE;
3710 aNodePosition->params.length(2);
3711 aNodePosition->params[0] =
3712 static_cast<SMDS_FacePosition*>( pos )->GetUParameter();
3713 aNodePosition->params[1] =
3714 static_cast<SMDS_FacePosition*>( pos )->GetVParameter();
3716 case SMDS_TOP_VERTEX:
3717 aNodePosition->shapeType = GEOM::VERTEX;
3719 case SMDS_TOP_3DSPACE:
3720 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
3721 aNodePosition->shapeType = GEOM::SOLID;
3722 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
3723 aNodePosition->shapeType = GEOM::SHELL;
3729 return aNodePosition;
3732 //=============================================================================
3734 * \brief Return position of an element on shape
3736 //=============================================================================
3738 SMESH::ElementPosition SMESH_Mesh_i::GetElementPosition(CORBA::Long ElemID)
3741 _preMeshInfo->FullLoadFromFile();
3743 SMESH::ElementPosition anElementPosition;
3744 anElementPosition.shapeID = 0;
3745 anElementPosition.shapeType = GEOM::SHAPE;
3747 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
3748 if ( !mesh ) return anElementPosition;
3750 if ( const SMDS_MeshElement* anElem = mesh->FindElement( ElemID ) )
3752 anElementPosition.shapeID = anElem->getshapeId();
3753 const TopoDS_Shape& aSp = mesh->IndexToShape( anElem->getshapeId() );
3754 if ( !aSp.IsNull() ) {
3755 switch ( aSp.ShapeType() ) {
3757 anElementPosition.shapeType = GEOM::EDGE;
3760 anElementPosition.shapeType = GEOM::FACE;
3763 anElementPosition.shapeType = GEOM::VERTEX;
3766 anElementPosition.shapeType = GEOM::SOLID;
3769 anElementPosition.shapeType = GEOM::SHELL;
3775 return anElementPosition;
3778 //=============================================================================
3780 * If given element is node returns IDs of shape from position
3781 * If there is not node for given ID - returns -1
3783 //=============================================================================
3785 CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
3788 _preMeshInfo->FullLoadFromFile();
3790 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3791 if ( aSMESHDS_Mesh == NULL )
3795 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
3797 return aNode->getshapeId();
3804 //=============================================================================
3806 * For given element returns ID of result shape after
3807 * ::FindShape() from SMESH_MeshEditor
3808 * If there is not element for given ID - returns -1
3810 //=============================================================================
3812 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
3815 _preMeshInfo->FullLoadFromFile();
3817 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3818 if ( aSMESHDS_Mesh == NULL )
3821 // try to find element
3822 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3826 ::SMESH_MeshEditor aMeshEditor(_impl);
3827 int index = aMeshEditor.FindShape( elem );
3835 //=============================================================================
3837 * Returns number of nodes for given element
3838 * If there is not element for given ID - returns -1
3840 //=============================================================================
3842 CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
3845 _preMeshInfo->FullLoadFromFile();
3847 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3848 if ( aSMESHDS_Mesh == NULL ) return -1;
3849 // try to find element
3850 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3851 if(!elem) return -1;
3852 return elem->NbNodes();
3856 //=============================================================================
3858 * Returns ID of node by given index for given element
3859 * If there is not element for given ID - returns -1
3860 * If there is not node for given index - returns -2
3862 //=============================================================================
3864 CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
3867 _preMeshInfo->FullLoadFromFile();
3869 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3870 if ( aSMESHDS_Mesh == NULL ) return -1;
3871 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3872 if(!elem) return -1;
3873 if( index>=elem->NbNodes() || index<0 ) return -1;
3874 return elem->GetNode(index)->GetID();
3877 //=============================================================================
3879 * Returns IDs of nodes of given element
3881 //=============================================================================
3883 SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
3886 _preMeshInfo->FullLoadFromFile();
3888 SMESH::long_array_var aResult = new SMESH::long_array();
3889 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
3891 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
3893 aResult->length( elem->NbNodes() );
3894 for ( int i = 0; i < elem->NbNodes(); ++i )
3895 aResult[ i ] = elem->GetNode( i )->GetID();
3898 return aResult._retn();
3901 //=============================================================================
3903 * Returns true if given node is medium node
3904 * in given quadratic element
3906 //=============================================================================
3908 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
3911 _preMeshInfo->FullLoadFromFile();
3913 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3914 if ( aSMESHDS_Mesh == NULL ) return false;
3916 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
3917 if(!aNode) return false;
3918 // try to find element
3919 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
3920 if(!elem) return false;
3922 return elem->IsMediumNode(aNode);
3926 //=============================================================================
3928 * Returns true if given node is medium node
3929 * in one of quadratic elements
3931 //=============================================================================
3933 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
3934 SMESH::ElementType theElemType)
3937 _preMeshInfo->FullLoadFromFile();
3939 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3940 if ( aSMESHDS_Mesh == NULL ) return false;
3943 const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
3944 if(!aNode) return false;
3946 SMESH_MesherHelper aHelper( *(_impl) );
3948 SMDSAbs_ElementType aType;
3949 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
3950 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
3951 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
3952 else aType = SMDSAbs_All;
3954 return aHelper.IsMedium(aNode,aType);
3958 //=============================================================================
3960 * Returns number of edges for given element
3962 //=============================================================================
3964 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
3967 _preMeshInfo->FullLoadFromFile();
3969 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3970 if ( aSMESHDS_Mesh == NULL ) return -1;
3971 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3972 if(!elem) return -1;
3973 return elem->NbEdges();
3977 //=============================================================================
3979 * Returns number of faces for given element
3981 //=============================================================================
3983 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)
3986 _preMeshInfo->FullLoadFromFile();
3988 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
3989 if ( aSMESHDS_Mesh == NULL ) return -1;
3990 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
3991 if(!elem) return -1;
3992 return elem->NbFaces();
3995 //=======================================================================
3996 //function : GetElemFaceNodes
3997 //purpose : Returns nodes of given face (counted from zero) for given element.
3998 //=======================================================================
4000 SMESH::long_array* SMESH_Mesh_i::GetElemFaceNodes(CORBA::Long elemId,
4001 CORBA::Short faceIndex)
4004 _preMeshInfo->FullLoadFromFile();
4006 SMESH::long_array_var aResult = new SMESH::long_array();
4007 if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
4009 if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(elemId) )
4011 SMDS_VolumeTool vtool( elem );
4012 if ( faceIndex < vtool.NbFaces() )
4014 aResult->length( vtool.NbFaceNodes( faceIndex ));
4015 const SMDS_MeshNode** nn = vtool.GetFaceNodes( faceIndex );
4016 for ( int i = 0; i < aResult->length(); ++i )
4017 aResult[ i ] = nn[ i ]->GetID();
4021 return aResult._retn();
4024 //=======================================================================
4025 //function : FindElementByNodes
4026 //purpose : Returns an element based on all given nodes.
4027 //=======================================================================
4029 CORBA::Long SMESH_Mesh_i::FindElementByNodes(const SMESH::long_array& nodes)
4032 _preMeshInfo->FullLoadFromFile();
4034 CORBA::Long elemID(0);
4035 if ( SMESHDS_Mesh* mesh = _impl->GetMeshDS() )
4037 vector< const SMDS_MeshNode * > nn( nodes.length() );
4038 for ( int i = 0; i < nodes.length(); ++i )
4039 if ( !( nn[i] = mesh->FindNode( nodes[i] )))
4042 const SMDS_MeshElement* elem = mesh->FindElement( nn, SMDSAbs_All, /*noMedium=*/false );
4043 if ( !elem && ( _impl->NbEdges ( ORDER_QUADRATIC ) ||
4044 _impl->NbFaces ( ORDER_QUADRATIC ) ||
4045 _impl->NbVolumes( ORDER_QUADRATIC )))
4046 elem = mesh->FindElement( nn, SMDSAbs_All, /*noMedium=*/true );
4048 if ( elem ) elemID = CORBA::Long( elem->GetID() );
4053 //=============================================================================
4055 * Returns true if given element is polygon
4057 //=============================================================================
4059 CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
4062 _preMeshInfo->FullLoadFromFile();
4064 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
4065 if ( aSMESHDS_Mesh == NULL ) return false;
4066 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
4067 if(!elem) return false;
4068 return elem->IsPoly();
4072 //=============================================================================
4074 * Returns true if given element is quadratic
4076 //=============================================================================
4078 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const CORBA::Long id)
4081 _preMeshInfo->FullLoadFromFile();
4083 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
4084 if ( aSMESHDS_Mesh == NULL ) return false;
4085 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
4086 if(!elem) return false;
4087 return elem->IsQuadratic();
4090 //=============================================================================
4092 * Returns diameter of ball discrete element or zero in case of an invalid \a id
4094 //=============================================================================
4096 CORBA::Double SMESH_Mesh_i::GetBallDiameter(CORBA::Long id)
4099 _preMeshInfo->FullLoadFromFile();
4101 if ( const SMDS_BallElement* ball =
4102 dynamic_cast<const SMDS_BallElement*>( _impl->GetMeshDS()->FindElement( id )))
4103 return ball->GetDiameter();
4108 //=============================================================================
4110 * Returns bary center for given element
4112 //=============================================================================
4114 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
4117 _preMeshInfo->FullLoadFromFile();
4119 SMESH::double_array_var aResult = new SMESH::double_array();
4120 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
4121 if ( aSMESHDS_Mesh == NULL )
4122 return aResult._retn();
4124 const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
4126 return aResult._retn();
4128 if(elem->GetType()==SMDSAbs_Volume) {
4129 SMDS_VolumeTool aTool;
4130 if(aTool.Set(elem)) {
4132 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
4137 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
4139 double x=0., y=0., z=0.;
4140 for(; anIt->more(); ) {
4142 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
4156 return aResult._retn();
4159 //================================================================================
4161 * \brief Create a group of elements preventing computation of a sub-shape
4163 //================================================================================
4165 SMESH::ListOfGroups*
4166 SMESH_Mesh_i::MakeGroupsOfBadInputElements( int theSubShapeID,
4167 const char* theGroupName )
4168 throw ( SALOME::SALOME_Exception )
4170 Unexpect aCatch(SALOME_SalomeException);
4172 if ( !theGroupName || strlen( theGroupName) == 0 )
4173 THROW_SALOME_CORBA_EXCEPTION( "empty group name",SALOME::BAD_PARAM );
4175 SMESH::ListOfGroups_var groups = new SMESH::ListOfGroups;
4177 // submesh by subshape id
4178 if ( !_impl->HasShapeToMesh() ) theSubShapeID = 1;
4179 if ( SMESH_subMesh * sm = _impl->GetSubMeshContaining( theSubShapeID ))
4182 SMESH_ComputeErrorPtr error = sm->GetComputeError();
4183 if ( error && !error->myBadElements.empty())
4185 // sort bad elements by type
4186 vector< const SMDS_MeshElement* > elemsByType[ SMDSAbs_NbElementTypes ];
4187 list<const SMDS_MeshElement*>::iterator elemIt = error->myBadElements.begin();
4188 list<const SMDS_MeshElement*>::iterator elemEnd = error->myBadElements.end();
4189 for ( ; elemIt != elemEnd; ++elemIt )
4191 const SMDS_MeshElement* elem = *elemIt;
4192 if ( !elem ) continue;
4194 if ( elem->GetID() < 1 )
4196 // elem is a temporary element, make a real element
4197 vector< const SMDS_MeshNode* > nodes;
4198 SMDS_NodeIteratorPtr nIt = elem->nodeIterator();
4199 while ( nIt->more() && elem )
4201 nodes.push_back( nIt->next() );
4202 if ( nodes.back()->GetID() < 1 )
4203 elem = 0; // a temporary element on temporary nodes
4207 ::SMESH_MeshEditor editor( _impl );
4208 elem = editor.AddElement( nodes, elem->GetType(), elem->IsPoly() );
4212 elemsByType[ elem->GetType() ].push_back( elem );
4215 // how many groups to create?
4217 for ( int i = 0; i < SMDSAbs_NbElementTypes; ++i )
4218 nbTypes += int( !elemsByType[ i ].empty() );
4219 groups->length( nbTypes );
4222 for ( int i = 0, iG = -1; i < SMDSAbs_NbElementTypes; ++i )
4224 vector< const SMDS_MeshElement* >& elems = elemsByType[ i ];
4225 if ( elems.empty() ) continue;
4227 groups[ ++iG ] = createGroup( SMESH::ElementType(i), theGroupName );
4228 if ( _gen_i->CanPublishInStudy( groups[ iG ] ))
4230 SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
4231 SMESH::SMESH_Mesh_var mesh = _this();
4232 SALOMEDS::SObject_wrap aSO =
4233 _gen_i->PublishGroup( study, mesh, groups[ iG ],
4234 GEOM::GEOM_Object::_nil(), theGroupName);
4235 aSO->_is_nil(); // avoid "unused variable" warning
4237 SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( groups[ iG ]);
4238 if ( !grp_i ) continue;
4240 if ( SMESHDS_Group* grpDS = dynamic_cast< SMESHDS_Group* >( grp_i->GetGroupDS() ))
4241 for ( size_t iE = 0; iE < elems.size(); ++iE )
4242 grpDS->SMDSGroup().Add( elems[ iE ]);
4247 return groups._retn();
4250 //=============================================================================
4252 * Create and publish group servants if any groups were imported or created anyhow
4254 //=============================================================================
4256 void SMESH_Mesh_i::CreateGroupServants()
4258 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
4259 SMESH::SMESH_Mesh_var aMesh = _this();
4262 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
4263 while ( groupIt->more() )
4265 ::SMESH_Group* group = groupIt->next();
4266 int anId = group->GetGroupDS()->GetID();
4268 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
4269 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
4271 addedIDs.insert( anId );
4273 SMESH_GroupBase_i* aGroupImpl;
4275 if ( SMESHDS_GroupOnGeom* groupOnGeom =
4276 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
4278 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
4279 shape = groupOnGeom->GetShape();
4282 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
4285 SMESH::SMESH_GroupBase_var groupVar = aGroupImpl->_this();
4286 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
4287 aGroupImpl->Register();
4289 // register CORBA object for persistence
4290 int nextId = _gen_i->RegisterObject( groupVar );
4291 if(MYDEBUG) { MESSAGE( "Add group to map with id = "<< nextId); }
4292 else { nextId = 0; } // avoid "unused variable" warning in release mode
4294 // publishing the groups in the study
4295 if ( !aStudy->_is_nil() ) {
4296 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
4297 _gen_i->PublishGroup( aStudy, aMesh, groupVar, shapeVar, group->GetName());
4300 if ( !addedIDs.empty() )
4303 set<int>::iterator id = addedIDs.begin();
4304 for ( ; id != addedIDs.end(); ++id )
4306 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(*id);
4307 int i = std::distance( _mapGroups.begin(), it );
4308 TPythonDump() << it->second << " = " << aMesh << ".GetGroups()[ "<< i << " ]";
4313 //=============================================================================
4315 * \brief Return groups cantained in _mapGroups by their IDs
4317 //=============================================================================
4319 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
4321 int nbGroups = groupIDs.size();
4322 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
4323 aList->length( nbGroups );
4325 list<int>::const_iterator ids = groupIDs.begin();
4326 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
4328 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
4329 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
4330 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
4332 aList->length( nbGroups );
4333 return aList._retn();
4336 //=============================================================================
4338 * \brief Return information about imported file
4340 //=============================================================================
4342 SMESH::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
4344 SMESH::MedFileInfo_var res( _medFileInfo );
4345 if ( !res.operator->() ) {
4346 res = new SMESH::MedFileInfo;
4348 res->fileSize = res->major = res->minor = res->release = -1;
4353 //=============================================================================
4355 * \brief Pass names of mesh groups from study to mesh DS
4357 //=============================================================================
4359 void SMESH_Mesh_i::checkGroupNames()
4361 int nbGrp = NbGroups();
4365 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
4366 if ( aStudy->_is_nil() )
4367 return; // nothing to do
4369 SMESH::ListOfGroups* grpList = 0;
4370 // avoid dump of "GetGroups"
4372 // store python dump into a local variable inside local scope
4373 SMESH::TPythonDump pDump; // do not delete this line of code
4374 grpList = GetGroups();
4377 for ( int gIndx = 0; gIndx < nbGrp; gIndx++ ) {
4378 SMESH::SMESH_GroupBase_ptr aGrp = (*grpList)[ gIndx ];
4381 SALOMEDS::SObject_wrap aGrpSO = _gen_i->ObjectToSObject( aStudy, aGrp );
4382 if ( aGrpSO->_is_nil() )
4384 // correct name of the mesh group if necessary
4385 const char* guiName = aGrpSO->GetName();
4386 if ( strcmp(guiName, aGrp->GetName()) )
4387 aGrp->SetName( guiName );
4391 //=============================================================================
4393 * \brief Sets list of notebook variables used for Mesh operations separated by ":" symbol
4395 //=============================================================================
4396 void SMESH_Mesh_i::SetParameters(const char* theParameters)
4398 SMESH_Gen_i::GetSMESHGen()->UpdateParameters( CORBA::Object_var( _this() ).in(),
4402 //=============================================================================
4404 * \brief Returns list of notebook variables used for Mesh operations separated by ":" symbol
4406 //=============================================================================
4408 char* SMESH_Mesh_i::GetParameters()
4410 return SMESH_Gen_i::GetSMESHGen()->GetParameters( SMESH::SMESH_Mesh_var( _this()) );
4413 //=============================================================================
4415 * \brief Returns list of notebook variables used for last Mesh operation
4417 //=============================================================================
4418 SMESH::string_array* SMESH_Mesh_i::GetLastParameters()
4420 SMESH::string_array_var aResult = new SMESH::string_array();
4421 SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
4423 CORBA::String_var aParameters = GetParameters();
4424 SALOMEDS::Study_var aStudy = gen->GetCurrentStudy();
4425 if ( !aStudy->_is_nil()) {
4426 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
4427 if(aSections->length() > 0) {
4428 SALOMEDS::ListOfStrings aVars = aSections[aSections->length()-1];
4429 aResult->length(aVars.length());
4430 for(int i = 0;i < aVars.length();i++)
4431 aResult[i] = CORBA::string_dup( aVars[i]);
4435 return aResult._retn();
4438 //=======================================================================
4439 //function : GetTypes
4440 //purpose : Returns types of elements it contains
4441 //=======================================================================
4443 SMESH::array_of_ElementType* SMESH_Mesh_i::GetTypes()
4446 return _preMeshInfo->GetTypes();
4448 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
4452 if (_impl->NbEdges()) types[nbTypes++] = SMESH::EDGE;
4453 if (_impl->NbFaces()) types[nbTypes++] = SMESH::FACE;
4454 if (_impl->NbVolumes()) types[nbTypes++] = SMESH::VOLUME;
4455 if (_impl->Nb0DElements()) types[nbTypes++] = SMESH::ELEM0D;
4456 if (_impl->NbBalls()) types[nbTypes++] = SMESH::BALL;
4457 types->length( nbTypes );
4459 return types._retn();
4462 //=======================================================================
4463 //function : GetMesh
4464 //purpose : Returns self
4465 //=======================================================================
4467 SMESH::SMESH_Mesh_ptr SMESH_Mesh_i::GetMesh()
4469 return SMESH::SMESH_Mesh::_duplicate( _this() );
4472 //=======================================================================
4473 //function : IsMeshInfoCorrect
4474 //purpose : * Returns false if GetMeshInfo() returns incorrect information that may
4475 // * happen if mesh data is not yet fully loaded from the file of study.
4476 //=======================================================================
4478 bool SMESH_Mesh_i::IsMeshInfoCorrect()
4480 return _preMeshInfo ? _preMeshInfo->IsMeshInfoCorrect() : true;
4483 //=============================================================================
4485 * \brief Returns number of mesh elements per each \a EntityType
4487 //=============================================================================
4489 SMESH::long_array* SMESH_Mesh_i::GetMeshInfo()
4492 return _preMeshInfo->GetMeshInfo();
4494 SMESH::long_array_var aRes = new SMESH::long_array();
4495 aRes->length(SMESH::Entity_Last);
4496 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
4498 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
4500 return aRes._retn();
4501 const SMDS_MeshInfo& aMeshInfo = aMeshDS->GetMeshInfo();
4502 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
4503 aRes[i] = aMeshInfo.NbEntities((SMDSAbs_EntityType)i);
4504 return aRes._retn();
4507 //=============================================================================
4509 * \brief Returns number of mesh elements per each \a ElementType
4511 //=============================================================================
4513 SMESH::long_array* SMESH_Mesh_i::GetNbElementsByType()
4515 SMESH::long_array_var aRes = new SMESH::long_array();
4516 aRes->length(SMESH::NB_ELEMENT_TYPES);
4517 for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++)
4520 const SMDS_MeshInfo* meshInfo = 0;
4522 meshInfo = _preMeshInfo;
4523 else if ( SMESHDS_Mesh* meshDS = _impl->GetMeshDS() )
4524 meshInfo = & meshDS->GetMeshInfo();
4527 for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++)
4528 aRes[i] = meshInfo->NbElements((SMDSAbs_ElementType)i);
4530 return aRes._retn();
4533 //=============================================================================
4535 * Collect statistic of mesh elements given by iterator
4537 //=============================================================================
4539 void SMESH_Mesh_i::CollectMeshInfo(const SMDS_ElemIteratorPtr theItr,
4540 SMESH::long_array& theInfo)
4542 if (!theItr) return;
4543 while (theItr->more())
4544 theInfo[ theItr->next()->GetEntityType() ]++;
4547 //=============================================================================
4548 namespace /* Iterators used in SMESH_Mesh_i::GetElements(SMESH::SMESH_IDSource_var obj,
4549 * SMESH::ElementType type) */
4551 using namespace SMESH::Controls;
4552 //-----------------------------------------------------------------------------
4553 struct PredicateIterator : public SMDS_ElemIterator
4555 SMDS_ElemIteratorPtr _elemIter;
4556 PredicatePtr _predicate;
4557 const SMDS_MeshElement* _elem;
4559 PredicateIterator( SMDS_ElemIteratorPtr iterator,
4560 PredicatePtr predicate):
4561 _elemIter(iterator), _predicate(predicate)
4569 virtual const SMDS_MeshElement* next()
4571 const SMDS_MeshElement* res = _elem;
4573 while ( _elemIter->more() && !_elem )
4575 _elem = _elemIter->next();
4576 if ( _elem && ( !_predicate->IsSatisfy( _elem->GetID() )))
4583 //-----------------------------------------------------------------------------
4584 struct IDSourceIterator : public SMDS_ElemIterator
4586 const CORBA::Long* _idPtr;
4587 const CORBA::Long* _idEndPtr;
4588 SMESH::long_array_var _idArray;
4589 const SMDS_Mesh* _mesh;
4590 const SMDSAbs_ElementType _type;
4591 const SMDS_MeshElement* _elem;
4593 IDSourceIterator( const SMDS_Mesh* mesh,
4594 const CORBA::Long* ids,
4596 SMDSAbs_ElementType type):
4597 _idPtr( ids ), _idEndPtr( ids + nbIds ), _mesh( mesh ), _type( type ), _elem( 0 )
4599 if ( _idPtr && nbIds && _mesh )
4602 IDSourceIterator( const SMDS_Mesh* mesh,
4603 SMESH::long_array* idArray,
4604 SMDSAbs_ElementType type):
4605 _idPtr( 0 ), _idEndPtr( 0 ), _idArray( idArray), _mesh( mesh ), _type( type ), _elem( 0 )
4607 if ( idArray && _mesh )
4609 _idPtr = &_idArray[0];
4610 _idEndPtr = _idPtr + _idArray->length();
4618 virtual const SMDS_MeshElement* next()
4620 const SMDS_MeshElement* res = _elem;
4622 while ( _idPtr < _idEndPtr && !_elem )
4624 if ( _type == SMDSAbs_Node )
4626 _elem = _mesh->FindNode( *_idPtr++ );
4628 else if ((_elem = _mesh->FindElement( *_idPtr++ )) &&
4629 _elem->GetType() != _type )
4637 //-----------------------------------------------------------------------------
4639 struct NodeOfElemIterator : public SMDS_ElemIterator
4641 TColStd_MapOfInteger _checkedNodeIDs;
4642 SMDS_ElemIteratorPtr _elemIter;
4643 SMDS_ElemIteratorPtr _nodeIter;
4644 const SMDS_MeshElement* _node;
4646 NodeOfElemIterator( SMDS_ElemIteratorPtr iter ): _elemIter( iter ), _node( 0 )
4648 if ( _elemIter && _elemIter->more() )
4650 _nodeIter = _elemIter->next()->nodesIterator();
4658 virtual const SMDS_MeshElement* next()
4660 const SMDS_MeshElement* res = _node;
4662 while (( _elemIter->more() || _nodeIter->more() ) && !_node )
4664 if ( _nodeIter->more() )
4666 _node = _nodeIter->next();
4667 if ( !_checkedNodeIDs.Add( _node->GetID() ))
4672 _nodeIter = _elemIter->next()->nodesIterator();
4680 //=============================================================================
4682 * Return iterator on elements of given type in given object
4684 //=============================================================================
4686 SMDS_ElemIteratorPtr SMESH_Mesh_i::GetElements(SMESH::SMESH_IDSource_ptr theObject,
4687 SMESH::ElementType theType)
4689 SMDS_ElemIteratorPtr elemIt;
4690 bool typeOK = false;
4691 SMDSAbs_ElementType elemType = SMDSAbs_ElementType( theType );
4693 SMESH::SMESH_Mesh_var meshVar = theObject->GetMesh();
4694 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( meshVar );
4695 if ( !mesh_i ) return elemIt;
4696 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
4698 if ( SMESH::DownCast<SMESH_Mesh_i*>( theObject ))
4700 elemIt = meshDS->elementsIterator( elemType );
4703 else if ( SMESH_subMesh_i* submesh_i = SMESH::DownCast<SMESH_subMesh_i*>( theObject ))
4705 SMESHDS_SubMesh* sm = ((SMESHDS_Mesh*) meshDS)->MeshElements( submesh_i->GetId() );
4708 elemIt = sm->GetElements();
4709 if ( elemType != SMDSAbs_Node )
4711 typeOK = ( elemIt && elemIt->more() && elemIt->next()->GetType() == elemType );
4712 elemIt = typeOK ? sm->GetElements() : SMDS_ElemIteratorPtr();
4716 else if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( theObject ))
4718 SMESHDS_GroupBase* groupDS = group_i->GetGroupDS();
4719 if ( groupDS && ( groupDS->GetType() == elemType || elemType == SMDSAbs_Node ))
4721 elemIt = groupDS->GetElements();
4722 typeOK = ( groupDS->GetType() == elemType );
4725 else if ( SMESH::Filter_i* filter_i = SMESH::DownCast<SMESH::Filter_i*>( theObject ))
4727 if ( filter_i->GetElementType() == theType || elemType == SMDSAbs_Node )
4729 SMESH::Predicate_i* pred_i = filter_i->GetPredicate_i();
4730 if ( pred_i && pred_i->GetPredicate() )
4732 SMDSAbs_ElementType filterType = SMDSAbs_ElementType( filter_i->GetElementType() );
4733 SMDS_ElemIteratorPtr allElemIt = meshDS->elementsIterator( filterType );
4734 elemIt = SMDS_ElemIteratorPtr( new PredicateIterator( allElemIt, pred_i->GetPredicate() ));
4735 typeOK = ( filterType == elemType );
4741 SMESH::array_of_ElementType_var types = theObject->GetTypes();
4742 const bool isNodes = ( types->length() == 1 && types[0] == SMESH::NODE );
4743 if ( isNodes && elemType != SMDSAbs_Node )
4745 if ( SMESH_MeshEditor_i::IsTemporaryIDSource( theObject ))
4748 if ( CORBA::Long* ids = SMESH_MeshEditor_i::GetTemporaryIDs( theObject, nbIds ))
4749 elemIt = SMDS_ElemIteratorPtr( new IDSourceIterator( meshDS, ids, nbIds, elemType ));
4753 SMESH::long_array_var ids = theObject->GetIDs();
4754 elemIt = SMDS_ElemIteratorPtr( new IDSourceIterator( meshDS, ids._retn(), elemType ));
4756 typeOK = ( isNodes == ( elemType == SMDSAbs_Node ));
4759 if ( elemIt && elemIt->more() && !typeOK )
4761 if ( elemType == SMDSAbs_Node )
4763 elemIt = SMDS_ElemIteratorPtr( new NodeOfElemIterator( elemIt ));
4767 elemIt = SMDS_ElemIteratorPtr();
4773 //=============================================================================
4774 namespace // Finding concurrent hypotheses
4775 //=============================================================================
4779 * \brief mapping of mesh dimension into shape type
4781 TopAbs_ShapeEnum shapeTypeByDim(const int theDim)
4783 TopAbs_ShapeEnum aType = TopAbs_SOLID;
4785 case 0: aType = TopAbs_VERTEX; break;
4786 case 1: aType = TopAbs_EDGE; break;
4787 case 2: aType = TopAbs_FACE; break;
4789 default:aType = TopAbs_SOLID; break;
4794 //-----------------------------------------------------------------------------
4796 * \brief Internal structure used to find concurent submeshes
4798 * It represents a pair < submesh, concurent dimension >, where
4799 * 'concurrent dimension' is dimension of shape where the submesh can concurent
4800 * with another submesh. In other words, it is dimension of a hypothesis assigned
4807 int _dim; //!< a dimension the algo can build (concurrent dimension)
4808 int _ownDim; //!< dimension of shape of _subMesh (>=_dim)
4809 TopTools_MapOfShape _shapeMap;
4810 SMESH_subMesh* _subMesh;
4811 list<const SMESHDS_Hypothesis*> _hypotheses; //!< algo is first, then its parameters
4813 //-----------------------------------------------------------------------------
4814 // Return the algorithm
4815 const SMESH_Algo* GetAlgo() const
4816 { return _hypotheses.empty() ? 0 : dynamic_cast<const SMESH_Algo*>( _hypotheses.front() ); }
4818 //-----------------------------------------------------------------------------
4820 SMESH_DimHyp(const SMESH_subMesh* theSubMesh,
4822 const TopoDS_Shape& theShape)
4824 _subMesh = (SMESH_subMesh*)theSubMesh;
4825 SetShape( theDim, theShape );
4828 //-----------------------------------------------------------------------------
4830 void SetShape(const int theDim,
4831 const TopoDS_Shape& theShape)
4834 _ownDim = SMESH_Gen::GetShapeDim(theShape);
4835 if (_dim >= _ownDim)
4836 _shapeMap.Add( theShape );
4838 TopExp_Explorer anExp( theShape, shapeTypeByDim(theDim) );
4839 for( ; anExp.More(); anExp.Next() )
4840 _shapeMap.Add( anExp.Current() );
4844 //-----------------------------------------------------------------------------
4845 //! Check sharing of sub-shapes
4846 static bool isShareSubShapes(const TopTools_MapOfShape& theToCheck,
4847 const TopTools_MapOfShape& theToFind,
4848 const TopAbs_ShapeEnum theType)
4850 bool isShared = false;
4851 TopTools_MapIteratorOfMapOfShape anItr( theToCheck );
4852 for (; !isShared && anItr.More(); anItr.Next() )
4854 const TopoDS_Shape aSubSh = anItr.Key();
4855 // check for case when concurrent dimensions are same
4856 isShared = theToFind.Contains( aSubSh );
4857 // check for sub-shape with concurrent dimension
4858 TopExp_Explorer anExp( aSubSh, theType );
4859 for ( ; !isShared && anExp.More(); anExp.Next() )
4860 isShared = theToFind.Contains( anExp.Current() );
4865 //-----------------------------------------------------------------------------
4866 //! check algorithms
4867 static bool checkAlgo(const SMESHDS_Hypothesis* theA1,
4868 const SMESHDS_Hypothesis* theA2)
4870 if ( !theA1 || !theA2 ||
4871 theA1->GetType() == SMESHDS_Hypothesis::PARAM_ALGO ||
4872 theA2->GetType() == SMESHDS_Hypothesis::PARAM_ALGO )
4873 return false; // one of the hypothesis is not algorithm
4874 // check algorithm names (should be equal)
4875 return strcmp( theA1->GetName(), theA2->GetName() ) == 0;
4879 //-----------------------------------------------------------------------------
4880 //! Check if sub-shape hypotheses are concurrent
4881 bool IsConcurrent(const SMESH_DimHyp* theOther) const
4883 if ( _subMesh == theOther->_subMesh )
4884 return false; // same sub-shape - should not be
4886 // if ( <own dim of either of submeshes> == <concurrent dim> &&
4887 // any of the two submeshes is not on COMPOUND shape )
4888 // -> no concurrency
4889 bool meIsCompound = (_subMesh->GetSubMeshDS() &&
4890 _subMesh->GetSubMeshDS()->IsComplexSubmesh());
4891 bool otherIsCompound = (theOther->_subMesh->GetSubMeshDS() &&
4892 theOther->_subMesh->GetSubMeshDS()->IsComplexSubmesh());
4893 if ( (_ownDim == _dim || theOther->_ownDim == _dim ) && (!meIsCompound || !otherIsCompound))
4896 // bool checkSubShape = ( _dim >= theOther->_dim )
4897 // ? isShareSubShapes( _shapeMap, theOther->_shapeMap, shapeTypeByDim(theOther->_dim) )
4898 // : isShareSubShapes( theOther->_shapeMap, _shapeMap, shapeTypeByDim(_dim) ) ;
4899 bool checkSubShape = isShareSubShapes( _shapeMap, theOther->_shapeMap, shapeTypeByDim(_dim));
4900 if ( !checkSubShape )
4903 // check algorithms to be same
4904 if ( !checkAlgo( this->GetAlgo(), theOther->GetAlgo() ))
4905 return true; // different algorithms -> concurrency !
4907 // check hypothesises for concurrence (skip first as algorithm)
4909 // pointers should be same, because it is referened from mesh hypothesis partition
4910 list <const SMESHDS_Hypothesis*>::const_iterator hypIt = _hypotheses.begin();
4911 list <const SMESHDS_Hypothesis*>::const_iterator otheEndIt = theOther->_hypotheses.end();
4912 for ( hypIt++ /*skip first as algo*/; hypIt != _hypotheses.end(); hypIt++ )
4913 if ( find( theOther->_hypotheses.begin(), otheEndIt, *hypIt ) != otheEndIt )
4915 // the submeshes are concurrent if their algorithms has different parameters
4916 return nbSame != theOther->_hypotheses.size() - 1;
4919 // Return true if algorithm of this SMESH_DimHyp is used if no
4920 // sub-mesh order is imposed by the user
4921 bool IsHigherPriorityThan( const SMESH_DimHyp* theOther ) const
4923 // NeedDiscreteBoundary() algo has a higher priority
4924 if ( this ->GetAlgo()->NeedDiscreteBoundary() !=
4925 theOther->GetAlgo()->NeedDiscreteBoundary() )
4926 return !this->GetAlgo()->NeedDiscreteBoundary();
4928 return ( this->_subMesh->GetId() < theOther->_subMesh->GetId() );
4931 }; // end of SMESH_DimHyp
4932 //-----------------------------------------------------------------------------
4934 typedef list<const SMESH_DimHyp*> TDimHypList;
4936 //-----------------------------------------------------------------------------
4938 void addDimHypInstance(const int theDim,
4939 const TopoDS_Shape& theShape,
4940 const SMESH_Algo* theAlgo,
4941 const SMESH_subMesh* theSubMesh,
4942 const list <const SMESHDS_Hypothesis*>& theHypList,
4943 TDimHypList* theDimHypListArr )
4945 TDimHypList& listOfdimHyp = theDimHypListArr[theDim];
4946 if ( listOfdimHyp.empty() || listOfdimHyp.back()->_subMesh != theSubMesh ) {
4947 SMESH_DimHyp* dimHyp = new SMESH_DimHyp( theSubMesh, theDim, theShape );
4948 dimHyp->_hypotheses.push_front(theAlgo);
4949 listOfdimHyp.push_back( dimHyp );
4952 SMESH_DimHyp* dimHyp = const_cast<SMESH_DimHyp*>( listOfdimHyp.back() );
4953 dimHyp->_hypotheses.insert( dimHyp->_hypotheses.end(),
4954 theHypList.begin(), theHypList.end() );
4957 //-----------------------------------------------------------------------------
4958 void addInOrderOfPriority( const SMESH_DimHyp* theDimHyp,
4959 TDimHypList& theListOfConcurr)
4961 if ( theListOfConcurr.empty() )
4963 theListOfConcurr.push_back( theDimHyp );
4967 TDimHypList::iterator hypIt = theListOfConcurr.begin();
4968 while ( hypIt != theListOfConcurr.end() &&
4969 !theDimHyp->IsHigherPriorityThan( *hypIt ))
4971 theListOfConcurr.insert( hypIt, theDimHyp );
4975 //-----------------------------------------------------------------------------
4976 void findConcurrents(const SMESH_DimHyp* theDimHyp,
4977 const TDimHypList& theListOfDimHyp,
4978 TDimHypList& theListOfConcurrHyp,
4979 set<int>& theSetOfConcurrId )
4981 TDimHypList::const_reverse_iterator rIt = theListOfDimHyp.rbegin();
4982 for ( ; rIt != theListOfDimHyp.rend(); rIt++ )
4984 const SMESH_DimHyp* curDimHyp = *rIt;
4985 if ( curDimHyp == theDimHyp )
4986 break; // meet own dimHyp pointer in same dimension
4988 if ( theDimHyp->IsConcurrent( curDimHyp ) &&
4989 theSetOfConcurrId.insert( curDimHyp->_subMesh->GetId() ).second )
4991 addInOrderOfPriority( curDimHyp, theListOfConcurrHyp );
4996 //-----------------------------------------------------------------------------
4997 void unionLists(TListOfInt& theListOfId,
4998 TListOfListOfInt& theListOfListOfId,
5001 TListOfListOfInt::iterator it = theListOfListOfId.begin();
5002 for ( int i = 0; it != theListOfListOfId.end(); it++, i++ ) {
5004 continue; //skip already treated lists
5005 // check if other list has any same submesh object
5006 TListOfInt& otherListOfId = *it;
5007 if ( find_first_of( theListOfId.begin(), theListOfId.end(),
5008 otherListOfId.begin(), otherListOfId.end() ) == theListOfId.end() )
5011 // union two lists (from source into target)
5012 TListOfInt::iterator it2 = otherListOfId.begin();
5013 for ( ; it2 != otherListOfId.end(); it2++ ) {
5014 if ( find( theListOfId.begin(), theListOfId.end(), (*it2) ) == theListOfId.end() )
5015 theListOfId.push_back(*it2);
5017 // clear source list
5018 otherListOfId.clear();
5021 //-----------------------------------------------------------------------------
5023 //! free memory allocated for dimension-hypothesis objects
5024 void removeDimHyps( TDimHypList* theArrOfList )
5026 for (int i = 0; i < 4; i++ ) {
5027 TDimHypList& listOfdimHyp = theArrOfList[i];
5028 TDimHypList::const_iterator it = listOfdimHyp.begin();
5029 for ( ; it != listOfdimHyp.end(); it++ )
5034 //-----------------------------------------------------------------------------
5036 * \brief find common submeshes with given submesh
5037 * \param theSubMeshList list of already collected submesh to check
5038 * \param theSubMesh given submesh to intersect with other
5039 * \param theCommonSubMeshes collected common submeshes
5041 void findCommonSubMesh (list<const SMESH_subMesh*>& theSubMeshList,
5042 const SMESH_subMesh* theSubMesh,
5043 set<const SMESH_subMesh*>& theCommon )
5047 list<const SMESH_subMesh*>::const_iterator it = theSubMeshList.begin();
5048 for ( ; it != theSubMeshList.end(); it++ )
5049 theSubMesh->FindIntersection( *it, theCommon );
5050 theSubMeshList.push_back( theSubMesh );
5051 //theCommon.insert( theSubMesh );
5056 //=============================================================================
5058 * \brief Return submesh objects list in meshing order
5060 //=============================================================================
5062 SMESH::submesh_array_array* SMESH_Mesh_i::GetMeshOrder()
5064 SMESH::submesh_array_array_var aResult = new SMESH::submesh_array_array();
5066 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5068 return aResult._retn();
5070 ::SMESH_Mesh& mesh = GetImpl();
5071 TListOfListOfInt anOrder = mesh.GetMeshOrder(); // is there already defined order?
5072 if ( !anOrder.size() ) {
5074 // collect submeshes and detect concurrent algorithms and hypothesises
5075 TDimHypList dimHypListArr[4]; // dimHyp list for each shape dimension
5077 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
5078 for ( ; i_sm != _mapSubMesh.end(); i_sm++ ) {
5079 ::SMESH_subMesh* sm = (*i_sm).second;
5081 const TopoDS_Shape& aSubMeshShape = sm->GetSubShape();
5083 // list of assigned hypothesises
5084 const list <const SMESHDS_Hypothesis*>& hypList = mesh.GetHypothesisList(aSubMeshShape);
5085 // Find out dimensions where the submesh can be concurrent.
5086 // We define the dimensions by algo of each of hypotheses in hypList
5087 list <const SMESHDS_Hypothesis*>::const_iterator hypIt = hypList.begin();
5088 for( ; hypIt != hypList.end(); hypIt++ ) {
5089 SMESH_Algo* anAlgo = 0;
5090 const SMESH_Hypothesis* hyp = dynamic_cast<const SMESH_Hypothesis*>(*hypIt);
5091 if ( hyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO )
5092 // hyp it-self is algo
5093 anAlgo = (SMESH_Algo*)dynamic_cast<const SMESH_Algo*>(hyp);
5095 // try to find algorithm with help of sub-shapes
5096 TopExp_Explorer anExp( aSubMeshShape, shapeTypeByDim(hyp->GetDim()) );
5097 for ( ; !anAlgo && anExp.More(); anExp.Next() )
5098 anAlgo = mesh.GetGen()->GetAlgo( mesh, anExp.Current() );
5101 continue; // no algorithm assigned to a current submesh
5103 int dim = anAlgo->GetDim(); // top concurrent dimension (see comment to SMESH_DimHyp)
5104 // the submesh can concurrent at <dim> (or lower dims if !anAlgo->NeedDiscreteBoundary())
5106 // create instance of dimension-hypothesis for found concurrent dimension(s) and algorithm
5107 for ( int j = anAlgo->NeedDiscreteBoundary() ? dim : 1, jn = dim; j <= jn; j++ )
5108 addDimHypInstance( j, aSubMeshShape, anAlgo, sm, hypList, dimHypListArr );
5110 } // end iterations on submesh
5112 // iterate on created dimension-hypotheses and check for concurrents
5113 for ( int i = 0; i < 4; i++ ) {
5114 const TDimHypList& listOfDimHyp = dimHypListArr[i];
5115 // check for concurrents in own and other dimensions (step-by-step)
5116 TDimHypList::const_iterator dhIt = listOfDimHyp.begin();
5117 for ( ; dhIt != listOfDimHyp.end(); dhIt++ ) {
5118 const SMESH_DimHyp* dimHyp = *dhIt;
5119 TDimHypList listOfConcurr;
5120 set<int> setOfConcurrIds;
5121 // looking for concurrents and collect into own list
5122 for ( int j = i; j < 4; j++ )
5123 findConcurrents( dimHyp, dimHypListArr[j], listOfConcurr, setOfConcurrIds );
5124 // check if any concurrents found
5125 if ( listOfConcurr.size() > 0 ) {
5126 // add own submesh to list of concurrent
5127 addInOrderOfPriority( dimHyp, listOfConcurr );
5128 list<int> listOfConcurrIds;
5129 TDimHypList::iterator hypIt = listOfConcurr.begin();
5130 for ( ; hypIt != listOfConcurr.end(); ++hypIt )
5131 listOfConcurrIds.push_back( (*hypIt)->_subMesh->GetId() );
5132 anOrder.push_back( listOfConcurrIds );
5137 removeDimHyps(dimHypListArr);
5139 // now, minimise the number of concurrent groups
5140 // Here we assume that lists of submeshes can have same submesh
5141 // in case of multi-dimension algorithms, as result
5142 // list with common submesh has to be united into one list
5144 TListOfListOfInt::iterator listIt = anOrder.begin();
5145 for(; listIt != anOrder.end(); listIt++, listIndx++ )
5146 unionLists( *listIt, anOrder, listIndx + 1 );
5148 // convert submesh ids into interface instances
5149 // and dump command into python
5150 convertMeshOrder( anOrder, aResult, false );
5152 return aResult._retn();
5155 //=============================================================================
5157 * \brief Set submesh object order
5158 * \param theSubMeshArray submesh array order
5160 //=============================================================================
5162 ::CORBA::Boolean SMESH_Mesh_i::SetMeshOrder(const SMESH::submesh_array_array& theSubMeshArray)
5165 _preMeshInfo->ForgetOrLoad();
5168 ::SMESH_Mesh& mesh = GetImpl();
5170 TPythonDump aPythonDump; // prevent dump of called methods
5171 aPythonDump << "isDone = " << SMESH::SMESH_Mesh_var(_this()) << ".SetMeshOrder( [ ";
5173 TListOfListOfInt subMeshOrder;
5174 for ( int i = 0, n = theSubMeshArray.length(); i < n; i++ )
5176 const SMESH::submesh_array& aSMArray = theSubMeshArray[i];
5177 TListOfInt subMeshIds;
5178 aPythonDump << "[ ";
5179 // Collect subMeshes which should be clear
5180 // do it list-by-list, because modification of submesh order
5181 // take effect between concurrent submeshes only
5182 set<const SMESH_subMesh*> subMeshToClear;
5183 list<const SMESH_subMesh*> subMeshList;
5184 for ( int j = 0, jn = aSMArray.length(); j < jn; j++ )
5186 const SMESH::SMESH_subMesh_var subMesh = SMESH::SMESH_subMesh::_duplicate(aSMArray[j]);
5188 aPythonDump << ", ";
5189 aPythonDump << subMesh;
5190 subMeshIds.push_back( subMesh->GetId() );
5191 // detect common parts of submeshes
5192 if ( _mapSubMesh.find(subMesh->GetId()) != _mapSubMesh.end() )
5193 findCommonSubMesh( subMeshList, _mapSubMesh[ subMesh->GetId() ], subMeshToClear );
5195 aPythonDump << " ]";
5196 subMeshOrder.push_back( subMeshIds );
5198 // clear collected submeshes
5199 set<const SMESH_subMesh*>::iterator clrIt = subMeshToClear.begin();
5200 for ( ; clrIt != subMeshToClear.end(); clrIt++ )
5201 if ( SMESH_subMesh* sm = (SMESH_subMesh*)*clrIt )
5202 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
5204 aPythonDump << " ])";
5206 mesh.SetMeshOrder( subMeshOrder );
5212 //=============================================================================
5214 * \brief Convert submesh ids into submesh interfaces
5216 //=============================================================================
5218 void SMESH_Mesh_i::convertMeshOrder (const TListOfListOfInt& theIdsOrder,
5219 SMESH::submesh_array_array& theResOrder,
5220 const bool theIsDump)
5222 int nbSet = theIdsOrder.size();
5223 TPythonDump aPythonDump; // prevent dump of called methods
5225 aPythonDump << "[ ";
5226 theResOrder.length(nbSet);
5227 TListOfListOfInt::const_iterator it = theIdsOrder.begin();
5229 for( ; it != theIdsOrder.end(); it++ ) {
5230 // translate submesh identificators into submesh objects
5231 // takeing into account real number of concurrent lists
5232 const TListOfInt& aSubOrder = (*it);
5233 if (!aSubOrder.size())
5236 aPythonDump << "[ ";
5237 // convert shape indeces into interfaces
5238 SMESH::submesh_array_var aResSubSet = new SMESH::submesh_array();
5239 aResSubSet->length(aSubOrder.size());
5240 TListOfInt::const_iterator subIt = aSubOrder.begin();
5241 for( int j = 0; subIt != aSubOrder.end(); subIt++ ) {
5242 if ( _mapSubMeshIor.find(*subIt) == _mapSubMeshIor.end() )
5244 SMESH::SMESH_subMesh_var subMesh =
5245 SMESH::SMESH_subMesh::_duplicate( _mapSubMeshIor[*subIt] );
5248 aPythonDump << ", ";
5249 aPythonDump << subMesh;
5251 aResSubSet[ j++ ] = subMesh;
5254 aPythonDump << " ]";
5255 theResOrder[ listIndx++ ] = aResSubSet;
5257 // correct number of lists
5258 theResOrder.length( listIndx );
5261 // finilise python dump
5262 aPythonDump << " ]";
5263 aPythonDump << " = " << SMESH::SMESH_Mesh_var(_this()) << ".GetMeshOrder()";
5267 //================================================================================
5269 // Implementation of SMESH_MeshPartDS
5271 SMESH_MeshPartDS::SMESH_MeshPartDS(SMESH::SMESH_IDSource_ptr meshPart):
5272 SMESHDS_Mesh( /*meshID=*/-1, /*isEmbeddedMode=*/true)
5274 SMESH::SMESH_Mesh_var mesh = meshPart->GetMesh();
5275 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
5277 _meshDS = mesh_i->GetImpl().GetMeshDS();
5279 SetPersistentId( _meshDS->GetPersistentId() );
5281 if ( mesh_i == SMESH::DownCast<SMESH_Mesh_i*>( meshPart ))
5283 // <meshPart> is the whole mesh
5284 myInfo = _meshDS->GetMeshInfo(); // copy mesh info;
5286 set<SMESHDS_GroupBase*>& myGroupSet = const_cast<set<SMESHDS_GroupBase*>&>( GetGroups() );
5287 myGroupSet = _meshDS->GetGroups();
5292 SMESH::long_array_var anIDs = meshPart->GetIDs();
5293 SMESH::array_of_ElementType_var types = meshPart->GetTypes();
5294 if ( types->length() == 1 && types[0] == SMESH::NODE ) // group of nodes
5296 for (int i=0; i < anIDs->length(); i++)
5297 if ( const SMDS_MeshNode * n = _meshDS->FindNode(anIDs[i]))
5298 if ( _elements[ SMDSAbs_Node ].insert( n ).second )
5303 for (int i=0; i < anIDs->length(); i++)
5304 if ( const SMDS_MeshElement * e = _meshDS->FindElement(anIDs[i]))
5305 if ( _elements[ e->GetType() ].insert( e ).second )
5308 SMDS_ElemIteratorPtr nIt = e->nodesIterator();
5309 while ( nIt->more() )
5311 const SMDS_MeshNode * n = (const SMDS_MeshNode*) nIt->next();
5312 if ( _elements[ SMDSAbs_Node ].insert( n ).second )
5319 _meshDS = 0; // to enforce iteration on _elements and _nodes
5322 // -------------------------------------------------------------------------------------
5323 SMESH_MeshPartDS::SMESH_MeshPartDS(const std::list< const SMDS_MeshElement* > & meshPart):
5324 SMESHDS_Mesh( /*meshID=*/-1, /*isEmbeddedMode=*/true), _meshDS(0)
5327 list< const SMDS_MeshElement* >::const_iterator partIt = meshPart.begin();
5328 for ( ; partIt != meshPart.end(); ++partIt )
5329 if ( const SMDS_MeshElement * e = *partIt )
5330 if ( _elements[ e->GetType() ].insert( e ).second )
5333 SMDS_ElemIteratorPtr nIt = e->nodesIterator();
5334 while ( nIt->more() )
5336 const SMDS_MeshNode * n = (const SMDS_MeshNode*) nIt->next();
5337 if ( _elements[ SMDSAbs_Node ].insert( n ).second )
5343 // -------------------------------------------------------------------------------------
5344 SMDS_ElemIteratorPtr SMESH_MeshPartDS::elementGeomIterator(SMDSAbs_GeometryType geomType) const
5346 if ( _meshDS ) return _meshDS->elementGeomIterator( geomType );
5348 typedef SMDS_SetIterator
5349 <const SMDS_MeshElement*,
5350 TIDSortedElemSet::const_iterator,
5351 SMDS::SimpleAccessor<const SMDS_MeshElement*, TIDSortedElemSet::const_iterator>,
5352 SMDS_MeshElement::GeomFilter
5355 SMDSAbs_ElementType type = SMDS_MeshCell::toSmdsType( geomType );
5357 return SMDS_ElemIteratorPtr( new TIter( _elements[type].begin(),
5358 _elements[type].end(),
5359 SMDS_MeshElement::GeomFilter( geomType )));
5361 // -------------------------------------------------------------------------------------
5362 SMDS_ElemIteratorPtr SMESH_MeshPartDS::elementEntityIterator(SMDSAbs_EntityType entity) const
5364 if ( _meshDS ) return _meshDS->elementEntityIterator( entity );
5366 typedef SMDS_SetIterator
5367 <const SMDS_MeshElement*,
5368 TIDSortedElemSet::const_iterator,
5369 SMDS::SimpleAccessor<const SMDS_MeshElement*, TIDSortedElemSet::const_iterator>,
5370 SMDS_MeshElement::EntityFilter
5373 SMDSAbs_ElementType type = SMDS_MeshCell::toSmdsType( entity );
5375 return SMDS_ElemIteratorPtr( new TIter( _elements[type].begin(),
5376 _elements[type].end(),
5377 SMDS_MeshElement::EntityFilter( entity )));
5379 // -------------------------------------------------------------------------------------
5380 SMDS_ElemIteratorPtr SMESH_MeshPartDS::elementsIterator(SMDSAbs_ElementType type) const
5382 typedef SMDS_SetIterator<const SMDS_MeshElement*, TIDSortedElemSet::const_iterator > TIter;
5383 if ( type == SMDSAbs_All && !_meshDS )
5385 typedef vector< SMDS_ElemIteratorPtr > TIterVec;
5387 for ( int i = 0; i < SMDSAbs_NbElementTypes; ++i )
5388 if ( !_elements[i].empty() && i != SMDSAbs_Node )
5390 ( SMDS_ElemIteratorPtr( new TIter( _elements[i].begin(), _elements[i].end() )));
5392 typedef SMDS_IteratorOnIterators<const SMDS_MeshElement*, TIterVec > TIterOnIters;
5393 return SMDS_ElemIteratorPtr( new TIterOnIters( iterVec ));
5395 return _meshDS ? _meshDS->elementsIterator(type) : SMDS_ElemIteratorPtr
5396 ( new TIter( _elements[type].begin(), _elements[type].end() ));
5398 // -------------------------------------------------------------------------------------
5399 #define _GET_ITER_DEFINE( iterType, methName, elem, elemType) \
5400 iterType SMESH_MeshPartDS::methName( bool idInceasingOrder) const \
5402 typedef SMDS_SetIterator<const elem*, TIDSortedElemSet::const_iterator > TIter; \
5403 return _meshDS ? _meshDS->methName(idInceasingOrder) : iterType \
5404 ( new TIter( _elements[elemType].begin(), _elements[elemType].end() )); \
5406 // -------------------------------------------------------------------------------------
5407 _GET_ITER_DEFINE( SMDS_NodeIteratorPtr, nodesIterator, SMDS_MeshNode, SMDSAbs_Node )
5408 _GET_ITER_DEFINE( SMDS_EdgeIteratorPtr, edgesIterator, SMDS_MeshEdge, SMDSAbs_Edge )
5409 _GET_ITER_DEFINE( SMDS_FaceIteratorPtr, facesIterator, SMDS_MeshFace, SMDSAbs_Face )
5410 _GET_ITER_DEFINE( SMDS_VolumeIteratorPtr, volumesIterator, SMDS_MeshVolume, SMDSAbs_Volume)
5411 #undef _GET_ITER_DEFINE
5413 // END Implementation of SMESH_MeshPartDS
5415 //================================================================================