]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
To improve perfomance of the data model / object browser update functionality. Now...
authorapo <apo@opencascade.com>
Fri, 9 Dec 2005 11:43:34 +0000 (11:43 +0000)
committerapo <apo@opencascade.com>
Fri, 9 Dec 2005 11:43:34 +0000 (11:43 +0000)
src/LightApp/LightApp_Module.cxx
src/SalomeApp/SalomeApp_DataModel.cxx

index 46d3f82afbba36a87b47afa7317d9a1e08445b21..dfa6cc6c53b75e095cefbba51eef4ff60b3377f5 100644 (file)
@@ -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<LightApp_DataModel*>( aDataModel ) )
-        aModel->update( 0, dynamic_cast<LightApp_Study*>( 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<LightApp_DataModel*>( aDataModel ) ) {
+       LightApp_DataObject* anObject = dynamic_cast<LightApp_DataObject*>(theDataObject);
+       SUIT_DataObject* aParent = anObject->parent();
+        aModel->update( anObject, dynamic_cast<LightApp_Study*>( getApp()->activeStudy() ) );
+       if(aParent && aParent->childPos(anObject) < 0)
+         aDataObject = dynamic_cast<LightApp_DataObject*>(aParent);
+      }
+    }
+  }
+  getApp()->objectBrowser()->updateTree( aDataObject );
 }
 
 /*!NOT IMPLEMENTED*/
index 48838709e699d2e121c6fe543d203a8f195be362..1b2995e9b664ba846532f733f88d58ef87411437 100644 (file)
@@ -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<SalomeApp_Study*>(study);
-  LightApp_RootObject* studyRoot = 0;
-  _PTR(SObject) sobj;
-  SalomeApp_DataObject* modelRoot = dynamic_cast<SalomeApp_DataObject*>( root() );
-  if ( !modelRoot ){ // not yet connected to a study -> try using <study> 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<LightApp_DataObject*>(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<SalomeApp_Study*>(theStudy);
+  _PTR(SObject) aSObject;
+  LightApp_RootObject* aRootObject = NULL;
+  SalomeApp_DataObject* aModelRoot = dynamic_cast<SalomeApp_DataObject*>( root() );
+  if ( !aModelRoot ){ // not yet connected to a study -> try using <study> argument
     if ( !aSStudy )
       aSStudy = dynamic_cast<SalomeApp_Study*>( getModule()->getApp()->activeStudy() );
     if ( aSStudy ){
-      studyRoot = dynamic_cast<LightApp_RootObject*>( aSStudy->root() );
+      aRootObject = dynamic_cast<LightApp_RootObject*>( 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<LightApp_RootObject*>( modelRoot->root() );
-    if ( studyRoot ) {
-      aSStudy = dynamic_cast<SalomeApp_Study*>( studyRoot->study() ); // <study> value should not change here theoretically, but just to make sure
+    aRootObject = dynamic_cast<LightApp_RootObject*>( aModelRoot->root() );
+    if ( aRootObject ) {
+      aSStudy = dynamic_cast<SalomeApp_Study*>( aRootObject->study() ); // <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);
+    }
+  }
 }
 
 //================================================================