1 // File: Model_PluginManager.cxx
2 // Created: 20 Mar 2014
3 // Author: Mikhail PONIKAROV
5 #include <Model_PluginManager.h>
6 #include <ModelAPI_Feature.h>
7 #include <ModelAPI_Plugin.h>
8 #include <Model_Feature.h>
9 #include <Model_Document.h>
10 #include <Model_Application.h>
11 #include <Event_Loop.h>
12 #include <Config_FeatureMessage.h>
13 #include <Config_ModuleReader.h>
17 static Model_PluginManager* myImpl = new Model_PluginManager();
19 boost::shared_ptr<ModelAPI_Feature> Model_PluginManager::createFeature(string theFeatureID)
21 if (this != myImpl) return myImpl->createFeature(theFeatureID);
24 if (myPlugins.find(theFeatureID) != myPlugins.end()) {
25 if (myPluginObjs.find(myPlugins[theFeatureID]) == myPluginObjs.end()) {
26 // load plugin library if not yet done
27 myCurrentPluginName = myPlugins[theFeatureID];
28 loadLibrary(myCurrentPluginName);
30 if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
31 boost::shared_ptr<ModelAPI_Feature> aCreated =
32 myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
36 return boost::shared_ptr<ModelAPI_Feature>(); // return nothing
39 boost::shared_ptr<ModelAPI_Document> Model_PluginManager::rootDocument()
41 return boost::shared_ptr<ModelAPI_Document>(
42 Model_Application::getApplication()->getDocument("root"));
46 Model_PluginManager::Model_PluginManager()
48 myPluginsInfoLoaded = false;
49 static Event_ID aFeatureEvent = Event_Loop::eventByName("RegisterFeature");
51 ModelAPI_PluginManager::SetPluginManager(boost::shared_ptr<ModelAPI_PluginManager>(this));
52 // register the configuration reading listener
53 Event_Loop* aLoop = Event_Loop::loop();
54 aLoop->registerListener(this, aFeatureEvent);
57 void Model_PluginManager::processEvent(const Event_Message* theMessage)
59 const Config_FeatureMessage* aMsg =
60 dynamic_cast<const Config_FeatureMessage*>(theMessage);
62 // proccess the plugin info, load plugin
63 if (myPlugins.find(aMsg->id()) == myPlugins.end()) {
64 myPlugins[aMsg->id()] = aMsg->pluginLibrary();
67 // plugins information was started to load, so, it will be loaded
68 myPluginsInfoLoaded = true;
71 void Model_PluginManager::LoadPluginsInfo()
73 if (myPluginsInfoLoaded) // nothing to do
76 // Read plugins information from XML files
77 Config_ModuleReader aXMLReader;
78 aXMLReader.setAutoImport(true);
82 void Model_PluginManager::registerPlugin(ModelAPI_Plugin* thePlugin)
84 myPluginObjs[myCurrentPluginName] = thePlugin;