From aef415754bb4db257b9ee7fbd75d3a5dd6505b53 Mon Sep 17 00:00:00 2001 From: apo Date: Fri, 9 Dec 2005 11:43:34 +0000 Subject: [PATCH] To improve perfomance of the data model / object browser update functionality. Now given SUIT_DataObject is taken into account. --- src/LightApp/LightApp_Module.cxx | 24 +++++--- src/SalomeApp/SalomeApp_DataModel.cxx | 79 ++++++++++++++++++++++----- 2 files changed, 82 insertions(+), 21 deletions(-) diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 46d3f82af..dfa6cc6c5 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -9,6 +9,7 @@ #include "LightApp_Application.h" #include "LightApp_DataModel.h" +#include "LightApp_DataObject.h" #include "LightApp_Study.h" #include "LightApp_Preferences.h" #include "LightApp_Selection.h" @@ -92,13 +93,22 @@ void LightApp_Module::contextMenuPopup( const QString& client, QPopupMenu* menu, /*!Update object browser. * For updating model or whole object browser use update() method can be used. */ -void LightApp_Module::updateObjBrowser( bool updateDataModel, SUIT_DataObject* root ) -{ - if( updateDataModel ) - if( CAM_DataModel* aDataModel = dataModel() ) - if( LightApp_DataModel* aModel = dynamic_cast( aDataModel ) ) - aModel->update( 0, dynamic_cast( getApp()->activeStudy() ) ); - getApp()->objectBrowser()->updateTree( root ); +void LightApp_Module::updateObjBrowser( bool theIsUpdateDataModel, + SUIT_DataObject* theDataObject ) +{ + SUIT_DataObject* aDataObject = theDataObject; + if( theIsUpdateDataModel ){ + if( CAM_DataModel* aDataModel = dataModel() ){ + if ( LightApp_DataModel* aModel = dynamic_cast( aDataModel ) ) { + LightApp_DataObject* anObject = dynamic_cast(theDataObject); + SUIT_DataObject* aParent = anObject->parent(); + aModel->update( anObject, dynamic_cast( getApp()->activeStudy() ) ); + if(aParent && aParent->childPos(anObject) < 0) + aDataObject = dynamic_cast(aParent); + } + } + } + getApp()->objectBrowser()->updateTree( aDataObject ); } /*!NOT IMPLEMENTED*/ diff --git a/src/SalomeApp/SalomeApp_DataModel.cxx b/src/SalomeApp/SalomeApp_DataModel.cxx index 48838709e..1b2995e9b 100644 --- a/src/SalomeApp/SalomeApp_DataModel.cxx +++ b/src/SalomeApp/SalomeApp_DataModel.cxx @@ -132,36 +132,87 @@ bool SalomeApp_DataModel::open( const QString& name, CAM_Study* study, QStringLi // Function : update /*! Purpose : Update application.*/ //================================================================ -void SalomeApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study ) +namespace { - SalomeApp_Study* aSStudy = dynamic_cast(study); - LightApp_RootObject* studyRoot = 0; - _PTR(SObject) sobj; - SalomeApp_DataObject* modelRoot = dynamic_cast( root() ); - if ( !modelRoot ){ // not yet connected to a study -> try using argument + LightApp_DataObject* FindDataObject(const _PTR(SObject)& theSObject, + SUIT_DataObject* theDataObject) + { + std::string anID = theSObject->GetID(); + DataObjectList aList; + theDataObject->children(aList); + DataObjectListIterator aDataObjectIter(aList); + while(SUIT_DataObject* aDataObject = aDataObjectIter.current()){ + if(LightApp_DataObject* aChildDataObject = dynamic_cast(aDataObject)){ + QString anEntry = aChildDataObject->entry(); + if(anID == anEntry.latin1()) + return aChildDataObject; + } + ++aDataObjectIter; + } + return NULL; + } + + void BuildTree(const _PTR(SObject)& theSObject, + SUIT_DataObject* theDataObject, + const _PTR(Study)& theStudyDS) + { + _PTR(ChildIterator) aSObjectIter(theStudyDS->NewChildIterator(theSObject)); + for(; aSObjectIter->More(); aSObjectIter->Next()){ + _PTR(SObject) aChildSObject(aSObjectIter->Value()); + std::string aName = aChildSObject->GetName(); + if(aName.empty()) + continue; + SUIT_DataObject* aChildDataObject = FindDataObject(aChildSObject,theDataObject); + if(!aChildDataObject) + aChildDataObject = new SalomeApp_DataObject(aChildSObject,theDataObject); + BuildTree(aChildSObject,aChildDataObject,theStudyDS); + } + } +} + +void SalomeApp_DataModel::update( LightApp_DataObject* theDataObject, LightApp_Study* theStudy ) +{ + SalomeApp_Study* aSStudy = dynamic_cast(theStudy); + _PTR(SObject) aSObject; + LightApp_RootObject* aRootObject = NULL; + SalomeApp_DataObject* aModelRoot = dynamic_cast( root() ); + if ( !aModelRoot ){ // not yet connected to a study -> try using argument if ( !aSStudy ) aSStudy = dynamic_cast( getModule()->getApp()->activeStudy() ); if ( aSStudy ){ - studyRoot = dynamic_cast( aSStudy->root() ); + aRootObject = dynamic_cast( aSStudy->root() ); QString anId = getRootEntry( aSStudy ); if ( !anId.isEmpty() ){ // if nothing is published in the study for this module -> do nothing _PTR(Study) aStudy ( aSStudy->studyDS() ); - sobj = aStudy->FindComponentID( std::string( anId.latin1() ) ); + aSObject = aStudy->FindComponentID( std::string( anId.latin1() ) ); } } } else{ - studyRoot = dynamic_cast( modelRoot->root() ); - if ( studyRoot ) { - aSStudy = dynamic_cast( studyRoot->study() ); // value should not change here theoretically, but just to make sure + aRootObject = dynamic_cast( aModelRoot->root() ); + if ( aRootObject ) { + aSStudy = dynamic_cast( aRootObject->study() ); // value should not change here theoretically, but just to make sure if ( aSStudy ) { _PTR(Study) aStudy ( aSStudy->studyDS() ); - // modelRoot->object() cannot be reused here: it is about to be deleted by buildTree() soon - sobj = aStudy->FindComponentID( std::string( modelRoot->entry().latin1() ) ); + // aModelRoot->object() cannot be reused here: it is about to be deleted by buildTree() soon + aSObject = aStudy->FindComponentID( aModelRoot->entry().latin1() ); } } } - buildTree( sobj, studyRoot, aSStudy ); + if(!theDataObject) + buildTree( aSObject, aRootObject, aSStudy ); + else{ + _PTR(Study) aStudyDS(aSStudy->studyDS()); + QString anEntry = theDataObject->entry(); + if(_PTR(SObject) aSObject = aStudyDS->FindObjectID(anEntry.latin1())){ + std::string aName = aSObject->GetName(); + if(aName.empty()){ + if(SUIT_DataObject* aParentDataObject = theDataObject->parent()) + aParentDataObject->removeChild(theDataObject); + }else + ::BuildTree(aSObject,theDataObject,aStudyDS); + } + } } //================================================================ -- 2.39.2