remove some memory leaks

This commit is contained in:
eap 2012-04-27 13:01:23 +00:00
parent b787ff461b
commit 3305acaefc

View File

@ -487,21 +487,16 @@ static TopoDS_Shape getShapeByName( const char* theName )
{ {
if ( theName != 0 ) if ( theName != 0 )
{ {
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy(); SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
if (!CORBA::is_nil(aStudy)) if ( !aStudy->_is_nil() )
{ {
SALOMEDS::Study::ListOfSObject_var aList = SALOMEDS::Study::ListOfSObject_var aList = aStudy->FindObjectByName( theName, "GEOM" );
aStudy->FindObjectByName( theName, "GEOM" );
if ( aList->length() > 0 ) if ( aList->length() > 0 )
{ {
GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() ); SALOMEDS::SObject_var aSObj = aList[ 0 ].in();
if ( !aGeomObj->_is_nil() ) GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aSObj );
{ return aSMESHGen->GeomObjectToShape( aGeomObj );
GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
return aLocShape;
}
} }
} }
} }
@ -510,48 +505,35 @@ static TopoDS_Shape getShapeByName( const char* theName )
static TopoDS_Shape getShapeByID (const char* theID) static TopoDS_Shape getShapeByID (const char* theID)
{ {
if (theID != 0 && theID != "") { if ( theID && strlen( theID ) > 0 ) {
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy(); SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
if (aStudy != 0) { if ( !aStudy->_is_nil() ) {
SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID); SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
SALOMEDS::GenericAttribute_var anAttr; if ( !aSObj->_is_nil() ) {
if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) { CORBA::Object_var obj = aSObj->GetObject();
SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
CORBA::String_var aVal = anIOR->Value();
CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal);
GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj); GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
return aSMESHGen->GeomObjectToShape( aGeomObj );
if (!aGeomObj->_is_nil()) {
GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
return aLocShape;
}
} }
} }
} }
return TopoDS_Shape(); return TopoDS_Shape();
} }
static char* getShapeNameByID (const char* theID) static std::string getShapeNameByID (const char* theID)
{ {
char* aName = (char*)""; if ( theID && strlen( theID ) > 0 ) {
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
if (theID != 0 && theID != "") { SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); if ( !aStudy->_is_nil() ) {
SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
if (aStudy != 0) {
//SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID); SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
SALOMEDS::GenericAttribute_var anAttr; if ( !aSObj->_is_nil() ) {
if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeName")) { CORBA::String_var name = aSObj->GetName();
SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr); return name.in();
aName = aNameAttr->Value();
} }
} }
} }
return "";
return aName;
} }
/* /*
@ -1064,7 +1046,7 @@ void BelongToGeom_i::SetShape( const char* theID, const char* theName )
else else
myShapeID = 0; myShapeID = 0;
if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 ) if ( myShapeID && myShapeName == getShapeNameByID(myShapeID))
myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) ); myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
else else
myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) ); myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
@ -1149,7 +1131,7 @@ void BelongToSurface_i::SetShape( const char* theID, const char* theName, Eleme
else else
myShapeID = 0; myShapeID = 0;
if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 ) if ( myShapeID && myShapeName == getShapeNameByID(myShapeID))
myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType ); myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
else else
myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType ); myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
@ -1319,7 +1301,7 @@ void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
else else
myShapeID = 0; myShapeID = 0;
if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 ) if ( myShapeID && myShapeName == getShapeNameByID(myShapeID))
myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) ); myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
else else
myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) ); myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );