#include "LightApp_Application.h"
#include "LightApp_DataModel.h"
+#include "LightApp_DataObject.h"
#include "LightApp_Study.h"
#include "LightApp_Preferences.h"
#include "LightApp_Selection.h"
/*!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*/
// 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);
+ }
+ }
}
//================================================================