From: vsr Date: Mon, 7 Nov 2011 14:38:15 +0000 (+0000) Subject: 021419: [CEA 516] Invalid tree representation of ATOMIC light-component X-Git-Tag: RELIQUAT_6x_15112011~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9302eac0483c529917f7aff1ba74b17c0f1237db;p=modules%2Fgui.git 021419: [CEA 516] Invalid tree representation of ATOMIC light-component --- diff --git a/src/LightApp/LightApp_DataModel.cxx b/src/LightApp/LightApp_DataModel.cxx index da1544eee..0c8c40888 100644 --- a/src/LightApp/LightApp_DataModel.cxx +++ b/src/LightApp/LightApp_DataModel.cxx @@ -110,7 +110,10 @@ void LightApp_DataModel::updateWidgets() */ void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* ) { - LightApp_ModuleObject* modelRoot = dynamic_cast( root() ); + // san: Previously modelRoot was casted to LightApp_ModuleObject*, + // BUT this is incorrect: in full SALOME the model root has different type. + // Hopefully LightApp_DataObject* is sufficient here. + LightApp_DataObject* modelRoot = dynamic_cast( root() ); DataObjectList ch; QMap aMap; if( modelRoot ) @@ -123,7 +126,7 @@ void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* ) build(); - modelRoot = dynamic_cast( root() ); + modelRoot = dynamic_cast( root() ); if( modelRoot ) { DataObjectList new_ch = modelRoot->children(); @@ -207,5 +210,27 @@ void LightApp_DataModel::unregisterColumn( SUIT_DataBrowser* browser, const QStr { SUIT_AbstractModel* m = dynamic_cast( browser ? browser->model() : 0 ); if( m ) - m->unregisterColumn( groupId(), name ); + m->unregisterColumn( groupId(), name ); +} + +/*! + Creates the data model's root (module object) using the study services. + This is important because different study classes use different moduel object classes. + Therefore creation of the module object cannot be done at the data model level + where the type of the current study instance should not be known. + The module object returned by this method should be then passed to the model's setRoot(). + \return the module object instance corresponding to the study type + \sa CAM_DataModel class +*/ +CAM_ModuleObject* LightApp_DataModel::createModuleObject( SUIT_DataObject* theRoot ) const +{ + LightApp_RootObject* aStudyRoot = dynamic_cast( theRoot ); + if ( !aStudyRoot ) + return 0; + + LightApp_Study* aStudy = aStudyRoot->study(); + if ( aStudy ) + return aStudy->createModuleObject( const_cast( this ), + theRoot ); + return 0; } diff --git a/src/LightApp/LightApp_DataModel.h b/src/LightApp/LightApp_DataModel.h index 097fe9ab5..994cbecaa 100644 --- a/src/LightApp/LightApp_DataModel.h +++ b/src/LightApp/LightApp_DataModel.h @@ -38,6 +38,7 @@ class LightApp_Module; class LightApp_Study; class LightApp_DataObject; class SUIT_DataBrowser; +class CAM_ModuleObject; /*! Description : Base class of data model @@ -75,6 +76,7 @@ protected: LightApp_Study* getStudy() const; virtual void build(); virtual void updateWidgets(); + virtual CAM_ModuleObject* createModuleObject( SUIT_DataObject* theRoot ) const; private: int myGroupId; diff --git a/src/LightApp/LightApp_Study.cxx b/src/LightApp/LightApp_Study.cxx index 4bbf7a886..69ecbe9cf 100644 --- a/src/LightApp/LightApp_Study.cxx +++ b/src/LightApp/LightApp_Study.cxx @@ -448,6 +448,44 @@ void LightApp_Study::RemoveTemporaryFiles (const char* theModuleName, const bool myDriver->RemoveTemporaryFiles(theModuleName, isDirDeleted); } +/*! + Virtual method that creates the root object (module object) for the given data model. + The type of the created object depends on the study class, therefore data model classes + should not create their module objects directly and should instead use + LightApp_DataModel::createModuleObject() that in its turn relies on this method. + + \param theDataModel - data model instance to create a module object for + \param theParent - the module object's parent (normally it's the study root) + \return the module object instance + \sa LightApp_DataModel class, SalomeApp_Study class, LightApp_ModuleObject class +*/ +CAM_ModuleObject* LightApp_Study::createModuleObject( LightApp_DataModel* theDataModel, + SUIT_DataObject* theParent ) const +{ + // Calling addComponent() for symmetry with SalomeApp_Study + // Currently it has empty implementation, but maybe in the future things will change... + LightApp_Study* that = const_cast( this ); + that->addComponent( theDataModel ); + + // Avoid creating multiple module objects for the same module + CAM_ModuleObject* res = 0; + + DataObjectList children = root()->children(); + DataObjectList::const_iterator anIt = children.begin(), aLast = children.end(); + for( ; !res && anIt!=aLast; anIt++ ) + { + LightApp_ModuleObject* obj = dynamic_cast( *anIt ); + if ( obj && obj->name() == theDataModel->module()->moduleName() ) + res = obj; + } + + if ( !res ){ + res = new LightApp_ModuleObject( theDataModel, theParent ); + } + + return res; +} + /*! Fills list with components names \param comp - list to be filled diff --git a/src/LightApp/LightApp_Study.h b/src/LightApp/LightApp_Study.h index 72dcfe0c5..428900cda 100644 --- a/src/LightApp/LightApp_Study.h +++ b/src/LightApp/LightApp_Study.h @@ -38,7 +38,9 @@ class SUIT_Study; class SUIT_Application; class CAM_DataModel; +class CAM_ModuleObject; class LightApp_DataObject; +class LightApp_DataModel; //Map to store visual property of the object. //Key: Name of the visual property of the object. @@ -123,6 +125,8 @@ protected: protected: virtual bool openDataModel ( const QString&, CAM_DataModel* ); + virtual CAM_ModuleObject* createModuleObject( LightApp_DataModel* theDataModel, + SUIT_DataObject* theParent ) const; signals: void saved ( SUIT_Study* ); @@ -136,6 +140,7 @@ private: ViewMgrMap myViewMgrMap; friend class LightApp_Application; + friend class LightApp_DataModel; }; #endif diff --git a/src/SalomeApp/SalomeApp_DataObject.cxx b/src/SalomeApp/SalomeApp_DataObject.cxx index fa5cd5a52..86fb9f13c 100644 --- a/src/SalomeApp/SalomeApp_DataObject.cxx +++ b/src/SalomeApp/SalomeApp_DataObject.cxx @@ -671,10 +671,17 @@ QString SalomeApp_ModuleObject::name() const \brief Get data object icon for the specified column. \param id column id \return object icon for the specified column + \sa CAM_ModuleObject class */ QPixmap SalomeApp_ModuleObject::icon( const int id ) const { - return SalomeApp_DataObject::icon( id ); + QPixmap p = SalomeApp_DataObject::icon( id ); + // The module might not provide a separate small icon + // for Obj. Browser representation -> always try to scale it + // See CAM_ModuleObject::icon() + if ( !p.isNull() ) + p = Qtx::scaleIcon( p, 16 ); + return p; } /*! diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index c0bd439b4..c46ea3e69 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -764,6 +764,54 @@ void SalomeApp_Study::setStudyDS( const _PTR(Study)& s ) myStudyDS = s; } +/*! + Virtual method re-implemented from LightApp_Study in order to create + the module object connected to SALOMEDS - SalomeApp_ModuleObject. + + \param theDataModel - data model instance to create a module object for + \param theParent - the module object's parent (normally it's the study root) + \return the module object instance + \sa LightApp_Study class, LightApp_DataModel class +*/ +CAM_ModuleObject* SalomeApp_Study::createModuleObject( LightApp_DataModel* theDataModel, + SUIT_DataObject* theParent ) const +{ + SalomeApp_Study* that = const_cast( this ); + + // Ensure that SComponent instance is published in the study for the given module + // This line causes automatic creation of SalomeApp_ModuleObject in case if + // WITH_SALOMEDS_OBSERVER is defined + that->addComponent( theDataModel ); + + // SalomeApp_ModuleObject might have been created by SALOMEDS observer + // or by someone else so check if it exists first of all + CAM_ModuleObject* res = 0; + + DataObjectList children = root()->children(); + DataObjectList::const_iterator anIt = children.begin(), aLast = children.end(); + for( ; !res && anIt!=aLast; anIt++ ) + { + SalomeApp_ModuleObject* obj = dynamic_cast( *anIt ); + if ( obj && obj->componentDataType() == theDataModel->module()->name() ) + res = obj; + } + + if ( !res ){ + _PTR(Study) aStudy = studyDS(); + if ( !aStudy ) + return res; + + _PTR(SComponent) aComp = aStudy->FindComponent( + theDataModel->module()->name().toStdString() ); + if ( !aComp ) + return res; + + res = new SalomeApp_ModuleObject( theDataModel, aComp, theParent ); + } + + return res; +} + /*! Insert data model. */ @@ -805,6 +853,17 @@ void SalomeApp_Study::addComponent(const CAM_DataModel* dm) //SalomeApp_DataModel::BuildTree( aComp, root(), this, /*skipExisitng=*/true ); SalomeApp_DataModel::synchronize( aComp, this ); } + else { + _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); + aBuilder->SetName(aComp, dm->module()->moduleName().toStdString()); + QString anIconName = dm->module()->iconName(); + if (!anIconName.isEmpty()) { + _PTR(AttributePixMap) anAttr = aBuilder->FindOrCreateAttribute(aComp, "AttributePixMap"); + if (anAttr) + anAttr->SetPixMap(anIconName.toStdString()); + } + // Set default engine IOR + } } } diff --git a/src/SalomeApp/SalomeApp_Study.h b/src/SalomeApp/SalomeApp_Study.h index 6e9cef141..41ebe3715 100644 --- a/src/SalomeApp/SalomeApp_Study.h +++ b/src/SalomeApp/SalomeApp_Study.h @@ -100,7 +100,8 @@ protected: virtual void dataModelInserted( const CAM_DataModel* ); virtual bool openDataModel( const QString&, CAM_DataModel* ); void setStudyDS(const _PTR(Study)& s ); - + virtual CAM_ModuleObject* createModuleObject( LightApp_DataModel* theDataModel, + SUIT_DataObject* theParent ) const; protected slots: virtual void updateModelRoot( const CAM_DataModel* );