1 // Copyright (C) 2007-2022 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, or (at your option) any later version.
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_Field.h"
30 #include "DriverMED_W_SMESHDS_Mesh.h"
31 #include "MED_Factory.hxx"
32 #include "SMDS_LinearEdge.hxx"
33 #include "SMDS_EdgePosition.hxx"
34 #include "SMDS_ElemIterator.hxx"
35 #include "SMDS_FacePosition.hxx"
36 #include "SMDS_IteratorOnIterators.hxx"
37 #include "SMDS_MeshGroup.hxx"
38 #include "SMDS_SetIterator.hxx"
39 #include "SMDS_StdIterator.hxx"
40 #include "SMDS_VolumeTool.hxx"
41 #include "SMESHDS_Command.hxx"
42 #include "SMESHDS_CommandType.hxx"
43 #include "SMESHDS_Group.hxx"
44 #include "SMESHDS_GroupOnGeom.hxx"
45 #include "SMESH_Controls.hxx"
46 #include "SMESH_File.hxx"
47 #include "SMESH_Filter_i.hxx"
48 #include "SMESH_Gen_i.hxx"
49 #include "SMESH_Group.hxx"
50 #include "SMESH_Group_i.hxx"
51 #include "SMESH_Mesh.hxx"
52 #include "SMESH_MeshAlgos.hxx"
53 #include "SMESH_MeshEditor.hxx"
54 #include "SMESH_MeshEditor_i.hxx"
55 #include "SMESH_MeshPartDS.hxx"
56 #include "SMESH_MesherHelper.hxx"
57 #include "SMESH_PreMeshInfo.hxx"
58 #include "SMESH_PythonDump.hxx"
59 #include "SMESH_subMesh_i.hxx"
61 #include <SALOMEDS_Attributes_wrap.hxx>
62 #include <SALOMEDS_wrap.hxx>
63 #include <Utils_ExceptHandlers.hxx>
64 #include <utilities.h>
66 #include <GEOMImpl_Types.hxx>
67 #include <GEOM_wrap.hxx>
70 #include <BRep_Builder.hxx>
71 #include <Standard_ErrorHandler.hxx>
72 #include <TColStd_MapOfInteger.hxx>
74 #include <TopExp_Explorer.hxx>
75 #include <TopTools_DataMapOfShapeShape.hxx>
76 #include <TopTools_MapIteratorOfMapOfShape.hxx>
77 #include <TopTools_MapOfShape.hxx>
78 #include <TopoDS_Compound.hxx>
85 #include <vtkUnstructuredGridWriter.h>
87 // to pass CORBA exception and TooLargeForExport exception through SMESH_TRY
88 #define SMY_OWN_CATCH \
89 catch( SALOME::SALOME_Exception& se ) { throw se; } \
90 catch( ::SMESH_Mesh::TooLargeForExport& ex ) \
91 { SALOME::ExceptionStruct se = { \
93 CORBA::string_dup(SMESH_Comment("Mesh is too large for export in format ") << ex.what()), \
94 CORBA::string_dup(SMESH_Comment("format=") << ex.what() ), 0 }; \
95 throw SALOME::SALOME_Exception( se ); }
97 #include "SMESH_TryCatch.hxx" // include after OCCT headers!
100 static int MYDEBUG = 0;
102 static int MYDEBUG = 0;
106 using SMESH::TPythonDump;
109 int SMESH_Mesh_i::_idGenerator = 0;
111 //=============================================================================
115 //=============================================================================
117 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
119 : SALOME::GenericObj_i( thePOA )
123 _id = _idGenerator++;
126 _previewEditor = NULL;
131 //=============================================================================
135 //=============================================================================
137 SMESH_Mesh_i::~SMESH_Mesh_i()
140 map<int, SMESH::SMESH_GroupBase_ptr>::iterator itGr;
141 for (itGr = _mapGroups.begin(); itGr != _mapGroups.end(); itGr++)
142 if (SMESH_GroupBase_i* aGroup = SMESH::DownCast<SMESH_GroupBase_i*>(itGr->second))
144 aGroup->UnRegister();
145 SMESH::SMESH_GroupBase_var( itGr->second );
150 map<int, SMESH::SMESH_subMesh_ptr>::iterator itSM;
151 for ( itSM = _mapSubMeshIor.begin(); itSM != _mapSubMeshIor.end(); itSM++ )
152 if ( SMESH_subMesh_i* aSubMesh = SMESH::DownCast<SMESH_subMesh_i*>( itSM->second ))
154 aSubMesh->UnRegister();
155 SMESH::SMESH_subMesh_var( itSM->second );
157 _mapSubMeshIor.clear();
159 // destroy hypotheses. _mapHypo contains all hyps ever been assigned
160 map<int, SMESH::SMESH_Hypothesis_ptr>::iterator itH;
161 for ( itH = _mapHypo.begin(); itH != _mapHypo.end(); itH++ ) {
162 if ( SMESH_Hypothesis_i* hyp_i = SMESH::DownCast<SMESH_Hypothesis_i*>( itH->second ))
163 if ( SMESH_Hypothesis * smHyp = _impl->GetHypothesis( itH->first ))
164 if ( _impl->GetMeshDS()->IsUsedHypothesis( smHyp ))
167 SMESH::SMESH_Hypothesis_var( itH->second ); // decref CORBA object
171 // clear cached shapes if no more meshes remain; (the cache is blame,
172 // together with publishing, of spent time increasing in issue 22874)
173 if ( _impl->NbMeshes() == 1 )
174 _gen_i->GetShapeReader()->ClearClientBuffer();
176 delete _editor; _editor = NULL;
177 delete _previewEditor; _previewEditor = NULL;
178 delete _impl; _impl = NULL;
179 delete _preMeshInfo; _preMeshInfo = NULL;
182 //=============================================================================
186 * Associate <this> mesh with <theShape> and put a reference
187 * to <theShape> into the current study;
188 * the previous shape is substituted by the new one.
190 //=============================================================================
192 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
194 Unexpect aCatch(SALOME_SalomeException);
196 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
198 catch(SALOME_Exception & S_ex) {
199 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
201 // to track changes of GEOM groups
202 SMESH::SMESH_Mesh_var mesh = _this();
203 addGeomGroupData( theShapeObject, mesh );
204 if ( !CORBA::is_nil( theShapeObject ))
205 _mainShapeTick = theShapeObject->GetTick();
208 //================================================================================
210 * \brief Return true if mesh has a shape to build a shape on
212 //================================================================================
214 CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
216 Unexpect aCatch(SALOME_SalomeException);
219 res = _impl->HasShapeToMesh();
221 catch(SALOME_Exception & S_ex) {
222 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
227 //================================================================================
229 * \brief Return the shape to mesh
231 //================================================================================
233 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
235 Unexpect aCatch(SALOME_SalomeException);
236 GEOM::GEOM_Object_var aShapeObj;
238 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
241 aShapeObj = _gen_i->ShapeToGeomObject( S );
242 if ( aShapeObj->_is_nil() )
244 // S was removed from GEOM_Client by newGroupShape() called by other mesh;
245 // find GEOM_Object by entry (IPAL52735)
246 list<TGeomGroupData>::iterator data = _geomGroupData.begin();
247 for ( ; data != _geomGroupData.end(); ++data )
248 if ( data->_smeshObject->_is_equivalent( _this() ))
250 SALOMEDS::SObject_wrap so = _gen_i->getStudyServant()->FindObjectID( data->_groupEntry.c_str() );
251 CORBA::Object_var obj = _gen_i->SObjectToObject( so );
252 aShapeObj = GEOM::GEOM_Object::_narrow( obj );
258 catch(SALOME_Exception & S_ex) {
259 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
261 return aShapeObj._retn();
264 //================================================================================
266 * \brief Return false if the mesh is not yet fully loaded from the study file
268 //================================================================================
270 CORBA::Boolean SMESH_Mesh_i::IsLoaded()
272 Unexpect aCatch(SALOME_SalomeException);
273 return !_preMeshInfo;
276 //================================================================================
278 * \brief Load full mesh data from the study file
280 //================================================================================
282 void SMESH_Mesh_i::Load()
284 Unexpect aCatch(SALOME_SalomeException);
286 _preMeshInfo->FullLoadFromFile();
289 //================================================================================
291 * \brief Remove all nodes and elements
293 //================================================================================
295 void SMESH_Mesh_i::Clear()
297 Unexpect aCatch(SALOME_SalomeException);
299 _preMeshInfo->ForgetOrLoad(); // load in case if !HasShapeToMesh()
303 //CheckGeomGroupModif(); // issue 20145
305 catch(SALOME_Exception & S_ex) {
306 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
309 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".Clear()";
311 SMESH::SMESH_Mesh_var mesh = _this();
312 _gen_i->UpdateIcons( mesh );
315 //================================================================================
317 * \brief Remove all nodes and elements for indicated shape
319 //================================================================================
321 void SMESH_Mesh_i::ClearSubMesh(CORBA::Long ShapeID)
323 Unexpect aCatch(SALOME_SalomeException);
325 _preMeshInfo->FullLoadFromFile();
328 _impl->ClearSubMesh( ShapeID );
330 catch(SALOME_Exception & S_ex) {
331 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
333 _impl->GetMeshDS()->Modified();
335 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ClearSubMesh( " << ShapeID << " )";
338 //=============================================================================
340 * Convert enum Driver_Mesh::Status to SMESH::DriverMED_ReadStatus
342 //=============================================================================
344 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
346 SMESH::DriverMED_ReadStatus res;
349 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
350 res = SMESH::DRS_OK; break;
351 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
352 res = SMESH::DRS_EMPTY; break;
353 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
354 res = SMESH::DRS_WARN_RENUMBER; break;
355 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
356 res = SMESH::DRS_WARN_SKIP_ELEM; break;
357 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_DESCENDING:
358 res = SMESH::DRS_WARN_DESCENDING; break;
359 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
361 res = SMESH::DRS_FAIL; break;
366 //=============================================================================
368 * Convert ::SMESH_ComputeError to SMESH::ComputeError
370 //=============================================================================
372 static SMESH::ComputeError* ConvertComputeError( SMESH_ComputeErrorPtr errorPtr )
374 SMESH::ComputeError_var errVar = new SMESH::ComputeError();
375 errVar->subShapeID = -1;
376 errVar->hasBadMesh = false;
378 if ( !errorPtr || errorPtr->IsOK() )
380 errVar->code = SMESH::COMPERR_OK;
384 errVar->code = ConvertDriverMEDReadStatus( errorPtr->myName );
385 errVar->comment = errorPtr->myComment.c_str();
387 return errVar._retn();
390 //=============================================================================
394 * Import mesh data from MED file
396 //=============================================================================
398 SMESH::DriverMED_ReadStatus
399 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
401 Unexpect aCatch(SALOME_SalomeException);
404 status = _impl->MEDToMesh( theFileName, theMeshName );
406 catch( SALOME_Exception& S_ex ) {
407 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
410 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
413 CreateGroupServants();
415 int major, minor, release;
416 major = minor = release = 0;
417 MED::GetMEDVersion(theFileName, major, minor, release);
418 _medFileInfo = new SMESH::MedFileInfo();
419 _medFileInfo->fileName = theFileName;
420 _medFileInfo->fileSize = 0;
421 _medFileInfo->major = major;
422 _medFileInfo->minor = minor;
423 _medFileInfo->release = release;
424 _medFileInfo->fileSize = SMESH_File( theFileName ).size();
426 return ConvertDriverMEDReadStatus(status);
429 //================================================================================
431 * \brief Import mesh data from the CGNS file
433 //================================================================================
435 SMESH::DriverMED_ReadStatus SMESH_Mesh_i::ImportCGNSFile( const char* theFileName,
436 const int theMeshIndex,
437 std::string& theMeshName )
439 Unexpect aCatch(SALOME_SalomeException);
442 status = _impl->CGNSToMesh( theFileName, theMeshIndex, theMeshName );
444 catch( SALOME_Exception& S_ex ) {
445 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
448 THROW_SALOME_CORBA_EXCEPTION("ImportCGNSFile(): unknown exception", SALOME::BAD_PARAM);
451 CreateGroupServants();
453 _medFileInfo = new SMESH::MedFileInfo();
454 _medFileInfo->fileName = theFileName;
455 _medFileInfo->major = 0;
456 _medFileInfo->minor = 0;
457 _medFileInfo->release = 0;
458 _medFileInfo->fileSize = SMESH_File( theFileName ).size();
460 return ConvertDriverMEDReadStatus(status);
463 //================================================================================
465 * \brief Return string representation of a MED file version comprising nbDigits
467 //================================================================================
469 char* SMESH_Mesh_i::GetVersionString(CORBA::Long minor, CORBA::Short nbDigits)
471 string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(minor, nbDigits);
472 return CORBA::string_dup( ver.c_str() );
475 //================================================================================
477 * Return the list of med versions compatibles for write/append,
478 * encoded in 10*major+minor (for instance, code for med 3.2.1 is 32)
480 //================================================================================
482 SMESH::long_array* SMESH_Mesh_i::GetMEDVersionsCompatibleForAppend()
484 SMESH::long_array_var aResult = new SMESH::long_array();
485 std::vector<int> mvok = MED::GetMEDVersionsAppendCompatible();
486 long nbver = mvok.size();
487 aResult->length( nbver );
488 for ( int i = 0; i < nbver; i++ )
489 aResult[i] = mvok[i];
490 return aResult._retn();
493 //=============================================================================
497 * Import mesh data from MED file
499 //=============================================================================
501 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
505 // Read mesh with name = <theMeshName> into SMESH_Mesh
506 _impl->UNVToMesh( theFileName );
508 CreateGroupServants();
510 _medFileInfo = new SMESH::MedFileInfo();
511 _medFileInfo->fileName = theFileName;
512 _medFileInfo->major = 0;
513 _medFileInfo->minor = 0;
514 _medFileInfo->release = 0;
515 _medFileInfo->fileSize = SMESH_File( theFileName ).size();
517 SMESH_CATCH( SMESH::throwCorbaException );
522 //=============================================================================
526 * Import mesh data from STL file
528 //=============================================================================
530 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
534 // Read mesh with name = <theMeshName> into SMESH_Mesh
535 std::string name = _impl->STLToMesh( theFileName );
538 SALOMEDS::SObject_wrap meshSO = _gen_i->ObjectToSObject( _this() );
539 _gen_i->SetName( meshSO, name.c_str() );
541 _medFileInfo = new SMESH::MedFileInfo();
542 _medFileInfo->fileName = theFileName;
543 _medFileInfo->major = 0;
544 _medFileInfo->minor = 0;
545 _medFileInfo->release = 0;
546 _medFileInfo->fileSize = SMESH_File( theFileName ).size();
548 SMESH_CATCH( SMESH::throwCorbaException );
553 //================================================================================
555 * \brief Function used in SMESH_CATCH by ImportGMFFile()
557 //================================================================================
561 SMESH_ComputeErrorPtr exceptionToComputeError(const char* excText)
563 return SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, excText );
567 //================================================================================
569 * \brief Import data from a GMF file and return an error description
571 //================================================================================
573 SMESH::ComputeError* SMESH_Mesh_i::ImportGMFFile( const char* theFileName,
574 bool theMakeRequiredGroups )
576 SMESH_ComputeErrorPtr error;
579 #define SMESH_CAUGHT error =
582 error = _impl->GMFToMesh( theFileName, theMakeRequiredGroups );
584 _medFileInfo = new SMESH::MedFileInfo();
585 _medFileInfo->fileName = theFileName;
586 _medFileInfo->major = 0;
587 _medFileInfo->minor = 0;
588 _medFileInfo->release = 0;
589 _medFileInfo->fileSize = SMESH_File( theFileName ).size();
591 SMESH_CATCH( exceptionToComputeError );
595 CreateGroupServants();
597 return ConvertComputeError( error );
600 //=============================================================================
602 * \brief Convert SMESH_Hypothesis::Hypothesis_Status into SMESH::Hypothesis_Status
604 //=============================================================================
606 #define RETURNCASE(hyp_stat) case SMESH_Hypothesis::hyp_stat: return SMESH::hyp_stat;
608 SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
609 (SMESH_Hypothesis::Hypothesis_Status theStatus)
612 RETURNCASE( HYP_OK );
613 RETURNCASE( HYP_MISSING );
614 RETURNCASE( HYP_CONCURRENT );
615 RETURNCASE( HYP_BAD_PARAMETER );
616 RETURNCASE( HYP_HIDDEN_ALGO );
617 RETURNCASE( HYP_HIDING_ALGO );
618 RETURNCASE( HYP_UNKNOWN_FATAL );
619 RETURNCASE( HYP_INCOMPATIBLE );
620 RETURNCASE( HYP_NOTCONFORM );
621 RETURNCASE( HYP_ALREADY_EXIST );
622 RETURNCASE( HYP_BAD_DIM );
623 RETURNCASE( HYP_BAD_SUBSHAPE );
624 RETURNCASE( HYP_BAD_GEOMETRY );
625 RETURNCASE( HYP_NEED_SHAPE );
626 RETURNCASE( HYP_INCOMPAT_HYPS );
629 return SMESH::HYP_UNKNOWN_FATAL;
632 //=============================================================================
636 * Call internal addHypothesis() and then add a reference to <anHyp> under
637 * the SObject actually having a reference to <aSubShape>.
638 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
640 //=============================================================================
642 SMESH::Hypothesis_Status
643 SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShape,
644 SMESH::SMESH_Hypothesis_ptr anHyp,
645 CORBA::String_out anErrorText)
647 Unexpect aCatch(SALOME_SalomeException);
649 const smIdType prevNbMeshEnt = NbNodes() + NbElements();
652 _preMeshInfo->ForgetOrLoad();
655 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShape, anHyp, &error );
656 anErrorText = error.c_str();
658 SMESH::SMESH_Mesh_var mesh( _this() );
659 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
661 _gen_i->AddHypothesisToShape( mesh, aSubShape, anHyp );
663 //int newNbMeshEnt = _impl->NbNodes() + _impl->GetMeshDS()->NbElements();
664 if ( prevNbMeshEnt > 0 /*newNbMeshEnt != prevNbMeshEnt*/ )
665 _gen_i->UpdateIcons( mesh );
667 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
669 // Update Python script
670 TPythonDump() << "status = " << mesh << ".AddHypothesis( "
671 << aSubShape << ", " << anHyp << " )";
673 return ConvertHypothesisStatus(status);
676 //================================================================================
678 * \brief Create a sub-mesh and add a hypothesis to it
680 //================================================================================
682 SMESH_Hypothesis::Hypothesis_Status
683 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShape,
684 SMESH::SMESH_Hypothesis_ptr anHyp,
685 std::string* anErrorText)
687 if(MYDEBUG) MESSAGE("addHypothesis");
689 if (CORBA::is_nil( aSubShape ) && HasShapeToMesh())
690 THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference",SALOME::BAD_PARAM);
692 if (CORBA::is_nil( anHyp ))
693 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",SALOME::BAD_PARAM);
695 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
698 TopoDS_Shape myLocSubShape;
699 //use PseudoShape in case if mesh has no shape
701 myLocSubShape = _gen_i->GeomObjectToShape( aSubShape);
703 myLocSubShape = _impl->GetShapeToMesh();
705 const int hypId = anHyp->GetId();
707 status = _impl->AddHypothesis( myLocSubShape, hypId, &error );
708 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
710 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( anHyp );
712 // assure there is a corresponding submesh
713 if ( !_impl->IsMainShape( myLocSubShape )) {
714 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
715 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
716 SMESH::SMESH_subMesh_var( createSubMesh( aSubShape ));
719 else if ( anErrorText )
721 *anErrorText = error;
724 catch(SALOME_Exception & S_ex)
726 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
731 //================================================================================
733 * \brief Un-assign a hypothesis from a sub-mesh dedicate to the given sub-shape
735 //================================================================================
737 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShape,
738 SMESH::SMESH_Hypothesis_ptr anHyp)
740 Unexpect aCatch(SALOME_SalomeException);
742 _preMeshInfo->ForgetOrLoad();
744 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShape, anHyp );
745 SMESH::SMESH_Mesh_var mesh = _this();
747 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
749 _gen_i->RemoveHypothesisFromShape( mesh, aSubShape, anHyp );
750 _gen_i->UpdateIcons( mesh );
752 // Update Python script
753 if(_impl->HasShapeToMesh())
754 TPythonDump() << "status = " << mesh << ".RemoveHypothesis( "
755 << aSubShape << ", " << anHyp << " )";
757 TPythonDump() << "status = " << mesh << ".RemoveHypothesis( "
760 return ConvertHypothesisStatus(status);
763 //=============================================================================
765 * \brief Un-assign a hypothesis from a sub-mesh dedicate to the given sub-shape
767 //=============================================================================
769 SMESH_Hypothesis::Hypothesis_Status
770 SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShape,
771 SMESH::SMESH_Hypothesis_ptr anHyp)
773 if(MYDEBUG) MESSAGE("removeHypothesis()");
775 if (CORBA::is_nil( aSubShape ) && HasShapeToMesh())
776 THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference", SALOME::BAD_PARAM);
778 if (CORBA::is_nil( anHyp ))
779 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference", SALOME::BAD_PARAM);
782 _preMeshInfo->ForgetOrLoad();
784 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
787 TopoDS_Shape myLocSubShape;
788 //use PseudoShape in case if mesh has no shape
789 if( _impl->HasShapeToMesh() )
790 myLocSubShape = _gen_i->GeomObjectToShape( aSubShape );
792 myLocSubShape = _impl->GetShapeToMesh();
794 const int hypId = anHyp->GetId();
795 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
796 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
798 // _mapHypo.erase( hypId ); EAP: hyp can be used on many sub-shapes
802 catch(SALOME_Exception & S_ex)
804 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
809 //================================================================================
811 * \brief Return hypotheses assigned to a given sub-shape
813 //================================================================================
815 SMESH::ListOfHypothesis *
816 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShape)
818 Unexpect aCatch(SALOME_SalomeException);
819 if (MYDEBUG) MESSAGE("GetHypothesisList");
820 if (_impl->HasShapeToMesh() && CORBA::is_nil(aSubShape))
821 THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference", SALOME::BAD_PARAM);
823 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
826 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShape);
827 if ( myLocSubShape.IsNull() && !_impl->HasShapeToMesh() )
828 myLocSubShape = _impl->GetShapeToMesh();
829 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
830 int i = 0, n = aLocalList.size();
833 list<const SMESHDS_Hypothesis*>::const_iterator aHyp = aLocalList.begin();
834 std::map<int, SMESH::SMESH_Hypothesis_ptr>::iterator id_hypptr;
835 for ( ; i < n && aHyp != aLocalList.end(); aHyp++ )
837 id_hypptr = _mapHypo.find( (*aHyp)->GetID() );
838 if ( id_hypptr != _mapHypo.end() )
839 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( id_hypptr->second );
843 catch(SALOME_Exception & S_ex) {
844 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
847 return aList._retn();
850 //================================================================================
852 * \brief Return sub-meshes
854 //================================================================================
856 SMESH::submesh_array* SMESH_Mesh_i::GetSubMeshes()
858 Unexpect aCatch(SALOME_SalomeException);
859 if (MYDEBUG) MESSAGE("GetSubMeshes");
861 SMESH::submesh_array_var aList = new SMESH::submesh_array();
864 TPythonDump aPythonDump;
865 if ( !_mapSubMeshIor.empty() )
869 aList->length( _mapSubMeshIor.size() );
871 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.begin();
872 for ( ; it != _mapSubMeshIor.end(); it++ ) {
873 if ( CORBA::is_nil( it->second )) continue;
874 aList[i++] = SMESH::SMESH_subMesh::_duplicate( it->second );
876 if (i > 1) aPythonDump << ", ";
877 aPythonDump << it->second;
881 catch(SALOME_Exception & S_ex) {
882 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
885 // Update Python script
886 if ( !_mapSubMeshIor.empty() )
887 aPythonDump << " ] = " << SMESH::SMESH_Mesh_var( _this() ) << ".GetSubMeshes()";
889 return aList._retn();
892 //================================================================================
894 * \brief Create and return a sub-mesh on the given sub-shape
896 //================================================================================
898 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShape,
899 const char* theName )
901 Unexpect aCatch(SALOME_SalomeException);
902 if (CORBA::is_nil(aSubShape))
903 THROW_SALOME_CORBA_EXCEPTION("bad Sub-shape reference", SALOME::BAD_PARAM);
905 SMESH::SMESH_subMesh_var subMesh;
906 SMESH::SMESH_Mesh_var aMesh = _this();
908 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShape);
910 //Get or Create the SMESH_subMesh object implementation
912 TopoDS_Iterator it( myLocSubShape );
913 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
914 bool isValidSub = ( subMeshId || _impl->GetMeshDS()->IsGroupOfSubShapes( myLocSubShape ));
915 if ( isValidSub && myLocSubShape.ShapeType() == TopAbs_COMPOUND )
916 isValidSub = !it.Value().IsSame( _impl->GetShapeToMesh() );
920 THROW_SALOME_CORBA_EXCEPTION("Not a sub-shape of the main shape", SALOME::BAD_PARAM);
922 subMesh = getSubMesh( subMeshId );
924 // create a new subMesh object servant if there is none for the shape
925 if ( subMesh->_is_nil() )
926 subMesh = createSubMesh( aSubShape );
927 if ( _gen_i->CanPublishInStudy( subMesh ))
929 SALOMEDS::SObject_wrap aSO =
930 _gen_i->PublishSubMesh( aMesh, subMesh, aSubShape, theName );
931 if ( !aSO->_is_nil()) {
932 // Update Python script
933 TPythonDump() << aSO << " = " << aMesh << ".GetSubMesh( "
934 << aSubShape << ", '" << theName << "' )";
938 catch(SALOME_Exception & S_ex) {
939 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
941 return subMesh._retn();
944 //================================================================================
946 * \brief Remove a sub-mesh
948 //================================================================================
950 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
954 if ( theSubMesh->_is_nil() )
957 GEOM::GEOM_Object_var aSubShape;
958 // Remove submesh's SObject
959 SALOMEDS::SObject_wrap anSO = _gen_i->ObjectToSObject( theSubMesh );
960 if ( !anSO->_is_nil() ) {
961 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
962 SALOMEDS::SObject_wrap anObj, aRef;
963 if ( anSO->FindSubObject( aTag, anObj.inout() ) &&
964 anObj->ReferencedObject( aRef.inout() ))
966 CORBA::Object_var obj = aRef->GetObject();
967 aSubShape = GEOM::GEOM_Object::_narrow( obj );
969 // if ( aSubShape->_is_nil() ) // not published shape (IPAL13617)
970 // aSubShape = theSubMesh->GetSubShape();
972 SALOMEDS::StudyBuilder_var builder = _gen_i->getStudyServant()->NewBuilder();
973 builder->RemoveObjectWithChildren( anSO );
975 // Update Python script
976 TPythonDump() << SMESH::SMESH_Mesh_var( _this() ) << ".RemoveSubMesh( " << anSO << " )";
979 if ( removeSubMesh( theSubMesh, aSubShape.in() ))
981 _preMeshInfo->ForgetOrLoad();
983 SMESH_CATCH( SMESH::throwCorbaException );
986 //================================================================================
988 * \brief Create a standalone group
990 //================================================================================
992 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
993 const char* theName )
995 Unexpect aCatch(SALOME_SalomeException);
997 _preMeshInfo->FullLoadFromFile();
999 SMESH::SMESH_Group_var aNewGroup =
1000 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
1002 if ( _gen_i->CanPublishInStudy( aNewGroup ) )
1004 SMESH::SMESH_Mesh_var mesh = _this();
1005 SALOMEDS::SObject_wrap aSO =
1006 _gen_i->PublishGroup( mesh, aNewGroup, GEOM::GEOM_Object::_nil(), theName);
1007 if ( !aSO->_is_nil())
1008 // Update Python script
1009 TPythonDump() << aSO << " = " << mesh << ".CreateGroup( "
1010 << theElemType << ", '" << theName << "' )";
1012 return aNewGroup._retn();
1015 //================================================================================
1017 * \brief Create a group based on the given geometry
1019 //================================================================================
1021 SMESH::SMESH_GroupOnGeom_ptr
1022 SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
1023 const char* theName,
1024 GEOM::GEOM_Object_ptr theGeomObj)
1026 Unexpect aCatch(SALOME_SalomeException);
1028 _preMeshInfo->FullLoadFromFile();
1030 SMESH::SMESH_GroupOnGeom_var aNewGroup;
1032 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
1033 if ( !aShape.IsNull() )
1036 SMESH::SMESH_GroupOnGeom::_narrow( createGroup( theElemType, theName, /*id=*/-1, aShape ));
1038 if ( _gen_i->CanPublishInStudy( aNewGroup ) )
1040 SMESH::SMESH_Mesh_var mesh = _this();
1041 SALOMEDS::SObject_wrap aSO =
1042 _gen_i->PublishGroup( mesh, aNewGroup, theGeomObj, theName );
1043 if ( !aSO->_is_nil())
1044 TPythonDump() << aSO << " = " << mesh << ".CreateGroupFromGEOM( "
1045 << theElemType << ", '" << theName << "', " << theGeomObj << " )";
1049 return aNewGroup._retn();
1052 //================================================================================
1054 * \brief Creates a group whose contents is defined by filter
1055 * \param theElemType - group type
1056 * \param theName - group name
1057 * \param theFilter - the filter
1058 * \retval SMESH::SMESH_GroupOnFilter_ptr - group defined by filter
1060 //================================================================================
1062 SMESH::SMESH_GroupOnFilter_ptr
1063 SMESH_Mesh_i::CreateGroupFromFilter(SMESH::ElementType theElemType,
1064 const char* theName,
1065 SMESH::Filter_ptr theFilter )
1067 Unexpect aCatch(SALOME_SalomeException);
1069 _preMeshInfo->FullLoadFromFile();
1071 if ( CORBA::is_nil( theFilter ))
1072 THROW_SALOME_CORBA_EXCEPTION("NULL filter", SALOME::BAD_PARAM);
1074 SMESH_PredicatePtr predicate = SMESH_GroupOnFilter_i::GetPredicate( theFilter );
1076 THROW_SALOME_CORBA_EXCEPTION("Invalid filter", SALOME::BAD_PARAM);
1078 SMESH::SMESH_GroupOnFilter_var aNewGroup = SMESH::SMESH_GroupOnFilter::_narrow
1079 ( createGroup( theElemType, theName, /*id=*/-1, TopoDS_Shape(), predicate ));
1082 if ( !aNewGroup->_is_nil() )
1083 aNewGroup->SetFilter( theFilter );
1085 if ( _gen_i->CanPublishInStudy( aNewGroup ) )
1087 SMESH::SMESH_Mesh_var mesh = _this();
1088 SALOMEDS::SObject_wrap aSO =
1089 _gen_i->PublishGroup( mesh, aNewGroup, GEOM::GEOM_Object::_nil(), theName );
1091 if ( !aSO->_is_nil())
1092 pd << aSO << " = " << mesh << ".CreateGroupFromFilter( "
1093 << theElemType << ", '" << theName << "', " << theFilter << " )";
1095 return aNewGroup._retn();
1098 //================================================================================
1100 * \brief Remove a group
1102 //================================================================================
1104 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
1106 if ( theGroup->_is_nil() )
1111 SMESH_GroupBase_i* aGroup = SMESH::DownCast<SMESH_GroupBase_i*>( theGroup );
1115 if ( aGroup->GetMeshServant() != this )
1116 THROW_SALOME_CORBA_EXCEPTION( "RemoveGroup(): group does not belong to this mesh",
1117 SALOME::BAD_PARAM );
1119 SALOMEDS::SObject_wrap aGroupSO = _gen_i->ObjectToSObject( theGroup );
1120 if ( !aGroupSO->_is_nil() )
1122 // Update Python script
1123 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".RemoveGroup( " << aGroupSO << " )";
1125 // Remove group's SObject
1126 SALOMEDS::StudyBuilder_var builder = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewBuilder();
1127 builder->RemoveObjectWithChildren( aGroupSO );
1129 aGroup->Modified(/*removed=*/true); // notify dependent Filter with FT_BelongToMeshGroup criterion
1131 // Remove the group from SMESH data structures
1132 removeGroup( aGroup->GetLocalID() );
1134 SMESH_CATCH( SMESH::throwCorbaException );
1137 //=============================================================================
1139 * Remove group with its contents
1141 //=============================================================================
1143 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
1147 _preMeshInfo->FullLoadFromFile();
1149 if ( theGroup->_is_nil() )
1152 SMESH_GroupBase_i* groupImpl = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup );
1153 if ( !groupImpl || groupImpl->GetMeshServant() != this )
1154 THROW_SALOME_CORBA_EXCEPTION( "RemoveGroupWithContents(): group does not belong to this mesh",
1157 vector<smIdType> nodeIds; // to remove nodes becoming free
1158 bool isNodal = ( theGroup->GetType() == SMESH::NODE );
1159 if ( !isNodal && !theGroup->IsEmpty() )
1161 SMESH::smIdType elemID = theGroup->GetID( 1 );
1162 int nbElemNodes = GetElemNbNodes( elemID );
1163 if ( nbElemNodes > 0 )
1164 nodeIds.reserve( theGroup->Size() * nbElemNodes );
1167 // Retrieve contents
1168 SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( theGroup );
1169 SMDS_ElemIteratorPtr elemIt = GetElements( idSrc, theGroup->GetType() );
1170 SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > elemBeg( elemIt ), elemEnd;
1171 std::vector< const SMDS_MeshElement* > elems( theGroup->Size() );
1172 elems.assign( elemBeg, elemEnd );
1174 TPythonDump pyDump; // Suppress dump from RemoveGroup()
1177 RemoveGroup( theGroup );
1180 for ( size_t i = 0; i < elems.size(); ++i )
1182 // if ( !_impl->GetMeshDS()->Contains( elems[i] ))
1186 for ( SMDS_ElemIteratorPtr nIt = elems[i]->nodesIterator(); nIt->more(); )
1187 nodeIds.push_back( nIt->next()->GetID() );
1189 _impl->GetMeshDS()->RemoveFreeElement( elems[i], /*sm=*/0 );
1193 _impl->GetMeshDS()->RemoveElement( elems[i] );
1197 // Remove free nodes
1198 for ( size_t i = 0 ; i < nodeIds.size(); ++i )
1199 if ( const SMDS_MeshNode* n = _impl->GetMeshDS()->FindNode( nodeIds[i] ))
1200 if ( n->NbInverseElements() == 0 )
1201 _impl->GetMeshDS()->RemoveFreeNode( n, /*sm=*/0 );
1203 _impl->GetMeshDS()->Modified();
1204 _impl->SetIsModified( true );
1206 // Update Python script (theGroup must be alive for this)
1207 pyDump << SMESH::SMESH_Mesh_var(_this())
1208 << ".RemoveGroupWithContents( " << theGroup << " )";
1210 SMESH_CATCH( SMESH::throwCorbaException );
1213 //================================================================================
1215 * \brief Get the list of groups existing in the mesh
1216 * \retval SMESH::ListOfGroups * - list of groups
1218 //================================================================================
1220 SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups()
1222 Unexpect aCatch(SALOME_SalomeException);
1223 if (MYDEBUG) MESSAGE("GetGroups");
1225 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
1228 TPythonDump aPythonDump;
1229 if ( !_mapGroups.empty() )
1231 aPythonDump << "[ ";
1233 aList->length( _mapGroups.size() );
1235 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
1236 for ( ; it != _mapGroups.end(); it++ ) {
1237 if ( CORBA::is_nil( it->second )) continue;
1238 aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
1240 if (i > 1) aPythonDump << ", ";
1241 aPythonDump << it->second;
1245 catch(SALOME_Exception & S_ex) {
1246 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1248 aPythonDump << " ] = " << SMESH::SMESH_Mesh_var(_this()) << ".GetGroups()";
1250 return aList._retn();
1253 //=============================================================================
1255 * Get number of groups existing in the mesh
1257 //=============================================================================
1259 CORBA::Long SMESH_Mesh_i::NbGroups()
1261 Unexpect aCatch(SALOME_SalomeException);
1262 return _mapGroups.size();
1265 //=============================================================================
1267 * New group including all mesh elements present in initial groups is created.
1269 //=============================================================================
1271 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1272 SMESH::SMESH_GroupBase_ptr theGroup2,
1273 const char* theName )
1275 SMESH::SMESH_Group_var aResGrp;
1279 _preMeshInfo->FullLoadFromFile();
1281 if ( theGroup1->_is_nil() || theGroup2->_is_nil() )
1282 THROW_SALOME_CORBA_EXCEPTION("UnionGroups(): NULL Group",
1284 if ( theGroup1->GetType() != theGroup2->GetType() )
1285 THROW_SALOME_CORBA_EXCEPTION("UnionGroups(): different group types",
1290 aResGrp = CreateGroup( theGroup1->GetType(), theName );
1291 if ( aResGrp->_is_nil() )
1292 return SMESH::SMESH_Group::_nil();
1294 aResGrp->AddFrom( theGroup1 );
1295 aResGrp->AddFrom( theGroup2 );
1297 // Update Python script
1298 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var(_this())
1299 << ".UnionGroups( " << theGroup1 << ", " << theGroup2 << ", '" << theName << "' )";
1301 SMESH_CATCH( SMESH::throwCorbaException );
1303 return aResGrp._retn();
1306 //=============================================================================
1308 * \brief New group including all mesh elements present in initial groups is created.
1309 * \param theGroups list of groups
1310 * \param theName name of group to be created
1311 * \return pointer to the new group
1313 //=============================================================================
1315 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionListOfGroups(const SMESH::ListOfGroups& theGroups,
1316 const char* theName )
1318 SMESH::SMESH_Group_var aResGrp;
1321 _preMeshInfo->FullLoadFromFile();
1324 return SMESH::SMESH_Group::_nil();
1329 SMESH::ElementType aType = SMESH::ALL;
1330 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1332 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1333 if ( CORBA::is_nil( aGrp ) )
1335 if ( aType == SMESH::ALL )
1336 aType = aGrp->GetType();
1337 else if ( aType != aGrp->GetType() )
1338 THROW_SALOME_CORBA_EXCEPTION("UnionListOfGroups(): different group types",
1341 if ( aType == SMESH::ALL )
1342 return SMESH::SMESH_Group::_nil();
1347 aResGrp = CreateGroup( aType, theName );
1348 if ( aResGrp->_is_nil() )
1349 return SMESH::SMESH_Group::_nil();
1351 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var(_this()) << ".UnionListOfGroups([ ";
1352 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1354 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1355 if ( !CORBA::is_nil( aGrp ) )
1357 aResGrp->AddFrom( aGrp );
1358 if ( g > 0 ) pyDump << ", ";
1362 pyDump << " ], '" << theName << "' )";
1364 SMESH_CATCH( SMESH::throwCorbaException );
1366 return aResGrp._retn();
1369 //=============================================================================
1371 * New group is created. All mesh elements that are
1372 * present in both initial groups are added to the new one.
1374 //=============================================================================
1376 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1377 SMESH::SMESH_GroupBase_ptr theGroup2,
1378 const char* theName )
1380 SMESH::SMESH_Group_var aResGrp;
1385 _preMeshInfo->FullLoadFromFile();
1387 if ( theGroup1->_is_nil() || theGroup2->_is_nil() )
1388 THROW_SALOME_CORBA_EXCEPTION("IntersectGroups(): NULL Group",
1390 if ( theGroup1->GetType() != theGroup2->GetType() )
1391 THROW_SALOME_CORBA_EXCEPTION("IntersectGroups(): different group types",
1395 // Create Intersection
1396 aResGrp = CreateGroup( theGroup1->GetType(), theName );
1397 if ( aResGrp->_is_nil() )
1398 return aResGrp._retn();
1400 SMESHDS_GroupBase* groupDS1 = 0;
1401 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup1 ))
1402 groupDS1 = grp_i->GetGroupDS();
1404 SMESHDS_GroupBase* groupDS2 = 0;
1405 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup2 ))
1406 groupDS2 = grp_i->GetGroupDS();
1408 SMESHDS_Group* resGroupDS = 0;
1409 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aResGrp ))
1410 resGroupDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() );
1412 if ( groupDS1 && groupDS2 && resGroupDS && !groupDS2->IsEmpty() )
1414 SMDS_ElemIteratorPtr elemIt1 = groupDS1->GetElements();
1415 while ( elemIt1->more() )
1417 const SMDS_MeshElement* e = elemIt1->next();
1418 if ( groupDS2->Contains( e ))
1419 resGroupDS->SMDSGroup().Add( e );
1422 // Update Python script
1423 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var(_this()) << ".IntersectGroups( "
1424 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
1426 SMESH_CATCH( SMESH::throwCorbaException );
1428 return aResGrp._retn();
1431 //=============================================================================
1433 \brief Intersect list of groups. New group is created. All mesh elements that
1434 are present in all initial groups simultaneously are added to the new one.
1435 \param theGroups list of groups
1436 \param theName name of group to be created
1437 \return pointer on the group
1439 //=============================================================================
1441 SMESH::SMESH_Group_ptr
1442 SMESH_Mesh_i::IntersectListOfGroups(const SMESH::ListOfGroups& theGroups,
1443 const char* theName )
1445 SMESH::SMESH_Group_var aResGrp;
1450 _preMeshInfo->FullLoadFromFile();
1453 return SMESH::SMESH_Group::_nil();
1455 // check types and get SMESHDS_GroupBase's
1456 SMESH::ElementType aType = SMESH::ALL;
1457 vector< SMESHDS_GroupBase* > groupVec;
1458 for ( int g = 0, n = theGroups.length(); g < n; g++ )
1460 SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
1461 if ( CORBA::is_nil( aGrp ) )
1463 if ( aType == SMESH::ALL )
1464 aType = aGrp->GetType();
1465 else if ( aType != aGrp->GetType() )
1466 THROW_SALOME_CORBA_EXCEPTION("IntersectListOfGroups(): different group types",
1469 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aGrp ))
1470 if ( SMESHDS_GroupBase* grpDS = grp_i->GetGroupDS() )
1472 if ( grpDS->IsEmpty() )
1477 groupVec.push_back( grpDS );
1480 if ( aType == SMESH::ALL ) // all groups are nil
1481 return SMESH::SMESH_Group::_nil();
1486 aResGrp = CreateGroup( aType, theName );
1488 SMESHDS_Group* resGroupDS = 0;
1489 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aResGrp ))
1490 resGroupDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() );
1491 if ( !resGroupDS || groupVec.empty() )
1492 return aResGrp._retn();
1495 size_t i, nb = groupVec.size();
1496 SMDS_ElemIteratorPtr elemIt1 = groupVec[0]->GetElements();
1497 while ( elemIt1->more() )
1499 const SMDS_MeshElement* e = elemIt1->next();
1501 for ( i = 1; ( i < nb && inAll ); ++i )
1502 inAll = groupVec[i]->Contains( e );
1505 resGroupDS->SMDSGroup().Add( e );
1508 // Update Python script
1509 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var( _this() )
1510 << ".IntersectListOfGroups( " << theGroups << ", '" << theName << "' )";
1512 SMESH_CATCH( SMESH::throwCorbaException );
1514 return aResGrp._retn();
1517 //=============================================================================
1519 * New group is created. All mesh elements that are present in
1520 * a main group but is not present in a tool group are added to the new one
1522 //=============================================================================
1524 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
1525 SMESH::SMESH_GroupBase_ptr theGroup2,
1526 const char* theName )
1528 SMESH::SMESH_Group_var aResGrp;
1533 _preMeshInfo->FullLoadFromFile();
1535 if ( theGroup1->_is_nil() || theGroup2->_is_nil() )
1536 THROW_SALOME_CORBA_EXCEPTION("CutGroups(): NULL Group",
1538 if ( theGroup1->GetType() != theGroup2->GetType() )
1539 THROW_SALOME_CORBA_EXCEPTION("CutGroups(): different group types",
1543 aResGrp = CreateGroup( theGroup1->GetType(), theName );
1544 if ( aResGrp->_is_nil() )
1545 return aResGrp._retn();
1547 SMESHDS_GroupBase* groupDS1 = 0;
1548 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup1 ))
1549 groupDS1 = grp_i->GetGroupDS();
1551 SMESHDS_GroupBase* groupDS2 = 0;
1552 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( theGroup2 ))
1553 groupDS2 = grp_i->GetGroupDS();
1555 SMESHDS_Group* resGroupDS = 0;
1556 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aResGrp ))
1557 resGroupDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() );
1559 if ( groupDS1 && groupDS2 && resGroupDS )
1561 SMDS_ElemIteratorPtr elemIt1 = groupDS1->GetElements();
1562 while ( elemIt1->more() )
1564 const SMDS_MeshElement* e = elemIt1->next();
1565 if ( !groupDS2->Contains( e ))
1566 resGroupDS->SMDSGroup().Add( e );
1569 // Update Python script
1570 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var(_this()) << ".CutGroups( "
1571 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
1573 SMESH_CATCH( SMESH::throwCorbaException );
1575 return aResGrp._retn();
1578 //=============================================================================
1580 \brief Cut lists of groups. New group is created. All mesh elements that are
1581 present in main groups but do not present in tool groups are added to the new one
1582 \param theMainGroups list of main groups
1583 \param theToolGroups list of tool groups
1584 \param theName name of group to be created
1585 \return pointer on the group
1587 //=============================================================================
1589 SMESH::SMESH_Group_ptr
1590 SMESH_Mesh_i::CutListOfGroups(const SMESH::ListOfGroups& theMainGroups,
1591 const SMESH::ListOfGroups& theToolGroups,
1592 const char* theName )
1594 SMESH::SMESH_Group_var aResGrp;
1599 _preMeshInfo->FullLoadFromFile();
1602 return SMESH::SMESH_Group::_nil();
1604 // check types and get SMESHDS_GroupBase's
1605 SMESH::ElementType aType = SMESH::ALL;
1606 vector< SMESHDS_GroupBase* > toolGroupVec;
1607 vector< SMDS_ElemIteratorPtr > mainIterVec;
1609 for ( int g = 0, n = theMainGroups.length(); g < n; g++ )
1611 SMESH::SMESH_GroupBase_var aGrp = theMainGroups[ g ];
1612 if ( CORBA::is_nil( aGrp ) )
1614 if ( aType == SMESH::ALL )
1615 aType = aGrp->GetType();
1616 else if ( aType != aGrp->GetType() )
1617 THROW_SALOME_CORBA_EXCEPTION("CutListOfGroups(): different group types",
1619 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aGrp ))
1620 if ( SMESHDS_GroupBase* grpDS = grp_i->GetGroupDS() )
1621 if ( !grpDS->IsEmpty() )
1622 mainIterVec.push_back( grpDS->GetElements() );
1624 if ( aType == SMESH::ALL ) // all main groups are nil
1625 return SMESH::SMESH_Group::_nil();
1626 if ( mainIterVec.empty() ) // all main groups are empty
1627 return aResGrp._retn();
1629 for ( int g = 0, n = theToolGroups.length(); g < n; g++ )
1631 SMESH::SMESH_GroupBase_var aGrp = theToolGroups[ g ];
1632 if ( CORBA::is_nil( aGrp ) )
1634 if ( aType != aGrp->GetType() )
1635 THROW_SALOME_CORBA_EXCEPTION("CutListOfGroups(): different group types",
1637 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aGrp ))
1638 if ( SMESHDS_GroupBase* grpDS = grp_i->GetGroupDS() )
1639 toolGroupVec.push_back( grpDS );
1645 aResGrp = CreateGroup( aType, theName );
1647 SMESHDS_Group* resGroupDS = 0;
1648 if ( SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( aResGrp ))
1649 resGroupDS = dynamic_cast<SMESHDS_Group*>( grp_i->GetGroupDS() );
1651 return aResGrp._retn();
1654 size_t i, nb = toolGroupVec.size();
1655 SMDS_ElemIteratorPtr mainElemIt
1656 ( new SMDS_IteratorOnIterators
1657 < const SMDS_MeshElement*, vector< SMDS_ElemIteratorPtr > >( mainIterVec ));
1658 while ( mainElemIt->more() )
1660 const SMDS_MeshElement* e = mainElemIt->next();
1662 for ( i = 0; ( i < nb && !isIn ); ++i )
1663 isIn = toolGroupVec[i]->Contains( e );
1666 resGroupDS->SMDSGroup().Add( e );
1669 // Update Python script
1670 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var( _this() )
1671 << ".CutListOfGroups( " << theMainGroups << ", "
1672 << theToolGroups << ", '" << theName << "' )";
1674 SMESH_CATCH( SMESH::throwCorbaException );
1676 return aResGrp._retn();
1679 namespace // functions making checks according to SMESH::NB_COMMON_NODES_ENUM
1681 bool isAllNodesCommon(int nbChecked, int nbCommon, int nbNodes, int /*nbCorners*/,
1682 bool & toStopChecking )
1684 toStopChecking = ( nbCommon < nbChecked );
1685 return nbCommon == nbNodes;
1687 bool isMainNodesCommon(int nbChecked, int nbCommon, int /*nbNodes*/, int nbCorners,
1688 bool & toStopChecking )
1690 toStopChecking = ( nbCommon < nbChecked || nbChecked >= nbCorners );
1691 return nbCommon == nbCorners;
1693 bool isAtLeastOneNodeCommon(int /*nbChecked*/, int nbCommon, int /*nbNodes*/, int /*nbCorners*/,
1694 bool & /*toStopChecking*/ )
1696 return nbCommon > 0;
1698 bool isMajorityOfNodesCommon(int /*nbChecked*/, int nbCommon, int nbNodes, int /*nbCorners*/,
1699 bool & /*toStopChecking*/ )
1701 return nbCommon >= (nbNodes+1) / 2;
1705 //=============================================================================
1707 * Create a group of entities basing on nodes of other groups.
1708 * \param [in] theGroups - list of either groups, sub-meshes or filters.
1709 * \param [in] anElemType - a type of elements to include to the new group.
1710 * \param [in] theName - a name of the new group.
1711 * \param [in] theNbCommonNodes - criterion of inclusion of an element to the new group.
1712 * \param [in] theUnderlyingOnly - if \c True, an element is included to the
1713 * new group provided that it is based on nodes of an element of \a aListOfGroups
1714 * \return SMESH_Group - the created group
1716 // IMP 19939, bug 22010, IMP 22635
1717 //=============================================================================
1719 SMESH::SMESH_Group_ptr
1720 SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfIDSources& theGroups,
1721 SMESH::ElementType theElemType,
1722 const char* theName,
1723 SMESH::NB_COMMON_NODES_ENUM theNbCommonNodes,
1724 CORBA::Boolean theUnderlyingOnly)
1726 SMESH::SMESH_Group_var aResGrp;
1730 _preMeshInfo->FullLoadFromFile();
1732 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
1734 if ( !theName || !aMeshDS )
1735 return SMESH::SMESH_Group::_nil();
1737 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)theElemType;
1739 bool (*isToInclude)(int nbChecked, int nbCommon, int nbNodes, int nbCorners, bool & toStop);
1740 SMESH_Comment nbCoNoStr( "SMESH.");
1741 switch ( theNbCommonNodes ) {
1742 case SMESH::ALL_NODES : isToInclude = isAllNodesCommon; nbCoNoStr<<"ALL_NODES" ;break;
1743 case SMESH::MAIN : isToInclude = isMainNodesCommon; nbCoNoStr<<"MAIN" ;break;
1744 case SMESH::AT_LEAST_ONE: isToInclude = isAtLeastOneNodeCommon; nbCoNoStr<<"AT_LEAST_ONE";break;
1745 case SMESH::MAJORITY : isToInclude = isMajorityOfNodesCommon; nbCoNoStr<<"MAJORITY" ;break;
1746 default: return aResGrp._retn();
1748 int nbChecked, nbCommon, nbNodes, nbCorners;
1754 aResGrp = CreateGroup( theElemType, theName );
1755 if ( aResGrp->_is_nil() )
1756 return SMESH::SMESH_Group::_nil();
1758 SMESHDS_GroupBase* groupBaseDS =
1759 SMESH::DownCast<SMESH_GroupBase_i*>( aResGrp )->GetGroupDS();
1760 SMDS_MeshGroup& resGroupCore = static_cast< SMESHDS_Group* >( groupBaseDS )->SMDSGroup();
1762 vector<bool> isNodeInGroups;
1764 for ( int g = 0, n = theGroups.length(); g < n; g++ ) // loop on theGroups
1766 SMESH::SMESH_IDSource_var aGrp = theGroups[ g ];
1767 if ( CORBA::is_nil( aGrp ) )
1769 SMESH::SMESH_Mesh_var mesh = aGrp->GetMesh();
1770 if ( mesh->_is_nil() || mesh->GetId() != this->GetId() )
1773 SMDS_ElemIteratorPtr elIt = GetElements( aGrp, SMESH::ALL );
1774 if ( !elIt ) continue;
1776 if ( theElemType == SMESH::NODE ) // get all nodes of elements
1778 while ( elIt->more() ) {
1779 const SMDS_MeshElement* el = elIt->next();
1780 SMDS_ElemIteratorPtr nIt = el->nodesIterator();
1781 while ( nIt->more() )
1782 resGroupCore.Add( nIt->next() );
1785 // get elements of theElemType based on nodes of every element of group
1786 else if ( theUnderlyingOnly )
1788 while ( elIt->more() )
1790 const SMDS_MeshElement* el = elIt->next(); // an element of ref group
1791 TIDSortedElemSet elNodes( el->begin_nodes(), el->end_nodes() );
1792 TIDSortedElemSet checkedElems;
1793 SMDS_NodeIteratorPtr nIt = el->nodeIterator();
1794 while ( nIt->more() )
1796 const SMDS_MeshNode* n = nIt->next();
1797 SMDS_ElemIteratorPtr elOfTypeIt = n->GetInverseElementIterator( anElemType );
1798 // check nodes of elements of theElemType around el
1799 while ( elOfTypeIt->more() )
1801 const SMDS_MeshElement* elOfType = elOfTypeIt->next();
1802 if ( !checkedElems.insert( elOfType ).second ) continue;
1803 nbNodes = elOfType->NbNodes();
1804 nbCorners = elOfType->NbCornerNodes();
1806 bool toStopChecking = false;
1807 SMDS_ElemIteratorPtr nIt2 = elOfType->nodesIterator();
1808 for ( nbChecked = 1; nIt2->more() && !toStopChecking; ++nbChecked )
1809 if ( elNodes.count( nIt2->next() ) &&
1810 isToInclude( nbChecked, ++nbCommon, nbNodes, nbCorners, toStopChecking ))
1812 resGroupCore.Add( elOfType );
1819 // get all nodes of elements of groups
1822 while ( elIt->more() )
1824 const SMDS_MeshElement* el = elIt->next(); // an element of group
1825 SMDS_NodeIteratorPtr nIt = el->nodeIterator();
1826 while ( nIt->more() )
1828 const SMDS_MeshNode* n = nIt->next();
1829 if ( n->GetID() >= (int) isNodeInGroups.size() )
1830 isNodeInGroups.resize( n->GetID() + 1, false );
1831 isNodeInGroups[ n->GetID() ] = true;
1837 // Get elements of theElemType based on a certain number of nodes of elements of groups
1838 if ( !theUnderlyingOnly && !isNodeInGroups.empty() )
1840 const SMDS_MeshNode* n;
1841 vector<bool> isElemChecked( aMeshDS->MaxElementID() + 1 );
1842 const int isNodeInGroupsSize = isNodeInGroups.size();
1843 for ( int iN = 0; iN < isNodeInGroupsSize; ++iN )
1845 if ( !isNodeInGroups[ iN ] ||
1846 !( n = aMeshDS->FindNode( iN )))
1849 // check nodes of elements of theElemType around n
1850 SMDS_ElemIteratorPtr elOfTypeIt = n->GetInverseElementIterator( anElemType );
1851 while ( elOfTypeIt->more() )
1853 const SMDS_MeshElement* elOfType = elOfTypeIt->next();
1854 vector<bool>::reference isChecked = isElemChecked[ elOfType->GetID() ];
1859 nbNodes = elOfType->NbNodes();
1860 nbCorners = elOfType->NbCornerNodes();
1862 bool toStopChecking = false;
1863 SMDS_ElemIteratorPtr nIt = elOfType->nodesIterator();
1864 for ( nbChecked = 1; nIt->more() && !toStopChecking; ++nbChecked )
1866 const smIdType nID = nIt->next()->GetID();
1867 if ( nID < isNodeInGroupsSize && isNodeInGroups[ nID ] &&
1868 isToInclude( nbChecked, ++nbCommon, nbNodes, nbCorners, toStopChecking ))
1870 resGroupCore.Add( elOfType );
1878 // Update Python script
1879 pyDump << aResGrp << " = " << SMESH::SMESH_Mesh_var( _this())
1880 << ".CreateDimGroup( "
1881 << theGroups << ", " << theElemType << ", '" << theName << "', "
1882 << nbCoNoStr << ", " << theUnderlyingOnly << ")";
1884 SMESH_CATCH( SMESH::throwCorbaException );
1886 return aResGrp._retn();
1889 //================================================================================
1891 * \brief Distribute all faces of the mesh between groups using sharp edges and optionally
1892 * existing 1D elements as group boundaries.
1893 * \param [in] theSharpAngle - edge is considered sharp if an angle between normals of
1894 * adjacent faces is more than \a sharpAngle in degrees.
1895 * \param [in] theCreateEdges - to create 1D elements for detected sharp edges.
1896 * \param [in] theUseExistingEdges - to use existing edges as group boundaries
1897 * \return ListOfGroups - the created groups
1899 //================================================================================
1901 SMESH::ListOfGroups*
1902 SMESH_Mesh_i::FaceGroupsSeparatedByEdges( CORBA::Double theSharpAngle,
1903 CORBA::Boolean theCreateEdges,
1904 CORBA::Boolean theUseExistingEdges )
1906 if ( theSharpAngle < 0 || theSharpAngle > 180 )
1907 THROW_SALOME_CORBA_EXCEPTION("Invalid sharp angle, it must be between 0 and 180 degrees",
1910 SMESH::ListOfGroups_var resultGroups = new SMESH::ListOfGroups;
1916 _preMeshInfo->FullLoadFromFile();
1918 SMESHDS_Mesh* meshDS = _impl->GetMeshDS();
1920 std::vector< SMESH_MeshAlgos::Edge > edges =
1921 SMESH_MeshAlgos::FindSharpEdges( meshDS, theSharpAngle, theUseExistingEdges );
1923 if ( theCreateEdges )
1925 std::vector<const SMDS_MeshNode *> nodes(2);
1926 for ( size_t i = 0; i < edges.size(); ++i )
1928 nodes[0] = edges[i]._node1;
1929 nodes[1] = edges[i]._node2;
1930 if ( meshDS->FindElement( nodes, SMDSAbs_Edge ))
1932 if ( edges[i]._medium )
1933 meshDS->AddEdge( edges[i]._node1, edges[i]._node2, edges[i]._medium );
1935 meshDS->AddEdge( edges[i]._node1, edges[i]._node2 );
1939 std::vector< std::vector< const SMDS_MeshElement* > > faceGroups =
1940 SMESH_MeshAlgos::SeparateFacesByEdges( meshDS, edges );
1942 SMESH::SMESH_MeshEditor_var editor = GetMeshEditor(); // create _editor
1944 resultGroups->length( faceGroups.size() );
1945 for ( size_t iG = 0; iG < faceGroups.size(); ++iG )
1947 SMESH::SMESH_Group_var group = CreateGroup( SMESH::FACE,
1948 _editor->GenerateGroupName("Group").c_str());
1949 resultGroups[iG] = SMESH::SMESH_Group::_duplicate( group );
1951 SMESHDS_GroupBase* groupBaseDS =
1952 SMESH::DownCast<SMESH_GroupBase_i*>( group )->GetGroupDS();
1953 SMDS_MeshGroup& groupCore = static_cast< SMESHDS_Group* >( groupBaseDS )->SMDSGroup();
1955 std::vector< const SMDS_MeshElement* >& faces = faceGroups[ iG ];
1956 for ( size_t i = 0; i < faces.size(); ++i )
1957 groupCore.Add( faces[i] );
1960 pyDump << resultGroups << " = " << SMESH::SMESH_Mesh_var(_this())
1961 << ".FaceGroupsSeparatedByEdges( "
1962 << TVar( theSharpAngle ) << ", "
1963 << theCreateEdges << ", "
1964 << theUseExistingEdges << " )";
1966 SMESH_CATCH( SMESH::throwCorbaException );
1967 return resultGroups._retn();
1971 //================================================================================
1973 * \brief Remember GEOM group data
1975 //================================================================================
1977 void SMESH_Mesh_i::addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
1978 CORBA::Object_ptr theSmeshObj)
1980 if ( CORBA::is_nil( theGeomObj ) || theGeomObj->GetType() != GEOM_GROUP )
1983 SALOMEDS::SObject_wrap groupSO = _gen_i->ObjectToSObject( theGeomObj );
1984 if ( groupSO->_is_nil() )
1987 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine( theGeomObj );
1988 GEOM::GEOM_IGroupOperations_wrap groupOp = geomGen->GetIGroupOperations();
1989 GEOM::ListOfLong_var ids = groupOp->GetObjects( theGeomObj );
1992 _geomGroupData.push_back( TGeomGroupData() );
1993 TGeomGroupData & groupData = _geomGroupData.back();
1995 CORBA::String_var entry = groupSO->GetID();
1996 groupData._groupEntry = entry.in();
1998 for ( CORBA::ULong i = 0; i < ids->length(); ++i )
1999 groupData._indices.insert( ids[i] );
2001 groupData._smeshObject = CORBA::Object::_duplicate( theSmeshObj );
2002 // shape index in SMESHDS
2003 // TopoDS_Shape shape = _gen_i->GeomObjectToShape( theGeomObj );
2004 // groupData._dsID = shape.IsNull() ? 0 : _impl->GetSubMesh( shape )->GetId();
2007 //================================================================================
2009 * Remove GEOM group data relating to removed smesh object
2011 //================================================================================
2013 void SMESH_Mesh_i::removeGeomGroupData(CORBA::Object_ptr theSmeshObj)
2015 list<TGeomGroupData>::iterator
2016 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
2017 for ( ; data != dataEnd; ++data ) {
2018 if ( theSmeshObj->_is_equivalent( data->_smeshObject )) {
2019 _geomGroupData.erase( data );
2025 //================================================================================
2027 * \brief Replace a shape in the mesh upon Break Link
2029 //================================================================================
2031 void SMESH_Mesh_i::ReplaceShape(GEOM::GEOM_Object_ptr theNewGeom)
2033 // check if geometry changed
2034 bool geomChanged = true;
2035 GEOM::GEOM_Object_var oldGeom = GetShapeToMesh();
2036 if ( !theNewGeom->_is_nil() && !oldGeom->_is_nil() )
2037 geomChanged = ( oldGeom->GetTick() != theNewGeom->GetTick() );
2039 TopoDS_Shape S = _impl->GetShapeToMesh();
2040 GEOM_Client* geomClient = _gen_i->GetShapeReader();
2041 TCollection_AsciiString aIOR;
2042 if ( geomClient->Find( S, aIOR ))
2043 geomClient->RemoveShapeFromBuffer( aIOR );
2045 // clear buffer also for sub-groups
2046 SMESHDS_Mesh* meshDS = _impl->GetMeshDS();
2047 const std::set<SMESHDS_GroupBase*>& groups = meshDS->GetGroups();
2048 std::set<SMESHDS_GroupBase*>::const_iterator g = groups.begin();
2049 for (; g != groups.end(); ++g)
2050 if (const SMESHDS_GroupOnGeom* group = dynamic_cast<SMESHDS_GroupOnGeom*>(*g))
2052 const TopoDS_Shape& s = group->GetShape();
2053 if ( geomClient->Find( s, aIOR ))
2054 geomClient->RemoveShapeFromBuffer( aIOR );
2057 // clear buffer also for sub-meshes
2058 std::map<int, SMESH_subMesh_i*>::const_iterator aSubMeshIter = _mapSubMesh_i.cbegin();
2059 for(; aSubMeshIter != _mapSubMesh_i.cend(); aSubMeshIter++) {
2060 int aShapeID = aSubMeshIter->first;
2061 const TopoDS_Shape& aSubShape = meshDS->IndexToShape(aShapeID);
2062 TCollection_AsciiString aShapeIOR;
2063 if ( geomClient->Find( aSubShape, aShapeIOR ))
2064 geomClient->RemoveShapeFromBuffer( aShapeIOR );
2068 int shapeID; smIdType fromID, toID; // indices of elements of a sub-mesh
2070 std::vector< TRange > elemRanges, nodeRanges; // elements of sub-meshes
2071 std::vector< SMDS_PositionPtr > positions; // node positions
2074 // store positions of elements on geometry
2076 if ( meshDS->MaxNodeID() > meshDS->NbNodes() ||
2077 meshDS->MaxElementID() > meshDS->NbElements() )
2080 meshDS->CompactMesh();
2082 positions.resize( meshDS->NbNodes() + 1 );
2083 for ( SMDS_NodeIteratorPtr nodeIt = meshDS->nodesIterator(); nodeIt->more(); )
2085 const SMDS_MeshNode* n = nodeIt->next();
2086 positions[ n->GetID() ] = n->GetPosition();
2089 // remove elements from sub-meshes to avoid their removal at hypotheses addition
2090 for ( int isNode = 0; isNode < 2; ++isNode )
2092 std::vector< TRange > & ranges = isNode ? nodeRanges : elemRanges;
2093 ranges.reserve( meshDS->MaxShapeIndex() + 10 );
2094 ranges.push_back( TRange{ 0,0,0 });
2095 SMDS_ElemIteratorPtr elemIt = meshDS->elementsIterator( isNode ? SMDSAbs_Node : SMDSAbs_All );
2096 while ( elemIt->more() )
2098 const SMDS_MeshElement* e = elemIt->next();
2099 const smIdType elemID = e->GetID();
2100 const int shapeID = e->GetShapeID();
2101 TRange & lastRange = ranges.back();
2102 if ( lastRange.shapeID != shapeID ||
2103 lastRange.toID != elemID )
2104 ranges.push_back( TRange{ shapeID, elemID, elemID + 1 });
2106 lastRange.toID = elemID + 1;
2108 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements( shapeID ))
2110 if ( isNode ) sm->RemoveNode( static_cast< const SMDS_MeshNode *>( e ));
2111 else sm->RemoveElement( e );
2118 // update the reference to theNewGeom (needed for correct execution of a dumped python script)
2119 SMESH::SMESH_Mesh_var me = _this();
2120 SALOMEDS::SObject_wrap aSO = _gen_i->ObjectToSObject( me );
2121 CORBA::String_var entry = theNewGeom->GetStudyEntry();
2122 if ( !aSO->_is_nil() )
2124 SALOMEDS::SObject_wrap aShapeRefSO;
2125 if ( aSO->FindSubObject( _gen_i->GetRefOnShapeTag(), aShapeRefSO.inout() ))
2127 SALOMEDS::SObject_wrap aShapeSO = _gen_i->getStudyServant()->FindObjectID( entry );
2128 SALOMEDS::StudyBuilder_var builder = _gen_i->getStudyServant()->NewBuilder();
2129 builder->Addreference( aShapeRefSO, aShapeSO );
2133 // re-assign global hypotheses to the new shape
2134 _mainShapeTick = geomChanged ? -1 : theNewGeom->GetTick();
2135 CheckGeomModif( true );
2139 // restore positions of elements on geometry
2140 for ( int isNode = 0; isNode < 2; ++isNode )
2142 std::vector< TRange > & ranges = isNode ? nodeRanges : elemRanges;
2143 for ( size_t i = 1; i < ranges.size(); ++i )
2145 int elemID = ranges[ i ].fromID;
2146 int toID = ranges[ i ].toID;
2147 SMESHDS_SubMesh * smDS = meshDS->NewSubMesh( ranges[ i ].shapeID );
2149 for ( ; elemID < toID; ++elemID )
2150 smDS->AddNode( meshDS->FindNode( elemID ));
2152 for ( ; elemID < toID; ++elemID )
2153 smDS->AddElement( meshDS->FindElement( elemID ));
2155 if ( SMESH_subMesh* sm = _impl->GetSubMeshContaining( ranges[ i ].shapeID ))
2156 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
2159 for ( unsigned int nodeID = 1; nodeID < positions.size(); ++nodeID )
2160 if ( positions[ nodeID ])
2161 if ( SMDS_MeshNode* n = const_cast< SMDS_MeshNode*>( meshDS->FindNode( nodeID )))
2162 n->SetPosition( positions[ nodeID ], n->GetShapeID() );
2165 _gen_i->UpdateIcons( SMESH::SMESH_Mesh_var( _this() ));
2168 TPythonDump() << "SHAPERSTUDY.breakLinkForSubElements(salome.ObjectToSObject("
2169 << me <<".GetMesh()), " << entry.in() << ")";
2171 TPythonDump() << me << ".ReplaceShape( " << entry.in() << " )";
2175 //================================================================================
2177 * \brief Return new group contents if it has been changed and update group data
2179 //================================================================================
2181 enum { ONLY_IF_CHANGED, IS_BREAK_LINK, MAIN_TRANSFORMED };
2183 TopoDS_Shape SMESH_Mesh_i::newGroupShape( TGeomGroupData & groupData, int how )
2185 TopoDS_Shape newShape;
2186 SALOMEDS::SObject_wrap groupSO;
2188 if ( how == IS_BREAK_LINK )
2190 SALOMEDS::SObject_wrap meshSO = _gen_i->ObjectToSObject( groupData._smeshObject );
2191 SALOMEDS::SObject_wrap geomRefSO;
2192 if ( !meshSO->_is_nil() &&
2193 meshSO->FindSubObject( SMESH::Tag_RefOnShape, geomRefSO.inout() ))
2195 geomRefSO->ReferencedObject( groupSO.inout() );
2201 groupSO = _gen_i->getStudyServant()->FindObjectID( groupData._groupEntry.c_str() );
2204 if ( groupSO->_is_nil() )
2207 CORBA::Object_var groupObj = _gen_i->SObjectToObject( groupSO );
2208 GEOM::GEOM_Object_var geomGroup = GEOM::GEOM_Object::_narrow( groupObj );
2209 if ( geomGroup->_is_nil() )
2212 // get indices of group items
2213 set<int> curIndices;
2214 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine( geomGroup );
2215 GEOM::GEOM_IGroupOperations_wrap groupOp = geomGen->GetIGroupOperations();
2216 GEOM::ListOfLong_var ids = groupOp->GetObjects( geomGroup );
2217 for ( CORBA::ULong i = 0; i < ids->length(); ++i )
2218 curIndices.insert( ids[i] );
2220 bool sameIndices = ( groupData._indices == curIndices );
2221 if ( how == ONLY_IF_CHANGED && sameIndices )
2222 return newShape; // group not changed
2225 CORBA::String_var entry = geomGroup->GetStudyEntry();
2226 groupData._groupEntry = entry.in();
2227 groupData._indices = curIndices;
2229 newShape = _gen_i->GeomObjectToShape( geomGroup );
2231 // check if newShape is up-to-date
2232 if ( !newShape.IsNull() && ids->length() > 0 )
2234 bool toUpdate = ! _impl->GetMeshDS()->IsGroupOfSubShapes( newShape );
2237 TopExp_Explorer exp( newShape, (TopAbs_ShapeEnum)( groupOp->GetType( geomGroup )));
2238 for ( ; exp.More() && !toUpdate; exp.Next() )
2240 int ind = _impl->GetMeshDS()->ShapeToIndex( exp.Current() );
2241 toUpdate = ( curIndices.erase( ind ) == 0 );
2243 if ( !curIndices.empty() )
2248 GEOM_Client* geomClient = _gen_i->GetShapeReader();
2249 CORBA::String_var groupIOR = geomGen->GetStringFromIOR( geomGroup );
2250 geomClient->RemoveShapeFromBuffer( groupIOR.in() );
2251 newShape = _gen_i->GeomObjectToShape( geomGroup );
2256 // geom group becomes empty - return empty compound
2257 TopoDS_Compound compound;
2258 BRep_Builder().MakeCompound(compound);
2259 newShape = compound;
2267 //-----------------------------------------------------------------------------
2269 * \brief Storage of shape and index used in CheckGeomGroupModif()
2271 struct TIndexedShape
2274 TopoDS_Shape _shape;
2275 TIndexedShape( int i, const TopoDS_Shape& s ):_index(i), _shape(s) {}
2277 //-----------------------------------------------------------------------------
2279 * \brief Data to re-create a group on geometry
2281 struct TGroupOnGeomData
2284 TopoDS_Shape _shape;
2285 SMDSAbs_ElementType _type;
2287 Quantity_Color _color;
2289 TGroupOnGeomData( const SMESHDS_GroupOnGeom* group )
2291 _oldID = group->GetID();
2292 _type = group->GetType();
2293 _name = group->GetStoreName();
2294 _color = group->GetColor();
2298 //-----------------------------------------------------------------------------
2300 * \brief Check if a filter is still valid after geometry removal
2302 bool isValidGeomFilter( SMESH::Filter_var theFilter )
2304 if ( theFilter->_is_nil() )
2306 SMESH::Filter::Criteria_var criteria;
2307 theFilter->GetCriteria( criteria.out() );
2309 for ( CORBA::ULong iCr = 0; iCr < criteria->length(); ++iCr )
2311 const char* thresholdID = criteria[ iCr ].ThresholdID.in();
2313 switch ( criteria[ iCr ].Type )
2315 case SMESH::FT_BelongToGeom:
2316 case SMESH::FT_BelongToPlane:
2317 case SMESH::FT_BelongToCylinder:
2318 case SMESH::FT_BelongToGenSurface:
2319 case SMESH::FT_LyingOnGeom:
2320 entry = thresholdID;
2322 case SMESH::FT_ConnectedElements:
2325 entry = thresholdID;
2331 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
2332 SALOMEDS::SObject_wrap so = gen->getStudyServant()->FindObjectID( entry.c_str() );
2333 if ( so->_is_nil() )
2335 CORBA::Object_var obj = so->GetObject();
2336 GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( obj );
2337 if ( gen->GeomObjectToShape( geom ).IsNull() )
2340 } // loop on criteria
2346 //=============================================================================
2348 * \brief Update data if geometry changes
2352 //=============================================================================
2354 void SMESH_Mesh_i::CheckGeomModif( bool theIsBreakLink )
2356 SMESH::SMESH_Mesh_var me = _this();
2357 GEOM::GEOM_Object_var mainGO = GetShapeToMesh();
2359 TPythonDump dumpNothing; // prevent any dump
2361 //bool removedFromClient = false;
2363 if ( mainGO->_is_nil() ) // GEOM_Client cleared or geometry removed? (IPAL52735, PAL23636)
2365 //removedFromClient = _impl->HasShapeToMesh();
2367 // try to find geometry by study reference
2368 SALOMEDS::SObject_wrap meshSO = _gen_i->ObjectToSObject( me );
2369 SALOMEDS::SObject_wrap geomRefSO, geomSO;
2370 if ( !meshSO->_is_nil() &&
2371 meshSO->FindSubObject( SMESH::Tag_RefOnShape, geomRefSO.inout() ) &&
2372 geomRefSO->ReferencedObject( geomSO.inout() ))
2374 CORBA::Object_var geomObj = _gen_i->SObjectToObject( geomSO );
2375 mainGO = GEOM::GEOM_Object::_narrow( geomObj );
2378 if ( mainGO->_is_nil() && // geometry removed ==>
2379 !geomRefSO->_is_nil() ) // remove geom dependent data: sub-meshes etc.
2381 // convert geom dependent groups into standalone ones
2382 CheckGeomGroupModif();
2384 _impl->ShapeToMesh( TopoDS_Shape() );
2386 // remove sub-meshes
2387 std::map<int, SMESH::SMESH_subMesh_ptr>::iterator i_sm = _mapSubMeshIor.begin();
2388 while ( i_sm != _mapSubMeshIor.end() )
2390 SMESH::SMESH_subMesh_ptr sm = i_sm->second;
2392 RemoveSubMesh( sm );
2394 // remove all children except groups in the study
2395 SALOMEDS::StudyBuilder_var builder = _gen_i->getStudyServant()->NewBuilder();
2396 SALOMEDS::SObject_wrap so;
2397 for ( CORBA::Long tag = SMESH::Tag_RefOnShape; tag <= SMESH::Tag_LastSubMesh; ++tag )
2398 if ( meshSO->FindSubObject( tag, so.inout() ))
2399 builder->RemoveObjectWithChildren( so );
2401 _gen_i->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED" );
2407 if ( !_impl->HasShapeToMesh() ) return;
2410 // Update after group modification
2412 const bool geomChanged = ( mainGO->GetTick() != _mainShapeTick );
2413 if ( !theIsBreakLink )
2414 if ( mainGO->GetType() == GEOM_GROUP || !geomChanged ) // is group or not modified
2416 smIdType nb = NbNodes() + NbElements();
2417 CheckGeomGroupModif();
2418 if ( nb != NbNodes() + NbElements() ) // something removed due to hypotheses change
2419 _gen_i->UpdateIcons( me );
2423 // Update after shape modification or breakLink w/o geometry change
2425 GEOM_Client* geomClient = _gen_i->GetShapeReader();
2426 if ( !geomClient ) return;
2427 GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine( mainGO );
2428 if ( geomGen->_is_nil() ) return;
2429 CORBA::String_var geomComponentType = geomGen->ComponentDataType();
2430 bool isShaper = ( strcmp( geomComponentType.in(), "SHAPERSTUDY" ) == 0 );
2432 SMESHDS_Mesh * meshDS = _impl->GetMeshDS();
2434 TopoDS_Shape newShape = _gen_i->GeomObjectToShape( mainGO );
2435 if ( meshDS->ShapeToIndex( newShape ) == 1 ) // not yet updated
2437 CORBA::String_var ior = geomGen->GetStringFromIOR( mainGO );
2438 geomClient->RemoveShapeFromBuffer( ior.in() );
2439 newShape = _gen_i->GeomObjectToShape( mainGO );
2442 // Update data taking into account that if topology doesn't change
2443 // all sub-shapes change but IDs of sub-shapes remain (except for geom groups)
2446 _preMeshInfo->ForgetAllData();
2448 if ( geomChanged || !isShaper )
2450 if ( newShape.IsNull() )
2453 _mainShapeTick = mainGO->GetTick();
2455 // store data of groups on geometry including new TopoDS_Shape's
2456 std::vector< TGroupOnGeomData > groupsData;
2457 const std::set<SMESHDS_GroupBase*>& groups = meshDS->GetGroups();
2458 groupsData.reserve( groups.size() );
2459 TopTools_DataMapOfShapeShape old2newShapeMap;
2460 std::set<SMESHDS_GroupBase*>::const_iterator g = groups.begin();
2461 for ( ; g != groups.end(); ++g )
2463 if ( const SMESHDS_GroupOnGeom* group = dynamic_cast< SMESHDS_GroupOnGeom* >( *g ))
2465 groupsData.push_back( TGroupOnGeomData( group ));
2468 SMESH::SMESH_GroupOnGeom_var gog;
2469 std::map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_grp = _mapGroups.find( group->GetID() );
2470 if ( i_grp != _mapGroups.end() )
2471 gog = SMESH::SMESH_GroupOnGeom::_narrow( i_grp->second );
2473 GEOM::GEOM_Object_var geom;
2474 if ( !gog->_is_nil() )
2476 if ( !theIsBreakLink )
2477 geom = gog->GetShape();
2479 if ( theIsBreakLink || geom->_is_nil() )
2481 SALOMEDS::SObject_wrap grpSO = _gen_i->ObjectToSObject( gog );
2482 SALOMEDS::SObject_wrap geomRefSO, geomSO;
2483 if ( !grpSO->_is_nil() &&
2484 grpSO->FindSubObject( SMESH::Tag_RefOnShape, geomRefSO.inout() ) &&
2485 geomRefSO->ReferencedObject( geomSO.inout() ))
2487 CORBA::Object_var geomObj = _gen_i->SObjectToObject( geomSO );
2488 geom = GEOM::GEOM_Object::_narrow( geomObj );
2492 if ( old2newShapeMap.IsBound( group->GetShape() ))
2494 groupsData.back()._shape = old2newShapeMap( group->GetShape() );
2496 else if ( !geom->_is_nil() )
2498 groupsData.back()._shape = _gen_i->GeomObjectToShape( geom );
2499 if ( meshDS->IsGroupOfSubShapes( groupsData.back()._shape ))
2501 CORBA::String_var ior = geomGen->GetStringFromIOR( geom );
2502 geomClient->RemoveShapeFromBuffer( ior.in() );
2503 groupsData.back()._shape = _gen_i->GeomObjectToShape( geom );
2505 old2newShapeMap.Bind( group->GetShape(), groupsData.back()._shape );
2510 // store assigned hypotheses
2511 std::vector< pair< int, THypList > > ids2Hyps;
2512 const ShapeToHypothesis & hyps = meshDS->GetHypotheses();
2513 for ( ShapeToHypothesis::Iterator s2hyps( hyps ); s2hyps.More(); s2hyps.Next() )
2515 const TopoDS_Shape& s = s2hyps.Key();
2516 const THypList& hyps = s2hyps.ChangeValue();
2517 ids2Hyps.push_back( make_pair( meshDS->ShapeToIndex( s ), hyps ));
2520 std::multimap< std::set<int>, int > ii2iMap; // group sub-ids to group id in SMESHDS
2522 // count shapes excluding compounds corresponding to geom groups
2523 int oldNbSubShapes = meshDS->MaxShapeIndex();
2524 for ( ; oldNbSubShapes > 0; --oldNbSubShapes )
2526 const TopoDS_Shape& s = meshDS->IndexToShape( oldNbSubShapes );
2527 if ( s.IsNull() || s.ShapeType() != TopAbs_COMPOUND )
2530 std::set<int> subIds;
2531 for ( TopoDS_Iterator it( s ); it.More(); it.Next() )
2532 subIds.insert( meshDS->ShapeToIndex( it.Value() ));
2533 ii2iMap.insert( std::make_pair( subIds, oldNbSubShapes ));
2536 // check if shape topology changes - save shape type per shape ID
2537 std::vector< TopAbs_ShapeEnum > shapeTypes( Max( oldNbSubShapes + 1, 1 ));
2538 for ( int shapeID = oldNbSubShapes; shapeID > 0; --shapeID )
2539 shapeTypes[ shapeID ] = meshDS->IndexToShape( shapeID ).ShapeType();
2541 // change shape to mesh
2542 _impl->ShapeToMesh( TopoDS_Shape() );
2543 _impl->ShapeToMesh( newShape );
2545 // check if shape topology changes - check new shape types
2546 bool sameTopology = ( oldNbSubShapes == meshDS->MaxShapeIndex() );
2547 for ( int shapeID = oldNbSubShapes; shapeID > 0 && sameTopology; --shapeID )
2549 const TopoDS_Shape& s = meshDS->IndexToShape( shapeID );
2550 sameTopology = ( !s.IsNull() && s.ShapeType() == shapeTypes[ shapeID ]);
2553 // re-add shapes (compounds) of geom groups
2554 typedef std::map< std::vector< int >, TGeomGroupData* > TIndices2GroupData;
2555 TIndices2GroupData ii2grData;
2556 std::vector< int > ii;
2557 std::map< int, int > old2newIDs; // group IDs
2558 std::list<TGeomGroupData>::iterator dataIt = _geomGroupData.begin();
2559 for ( ; dataIt != _geomGroupData.end(); ++dataIt )
2561 TGeomGroupData* data = &(*dataIt);
2562 ii.reserve( data->_indices.size() );
2563 ii.assign( data->_indices.begin(), data->_indices.end() );
2564 TIndices2GroupData::iterator ii2gd = ii2grData.insert( std::make_pair( ii, data )).first;
2565 if ( ii2gd->second != data )
2567 data->_groupEntry = ii2gd->second->_groupEntry;
2568 data->_indices = ii2gd->second->_indices;
2571 const int oldNbSub = data->_indices.size();
2572 const int soleOldID = oldNbSub == 1 ? *data->_indices.begin() : 0;
2574 std::multimap< std::set<int>, int >::iterator ii2i = ii2iMap.find( data->_indices );
2575 if ( ii2i != ii2iMap.end() )
2577 oldID = ii2i->second;
2578 ii2iMap.erase( ii2i );
2580 if ( !oldID && oldNbSub == 1 )
2582 if ( old2newIDs.count( oldID ))
2585 int how = ( theIsBreakLink || !sameTopology ) ? IS_BREAK_LINK : MAIN_TRANSFORMED;
2586 newShape = newGroupShape( *data, how );
2588 if ( !newShape.IsNull() )
2590 if ( oldNbSub > 1 && meshDS->ShapeToIndex( newShape ) > 0 ) // group reduced to one sub-shape
2592 TopoDS_Compound compound;
2593 BRep_Builder().MakeCompound( compound );
2594 BRep_Builder().Add( compound, newShape );
2595 newShape = compound;
2597 int newID = _impl->GetSubMesh( newShape )->GetId();
2598 if ( oldID /*&& oldID != newID*/ )
2599 old2newIDs.insert( std::make_pair( oldID, newID ));
2600 if ( oldNbSub == 1 )
2601 old2newIDs.insert( std::make_pair( soleOldID, newID ));
2605 // re-assign hypotheses
2606 for ( size_t i = 0; i < ids2Hyps.size(); ++i )
2608 int sID = ids2Hyps[i].first;
2611 std::map< int, int >::iterator o2n = old2newIDs.find( sID );
2612 if ( o2n != old2newIDs.end() )
2614 else if ( !sameTopology )
2617 const TopoDS_Shape& s = meshDS->IndexToShape( sID );
2620 const THypList& hyps = ids2Hyps[i].second;
2621 THypList::const_iterator h = hyps.begin();
2622 for ( ; h != hyps.end(); ++h )
2623 _impl->AddHypothesis( s, (*h)->GetID() );
2627 // restore groups on geometry
2628 for ( size_t i = 0; i < groupsData.size(); ++i )
2630 const TGroupOnGeomData& data = groupsData[i];
2631 if ( data._shape.IsNull() )
2634 std::map<int, SMESH::SMESH_GroupBase_ptr>::iterator i2g = _mapGroups.find( data._oldID );
2635 if ( i2g == _mapGroups.end() ) continue;
2637 SMESH_GroupBase_i* gr_i = SMESH::DownCast<SMESH_GroupBase_i*>( i2g->second );
2638 if ( !gr_i ) continue;
2640 SMESH_Group* g = _impl->AddGroup( data._type, data._name.c_str(), data._oldID, data._shape );
2642 _mapGroups.erase( i2g );
2644 g->GetGroupDS()->SetColor( data._color );
2647 if ( !sameTopology )
2649 std::map< int, int >::iterator o2n = old2newIDs.begin();
2650 for ( ; o2n != old2newIDs.end(); ++o2n )
2652 int newID = o2n->second, oldID = o2n->first;
2653 if ( newID == oldID || !_mapSubMesh.count( oldID ))
2657 _mapSubMesh [ newID ] = _impl->GetSubMeshContaining( newID );
2658 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
2659 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
2661 _mapSubMesh. erase(oldID);
2662 _mapSubMesh_i. erase(oldID);
2663 _mapSubMeshIor.erase(oldID);
2665 _mapSubMesh_i [ newID ]->changeLocalId( newID );
2669 // update _mapSubMesh
2670 std::map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
2671 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
2672 i_sm->second = _impl->GetSubMesh( meshDS->IndexToShape( i_sm->first ));
2675 if ( !sameTopology )
2677 // remove invalid study sub-objects
2678 CheckGeomGroupModif();
2681 _gen_i->UpdateIcons( me );
2683 if ( !theIsBreakLink && isShaper )
2685 SALOMEDS::SObject_wrap meshSO = _gen_i->ObjectToSObject( me );
2686 if ( !meshSO->_is_nil() )
2687 _gen_i->SetPixMap(meshSO, "ICON_SMESH_TREE_GEOM_MODIF");
2691 //=============================================================================
2693 * \brief Update objects depending on changed geom groups
2695 * NPAL16168: geometrical group edition from a submesh don't modify mesh computation
2696 * issue 0020210: Update of a smesh group after modification of the associated geom group
2698 //=============================================================================
2700 void SMESH_Mesh_i::CheckGeomGroupModif()
2702 // remove sub-meshes referring a removed sub-shapes (if main shape still exists)
2703 SALOMEDS::StudyBuilder_var builder = _gen_i->getStudyServant()->NewBuilder();
2704 GEOM::GEOM_Object_var mainGO = GetShapeToMesh();
2705 SALOMEDS::SObject_wrap meshSO = _gen_i->ObjectToSObject( SMESH::SMESH_Mesh_var( _this() ));
2706 if ( !mainGO->_is_nil() && !meshSO->_is_nil() )
2708 SALOMEDS::SObject_wrap rootSO, geomRefSO, geomSO;
2709 for ( CORBA::Long tag = SMESH::Tag_FirstSubMesh; tag <= SMESH::Tag_LastSubMesh; ++tag )
2710 if ( meshSO->FindSubObject( tag, rootSO.inout() ))
2712 int nbValid = 0, nbRemoved = 0;
2713 SALOMEDS::ChildIterator_wrap chItr = _gen_i->getStudyServant()->NewChildIterator( rootSO );
2714 for ( ; chItr->More(); chItr->Next() )
2716 SALOMEDS::SObject_wrap smSO = chItr->Value(); // sub-mesh SO
2717 if ( !smSO->_is_nil() &&
2718 smSO->FindSubObject( SMESH::Tag_RefOnShape, geomRefSO.inout() ) &&
2719 geomRefSO->ReferencedObject( geomSO.inout() )) // find geometry by reference
2721 CORBA::Object_var geomObj = _gen_i->SObjectToObject( geomSO );
2722 GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( geomObj );
2723 if ( !geom->_non_existent() )
2726 continue; // keep the sub-mesh
2729 CORBA::Object_var smObj = _gen_i->SObjectToObject( smSO );
2730 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( smObj );
2731 if ( !sm->_is_nil() && !sm->_non_existent() )
2733 GEOM::GEOM_Object_var smGeom = sm->GetSubShape();
2734 if ( smGeom->_is_nil() )
2736 RemoveSubMesh( sm );
2743 _preMeshInfo->ForgetAllData(); // unknown hypothesis modified
2744 builder->RemoveObjectWithChildren( smSO ); // sub-shape removed before loading SMESH
2748 if ( /*nbRemoved > 0 &&*/ nbValid == 0 )
2749 builder->RemoveObjectWithChildren( rootSO );
2753 // check for removed sub-shapes and convert geom dependent groups into standalone ones
2754 std::map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_gr = _mapGroups.begin();
2755 while ( i_gr != _mapGroups.end())
2757 SMESH::SMESH_GroupBase_ptr group = i_gr->second;
2759 SALOMEDS::SObject_wrap groupSO = _gen_i->ObjectToSObject( group ), refSO, geomSO;
2760 SMESH::SMESH_GroupOnGeom_var onGeom = SMESH::SMESH_GroupOnGeom::_narrow ( group );
2761 SMESH::SMESH_GroupOnFilter_var onFilt = SMESH::SMESH_GroupOnFilter::_narrow( group );
2762 bool isValidGeom = false;
2763 if ( !onGeom->_is_nil() )
2765 isValidGeom = ( ! GEOM::GEOM_Object_var( onGeom->GetShape() )->_is_nil() ); // check TopoDS
2766 if ( !isValidGeom ) // check reference
2768 isValidGeom = ( ! groupSO->_is_nil() &&
2769 groupSO->FindSubObject( SMESH::Tag_RefOnShape, refSO.inout() ) &&
2770 refSO->ReferencedObject( geomSO.inout() ) &&
2771 ! geomSO->_is_nil() &&
2772 !CORBA::is_nil( CORBA::Object_var( geomSO->GetObject() )));
2775 else if ( !onFilt->_is_nil() )
2777 isValidGeom = isValidGeomFilter( onFilt->GetFilter() );
2781 isValidGeom = ( !groupSO->_is_nil() &&
2782 !groupSO->FindSubObject( SMESH::Tag_RefOnShape, refSO.inout() ));
2786 if ( !IsLoaded() || group->IsEmpty() )
2788 RemoveGroup( group );
2790 else if ( !onGeom->_is_nil() || !onFilt->_is_nil() )
2792 SMESH::SMESH_Group_var ( ConvertToStandalone( group ));
2794 else // is it possible?
2796 builder->RemoveObjectWithChildren( refSO );
2802 if ( !_impl->HasShapeToMesh() ) return;
2804 SMESH::smIdType nbEntities = NbNodes() + NbElements();
2806 // Check if group contents changed
2808 typedef map< string, TopoDS_Shape > TEntry2Geom;
2809 TEntry2Geom newGroupContents;
2811 list<TGeomGroupData>::iterator
2812 data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
2813 for ( ; data != dataEnd; ++data )
2815 pair< TEntry2Geom::iterator, bool > it_new =
2816 newGroupContents.insert( make_pair( data->_groupEntry, TopoDS_Shape() ));
2817 bool processedGroup = !it_new.second;
2818 TopoDS_Shape& newShape = it_new.first->second;
2819 if ( !processedGroup )
2820 newShape = newGroupShape( *data, ONLY_IF_CHANGED );
2821 if ( newShape.IsNull() )
2822 continue; // no changes
2825 _preMeshInfo->ForgetOrLoad();
2827 if ( processedGroup ) { // update group indices
2828 list<TGeomGroupData>::iterator data2 = data;
2829 for ( --data2; data2->_groupEntry != data->_groupEntry; --data2) {}
2830 data->_indices = data2->_indices;
2833 // Update SMESH objects according to new GEOM group contents
2835 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( data->_smeshObject );
2836 if ( !submesh->_is_nil() ) // -------------- Sub mesh ---------------------
2838 int oldID = submesh->GetId();
2839 if ( !_mapSubMeshIor.count( oldID ))
2841 TopoDS_Shape oldShape = _mapSubMesh[oldID]->GetSubShape();
2843 // update hypotheses
2844 list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldShape);
2845 list <const SMESHDS_Hypothesis * >::iterator hypIt;
2846 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
2848 _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
2849 _impl->AddHypothesis ( newShape, (*hypIt)->GetID());
2851 // care of submeshes
2852 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newShape );
2853 int newID = newSubmesh->GetId();
2854 if ( newID != oldID ) {
2855 _mapSubMesh [ newID ] = newSubmesh;
2856 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
2857 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
2858 _mapSubMesh. erase(oldID);
2859 _mapSubMesh_i. erase(oldID);
2860 _mapSubMeshIor.erase(oldID);
2861 _mapSubMesh_i [ newID ]->changeLocalId( newID );
2866 SMESH::SMESH_GroupOnGeom_var smeshGroup =
2867 SMESH::SMESH_GroupOnGeom::_narrow( data->_smeshObject );
2868 if ( !smeshGroup->_is_nil() ) // ------------ GROUP -----------------------
2870 SMESH_GroupOnGeom_i* group_i = SMESH::DownCast<SMESH_GroupOnGeom_i*>( smeshGroup );
2872 ::SMESH_Group* group = _impl->GetGroup( group_i->GetLocalID() );
2873 SMESHDS_GroupOnGeom* ds = static_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() );
2874 ds->SetShape( newShape );
2879 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( data->_smeshObject );
2880 if ( !mesh->_is_nil() ) // -------------- MESH ----------------------------
2882 // Remove groups and submeshes basing on removed sub-shapes
2884 TopTools_MapOfShape newShapeMap;
2885 TopoDS_Iterator shapeIt( newShape );
2886 for ( ; shapeIt.More(); shapeIt.Next() )
2887 newShapeMap.Add( shapeIt.Value() );
2889 SMESHDS_Mesh* meshDS = _impl->GetMeshDS();
2890 for ( shapeIt.Initialize( meshDS->ShapeToMesh() ); shapeIt.More(); shapeIt.Next() )
2892 if ( newShapeMap.Contains( shapeIt.Value() ))
2894 TopTools_IndexedMapOfShape oldShapeMap;
2895 TopExp::MapShapes( shapeIt.Value(), oldShapeMap );
2896 for ( int i = 1; i <= oldShapeMap.Extent(); ++i )
2898 const TopoDS_Shape& oldShape = oldShapeMap(i);
2899 int oldInd = meshDS->ShapeToIndex( oldShape );
2901 map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldInd );
2902 if ( i_smIor != _mapSubMeshIor.end() ) {
2903 RemoveSubMesh( i_smIor->second ); // one submesh per shape index
2906 map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_grp = _mapGroups.begin();
2907 for ( ; i_grp != _mapGroups.end(); ++i_grp )
2909 // check if a group bases on oldInd shape
2910 SMESHDS_GroupOnGeom* grpOnGeom = 0;
2911 if ( ::SMESH_Group* g = _impl->GetGroup( i_grp->first ))
2912 grpOnGeom = dynamic_cast<SMESHDS_GroupOnGeom*>( g->GetGroupDS() );
2913 if ( grpOnGeom && oldShape.IsSame( grpOnGeom->GetShape() ))
2915 RemoveGroup( i_grp->second ); // several groups can base on same shape
2916 i_grp = _mapGroups.begin(); // _mapGroups changed - restart iteration
2921 // Reassign hypotheses and update groups after setting the new shape to mesh
2923 // collect anassigned hypotheses
2924 typedef list< pair< TIndexedShape, list<const SMESHDS_Hypothesis*> > > TShapeHypList;
2925 list <const SMESHDS_Hypothesis * >::const_iterator hypIt;
2926 TShapeHypList assignedHyps;
2927 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
2929 const TopoDS_Shape& oldShape = meshDS->IndexToShape(i);
2930 list<const SMESHDS_Hypothesis*> hyps = meshDS->GetHypothesis( oldShape );// copy
2931 if ( !hyps.empty() ) {
2932 assignedHyps.push_back( make_pair( TIndexedShape(i,oldShape), hyps ));
2933 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
2934 _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
2937 // collect shapes supporting groups
2938 typedef list < pair< TIndexedShape, SMDSAbs_ElementType > > TShapeTypeList;
2939 TShapeTypeList groupData;
2940 const set<SMESHDS_GroupBase*>& groups = meshDS->GetGroups();
2941 set<SMESHDS_GroupBase*>::const_iterator grIt = groups.begin();
2942 for ( ; grIt != groups.end(); ++grIt )
2944 if ( SMESHDS_GroupOnGeom* gog = dynamic_cast<SMESHDS_GroupOnGeom*>( *grIt ))
2946 ( make_pair( TIndexedShape( gog->GetID(),gog->GetShape()), gog->GetType()));
2948 // set new shape to mesh -> DS of sub-meshes and geom groups is deleted
2950 _impl->ShapeToMesh( TopoDS_Shape() ); // IPAL52730
2951 _impl->ShapeToMesh( newShape );
2953 // reassign hypotheses
2954 TShapeHypList::iterator indS_hyps = assignedHyps.begin();
2955 for ( ; indS_hyps != assignedHyps.end(); ++indS_hyps )
2957 TIndexedShape& geom = indS_hyps->first;
2958 list<const SMESHDS_Hypothesis*>& hyps = indS_hyps->second;
2959 int oldID = geom._index;
2960 int newID = meshDS->ShapeToIndex( geom._shape );
2961 if ( oldID == 1 ) { // main shape
2963 geom._shape = newShape;
2967 for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
2968 _impl->AddHypothesis( geom._shape, (*hypIt)->GetID());
2969 // care of sub-meshes
2970 SMESH_subMesh* newSubmesh = _impl->GetSubMesh( geom._shape );
2971 if ( newID != oldID ) {
2972 _mapSubMesh [ newID ] = newSubmesh;
2973 _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
2974 _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
2975 _mapSubMesh. erase(oldID);
2976 _mapSubMesh_i. erase(oldID);
2977 _mapSubMeshIor.erase(oldID);
2978 _mapSubMesh_i [ newID ]->changeLocalId( newID );
2982 TShapeTypeList::iterator geomType = groupData.begin();
2983 for ( ; geomType != groupData.end(); ++geomType )
2985 const TIndexedShape& geom = geomType->first;
2986 int oldID = geom._index;
2987 if ( _mapGroups.find( oldID ) == _mapGroups.end() )
2990 SALOMEDS::SObject_wrap groupSO = _gen_i->ObjectToSObject( _mapGroups[oldID] );
2991 CORBA::String_var name = groupSO->GetName();
2993 if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>(_mapGroups[oldID]))
2994 if ( SMESH_Group* group = _impl->AddGroup( geomType->second, name.in(),
2995 /*id=*/-1, geom._shape ))
2996 group_i->changeLocalId( group->GetID() );
2999 break; // everything has been updated
3002 } // loop on group data
3006 SMESH::smIdType newNbEntities = NbNodes() + NbElements();
3007 list< SALOMEDS::SObject_wrap > soToUpdateIcons;
3008 if ( newNbEntities != nbEntities )
3010 // Add all SObjects with icons to soToUpdateIcons
3011 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( _this() )); // mesh
3013 for (map<int, SMESH::SMESH_subMesh_ptr>::iterator i_sm = _mapSubMeshIor.begin();
3014 i_sm != _mapSubMeshIor.end(); ++i_sm ) // submeshes
3015 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( i_sm->second ));
3017 for ( map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_gr = _mapGroups.begin();
3018 i_gr != _mapGroups.end(); ++i_gr ) // groups
3019 soToUpdateIcons.push_back( _gen_i->ObjectToSObject( i_gr->second ));
3022 list< SALOMEDS::SObject_wrap >::iterator so = soToUpdateIcons.begin();
3023 for ( ; so != soToUpdateIcons.end(); ++so )
3024 _gen_i->SetPixMap( *so, "ICON_SMESH_TREE_MESH_WARN" );
3027 //=============================================================================
3029 * \brief Create standalone group from a group on geometry or filter
3031 //=============================================================================
3033 SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupBase_ptr theGroup )
3035 SMESH::SMESH_Group_var aGroup;
3040 _preMeshInfo->FullLoadFromFile();
3042 if ( theGroup->_is_nil() )
3043 return aGroup._retn();
3045 SMESH_GroupBase_i* aGroupToRem = SMESH::DownCast<SMESH_GroupBase_i*>( theGroup );
3047 return aGroup._retn();
3049 const bool isOnFilter = ( SMESH::DownCast< SMESH_GroupOnFilter_i* > ( theGroup ));
3051 const int anId = aGroupToRem->GetLocalID();
3052 if ( !_impl->ConvertToStandalone( anId ) )
3053 return aGroup._retn();
3054 removeGeomGroupData( theGroup );
3056 SMESH_GroupBase_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
3058 // remove old instance of group from own map
3059 { SMESH::SMESH_GroupBase_var var( _mapGroups[anId] ); } // decref CORBA object
3060 _mapGroups.erase( anId );
3062 SALOMEDS::StudyBuilder_var builder;
3063 SALOMEDS::SObject_wrap aGroupSO;
3064 SALOMEDS::Study_var aStudy = SMESH_Gen_i::GetSMESHGen()->getStudyServant();
3065 if ( !aStudy->_is_nil() ) {
3066 builder = aStudy->NewBuilder();
3067 aGroupSO = _gen_i->ObjectToSObject( theGroup );
3068 if ( !aGroupSO->_is_nil() )
3070 // remove reference to geometry
3071 SALOMEDS::ChildIterator_wrap chItr = aStudy->NewChildIterator(aGroupSO);
3072 for ( ; chItr->More(); chItr->Next() )
3074 // Remove group's child SObject
3075 SALOMEDS::SObject_wrap so = chItr->Value();
3076 builder->RemoveObject( so );
3078 // Update Python script
3079 TPythonDump() << aGroupSO << " = " << SMESH::SMESH_Mesh_var(_this())
3080 << ".ConvertToStandalone( " << aGroupSO << " )";
3082 // change icon of Group on Filter
3085 // SMESH::array_of_ElementType_var elemTypes = aGroupImpl->GetTypes();
3086 // const int isEmpty = ( elemTypes->length() == 0 );
3089 SALOMEDS::GenericAttribute_wrap anAttr =
3090 builder->FindOrCreateAttribute( aGroupSO, "AttributePixMap" );
3091 SALOMEDS::AttributePixMap_wrap pm = anAttr;
3092 pm->SetPixMap( "ICON_SMESH_TREE_GROUP" );
3098 // remember new group in own map
3099 aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
3100 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
3102 // register CORBA object for persistence
3103 _gen_i->RegisterObject( aGroup );
3105 CORBA::String_var ior = _gen_i->GetORB()->object_to_string( aGroup );
3106 builder->SetIOR( aGroupSO, ior.in() ); // == aGroup->Register();
3107 //aGroup->Register();
3108 aGroupToRem->UnRegister();
3110 SMESH_CATCH( SMESH::throwCorbaException );
3112 return aGroup._retn();
3115 //================================================================================
3117 * \brief Create a sub-mesh on a given sub-shape
3119 //================================================================================
3121 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
3123 if(MYDEBUG) MESSAGE( "createSubMesh" );
3124 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
3125 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
3128 SMESH_subMesh_i * subMeshServant;
3131 subMeshId = mySubMesh->GetId();
3132 subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
3134 else // "invalid sub-mesh"
3136 // The invalid sub-mesh is created for the case where a valid sub-shape not found
3137 // by SMESH_Gen_i::CopyMeshWithGeom(). The invalid sub-mesh has GetId() < 0.
3138 if ( _mapSubMesh.empty() )
3141 subMeshId = _mapSubMesh.begin()->first - 1;
3142 subMeshServant = new SMESH_Invalid_subMesh_i(myPOA, _gen_i, this, subMeshId, theSubShapeObject);
3145 SMESH::SMESH_subMesh_var subMesh = subMeshServant->_this();
3147 _mapSubMesh [subMeshId] = mySubMesh;
3148 _mapSubMesh_i [subMeshId] = subMeshServant;
3149 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate( subMesh );
3151 subMeshServant->Register();
3153 // register CORBA object for persistence
3154 int nextId = _gen_i->RegisterObject( subMesh );
3155 if(MYDEBUG) { MESSAGE( "Add submesh to map with id = "<< nextId); }
3156 else { (void)nextId; } // avoid "unused variable" warning
3158 // to track changes of GEOM groups
3159 if ( subMeshId > 0 )
3160 addGeomGroupData( theSubShapeObject, subMesh );
3162 return subMesh._retn();
3165 //================================================================================
3167 * \brief Return an existing sub-mesh based on a sub-shape with the given ID
3169 //================================================================================
3171 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
3173 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
3174 if ( it == _mapSubMeshIor.end() )
3175 return SMESH::SMESH_subMesh::_nil();
3177 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
3180 //================================================================================
3182 * \brief Remove a sub-mesh based on the given sub-shape
3184 //================================================================================
3186 bool SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
3187 GEOM::GEOM_Object_ptr theSubShapeObject )
3189 bool isHypChanged = false;
3190 if ( theSubMesh->_is_nil() /*|| theSubShapeObject->_is_nil()*/ )
3191 return isHypChanged;
3193 const int subMeshId = theSubMesh->GetId();
3195 if ( theSubShapeObject->_is_nil() ) // not published shape (IPAL13617)
3198 if (( _mapSubMesh.count( subMeshId )) &&
3199 ( sm = _impl->GetSubMeshContaining( subMeshId )))
3201 TopoDS_Shape S = sm->GetSubShape();
3204 list<const SMESHDS_Hypothesis*> hyps = _impl->GetHypothesisList( S );
3205 isHypChanged = !hyps.empty();
3206 if ( isHypChanged && _preMeshInfo )
3207 _preMeshInfo->ForgetOrLoad();
3208 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hyps.begin();
3209 for ( ; hyp != hyps.end(); ++hyp )
3210 _impl->RemoveHypothesis(S, (*hyp)->GetID());
3217 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
3218 isHypChanged = ( aHypList->length() > 0 );
3219 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
3220 removeHypothesis( theSubShapeObject, aHypList[i] );
3223 catch( const SALOME::SALOME_Exception& ) {
3224 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
3226 removeGeomGroupData( theSubShapeObject );
3230 std::map<int, SMESH_subMesh_i*>::iterator id_smi = _mapSubMesh_i.find( subMeshId );
3231 if ( id_smi != _mapSubMesh_i.end() )
3232 id_smi->second->UnRegister();
3234 // remove a CORBA object
3235 std::map<int, SMESH::SMESH_subMesh_ptr>::iterator id_smptr = _mapSubMeshIor.find( subMeshId );
3236 if ( id_smptr != _mapSubMeshIor.end() )
3237 SMESH::SMESH_subMesh_var( id_smptr->second );
3239 _mapSubMesh.erase(subMeshId);
3240 _mapSubMesh_i.erase(subMeshId);
3241 _mapSubMeshIor.erase(subMeshId);
3243 return isHypChanged;
3246 //================================================================================
3248 * \brief Create a group. Group type depends on given arguments
3250 //================================================================================
3252 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
3253 const char* theName,
3255 const TopoDS_Shape& theShape,
3256 const SMESH_PredicatePtr& thePredicate )
3258 std::string newName;
3259 if ( !theName || !theName[0] )
3261 std::set< std::string > presentNames;
3262 std::map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator i_gr = _mapGroups.begin();
3263 for ( ; i_gr != _mapGroups.end(); ++i_gr )
3265 CORBA::String_var name = i_gr->second->GetName();
3266 presentNames.insert( name.in() );
3269 newName = "noname_Group_" + SMESH_Comment( presentNames.size() + 1 );
3270 } while ( !presentNames.insert( newName ).second );
3271 theName = newName.c_str();
3273 SMESH::SMESH_GroupBase_var aGroup;
3274 if ( SMESH_Group* g = _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName,
3275 theID, theShape, thePredicate ))
3277 int anId = g->GetID();
3278 SMESH_GroupBase_i* aGroupImpl;
3279 if ( !theShape.IsNull() )
3280 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
3281 else if ( thePredicate )
3282 aGroupImpl = new SMESH_GroupOnFilter_i( SMESH_Gen_i::GetPOA(), this, anId );
3284 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
3286 aGroup = aGroupImpl->_this();
3287 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
3288 aGroupImpl->Register();
3290 // register CORBA object for persistence
3291 int nextId = _gen_i->RegisterObject( aGroup );
3292 if(MYDEBUG) { MESSAGE( "Add group to map with id = "<< nextId); }
3293 else { nextId = ( nextId > 0 ); } // avoid "unused variable" warning in release mode
3295 // to track changes of GEOM groups
3296 if ( !theShape.IsNull() ) {
3297 GEOM::GEOM_Object_var geom = _gen_i->ShapeToGeomObject( theShape );
3298 addGeomGroupData( geom, aGroup );
3301 return aGroup._retn();
3304 //=============================================================================
3306 * SMESH_Mesh_i::removeGroup
3308 * Should be called by ~SMESH_Group_i()
3310 //=============================================================================
3312 void SMESH_Mesh_i::removeGroup( const int theId )
3314 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
3315 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
3316 SMESH::SMESH_GroupBase_var group = _mapGroups[theId];
3317 _mapGroups.erase( theId );
3318 removeGeomGroupData( group );
3319 if ( !_impl->RemoveGroup( theId ))
3321 // it seems to be a call up from _impl caused by hyp modification (issue 0020918)
3322 RemoveGroup( group );
3324 group->UnRegister();
3328 //================================================================================
3330 * \brief Return a log that can be used to move another mesh to the same state as this one
3332 //================================================================================
3334 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
3336 SMESH::log_array_var aLog;
3340 _preMeshInfo->FullLoadFromFile();
3342 list < SMESHDS_Command * >logDS = _impl->GetLog();
3343 aLog = new SMESH::log_array;
3345 int lg = logDS.size();
3347 list < SMESHDS_Command * >::iterator its = logDS.begin();
3348 while(its != logDS.end()){
3349 SMESHDS_Command *com = *its;
3350 int comType = com->GetType();
3351 smIdType lgcom = com->GetNumber();
3352 const list < smIdType >&intList = com->GetIndexes();
3353 int inum = intList.size();
3354 list < smIdType >::const_iterator ii = intList.begin();
3355 const list < double >&coordList = com->GetCoords();
3356 int rnum = coordList.size();
3357 list < double >::const_iterator ir = coordList.begin();
3358 aLog[indexLog].commandType = comType;
3359 aLog[indexLog].number = lgcom;
3360 aLog[indexLog].coords.length(rnum);
3361 aLog[indexLog].indexes.length(inum);
3362 for(int i = 0; i < rnum; i++){
3363 aLog[indexLog].coords[i] = *ir;
3366 for(int i = 0; i < inum; i++){
3367 aLog[indexLog].indexes[i] = *ii;
3376 SMESH_CATCH( SMESH::throwCorbaException );
3378 return aLog._retn();
3381 //================================================================================
3383 * \brief Remove the log of commands
3385 //================================================================================
3387 void SMESH_Mesh_i::ClearLog()
3391 SMESH_CATCH( SMESH::throwCorbaException );
3394 //================================================================================
3396 * \brief Return a mesh ID
3398 //================================================================================
3400 CORBA::Long SMESH_Mesh_i::GetId()
3405 //=============================================================================
3408 //!< implementation of struct used to call methods of SMESH_Mesh_i from SMESH_Mesh
3409 // issue 0020918: groups removal is caused by hyp modification
3410 // issue 0021208: to forget not loaded mesh data at hyp modification
3411 struct TCallUp_i : public SMESH_Mesh::TCallUp
3413 SMESH_Mesh_i* _mesh;
3414 TCallUp_i(SMESH_Mesh_i* mesh):_mesh(mesh) {}
3415 void RemoveGroup (const int theGroupID) override { _mesh->removeGroup( theGroupID ); }
3416 void HypothesisModified( int hypID,
3417 bool updIcons) override { _mesh->onHypothesisModified( hypID,
3419 void Load () override { _mesh->Load(); }
3420 bool IsLoaded() override { return _mesh->IsLoaded(); }
3421 TopoDS_Shape GetShapeByEntry(const std::string& entry) override
3423 GEOM::GEOM_Object_var go = SMESH_Gen_i::GetGeomObjectByEntry( entry );
3424 return SMESH_Gen_i::GeomObjectToShape( go );
3429 //================================================================================
3431 * \brief callback from _impl to
3432 * 1) forget not loaded mesh data (issue 0021208)
3433 * 2) mark hypothesis as valid
3435 //================================================================================
3437 void SMESH_Mesh_i::onHypothesisModified(int theHypID, bool theUpdateIcons)
3440 _preMeshInfo->ForgetOrLoad();
3442 if ( theUpdateIcons )
3444 SMESH::SMESH_Mesh_var mesh = _this();
3445 _gen_i->UpdateIcons( mesh );
3448 if ( _nbInvalidHypos != 0 )
3450 // mark a hypothesis as valid after edition
3452 SALOMEDS::SComponent_wrap smeshComp = _gen_i->PublishComponent();
3453 SALOMEDS::SObject_wrap hypRoot;
3454 if ( !smeshComp->_is_nil() &&
3455 smeshComp->FindSubObject( _gen_i->GetHypothesisRootTag(), hypRoot.inout() ))
3457 SALOMEDS::ChildIterator_wrap anIter = _gen_i->getStudyServant()->NewChildIterator( hypRoot );
3458 for ( ; anIter->More(); anIter->Next() )
3460 SALOMEDS::SObject_wrap hypSO = anIter->Value();
3461 CORBA::Object_var obj = _gen_i->SObjectToObject( hypSO );
3462 SMESH::SMESH_Hypothesis_var hyp = SMESH::SMESH_Hypothesis::_narrow( obj );
3463 if ( !hyp->_is_nil() && hyp->GetId() == theHypID )
3464 _gen_i->HighLightInvalid( hyp, false );
3466 nbInvalid += _gen_i->IsInvalid( hypSO );
3469 _nbInvalidHypos = nbInvalid;
3473 //================================================================================
3475 * \brief Set mesh implementation
3477 //================================================================================
3479 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
3481 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
3484 _impl->SetCallUp( new TCallUp_i(this));
3487 //=============================================================================
3489 * Return a mesh implementation
3491 //=============================================================================
3493 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
3495 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
3499 //=============================================================================
3501 * Return mesh editor
3503 //=============================================================================
3505 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
3507 SMESH::SMESH_MeshEditor_var aMeshEdVar;
3511 _preMeshInfo->FullLoadFromFile();
3513 // Create MeshEditor
3515 _editor = new SMESH_MeshEditor_i( this, false );
3516 aMeshEdVar = _editor->_this();
3518 // Update Python script
3519 TPythonDump() << _editor << " = "
3520 << SMESH::SMESH_Mesh_var(_this()) << ".GetMeshEditor()";
3522 SMESH_CATCH( SMESH::throwCorbaException );
3524 return aMeshEdVar._retn();
3527 //=============================================================================
3529 * Return mesh edition previewer
3531 //=============================================================================
3533 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
3535 SMESH::SMESH_MeshEditor_var aMeshEdVar;
3539 _preMeshInfo->FullLoadFromFile();
3541 if ( !_previewEditor )
3542 _previewEditor = new SMESH_MeshEditor_i( this, true );
3543 aMeshEdVar = _previewEditor->_this();
3545 SMESH_CATCH( SMESH::throwCorbaException );
3547 return aMeshEdVar._retn();
3550 //================================================================================
3552 * \brief Return true if the mesh has been edited since a last total re-compute
3553 * and those modifications may prevent successful partial re-compute
3555 //================================================================================
3557 CORBA::Boolean SMESH_Mesh_i::HasModificationsToDiscard()
3559 Unexpect aCatch(SALOME_SalomeException);
3560 return _impl->HasModificationsToDiscard();
3563 //================================================================================
3565 * \brief Return a random unique color
3567 //================================================================================
3569 static SALOMEDS::Color getUniqueColor( const std::list<SALOMEDS::Color>& theReservedColors )
3571 const int MAX_ATTEMPTS = 100;
3573 double tolerance = 0.5;
3574 SALOMEDS::Color col;
3578 // generate random color
3579 double red = (double)rand() / RAND_MAX;
3580 double green = (double)rand() / RAND_MAX;
3581 double blue = (double)rand() / RAND_MAX;
3582 // check existence in the list of the existing colors
3583 bool matched = false;
3584 std::list<SALOMEDS::Color>::const_iterator it;
3585 for ( it = theReservedColors.begin(); it != theReservedColors.end() && !matched; ++it ) {
3586 SALOMEDS::Color color = *it;
3587 double tol = fabs( color.R - red ) + fabs( color.G - green ) + fabs( color.B - blue );
3588 matched = tol < tolerance;
3590 if ( (cnt+1) % 20 == 0 ) tolerance = tolerance/2;
3591 ok = ( ++cnt == MAX_ATTEMPTS ) || !matched;
3599 //=============================================================================
3601 * Set auto-color mode. If it is on, groups get unique random colors
3603 //=============================================================================
3605 void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor)
3607 Unexpect aCatch(SALOME_SalomeException);
3608 _impl->SetAutoColor(theAutoColor);
3610 TPythonDump pyDump; // not to dump group->SetColor() from below code
3611 pyDump << SMESH::SMESH_Mesh_var(_this()) <<".SetAutoColor( "<<theAutoColor<<" )";
3613 std::list<SALOMEDS::Color> aReservedColors;
3614 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
3615 for ( ; it != _mapGroups.end(); it++ ) {
3616 if ( CORBA::is_nil( it->second )) continue;
3617 SALOMEDS::Color aColor = getUniqueColor( aReservedColors );
3618 it->second->SetColor( aColor );
3619 aReservedColors.push_back( aColor );
3623 //=============================================================================
3625 * Return true if auto-color mode is on
3627 //=============================================================================
3629 CORBA::Boolean SMESH_Mesh_i::GetAutoColor()
3631 Unexpect aCatch(SALOME_SalomeException);
3632 return _impl->GetAutoColor();
3635 //=============================================================================
3637 * Check if there are groups with equal names
3639 //=============================================================================
3641 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
3643 return _impl->HasDuplicatedGroupNamesMED();
3646 //================================================================================
3648 * \brief Care of a file before exporting mesh into it
3650 //================================================================================
3652 void SMESH_Mesh_i::PrepareForWriting (const char* file, bool overwrite)
3654 SMESH_File aFile( file, false );
3656 if ( aFile.exists() ) {
3657 // existing filesystem node
3658 if ( !aFile.isDirectory() ) {
3659 if ( aFile.openForWriting() ) {
3660 if ( overwrite && ! aFile.remove()) {
3661 msg << "Can't replace " << aFile.getName();
3664 msg << "Can't write into " << aFile.getName();
3667 msg << "Location " << aFile.getName() << " is not a file";
3671 // nonexisting file; check if it can be created
3672 if ( !aFile.openForWriting() ) {
3673 msg << "You cannot create the file "
3675 << ". Check the directory existence and access rights";
3683 THROW_SALOME_CORBA_EXCEPTION(msg.c_str(), SALOME::BAD_PARAM);
3690 std::string SMESH_Mesh_i::generateMeshName()
3692 string aMeshName = "Mesh";
3693 SALOMEDS::Study_var aStudy = SMESH_Gen_i::GetSMESHGen()->getStudyServant();
3694 if ( !aStudy->_is_nil() )
3696 SALOMEDS::SObject_wrap aMeshSO = _gen_i->ObjectToSObject( _this() );
3697 if ( !aMeshSO->_is_nil() )
3699 CORBA::String_var name = aMeshSO->GetName();
3706 //================================================================================
3708 * \brief Prepare a file for export and pass names of mesh groups from study to mesh DS
3709 * \param file - file name
3710 * \param overwrite - to erase the file or not
3711 * \retval string - mesh name
3713 //================================================================================
3715 string SMESH_Mesh_i::prepareMeshNameAndGroups(const char* file,
3716 CORBA::Boolean overwrite)
3719 PrepareForWriting(file, overwrite);
3720 string aMeshName(this->generateMeshName());
3721 SALOMEDS::Study_var aStudy = SMESH_Gen_i::GetSMESHGen()->getStudyServant();
3722 if ( !aStudy->_is_nil() ) {
3723 SALOMEDS::SObject_wrap aMeshSO = _gen_i->ObjectToSObject( _this() );
3724 if ( !aMeshSO->_is_nil() ) {
3725 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
3726 if ( !aStudy->GetProperties()->IsLocked() )
3728 SALOMEDS::GenericAttribute_wrap anAttr;
3729 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
3730 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
3731 SALOMEDS::AttributeExternalFileDef_wrap aFileName = anAttr;
3732 ASSERT(!aFileName->_is_nil());
3733 aFileName->SetValue(file);
3734 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
3735 SALOMEDS::AttributeFileType_wrap aFileType = anAttr;
3736 ASSERT(!aFileType->_is_nil());
3737 aFileType->SetValue("FICHIERMED");
3741 // Update Python script
3742 // set name of mesh before export
3743 TPythonDump() << _gen_i << ".SetName("
3744 << SMESH::SMESH_Mesh_var(_this()) << ", '" << aMeshName.c_str() << "')";
3746 // check names of groups
3752 //================================================================================
3754 * \brief Export to MED file
3756 //================================================================================
3758 void SMESH_Mesh_i::ExportMED(const char* file,
3759 CORBA::Boolean auto_groups,
3760 CORBA::Long version,
3761 CORBA::Boolean overwrite,
3762 CORBA::Boolean autoDimension)
3764 //MESSAGE("MED minor version: "<< minor);
3767 _preMeshInfo->FullLoadFromFile();
3769 string aMeshName = prepareMeshNameAndGroups(file, overwrite);
3770 _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, 0, autoDimension );
3772 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportMED( r'"
3774 << "auto_groups=" <<auto_groups << ", "
3775 << "version=" << version << ", "
3776 << "overwrite=" << overwrite << ", "
3777 << "meshPart=None, "
3778 << "autoDimension=" << autoDimension << " )";
3780 SMESH_CATCH( SMESH::throwCorbaException );
3783 CORBA::LongLong SMESH_Mesh_i::ExportMEDCoupling(CORBA::Boolean auto_groups, CORBA::Boolean autoDimension)
3785 MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> data;
3787 // TODO : Fix me ! 2 next lines are required
3788 if( !this->_gen_i->isSSLMode() )
3789 SMESH::throwCorbaException("SMESH_Mesh_i::ExportMEDCoupling : only for embedded mode !");
3791 _preMeshInfo->FullLoadFromFile();
3793 string aMeshName = this->generateMeshName();
3794 data = _impl->ExportMEDCoupling( aMeshName.c_str(), auto_groups, 0, autoDimension );
3795 SMESH_CATCH( SMESH::throwCorbaException );
3796 MEDCoupling::DataArrayByte *ret(data.retn());
3797 return reinterpret_cast<CORBA::LongLong>(ret);
3800 //================================================================================
3802 * \brief Export a mesh to a DAT file
3804 //================================================================================
3806 void SMESH_Mesh_i::ExportDAT (const char *file, CORBA::Boolean renumber )
3810 _preMeshInfo->FullLoadFromFile();
3812 // check names of groups
3814 // Update Python script
3815 TPythonDump() << SMESH::SMESH_Mesh_var(_this())
3816 << ".ExportDAT( r'" << file<< ", " << renumber << "' )";
3819 PrepareForWriting( file );
3820 _impl->ExportDAT( file, /*part=*/nullptr, renumber );
3822 SMESH_CATCH( SMESH::throwCorbaException );
3825 //================================================================================
3827 * \brief Export a mesh to an UNV file
3829 //================================================================================
3831 void SMESH_Mesh_i::ExportUNV (const char *file, CORBA::Boolean renumber)
3835 _preMeshInfo->FullLoadFromFile();
3837 // check names of groups
3839 // Update Python script
3840 TPythonDump() << SMESH::SMESH_Mesh_var(_this())
3841 << ".ExportUNV( r'" << file << "' " << renumber << "' )";
3844 PrepareForWriting( file );
3845 _impl->ExportUNV( file, /*part=*/nullptr, renumber );
3847 SMESH_CATCH( SMESH::throwCorbaException );
3850 //================================================================================
3852 * \brief Export a mesh to an STL file
3854 //================================================================================
3856 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
3860 _preMeshInfo->FullLoadFromFile();
3862 // check names of groups
3864 // Update Python script
3865 TPythonDump() << SMESH::SMESH_Mesh_var(_this())
3866 << ".ExportSTL( r'" << file << "', " << isascii << " )";
3868 CORBA::String_var name;
3869 SALOMEDS::SObject_wrap so = _gen_i->ObjectToSObject( _this() );
3870 if ( !so->_is_nil() )
3871 name = so->GetName();
3874 PrepareForWriting( file );
3875 _impl->ExportSTL( file, isascii, name.in() );
3877 SMESH_CATCH( SMESH::throwCorbaException );
3880 //================================================================================
3885 MEDFileSpeCls(const char * file,
3886 CORBA::Boolean overwrite,
3887 CORBA::Long version)
3888 :_file(file), _overwrite(overwrite), _version(version)
3890 std::string prepareMeshNameAndGroups(SMESH_Mesh_i& self)
3892 return self.prepareMeshNameAndGroups(_file.c_str(),_overwrite);
3895 void exportTo(SMESH_Mesh *mesh, const std::string& aMeshName, CORBA::Boolean auto_groups,
3896 SMESH_MeshPartDS* partDS, CORBA::Boolean autoDimension, bool have0dField,
3897 CORBA::Double ZTolerance, CORBA::Boolean saveNumbers )
3899 mesh->ExportMED( _file.c_str(), aMeshName.c_str(), auto_groups, _version,
3900 partDS, autoDimension, have0dField, ZTolerance, saveNumbers );
3903 void exportField(SMESH_Mesh_i& self, const std::string& aMeshName, bool have0dField,
3904 SMESHDS_Mesh *meshDS, const GEOM::ListOfFields& fields,
3905 const char*geomAssocFields)
3907 DriverMED_W_Field fieldWriter;
3908 fieldWriter.SetFile( _file.c_str() );
3909 fieldWriter.SetMeshName( aMeshName );
3910 fieldWriter.AddODOnVertices( have0dField );
3911 self.exportMEDFields( fieldWriter, meshDS, fields, geomAssocFields );
3914 void prepareForWriting(SMESH_Mesh_i& self) { self.PrepareForWriting(_file.c_str(), _overwrite); }
3918 CORBA::Boolean _overwrite;
3919 CORBA::Long _version;
3922 //================================================================================
3924 * \brief Export a part of mesh to a med file
3926 //================================================================================
3928 template<class SPECLS>
3929 void SMESH_Mesh_i::ExportPartToMEDCommon(SPECLS& speCls,
3930 SMESH::SMESH_IDSource_ptr meshPart,
3931 CORBA::Boolean auto_groups,
3932 CORBA::Boolean autoDimension,
3933 const GEOM::ListOfFields& fields,
3934 const char* geomAssocFields,
3935 CORBA::Double ZTolerance,
3936 CORBA::Boolean saveNumbers)
3940 _preMeshInfo->FullLoadFromFile();
3943 bool have0dField = false;
3944 if ( fields.length() > 0 )
3946 GEOM::GEOM_Object_var shapeToMesh = GetShapeToMesh();
3947 if ( shapeToMesh->_is_nil() )
3948 THROW_SALOME_CORBA_EXCEPTION( "No shape to mesh", SALOME::INTERNAL_ERROR );
3950 for ( size_t i = 0; i < fields.length(); ++i )
3952 if ( fields[i]->GetDataType() == GEOM::FDT_String )
3953 THROW_SALOME_CORBA_EXCEPTION
3954 ( "Export of string fields is not supported", SALOME::BAD_PARAM);
3955 GEOM::GEOM_Object_var fieldShape = fields[i]->GetShape();
3956 if ( fieldShape->_is_nil() )
3957 THROW_SALOME_CORBA_EXCEPTION( "Null shape under a field", SALOME::INTERNAL_ERROR );
3958 if ( !fieldShape->IsSame( shapeToMesh ) )
3959 THROW_SALOME_CORBA_EXCEPTION( "Field defined not on shape", SALOME::BAD_PARAM);
3960 if ( fields[i]->GetDimension() == 0 )
3963 if ( geomAssocFields )
3964 for ( int i = 0; geomAssocFields[i]; ++i )
3965 switch ( geomAssocFields[i] ) {
3966 case 'v':case 'e':case 'f':case 's': break;
3967 case 'V':case 'E':case 'F':case 'S': break;
3968 default: THROW_SALOME_CORBA_EXCEPTION
3969 ( "geomAssocFields can include only [vefs] characters", SALOME::BAD_PARAM);
3973 SMESHDS_Mesh* meshDS = _impl->GetMeshDS();
3977 string aMeshName = "Mesh";
3978 SMESHUtils::Deleter< SMESH_MeshPartDS > tmpDSDeleter(0);
3979 if ( CORBA::is_nil( meshPart ) ||
3980 SMESH::DownCast< SMESH_Mesh_i* >( meshPart ))
3982 aMeshName = speCls.prepareMeshNameAndGroups(*this);
3983 speCls.exportTo(_impl, aMeshName, auto_groups, nullptr, autoDimension,
3984 have0dField, ZTolerance, saveNumbers );
3985 meshDS = _impl->GetMeshDS();
3990 _preMeshInfo->FullLoadFromFile();
3992 speCls.prepareForWriting(*this);
3994 SALOMEDS::SObject_wrap SO = _gen_i->ObjectToSObject( meshPart );
3995 if ( !SO->_is_nil() ) {
3996 CORBA::String_var name = SO->GetName();
4000 SMESH_MeshPartDS* partDS = new SMESH_MeshPartDS( meshPart );
4001 speCls.exportTo(_impl, aMeshName, auto_groups, partDS, autoDimension,
4002 have0dField, ZTolerance, saveNumbers);
4003 meshDS = tmpDSDeleter._obj = partDS;
4008 if ( _impl->HasShapeToMesh() )
4010 speCls.exportField( *this, aMeshName, have0dField, meshDS, fields, geomAssocFields);
4012 SMESH_CATCH( SMESH::throwCorbaException );
4015 //================================================================================
4017 * \brief Export a part of mesh to a med file
4019 //================================================================================
4021 void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
4023 CORBA::Boolean auto_groups,
4024 CORBA::Long version,
4025 CORBA::Boolean overwrite,
4026 CORBA::Boolean autoDimension,
4027 const GEOM::ListOfFields& fields,
4028 const char* geomAssocFields,
4029 CORBA::Double ZTolerance,
4030 CORBA::Boolean saveNumbers)
4032 MESSAGE("MED version: "<< version);
4034 MEDFileSpeCls spe( file, overwrite, version );
4035 this->ExportPartToMEDCommon( spe, meshPart, auto_groups, autoDimension, fields,
4036 geomAssocFields, ZTolerance, saveNumbers );
4039 GEOM::ListOfGBO_var goList = new GEOM::ListOfGBO;
4040 goList->length( fields.length() );
4041 for ( size_t i = 0; i < fields.length(); ++i )
4043 GEOM::GEOM_BaseObject_var gbo = GEOM::GEOM_BaseObject::_narrow( fields[i] );
4046 TPythonDump() << _this() << ".ExportPartToMED( "
4047 << meshPart << ", r'"
4049 << auto_groups << ", "
4051 << overwrite << ", "
4052 << autoDimension << ", "
4054 << ( geomAssocFields ? geomAssocFields : "" ) << "',"
4055 << TVar( ZTolerance ) << ", "
4058 SMESH_CATCH( SMESH::throwCorbaException );
4061 //================================================================================
4063 class MEDFileMemSpeCls
4066 std::string prepareMeshNameAndGroups(SMESH_Mesh_i& self) { return self.generateMeshName(); }
4068 void exportTo(SMESH_Mesh *mesh, const std::string& aMeshName, CORBA::Boolean auto_groups,
4069 SMESH_MeshPartDS* partDS, CORBA::Boolean autoDimension, bool have0dField,
4070 CORBA::Double ZTolerance, CORBA::Boolean saveNumbers )
4072 _res = mesh->ExportMEDCoupling(aMeshName.c_str(), auto_groups, partDS,
4073 autoDimension, have0dField, ZTolerance, saveNumbers );
4075 void prepareForWriting(SMESH_Mesh_i& /*self*/) { /* nothing here */ }
4077 void exportField(SMESH_Mesh_i& self, const std::string& aMeshName, bool have0dField,
4078 SMESHDS_Mesh *meshDS, const GEOM::ListOfFields& fields,
4079 const char*geomAssocFields)
4081 DriverMED_W_Field_Mem fieldWriter(_res);
4082 fieldWriter.SetMeshName( aMeshName );
4083 fieldWriter.AddODOnVertices( have0dField );
4084 self.exportMEDFields( fieldWriter, meshDS, fields, geomAssocFields );
4085 _res = fieldWriter.getData();
4088 MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> getData() { return _res; }
4091 MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> _res;
4094 //================================================================================
4096 * \brief Export a part of mesh to a MEDCoupling DS
4098 //================================================================================
4100 CORBA::LongLong SMESH_Mesh_i::ExportPartToMEDCoupling(SMESH::SMESH_IDSource_ptr meshPart,
4101 CORBA::Boolean auto_groups,
4102 CORBA::Boolean autoDimension,
4103 const GEOM::ListOfFields& fields,
4104 const char* geomAssocFields,
4105 CORBA::Double ZTolerance,
4106 CORBA::Boolean saveNumbers)
4108 MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> data;
4111 if( !this->_gen_i->isSSLMode() )
4112 SMESH::throwCorbaException("SMESH_Mesh_i::ExportPartToMEDCoupling : only for embedded mode !");
4114 MEDFileMemSpeCls spe;
4115 this->ExportPartToMEDCommon( spe, meshPart, auto_groups, autoDimension, fields, geomAssocFields,
4116 ZTolerance, saveNumbers );
4117 data = spe.getData();
4119 SMESH_CATCH( SMESH::throwCorbaException );
4121 MEDCoupling::DataArrayByte *ret(data.retn());
4122 return reinterpret_cast<CORBA::LongLong>(ret);
4125 //================================================================================
4127 * Write GEOM fields to MED file
4129 //================================================================================
4131 void SMESH_Mesh_i::exportMEDFields( DriverMED_W_Field& fieldWriter,
4132 SMESHDS_Mesh* meshDS,
4133 const GEOM::ListOfFields& fields,
4134 const char* geomAssocFields)
4136 #define METH "SMESH_Mesh_i::exportMEDFields() "
4138 if (( fields.length() < 1 ) &&
4139 ( !geomAssocFields || !geomAssocFields[0] ))
4142 std::vector< std::vector< double > > dblVals;
4143 std::vector< std::vector< int > > intVals;
4144 std::vector< int > subIdsByDim[ 4 ];
4145 const double noneDblValue = 0.;
4146 const double noneIntValue = 0;
4148 for ( size_t iF = 0; iF < fields.length(); ++iF )
4152 int dim = fields[ iF ]->GetDimension();
4153 SMDSAbs_ElementType elemType;
4154 TopAbs_ShapeEnum shapeType;
4156 case 0: elemType = SMDSAbs_0DElement; shapeType = TopAbs_VERTEX; break;
4157 case 1: elemType = SMDSAbs_Edge; shapeType = TopAbs_EDGE; break;
4158 case 2: elemType = SMDSAbs_Face; shapeType = TopAbs_FACE; break;
4159 case 3: elemType = SMDSAbs_Volume; shapeType = TopAbs_SOLID; break;
4161 continue; // skip fields on whole shape
4163 GEOM::field_data_type dataType = fields[ iF ]->GetDataType();
4164 if ( dataType == GEOM::FDT_String )
4166 GEOM::ListOfLong_var stepIDs = fields[ iF ]->GetSteps();
4167 if ( stepIDs->length() < 1 )
4169 GEOM::string_array_var comps = fields[ iF ]->GetComponents();
4170 if ( comps->length() < 1 )
4172 CORBA::String_var name = fields[ iF ]->GetName();
4174 if ( !fieldWriter.Set( meshDS,
4178 /*isIntData=*/false ))//( dataType == GEOM::FDT_Int )))
4181 for ( size_t iC = 0; iC < comps->length(); ++iC )
4182 fieldWriter.SetCompName( iC, comps[ iC ].in() );
4184 dblVals.resize( comps->length() );
4185 intVals.resize( comps->length() );
4187 // find sub-shape IDs
4189 std::vector< int >& subIds = subIdsByDim[ dim ];
4190 if ( subIds.empty() )
4191 for ( int id = 1; id <= meshDS->MaxShapeIndex(); ++id )
4192 if ( meshDS->IndexToShape( id ).ShapeType() == shapeType )
4193 subIds.push_back( id );
4197 SMDS_ElemIteratorPtr elemIt = fieldWriter.GetOrderedElems();
4201 for ( size_t iS = 0; iS < stepIDs->length(); ++iS )
4203 GEOM::GEOM_FieldStep_var step = fields[ iF ]->GetStep( stepIDs[ iS ]);
4204 if ( step->_is_nil() )
4207 CORBA::Long stamp = step->GetStamp();
4208 CORBA::Long id = step->GetID();
4209 fieldWriter.SetDtIt( int( stamp ), int( id ));
4211 // fill dblVals or intVals
4212 for ( size_t iC = 0; iC < comps->length(); ++iC )
4213 if ( dataType == GEOM::FDT_Double )
4215 dblVals[ iC ].clear();
4216 dblVals[ iC ].resize( meshDS->MaxShapeIndex()+1, 0 );
4220 intVals[ iC ].clear();
4221 intVals[ iC ].resize( meshDS->MaxShapeIndex()+1, 0 );
4225 case GEOM::FDT_Double:
4227 GEOM::GEOM_DoubleFieldStep_var dblStep = GEOM::GEOM_DoubleFieldStep::_narrow( step );
4228 if ( dblStep->_is_nil() ) continue;
4229 GEOM::ListOfDouble_var vv = dblStep->GetValues();
4230 if ( vv->length() != subIds.size() * comps->length() )
4231 THROW_SALOME_CORBA_EXCEPTION( METH "BUG: wrong nb subIds", SALOME::INTERNAL_ERROR );
4232 for ( size_t iS = 0, iV = 0; iS < subIds.size(); ++iS )
4233 for ( size_t iC = 0; iC < comps->length(); ++iC )
4234 dblVals[ iC ][ subIds[ iS ]] = vv[ iV++ ];
4239 GEOM::GEOM_IntFieldStep_var intStep = GEOM::GEOM_IntFieldStep::_narrow( step );
4240 if ( intStep->_is_nil() ) continue;
4241 GEOM::ListOfLong_var vv = intStep->GetValues();
4242 if ( vv->length() != subIds.size() * comps->length() )
4243 THROW_SALOME_CORBA_EXCEPTION( METH "BUG: wrong nb subIds", SALOME::INTERNAL_ERROR );
4244 for ( size_t iS = 0, iV = 0; iS < subIds.size(); ++iS )
4245 for ( size_t iC = 0; iC < comps->length(); ++iC )
4246 intVals[ iC ][ subIds[ iS ]] = (int) vv[ iV++ ];
4249 case GEOM::FDT_Bool:
4251 GEOM::GEOM_BoolFieldStep_var boolStep = GEOM::GEOM_BoolFieldStep::_narrow( step );
4252 if ( boolStep->_is_nil() ) continue;
4253 GEOM::short_array_var vv = boolStep->GetValues();
4254 if ( vv->length() != subIds.size() * comps->length() )
4255 THROW_SALOME_CORBA_EXCEPTION( METH "BUG: wrong nb subIds", SALOME::INTERNAL_ERROR );
4256 for ( size_t iS = 0, iV = 0; iS < subIds.size(); ++iS )
4257 for ( size_t iC = 0; iC < comps->length(); ++iC )
4258 intVals[ iC ][ subIds[ iS ]] = (int) vv[ iV++ ];
4264 // pass values to fieldWriter
4265 elemIt = fieldWriter.GetOrderedElems();
4266 if ( dataType == GEOM::FDT_Double )
4267 while ( elemIt->more() )
4269 const SMDS_MeshElement* e = elemIt->next();
4270 const int shapeID = e->getshapeId();
4271 if ( shapeID < 1 || shapeID >= (int) dblVals[0].size() )
4272 for ( size_t iC = 0; iC < comps->length(); ++iC )
4273 fieldWriter.AddValue( noneDblValue );
4275 for ( size_t iC = 0; iC < comps->length(); ++iC )
4276 fieldWriter.AddValue( dblVals[ iC ][ shapeID ]);
4279 while ( elemIt->more() )
4281 const SMDS_MeshElement* e = elemIt->next();
4282 const int shapeID = e->getshapeId();
4283 if ( shapeID < 1 || shapeID >= (int) intVals[0].size() )
4284 for ( size_t iC = 0; iC < comps->length(); ++iC )
4285 fieldWriter.AddValue( (double) noneIntValue );
4287 for ( size_t iC = 0; iC < comps->length(); ++iC )
4288 fieldWriter.AddValue( (double) intVals[ iC ][ shapeID ]);
4292 fieldWriter.Perform();
4293 SMESH_ComputeErrorPtr res = fieldWriter.GetError();
4294 if ( res && res->IsKO() )
4296 if ( res->myComment.empty() )
4297 { THROW_SALOME_CORBA_EXCEPTION( METH "Fatal error", SALOME::INTERNAL_ERROR ); }
4299 { THROW_SALOME_CORBA_EXCEPTION( res->myComment.c_str(), SALOME::INTERNAL_ERROR ); }
4305 if ( !geomAssocFields || !geomAssocFields[0] )
4308 // write geomAssocFields
4310 std::vector< int > shapeDim( TopAbs_SHAPE + 1 );
4311 shapeDim[ TopAbs_COMPOUND ] = 3;
4312 shapeDim[ TopAbs_COMPSOLID ] = 3;
4313 shapeDim[ TopAbs_SOLID ] = 3;
4314 shapeDim[ TopAbs_SHELL ] = 2;
4315 shapeDim[ TopAbs_FACE ] = 2;
4316 shapeDim[ TopAbs_WIRE ] = 1;
4317 shapeDim[ TopAbs_EDGE ] = 1;
4318 shapeDim[ TopAbs_VERTEX ] = 0;
4319 shapeDim[ TopAbs_SHAPE ] = 3;
4321 for ( int iF = 0; geomAssocFields[ iF ]; ++iF )
4323 std::vector< std::string > compNames;
4324 switch ( geomAssocFields[ iF ]) {
4326 fieldWriter.Set( meshDS, "_vertices_", SMDSAbs_Node, /*nbComps=*/2, /*isInt=*/false );
4327 compNames.push_back( "dim" );
4330 fieldWriter.Set( meshDS, "_edges_", SMDSAbs_Edge, /*nbComps=*/1, /*isInt=*/false );
4333 fieldWriter.Set( meshDS, "_faces_", SMDSAbs_Face, /*nbComps=*/1, /*isInt=*/false );
4336 fieldWriter.Set( meshDS, "_solids_", SMDSAbs_Volume, /*nbComps=*/1, /*isInt=*/false );
4340 compNames.push_back( "id" );
4341 for ( size_t iC = 0; iC < compNames.size(); ++iC )
4342 fieldWriter.SetCompName( iC, compNames[ iC ].c_str() );
4344 fieldWriter.SetDtIt( -1, -1 );
4346 SMDS_ElemIteratorPtr elemIt = fieldWriter.GetOrderedElems();
4350 if ( compNames.size() == 2 ) // _vertices_
4351 while ( elemIt->more() )
4353 const SMDS_MeshElement* e = elemIt->next();
4354 const int shapeID = e->getshapeId();
4357 fieldWriter.AddValue( (double) -1 );
4358 fieldWriter.AddValue( (double) -1 );
4362 const TopoDS_Shape& S = meshDS->IndexToShape( shapeID );
4363 fieldWriter.AddValue( (double) ( S.IsNull() ? -1 : shapeDim[ S.ShapeType() ]));
4364 fieldWriter.AddValue( (double) shapeID );
4368 while ( elemIt->more() )
4370 const SMDS_MeshElement* e = elemIt->next();
4371 const int shapeID = e->getshapeId();
4373 fieldWriter.AddValue( (double) -1 );
4375 fieldWriter.AddValue( (double) shapeID );
4379 fieldWriter.Perform();
4380 SMESH_ComputeErrorPtr res = fieldWriter.GetError();
4381 if ( res && res->IsKO() )
4383 if ( res->myComment.empty() )
4384 { THROW_SALOME_CORBA_EXCEPTION( METH "Fatal error", SALOME::INTERNAL_ERROR ); }
4386 { THROW_SALOME_CORBA_EXCEPTION( res->myComment.c_str(), SALOME::INTERNAL_ERROR ); }
4389 } // loop on geomAssocFields
4394 //================================================================================
4396 * \brief Export a part of mesh to a DAT file
4398 //================================================================================
4400 void SMESH_Mesh_i::ExportPartToDAT(SMESH::SMESH_IDSource_ptr meshPart,
4402 CORBA::Boolean renumber )
4406 SMESH_MeshPartDS partDS( meshPart );
4407 _impl->ExportDAT( file, &partDS, renumber );
4409 TPythonDump() << SMESH::SMESH_Mesh_var(_this())
4410 << ".ExportPartToDAT( " << meshPart << ", r'" << file << ", " << renumber << "' )";
4412 SMESH_CATCH( SMESH::throwCorbaException );
4414 //================================================================================
4416 * \brief Export a part of mesh to an UNV file
4418 //================================================================================
4420 void SMESH_Mesh_i::ExportPartToUNV(SMESH::SMESH_IDSource_ptr meshPart,
4422 CORBA::Boolean renumber)
4426 _preMeshInfo->FullLoadFromFile();
4428 PrepareForWriting(file);
4430 SMESH_MeshPartDS partDS( meshPart );
4431 _impl->ExportUNV(file, &partDS, renumber );
4433 TPythonDump() << SMESH::SMESH_Mesh_var(_this())
4434 << ".ExportPartToUNV( " << meshPart<< ", r'" << file << ", " << renumber << "' )";
4436 SMESH_CATCH( SMESH::throwCorbaException );
4438 //================================================================================
4440 * \brief Export a part of mesh to an STL file
4442 //================================================================================
4444 void SMESH_Mesh_i::ExportPartToSTL(::SMESH::SMESH_IDSource_ptr meshPart,
4446 ::CORBA::Boolean isascii)
4450 _preMeshInfo->FullLoadFromFile();
4452 PrepareForWriting(file);
4454 CORBA::String_var name;
4455 SALOMEDS::SObject_wrap so = _gen_i->ObjectToSObject( meshPart );
4456 if ( !so->_is_nil() )
4457 name = so->GetName();
4459 SMESH_MeshPartDS partDS( meshPart );
4460 _impl->ExportSTL( file, isascii, name.in(), &partDS );
4462 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportPartToSTL( "
4463 << meshPart<< ", r'" << file << "', " << isascii << ")";
4465 SMESH_CATCH( SMESH::throwCorbaException );
4468 //================================================================================
4470 * \brief Export a part of mesh to an STL file
4472 //================================================================================
4474 void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
4476 CORBA::Boolean overwrite,
4477 CORBA::Boolean groupElemsByType)
4482 _preMeshInfo->FullLoadFromFile();
4484 PrepareForWriting(file,overwrite);
4486 std::string meshName("");
4487 SALOMEDS::SObject_wrap so = _gen_i->ObjectToSObject( meshPart );
4488 if ( !so->_is_nil() )
4490 CORBA::String_var name = so->GetName();
4491 meshName = name.in();
4495 SMESH_MeshPartDS partDS( meshPart );
4496 _impl->ExportCGNS(file, &partDS, meshName.c_str(), groupElemsByType );
4498 SMESH_CATCH( SMESH::throwCorbaException );
4500 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportCGNS( "
4501 << meshPart<< ", r'" << file << "', " << overwrite << ")";
4503 SMESH_CATCH( SMESH::throwCorbaException );
4506 THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
4510 //================================================================================
4512 * \brief Export a part of mesh to a GMF file
4514 //================================================================================
4516 void SMESH_Mesh_i::ExportGMF(::SMESH::SMESH_IDSource_ptr meshPart,
4518 bool withRequiredGroups)
4522 _preMeshInfo->FullLoadFromFile();
4524 PrepareForWriting(file,/*overwrite=*/true);
4526 SMESH_MeshPartDS partDS( meshPart );
4527 _impl->ExportGMF(file, &partDS, withRequiredGroups);
4529 TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportGMF( "
4530 << meshPart<< ", r'"
4532 << withRequiredGroups << ")";
4534 SMESH_CATCH( SMESH::throwCorbaException );
4537 //=============================================================================
4539 * Return computation progress [0.,1]
4541 //=============================================================================
4543 CORBA::Double SMESH_Mesh_i::GetComputeProgress()
4547 return _impl->GetComputeProgress();
4549 SMESH_CATCH( SMESH::doNothing );
4553 //================================================================================
4555 * \brief Return nb of nodes
4557 //================================================================================
4559 SMESH::smIdType SMESH_Mesh_i::NbNodes()
4561 Unexpect aCatch(SALOME_SalomeException);
4563 return _preMeshInfo->NbNodes();
4565 return _impl->NbNodes();
4568 //================================================================================
4570 * \brief Return nb of elements
4572 //================================================================================
4574 SMESH::smIdType SMESH_Mesh_i::NbElements()
4576 Unexpect aCatch(SALOME_SalomeException);
4578 return _preMeshInfo->NbElements();
4580 return Nb0DElements() + NbEdges() + NbFaces() + NbVolumes() + NbBalls();
4583 //================================================================================
4585 * \brief Return nb of 0D elements
4587 //================================================================================
4589 SMESH::smIdType SMESH_Mesh_i::Nb0DElements()
4591 Unexpect aCatch(SALOME_SalomeException);
4593 return _preMeshInfo->Nb0DElements();
4595 return _impl->Nb0DElements();
4598 //================================================================================
4600 * \brief Return nb of BALL elements
4602 //================================================================================
4604 SMESH::smIdType SMESH_Mesh_i::NbBalls()
4606 Unexpect aCatch(SALOME_SalomeException);
4608 return _preMeshInfo->NbBalls();
4610 return _impl->NbBalls();
4613 //================================================================================
4615 * \brief Return nb of 1D elements
4617 //================================================================================
4619 SMESH::smIdType SMESH_Mesh_i::NbEdges()
4621 Unexpect aCatch(SALOME_SalomeException);
4623 return _preMeshInfo->NbEdges();
4625 return _impl->NbEdges();
4628 //================================================================================
4630 * \brief Return nb of edges
4632 //================================================================================
4634 SMESH::smIdType SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
4636 Unexpect aCatch(SALOME_SalomeException);
4638 return _preMeshInfo->NbEdges( (SMDSAbs_ElementOrder) order );
4640 return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
4643 //================================================================================
4645 * \brief Return nb of faces
4647 //================================================================================
4649 SMESH::smIdType SMESH_Mesh_i::NbFaces()
4651 Unexpect aCatch(SALOME_SalomeException);
4653 return _preMeshInfo->NbFaces();
4655 return _impl->NbFaces();
4658 //================================================================================
4660 * \brief Return nb of tringles
4662 //================================================================================
4664 SMESH::smIdType SMESH_Mesh_i::NbTriangles()
4666 Unexpect aCatch(SALOME_SalomeException);
4668 return _preMeshInfo->NbTriangles();
4670 return _impl->NbTriangles();
4673 //================================================================================
4675 * \brief Return nb of bi-quadratic triangles
4677 //================================================================================
4679 SMESH::smIdType SMESH_Mesh_i::NbBiQuadTriangles()
4681 Unexpect aCatch(SALOME_SalomeException);
4683 return _preMeshInfo->NbBiQuadTriangles();
4685 return _impl->NbBiQuadTriangles();
4688 SMESH::smIdType SMESH_Mesh_i::NbQuadrangles()
4690 Unexpect aCatch(SALOME_SalomeException);
4692 return _preMeshInfo->NbQuadrangles();
4694 return _impl->NbQuadrangles();
4697 SMESH::smIdType SMESH_Mesh_i::NbBiQuadQuadrangles()
4699 Unexpect aCatch(SALOME_SalomeException);
4701 return _preMeshInfo->NbBiQuadQuadrangles();
4703 return _impl->NbBiQuadQuadrangles();
4706 SMESH::smIdType SMESH_Mesh_i::NbPolygons()
4708 Unexpect aCatch(SALOME_SalomeException);
4710 return _preMeshInfo->NbPolygons();
4712 return _impl->NbPolygons();
4715 SMESH::smIdType SMESH_Mesh_i::NbPolygonsOfOrder(SMESH::ElementOrder order)
4717 Unexpect aCatch(SALOME_SalomeException);
4719 return _preMeshInfo->NbPolygons((SMDSAbs_ElementOrder) order);
4721 return _impl->NbPolygons((SMDSAbs_ElementOrder)order);
4724 SMESH::smIdType SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
4726 Unexpect aCatch(SALOME_SalomeException);
4728 return _preMeshInfo->NbFaces( (SMDSAbs_ElementOrder) order );
4730 return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
4733 SMESH::smIdType SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
4735 Unexpect aCatch(SALOME_SalomeException);
4737 return _preMeshInfo->NbTriangles( (SMDSAbs_ElementOrder) order );
4739 return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
4742 SMESH::smIdType SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
4744 Unexpect aCatch(SALOME_SalomeException);
4746 return _preMeshInfo->NbQuadrangles( (SMDSAbs_ElementOrder) order );
4748 return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
4751 //=============================================================================
4753 SMESH::smIdType SMESH_Mesh_i::NbVolumes()
4755 Unexpect aCatch(SALOME_SalomeException);
4757 return _preMeshInfo->NbVolumes();
4759 return _impl->NbVolumes();
4762 SMESH::smIdType SMESH_Mesh_i::NbTetras()
4764 Unexpect aCatch(SALOME_SalomeException);
4766 return _preMeshInfo->NbTetras();
4768 return _impl->NbTetras();
4771 SMESH::smIdType SMESH_Mesh_i::NbHexas()
4773 Unexpect aCatch(SALOME_SalomeException);
4775 return _preMeshInfo->NbHexas();
4777 return _impl->NbHexas();
4780 SMESH::smIdType SMESH_Mesh_i::NbTriQuadraticHexas()
4782 Unexpect aCatch(SALOME_SalomeException);
4784 return _preMeshInfo->NbTriQuadHexas();
4786 return _impl->NbTriQuadraticHexas();
4789 SMESH::smIdType SMESH_Mesh_i::NbPyramids()
4791 Unexpect aCatch(SALOME_SalomeException);
4793 return _preMeshInfo->NbPyramids();
4795 return _impl->NbPyramids();
4798 SMESH::smIdType SMESH_Mesh_i::NbPrisms()
4800 Unexpect aCatch(SALOME_SalomeException);
4802 return _preMeshInfo->NbPrisms();
4804 return _impl->NbPrisms();
4807 SMESH::smIdType SMESH_Mesh_i::NbHexagonalPrisms()
4809 Unexpect aCatch(SALOME_SalomeException);
4811 return _preMeshInfo->NbHexPrisms();
4813 return _impl->NbHexagonalPrisms();
4816 SMESH::smIdType SMESH_Mesh_i::NbPolyhedrons()
4818 Unexpect aCatch(SALOME_SalomeException);
4820 return _preMeshInfo->NbPolyhedrons();
4822 return _impl->NbPolyhedrons();
4825 SMESH::smIdType SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
4827 Unexpect aCatch(SALOME_SalomeException);
4829 return _preMeshInfo->NbVolumes( (SMDSAbs_ElementOrder) order );
4831 return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
4834 SMESH::smIdType SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
4836 Unexpect aCatch(SALOME_SalomeException);
4838 return _preMeshInfo->NbTetras( (SMDSAbs_ElementOrder) order);
4840 return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
4843 SMESH::smIdType SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
4845 Unexpect aCatch(SALOME_SalomeException);
4847 return _preMeshInfo->NbHexas( (SMDSAbs_ElementOrder) order);
4849 return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
4852 SMESH::smIdType SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
4854 Unexpect aCatch(SALOME_SalomeException);
4856 return _preMeshInfo->NbPyramids( (SMDSAbs_ElementOrder) order);
4858 return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
4861 SMESH::smIdType SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
4863 Unexpect aCatch(SALOME_SalomeException);
4865 return _preMeshInfo->NbPrisms( (SMDSAbs_ElementOrder) order);
4867 return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
4870 //=============================================================================
4872 * Return nb of published sub-meshes
4874 //=============================================================================
4876 SMESH::smIdType SMESH_Mesh_i::NbSubMesh()
4878 Unexpect aCatch(SALOME_SalomeException);
4879 return _mapSubMesh_i.size();
4882 //=============================================================================
4884 * Dumps mesh into a string
4886 //=============================================================================
4888 char* SMESH_Mesh_i::Dump()
4892 return CORBA::string_dup( os.str().c_str() );
4895 //=============================================================================
4897 * Method of SMESH_IDSource interface
4899 //=============================================================================
4901 SMESH::smIdType_array* SMESH_Mesh_i::GetIDs()
4903 return GetElementsId();
4906 //=============================================================================
4908 * Return ids of all elements
4910 //=============================================================================
4912 SMESH::smIdType_array* SMESH_Mesh_i::GetElementsId()
4914 Unexpect aCatch(SALOME_SalomeException);
4916 _preMeshInfo->FullLoadFromFile();
4918 SMESH::smIdType_array_var aResult = new SMESH::smIdType_array();
4919 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
4921 if ( aSMESHDS_Mesh == NULL )
4922 return aResult._retn();
4924 smIdType nbElements = NbElements();
4925 aResult->length( nbElements );
4926 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
4927 for ( smIdType i = 0, n = nbElements; i < n && anIt->more(); i++ )
4928 aResult[i] = anIt->next()->GetID();
4930 return aResult._retn();
4934 //=============================================================================
4936 * Return ids of all elements of given type
4938 //=============================================================================
4940 SMESH::smIdType_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
4942 Unexpect aCatch(SALOME_SalomeException);
4944 _preMeshInfo->FullLoadFromFile();
4946 SMESH::smIdType_array_var aResult = new SMESH::smIdType_array();
4947 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
4949 if ( aSMESHDS_Mesh == NULL )
4950 return aResult._retn();
4952 smIdType nbElements = NbElements();
4954 // No sense in returning ids of elements along with ids of nodes:
4955 // when theElemType == SMESH::ALL, return node ids only if
4956 // there are no elements
4957 if ( theElemType == SMESH::NODE || (theElemType == SMESH::ALL && nbElements == 0) )
4958 return GetNodesId();
4960 aResult->length( nbElements );
4964 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator( (SMDSAbs_ElementType)theElemType );
4965 while ( i < nbElements && anIt->more() )
4966 aResult[i++] = anIt->next()->GetID();
4968 aResult->length( i );
4970 return aResult._retn();
4973 //=============================================================================
4975 * Return ids of all nodes
4977 //=============================================================================
4979 SMESH::smIdType_array* SMESH_Mesh_i::GetNodesId()
4981 Unexpect aCatch(SALOME_SalomeException);
4983 _preMeshInfo->FullLoadFromFile();
4985 SMESH::smIdType_array_var aResult = new SMESH::smIdType_array();
4986 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
4988 if ( aMeshDS == NULL )
4989 return aResult._retn();
4991 smIdType nbNodes = NbNodes();
4992 aResult->length( nbNodes );
4993 SMDS_NodeIteratorPtr anIt = aMeshDS->nodesIterator();
4994 for ( smIdType i = 0, n = nbNodes; i < n && anIt->more(); i++ )
4995 aResult[i] = anIt->next()->GetID();
4997 return aResult._retn();
5000 //=============================================================================
5002 * Return type of the given element
5004 //=============================================================================
5006 SMESH::ElementType SMESH_Mesh_i::GetElementType( const SMESH::smIdType id, const bool iselem )
5008 SMESH::ElementType type = SMESH::ALL;
5012 _preMeshInfo->FullLoadFromFile();
5014 type = ( SMESH::ElementType ) _impl->GetElementType( id, iselem );
5016 SMESH_CATCH( SMESH::throwCorbaException );
5021 //=============================================================================
5023 * Return geometric type of the given element
5025 //=============================================================================
5027 SMESH::EntityType SMESH_Mesh_i::GetElementGeomType( const SMESH::smIdType id )
5030 _preMeshInfo->FullLoadFromFile();
5032 const SMDS_MeshElement* e = _impl->GetMeshDS()->FindElement(id);
5034 THROW_SALOME_CORBA_EXCEPTION( "invalid element id", SALOME::BAD_PARAM );
5036 return ( SMESH::EntityType ) e->GetEntityType();
5039 //=============================================================================
5041 * Return type of the given element
5043 //=============================================================================
5045 SMESH::GeometryType SMESH_Mesh_i::GetElementShape( const SMESH::smIdType id )
5048 _preMeshInfo->FullLoadFromFile();
5050 const SMDS_MeshElement* e = _impl->GetMeshDS()->FindElement(id);
5052 THROW_SALOME_CORBA_EXCEPTION( "invalid element id", SALOME::BAD_PARAM );
5054 return ( SMESH::GeometryType ) e->GetGeomType();
5057 //=============================================================================
5059 * Return ID of elements for given submesh
5061 //=============================================================================
5063 SMESH::smIdType_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
5065 SMESH::smIdType_array_var aResult = new SMESH::smIdType_array();
5069 _preMeshInfo->FullLoadFromFile();
5071 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
5072 if(!SM) return aResult._retn();
5074 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
5075 if(!SDSM) return aResult._retn();
5077 aResult->length(SDSM->NbElements());
5079 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
5081 while ( eIt->more() ) {
5082 aResult[i++] = eIt->next()->GetID();
5085 SMESH_CATCH( SMESH::throwCorbaException );
5087 return aResult._retn();
5090 //=============================================================================
5092 * Return ID of nodes for given sub-mesh
5093 * If param all==true - return all nodes, else -
5094 * Return only nodes on shapes.
5096 //=============================================================================
5098 SMESH::smIdType_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID,
5101 SMESH::smIdType_array_var aResult = new SMESH::smIdType_array();
5105 _preMeshInfo->FullLoadFromFile();
5107 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
5108 if(!SM) return aResult._retn();
5110 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
5111 if(!SDSM) return aResult._retn();
5113 set<smIdType> theElems;
5114 if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
5115 SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
5116 while ( nIt->more() ) {
5117 const SMDS_MeshNode* elem = nIt->next();
5118 theElems.insert( elem->GetID() );
5121 else { // all nodes of submesh elements
5122 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
5123 while ( eIt->more() ) {
5124 const SMDS_MeshElement* anElem = eIt->next();
5125 SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
5126 while ( nIt->more() ) {
5127 const SMDS_MeshElement* elem = nIt->next();
5128 theElems.insert( elem->GetID() );
5133 aResult->length(theElems.size());
5134 set<smIdType>::iterator itElem;
5136 for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
5137 aResult[i++] = *itElem;
5139 SMESH_CATCH( SMESH::throwCorbaException );
5141 return aResult._retn();
5144 //=============================================================================
5146 * Return type of elements for given sub-mesh
5148 //=============================================================================
5150 SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
5152 SMESH::ElementType type = SMESH::ALL;
5156 _preMeshInfo->FullLoadFromFile();
5158 SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
5159 if(!SM) return SMESH::ALL;
5161 SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
5162 if(!SDSM) return SMESH::ALL;
5164 if(SDSM->NbElements()==0)
5165 return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
5167 SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
5168 const SMDS_MeshElement* anElem = eIt->next();
5170 type = ( SMESH::ElementType ) anElem->GetType();
5172 SMESH_CATCH( SMESH::throwCorbaException );
5178 //=============================================================================
5180 * Return pointer to _impl as an integer value. Is called from constructor of SMESH_Client
5182 //=============================================================================
5184 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
5187 _preMeshInfo->FullLoadFromFile();
5189 CORBA::LongLong pointeur = CORBA::LongLong(_impl);
5190 if ( MYDEBUG ) MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
5195 //=============================================================================
5197 * Get XYZ coordinates of node as list of double
5198 * If there is not node for given ID - return empty list
5200 //=============================================================================
5202 SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const SMESH::smIdType id)
5205 _preMeshInfo->FullLoadFromFile();
5207 SMESH::double_array_var aResult = new SMESH::double_array();
5208 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5209 if ( aMeshDS == NULL )
5210 return aResult._retn();
5213 const SMDS_MeshNode* aNode = aMeshDS->FindNode(id);
5215 return aResult._retn();
5219 aResult[0] = aNode->X();
5220 aResult[1] = aNode->Y();
5221 aResult[2] = aNode->Z();
5222 return aResult._retn();
5226 //=============================================================================
5228 * For given node return list of IDs of inverse elements
5229 * If there is not node for given ID - return empty list
5231 //=============================================================================
5233 SMESH::smIdType_array* SMESH_Mesh_i::GetNodeInverseElements(const SMESH::smIdType id,
5234 SMESH::ElementType elemType)
5237 _preMeshInfo->FullLoadFromFile();
5239 SMESH::smIdType_array_var aResult = new SMESH::smIdType_array();
5240 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5241 if ( aMeshDS == NULL )
5242 return aResult._retn();
5245 const SMDS_MeshNode* aNode = aMeshDS->FindNode( id );
5247 return aResult._retn();
5249 // find inverse elements
5250 SMDSAbs_ElementType type = SMDSAbs_ElementType( elemType );
5251 SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator( type );
5252 aResult->length( aNode->NbInverseElements( type ));
5253 for( smIdType i = 0; eIt->more(); ++i )
5255 const SMDS_MeshElement* elem = eIt->next();
5256 aResult[ i ] = elem->GetID();
5258 return aResult._retn();
5261 //=============================================================================
5263 * \brief Return position of a node on shape
5265 //=============================================================================
5267 SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(SMESH::smIdType NodeID)
5270 _preMeshInfo->FullLoadFromFile();
5272 SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
5273 aNodePosition->shapeID = 0;
5274 aNodePosition->shapeType = GEOM::SHAPE;
5276 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
5277 if ( !mesh ) return aNodePosition;
5279 if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
5281 if ( SMDS_PositionPtr pos = aNode->GetPosition() )
5283 aNodePosition->shapeID = aNode->getshapeId();
5284 switch ( pos->GetTypeOfPosition() ) {
5286 aNodePosition->shapeType = GEOM::EDGE;
5287 aNodePosition->params.length(1);
5288 aNodePosition->params[0] = SMDS_EdgePositionPtr( pos )->GetUParameter();
5290 case SMDS_TOP_FACE: {
5291 SMDS_FacePositionPtr fPos = pos;
5292 aNodePosition->shapeType = GEOM::FACE;
5293 aNodePosition->params.length(2);
5294 aNodePosition->params[0] = fPos->GetUParameter();
5295 aNodePosition->params[1] = fPos->GetVParameter();
5298 case SMDS_TOP_VERTEX:
5299 aNodePosition->shapeType = GEOM::VERTEX;
5301 case SMDS_TOP_3DSPACE:
5302 if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
5303 aNodePosition->shapeType = GEOM::SOLID;
5304 else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
5305 aNodePosition->shapeType = GEOM::SHELL;
5311 return aNodePosition;
5314 //=============================================================================
5316 * \brief Return position of an element on shape
5318 //=============================================================================
5320 SMESH::ElementPosition SMESH_Mesh_i::GetElementPosition(SMESH::smIdType ElemID)
5323 _preMeshInfo->FullLoadFromFile();
5325 SMESH::ElementPosition anElementPosition;
5326 anElementPosition.shapeID = 0;
5327 anElementPosition.shapeType = GEOM::SHAPE;
5329 SMESHDS_Mesh* mesh = _impl->GetMeshDS();
5330 if ( !mesh ) return anElementPosition;
5332 if ( const SMDS_MeshElement* anElem = mesh->FindElement( ElemID ) )
5334 anElementPosition.shapeID = anElem->getshapeId();
5335 const TopoDS_Shape& aSp = mesh->IndexToShape( anElem->getshapeId() );
5336 if ( !aSp.IsNull() ) {
5337 switch ( aSp.ShapeType() ) {
5339 anElementPosition.shapeType = GEOM::EDGE;
5342 anElementPosition.shapeType = GEOM::FACE;
5345 anElementPosition.shapeType = GEOM::VERTEX;
5348 anElementPosition.shapeType = GEOM::SOLID;
5351 anElementPosition.shapeType = GEOM::SHELL;
5357 return anElementPosition;
5360 //=============================================================================
5362 * If given element is node return IDs of shape from position
5363 * If there is not node for given ID - return -1
5365 //=============================================================================
5367 CORBA::Long SMESH_Mesh_i::GetShapeID(const SMESH::smIdType id)
5370 _preMeshInfo->FullLoadFromFile();
5372 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5373 if ( aMeshDS == NULL )
5377 const SMDS_MeshNode* aNode = aMeshDS->FindNode(id);
5379 return aNode->getshapeId();
5386 //=============================================================================
5388 * For given element return ID of result shape after
5389 * ::FindShape() from SMESH_MeshEditor
5390 * If there is not element for given ID - return -1
5392 //=============================================================================
5394 CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const SMESH::smIdType id)
5397 _preMeshInfo->FullLoadFromFile();
5399 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5400 if ( aMeshDS == NULL )
5403 // try to find element
5404 const SMDS_MeshElement* elem = aMeshDS->FindElement(id);
5408 ::SMESH_MeshEditor aMeshEditor(_impl);
5409 int index = aMeshEditor.FindShape( elem );
5417 //=============================================================================
5419 * Return number of nodes for given element
5420 * If there is not element for given ID - return -1
5422 //=============================================================================
5424 CORBA::Short SMESH_Mesh_i::GetElemNbNodes(const SMESH::smIdType id)
5427 _preMeshInfo->FullLoadFromFile();
5429 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5430 if ( aMeshDS == NULL ) return -1;
5431 // try to find element
5432 const SMDS_MeshElement* elem = aMeshDS->FindElement(id);
5433 if(!elem) return -1;
5434 return elem->NbNodes();
5438 //=============================================================================
5440 * Return ID of node by given index for given element
5441 * If there is not element for given ID - return -1
5442 * If there is not node for given index - return -2
5444 //=============================================================================
5446 SMESH::smIdType SMESH_Mesh_i::GetElemNode(const SMESH::smIdType id, const CORBA::Short index)
5449 _preMeshInfo->FullLoadFromFile();
5451 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5452 if ( aMeshDS == NULL ) return -1;
5453 const SMDS_MeshElement* elem = aMeshDS->FindElement(id);
5454 if(!elem) return -1;
5455 if( index>=elem->NbNodes() || index<0 ) return -1;
5456 return elem->GetNode(index)->GetID();
5459 //=============================================================================
5461 * Return IDs of nodes of given element
5463 //=============================================================================
5465 SMESH::smIdType_array* SMESH_Mesh_i::GetElemNodes(const SMESH::smIdType id)
5468 _preMeshInfo->FullLoadFromFile();
5470 SMESH::smIdType_array_var aResult = new SMESH::smIdType_array();
5471 if ( SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS() )
5473 if ( const SMDS_MeshElement* elem = aMeshDS->FindElement(id) )
5475 aResult->length( elem->NbNodes() );
5476 for ( CORBA::ULong i = 0; i < aResult->length(); ++i )
5477 if ( const SMDS_MeshNode* n = elem->GetNode( i ))
5478 aResult[ i ] = n->GetID();
5481 return aResult._retn();
5484 //=============================================================================
5486 * Return true if given node is medium node
5487 * in given quadratic element
5489 //=============================================================================
5491 CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const SMESH::smIdType ide, const SMESH::smIdType idn)
5494 _preMeshInfo->FullLoadFromFile();
5496 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5497 if ( aMeshDS == NULL ) return false;
5499 const SMDS_MeshNode* aNode = aMeshDS->FindNode(idn);
5500 if(!aNode) return false;
5501 // try to find element
5502 const SMDS_MeshElement* elem = aMeshDS->FindElement(ide);
5503 if(!elem) return false;
5505 return elem->IsMediumNode(aNode);
5509 //=============================================================================
5511 * Return true if given node is medium node
5512 * in one of quadratic elements
5514 //=============================================================================
5516 CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const SMESH::smIdType idn,
5517 SMESH::ElementType theElemType)
5520 _preMeshInfo->FullLoadFromFile();
5522 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5523 if ( aMeshDS == NULL ) return false;
5526 const SMDS_MeshNode* aNode = aMeshDS->FindNode(idn);
5527 if(!aNode) return false;
5529 SMESH_MesherHelper aHelper( *(_impl) );
5531 SMDSAbs_ElementType aType;
5532 if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
5533 else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
5534 else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
5535 else aType = SMDSAbs_All;
5537 return aHelper.IsMedium(aNode,aType);
5541 //=============================================================================
5543 * Return number of edges for given element
5545 //=============================================================================
5547 CORBA::Long SMESH_Mesh_i::ElemNbEdges(const SMESH::smIdType id)
5550 _preMeshInfo->FullLoadFromFile();
5552 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5553 if ( aMeshDS == NULL ) return -1;
5554 const SMDS_MeshElement* elem = aMeshDS->FindElement(id);
5555 if(!elem) return -1;
5556 return elem->NbEdges();
5560 //=============================================================================
5562 * Return number of faces for given element
5564 //=============================================================================
5566 CORBA::Long SMESH_Mesh_i::ElemNbFaces(const SMESH::smIdType id)
5569 _preMeshInfo->FullLoadFromFile();
5571 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5572 if ( aMeshDS == NULL ) return -1;
5573 const SMDS_MeshElement* elem = aMeshDS->FindElement(id);
5574 if(!elem) return -1;
5575 return elem->NbFaces();
5578 //================================================================================
5580 * \brief Return nodes of given face (counted from zero) for given element.
5582 //================================================================================
5584 SMESH::smIdType_array* SMESH_Mesh_i::GetElemFaceNodes(SMESH::smIdType elemId,
5585 CORBA::Short faceIndex)
5588 _preMeshInfo->FullLoadFromFile();
5590 SMESH::smIdType_array_var aResult = new SMESH::smIdType_array();
5591 if ( SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS() )
5593 if ( const SMDS_MeshElement* elem = aMeshDS->FindElement(elemId) )
5595 SMDS_VolumeTool vtool( elem, /*skipCentralNodes = */false );
5596 if ( faceIndex < vtool.NbFaces() )
5598 aResult->length( vtool.NbFaceNodes( faceIndex ));
5599 const SMDS_MeshNode** nn = vtool.GetFaceNodes( faceIndex );
5600 for ( CORBA::ULong i = 0; i < aResult->length(); ++i )
5601 aResult[ i ] = nn[ i ]->GetID();
5605 return aResult._retn();
5608 //================================================================================
5610 * \brief Return three components of normal of given mesh face.
5612 //================================================================================
5614 SMESH::double_array* SMESH_Mesh_i::GetFaceNormal(CORBA::Long elemId,
5615 CORBA::Boolean normalized)
5618 _preMeshInfo->FullLoadFromFile();
5620 SMESH::double_array_var aResult = new SMESH::double_array();
5622 if ( SMESHDS_Mesh* mesh = _impl->GetMeshDS() )
5625 if ( SMESH_MeshAlgos::FaceNormal( mesh->FindElement(elemId), normal, normalized ))
5627 aResult->length( 3 );
5628 aResult[ 0 ] = normal.X();
5629 aResult[ 1 ] = normal.Y();
5630 aResult[ 2 ] = normal.Z();
5633 return aResult._retn();
5636 //================================================================================
5638 * \brief Return an element based on all given nodes.
5640 //================================================================================
5642 SMESH::smIdType SMESH_Mesh_i::FindElementByNodes(const SMESH::smIdType_array& nodes)
5645 _preMeshInfo->FullLoadFromFile();
5647 CORBA::Long elemID(0);
5648 if ( SMESHDS_Mesh* mesh = _impl->GetMeshDS() )
5650 vector< const SMDS_MeshNode * > nn( nodes.length() );
5651 for ( CORBA::ULong i = 0; i < nodes.length(); ++i )
5652 if ( !( nn[i] = mesh->FindNode( nodes[i] )))
5655 const SMDS_MeshElement* elem = mesh->FindElement( nn, SMDSAbs_All, /*noMedium=*/false );
5656 if ( !elem && ( _impl->NbEdges ( ORDER_QUADRATIC ) ||
5657 _impl->NbFaces ( ORDER_QUADRATIC ) ||
5658 _impl->NbVolumes( ORDER_QUADRATIC )))
5659 elem = mesh->FindElement( nn, SMDSAbs_All, /*noMedium=*/true );
5661 if ( elem ) elemID = CORBA::Long( elem->GetID() );
5666 //================================================================================
5668 * \brief Return elements including all given nodes.
5670 //================================================================================
5672 SMESH::smIdType_array* SMESH_Mesh_i::GetElementsByNodes(const SMESH::smIdType_array& nodes,
5673 SMESH::ElementType elemType)
5676 _preMeshInfo->FullLoadFromFile();
5678 SMESH::smIdType_array_var result = new SMESH::smIdType_array();
5680 if ( SMESHDS_Mesh* mesh = _impl->GetMeshDS() )
5682 vector< const SMDS_MeshNode * > nn( nodes.length() );
5683 for ( CORBA::ULong i = 0; i < nodes.length(); ++i )
5684 nn[i] = mesh->FindNode( nodes[i] );
5686 std::vector<const SMDS_MeshElement *> elems;
5687 mesh->GetElementsByNodes( nn, elems, (SMDSAbs_ElementType) elemType );
5688 result->length( elems.size() );
5689 for ( size_t i = 0; i < elems.size(); ++i )
5690 result[i] = elems[i]->GetID();
5692 return result._retn();
5695 //=============================================================================
5697 * Return true if given element is polygon
5699 //=============================================================================
5701 CORBA::Boolean SMESH_Mesh_i::IsPoly(const SMESH::smIdType id)
5704 _preMeshInfo->FullLoadFromFile();
5706 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5707 if ( aMeshDS == NULL ) return false;
5708 const SMDS_MeshElement* elem = aMeshDS->FindElement(id);
5709 if(!elem) return false;
5710 return elem->IsPoly();
5714 //=============================================================================
5716 * Return true if given element is quadratic
5718 //=============================================================================
5720 CORBA::Boolean SMESH_Mesh_i::IsQuadratic(const SMESH::smIdType id)
5723 _preMeshInfo->FullLoadFromFile();
5725 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5726 if ( aMeshDS == NULL ) return false;
5727 const SMDS_MeshElement* elem = aMeshDS->FindElement(id);
5728 if(!elem) return false;
5729 return elem->IsQuadratic();
5732 //=============================================================================
5734 * Return diameter of ball discrete element or zero in case of an invalid \a id
5736 //=============================================================================
5738 CORBA::Double SMESH_Mesh_i::GetBallDiameter(SMESH::smIdType id)
5741 _preMeshInfo->FullLoadFromFile();
5743 if ( const SMDS_BallElement* ball =
5744 SMDS_Mesh::DownCast<SMDS_BallElement>( _impl->GetMeshDS()->FindElement( id )))
5745 return ball->GetDiameter();
5750 //=============================================================================
5752 * Return bary center for given element
5754 //=============================================================================
5756 SMESH::double_array* SMESH_Mesh_i::BaryCenter(const SMESH::smIdType id)
5759 _preMeshInfo->FullLoadFromFile();
5761 SMESH::double_array_var aResult = new SMESH::double_array();
5762 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
5763 if ( aMeshDS == NULL )
5764 return aResult._retn();
5766 const SMDS_MeshElement* elem = aMeshDS->FindElement(id);
5768 return aResult._retn();
5770 if(elem->GetType()==SMDSAbs_Volume) {
5771 SMDS_VolumeTool aTool;
5772 if(aTool.Set(elem)) {
5774 if (!aTool.GetBaryCenter( aResult[0], aResult[1], aResult[2]) )
5779 SMDS_ElemIteratorPtr anIt = elem->nodesIterator();
5781 double x=0., y=0., z=0.;
5782 for(; anIt->more(); ) {
5784 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(anIt->next());
5798 return aResult._retn();
5801 //================================================================================
5803 * \brief Create a group of elements preventing computation of a sub-shape
5805 //================================================================================
5807 SMESH::ListOfGroups*
5808 SMESH_Mesh_i::MakeGroupsOfBadInputElements( int theSubShapeID,
5809 const char* theGroupName )
5811 Unexpect aCatch(SALOME_SalomeException);
5813 if ( !theGroupName || strlen( theGroupName) == 0 )
5814 THROW_SALOME_CORBA_EXCEPTION( "empty group name",SALOME::BAD_PARAM );
5816 SMESH::ListOfGroups_var groups = new SMESH::ListOfGroups;
5817 ::SMESH_MeshEditor::ElemFeatures elemType;
5819 // submesh by subshape id
5820 if ( !_impl->HasShapeToMesh() ) theSubShapeID = 1;
5821 if ( SMESH_subMesh * sm = _impl->GetSubMeshContaining( theSubShapeID ))
5824 SMESH_ComputeErrorPtr error = sm->GetComputeError();
5825 if ( error && error->HasBadElems() )
5827 // sort bad elements by type
5828 vector< const SMDS_MeshElement* > elemsByType[ SMDSAbs_NbElementTypes ];
5829 const list<const SMDS_MeshElement*>& badElems =
5830 static_cast<SMESH_BadInputElements*>( error.get() )->myBadElements;
5831 list<const SMDS_MeshElement*>::const_iterator elemIt = badElems.begin();
5832 list<const SMDS_MeshElement*>::const_iterator elemEnd = badElems.end();
5833 for ( ; elemIt != elemEnd; ++elemIt )
5835 const SMDS_MeshElement* elem = *elemIt;
5836 if ( !elem ) continue;
5838 if ( elem->GetID() < 1 )
5840 // elem is a temporary element, make a real element
5841 vector< const SMDS_MeshNode* > nodes;
5842 SMDS_NodeIteratorPtr nIt = elem->nodeIterator();
5843 while ( nIt->more() && elem )
5845 nodes.push_back( nIt->next() );
5846 if ( nodes.back()->GetID() < 1 )
5847 elem = 0; // a temporary element on temporary nodes
5851 ::SMESH_MeshEditor editor( _impl );
5852 elem = editor.AddElement( nodes, elemType.Init( elem ));
5856 elemsByType[ elem->GetType() ].push_back( elem );
5859 // how many groups to create?
5861 for ( int i = 0; i < SMDSAbs_NbElementTypes; ++i )
5862 nbTypes += int( !elemsByType[ i ].empty() );
5863 groups->length( nbTypes );
5866 for ( int i = 0, iG = -1; i < SMDSAbs_NbElementTypes; ++i )
5868 vector< const SMDS_MeshElement* >& elems = elemsByType[ i ];
5869 if ( elems.empty() ) continue;
5871 groups[ ++iG ] = createGroup( SMESH::ElementType(i), theGroupName );
5872 if ( _gen_i->CanPublishInStudy( groups[ iG ] ))
5874 SMESH::SMESH_Mesh_var mesh = _this();
5875 SALOMEDS::SObject_wrap aSO =
5876 _gen_i->PublishGroup( mesh, groups[ iG ],
5877 GEOM::GEOM_Object::_nil(), theGroupName);
5879 SMESH_GroupBase_i* grp_i = SMESH::DownCast< SMESH_GroupBase_i* >( groups[ iG ]);
5880 if ( !grp_i ) continue;
5882 if ( SMESHDS_Group* grpDS = dynamic_cast< SMESHDS_Group* >( grp_i->GetGroupDS() ))
5883 for ( size_t iE = 0; iE < elems.size(); ++iE )
5884 grpDS->SMDSGroup().Add( elems[ iE ]);
5889 return groups._retn();
5892 //=============================================================================
5894 * Create and publish group servants if any groups were imported or created anyhow
5896 //=============================================================================
5898 void SMESH_Mesh_i::CreateGroupServants()
5900 SMESH::SMESH_Mesh_var aMesh = _this();
5903 ::SMESH_Mesh::GroupIteratorPtr groupIt = _impl->GetGroups();
5904 while ( groupIt->more() )
5906 ::SMESH_Group* group = groupIt->next();
5907 int anId = group->GetID();
5909 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(anId);
5910 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
5912 addedIDs.insert( anId );
5914 SMESH_GroupBase_i* aGroupImpl;
5916 if ( SMESHDS_GroupOnGeom* groupOnGeom =
5917 dynamic_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() ))
5919 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
5920 shape = groupOnGeom->GetShape();
5923 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
5926 SMESH::SMESH_GroupBase_var groupVar = aGroupImpl->_this();
5927 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( groupVar );
5928 aGroupImpl->Register();
5930 // register CORBA object for persistence
5931 int nextId = _gen_i->RegisterObject( groupVar );
5932 if(MYDEBUG) { MESSAGE( "Add group to map with id = "<< nextId); }
5933 else { (void)nextId; } // avoid "unused variable" warning in release mode
5935 // publishing the groups in the study
5936 GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
5937 _gen_i->PublishGroup( aMesh, groupVar, shapeVar, group->GetName());
5940 if ( !addedIDs.empty() )
5943 map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_grp = _mapGroups.begin();
5944 for ( int index = 0; i_grp != _mapGroups.end(); ++index, ++i_grp )
5946 set<int>::iterator it = addedIDs.find( i_grp->first );
5947 if ( it != addedIDs.end() )
5949 TPythonDump() << i_grp->second << " = " << aMesh << ".GetGroups()[ "<< index << " ]";
5950 addedIDs.erase( it );
5951 if ( addedIDs.empty() )
5958 //=============================================================================
5960 * \brief Return true if all sub-meshes are computed OK - to update an icon
5962 //=============================================================================
5964 bool SMESH_Mesh_i::IsComputedOK()
5966 return _impl->IsComputedOK();
5969 //=============================================================================
5971 * \brief Return groups cantained in _mapGroups by their IDs
5973 //=============================================================================
5975 SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
5977 int nbGroups = groupIDs.size();
5978 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
5979 aList->length( nbGroups );
5981 list<int>::const_iterator ids = groupIDs.begin();
5982 for ( nbGroups = 0; ids != groupIDs.end(); ++ids )
5984 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = _mapGroups.find( *ids );
5985 if ( it != _mapGroups.end() && !CORBA::is_nil( it->second ))
5986 aList[nbGroups++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
5988 aList->length( nbGroups );
5989 return aList._retn();
5992 //=============================================================================
5994 * \brief Return information about imported file
5996 //=============================================================================
5998 SMESH::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
6000 SMESH::MedFileInfo_var res( _medFileInfo );
6001 if ( !res.operator->() ) {
6002 res = new SMESH::MedFileInfo;
6004 res->fileSize = res->major = res->minor = res->release = -1;
6009 //=======================================================================
6010 //function : FileInfoToString
6011 //purpose : Persistence of file info
6012 //=======================================================================
6014 std::string SMESH_Mesh_i::FileInfoToString()
6017 if ( &_medFileInfo.in() && _medFileInfo->fileName[0] )
6019 s = SMESH_Comment( _medFileInfo->fileSize )
6020 << " " << _medFileInfo->major
6021 << " " << _medFileInfo->minor
6022 << " " << _medFileInfo->release
6023 << " " << _medFileInfo->fileName;
6028 //=======================================================================
6029 //function : FileInfoFromString
6030 //purpose : Persistence of file info
6031 //=======================================================================
6033 void SMESH_Mesh_i::FileInfoFromString(const std::string& info)
6035 std::string size, major, minor, release, fileName;
6036 std::istringstream is(info);
6037 is >> size >> major >> minor >> release;
6038 fileName = info.data() + ( size.size() + 1 +
6041 release.size()+ 1 );
6043 _medFileInfo = new SMESH::MedFileInfo();
6044 _medFileInfo->fileName = fileName.c_str();
6045 _medFileInfo->fileSize = atoi( size.c_str() );
6046 _medFileInfo->major = atoi( major.c_str() );
6047 _medFileInfo->minor = atoi( minor.c_str() );
6048 _medFileInfo->release = atoi( release.c_str() );
6051 //=============================================================================
6053 * \brief Pass names of mesh groups from study to mesh DS
6055 //=============================================================================
6057 void SMESH_Mesh_i::checkGroupNames()
6059 int nbGrp = NbGroups();
6063 SMESH::ListOfGroups* grpList = 0;
6064 // avoid dump of "GetGroups"
6066 // store python dump into a local variable inside local scope
6067 SMESH::TPythonDump pDump; // do not delete this line of code
6068 grpList = GetGroups();
6071 for ( int gIndx = 0; gIndx < nbGrp; gIndx++ ) {
6072 SMESH::SMESH_GroupBase_ptr aGrp = (*grpList)[ gIndx ];
6075 SALOMEDS::SObject_wrap aGrpSO = _gen_i->ObjectToSObject( aGrp );
6076 if ( aGrpSO->_is_nil() )
6078 // correct name of the mesh group if necessary
6079 const char* guiName = aGrpSO->GetName();
6080 if ( strcmp(guiName, aGrp->GetName()) )
6081 aGrp->SetName( guiName );
6085 //=============================================================================
6087 * \brief Set list of notebook variables used for Mesh operations separated by ":" symbol
6089 //=============================================================================
6090 void SMESH_Mesh_i::SetParameters(const char* theParameters)
6092 SMESH_Gen_i::GetSMESHGen()->UpdateParameters( CORBA::Object_var( _this() ).in(),
6096 //=============================================================================
6098 * \brief Return list of notebook variables used for Mesh operations separated by ":" symbol
6100 //=============================================================================
6102 char* SMESH_Mesh_i::GetParameters()
6104 return SMESH_Gen_i::GetSMESHGen()->GetParameters( SMESH::SMESH_Mesh_var( _this()) );
6107 //=============================================================================
6109 * \brief Return list of notebook variables used for last Mesh operation
6111 //=============================================================================
6112 SMESH::string_array* SMESH_Mesh_i::GetLastParameters()
6114 SMESH::string_array_var aResult = new SMESH::string_array();
6115 SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
6117 CORBA::String_var aParameters = GetParameters();
6118 SALOMEDS::ListOfListOfStrings_var aSections = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->ParseVariables(aParameters);
6119 if ( aSections->length() > 0 ) {
6120 SALOMEDS::ListOfStrings aVars = aSections[ aSections->length() - 1 ];
6121 aResult->length( aVars.length() );
6122 for ( CORBA::ULong i = 0;i < aVars.length(); i++ )
6123 aResult[i] = CORBA::string_dup( aVars[i] );
6126 return aResult._retn();
6129 //================================================================================
6131 * \brief Return types of elements it contains
6133 //================================================================================
6135 SMESH::array_of_ElementType* SMESH_Mesh_i::GetTypes()
6138 return _preMeshInfo->GetTypes();
6140 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
6144 if (_impl->NbEdges()) types[nbTypes++] = SMESH::EDGE;
6145 if (_impl->NbFaces()) types[nbTypes++] = SMESH::FACE;
6146 if (_impl->NbVolumes()) types[nbTypes++] = SMESH::VOLUME;
6147 if (_impl->Nb0DElements()) types[nbTypes++] = SMESH::ELEM0D;
6148 if (_impl->NbBalls()) types[nbTypes++] = SMESH::BALL;
6149 if (_impl->NbNodes() &&
6150 nbTypes == 0 ) types[nbTypes++] = SMESH::NODE;
6151 types->length( nbTypes );
6153 return types._retn();
6156 //================================================================================
6158 * \brief Return self
6160 //================================================================================
6162 SMESH::SMESH_Mesh_ptr SMESH_Mesh_i::GetMesh()
6164 return SMESH::SMESH_Mesh::_duplicate( _this() );
6167 //================================================================================
6169 * \brief Return false if GetMeshInfo() return incorrect information that may
6170 * happen if mesh data is not yet fully loaded from the file of study.
6174 //================================================================================
6176 bool SMESH_Mesh_i::IsMeshInfoCorrect()
6178 return _preMeshInfo ? _preMeshInfo->IsMeshInfoCorrect() : true;
6181 //=============================================================================
6183 * \brief Return number of mesh elements per each \a EntityType
6185 //=============================================================================
6187 SMESH::smIdType_array* SMESH_Mesh_i::GetMeshInfo()
6190 return _preMeshInfo->GetMeshInfo();
6192 SMESH::smIdType_array_var aRes = new SMESH::smIdType_array();
6193 aRes->length(SMESH::Entity_Last);
6194 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
6196 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
6198 return aRes._retn();
6199 const SMDS_MeshInfo& aMeshInfo = aMeshDS->GetMeshInfo();
6200 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
6201 aRes[i] = aMeshInfo.NbEntities((SMDSAbs_EntityType)i);
6202 return aRes._retn();
6205 //=============================================================================
6207 * \brief Return number of mesh elements per each \a ElementType
6209 //=============================================================================
6211 SMESH::smIdType_array* SMESH_Mesh_i::GetNbElementsByType()
6213 SMESH::smIdType_array_var aRes = new SMESH::smIdType_array();
6214 aRes->length(SMESH::NB_ELEMENT_TYPES);
6215 for (smIdType i = 0; i < SMESH::NB_ELEMENT_TYPES; i++)
6218 const SMDS_MeshInfo* meshInfo = 0;
6220 meshInfo = _preMeshInfo;
6221 else if ( SMESHDS_Mesh* meshDS = _impl->GetMeshDS() )
6222 meshInfo = & meshDS->GetMeshInfo();
6225 for (smIdType i = 0; i < SMESH::NB_ELEMENT_TYPES; i++)
6226 aRes[i] = meshInfo->NbElements((SMDSAbs_ElementType)i);
6228 return aRes._retn();
6231 //=============================================================================
6233 * Collect statistic of mesh elements given by iterator
6235 //=============================================================================
6237 void SMESH_Mesh_i::CollectMeshInfo(const SMDS_ElemIteratorPtr theItr,
6238 SMESH::smIdType_array& theInfo)
6240 if (!theItr) return;
6241 while (theItr->more())
6242 theInfo[ theItr->next()->GetEntityType() ]++;
6244 //=============================================================================
6246 * Return mesh unstructed grid information.
6248 //=============================================================================
6250 SALOMEDS::TMPFile* SMESH_Mesh_i::GetVtkUgStream()
6252 SALOMEDS::TMPFile_var SeqFile;
6253 if ( SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS() ) {
6254 SMDS_UnstructuredGrid* aGrid = aMeshDS->GetGrid();
6256 vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
6257 aWriter->WriteToOutputStringOn();
6258 aWriter->SetInputData(aGrid);
6259 aWriter->SetFileTypeToBinary();
6261 char* str = aWriter->GetOutputString();
6262 int size = aWriter->GetOutputStringLength();
6264 //Allocate octet buffer of required size
6265 CORBA::Octet* OctetBuf = SALOMEDS::TMPFile::allocbuf(size);
6266 //Copy ostrstream content to the octet buffer
6267 memcpy(OctetBuf, str, size);
6268 //Create and return TMPFile
6269 SeqFile = new SALOMEDS::TMPFile(size, size, OctetBuf, 1);
6273 return SeqFile._retn();
6276 //=============================================================================
6277 namespace /* Iterators used in SMESH_Mesh_i::GetElements(SMESH::SMESH_IDSource_var obj,
6278 * SMESH::ElementType type) */
6280 using namespace SMESH::Controls;
6281 //-----------------------------------------------------------------------------
6282 struct PredicateIterator : public SMDS_ElemIterator
6284 SMDS_ElemIteratorPtr _elemIter;
6285 PredicatePtr _predicate;
6286 const SMDS_MeshElement* _elem;
6287 SMDSAbs_ElementType _type;
6289 PredicateIterator( SMDS_ElemIteratorPtr iterator,
6290 PredicatePtr predicate,
6291 SMDSAbs_ElementType type):
6292 _elemIter(iterator), _predicate(predicate), _type(type)
6300 virtual const SMDS_MeshElement* next()
6302 const SMDS_MeshElement* res = _elem;
6304 while ( _elemIter->more() && !_elem )
6306 if ((_elem = _elemIter->next()) &&
6307 (( _type != SMDSAbs_All && _type != _elem->GetType() ) ||
6308 ( !_predicate->IsSatisfy( _elem->GetID() ))))
6315 //-----------------------------------------------------------------------------
6316 struct IDSourceIterator : public SMDS_ElemIterator
6318 const SMESH::smIdType* _idPtr;
6319 const SMESH::smIdType* _idEndPtr;
6320 SMESH::smIdType_array_var _idArray;
6321 const SMDS_Mesh* _mesh;
6322 const SMDSAbs_ElementType _type;
6323 const SMDS_MeshElement* _elem;
6325 IDSourceIterator( const SMDS_Mesh* mesh,
6326 const SMESH::smIdType* ids,
6327 const smIdType nbIds,
6328 SMDSAbs_ElementType type):
6329 _idPtr( ids ), _idEndPtr( ids + nbIds ), _mesh( mesh ), _type( type ), _elem( 0 )
6331 if ( _idPtr && nbIds && _mesh )
6334 IDSourceIterator( const SMDS_Mesh* mesh,
6335 SMESH::smIdType_array* idArray,
6336 SMDSAbs_ElementType type):
6337 _idPtr( 0 ), _idEndPtr( 0 ), _idArray( idArray), _mesh( mesh ), _type( type ), _elem( 0 )
6339 if ( idArray && _mesh )
6341 _idPtr = &_idArray[0];
6342 _idEndPtr = _idPtr + _idArray->length();
6350 virtual const SMDS_MeshElement* next()
6352 const SMDS_MeshElement* res = _elem;
6354 while ( _idPtr < _idEndPtr && !_elem )
6356 if ( _type == SMDSAbs_Node )
6358 _elem = _mesh->FindNode( *_idPtr++ );
6360 else if ((_elem = _mesh->FindElement( *_idPtr++ )) &&
6361 (_elem->GetType() != _type && _type != SMDSAbs_All ))
6369 //-----------------------------------------------------------------------------
6371 struct NodeOfElemIterator : public SMDS_ElemIterator
6373 TColStd_MapOfInteger _checkedNodeIDs;
6374 SMDS_ElemIteratorPtr _elemIter;
6375 SMDS_ElemIteratorPtr _nodeIter;
6376 const SMDS_MeshElement* _node;
6378 NodeOfElemIterator( SMDS_ElemIteratorPtr iter ): _elemIter( iter ), _node( 0 )
6380 if ( _elemIter && _elemIter->more() )
6382 _nodeIter = _elemIter->next()->nodesIterator();
6390 virtual const SMDS_MeshElement* next()
6392 const SMDS_MeshElement* res = _node;
6394 while ( !_node && ( _elemIter->more() || _nodeIter->more() ))
6396 if ( _nodeIter->more() )
6398 _node = _nodeIter->next();
6399 if ( !_checkedNodeIDs.Add( _node->GetID() ))
6404 _nodeIter = _elemIter->next()->nodesIterator();
6412 //=============================================================================
6414 * Return iterator on elements of given type in given object
6416 //=============================================================================
6418 SMDS_ElemIteratorPtr SMESH_Mesh_i::GetElements(SMESH::SMESH_IDSource_ptr theObject,
6419 SMESH::ElementType theType)
6421 SMDS_ElemIteratorPtr elemIt;
6422 bool typeOK = ( theType == SMESH::ALL );
6423 SMDSAbs_ElementType elemType = SMDSAbs_ElementType( theType );
6425 SMESH::SMESH_Mesh_var meshVar = theObject->GetMesh();
6426 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( meshVar );
6427 if ( !mesh_i ) return elemIt;
6428 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
6430 if ( SMESH::DownCast<SMESH_Mesh_i*>( theObject ))
6432 elemIt = meshDS->elementsIterator( elemType );
6435 else if ( SMESH_subMesh_i* submesh_i = SMESH::DownCast<SMESH_subMesh_i*>( theObject ))
6437 SMESHDS_SubMesh* sm = ((SMESHDS_Mesh*) meshDS)->MeshElements( submesh_i->GetId() );
6440 elemIt = sm->GetElements();
6441 if ( elemType != SMDSAbs_Node && elemType != SMDSAbs_All )
6443 typeOK = ( elemIt && elemIt->more() && elemIt->next()->GetType() == elemType );
6444 elemIt = typeOK ? sm->GetElements() : SMDS_ElemIteratorPtr();
6448 else if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( theObject ))
6450 SMESHDS_GroupBase* groupDS = group_i->GetGroupDS();
6451 if ( groupDS && ( elemType == groupDS->GetType() ||
6452 elemType == SMDSAbs_Node ||
6453 elemType == SMDSAbs_All ))
6455 elemIt = groupDS->GetElements();
6456 typeOK = ( groupDS->GetType() == elemType || elemType == SMDSAbs_All );
6459 else if ( SMESH::Filter_i* filter_i = SMESH::DownCast<SMESH::Filter_i*>( theObject ))
6461 if ( filter_i->GetElementType() == theType ||
6462 filter_i->GetElementType() == SMESH::ALL ||
6463 elemType == SMDSAbs_Node ||
6464 elemType == SMDSAbs_All)
6466 SMESH::Predicate_i* pred_i = filter_i->GetPredicate_i();
6467 if ( pred_i && pred_i->GetPredicate() )
6469 SMDSAbs_ElementType filterType = SMDSAbs_ElementType( filter_i->GetElementType() );
6470 SMDS_ElemIteratorPtr allElemIt = meshDS->elementsIterator( filterType );
6471 SMDSAbs_ElementType iterType = elemType == SMDSAbs_Node ? filterType : elemType;
6472 elemIt = SMDS_ElemIteratorPtr
6473 ( new PredicateIterator( allElemIt, pred_i->GetPredicate(), iterType ));
6474 typeOK = ( elemType == SMDSAbs_Node ? filterType == SMDSAbs_Node : elemIt->more() );
6480 SMESH::array_of_ElementType_var types = theObject->GetTypes();
6481 const bool isNodes = ( types->length() == 1 && types[0] == SMESH::NODE );
6482 if ( isNodes && elemType != SMDSAbs_Node && elemType != SMDSAbs_All )
6484 SMDSAbs_ElementType iterType = isNodes ? SMDSAbs_Node : elemType;
6485 if ( SMESH_MeshEditor_i::IsTemporaryIDSource( theObject ))
6487 SMESH::smIdType nbIds;
6488 if ( SMESH::smIdType* ids = SMESH_MeshEditor_i::GetTemporaryIDs( theObject, nbIds ))
6489 elemIt = SMDS_ElemIteratorPtr( new IDSourceIterator( meshDS, ids, nbIds, iterType ));
6493 SMESH::smIdType_array_var ids = theObject->GetIDs();
6494 elemIt = SMDS_ElemIteratorPtr( new IDSourceIterator( meshDS, ids._retn(), iterType ));
6496 typeOK = ( isNodes == ( elemType == SMDSAbs_Node )) || ( elemType == SMDSAbs_All );
6499 if ( elemIt && elemIt->more() && !typeOK )
6501 if ( elemType == SMDSAbs_Node )
6503 elemIt = SMDS_ElemIteratorPtr( new NodeOfElemIterator( elemIt ));
6507 elemIt = SMDS_ElemIteratorPtr();
6513 //=============================================================================
6514 namespace // Finding concurrent hypotheses
6515 //=============================================================================
6519 * \brief mapping of mesh dimension into shape type
6521 TopAbs_ShapeEnum shapeTypeByDim(const int theDim)
6523 TopAbs_ShapeEnum aType = TopAbs_SOLID;
6525 case 0: aType = TopAbs_VERTEX; break;
6526 case 1: aType = TopAbs_EDGE; break;
6527 case 2: aType = TopAbs_FACE; break;
6529 default:aType = TopAbs_SOLID; break;
6534 //-----------------------------------------------------------------------------
6536 * \brief Internal structure used to find concurrent submeshes
6538 * It represents a pair < submesh, concurrent dimension >, where
6539 * 'concurrent dimension' is dimension of shape where the submesh can concurrent
6540 * with another submesh. In other words, it is dimension of a hypothesis assigned
6547 int _dim; //!< a dimension the algo can build (concurrent dimension)
6548 int _ownDim; //!< dimension of shape of _subMesh (>=_dim)
6549 TopTools_MapOfShape _shapeMap; //!< [sub-]shapes of dimension == _dim
6550 const SMESH_subMesh* _subMesh;
6551 list<const SMESHDS_Hypothesis*> _hypotheses; //!< algo is first, then its parameters
6553 //-----------------------------------------------------------------------------
6554 // Return the algorithm
6555 const SMESH_Algo* GetAlgo() const
6556 { return _hypotheses.empty() ? 0 : dynamic_cast<const SMESH_Algo*>( _hypotheses.front() ); }
6558 //-----------------------------------------------------------------------------
6560 SMESH_DimHyp(const SMESH_subMesh* theSubMesh,
6562 const TopoDS_Shape& theShape)
6564 _subMesh = theSubMesh;
6565 SetShape( theDim, theShape );
6568 //-----------------------------------------------------------------------------
6570 void SetShape(const int theDim,
6571 const TopoDS_Shape& theShape)
6574 _ownDim = SMESH_Gen::GetShapeDim(theShape);
6575 if (_dim >= _ownDim)
6576 _shapeMap.Add( theShape );
6578 TopExp_Explorer anExp( theShape, shapeTypeByDim(theDim) );
6579 for( ; anExp.More(); anExp.Next() )
6580 _shapeMap.Add( anExp.Current() );
6584 //-----------------------------------------------------------------------------
6585 //! Check sharing of sub-shapes
6586 static bool isShareSubShapes(const TopTools_MapOfShape& theToCheck,
6587 const TopTools_MapOfShape& theToFind,
6588 const TopAbs_ShapeEnum theType)
6590 bool isShared = false;
6591 TopTools_MapIteratorOfMapOfShape anItr( theToCheck );
6592 for (; !isShared && anItr.More(); anItr.Next() )
6594 const TopoDS_Shape& aSubSh = anItr.Key();
6595 // check for case when concurrent dimensions are same
6596 isShared = theToFind.Contains( aSubSh );
6597 // check for sub-shape with concurrent dimension
6598 TopExp_Explorer anExp( aSubSh, theType );
6599 for ( ; !isShared && anExp.More(); anExp.Next() )
6600 isShared = theToFind.Contains( anExp.Current() );
6605 //-----------------------------------------------------------------------------
6606 //! check algorithms
6607 static bool checkAlgo(const SMESHDS_Hypothesis* theA1,
6608 const SMESHDS_Hypothesis* theA2)
6610 if ( !theA1 || !theA2 ||
6611 theA1->GetType() == SMESHDS_Hypothesis::PARAM_ALGO ||
6612 theA2->GetType() == SMESHDS_Hypothesis::PARAM_ALGO )
6613 return false; // one of the hypothesis is not algorithm
6614 // check algorithm names (should be equal)
6615 return strcmp( theA1->GetName(), theA2->GetName() ) == 0;
6619 //-----------------------------------------------------------------------------
6620 //! Check if sub-shape hypotheses are concurrent
6621 bool IsConcurrent(const SMESH_DimHyp* theOther) const
6623 if ( _subMesh == theOther->_subMesh )
6624 return false; // same sub-shape - should not be
6626 // if ( <own dim of either of submeshes> == <concurrent dim> &&
6627 // any of the two submeshes is not on COMPOUND shape )
6628 // -> no concurrency
6629 bool meIsCompound = (_subMesh->GetSubMeshDS() &&
6630 _subMesh->GetSubMeshDS()->IsComplexSubmesh());
6631 bool otherIsCompound = (theOther->_subMesh->GetSubMeshDS() &&
6632 theOther->_subMesh->GetSubMeshDS()->IsComplexSubmesh());
6633 if ( (_ownDim == _dim || theOther->_ownDim == _dim ) && (!meIsCompound || !otherIsCompound))
6636 bool checkSubShape = isShareSubShapes( _shapeMap, theOther->_shapeMap, shapeTypeByDim(_dim));
6637 if ( !checkSubShape )
6640 // check algorithms to be same
6641 const SMESH_Algo* a1 = this->GetAlgo();
6642 const SMESH_Algo* a2 = theOther->GetAlgo();
6643 bool isSame = checkAlgo( a1, a2 );
6647 // commented off for IPAL54678
6648 // if ( !a1 || !a2 )
6649 // return false; // pb?
6650 // return a1->GetDim() == a2->GetDim(); // different algorithms of same dim -> concurrency !
6653 // check hypothesises for concurrence (skip first as algorithm)
6655 // pointers should be same, because it is referened from mesh hypothesis partition
6656 list <const SMESHDS_Hypothesis*>::const_iterator hypIt = _hypotheses.begin();
6657 list <const SMESHDS_Hypothesis*>::const_iterator otheEndIt = theOther->_hypotheses.end();
6658 for ( hypIt++ /*skip first as algo*/; hypIt != _hypotheses.end(); hypIt++ )
6659 if ( find( theOther->_hypotheses.begin(), otheEndIt, *hypIt ) != otheEndIt )
6661 // the submeshes are concurrent if their algorithms has different parameters
6662 return nbSame != theOther->_hypotheses.size() - 1;
6665 // Return true if algorithm of this SMESH_DimHyp is used if no
6666 // sub-mesh order is imposed by the user
6667 bool IsHigherPriorityThan( const SMESH_DimHyp* theOther ) const
6669 // NeedDiscreteBoundary() algo has a higher priority
6670 if ( this ->GetAlgo()->NeedDiscreteBoundary() !=
6671 theOther->GetAlgo()->NeedDiscreteBoundary() )
6672 return !this->GetAlgo()->NeedDiscreteBoundary();
6674 return ( this->_subMesh->GetId() < theOther->_subMesh->GetId() );
6677 }; // end of SMESH_DimHyp
6678 //-----------------------------------------------------------------------------
6680 typedef list<const SMESH_DimHyp*> TDimHypList;
6682 //-----------------------------------------------------------------------------
6684 void addDimHypInstance(const int theDim,
6685 const TopoDS_Shape& theShape,
6686 const SMESH_Algo* theAlgo,
6687 const SMESH_subMesh* theSubMesh,
6688 const list <const SMESHDS_Hypothesis*>& theHypList,
6689 TDimHypList* theDimHypListArr )
6691 if ( !theAlgo->NeedDiscreteBoundary() &&
6692 theAlgo->NeedLowerHyps( theDim )) // IPAL54678
6694 TDimHypList& listOfdimHyp = theDimHypListArr[theDim];
6695 if ( listOfdimHyp.empty() || listOfdimHyp.back()->_subMesh != theSubMesh )
6697 SMESH_DimHyp* dimHyp = new SMESH_DimHyp( theSubMesh, theDim, theShape );
6698 dimHyp->_hypotheses.push_front(theAlgo);
6699 listOfdimHyp.push_back( dimHyp );
6702 SMESH_DimHyp* dimHyp = const_cast<SMESH_DimHyp*>( listOfdimHyp.back() );
6703 dimHyp->_hypotheses.insert( dimHyp->_hypotheses.end(),
6704 theHypList.begin(), theHypList.end() );
6707 //-----------------------------------------------------------------------------
6708 void addInOrderOfPriority( const SMESH_DimHyp* theDimHyp,
6709 TDimHypList& theListOfConcurr)
6711 if ( theListOfConcurr.empty() )
6713 theListOfConcurr.push_back( theDimHyp );
6717 TDimHypList::iterator hypIt = theListOfConcurr.begin();
6718 while ( hypIt != theListOfConcurr.end() &&
6719 !theDimHyp->IsHigherPriorityThan( *hypIt ))
6721 theListOfConcurr.insert( hypIt, theDimHyp );
6725 //-----------------------------------------------------------------------------
6726 void findConcurrents(const SMESH_DimHyp* theDimHyp,
6727 const TDimHypList& theListOfDimHyp,
6728 TDimHypList& theListOfConcurrHyp,
6729 set<int>& theSetOfConcurrId )
6731 TDimHypList::const_reverse_iterator rIt = theListOfDimHyp.rbegin();
6732 for ( ; rIt != theListOfDimHyp.rend(); rIt++ )
6734 const SMESH_DimHyp* curDimHyp = *rIt;
6735 if ( curDimHyp == theDimHyp )
6736 break; // meet own dimHyp pointer in same dimension
6738 if ( theDimHyp->IsConcurrent( curDimHyp ) &&
6739 theSetOfConcurrId.insert( curDimHyp->_subMesh->GetId() ).second )
6741 addInOrderOfPriority( curDimHyp, theListOfConcurrHyp );
6746 //-----------------------------------------------------------------------------
6747 bool unionLists(TListOfInt& theListOfId,
6748 TListOfListOfInt& theListOfListOfId,
6751 bool changed = false;
6752 if ( theListOfId.empty() )
6754 TListOfListOfInt::iterator it = theListOfListOfId.begin();
6755 for ( int i = 0; it != theListOfListOfId.end(); it++, i++ )
6758 continue; //skip already treated lists
6759 // check if other list has any same submesh object
6760 TListOfInt& otherListOfId = *it;
6761 if ( find_first_of( theListOfId.begin(), theListOfId.end(),
6762 otherListOfId.begin(), otherListOfId.end() ) == theListOfId.end() )
6765 // union two lists (from source into target)
6766 TListOfInt::iterator it2 = otherListOfId.begin();
6767 for ( ; it2 != otherListOfId.end(); it2++ ) {
6768 if ( find( theListOfId.begin(), theListOfId.end(), (*it2) ) == theListOfId.end() )
6770 theListOfId.push_back(*it2);
6774 // clear source list
6775 otherListOfId.clear();
6779 //-----------------------------------------------------------------------------
6781 //! free memory allocated for dimension-hypothesis objects
6782 void removeDimHyps( TDimHypList* theArrOfList )
6784 for (int i = 0; i < 4; i++ ) {
6785 TDimHypList& listOfdimHyp = theArrOfList[i];
6786 TDimHypList::const_iterator it = listOfdimHyp.begin();
6787 for ( ; it != listOfdimHyp.end(); it++ )
6792 //-----------------------------------------------------------------------------
6794 * \brief find common submeshes with given submesh
6795 * \param theSubMeshList list of already collected submesh to check
6796 * \param theSubMesh given submesh to intersect with other
6797 * \param theCommonSubMeshes collected common submeshes
6799 void findCommonSubMesh (list<const SMESH_subMesh*>& theSubMeshList,
6800 const SMESH_subMesh* theSubMesh,
6801 set<const SMESH_subMesh*>& theCommon )
6805 list<const SMESH_subMesh*>::const_iterator it = theSubMeshList.begin();
6806 for ( ; it != theSubMeshList.end(); it++ )
6807 theSubMesh->FindIntersection( *it, theCommon );
6808 theSubMeshList.push_back( theSubMesh );
6809 //theCommon.insert( theSubMesh );
6812 //-----------------------------------------------------------------------------
6813 bool isSubMeshInList ( int smID, const TListOfListOfInt& smLists )
6815 TListOfListOfInt::const_iterator listsIt = smLists.begin();
6816 for ( ; listsIt != smLists.end(); ++listsIt )
6818 const TListOfInt& smIDs = *listsIt;
6819 if ( std::find( smIDs.begin(), smIDs.end(), smID ) != smIDs.end() )
6827 //=============================================================================
6829 * \brief Return \c true if a meshing order not yet set for a concurrent sub-mesh
6831 //=============================================================================
6833 CORBA::Boolean SMESH_Mesh_i::IsUnorderedSubMesh(CORBA::Long submeshID)
6835 TListOfListOfInt anOrder = GetImpl().GetMeshOrder(); // already defined order
6836 if ( isSubMeshInList( submeshID, anOrder ))
6839 TListOfListOfInt allConurrent = findConcurrentSubMeshes();
6840 return isSubMeshInList( submeshID, allConurrent );
6843 //=============================================================================
6845 * \brief Return sub-mesh objects list in meshing order
6847 //=============================================================================
6849 SMESH::submesh_array_array* SMESH_Mesh_i::GetMeshOrder()
6851 SMESH::submesh_array_array_var aResult = new SMESH::submesh_array_array();
6853 SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
6855 return aResult._retn();
6857 TListOfListOfInt anOrder = GetImpl().GetMeshOrder(); // already defined order
6858 TListOfListOfInt allConurrent = findConcurrentSubMeshes();
6859 anOrder.splice( anOrder.end(), allConurrent );
6864 TListOfListOfInt::iterator listIt = anOrder.begin();
6865 for ( int listIndx = 1; listIt != anOrder.end(); listIt++, listIndx++ )
6866 if ( unionLists( *listIt, anOrder, listIndx ))
6871 // convert submesh ids into interface instances
6872 // and dump command into python
6873 convertMeshOrder( anOrder, aResult, false );
6875 return aResult._retn();
6878 //=============================================================================
6880 * \brief Finds concurrent sub-meshes
6882 //=============================================================================
6884 TListOfListOfInt SMESH_Mesh_i::findConcurrentSubMeshes()
6886 TListOfListOfInt anOrder;
6887 ::SMESH_Mesh& mesh = GetImpl();
6889 // collect submeshes and detect concurrent algorithms and hypothesises
6890 TDimHypList dimHypListArr[4]; // dimHyp list for each shape dimension
6892 map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
6893 for ( ; i_sm != _mapSubMesh.end(); i_sm++ )
6895 ::SMESH_subMesh* sm = (*i_sm).second;
6897 const TopoDS_Shape& aSubMeshShape = sm->GetSubShape();
6899 // list of assigned hypothesises
6900 const list <const SMESHDS_Hypothesis*>& hypList = mesh.GetHypothesisList(aSubMeshShape);
6901 // Find out dimensions where the submesh can be concurrent.
6902 // We define the dimensions by algo of each of hypotheses in hypList
6903 list <const SMESHDS_Hypothesis*>::const_iterator hypIt = hypList.begin();
6904 for( ; hypIt != hypList.end(); hypIt++ )
6906 SMESH_Algo* anAlgo = 0;
6907 const SMESH_Hypothesis* hyp = dynamic_cast<const SMESH_Hypothesis*>(*hypIt);
6908 if ( hyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO )
6909 // hyp it-self is algo
6910 anAlgo = (SMESH_Algo*)dynamic_cast<const SMESH_Algo*>(hyp);
6912 // try to find algorithm with help of sub-shapes
6913 TopExp_Explorer anExp( aSubMeshShape, shapeTypeByDim(hyp->GetDim()) );
6914 for ( ; !anAlgo && anExp.More(); anExp.Next() )
6915 anAlgo = mesh.GetGen()->GetAlgo( mesh, anExp.Current() );
6918 continue; // no algorithm assigned to a current submesh
6920 int dim = anAlgo->GetDim(); // top concurrent dimension (see comment to SMESH_DimHyp)
6921 // the submesh can concurrent at <dim> (or lower dims if !anAlgo->NeedDiscreteBoundary()
6922 // and !anAlgo->NeedLowerHyps( dim ))
6924 // create instance of dimension-hypothesis for found concurrent dimension(s) and algorithm
6925 for ( int j = anAlgo->NeedDiscreteBoundary() ? dim : 1, jn = dim; j <= jn; j++ )
6926 addDimHypInstance( j, aSubMeshShape, anAlgo, sm, hypList, dimHypListArr );
6928 } // end iterations on submesh
6930 // iterate on created dimension-hypotheses and check for concurrents
6931 for ( int i = 0; i < 4; i++ )
6933 const TDimHypList& listOfDimHyp = dimHypListArr[i];
6934 // check for concurrents in own and other dimensions (step-by-step)
6935 TDimHypList::const_iterator dhIt = listOfDimHyp.begin();
6936 for ( ; dhIt != listOfDimHyp.end(); dhIt++ )
6938 const SMESH_DimHyp* dimHyp = *dhIt;
6939 TDimHypList listOfConcurr;
6940 set<int> setOfConcurrIds;
6941 // looking for concurrents and collect into own list
6942 for ( int j = i; j < 4; j++ )
6943 findConcurrents( dimHyp, dimHypListArr[j], listOfConcurr, setOfConcurrIds );
6944 // check if any concurrents found
6945 if ( listOfConcurr.size() > 0 )
6947 // add own submesh to list of concurrent
6948 addInOrderOfPriority( dimHyp, listOfConcurr );
6949 list<int> listOfConcurrIds;
6950 TDimHypList::iterator hypIt = listOfConcurr.begin();
6951 for ( ; hypIt != listOfConcurr.end(); ++hypIt )
6952 listOfConcurrIds.push_back( (*hypIt)->_subMesh->GetId() );
6953 anOrder.push_back( listOfConcurrIds );
6958 removeDimHyps(dimHypListArr);
6960 // now, minimize the number of concurrent groups
6961 // Here we assume that lists of submeshes can have same submesh
6962 // in case of multi-dimension algorithms, as result
6963 // list with common submesh has to be united into one list
6965 TListOfListOfInt::iterator listIt = anOrder.begin();
6966 for(; listIt != anOrder.end(); listIt++, listIndx++ )
6967 unionLists( *listIt, anOrder, listIndx + 1 );
6972 //=============================================================================
6974 * \brief Set submesh object order
6975 * \param theSubMeshArray submesh array order
6977 //=============================================================================
6979 ::CORBA::Boolean SMESH_Mesh_i::SetMeshOrder(const SMESH::submesh_array_array& theSubMeshArray)
6982 _preMeshInfo->ForgetOrLoad();
6985 ::SMESH_Mesh& mesh = GetImpl();
6987 TPythonDump aPythonDump; // prevent dump of called methods
6988 aPythonDump << "isDone = " << SMESH::SMESH_Mesh_var(_this()) << ".SetMeshOrder( [ ";
6990 TListOfListOfInt subMeshOrder;
6991 for ( int i = 0, n = theSubMeshArray.length(); i < n; i++ )
6993 const SMESH::submesh_array& aSMArray = theSubMeshArray[i];
6994 TListOfInt subMeshIds;
6996 aPythonDump << ", ";
6997 aPythonDump << "[ ";
6998 // Collect subMeshes which should be clear
6999 // do it list-by-list, because modification of submesh order
7000 // take effect between concurrent submeshes only
7001 set<const SMESH_subMesh*> subMeshToClear;
7002 list<const SMESH_subMesh*> subMeshList;
7003 for ( int j = 0, jn = aSMArray.length(); j < jn; j++ )
7005 const SMESH::SMESH_subMesh_var subMesh = SMESH::SMESH_subMesh::_duplicate(aSMArray[j]);
7007 aPythonDump << ", ";
7008 aPythonDump << subMesh;
7009 subMeshIds.push_back( subMesh->GetId() );
7010 // detect common parts of submeshes
7011 if ( _mapSubMesh.find(subMesh->GetId()) != _mapSubMesh.end() )
7012 findCommonSubMesh( subMeshList, _mapSubMesh[ subMesh->GetId() ], subMeshToClear );
7014 aPythonDump << " ]";
7015 subMeshOrder.push_back( subMeshIds );
7017 // clear collected sub-meshes
7018 set<const SMESH_subMesh*>::iterator clrIt = subMeshToClear.begin();
7019 for ( ; clrIt != subMeshToClear.end(); clrIt++ )
7020 if ( SMESH_subMesh* sm = (SMESH_subMesh*)*clrIt )
7022 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
7023 if ( SMESH_Algo* algo = sm->GetAlgo() ) // #16748
7024 sm->AlgoStateEngine( SMESH_subMesh::MODIF_HYP, algo ); // to clear a cached algo
7027 aPythonDump << " ])";
7029 mesh.SetMeshOrder( subMeshOrder );
7032 SMESH::SMESH_Mesh_var me = _this();
7033 _gen_i->UpdateIcons( me );
7038 //=============================================================================
7040 * \brief Convert submesh ids into submesh interfaces
7042 //=============================================================================
7044 void SMESH_Mesh_i::convertMeshOrder (const TListOfListOfInt& theIdsOrder,
7045 SMESH::submesh_array_array& theResOrder,
7046 const bool theIsDump)
7048 int nbSet = theIdsOrder.size();
7049 TPythonDump aPythonDump; // prevent dump of called methods
7051 aPythonDump << "[ ";
7052 theResOrder.length(nbSet);
7053 TListOfListOfInt::const_iterator it = theIdsOrder.begin();
7055 for( ; it != theIdsOrder.end(); it++ )
7057 // translate submesh identificators into submesh objects
7058 // takeing into account real number of concurrent lists
7059 const TListOfInt& aSubOrder = (*it);
7060 if (!aSubOrder.size())
7063 aPythonDump << "[ ";
7064 // convert shape indices into interfaces
7065 SMESH::submesh_array_var aResSubSet = new SMESH::submesh_array();
7066 aResSubSet->length(aSubOrder.size());
7067 TListOfInt::const_iterator subIt = aSubOrder.begin();
7069 for( j = 0; subIt != aSubOrder.end(); subIt++ )
7071 if ( _mapSubMeshIor.find(*subIt) == _mapSubMeshIor.end() )
7073 SMESH::SMESH_subMesh_var subMesh =
7074 SMESH::SMESH_subMesh::_duplicate( _mapSubMeshIor[*subIt] );
7077 aPythonDump << ", ";
7078 aPythonDump << subMesh;
7080 aResSubSet[ j++ ] = subMesh;
7083 aPythonDump << " ]";
7085 theResOrder[ listIndx++ ] = aResSubSet;
7087 // correct number of lists
7088 theResOrder.length( listIndx );
7091 // finilise python dump
7092 aPythonDump << " ]";
7093 aPythonDump << " = " << SMESH::SMESH_Mesh_var(_this()) << ".GetMeshOrder()";
7097 namespace // utils used by SMESH_MeshPartDS
7100 * \brief Class used to access to protected data of SMDS_MeshInfo
7102 struct TMeshInfo : public SMDS_MeshInfo
7104 void Add(const SMDS_MeshElement* e) { SMDS_MeshInfo::addWithPoly( e ); }
7107 * \brief Element holing its ID only
7109 struct TElemID : public SMDS_LinearEdge
7111 TElemID(int ID) : SMDS_LinearEdge(0,0) { setID( ID ); }
7115 //================================================================================
7117 // Implementation of SMESH_MeshPartDS
7119 SMESH_MeshPartDS::SMESH_MeshPartDS(SMESH::SMESH_IDSource_ptr meshPart):
7120 SMESHDS_Mesh( /*meshID=*/-1, /*isEmbeddedMode=*/true)
7122 SMESH::SMESH_Mesh_var mesh = meshPart->GetMesh();
7123 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
7126 _meshDS = mesh_i->GetImpl().GetMeshDS();
7128 SetPersistentId( _meshDS->GetPersistentId() );
7130 if ( mesh_i == SMESH::DownCast<SMESH_Mesh_i*>( meshPart ))
7132 // <meshPart> is the whole mesh
7133 myInfo = _meshDS->GetMeshInfo(); // copy mesh info;
7135 set<SMESHDS_GroupBase*>& myGroupSet = const_cast<set<SMESHDS_GroupBase*>&>( GetGroups() );
7136 myGroupSet = _meshDS->GetGroups();
7141 SMESH::smIdType_array_var anIDs = meshPart->GetIDs();
7142 SMESH::array_of_ElementType_var types = meshPart->GetTypes();
7143 if ( types->length() == 1 && types[0] == SMESH::NODE ) // group of nodes
7145 for ( CORBA::ULong i=0; i < anIDs->length(); i++ )
7146 if ( const SMDS_MeshNode * n = _meshDS->FindNode( anIDs[i] ))
7147 if ( _elements[ SMDSAbs_Node ].insert( n ).second )
7152 for ( CORBA::ULong i=0; i < anIDs->length(); i++ )
7153 if ( const SMDS_MeshElement * e = _meshDS->FindElement(anIDs[i]))
7154 if ( _elements[ e->GetType() ].insert( e ).second )
7157 SMDS_ElemIteratorPtr nIt = e->nodesIterator();
7158 while ( nIt->more() )
7160 const SMDS_MeshNode * n = (const SMDS_MeshNode*) nIt->next();
7161 if ( _elements[ SMDSAbs_Node ].insert( n ).second )
7168 ShapeToMesh( _meshDS->ShapeToMesh() );
7170 _meshDS = 0; // to enforce iteration on _elements and _nodes
7173 // -------------------------------------------------------------------------------------
7174 SMESH_MeshPartDS::SMESH_MeshPartDS(const std::list< const SMDS_MeshElement* > & meshPart):
7175 SMESHDS_Mesh( /*meshID=*/-1, /*isEmbeddedMode=*/true), _meshDS(0)
7178 list< const SMDS_MeshElement* >::const_iterator partIt = meshPart.begin();
7179 for ( ; partIt != meshPart.end(); ++partIt )
7180 if ( const SMDS_MeshElement * e = *partIt )
7181 if ( _elements[ e->GetType() ].insert( e ).second )
7184 SMDS_ElemIteratorPtr nIt = e->nodesIterator();
7185 while ( nIt->more() )
7187 const SMDS_MeshNode * n = (const SMDS_MeshNode*) nIt->next();
7188 if ( _elements[ SMDSAbs_Node ].insert( n ).second )
7194 // -------------------------------------------------------------------------------------
7195 const SMDS_MeshElement * SMESH_MeshPartDS::FindElement(int IDelem) const
7197 if ( _meshDS ) return _meshDS->FindElement( IDelem );
7199 TElemID elem( IDelem );
7200 for ( int iType = SMDSAbs_Edge; iType < SMDSAbs_NbElementTypes; ++iType )
7201 if ( !_elements[ iType ].empty() )
7203 TIDSortedElemSet::const_iterator it = _elements[ iType ].find( &elem );
7204 if ( it != _elements[ iType ].end() )
7209 // -------------------------------------------------------------------------------------
7210 bool SMESH_MeshPartDS::HasNumerationHoles()
7212 if ( _meshDS ) return _meshDS->HasNumerationHoles();
7214 return ( MinNodeID() != 1 ||
7215 MaxNodeID() != NbNodes() ||
7216 MinElementID() != 1 ||
7217 MaxElementID() != NbElements() );
7219 // -------------------------------------------------------------------------------------
7220 smIdType SMESH_MeshPartDS::MaxNodeID() const
7222 if ( _meshDS ) return _meshDS->MaxNodeID();
7223 return NbNodes() == 0 ? 0 : (*_elements[ SMDSAbs_Node ].rbegin())->GetID();
7225 // -------------------------------------------------------------------------------------
7226 smIdType SMESH_MeshPartDS::MinNodeID() const
7228 if ( _meshDS ) return _meshDS->MinNodeID();
7229 return NbNodes() == 0 ? 0 : (*_elements[ SMDSAbs_Node ].begin())->GetID();
7231 // -------------------------------------------------------------------------------------
7232 smIdType SMESH_MeshPartDS::MaxElementID() const
7234 if ( _meshDS ) return _meshDS->MaxElementID();
7236 for ( int iType = SMDSAbs_Edge; iType < SMDSAbs_NbElementTypes; ++iType )
7237 if ( !_elements[ iType ].empty() )
7238 maxID = std::max( maxID, (*_elements[ iType ].rbegin())->GetID() );
7241 // -------------------------------------------------------------------------------------
7242 smIdType SMESH_MeshPartDS::MinElementID() const
7244 if ( _meshDS ) return _meshDS->MinElementID();
7246 for ( int iType = SMDSAbs_Edge; iType < SMDSAbs_NbElementTypes; ++iType )
7247 if ( !_elements[ iType ].empty() )
7248 minID = std::min( minID, (*_elements[ iType ].begin())->GetID() );
7251 // -------------------------------------------------------------------------------------
7252 SMDS_ElemIteratorPtr SMESH_MeshPartDS::elementGeomIterator(SMDSAbs_GeometryType geomType) const
7254 if ( _meshDS ) return _meshDS->elementGeomIterator( geomType );
7256 typedef SMDS_SetIterator
7257 <const SMDS_MeshElement*,
7258 TIDSortedElemSet::const_iterator,
7259 SMDS::SimpleAccessor<const SMDS_MeshElement*, TIDSortedElemSet::const_iterator>,
7260 SMDS_MeshElement::GeomFilter
7263 SMDSAbs_ElementType type = SMDS_MeshCell::ElemType( geomType );
7265 return SMDS_ElemIteratorPtr( new TIter( _elements[type].begin(),
7266 _elements[type].end(),
7267 SMDS_MeshElement::GeomFilter( geomType )));
7269 // -------------------------------------------------------------------------------------
7270 SMDS_ElemIteratorPtr SMESH_MeshPartDS::elementEntityIterator(SMDSAbs_EntityType entity) const
7272 if ( _meshDS ) return _meshDS->elementEntityIterator( entity );
7274 typedef SMDS_SetIterator
7275 <const SMDS_MeshElement*,
7276 TIDSortedElemSet::const_iterator,
7277 SMDS::SimpleAccessor<const SMDS_MeshElement*, TIDSortedElemSet::const_iterator>,
7278 SMDS_MeshElement::EntityFilter
7281 SMDSAbs_ElementType type = SMDS_MeshCell::ElemType( entity );
7283 return SMDS_ElemIteratorPtr( new TIter( _elements[type].begin(),
7284 _elements[type].end(),
7285 SMDS_MeshElement::EntityFilter( entity )));
7287 // -------------------------------------------------------------------------------------
7288 SMDS_ElemIteratorPtr SMESH_MeshPartDS::elementsIterator(SMDSAbs_ElementType type) const
7290 typedef SMDS_SetIterator<const SMDS_MeshElement*, TIDSortedElemSet::const_iterator > TIter;
7291 if ( type == SMDSAbs_All && !_meshDS )
7293 typedef vector< SMDS_ElemIteratorPtr > TIterVec;
7295 for ( int i = 0; i < SMDSAbs_NbElementTypes; ++i )
7296 if ( !_elements[i].empty() && i != SMDSAbs_Node )
7298 ( SMDS_ElemIteratorPtr( new TIter( _elements[i].begin(), _elements[i].end() )));
7300 typedef SMDS_IteratorOnIterators<const SMDS_MeshElement*, TIterVec > TIterOnIters;
7301 return SMDS_ElemIteratorPtr( new TIterOnIters( iterVec ));
7303 return _meshDS ? _meshDS->elementsIterator(type) : SMDS_ElemIteratorPtr
7304 ( new TIter( _elements[type].begin(), _elements[type].end() ));
7306 // -------------------------------------------------------------------------------------
7307 #define _GET_ITER_DEFINE( iterType, methName, elem, elemType) \
7308 iterType SMESH_MeshPartDS::methName() const \
7310 typedef SMDS_SetIterator<const elem*, TIDSortedElemSet::const_iterator > TIter; \
7311 return _meshDS ? _meshDS->methName() : iterType \
7312 ( new TIter( _elements[elemType].begin(), _elements[elemType].end() )); \
7314 // -------------------------------------------------------------------------------------
7315 _GET_ITER_DEFINE( SMDS_NodeIteratorPtr, nodesIterator, SMDS_MeshNode, SMDSAbs_Node )
7316 _GET_ITER_DEFINE( SMDS_EdgeIteratorPtr, edgesIterator, SMDS_MeshEdge, SMDSAbs_Edge )
7317 _GET_ITER_DEFINE( SMDS_FaceIteratorPtr, facesIterator, SMDS_MeshFace, SMDSAbs_Face )
7318 _GET_ITER_DEFINE( SMDS_VolumeIteratorPtr, volumesIterator, SMDS_MeshVolume, SMDSAbs_Volume)
7319 #undef _GET_ITER_DEFINE
7321 // END Implementation of SMESH_MeshPartDS
7323 //================================================================================