*/
void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* )
{
- LightApp_ModuleObject* modelRoot = dynamic_cast<LightApp_ModuleObject*>( 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<LightApp_DataObject*>( root() );
DataObjectList ch;
QMap<SUIT_DataObject*,int> aMap;
if( modelRoot )
build();
- modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
+ modelRoot = dynamic_cast<LightApp_DataObject*>( root() );
if( modelRoot )
{
DataObjectList new_ch = modelRoot->children();
{
SUIT_AbstractModel* m = dynamic_cast<SUIT_AbstractModel*>( 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<LightApp_RootObject*>( theRoot );
+ if ( !aStudyRoot )
+ return 0;
+
+ LightApp_Study* aStudy = aStudyRoot->study();
+ if ( aStudy )
+ return aStudy->createModuleObject( const_cast<LightApp_DataModel*>( this ),
+ theRoot );
+ return 0;
}
class LightApp_Study;
class LightApp_DataObject;
class SUIT_DataBrowser;
+class CAM_ModuleObject;
/*!
Description : Base class of data model
LightApp_Study* getStudy() const;
virtual void build();
virtual void updateWidgets();
+ virtual CAM_ModuleObject* createModuleObject( SUIT_DataObject* theRoot ) const;
private:
int myGroupId;
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<LightApp_Study*>( 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<LightApp_ModuleObject*>( *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
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.
protected:
virtual bool openDataModel ( const QString&, CAM_DataModel* );
+ virtual CAM_ModuleObject* createModuleObject( LightApp_DataModel* theDataModel,
+ SUIT_DataObject* theParent ) const;
signals:
void saved ( SUIT_Study* );
ViewMgrMap myViewMgrMap;
friend class LightApp_Application;
+ friend class LightApp_DataModel;
};
#endif
\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;
}
/*!
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<SalomeApp_Study*>( 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<SalomeApp_ModuleObject*>( *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.
*/
//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
+ }
}
}
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* );