#include <Model_Data.h>
#include <Model_Document.h>
#include <Model_Application.h>
-#include <Event_Loop.h>
+#include <Model_Events.h>
+#include <Model_Validator.h>
+#include <Events_Loop.h>
+#include <Events_Error.h>
#include <Config_FeatureMessage.h>
#include <Config_ModuleReader.h>
+#include <TDF_CopyTool.hxx>
+#include <TDF_DataSet.hxx>
+#include <TDF_RelocationTable.hxx>
+#include <TDF_ClosureTool.hxx>
+
+
using namespace std;
static Model_PluginManager* myImpl = new Model_PluginManager();
-shared_ptr<ModelAPI_Feature> 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<ModelAPI_Feature> 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<ModelAPI_Feature>(); // return nothing
+ return FeaturePtr(); // return nothing
}
-std::shared_ptr<ModelAPI_Document> Model_PluginManager::rootDocument()
+boost::shared_ptr<ModelAPI_Document> Model_PluginManager::rootDocument()
{
- return std::shared_ptr<ModelAPI_Document>(
+ return boost::shared_ptr<ModelAPI_Document>(
Model_Application::getApplication()->getDocument("root"));
}
return Model_Application::getApplication()->hasDocument("root");
}
-shared_ptr<ModelAPI_Document> Model_PluginManager::currentDocument()
+boost::shared_ptr<ModelAPI_Document> Model_PluginManager::currentDocument()
{
- if (!myCurrentDoc)
+ if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id()))
myCurrentDoc = rootDocument();
return myCurrentDoc;
}
-void Model_PluginManager::setCurrentDocument(shared_ptr<ModelAPI_Document> theDoc)
+void Model_PluginManager::setCurrentDocument(boost::shared_ptr<ModelAPI_Document> theDoc)
{
myCurrentDoc = theDoc;
+ static Events_Message aMsg(Events_Loop::eventByName("CurrentDocumentChanged"));
+ Events_Loop::loop()->send(aMsg);
+}
+
+boost::shared_ptr<ModelAPI_Document> Model_PluginManager::copy(
+ boost::shared_ptr<ModelAPI_Document> theSource, std::string theID)
+{
+ // create a new document
+ boost::shared_ptr<Model_Document> aNew = boost::dynamic_pointer_cast<Model_Document>(
+ Model_Application::getApplication()->getDocument(theID));
+ // make a copy of all labels
+ TDF_Label aSourceRoot =
+ boost::dynamic_pointer_cast<Model_Document>(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<ModelAPI_PluginManager>(this));
+ myCheckTransactions = true;
+ ModelAPI_PluginManager::setPluginManager(boost::shared_ptr<ModelAPI_PluginManager>(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<const Config_FeatureMessage*>(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<const Config_FeatureMessage*>(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()
// Read plugins information from XML files
Config_ModuleReader aXMLReader("FeatureRegisterEvent");
- aXMLReader.setAutoImport(true);
aXMLReader.readAll();
}
{
myPluginObjs[myCurrentPluginName] = thePlugin;
}
+
+ModelAPI_ValidatorsFactory* Model_PluginManager::validators()
+{
+ static Model_ValidatorsFactory* aFactory = new Model_ValidatorsFactory;
+ return aFactory;
+}