NPAL18604: Pb. of performance with MakeVertex. Fixed memory leak and improved OCAF data management for particular case.

This commit is contained in:
jfa 2008-01-24 12:29:08 +00:00
parent c91537be6b
commit e673545f08
3 changed files with 46 additions and 12 deletions

View File

@ -114,6 +114,7 @@ GEOM_Engine::GEOM_Engine()
_OCAFApp = new GEOM_Application();
_UndoLimit = 10;
_lastObjectTag = 0;
}
//=============================================================================
@ -176,18 +177,34 @@ Handle(GEOM_Object) GEOM_Engine::GetObject(int theDocID, char* theEntry)
//=============================================================================
Handle(GEOM_Object) GEOM_Engine::AddObject(int theDocID, int theType)
{
Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main());
Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main());
TDF_Label aChild = TDF_TagSource::NewChild(aDoc->Main());
Handle(GEOM_Object) anObject = new GEOM_Object(aChild, theType);
//TDF_Label aChild = TDF_TagSource::NewChild(aDoc->Main());
// NPAL18604: use existing label to decrease memory usage,
// if this label has been freed (object deleted)
bool useExisting = false;
TDF_Label aChild;
if (_lastObjectTag > 0) {
aChild = aDoc->Main().FindChild(_lastObjectTag, Standard_False);
if (!aChild.IsAttribute(TDataStd_TreeNode::GetDefaultTreeID())) {
useExisting = true;
}
}
if (!useExisting) {
// create new label
aChild = TDF_TagSource::NewChild(aDoc->Main());
_lastObjectTag = aChild.Tag();
}
//Put an object in the map of created objects
TCollection_AsciiString anID = BuildIDFromObject(anObject);
if(_objects.IsBound(anID)) _objects.UnBind(anID);
_objects.Bind(anID, anObject);
Handle(GEOM_Object) anObject = new GEOM_Object(aChild, theType);
return anObject;
//Put an object in the map of created objects
TCollection_AsciiString anID = BuildIDFromObject(anObject);
if(_objects.IsBound(anID)) _objects.UnBind(anID);
_objects.Bind(anID, anObject);
return anObject;
}
//=============================================================================
@ -204,7 +221,22 @@ Handle(GEOM_Object) GEOM_Engine::AddSubShape(Handle(GEOM_Object) theMainShape,
Handle(TDocStd_Document) aDoc = GetDocument(theMainShape->GetDocID());
Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main());
TDF_Label aChild = TDF_TagSource::NewChild(aDoc->Main());
//TDF_Label aChild = TDF_TagSource::NewChild(aDoc->Main());
// NPAL18604: use existing label to decrease memory usage,
// if this label has been freed (object deleted)
bool useExisting = false;
TDF_Label aChild;
if (_lastObjectTag > 0) {
aChild = aDoc->Main().FindChild(_lastObjectTag, Standard_False);
if (!aChild.IsAttribute(TDataStd_TreeNode::GetDefaultTreeID())) {
useExisting = true;
}
}
if (!useExisting) {
// create new label
aChild = TDF_TagSource::NewChild(aDoc->Main());
_lastObjectTag = aChild.Tag();
}
Handle(GEOM_Function) aMainShape = theMainShape->GetLastFunction();
Handle(GEOM_Object) anObject = new GEOM_Object(aChild, 28); //28 is SUBSHAPE type

View File

@ -101,6 +101,8 @@ class GEOM_Engine
GEOM_DataMapOfAsciiStringTransient _objects;
Resource_DataMapOfAsciiStringAsciiString _studyEntry2NameMap;
int _lastObjectTag;
};
#endif

View File

@ -114,7 +114,7 @@ void GEOM_IOperations_i::FinishOperation()
//=============================================================================
/*!
* AboutOperation
* AbortOperation
*/
//=============================================================================
void GEOM_IOperations_i::AbortOperation()
@ -132,6 +132,6 @@ GEOM::GEOM_Object_ptr GEOM_IOperations_i::GetObject(Handle(GEOM_Object) theObjec
if(theObject.IsNull()) return NULL;
TCollection_AsciiString anEntry;
TDF_Tool::Entry(theObject->GetEntry(), anEntry);
GEOM::GEOM_Object_var GO = GEOM::GEOM_Object::_duplicate(_engine->GetObject(theObject->GetDocID(), anEntry.ToCString()));
GEOM::GEOM_Object_var GO = _engine->GetObject(theObject->GetDocID(), anEntry.ToCString());
return GO._retn();
}