X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FModel%2FModel_PluginManager.cpp;h=05f1586e678f1c1b5ba1df48cd2b668ee71926d8;hb=10afa56c18322075c75ff2616ac23853bd0c87ca;hp=2750614e7555e98a25bd973d215fb266ed39f5df;hpb=8272f8013305da9dd2b1e4fadb5aa7327f63d8e3;p=modules%2Fshaper.git diff --git a/src/Model/Model_PluginManager.cpp b/src/Model/Model_PluginManager.cpp index 2750614e7..05f1586e6 100644 --- a/src/Model/Model_PluginManager.cpp +++ b/src/Model/Model_PluginManager.cpp @@ -8,10 +8,18 @@ #include #include #include +#include #include +#include #include #include +#include +#include +#include +#include + + using namespace std; static Model_PluginManager* myImpl = new Model_PluginManager(); @@ -25,12 +33,18 @@ boost::shared_ptr Model_PluginManager::createFeature(string th myCurrentPluginName = myPlugins[theFeatureID]; if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) { // load plugin library if not yet done - loadLibrary(myCurrentPluginName); + Config_ModuleReader::loadLibrary(myCurrentPluginName); } if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) { boost::shared_ptr 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 + "'"); } } @@ -50,7 +64,7 @@ bool Model_PluginManager::hasRootDocument() boost::shared_ptr Model_PluginManager::currentDocument() { - if (!myCurrentDoc) + if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id())) myCurrentDoc = rootDocument(); return myCurrentDoc; } @@ -60,30 +74,58 @@ void Model_PluginManager::setCurrentDocument(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 Events_ID aFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent"); - ModelAPI_PluginManager::SetPluginManager(boost::shared_ptr(this)); // register the configuration reading listener Events_Loop* aLoop = Events_Loop::loop(); - aLoop->registerListener(this, aFeatureEvent); + 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 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 (!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 +135,6 @@ void Model_PluginManager::LoadPluginsInfo() // Read plugins information from XML files Config_ModuleReader aXMLReader("FeatureRegisterEvent"); - aXMLReader.setAutoImport(true); aXMLReader.readAll(); }