X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_PluginManager.cpp;h=d26ccd144e6546995c9bf25521cd92b93b0ef0e1;hb=a6e18c9e2793cc467da1ce82e14487dca06653c1;hp=eb279208afff32ba365016d136eac30c71cb7297;hpb=912b947536177180af5bd6d620d84e9ebc05be66;p=modules%2Fshaper.git diff --git a/src/Model/Model_PluginManager.cpp b/src/Model/Model_PluginManager.cpp index eb279208a..d26ccd144 100644 --- a/src/Model/Model_PluginManager.cpp +++ b/src/Model/Model_PluginManager.cpp @@ -8,38 +8,53 @@ #include #include #include -#include +#include +#include +#include +#include #include #include +#include +#include +#include +#include + + using namespace std; static Model_PluginManager* myImpl = new Model_PluginManager(); -shared_ptr Model_PluginManager::createFeature(string theFeatureID) +FeaturePtr Model_PluginManager::createFeature(string theFeatureID) { if (this != myImpl) return myImpl->createFeature(theFeatureID); LoadPluginsInfo(); if (myPlugins.find(theFeatureID) != myPlugins.end()) { - if (myPluginObjs.find(myPlugins[theFeatureID]) == myPluginObjs.end()) { + myCurrentPluginName = myPlugins[theFeatureID]; + if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) { // load plugin library if not yet done - myCurrentPluginName = myPlugins[theFeatureID]; - loadLibrary(myCurrentPluginName); + Config_ModuleReader::loadLibrary(myCurrentPluginName); } if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) { - std::shared_ptr aCreated = + FeaturePtr aCreated = myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID); + if (!aCreated) { + Events_Error::send(string("Can not initialize feature '") + theFeatureID + + "' in plugin '" + myCurrentPluginName + "'"); + } return aCreated; + } else { + Events_Error::send(string("Can not load plugin '") + myCurrentPluginName + "'"); } } - return std::shared_ptr(); // return nothing + return FeaturePtr(); // return nothing } -std::shared_ptr Model_PluginManager::rootDocument() +boost::shared_ptr Model_PluginManager::rootDocument() { - return std::shared_ptr( + return boost::shared_ptr( Model_Application::getApplication()->getDocument("root")); } @@ -48,42 +63,73 @@ bool Model_PluginManager::hasRootDocument() return Model_Application::getApplication()->hasDocument("root"); } -shared_ptr Model_PluginManager::currentDocument() +boost::shared_ptr Model_PluginManager::currentDocument() { - if (!myCurrentDoc) + if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id())) myCurrentDoc = rootDocument(); return myCurrentDoc; } -void Model_PluginManager::setCurrentDocument(shared_ptr theDoc) +void Model_PluginManager::setCurrentDocument(boost::shared_ptr theDoc) { myCurrentDoc = theDoc; + static Events_Message aMsg(Events_Loop::eventByName("CurrentDocumentChanged")); + Events_Loop::loop()->send(aMsg); +} + +boost::shared_ptr Model_PluginManager::copy( + boost::shared_ptr theSource, std::string theID) +{ + // create a new document + boost::shared_ptr aNew = boost::dynamic_pointer_cast( + Model_Application::getApplication()->getDocument(theID)); + // make a copy of all labels + TDF_Label aSourceRoot = + boost::dynamic_pointer_cast(theSource)->document()->Main().Father(); + TDF_Label aTargetRoot = aNew->document()->Main().Father(); + Handle(TDF_DataSet) aDS = new TDF_DataSet; + aDS->AddLabel(aSourceRoot); + TDF_ClosureTool::Closure(aDS); + Handle(TDF_RelocationTable) aRT = new TDF_RelocationTable; + aRT->SetRelocation(aSourceRoot, aTargetRoot); + TDF_CopyTool::Copy(aDS, aRT); + + aNew->synchronizeFeatures(); + return aNew; } Model_PluginManager::Model_PluginManager() { myPluginsInfoLoaded = false; - //TODO(sbh): Implement static method to extract event id [SEID] - static Event_ID aFeatureEvent = Event_Loop::eventByName("FeatureRegisterEvent"); - - ModelAPI_PluginManager::SetPluginManager(std::shared_ptr(this)); + myCheckTransactions = true; + ModelAPI_PluginManager::setPluginManager(boost::shared_ptr(this)); // register the configuration reading listener - Event_Loop* aLoop = Event_Loop::loop(); - aLoop->registerListener(this, aFeatureEvent); + Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID FeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent"); + aLoop->registerListener(this, FeatureEvent); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED)); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED)); } -void Model_PluginManager::processEvent(const Event_Message* theMessage) +void Model_PluginManager::processEvent(const Events_Message* theMessage) { - const Config_FeatureMessage* aMsg = - dynamic_cast(theMessage); - if (aMsg) { - // proccess the plugin info, load plugin - if (myPlugins.find(aMsg->id()) == myPlugins.end()) { - myPlugins[aMsg->id()] = aMsg->pluginLibrary(); + static Events_ID FeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent"); + if (theMessage->eventID() == FeatureEvent) { + const Config_FeatureMessage* aMsg = + dynamic_cast(theMessage); + if (aMsg) { + // proccess the plugin info, load plugin + if (myPlugins.find(aMsg->id()) == myPlugins.end()) { + myPlugins[aMsg->id()] = aMsg->pluginLibrary(); + } } + // plugins information was started to load, so, it will be loaded + myPluginsInfoLoaded = true; + } else { // create/update/delete + if (myCheckTransactions && !rootDocument()->isOperation()) + Events_Error::send("Modification of data structure outside of the transaction"); } - // plugins information was started to load, so, it will be loaded - myPluginsInfoLoaded = true; } void Model_PluginManager::LoadPluginsInfo() @@ -93,7 +139,6 @@ void Model_PluginManager::LoadPluginsInfo() // Read plugins information from XML files Config_ModuleReader aXMLReader("FeatureRegisterEvent"); - aXMLReader.setAutoImport(true); aXMLReader.readAll(); } @@ -101,3 +146,9 @@ void Model_PluginManager::registerPlugin(ModelAPI_Plugin* thePlugin) { myPluginObjs[myCurrentPluginName] = thePlugin; } + +ModelAPI_ValidatorsFactory* Model_PluginManager::validators() +{ + static Model_ValidatorsFactory* aFactory = new Model_ValidatorsFactory; + return aFactory; +}