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 )
{
objectBrowser()->updateGeometry();
objectBrowser()->updateTree( 0, false );
}
+ */
}
/*!
/*!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 );
getApp()->objectBrowser()->setAutoUpdate( upd );
getApp()->objectBrowser()->updateTree( 0, false );
+*/
}
/*!NOT IMPLEMENTED*/
#include <QtxTreeView.h>
#include <QShortcut>
+#include <iostream>
/*!
\class SUIT_DataBrowser
\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<SUIT_ProxyModel*>( model() );
if ( m ) {
m->updateTree( obj );
return myItems.contains( obj ) ? obj : 0;
}
+#include <iostream>
/*!
\brief Create an item corresponding to the data object.
\param obj source data object
SUIT_TreeModel::TreeItem* parent,
SUIT_TreeModel::TreeItem* after )
{
+ std::cerr << " SUIT_TreeModel::createItem " << std::endl;
if ( !obj )
return 0;
*/
void SUIT_TreeModel::updateItem( SUIT_TreeModel::TreeItem* item )
{
+
+ std::cerr << " SUIT_TreeModel::updateItem " << std::endl;
if ( !item )
return;
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;
\param index starting index for the updating
\sa setAutoUpdate()
*/
+#include <iostream>
void SUIT_ProxyModel::updateTree( const QModelIndex& index )
{
+ std::cerr << "updateTree with QModelIndex from SUIT_ProxyModel" << std::endl;
if ( treeModel() )
treeModel()->updateTree( mapToSource( 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
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;
public slots:
virtual void updateTree( const QModelIndex& );
virtual void updateTree( SUIT_DataObject* = 0 );
+ virtual void updateItem( SUIT_DataObject* );
signals:
void modelUpdated();
public slots:
virtual void updateTree( const QModelIndex& );
virtual void updateTree( SUIT_DataObject* = 0 );
+ virtual void updateItem( SUIT_DataObject* );
void setSortingEnabled( bool );
signals:
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<SalomeApp_Study*>(activeStudy());
if ( study )
*/
void SalomeApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study )
{
+ std::cerr << "in update" << std::endl;
SalomeApp_Study* aSStudy = dynamic_cast<SalomeApp_Study*>(study);
LightApp_RootObject* studyRoot = 0;
_PTR(SComponent) sobj;
*/
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;
*/
void SalomeApp_DataModel::updateTree( const _PTR( SComponent )& comp, SalomeApp_Study* study )
{
+ std::cerr << "in updatetree" << std::endl;
SalomeApp_ModuleObject* aNewRoot = dynamic_cast<SalomeApp_ModuleObject*>( synchronize( comp, study ) );
if( aNewRoot )
{
#include "SalomeApp_Application.h"
#include "SalomeApp_Engine_i.hxx"
#include "SalomeApp_VisualState.h"
+#include "SUIT_TreeModel.h"
+#include "SUIT_DataBrowser.h"
// temporary commented
//#include <OB_Browser.h>
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<LightApp_Application*>(myStudy->application());
+ if (myApp){
+ MESSAGE("Got an App !");
+ SUIT_ProxyModel* myModel=dynamic_cast<SUIT_ProxyModel*>(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<string,SUIT_DataObject*> entry2SuitObject;
+
+};
+
+
/*!
Constructor.
*/
*/
SalomeApp_Study::~SalomeApp_Study()
{
+ //myStudyDS->detach(myObserver);
}
/*!
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;
}
}
/*!
- \return a name of save point
*/
QString SalomeApp_Study::getNameOfSavePoint(int savePoint)
{
#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
private:
_PTR(Study) myStudyDS;
+
+private:
+ SALOME::Observer_var myObserver;
};
#ifdef WIN32