Regression of SMESH_SRC/doc/salome/examples/measurements_ex01.py

Manage temporary SMESH_IDSource created by MeshEditor::MakeIDSource()
This commit is contained in:
eap 2013-08-07 14:06:39 +00:00
parent 18efd0cad1
commit 5c95ba9078
7 changed files with 99 additions and 17 deletions

View File

@ -58,6 +58,7 @@
#include CORBA_SERVER_HEADER(SMESH_Mesh)
#include CORBA_SERVER_HEADER(SMESH_MeshEditor)
#define SPACING 6
#define MARGIN 11
@ -352,14 +353,17 @@ bool SMESHGUI_Add0DElemsOnAllNodesOp::onApply()
return false;
// get a mesh
SMESH::SMESH_IDSource_var meshObject;
SMESH::SMESH_IDSource_wrap meshObject;
SMESH::SMESH_Mesh_var mesh;
if ( !myIO.IsNull() )
{
CORBA::Object_var obj = SMESH::IObjectToObject( myIO );
meshObject = SMESH::SMESH_IDSource::_narrow( obj );
if ( !meshObject->_is_nil() )
{
mesh = meshObject->GetMesh();
meshObject->Register();
}
}
if ( mesh->_is_nil() )
{

View File

@ -308,10 +308,11 @@ bool SMESHGUI_CopyMeshDlg::ClickOnApply()
try
{
SUIT_OverrideCursor aWaitCursor;
SMESH::SMESH_IDSource_var aPartToCopy;
SMESH::SMESH_IDSource_wrap aPartToCopy;
if ( myIdSourceCheck->isChecked())
{
aPartToCopy = mySelectedObject;
aPartToCopy->Register();
}
else
{

View File

@ -519,8 +519,8 @@ void SMESHGUI_MinDistance::secondEdited()
void SMESHGUI_MinDistance::compute()
{
SUIT_OverrideCursor wc;
SMESH::SMESH_IDSource_var s1;
SMESH::SMESH_IDSource_var s2;
SMESH::SMESH_IDSource_wrap s1;
SMESH::SMESH_IDSource_wrap s2;
bool isOrigin = mySecond->checkedId() == OriginTgt;
// process first target
@ -538,6 +538,7 @@ void SMESHGUI_MinDistance::compute()
}
else {
s1 = myFirstSrc;
s1->Register();
}
}
@ -556,6 +557,7 @@ void SMESHGUI_MinDistance::compute()
}
else {
s2 = mySecondSrc;
s2->Register();
}
}
@ -1035,14 +1037,17 @@ void SMESHGUI_BoundingBox::compute()
}
else {
srcList->length( mySrc.count() );
for( int i = 0; i < mySrc.count(); i++ )
for( int i = 0; i < mySrc.count(); i++ ) {
srcList[i] = mySrc[i];
mySrc[i]->Register();
}
}
if ( srcList->length() > 0 ) {
// compute bounding box
int precision = SMESHGUI::resourceMgr()->integerValue( "SMESH", "length_precision", 6 );
SMESH::Measurements_var measure = SMESHGUI::GetSMESHGen()->CreateMeasurements();
SMESH::Measure result = measure->BoundingBox( srcList.in() );
SALOME::UnRegister( srcList );
measure->UnRegister();
myXmin->setText( QString::number( result.minX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
myXmax->setText( QString::number( result.maxX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );

View File

@ -1212,7 +1212,7 @@ bool SMESHGUI_CuttingOfQuadsDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
{
if ( hasObj )
return theEditor->QuadTo4Tri( obj ), true;
SMESH::SMESH_IDSource_var elems = theEditor->MakeIDSource( theIds, SMESH::FACE );
SMESH::SMESH_IDSource_wrap elems = theEditor->MakeIDSource( theIds, SMESH::FACE );
theEditor->QuadTo4Tri( elems );
return true;
}
@ -1466,9 +1466,11 @@ bool SMESHGUI_CuttingIntoTetraDlg::process (SMESH::SMESH_MeshEditor_ptr theEdito
const SMESH::long_array& theIds,
SMESH::SMESH_IDSource_ptr theObj)
{
SMESH::SMESH_IDSource_var obj = theObj;
SMESH::SMESH_IDSource_wrap obj = theObj;
if ( CORBA::is_nil( obj ))
obj = theEditor->MakeIDSource( theIds, myEntityType ? SMESH::VOLUME : SMESH::FACE );
else
obj->Register();
try {
theEditor->SplitVolumesIntoTetra( obj, myGroupChoice->checkedId()+1 );
}
@ -1476,5 +1478,8 @@ bool SMESHGUI_CuttingIntoTetraDlg::process (SMESH::SMESH_MeshEditor_ptr theEdito
SalomeApp_Tools::QtCatchCorbaException( S_ex );
return false;
}
catch(...) {
return false;
}
return true;
}

View File

@ -485,8 +485,9 @@ bool SMESHGUI_ScaleDlg::ClickOnApply()
}
else {
SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
SMESH::SMESH_IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
myMeshes[0]->SetParameters( aParameters.join( ":" ).toLatin1().constData() );
aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact, false);
aMeshEditor->Scale( src, aPoint, aScaleFact, false);
}
break;
@ -501,8 +502,9 @@ bool SMESHGUI_ScaleDlg::ClickOnApply()
}
else {
SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
SMESH::SMESH_IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
groups = aMeshEditor->ScaleMakeGroups(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact);
groups = aMeshEditor->ScaleMakeGroups( src, aPoint, aScaleFact);
}
}
else {
@ -515,8 +517,9 @@ bool SMESHGUI_ScaleDlg::ClickOnApply()
}
else {
SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
SMESH::SMESH_IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact, true);
aMeshEditor->Scale( src, aPoint, aScaleFact, true);
}
}
break;
@ -537,7 +540,8 @@ bool SMESHGUI_ScaleDlg::ClickOnApply()
else {
SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
mesh = aMeshEditor->ScaleMakeMesh(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact, makeGroups,
SMESH::SMESH_IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
mesh = aMeshEditor->ScaleMakeMesh( src, aPoint, aScaleFact, makeGroups,
LineEditNewMesh->text().toLatin1().data());
if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
anEntryList.append( aSObject->GetID().c_str() );
@ -1142,7 +1146,8 @@ void SMESHGUI_ScaleDlg::onDisplaySimulation( bool toDisplayPreview ) {
}
else {
SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact, copy);
SMESH::SMESH_IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
aMeshEditor->Scale( src, aPoint, aScaleFact, copy);
aMeshPreviewStruct << aMeshEditor->GetPreviewData();
}
setSimulationPreview(aMeshPreviewStruct);

View File

@ -35,6 +35,7 @@
// SALOME KERNEL includes
#include <SALOMEDSClient_definitions.hxx>
#include <SALOME_GenericObj_wrap.hxx>
// SALOME GUI includes
#include <SALOME_InteractiveObject.hxx>
@ -176,6 +177,10 @@ SMESHGUI_EXPORT
SMESHGUI_EXPORT
gp_XYZ getNormale( const SMDS_MeshFace* theFace );
// type to use instead of SMESH_IDSource_var for automatic UnRegister()
typedef SALOME::GenericObj_wrap<SMESH_IDSource> SMESH_IDSource_wrap;
}
#endif // SMESHGUI_UTILS_H

View File

@ -982,6 +982,7 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen):
if not hasattr(src1, "_narrow"): return None
src1 = src1._narrow(SMESH.SMESH_IDSource)
if not src1: return None
unRegister = genObjUnRegister()
if id1 != 0:
m = src1.GetMesh()
e = m.GetMeshEditor()
@ -989,6 +990,7 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen):
src1 = e.MakeIDSource([id1], SMESH.FACE)
else:
src1 = e.MakeIDSource([id1], SMESH.NODE)
unRegister.set( src1 )
pass
if hasattr(src2, "_narrow"):
src2 = src2._narrow(SMESH.SMESH_IDSource)
@ -999,11 +1001,12 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen):
src2 = e.MakeIDSource([id2], SMESH.FACE)
else:
src2 = e.MakeIDSource([id2], SMESH.NODE)
unRegister.set( src2 )
pass
pass
aMeasurements = self.CreateMeasurements()
unRegister.set( aMeasurements )
result = aMeasurements.MinDistance(src1, src2)
aMeasurements.UnRegister()
return result
## Get bounding box of the specified object(s)
@ -1579,8 +1582,10 @@ class Mesh:
def ExportMED(self, f, auto_groups=0, version=MED_V2_2,
overwrite=1, meshPart=None, autoDimension=True):
if meshPart:
unRegister = genObjUnRegister()
if isinstance( meshPart, list ):
meshPart = self.GetIDSource( meshPart, SMESH.ALL )
unRegister.set( meshPart )
self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite, autoDimension)
else:
self.mesh.ExportToMEDX(f, auto_groups, version, overwrite, autoDimension)
@ -1600,8 +1605,10 @@ class Mesh:
# @ingroup l2_impexp
def ExportDAT(self, f, meshPart=None):
if meshPart:
unRegister = genObjUnRegister()
if isinstance( meshPart, list ):
meshPart = self.GetIDSource( meshPart, SMESH.ALL )
unRegister.set( meshPart )
self.mesh.ExportPartToDAT( meshPart, f )
else:
self.mesh.ExportDAT(f)
@ -1612,8 +1619,10 @@ class Mesh:
# @ingroup l2_impexp
def ExportUNV(self, f, meshPart=None):
if meshPart:
unRegister = genObjUnRegister()
if isinstance( meshPart, list ):
meshPart = self.GetIDSource( meshPart, SMESH.ALL )
unRegister.set( meshPart )
self.mesh.ExportPartToUNV( meshPart, f )
else:
self.mesh.ExportUNV(f)
@ -1625,8 +1634,10 @@ class Mesh:
# @ingroup l2_impexp
def ExportSTL(self, f, ascii=1, meshPart=None):
if meshPart:
unRegister = genObjUnRegister()
if isinstance( meshPart, list ):
meshPart = self.GetIDSource( meshPart, SMESH.ALL )
unRegister.set( meshPart )
self.mesh.ExportPartToSTL( meshPart, f, ascii )
else:
self.mesh.ExportSTL(f, ascii)
@ -1637,8 +1648,10 @@ class Mesh:
# @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
# @ingroup l2_impexp
def ExportCGNS(self, f, overwrite=1, meshPart=None):
unRegister = genObjUnRegister()
if isinstance( meshPart, list ):
meshPart = self.GetIDSource( meshPart, SMESH.ALL )
unRegister.set( meshPart )
if isinstance( meshPart, Mesh ):
meshPart = meshPart.mesh
elif not meshPart:
@ -1652,8 +1665,10 @@ class Mesh:
# @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
# @ingroup l2_impexp
def ExportGMF(self, f, meshPart=None):
unRegister = genObjUnRegister()
if isinstance( meshPart, list ):
meshPart = self.GetIDSource( meshPart, SMESH.ALL )
unRegister.set( meshPart )
if isinstance( meshPart, Mesh ):
meshPart = meshPart.mesh
elif not meshPart:
@ -2438,7 +2453,7 @@ class Mesh:
aMeasurements = self.smeshpyD.CreateMeasurements()
aMeasure = aMeasurements.MinDistance(id1, id2)
aMeasurements.UnRegister()
genObjUnRegister([aMeasurements,id1, id2])
return aMeasure
## Get bounding box of the specified object(s)
@ -2471,6 +2486,7 @@ class Mesh:
if len(IDs) > 0 and isinstance(IDs[0], int):
IDs = [IDs]
srclist = []
unRegister = genObjUnRegister()
for o in IDs:
if isinstance(o, Mesh):
srclist.append(o.mesh)
@ -2483,11 +2499,12 @@ class Mesh:
srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
else:
srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
unRegister.set( srclist[-1] )
pass
pass
aMeasurements = self.smeshpyD.CreateMeasurements()
unRegister.set( aMeasurements )
aMeasure = aMeasurements.BoundingBox(srclist)
aMeasurements.UnRegister()
return aMeasure
# Mesh edition (SMESH_MeshEditor functionality):
@ -2540,10 +2557,12 @@ class Mesh:
# can be retrieved from the returned object by calling GetIDs()
# @ingroup l2_modif_add
def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
unRegister = genObjUnRegister()
if isinstance( theObject, Mesh ):
theObject = theObject.GetMesh()
if isinstance( theObject, list ):
theObject = self.GetIDSource( theObject, SMESH.ALL )
unRegister.set( theObject )
return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
## Creates a ball element on a node with given ID.
@ -2813,11 +2832,13 @@ class Mesh:
# @return number of reoriented faces
# @ingroup l2_modif_changori
def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
unRegister = genObjUnRegister()
# check the2DObject
if isinstance( the2DObject, Mesh ):
the2DObject = the2DObject.GetMesh()
if isinstance( the2DObject, list ):
the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
unRegister.set( the2DObject )
# check theDirection
if isinstance( theDirection, geomBuilder.GEOM._objref_GEOM_Object):
theDirection = self.smeshpyD.GetDirStruct( theDirection )
@ -2907,12 +2928,14 @@ class Mesh:
# group or a list of face IDs. By default all quadrangles are split
# @ingroup l2_modif_cutquadr
def QuadTo4Tri (self, theElements=[]):
unRegister = genObjUnRegister()
if isinstance( theElements, Mesh ):
theElements = theElements.mesh
elif not theElements:
theElements = self.mesh
elif isinstance( theElements, list ):
theElements = self.GetIDSource( theElements, SMESH.FACE )
unRegister.set( theElements )
return self.editor.QuadTo4Tri( theElements )
## Splits quadrangles into triangles.
@ -2952,10 +2975,12 @@ class Mesh:
# Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
# @ingroup l2_modif_cutquadr
def SplitVolumesIntoTetra(self, elemIDs, method=smeshBuilder.Hex_5Tet ):
unRegister = genObjUnRegister()
if isinstance( elemIDs, Mesh ):
elemIDs = elemIDs.GetMesh()
if ( isinstance( elemIDs, list )):
elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
unRegister.set( elemIDs )
self.editor.SplitVolumesIntoTetra(elemIDs, method)
## Splits quadrangle faces near triangular facets of volumes
@ -3226,12 +3251,14 @@ class Mesh:
# @ingroup l2_modif_edit
def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
toCopyElements=False, toCopyExistingBondary=False):
unRegister = genObjUnRegister()
if isinstance( elements, Mesh ):
elements = elements.GetMesh()
if ( isinstance( elements, list )):
elemType = SMESH.ALL
if elements: elemType = self.GetElementType( elements[0], iselem=True)
elements = self.editor.MakeIDSource(elements, elemType)
unRegister.set( elements )
mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
toCopyElements,toCopyExistingBondary)
if mesh: mesh = self.smeshpyD.Mesh(mesh)
@ -3914,10 +3941,12 @@ class Mesh:
# @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
# empty list otherwise
def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
unRegister = genObjUnRegister()
if ( isinstance( theObject, Mesh )):
theObject = theObject.GetMesh()
if ( isinstance( theObject, list )):
theObject = self.GetIDSource(theObject, SMESH.ALL)
unRegister.set( theObject )
if ( isinstance( theScaleFact, float )):
theScaleFact = [theScaleFact]
if ( isinstance( theScaleFact, int )):
@ -3938,10 +3967,12 @@ class Mesh:
# @param NewMeshName - the name of the newly created mesh
# @return instance of Mesh class
def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
unRegister = genObjUnRegister()
if (isinstance(theObject, Mesh)):
theObject = theObject.GetMesh()
if ( isinstance( theObject, list )):
theObject = self.GetIDSource(theObject,SMESH.ALL)
unRegister.set( theObject )
if ( isinstance( theScaleFact, float )):
theScaleFact = [theScaleFact]
if ( isinstance( theScaleFact, int )):
@ -4050,12 +4081,14 @@ class Mesh:
# @return the list of groups of nodes
# @ingroup l2_modif_trsf
def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
unRegister = genObjUnRegister()
if (isinstance( SubMeshOrGroup, Mesh )):
SubMeshOrGroup = SubMeshOrGroup.GetMesh()
if not isinstance( exceptNodes, list):
exceptNodes = [ exceptNodes ]
if exceptNodes and isinstance( exceptNodes[0], int):
exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
unRegister.set( exceptNodes )
return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
## Merges nodes
@ -4166,10 +4199,12 @@ class Mesh:
# @return a group where the new elements are added. None if theGroupName == "".
# @ingroup l2_modif_edit
def DoubleElements(self, theElements, theGroupName=""):
unRegister = genObjUnRegister()
if isinstance( theElements, Mesh ):
theElements = theElements.mesh
elif isinstance( theElements, list ):
theElements = self.GetIDSource( theElements, SMESH.ALL )
unRegister.set( theElements )
return self.editor.DoubleElements(theElements, theGroupName)
## Creates a hole in a mesh by doubling the nodes of some particular elements
@ -4525,6 +4560,28 @@ class hypMethodWrapper:
raise ValueError, detail # wrong variable name
return result
pass
# A helper class that call UnRegister() of SALOME.GenericObj'es stored in it
class genObjUnRegister:
def __init__(self, genObj=None):
self.genObjList = []
self.set( genObj )
return
def set(self, genObj):
"Store one or a list of of SALOME.GenericObj'es"
if isinstance( genObj, list ):
self.genObjList.extend( genObj )
else:
self.genObjList.append( genObj )
return
def __del__(self):
for genObj in self.genObjList:
if genObj and hasattr( genObj, "UnRegister" ):
genObj.UnRegister()
for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
#