Salome HOME
Update preferences on plug-in loading
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 10 Sep 2014 13:55:25 +0000 (17:55 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 10 Sep 2014 13:55:25 +0000 (17:55 +0400)
src/Model/Model_PluginManager.cpp
src/ModelAPI/ModelAPI_Events.h
src/NewGeom/NewGeom_Module.cpp
src/XGUI/XGUI_SalomeConnector.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 06893e6fc343c6615bac7b9f097d1cccb56af633..ad5767a5af0d73b470bce966285eb5be7a974ff1 100644 (file)
@@ -159,6 +159,9 @@ void Model_PluginManager::LoadPluginsInfo()
 void Model_PluginManager::registerPlugin(ModelAPI_Plugin* thePlugin)
 {
   myPluginObjs[myCurrentPluginName] = thePlugin;
+  static Events_ID EVENT_LOAD = Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED);
+  ModelAPI_EventCreator::get()->sendUpdated(ObjectPtr(), EVENT_LOAD);
+  Events_Loop::loop()->flush(EVENT_LOAD);
 }
 
 ModelAPI_ValidatorsFactory* Model_PluginManager::validators()
index 89b1fd5b941773551d7a8e2782771770dc12cf27..c35573168d23c8eeaaa68a642e5be0eb616f2ac7 100644 (file)
@@ -27,6 +27,8 @@ static const char * EVENT_OBJECT_MOVED = "ObjectsMoved";
 static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay";
 /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
 static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched";
+/// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
+static const char * EVENT_PLUGIN_LOADED = "PliginLoaded";
 
 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
 class ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
index dd97f0fc5a69b683b31d06d5a1c88e207fc7bf08..1caf55c95f97fca31bd11a50ff5a53570639179b 100644 (file)
@@ -286,10 +286,18 @@ void NewGeom_Module::createPreferences()
 {
   XGUI_Preferences::updateCustomProps();
   LightApp_Preferences* pref = preferences();
-  int catId = pref->addPreference( moduleName(), -1 );
+  QString aModName = moduleName();
+
+  QtxPreferenceItem* item = pref->findItem(aModName, true );
+  if ( item && (!item->isEmpty() )) {
+    item->parentItem()->removeItem(item);
+    delete item;
+  }
+
+  int catId = pref->addPreference(aModName, -1 );
   if ( catId == -1 )
     return;
-  NewGeom_PrefMgr aMgr(pref, moduleName());
+  NewGeom_PrefMgr aMgr(pref, aModName);
   XGUI_Preferences::createEditContent(&aMgr, catId);
   pref->retrieve();
 }
index 58489c127b61c50d5a96ac17b2fbd37055a8e2ae..0055714b73e4078e6898804484a0bd727e4d6ad9 100644 (file)
@@ -69,6 +69,8 @@ class XGUI_EXPORT XGUI_SalomeConnector
 
   //! Returns interface to Salome viewer
   virtual XGUI_SalomeViewer* viewer() const = 0;
+
+  virtual void createPreferences() = 0;
 };
 
 #endif
index fec644039bdd94d6cdf17f3becf425bfc5402230..a2c6ff0f0d0d5eeb49c6c8d8e46f31a609b67a26 100644 (file)
@@ -86,7 +86,8 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
       mySalomeConnector(theConnector),
       myPropertyPanel(0),
       myObjectBrowser(0),
-      myDisplayer(0)
+      myDisplayer(0),
+      myUpdatePrefs(false)
 {
   myMainWindow = mySalomeConnector ? 0 : new XGUI_MainWindow();
 
@@ -139,6 +140,7 @@ void XGUI_Workshop::startApplication()
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
   aLoop->registerListener(this, Events_Loop::eventByName("LongOperation"));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
 
   registerValidators();
   activateModule();
@@ -243,6 +245,15 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage)
     const ModelAPI_ObjectUpdatedMessage* aUpdMsg =
         dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
     onFeatureCreatedMsg(aUpdMsg);
+    if (myUpdatePrefs) {
+      if (mySalomeConnector)
+        mySalomeConnector->createPreferences();
+      myUpdatePrefs = false;
+    }
+    return;
+  }
+  if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
+    myUpdatePrefs = true;
     return;
   }
 
@@ -302,6 +313,7 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage)
   }
 }
 
+
 //******************************************************
 void XGUI_Workshop::onStartWaiting()
 {
index 95644a07fb1f25913f4141afd7223d137fce8680..dbf160d15105689a1fcf31346a25f7752e00e628 100644 (file)
@@ -208,7 +208,7 @@ signals:
   void displayDocumentResults(DocumentPtr theDoc);
   void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
 
- protected slots:
+ private slots:
   /// SLOT, that is called after the operation is started. Update workshop state according to
   /// the started operation, e.g. visualizes the property panel and connect to it.
   void onOperationStarted();
@@ -253,6 +253,8 @@ signals:
 
   QString myCurrentDir;
   static QMap<QString, QString> myIcons;
+
+  bool myUpdatePrefs;
 };
 
 #endif