From: nds Date: Thu, 10 Dec 2015 10:26:31 +0000 (+0300) Subject: #1021 HDF file : nothing saved if only parameters and sketch were created X-Git-Tag: V_2.1.0~196 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8e55a7274dac046a338e0c313188ec94cac487e8;p=modules%2Fshaper.git #1021 HDF file : nothing saved if only parameters and sketch were created --- diff --git a/src/NewGeom/NewGeom_DataModel.cpp b/src/NewGeom/NewGeom_DataModel.cpp index 88e7db728..2f2089509 100644 --- a/src/NewGeom/NewGeom_DataModel.cpp +++ b/src/NewGeom/NewGeom_DataModel.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -131,6 +132,20 @@ bool NewGeom_DataModel::isSaved() const void NewGeom_DataModel::update(LightApp_DataObject* theObj, LightApp_Study* theStudy) { + // Nothing to do here: we always keep the data tree in the up-to-date state + // The only goal of this method is to hide default behavior from LightApp_DataModel + return; +} + +void NewGeom_DataModel::initRootObject() +{ + LightApp_Study* study = dynamic_cast( module()->application()->activeStudy() ); + CAM_ModuleObject *aModelRoot = dynamic_cast(root()); + if(study && aModelRoot == NULL) { + aModelRoot = createModuleObject( study->root() ); + aModelRoot->setDataModel( this ); + setRoot(aModelRoot); + } } void NewGeom_DataModel::removeDirectory(const QString& theDirectoryName) diff --git a/src/NewGeom/NewGeom_DataModel.h b/src/NewGeom/NewGeom_DataModel.h index 5f6f9519d..e553f8ccc 100644 --- a/src/NewGeom/NewGeom_DataModel.h +++ b/src/NewGeom/NewGeom_DataModel.h @@ -51,6 +51,11 @@ class NewGeom_EXPORT NewGeom_DataModel : public LightApp_DataModel /// Returns True if the data structure is already saved virtual bool isSaved() const; + /// Creates a module root object if it has not been created yet + /// and append it to the active study. It is necessary for correct persistent + /// of the model. + void initRootObject(); + /// Update data object /// \param theObj an data object /// \param theStudy a current study diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index 04d3a1b6d..7bc410a0b 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -144,6 +144,9 @@ void NewGeom_Module::viewManagers(QStringList& theList) const bool NewGeom_Module::activateModule(SUIT_Study* theStudy) { bool isDone = LightApp_Module::activateModule(theStudy); + NewGeom_DataModel* aDataModel = dynamic_cast(dataModel()); + aDataModel->initRootObject(); + if (isDone) { setMenuShown(true); setToolShown(true); @@ -348,13 +351,7 @@ NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr) //****************************************************** CAM_DataModel* NewGeom_Module::createDataModel() { - NewGeom_DataModel* aDataModel = new NewGeom_DataModel(this); - - // Calling addComponent() for persistent functionality work in the SalomeApp_Study - LightApp_Study* aStudy = dynamic_cast(application()->activeStudy() ); - aStudy->addComponent(aDataModel); - - return aDataModel; + return new NewGeom_DataModel(this); } QAction* NewGeom_Module::addFeature(const QString& theWBName, const ActionInfo& theInfo)