From b3aa30bca3681f193de42a267833c5f229981aa2 Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 14 Dec 2012 13:57:37 +0000 Subject: [PATCH] 21948: EDF SMESH : Memory is not freed when deleting a mesh Elimenate memory leaks on CORBA objects, servants of SALOMEDS objects etc --- src/SMESHGUI/SMESHGUI_BuildCompoundDlg.cxx | 2 - src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx | 6 +- src/SMESHGUI/SMESHGUI_GroupDlg.cxx | 28 ++- src/SMESHGUI/SMESHGUI_GroupOnShapeDlg.cxx | 15 +- src/SMESHGUI/SMESHGUI_Hypotheses.cxx | 31 +-- src/SMESHGUI/SMESHGUI_HypothesesUtils.cxx | 12 +- src/SMESHGUI/SMESHGUI_MeshOp.cxx | 31 +-- src/SMESHGUI/SMESHGUI_Selection.cxx | 2 +- src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx | 154 ++++++------ src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx | 227 +++++++++++------- .../StdMeshersGUI_StdHypothesisCreator.cxx | 4 +- .../StdMeshersGUI_SubShapeSelectorWdg.cxx | 18 +- .../StdMeshers_ImportSource1D_i.cxx | 11 +- .../StdMeshers_ImportSource2D_i.cxx | 9 +- .../StdMeshers_LayerDistribution_i.cxx | 11 +- src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx | 16 +- 16 files changed, 327 insertions(+), 250 deletions(-) diff --git a/src/SMESHGUI/SMESHGUI_BuildCompoundDlg.cxx b/src/SMESHGUI/SMESHGUI_BuildCompoundDlg.cxx index 51e194370..cadd4593f 100644 --- a/src/SMESHGUI/SMESHGUI_BuildCompoundDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_BuildCompoundDlg.cxx @@ -347,13 +347,11 @@ bool SMESHGUI_BuildCompoundDlg::ClickOnApply() SMESHGUI::Modified(); -#ifdef WITHGENERICOBJ // obj has been published in study. Its refcount has been incremented. // It is safe to decrement its refcount // so that it will be destroyed when the entry in study will be removed if (!CORBA::is_nil(aCompoundMesh)) aCompoundMesh->UnRegister(); -#endif return true; } diff --git a/src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx b/src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx index ead9da3c0..37f13c33d 100644 --- a/src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx +++ b/src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx @@ -30,6 +30,7 @@ // SALOME GEOM includes #include +#include // SALOME KERNEL includes #include @@ -114,10 +115,11 @@ namespace SMESH _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); if (!aStudy || geomGen->_is_nil()) return GEOM::GEOM_Object::_nil(); - GEOM::GEOM_IShapesOperations_var aShapesOp = geomGen->GetIShapesOperations(aStudy->StudyId()); + GEOM::GEOM_IShapesOperations_wrap aShapesOp = + geomGen->GetIShapesOperations(aStudy->StudyId()); if (aShapesOp->_is_nil()) return GEOM::GEOM_Object::_nil(); - GEOM::GEOM_Object_var subShape = aShapesOp->GetSubShape (theMainShape,theID); + GEOM::GEOM_Object_wrap subShape = aShapesOp->GetSubShape (theMainShape,theID); return subShape._retn(); } } // end of namespace SMESH diff --git a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx index f6d02c232..bc27fbb69 100644 --- a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx @@ -44,6 +44,7 @@ // SALOME GEOM includes #include #include +#include // SALOME GUI includes #include @@ -1033,8 +1034,6 @@ bool SMESHGUI_GroupDlg::onApply() return false; _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - GEOM::GEOM_IGroupOperations_var aGroupOp = - SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); if (myGeomObjects->length() == 1) { myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, @@ -1053,8 +1052,7 @@ bool SMESHGUI_GroupDlg::onApply() if (geomGen->_is_nil() || !aStudy) return false; - GEOM::GEOM_IGroupOperations_var op = - geomGen->GetIGroupOperations(aStudy->StudyId()); + GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId()); if (op->_is_nil()) return false; @@ -1071,8 +1069,8 @@ bool SMESHGUI_GroupDlg::onApply() } } - GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh(); - GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType); + GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh(); + GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType); op->UnionList(aGroupVar, myGeomObjects); if (op->IsDone()) { @@ -1373,15 +1371,19 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged() // Check if group constructed on the same shape as a mesh or on its child _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - GEOM::GEOM_IGroupOperations_var anOp = - SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); // The main shape of the group - GEOM::GEOM_Object_var aGroupMainShape; - if (aGeomGroup->GetType() == 37) + GEOM::GEOM_Object_wrap aGroupMainShape; + if (aGeomGroup->GetType() == 37) { + GEOM::GEOM_IGroupOperations_wrap anOp = + SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); aGroupMainShape = anOp->GetMainShape(aGeomGroup); - else - aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup); + // aGroupMainShape is a new geom servant to be deleted by GEOM_Object_wrap + } + else { + aGroupMainShape = aGeomGroup; + aGroupMainShape->Register(); + } _PTR(SObject) aGroupMainShapeSO = aStudy->FindObjectID(aGroupMainShape->GetStudyEntry()); @@ -1951,7 +1953,7 @@ void SMESHGUI_GroupDlg::onAdd() } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) { _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - GEOM::GEOM_IGroupOperations_var aGroupOp = + GEOM::GEOM_IGroupOperations_wrap aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); SMESH::ElementType aGroupType = SMESH::ALL; diff --git a/src/SMESHGUI/SMESHGUI_GroupOnShapeDlg.cxx b/src/SMESHGUI/SMESHGUI_GroupOnShapeDlg.cxx index f4cde4f1b..50f3bbacc 100644 --- a/src/SMESHGUI/SMESHGUI_GroupOnShapeDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_GroupOnShapeDlg.cxx @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -204,7 +205,7 @@ LightApp_Dialog* SMESHGUI_GroupOnShapeOp::dlg() const */ //================================================================================ -static SMESH::ElementType elementType(GEOM::GEOM_Object_var& geom) +static SMESH::ElementType elementType(GEOM::GEOM_Object_var geom) { if ( !geom->_is_nil() ) { switch ( geom->GetShapeType() ) { @@ -219,17 +220,17 @@ static SMESH::ElementType elementType(GEOM::GEOM_Object_var& geom) default: return SMESH::ALL; } _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - GEOM::GEOM_IShapesOperations_var aShapeOp = + GEOM::GEOM_IShapesOperations_wrap aShapeOp = SMESH::GetGEOMGen()->GetIShapesOperations(aStudy->StudyId()); if ( geom->GetType() == 37 ) { // geom group - GEOM::GEOM_IGroupOperations_var aGroupOp = + GEOM::GEOM_IGroupOperations_wrap aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); if ( !aGroupOp->_is_nil() ) { - GEOM::GEOM_Object_var mainShape = aGroupOp->GetMainShape( geom ); - GEOM::ListOfLong_var ids = aGroupOp->GetObjects( geom ); + GEOM::GEOM_Object_wrap mainShape = aGroupOp->GetMainShape( geom ); + GEOM::ListOfLong_var ids = aGroupOp->GetObjects( geom ); if ( ids->length() && !mainShape->_is_nil() && !aShapeOp->_is_nil() ) { - GEOM::GEOM_Object_var member = aShapeOp->GetSubShape( mainShape, ids[0] ); + GEOM::GEOM_Object_wrap member = aShapeOp->GetSubShape( mainShape, ids[0] ); return elementType( member ); } } @@ -237,7 +238,7 @@ static SMESH::ElementType elementType(GEOM::GEOM_Object_var& geom) else if ( !aShapeOp->_is_nil() ) { // just a compoud shape GEOM::ListOfLong_var ids = aShapeOp->SubShapeAllIDs( geom, GEOM::SHAPE, false ); if ( ids->length() ) { - GEOM::GEOM_Object_var member = aShapeOp->GetSubShape( geom, ids[0] ); + GEOM::GEOM_Object_wrap member = aShapeOp->GetSubShape( geom, ids[0] ); return elementType( member ); } } diff --git a/src/SMESHGUI/SMESHGUI_Hypotheses.cxx b/src/SMESHGUI/SMESHGUI_Hypotheses.cxx index 7b10c0ff5..e2852230c 100644 --- a/src/SMESHGUI/SMESHGUI_Hypotheses.cxx +++ b/src/SMESHGUI/SMESHGUI_Hypotheses.cxx @@ -51,23 +51,32 @@ #define SPACING 6 #define MARGIN 11 -//To disable automatic genericobj management, the following line should be commented. -//Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx -#define WITHGENERICOBJ - SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType ) - : myHypType( theHypType ), myIsCreate( false ), myDlg( 0 ) + : myToDeleteInitParamsHypo( false ), + myHypType( theHypType ), + myIsCreate( false ), + myDlg( 0 ) { } SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator() { + if ( myToDeleteInitParamsHypo && !myInitParamsHypo->_is_nil() ) + myInitParamsHypo->UnRegister(); } void SMESHGUI_GenericHypothesisCreator::setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr hyp) { - if ( !CORBA::is_nil( hyp ) && hypType() == hyp->GetName() ) - myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( hyp ); + if ( !CORBA::is_nil( hyp ) ) { + if ( myToDeleteInitParamsHypo && !myInitParamsHypo->_is_nil() ) + myInitParamsHypo->UnRegister(); + CORBA::String_var hypName = hyp->GetName(); + if ( hypType() == hypName.in() ) + { + myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( hyp ); + myToDeleteInitParamsHypo = !SMESH::FindSObject( myInitParamsHypo ); + } + } } void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp, @@ -91,19 +100,15 @@ void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo, if (isAlgo) { SMESH::SMESH_Hypothesis_var anAlgo = SMESH::CreateHypothesis( hypType(), theHypName, isAlgo ); -#ifdef WITHGENERICOBJ if (!CORBA::is_nil(anAlgo)) anAlgo->UnRegister(); -#endif } else { SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::CreateHypothesis( hypType(), theHypName, false ); editHypothesis( aHypothesis.in(), theHypName, theParent, obj, slot ); -#ifdef WITHGENERICOBJ if (!CORBA::is_nil(aHypothesis)) aHypothesis->UnRegister(); -#endif } } @@ -128,9 +133,7 @@ void SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ { myHypName = theHypName; myHypo = SMESH::SMESH_Hypothesis::_duplicate( h ); -#ifdef WITHGENERICOBJ myHypo->Register(); -#endif SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent ); connect( Dlg, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) ); @@ -302,9 +305,7 @@ void SMESHGUI_GenericHypothesisCreator::onDialogFinished( int result ) } } SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 ); -#ifdef WITHGENERICOBJ myHypo->UnRegister(); -#endif myHypo = SMESH::SMESH_Hypothesis::_nil(); myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil(); diff --git a/src/SMESHGUI/SMESHGUI_HypothesesUtils.cxx b/src/SMESHGUI/SMESHGUI_HypothesesUtils.cxx index 2c5d1828c..b52f7308e 100644 --- a/src/SMESHGUI/SMESHGUI_HypothesesUtils.cxx +++ b/src/SMESHGUI/SMESHGUI_HypothesesUtils.cxx @@ -612,23 +612,21 @@ namespace SMESH return res < SMESH::HYP_UNKNOWN_FATAL; } - bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject) MorSM, + bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject) MorSM, SMESH::SMESH_Hypothesis_ptr anHyp) { - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; int res = SMESH::HYP_UNKNOWN_FATAL; SUIT_OverrideCursor wc; if (MorSM) { try { GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(MorSM); - SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface(MorSM); - SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface(MorSM); - + SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface(MorSM); + SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface(MorSM); + if (!aSubMesh->_is_nil()) aMesh = aSubMesh->GetFather(); - + if (!aMesh->_is_nil()) { if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) { res = aMesh->RemoveHypothesis(aShapeObject, anHyp); diff --git a/src/SMESHGUI/SMESHGUI_MeshOp.cxx b/src/SMESHGUI/SMESHGUI_MeshOp.cxx index df085305b..3252838e7 100644 --- a/src/SMESHGUI/SMESHGUI_MeshOp.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshOp.cxx @@ -40,6 +40,7 @@ #include #include #include +#include // SALOME GUI includes #include @@ -56,6 +57,8 @@ // SALOME KERNEL includes #include #include +#include +#include // Qt includes #include @@ -336,8 +339,7 @@ bool SMESHGUI_MeshOp::isSubshapeOk() const _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); if (geomGen->_is_nil() || !aStudy) return false; - GEOM::GEOM_IGroupOperations_var op = - geomGen->GetIGroupOperations(aStudy->StudyId()); + GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId()); if (op->_is_nil()) return false; // check all selected shapes @@ -352,18 +354,17 @@ bool SMESHGUI_MeshOp::isSubshapeOk() const if (aSubGeomVar->_is_nil()) return false; // skl for NPAL14695 - implementation of searching of mainObj - GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); - //if (mainObj->_is_nil() || - // string(mainObj->GetEntry()) != string(mainGeom->GetEntry())) return false; + GEOM::GEOM_Object_wrap mainObj = op->GetMainShape(aSubGeomVar); while(1) { if (mainObj->_is_nil()) return false; - if (std::string(mainObj->GetEntry()) == std::string(mainGeom->GetEntry())) + CORBA::String_var entry1 = mainObj->GetEntry(); + CORBA::String_var entry2 = mainGeom->GetEntry(); + if (std::string( entry1.in() ) == entry2.in() ) return true; mainObj = op->GetMainShape(mainObj); } } - //return true; } return false; @@ -896,7 +897,8 @@ void SMESHGUI_MeshOp::existingHyps( const int theDim, SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar ); if ( !aHypVar->_is_nil() ) { - HypothesisData* aData = SMESH::GetHypothesisData( aHypVar->GetName() ); + CORBA::String_var hypType = aHypVar->GetName(); + HypothesisData* aData = SMESH::GetHypothesisData( hypType.in() ); if ( !aData) continue; if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) && ( isCompatible ( theAlgoData, aData, theHypType )) && @@ -1710,7 +1712,7 @@ bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen(); _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); if (!geomGen->_is_nil() && aStudy) { - GEOM::GEOM_IGroupOperations_var op = + GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId()); if (!op->_is_nil()) { // check and add all selected GEOM objects: they must be @@ -1735,18 +1737,19 @@ bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList aSeq[iSubSh] = aSubGeomVar; } // create a group - GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(mainGeom, aGroupType); + GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType); op->UnionList(aGroupVar, aSeq); if (op->IsDone()) { - aGeomVar = aGroupVar; + aGeomVar = aGroupVar.in(); // publish the GEOM group in study QString aNewGeomGroupName ("Auto_group_for_"); aNewGeomGroupName += aName; - SALOMEDS::SObject_var aNewGroupSO = - geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGeomVar, - aNewGeomGroupName.toLatin1().data(), mainGeom); + SALOMEDS::Study_var aStudyVar = _CAST(Study, aStudy)->GetStudy(); + SALOMEDS::SObject_wrap aNewGroupSO = + geomGen->AddInStudy( aStudyVar, aGeomVar, + aNewGeomGroupName.toLatin1().data(), mainGeom); } } } diff --git a/src/SMESHGUI/SMESHGUI_Selection.cxx b/src/SMESHGUI/SMESHGUI_Selection.cxx index efa3c2361..758993e4d 100644 --- a/src/SMESHGUI/SMESHGUI_Selection.cxx +++ b/src/SMESHGUI/SMESHGUI_Selection.cxx @@ -653,7 +653,7 @@ bool SMESHGUI_Selection::isImported( const int ind ) const SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( SO ) ); if( !aMesh->_is_nil() ) { - SALOME_MED::MedFileInfo* inf = aMesh->GetMEDFileInfo(); + SALOME_MED::MedFileInfo_var inf = aMesh->GetMEDFileInfo(); res = strlen( (char*)inf->fileName ) > 0; } } diff --git a/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx b/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx index 940dd4f3e..e83ee56e2 100644 --- a/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx @@ -40,6 +40,7 @@ // SALOME GEOM includes #include #include +#include // SALOME GUI includes #include @@ -53,6 +54,8 @@ // SALOME KERNEL includes #include +#include +#include // OCCT includes #include @@ -223,7 +226,7 @@ SMESH::SMESH_Mesh_ptr SMESHGUI_ShapeByMeshOp::GetMesh() //======================================================================= // function : GetShape() -// purpose : Get published sub-shape +// purpose : Return published sub-shape, it must be UnRegister()ed! //======================================================================= GEOM::GEOM_Object_ptr SMESHGUI_ShapeByMeshOp::GetShape() { @@ -306,85 +309,92 @@ void SMESHGUI_ShapeByMeshOp::commitOperation() try { QStringList aListId = myDlg->myElementId->text().split( " ", QString::SkipEmptyParts); if (aListId.count() == 1) + { + int elemID = (aListId.first()).toInt(); + // GEOM_Object is published -> no need to UnRegister() + myGeomObj = GEOM::GEOM_Object::_duplicate + (SMESHGUI::GetSMESHGen()->GetGeometryByMeshElement + ( myMesh.in(), elemID, myDlg->myGeomName->text().toLatin1().constData()) ); + } + else + { + GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen(); + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + + if (geomGen->_is_nil() || !aStudy) + return; + + GEOM::GEOM_IShapesOperations_wrap aShapesOp = + geomGen->GetIShapesOperations(aStudy->StudyId()); + if (aShapesOp->_is_nil() ) + return; + + TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE; + + std::map aGeomObjectsMap; + GEOM::GEOM_Object_wrap aGeomObject; + + GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh(); + + for ( int i = 0; i < aListId.count(); i++ ) { - int elemID = (aListId.first()).toInt(); - myGeomObj = GEOM::GEOM_Object::_duplicate( - SMESHGUI::GetSMESHGen()->GetGeometryByMeshElement - ( myMesh.in(), elemID, myDlg->myGeomName->text().toLatin1().constData()) ); + aGeomObject = // received object need UnRegister()! + SMESHGUI::GetSMESHGen()->FindGeometryByMeshElement(myMesh.in(), aListId[i].toInt()); + + if (aGeomObject->_is_nil()) continue; + + double anId = aShapesOp->GetSubShapeIndex(aMeshShape, aGeomObject); + if (aShapesOp->IsDone() && !aGeomObjectsMap.count(anId) ) + { + aGeomObjectsMap[anId] = aGeomObject; + + TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aGeomObject->GetShapeType(); + if (i == 0) + aGroupType = aSubShapeType; + else if (aSubShapeType != aGroupType) + aGroupType = TopAbs_SHAPE; + } } - else + + int aNumberOfGO = aGeomObjectsMap.size(); + if (aNumberOfGO == 1) { - GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen(); - _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - - if (geomGen->_is_nil() || !aStudy) - return; - - GEOM::GEOM_IShapesOperations_var aShapesOp = - geomGen->GetIShapesOperations(aStudy->StudyId()); - if (aShapesOp->_is_nil() ) + aGeomObject = (*aGeomObjectsMap.begin()).second; + } + else if (aNumberOfGO > 1) + { + GEOM::GEOM_IGroupOperations_wrap aGroupOp = + geomGen->GetIGroupOperations(aStudy->StudyId()); + if(aGroupOp->_is_nil()) return; - - TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE; - - std::map aGeomObjectsMap; - GEOM::GEOM_Object_var aGeomObject; - GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh(); - - for ( int i = 0; i < aListId.count(); i++ ) - { - aGeomObject = - SMESHGUI::GetSMESHGen()->FindGeometryByMeshElement(myMesh.in(), aListId[i].toInt()); + GEOM::ListOfGO_var aGeomObjects = new GEOM::ListOfGO(); + aGeomObjects->length( aNumberOfGO ); - if (aGeomObject->_is_nil()) continue; - - double anId = aShapesOp->GetSubShapeIndex(aMeshShape, aGeomObject); - if (aShapesOp->IsDone() && aGeomObjectsMap.find(anId) == aGeomObjectsMap.end()) - { - aGeomObjectsMap[anId] = aGeomObject; + int i = 0; + std::map::iterator anIter; + for (anIter = aGeomObjectsMap.begin(); anIter!=aGeomObjectsMap.end(); anIter++) + aGeomObjects[i++] = (*anIter).second.in(); - TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aGeomObject->GetShapeType(); - if (i == 0) - aGroupType = aSubShapeType; - else if (aSubShapeType != aGroupType) - aGroupType = TopAbs_SHAPE; - } - } - - int aNumberOfGO = aGeomObjectsMap.size(); - if (aNumberOfGO == 1) - myGeomObj = (*aGeomObjectsMap.begin()).second; - else if (aNumberOfGO > 1) - { - GEOM::GEOM_IGroupOperations_var aGroupOp = - geomGen->GetIGroupOperations(aStudy->StudyId()); - if(aGroupOp->_is_nil()) - return; - - GEOM::ListOfGO_var aGeomObjects = new GEOM::ListOfGO(); - aGeomObjects->length( aNumberOfGO ); - - int i = 0; - std::map::iterator anIter; - for (anIter = aGeomObjectsMap.begin(); anIter!=aGeomObjectsMap.end(); anIter++) - aGeomObjects[i++] = (*anIter).second; - - //create geometry group - myGeomObj = aGroupOp->CreateGroup(aMeshShape, aGroupType); - aGroupOp->UnionList(myGeomObj, aGeomObjects); - - if (!aGroupOp->IsDone()) - return; - } - - // publish the GEOM object in study - QString aNewGeomGroupName ( myDlg->myGeomName->text() ); - - SALOMEDS::SObject_var aNewGroupSO = - geomGen->AddInStudy(SMESHGUI::GetSMESHGen()->GetCurrentStudy(), myGeomObj, - aNewGeomGroupName.toLatin1().data(), aMeshShape); + //create geometry group + aGeomObject = aGroupOp->CreateGroup(aMeshShape, aGroupType); + aGroupOp->UnionList(myGeomObj, aGeomObjects); + + if (!aGroupOp->IsDone()) + return; } + + // publish the GEOM object in study + QString aNewGeomGroupName ( myDlg->myGeomName->text() ); + SALOMEDS::Study_var aStudyVar = _CAST(Study,aStudy)->GetStudy(); + SALOMEDS::SObject_wrap aNewGroupSO = + geomGen->AddInStudy( aStudyVar, aGeomObject, + aNewGeomGroupName.toLatin1().data(), aMeshShape); + + // get a GEOM_Object already published, which doesn't need UnRegister() + CORBA::Object_var obj = aNewGroupSO->GetObject(); + myGeomObj = GEOM::GEOM_Object::_narrow( obj ); + } } catch (const SALOME::SALOME_Exception& S_ex) { SalomeApp_Tools::QtCatchCorbaException(S_ex); diff --git a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx index 679a8d853..905ca5f51 100644 --- a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx +++ b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx @@ -83,12 +83,15 @@ namespace SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeName"); SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(theName.toLatin1().data()); + aName->UnRegister(); anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributePixMap"); SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); aPixmap->SetPixMap(thePixmap.toLatin1().data()); + aPixmap->UnRegister(); anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeSelectable"); SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr); aSelAttr->SetSelectable(false); + aSelAttr->UnRegister(); } return aDomainRoot; @@ -126,12 +129,12 @@ namespace //--------------------------------------------------------------- inline SALOMEDS::SObject_var - AddToDomain(const std::string& theIOR, - const SALOMEDS::SComponent_var& theSComponentMesh, + AddToDomain(const std::string& theIOR, + const SALOMEDS::SComponent_var& theSComponentMesh, const SALOMEDS::StudyBuilder_var& theStudyBuilder, - CORBA::Long theDomainRootTag, - const QString& theDomainName, - const QString& theDomainPixmap) + CORBA::Long theDomainRootTag, + const QString& theDomainName, + const QString& theDomainPixmap) { SALOMEDS::SObject_var aDomain = GetDomainRoot(theSComponentMesh, theStudyBuilder, @@ -140,6 +143,7 @@ namespace theDomainPixmap); // Add New Hypothesis SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(aDomain); + aDomain->UnRegister(); SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap"); SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); CORBA::Object_var anObject = StringToObject(theIOR); @@ -147,9 +151,11 @@ namespace CORBA::String_var aType = aDomainItem->GetName(); QString aPixmapName = theDomainPixmap + "_" + aType.in(); aPixmap->SetPixMap(aPixmapName.toLatin1().data()); + aPixmap->UnRegister(); anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR"); SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); anIOR->SetValue(theIOR.c_str()); + anIOR->UnRegister(); return aSObject; } @@ -187,44 +193,52 @@ namespace //--------------------------------------------------------------- void - SetDomain(const char* theMeshOrSubMeshEntry, - const char* theDomainEntry, - const SALOMEDS::Study_var& theStudy, + SetDomain(const char* theMeshOrSubMeshEntry, + const char* theDomainEntry, + const SALOMEDS::Study_var& theStudy, const SALOMEDS::StudyBuilder_var& theStudyBuilder, - long theRefOnAppliedDomainTag, - const QString& theAppliedDomainMEN, - const QString& theAppliedDomainICON) + long theRefOnAppliedDomainTag, + const QString& theAppliedDomainMEN, + const QString& theAppliedDomainICON) { SALOMEDS::SObject_var aMeshOrSubMeshSO = theStudy->FindObjectID(theMeshOrSubMeshEntry); - SALOMEDS::SObject_var aHypothesisSO = theStudy->FindObjectID(theDomainEntry); + SALOMEDS::SObject_var aHypothesisSO = theStudy->FindObjectID(theDomainEntry); if(!aMeshOrSubMeshSO->_is_nil() && !aHypothesisSO->_is_nil()){ //Find or Create Applied Hypothesis root SALOMEDS::SObject_var anAppliedDomainSO; - if(!aMeshOrSubMeshSO->FindSubObject(theRefOnAppliedDomainTag,anAppliedDomainSO)){ + if( !aMeshOrSubMeshSO->FindSubObject( theRefOnAppliedDomainTag, anAppliedDomainSO )) + { anAppliedDomainSO = theStudyBuilder->NewObjectToTag(aMeshOrSubMeshSO,theRefOnAppliedDomainTag); SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributeName"); SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(theAppliedDomainMEN.toLatin1().data()); + aName->UnRegister(); anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributeSelectable"); SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr); aSelAttr->SetSelectable(false); + aSelAttr->UnRegister(); anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributePixMap"); SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); aPixmap->SetPixMap(theAppliedDomainICON.toLatin1().data()); + aPixmap->UnRegister(); } SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(anAppliedDomainSO); theStudyBuilder->Addreference(aSObject,aHypothesisSO); + aSObject->UnRegister(); + anAppliedDomainSO->UnRegister(); } + if ( !aMeshOrSubMeshSO->_is_nil() ) aMeshOrSubMeshSO->UnRegister(); + if ( !aHypothesisSO->_is_nil()) aHypothesisSO->UnRegister(); } //--------------------------------------------------------------- void - SetHypothesis(const char* theMeshOrSubMeshEntry, - const char* theDomainEntry, - const SALOMEDS::Study_var& theStudy, + SetHypothesis(const char* theMeshOrSubMeshEntry, + const char* theDomainEntry, + const SALOMEDS::Study_var& theStudy, const SALOMEDS::StudyBuilder_var& theStudyBuilder) { SetDomain(theMeshOrSubMeshEntry, @@ -239,9 +253,9 @@ namespace //--------------------------------------------------------------- void - SetAlgorithms(const char* theMeshOrSubMeshEntry, - const char* theDomainEntry, - const SALOMEDS::Study_var& theStudy, + SetAlgorithms(const char* theMeshOrSubMeshEntry, + const char* theDomainEntry, + const SALOMEDS::Study_var& theStudy, const SALOMEDS::StudyBuilder_var& theStudyBuilder) { SetDomain(theMeshOrSubMeshEntry, @@ -296,31 +310,36 @@ SMESH_Swig::Init(int theStudyID) { class TEvent: public SALOME_Event { - int myStudyID; - SALOMEDS::Study_var& myStudy; + int myStudyID; + SALOMEDS::Study_var& myStudy; SALOMEDS::StudyBuilder_var& myStudyBuilder; - SALOMEDS::SComponent_var& mySComponentMesh; + SALOMEDS::SComponent_var& mySComponentMesh; public: - TEvent(int theStudyID, - SALOMEDS::Study_var& theStudy, + TEvent(int theStudyID, + SALOMEDS::Study_var& theStudy, SALOMEDS::StudyBuilder_var& theStudyBuilder, - SALOMEDS::SComponent_var& theSComponentMesh): - myStudyID(theStudyID), - myStudy(theStudy), - myStudyBuilder(theStudyBuilder), + SALOMEDS::SComponent_var& theSComponentMesh): + myStudyID (theStudyID), + myStudy (theStudy), + myStudyBuilder (theStudyBuilder), mySComponentMesh(theSComponentMesh) {} + ~TEvent() + { + if ( !mySComponentMesh->_is_nil() ) mySComponentMesh->UnRegister(); + } + virtual void Execute() { - SUIT_Session* aSession = SUIT_Session::session(); + SUIT_Session* aSession = SUIT_Session::session(); SUIT_Application* anApplication = aSession->activeApplication(); - SalomeApp_Application* anApp = dynamic_cast(anApplication); + SalomeApp_Application* anApp = dynamic_cast(anApplication); SALOME_NamingService* aNamingService = anApp->namingService(); - CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager"); + CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager"); SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject); myStudy = aStudyMgr->GetStudyByID(myStudyID); @@ -334,26 +353,33 @@ SMESH_Swig::Init(int theStudyID) SALOMEDS::AttributePixMap_var aPixmap; SALOMEDS::SComponent_var aSComponent = myStudy->FindComponent("SMESH"); - if(aSComponent->_is_nil()){ + if ( aSComponent->_is_nil() ) + { bool aLocked = myStudy->GetProperties()->IsLocked(); if (aLocked) myStudy->GetProperties()->SetLocked(false); - - aSComponent = myStudyBuilder->NewComponent("SMESH"); - anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI(); //SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded - if (!aSMESHGUI){ + SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI(); + //SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded + if (!aSMESHGUI) { CAM_Module* aModule = anApp->module("Mesh"); if(!aModule) - aModule = anApp->loadModule("Mesh"); + aModule = anApp->loadModule("Mesh"); aSMESHGUI = dynamic_cast(aModule); } //SRN: BugID IPAL9186: end of a fix + + aSComponent = myStudyBuilder->NewComponent("SMESH"); + + anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributeName"); + aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(aSMESHGUI->moduleName().toLatin1().data()); + aName->UnRegister(); + anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributePixMap"); aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" ); + aPixmap->UnRegister(); + myStudyBuilder->DefineComponentInstance(aSComponent,aSMESHGen); if (aLocked) myStudy->GetProperties()->SetLocked(true); @@ -388,22 +414,29 @@ const char* SMESH_Swig::AddNewMesh(const char* theIOR) // VSR: added temporarily - to be removed - objects are published automatically by engine SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(theIOR); - if (aSObject->_is_nil()){ + if (aSObject->_is_nil()) + { //Find or Create Hypothesis root - GetHypothesisRoot(mySComponentMesh,myStudyBuilder); - GetAlgorithmsRoot(mySComponentMesh,myStudyBuilder); + SALOMEDS::SObject_var hroot = GetHypothesisRoot(mySComponentMesh,myStudyBuilder); + SALOMEDS::SObject_var aroot = GetAlgorithmsRoot(mySComponentMesh,myStudyBuilder); + hroot->UnRegister(); + aroot->UnRegister(); // Add New Mesh aSObject = myStudyBuilder->NewObject(mySComponentMesh); SALOMEDS::GenericAttribute_var anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap"); SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH" ); + aPixmap->UnRegister(); + anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR"); SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); anIOR->SetValue(theIOR); + anIOR->UnRegister(); } CORBA::String_var anEntry = aSObject->GetID(); + aSObject->UnRegister(); return anEntry._retn(); } @@ -418,6 +451,8 @@ const char* SMESH_Swig::AddNewHypothesis(const char* theIOR) mySComponentMesh, myStudyBuilder); CORBA::String_var anEntry = aSObject->GetID(); + aSObject->UnRegister(); + return anEntry._retn(); } @@ -431,6 +466,8 @@ const char* SMESH_Swig::AddNewAlgorithms(const char* theIOR) mySComponentMesh, myStudyBuilder); CORBA::String_var anEntry = aSObject->GetID(); + aSObject->UnRegister(); + return anEntry._retn(); } @@ -439,13 +476,16 @@ const char* SMESH_Swig::AddNewAlgorithms(const char* theIOR) void SMESH_Swig::SetShape(const char* theShapeEntry, const char* theMeshEntry) { - SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID( theMeshEntry ); SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID( theShapeEntry ); + SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID( theMeshEntry ); if(!aMeshSO->_is_nil() && !aGeomShapeSO->_is_nil()){ SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObjectToTag(aMeshSO, SMESH::Tag_RefOnShape); myStudyBuilder->Addreference(aSObject,aGeomShapeSO); + aSObject->UnRegister(); } + if ( !aMeshSO->_is_nil() ) aMeshSO->UnRegister(); + if ( !aGeomShapeSO->_is_nil() ) aGeomShapeSO->UnRegister(); } @@ -485,49 +525,57 @@ const char* SMESH_Swig::AddSubMesh(const char* theMeshEntry, int theShapeType) { SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID(theMeshEntry); - if(!aMeshSO->_is_nil()){ + if(!aMeshSO->_is_nil()) { long aShapeTag; QString aSubMeshName; - switch(theShapeType){ + switch(theShapeType) { case TopAbs_SOLID: - aShapeTag = SMESH::Tag_SubMeshOnSolid; + aShapeTag = SMESH::Tag_SubMeshOnSolid; aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnSolid"); break; case TopAbs_FACE: - aShapeTag = SMESH::Tag_SubMeshOnFace; + aShapeTag = SMESH::Tag_SubMeshOnFace; aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnFace"); break; case TopAbs_EDGE: - aShapeTag = SMESH::Tag_SubMeshOnEdge; + aShapeTag = SMESH::Tag_SubMeshOnEdge; aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnEdge"); break; case TopAbs_VERTEX: - aShapeTag = SMESH::Tag_SubMeshOnVertex; + aShapeTag = SMESH::Tag_SubMeshOnVertex; aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnVertex"); break; default: - aShapeTag = SMESH::Tag_SubMeshOnCompound; + aShapeTag = SMESH::Tag_SubMeshOnCompound; aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnCompound"); } - SALOMEDS::SObject_var aSubMeshesRoot; SALOMEDS::GenericAttribute_var anAttr; - if(!aMeshSO->FindSubObject(aShapeTag,aSubMeshesRoot)){ + SALOMEDS::SObject_var aSubMeshesRoot; + if ( !aMeshSO->FindSubObject( aShapeTag, aSubMeshesRoot ) ) + { aSubMeshesRoot = myStudyBuilder->NewObjectToTag(aMeshSO,aShapeTag); anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeName"); SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(aSubMeshName.toLatin1().data()); + aName->UnRegister(); anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeSelectable"); SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr); aSelAttr->SetSelectable(false); + aSelAttr->UnRegister(); } + aSubMeshesRoot->UnRegister(); + aMeshSO->UnRegister(); SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObject(aSubMeshesRoot); anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR"); SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); anIOR->SetValue(theSubMeshIOR); + anIOR->UnRegister(); CORBA::String_var aString = aSObject->GetID(); + aSObject->UnRegister(); + return aString._retn(); } @@ -537,17 +585,20 @@ const char* SMESH_Swig::AddSubMesh(const char* theMeshEntry, const char* SMESH_Swig::AddSubMeshOnShape(const char* theMeshEntry, const char* theGeomShapeEntry, const char* theSubMeshIOR, - int ShapeType) + int ShapeType) { SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID(theGeomShapeEntry); - if(!aGeomShapeSO->_is_nil()){ - const char * aSubMeshEntry = AddSubMesh(theMeshEntry,theSubMeshIOR,ShapeType); + if(!aGeomShapeSO->_is_nil()) + { + const char * aSubMeshEntry = AddSubMesh(theMeshEntry,theSubMeshIOR,ShapeType); SALOMEDS::SObject_var aSubMeshSO = myStudy->FindObjectID(aSubMeshEntry); - if(!aSubMeshSO->_is_nil()){ - SetShape(theGeomShapeEntry,aSubMeshEntry); + if ( !aSubMeshSO->_is_nil()) { + SetShape( theGeomShapeEntry, aSubMeshEntry ); CORBA::String_var aString = aSubMeshSO->GetID(); + aSubMeshSO->UnRegister(); return aString._retn(); } + aGeomShapeSO->UnRegister(); } return ""; @@ -566,11 +617,11 @@ void SMESH_Swig::CreateAndDisplayActor( const char* Mesh_Entry ) } virtual void Execute() { //SMESH::UpdateView(SMESH::eDisplay, _entry); - SUIT_Session* aSession = SUIT_Session::session(); + SUIT_Session* aSession = SUIT_Session::session(); SUIT_Application* anApplication = aSession->activeApplication(); - SalomeApp_Application* anApp = dynamic_cast(anApplication); - /*SUIT_ViewManager* vman = */anApp->getViewManager(VTKViewer_Viewer::Type(),true); - SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp); + SalomeApp_Application* anApp = dynamic_cast(anApplication); + /*SUIT_ViewManager* vman = */anApp->getViewManager(VTKViewer_Viewer::Type(),true); + SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp); aDisp->Display(_entry,1); } }; @@ -584,31 +635,31 @@ void SMESH_Swig::EraseActor( const char* Mesh_Entry, const bool allViewers ) { private: const char* _entry; - bool _allViewers; + bool _allViewers; public: TEvent(const char* Mesh_Entry, const bool allViewers ) { _entry = Mesh_Entry; _allViewers = allViewers; } virtual void Execute() { - SUIT_Session* aSession = SUIT_Session::session(); + SUIT_Session* aSession = SUIT_Session::session(); SUIT_Application* anApplication = aSession->activeApplication(); - SalomeApp_Application* anApp = dynamic_cast(anApplication); - SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp); + SalomeApp_Application* anApp = dynamic_cast(anApplication); + SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp); ViewManagerList aManagers; if ( !_allViewers ) { - aManagers << anApp->activeViewManager(); + aManagers << anApp->activeViewManager(); } else { - aManagers = anApp->viewManagers(); + aManagers = anApp->viewManagers(); } foreach( SUIT_ViewManager* aMgr, aManagers ) { - if ( aMgr && aMgr->getType() == VTKViewer_Viewer::Type() ) { - SALOME_View* aSalomeView = dynamic_cast(aMgr->getViewModel()); - if (aSalomeView) { - aDisp->Erase(_entry,true, true, aSalomeView); - } - } + if ( aMgr && aMgr->getType() == VTKViewer_Viewer::Type() ) { + SALOME_View* aSalomeView = dynamic_cast(aMgr->getViewModel()); + if (aSalomeView) { + aDisp->Erase(_entry,true, true, aSalomeView); + } + } } } }; @@ -626,6 +677,8 @@ void SMESH_Swig::SetName(const char* theEntry, anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName"); aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(theName); + aName->UnRegister(); + aSObject->UnRegister(); } } @@ -638,33 +691,33 @@ void SMESH_Swig::SetName(const char* theEntry, //================================================================================ void SMESH_Swig::SetMeshIcon(const char* theMeshEntry, - const bool theIsComputed, - const bool isEmpty) + const bool theIsComputed, + const bool isEmpty) { class TEvent: public SALOME_Event { SALOMEDS::Study_var myStudy; - std::string myMeshEntry; - bool myIsComputed, myIsEmpty; + std::string myMeshEntry; + bool myIsComputed, myIsEmpty; public: TEvent(const SALOMEDS::Study_var& theStudy, - const std::string& theMeshEntry, - const bool theIsComputed, - const bool isEmpty): - myStudy(theStudy), - myMeshEntry(theMeshEntry), + const std::string& theMeshEntry, + const bool theIsComputed, + const bool isEmpty): + myStudy (theStudy), + myMeshEntry (theMeshEntry), myIsComputed(theIsComputed), - myIsEmpty(isEmpty) + myIsEmpty (isEmpty) {} virtual void Execute() { - SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID(myMeshEntry.c_str()); - if(!aMeshSO->_is_nil()) - if(_PTR(SObject) aMesh = ClientFactory::SObject(aMeshSO)) - SMESH::ModifiedMesh(aMesh,myIsComputed,myIsEmpty); + SALOMEDS::SObject_ptr aMeshSO = myStudy->FindObjectID(myMeshEntry.c_str()); + if(_PTR(SObject) aMesh = ClientFactory::SObject(aMeshSO)) + SMESH::ModifiedMesh(aMesh,myIsComputed,myIsEmpty); + // aMeshSO->UnRegister(); ~aMesh() already called UnRegister()! } }; diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx index 0a033c033..ac7fa4dfa 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx @@ -42,6 +42,8 @@ #include +#include + // SALOME GUI includes #include @@ -418,7 +420,7 @@ bool StdMeshersGUI_StdHypothesisCreator::checkParams( QString& msg ) const GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen(); _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - GEOM::GEOM_IShapesOperations_var shapeOp; + GEOM::GEOM_IShapesOperations_wrap shapeOp; if ( !geomGen->_is_nil() && aStudy ) shapeOp = geomGen->GetIShapesOperations( aStudy->StudyId() ); if ( !shapeOp->_is_nil() ) diff --git a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx index 637163f66..a8be8c08c 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx @@ -68,9 +68,6 @@ #include #include -// SALOME KERNEL includes -#include - #define SPACING 6 #define MARGIN 0 @@ -470,18 +467,17 @@ GEOM::GEOM_Object_var StdMeshersGUI_SubShapeSelectorWdg::GetGeomObjectByEntry( c { GEOM::GEOM_Object_var aGeomObj; SALOMEDS::Study_var aStudy = SMESHGUI::GetSMESHGen()->GetCurrentStudy(); - if (aStudy != 0) { + if ( !aStudy->_is_nil() ) + { SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( theEntry.toLatin1().data() ); - SALOMEDS::GenericAttribute_var anAttr; - - if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) { - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::String_var aVal = anIOR->Value(); - CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal); + if (!aSObj->_is_nil() ) + { + CORBA::Object_var obj = aSObj->GetObject(); aGeomObj = GEOM::GEOM_Object::_narrow(obj); + aSObj->UnRegister(); } } - return aGeomObj; + return aGeomObj._retn(); } //================================================================================= diff --git a/src/StdMeshers_I/StdMeshers_ImportSource1D_i.cxx b/src/StdMeshers_I/StdMeshers_ImportSource1D_i.cxx index e2ad32141..cf6eb6986 100644 --- a/src/StdMeshers_I/StdMeshers_ImportSource1D_i.cxx +++ b/src/StdMeshers_I/StdMeshers_ImportSource1D_i.cxx @@ -32,8 +32,9 @@ #include "SMESH_PythonDump.hxx" #include "StdMeshers_ObjRefUlils.hxx" -#include "Utils_CorbaException.hxx" -#include "utilities.h" +#include +#include +#include #include @@ -97,7 +98,7 @@ void StdMeshers_ImportSource1D_i::SetSourceEdges(const SMESH::ListOfGroups& grou THROW_SALOME_CORBA_EXCEPTION("Wrong group type", SALOME::BAD_PARAM); smesh_groups.push_back( gp_i->GetSmeshGroup() ); - SALOMEDS::SObject_var so = SMESH_Gen_i::GetSMESHGen()->ObjectToSObject(study, groups[i]); + SALOMEDS::SObject_wrap so = SMESH_Gen_i::ObjectToSObject(study, groups[i]); if ( !so->_is_nil()) { CORBA::String_var entry = so->GetID(); @@ -178,8 +179,8 @@ char* StdMeshers_ImportSource1D_i::SaveTo() os << " " << _groupEntries[i]; // id - SALOMEDS::SObject_var groupSO = study->FindObjectID( _groupEntries[i] ); - CORBA::Object_var groupObj; + SALOMEDS::SObject_wrap groupSO = study->FindObjectID( _groupEntries[i] ); + CORBA::Object_var groupObj; if ( !groupSO->_is_nil() ) groupObj = groupSO->GetObject(); StdMeshers_ObjRefUlils::SaveToStream( groupObj, os ); diff --git a/src/StdMeshers_I/StdMeshers_ImportSource2D_i.cxx b/src/StdMeshers_I/StdMeshers_ImportSource2D_i.cxx index 35f9d3fb0..29d14804d 100644 --- a/src/StdMeshers_I/StdMeshers_ImportSource2D_i.cxx +++ b/src/StdMeshers_I/StdMeshers_ImportSource2D_i.cxx @@ -97,11 +97,12 @@ void StdMeshers_ImportSource2D_i::SetSourceFaces(const SMESH::ListOfGroups& grou THROW_SALOME_CORBA_EXCEPTION("Wrong group type", SALOME::BAD_PARAM); smesh_groups.push_back( gp_i->GetSmeshGroup() ); - SALOMEDS::SObject_var so = SMESH_Gen_i::GetSMESHGen()->ObjectToSObject(study, groups[i]); + SALOMEDS::SObject_var so = SMESH_Gen_i::ObjectToSObject(study, groups[i]); if ( !so->_is_nil()) { CORBA::String_var entry = so->GetID(); entries.push_back( entry.in() ); + so->UnRegister(); } } this->GetImpl()->SetGroups( smesh_groups ); @@ -179,9 +180,11 @@ char* StdMeshers_ImportSource2D_i::SaveTo() // id SALOMEDS::SObject_var groupSO = study->FindObjectID( _groupEntries[i] ); - CORBA::Object_var groupObj; - if ( !groupSO->_is_nil() ) + CORBA::Object_var groupObj; + if ( !groupSO->_is_nil() ) { groupObj = groupSO->GetObject(); + groupSO->UnRegister(); + } StdMeshers_ObjRefUlils::SaveToStream( groupObj, os ); } diff --git a/src/StdMeshers_I/StdMeshers_LayerDistribution_i.cxx b/src/StdMeshers_I/StdMeshers_LayerDistribution_i.cxx index e162f22aa..0d4381be1 100644 --- a/src/StdMeshers_I/StdMeshers_LayerDistribution_i.cxx +++ b/src/StdMeshers_I/StdMeshers_LayerDistribution_i.cxx @@ -88,11 +88,16 @@ void StdMeshers_LayerDistribution_i::SetLayerDistribution(SMESH::SMESH_Hypothesi this->GetImpl()->SetLayerDistribution( hyp_i->GetImpl() ); myHyp = SMESH::SMESH_Hypothesis::_duplicate( hyp1D ); // Remove SO of 1D hypothesis if it was published - if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) { + if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) + { SALOMEDS::Study_var study = gen->GetCurrentStudy(); - SALOMEDS::SObject_var SO = gen->ObjectToSObject( study, hyp1D ); + SALOMEDS::SObject_var SO = gen->ObjectToSObject( study, hyp1D ); if ( ! SO->_is_nil() ) - study->NewBuilder()->RemoveObjectWithChildren( SO ); + { + SALOMEDS::StudyBuilder_var builder = study->NewBuilder(); + builder->RemoveObjectWithChildren( SO ); + SO->UnRegister(); + } } // Update Python script: write creation of 1D hyp as it is not published and // for this, SMESH_Gen does not write it's creation diff --git a/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx b/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx index 910d0aaa8..390bd34c5 100644 --- a/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx +++ b/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx @@ -27,6 +27,7 @@ // #include "StdMeshers_ObjRefUlils.hxx" +#include #include using namespace std; @@ -60,8 +61,8 @@ StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject (const std::string& theEntry, if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) { SALOMEDS::Study_var study = gen->GetCurrentStudy(); if ( ! theEntry.empty() && ! study->_is_nil() ) { - SALOMEDS::SObject_var sobj= study->FindObjectID( theEntry.c_str() ); - CORBA::Object_var obj = gen->SObjectToObject( sobj ); + SALOMEDS::SObject_wrap sobj = study->FindObjectID( theEntry.c_str() ); + CORBA::Object_var obj = gen->SObjectToObject( sobj ); geom = GEOM::GEOM_Object::_narrow( obj ); } } @@ -87,9 +88,10 @@ void StdMeshers_ObjRefUlils::SaveToStream( const TopoDS_Shape& theShape, ostream if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) { GEOM::GEOM_Object_var geom = gen->ShapeToGeomObject( theShape ); if ( ! geom->_is_nil() ) { - SALOMEDS::SObject_var sobj = gen->ObjectToSObject( gen->GetCurrentStudy(), geom ); + SALOMEDS::SObject_wrap sobj = gen->ObjectToSObject( gen->GetCurrentStudy(), geom ); if ( !sobj->_is_nil() ) { - stream << " " << sobj->GetID(); + CORBA::String_var entry = sobj->GetID(); + stream << " " << entry.in(); ok = true; } } @@ -114,9 +116,9 @@ TopoDS_Shape StdMeshers_ObjRefUlils::LoadFromStream( istream & stream) if ( ! study->_is_nil() ) { string str; if (stream >> str) { - SALOMEDS::SObject_var sobj= study->FindObjectID( str.c_str() ); - CORBA::Object_var obj = gen->SObjectToObject( sobj ); - GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( obj ); + SALOMEDS::SObject_wrap sobj = study->FindObjectID( str.c_str() ); + CORBA::Object_var obj = gen->SObjectToObject( sobj ); + GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( obj ); return gen->GeomObjectToShape( geom.in() ); } } -- 2.39.2