Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / NewGeom / NewGeom_Module.cpp
index 9f8bc4543a6ee76012b5b0515195bd9c35e7f6ff..c9d875f1373ed6781255f440c61e6cfbdc2e6a38 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 
 #include "NewGeom_Module.h"
 #include "NewGeom_DataModel.h"
@@ -6,15 +8,16 @@
 #include <XGUI_Workshop.h>
 #include <XGUI_PropertyPanel.h>
 #include <XGUI_ContextMenuMgr.h>
-#include <XGUI_Preferences.h>
 #include <XGUI_ObjectsBrowser.h>
 #include <XGUI_OperationMgr.h>
 
 #include <ModuleBase_Operation.h>
+#include <ModuleBase_Preferences.h>
 
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 #include <LightApp_OCCSelector.h>
+#include <LightApp_Study.h>
 #include <OCCViewer_ViewModel.h>
 
 #include <SUIT_Selector.h>
@@ -45,7 +48,7 @@ NewGeom_EXPORT char* getModuleVersion()
 }
 }
 
-class NewGeom_PrefMgr: public XGUI_IPrefMgr
+class NewGeom_PrefMgr: public ModuleBase_IPrefMgr
 {
 public:
   NewGeom_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):myMgr(theMgr), myModName(theModName) {}
@@ -57,6 +60,14 @@ public:
     return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
   }
 
+  virtual void setItemProperty(const QString& thePropName,
+                               const QVariant& theValue,
+                               const int theId = -1)
+  {
+    myMgr->setItemProperty(thePropName, theValue, theId);
+  }
+
+
   virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
 
 private:
@@ -73,10 +84,13 @@ NewGeom_Module::NewGeom_Module()
       mySelector(0), myIsOpened(0), myPopupMgr(0)
 {
   myWorkshop = new XGUI_Workshop(this);
+  connect(myWorkshop, SIGNAL(commandStatusUpdated()),
+          this, SLOT(onUpdateCommandStatus()));
+
   myProxyViewer = new NewGeom_SalomeViewer(this);
 
-  XGUI_Preferences::setResourceMgr(application()->resourceMgr());
-  XGUI_Preferences::loadCustomProps();
+  ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
+  ModuleBase_Preferences::loadCustomProps();
 }
 
 //******************************************************
@@ -139,9 +153,13 @@ bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
       myIsOpened = false;
       QTimer::singleShot(1000, myWorkshop, SLOT(displayAllResults()));
     }
+    else
+      myWorkshop->updateCommandStatus();
   }
   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
   myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
+  myIsEditEnabled = getApp()->isEditEnabled();
+  getApp()->setEditEnabled(false);
 
   // this following row is caused by #187 bug.
   // SALOME saves the dock widget positions before deactivateModule() and
@@ -189,6 +207,7 @@ bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
 
   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
   aResMgr->setValue("Study", "store_positions", myIsStorePositions);
+  getApp()->setEditEnabled(myIsEditEnabled);
 
   return LightApp_Module::deactivateModule(theStudy);
 }
@@ -212,14 +231,20 @@ QtxPopupMgr* NewGeom_Module::popupMgr()
 //******************************************************
 void NewGeom_Module::onDefaultPreferences()
 {
-  XGUI_Preferences::resetConfig();
-  XGUI_Preferences::updateResourcesByConfig();
+  ModuleBase_Preferences::resetConfig();
+  ModuleBase_Preferences::updateResourcesByConfig();
 
   LightApp_Preferences* pref = preferences();
   if (pref)
     pref->retrieve();
 }
 
+//******************************************************
+void NewGeom_Module::onUpdateCommandStatus()
+{
+  getApp()->updateActions();
+}
+
 //******************************************************
 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
 {
@@ -242,7 +267,13 @@ NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
 //******************************************************
 CAM_DataModel* NewGeom_Module::createDataModel()
 {
-  return new NewGeom_DataModel(this);
+  NewGeom_DataModel* aDataModel = new NewGeom_DataModel(this);
+
+  // Calling addComponent() for persistent functionality work in the SalomeApp_Study
+  LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(application()->activeStudy() );
+  aStudy->addComponent(aDataModel);
+
+  return aDataModel;
 }
 
 //******************************************************
@@ -386,7 +417,7 @@ void NewGeom_Module::createPreferences()
   LightApp_Preferences* pref = preferences();
   if (!pref)
     return;
-  XGUI_Preferences::updateConfigByResources();
+  ModuleBase_Preferences::updateConfigByResources();
   QString aModName = moduleName();
 
   QtxPreferenceItem* item = pref->findItem(aModName, true );
@@ -399,7 +430,7 @@ void NewGeom_Module::createPreferences()
   if ( catId == -1 )
     return;
   NewGeom_PrefMgr aMgr(pref, aModName);
-  XGUI_Preferences::createEditContent(&aMgr, catId);
+  ModuleBase_Preferences::createEditContent(&aMgr, catId);
   pref->retrieve();
 }