From: nge Date: Thu, 3 Jun 2010 17:43:02 +0000 (+0000) Subject: Draft : First version of Observer on GUI Side X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bfd13e1a72df675545055b40302270afc8c1ba1b;p=modules%2Fgui.git Draft : First version of Observer on GUI Side Seems Ok except Pixmap in object browser --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index b1b027d92..ccfe56574 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -1211,8 +1211,11 @@ PyConsole_Console* LightApp_Application::pythonConsole() Updates object browser and maybe data models \param updateModels - if it is true, then data models are updated */ +#include "utilities.h" void LightApp_Application::updateObjectBrowser( const bool updateModels ) { + MESSAGE("Update from LightApp_Application"); + /* // update existing data models if ( updateModels ) { @@ -1240,6 +1243,7 @@ void LightApp_Application::updateObjectBrowser( const bool updateModels ) objectBrowser()->updateGeometry(); objectBrowser()->updateTree( 0, false ); } + */ } /*! diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 118fc9db4..1702acc3f 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -145,9 +145,12 @@ void LightApp_Module::contextMenuPopup( const QString& client, QMenu* menu, QStr /*!Update object browser. * For updating model or whole object browser use update() method can be used. */ +#include "utilities.h" void LightApp_Module::updateObjBrowser( bool theIsUpdateDataModel, SUIT_DataObject* theDataObject ) { + MESSAGE("Update from LightApp_Module"); + /* bool upd = getApp()->objectBrowser()->autoUpdate(); getApp()->objectBrowser()->setAutoUpdate( false ); @@ -167,6 +170,7 @@ void LightApp_Module::updateObjBrowser( bool theIsUpdateDataModel, getApp()->objectBrowser()->setAutoUpdate( upd ); getApp()->objectBrowser()->updateTree( 0, false ); +*/ } /*!NOT IMPLEMENTED*/ diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx index d4ec696a8..c88808ba3 100644 --- a/src/SUIT/SUIT_DataBrowser.cxx +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -25,6 +25,7 @@ #include #include +#include /*! \class SUIT_DataBrowser @@ -123,7 +124,8 @@ void SUIT_DataBrowser::setAutoUpdate( const bool on ) \param autoOpen if \c true automatically open branches */ void SUIT_DataBrowser::updateTree( SUIT_DataObject* obj, const bool autoOpen ) -{ +{ + std::cerr << " updateTree from SUIT_DataBrowser" << std::endl; SUIT_ProxyModel* m = qobject_cast( model() ); if ( m ) { m->updateTree( obj ); diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index 71211f3ca..a3110feea 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -1172,6 +1172,7 @@ SUIT_DataObject* SUIT_TreeModel::object( const SUIT_TreeModel::TreeItem* item ) return myItems.contains( obj ) ? obj : 0; } +#include /*! \brief Create an item corresponding to the data object. \param obj source data object @@ -1183,6 +1184,7 @@ SUIT_TreeModel::TreeItem* SUIT_TreeModel::createItem( SUIT_DataObject* obj, SUIT_TreeModel::TreeItem* parent, SUIT_TreeModel::TreeItem* after ) { + std::cerr << " SUIT_TreeModel::createItem " << std::endl; if ( !obj ) return 0; @@ -1207,6 +1209,8 @@ SUIT_TreeModel::TreeItem* SUIT_TreeModel::createItem( SUIT_DataObject* obj, */ void SUIT_TreeModel::updateItem( SUIT_TreeModel::TreeItem* item ) { + + std::cerr << " SUIT_TreeModel::updateItem " << std::endl; if ( !item ) return; @@ -1220,12 +1224,30 @@ void SUIT_TreeModel::updateItem( SUIT_TreeModel::TreeItem* item ) emit dataChanged( firstIdx, lastIdx ); } +/*! + \brief Update tree item from the data object + \param item the Data Object to be updated +*/ +void SUIT_TreeModel::updateItem( SUIT_DataObject* obj) +{ + std::cerr << " SUIT_TreeModel::updateItem from SuitObj " << std::endl; + if ( !treeItem(obj)) + return; + + // update all columns corresponding to the given data object + QModelIndex firstIdx = index( obj, 0 ); + QModelIndex lastIdx = index( obj, columnCount() - 1 ); + emit dataChanged( firstIdx, lastIdx ); +} + + /*! \brief Remove tree item (recursively). \param item tree item to be removed */ void SUIT_TreeModel::removeItem( SUIT_TreeModel::TreeItem* item ) { + std::cerr << " SUIT_TreeModel::removeItem " << std::endl; if ( !item ) return; @@ -1456,8 +1478,10 @@ QAbstractItemDelegate* SUIT_ProxyModel::delegate() const \param index starting index for the updating \sa setAutoUpdate() */ +#include void SUIT_ProxyModel::updateTree( const QModelIndex& index ) { + std::cerr << "updateTree with QModelIndex from SUIT_ProxyModel" << std::endl; if ( treeModel() ) treeModel()->updateTree( mapToSource( index ) ); } @@ -1474,10 +1498,18 @@ void SUIT_ProxyModel::updateTree( const QModelIndex& index ) */ void SUIT_ProxyModel::updateTree( SUIT_DataObject* obj ) { + std::cerr << "updateTree with SUIT_DataObj from SUIT_ProxyModel" << std::endl; if ( treeModel() ) treeModel()->updateTree( obj ); } +void SUIT_ProxyModel::updateItem( SUIT_DataObject* obj ) +{ + std::cerr << "updateItem with SUIT_DataObj from SUIT_ProxyModel" << std::endl; + if ( treeModel() ) + treeModel()->updateItem( obj ); +} + /*! \brief Compares two model indexes for the sorting purposes. \param left first index to compare diff --git a/src/SUIT/SUIT_TreeModel.h b/src/SUIT/SUIT_TreeModel.h index adc728c2d..967b83a6f 100755 --- a/src/SUIT/SUIT_TreeModel.h +++ b/src/SUIT/SUIT_TreeModel.h @@ -63,6 +63,7 @@ public: virtual void updateTree( const QModelIndex& ) = 0; virtual void updateTree( SUIT_DataObject* = 0 ) = 0; + virtual void updateItem( SUIT_DataObject* ) = 0; virtual void registerColumn( const int group_id, const QString& name, const int custom_id ) = 0; virtual void unregisterColumn( const int group_id, const QString& name ) = 0; @@ -146,6 +147,7 @@ public: public slots: virtual void updateTree( const QModelIndex& ); virtual void updateTree( SUIT_DataObject* = 0 ); + virtual void updateItem( SUIT_DataObject* ); signals: void modelUpdated(); @@ -225,6 +227,7 @@ public: public slots: virtual void updateTree( const QModelIndex& ); virtual void updateTree( SUIT_DataObject* = 0 ); + virtual void updateItem( SUIT_DataObject* ); void setSortingEnabled( bool ); signals: diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index ed874a3f4..3721f758c 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -1244,6 +1244,8 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QMenu* thePop 3. update object browser if it exists */ void SalomeApp_Application::updateObjectBrowser( const bool updateModels ) { + MESSAGE("UpdateObjBrowser"); + return; // update "non-existing" (not loaded yet) data models SalomeApp_Study* study = dynamic_cast(activeStudy()); if ( study ) diff --git a/src/SalomeApp/SalomeApp_DataModel.cxx b/src/SalomeApp/SalomeApp_DataModel.cxx index a1a8f02d9..9dcea194a 100644 --- a/src/SalomeApp/SalomeApp_DataModel.cxx +++ b/src/SalomeApp/SalomeApp_DataModel.cxx @@ -296,6 +296,7 @@ bool SalomeApp_DataModel::create( CAM_Study* theStudy ) */ void SalomeApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study ) { + std::cerr << "in update" << std::endl; SalomeApp_Study* aSStudy = dynamic_cast(study); LightApp_RootObject* studyRoot = 0; _PTR(SComponent) sobj; @@ -332,6 +333,8 @@ void SalomeApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study ) */ SUIT_DataObject* SalomeApp_DataModel::synchronize( const _PTR( SComponent )& sobj, SalomeApp_Study* study ) { + + std::cerr << "in synchronize" << std::endl; if( !study || !study->root() || !sobj ) return 0; @@ -361,6 +364,7 @@ SUIT_DataObject* SalomeApp_DataModel::synchronize( const _PTR( SComponent )& sob */ void SalomeApp_DataModel::updateTree( const _PTR( SComponent )& comp, SalomeApp_Study* study ) { + std::cerr << "in updatetree" << std::endl; SalomeApp_ModuleObject* aNewRoot = dynamic_cast( synchronize( comp, study ) ); if( aNewRoot ) { diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index be3b09618..da06dd0d5 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -28,6 +28,8 @@ #include "SalomeApp_Application.h" #include "SalomeApp_Engine_i.hxx" #include "SalomeApp_VisualState.h" +#include "SUIT_TreeModel.h" +#include "SUIT_DataBrowser.h" // temporary commented //#include @@ -45,6 +47,124 @@ using namespace std; + +class Observer_i : public virtual POA_SALOME::Observer +{ + public: + + Observer_i(_PTR(Study) aStudyDS, SalomeApp_Study* aStudy) + { + myStudyDS=aStudyDS; + myStudy=aStudy; + } + + virtual void notifyObserver(const char* theID, const char* event) + { + MESSAGE("I'm notified of " << event << " of ID = " << theID); + _PTR(SObject) obj = myStudyDS->FindObjectID( theID ); + MESSAGE("This obj is named " << obj->GetIOR()); + MESSAGE("Checking the ID from the sObj : " << obj->GetID()); + + std::string entry_str = theID; + int last2Pnt_pos = entry_str.rfind(":"); + std::string parent_id=entry_str.substr(0,last2Pnt_pos); + std::string pos_in_parent=entry_str.substr(last2Pnt_pos+1); + + + MESSAGE("Parent id " << parent_id << " with position " << pos_in_parent); + _PTR(SObject) obj_parent = myStudyDS->FindObjectID( parent_id ); + MESSAGE("Checking the ID from the sObj_parent : " << obj_parent->GetID()); + + SUIT_DataObject* suit_obj; + + if (std::string(event) == "ADD") + { + MESSAGE("ADDING"); + + _PTR(SComponent) aSComp(obj); + if( aSComp ){ + MESSAGE("This is a module"); + suit_obj=new SalomeApp_ModuleObject(aSComp,0); + } + else{ + MESSAGE("This is not a module "); + suit_obj=new SalomeApp_DataObject(obj,0); + } + + if (entry2SuitObject.count(parent_id)>0){ + SUIT_DataObject* father=entry2SuitObject[parent_id]; + SUIT_DataObject* after; + std::string after_id; + std::stringstream ss; + for (int i=atoi(pos_in_parent.c_str());i>0;i--){ + ss << parent_id << ":" << i ; + after_id = ss.str(); + ss.str(""); + if (entry2SuitObject.count(after_id)>0){ + after=entry2SuitObject[after_id]; + MESSAGE("after_id " << after_id); + break; + } + } + int pos = after ? father->childPos( after ) : 0; + father->insertChild(suit_obj,pos+1); + } + else{ + MESSAGE("This should be for a module"); + myStudy->root()->appendChild(suit_obj); + } + entry2SuitObject[theID]=suit_obj; + } + else if (std::string(event) == "REMOVE"){ + MESSAGE("REMOVING"); + + if (entry2SuitObject.count(theID)>0){ + suit_obj= entry2SuitObject[theID]; + if (entry2SuitObject.count(parent_id)>0){ + SUIT_DataObject* father=entry2SuitObject[parent_id]; + father->removeChild(suit_obj); + } + else{ + MESSAGE("This should be for a module"); + myStudy->root()->removeChild(suit_obj); + } + entry2SuitObject.erase(theID); + } + else{ + MESSAGE("Want to remove an unknown object"); + } + } + else if (std::string(event) == "MODIFY"){ + MESSAGE("MODIFYING"); + if (entry2SuitObject.count(theID)>0){ + suit_obj= entry2SuitObject[theID]; + LightApp_Application* myApp=dynamic_cast(myStudy->application()); + if (myApp){ + MESSAGE("Got an App !"); + SUIT_ProxyModel* myModel=dynamic_cast(myApp->objectBrowser()->model()); + if (myModel){ + MESSAGE("Call to myModel->updateItem"); + myModel->updateItem(suit_obj); + } + } + } + else{ + MESSAGE("Want to modify an unknown object"); + } + } + } + + + + private: + + _PTR(Study) myStudyDS; + SalomeApp_Study* myStudy; + map entry2SuitObject; + +}; + + /*! Constructor. */ @@ -58,6 +178,7 @@ SalomeApp_Study::SalomeApp_Study( SUIT_Application* app ) */ SalomeApp_Study::~SalomeApp_Study() { + //myStudyDS->detach(myObserver); } /*! @@ -101,6 +222,9 @@ bool SalomeApp_Study::createDocument( const QString& theStr ) bool aRet = CAM_Study::createDocument( theStr ); emit created( this ); + Observer_i* myObserver_i = new Observer_i(myStudyDS,this); + myStudyDS->attach(myObserver_i->_this()); + return aRet; } @@ -722,7 +846,6 @@ void SalomeApp_Study::removeSavePoint(int savePoint) } /*! - \return a name of save point */ QString SalomeApp_Study::getNameOfSavePoint(int savePoint) { diff --git a/src/SalomeApp/SalomeApp_Study.h b/src/SalomeApp/SalomeApp_Study.h index fe281212d..f5a34e5bc 100644 --- a/src/SalomeApp/SalomeApp_Study.h +++ b/src/SalomeApp/SalomeApp_Study.h @@ -32,8 +32,9 @@ #endif #include "SALOMEDSClient.hxx" +#include CORBA_SERVER_HEADER(SALOME_Observer) -class SALOMEAPP_EXPORT SalomeApp_Study : public LightApp_Study +class SALOMEAPP_EXPORT SalomeApp_Study : public LightApp_Study { Q_OBJECT @@ -104,6 +105,9 @@ private: private: _PTR(Study) myStudyDS; + +private: + SALOME::Observer_var myObserver; }; #ifdef WIN32