Salome HOME
Issue #83: renamed PluginManager to Session
authormpv <mikhail.ponikarov@opencascade.com>
Thu, 11 Sep 2014 08:20:39 +0000 (12:20 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Thu, 11 Sep 2014 08:20:39 +0000 (12:20 +0400)
45 files changed:
src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp
src/ConstructionPlugin/ConstructionPlugin_Point.cpp
src/ExchangePlugin/ExchangePlugin_Plugin.cpp
src/ExchangePlugin/ExchangePlugin_Validators.cpp
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/Model/CMakeLists.txt
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_PluginManager.cpp [deleted file]
src/Model/Model_PluginManager.h [deleted file]
src/Model/Model_ResultPart.cpp
src/Model/Model_Session.cpp [new file with mode: 0644]
src/Model/Model_Session.h [new file with mode: 0644]
src/Model/Model_Update.cpp
src/Model/Model_Validator.h
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_Feature.cpp
src/ModelAPI/ModelAPI_Feature.h
src/ModelAPI/ModelAPI_PluginManager.cpp [deleted file]
src/ModelAPI/ModelAPI_PluginManager.h [deleted file]
src/ModelAPI/ModelAPI_Session.cpp [new file with mode: 0644]
src/ModelAPI/ModelAPI_Session.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Validator.h
src/ModuleBase/ModuleBase_IOperation.cpp
src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_WidgetFeature.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_TestOCC.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSetPlugin/PartSetPlugin_Duplicate.cpp
src/PartSetPlugin/PartSetPlugin_Part.cpp
src/PartSetPlugin/PartSetPlugin_Plugin.cpp
src/PartSetPlugin/PartSetPlugin_Remove.cpp
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchSolver/SketchSolver_ConstraintManager.cpp
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_PartDataModel.cpp
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_Workshop.cpp

index 60d5694f581cd0e328b481759a95abe52efe05b4..fd5db868fc7443bf50cd3b982f2a15c7b5fa291f 100644 (file)
@@ -1,7 +1,7 @@
 #include "ConstructionPlugin_Plugin.h"
 #include "ConstructionPlugin_Point.h"
 
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
 
 using namespace std;
@@ -12,7 +12,7 @@ static ConstructionPlugin_Plugin* MY_INSTANCE = new ConstructionPlugin_Plugin();
 ConstructionPlugin_Plugin::ConstructionPlugin_Plugin()
 {
   // register this plugin
-  ModelAPI_PluginManager::get()->registerPlugin(this);
+  ModelAPI_Session::get()->registerPlugin(this);
 }
 
 FeaturePtr ConstructionPlugin_Plugin::createFeature(string theFeatureID)
index e39bcc06efd38d8591c7f833c06ef193011a183a..61c20a9ee79333a3b6de3d27f32d63fd5df2d94e 100644 (file)
@@ -3,7 +3,7 @@
 // Author:      Mikhail PONIKAROV
 
 #include "ConstructionPlugin_Point.h"
-#include "ModelAPI_PluginManager.h"
+#include "ModelAPI_Session.h"
 #include "ModelAPI_Document.h"
 #include "ModelAPI_Data.h"
 #include "ModelAPI_AttributeDouble.h"
index 97d2b6e587fa4d413198470800e1ca886b42cf8d..b3256862a1c9e1c726bae79e19fec8e41d6477fc 100644 (file)
@@ -5,7 +5,7 @@
 #include <ExchangePlugin_Plugin.h>
 #include <ExchangePlugin_ImportFeature.h>
 
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 
 #include <boost/smart_ptr/shared_ptr.hpp>
 
@@ -17,7 +17,7 @@ static ExchangePlugin_Plugin* MY_INSTANCE = new ExchangePlugin_Plugin();
 ExchangePlugin_Plugin::ExchangePlugin_Plugin()
 {
   // register this plugin
-  ModelAPI_PluginManager::get()->registerPlugin(this);
+  ModelAPI_Session::get()->registerPlugin(this);
 }
 
 FeaturePtr ExchangePlugin_Plugin::createFeature(string theFeatureID)
index 2560fb6213837d9cb567e48812f1a6551c600d71..f179e889bc0f7b632c7670555959636f208ab67f 100644 (file)
@@ -5,7 +5,7 @@
 #include <ExchangePlugin_Validators.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Object.h>
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 
 #include <list>
 #include <string>
@@ -14,7 +14,7 @@
 bool ExchangePlugin_ImportFormatValidator::isValid(
   const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
 {
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
   return false;
 }
index 1fb6e46d58089ea69e474bbf0f0daa8fff9bcecc..295fb1c9de489e55cd14f0df7190b7c341e05625 100644 (file)
@@ -3,7 +3,7 @@
 // Author:      Vitaly SMETANNIKOV
 
 #include "FeaturesPlugin_Extrusion.h"
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_ResultConstruction.h>
index 5c3fd3a4335c3beb3d5126536b28c03c9d392b96..7d4e26185482a45c948b9eb8c7433e8856a41378 100644 (file)
@@ -2,7 +2,7 @@
 #include "FeaturesPlugin_Extrusion.h"
 #include "FeaturesPlugin_Boolean.h"
 
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
 
 using namespace std;
@@ -13,7 +13,7 @@ static FeaturesPlugin_Plugin* MY_INSTANCE = new FeaturesPlugin_Plugin();
 FeaturesPlugin_Plugin::FeaturesPlugin_Plugin()
 {
   // register this plugin
-  ModelAPI_PluginManager::get()->registerPlugin(this);
+  ModelAPI_Session::get()->registerPlugin(this);
 }
 
 FeaturePtr FeaturesPlugin_Plugin::createFeature(string theFeatureID)
index 1642fbaca30f73cd6ab6a0940e27de69f5309b09..8e54742a9ab58b528339d6f9adf6cf1235cdb727 100644 (file)
@@ -4,7 +4,7 @@ SET(PROJECT_HEADERS
     Model.h
     Model_Application.h
     Model_Document.h
-    Model_PluginManager.h
+    Model_Session.h
     Model_Data.h
     Model_AttributeDouble.h
     Model_AttributeDocRef.h
@@ -26,7 +26,7 @@ SET(PROJECT_HEADERS
 SET(PROJECT_SOURCES
     Model_Application.cpp
     Model_Document.cpp
-    Model_PluginManager.cpp
+    Model_Session.cpp
     Model_Data.cpp
     Model_AttributeDouble.cpp
     Model_AttributeDocRef.cpp
index cb1b6d3073a089da1cfbfa54e900888ff0bf6496..b66318687afd51c2a32e52caa3ecf4e46dd2092f 100644 (file)
@@ -5,7 +5,7 @@
 #include <Model_Document.h>
 #include <Model_Data.h>
 #include <Model_Application.h>
-#include <Model_PluginManager.h>
+#include <Model_Session.h>
 #include <Model_Events.h>
 #include <Model_ResultPart.h>
 #include <Model_ResultConstruction.h>
@@ -74,7 +74,7 @@ static TCollection_ExtendedString DocFileName(const char* theFileName, const std
 bool Model_Document::load(const char* theFileName)
 {
   Handle(Model_Application) anApp = Model_Application::getApplication();
-  if (this == Model_PluginManager::get()->rootDocument().get()) {
+  if (this == Model_Session::get()->rootDocument().get()) {
     anApp->setLoadPath(theFileName);
   }
   TCollection_ExtendedString aPath(DocFileName(theFileName, myID));
@@ -151,7 +151,7 @@ bool Model_Document::load(const char* theFileName)
 bool Model_Document::save(const char* theFileName, std::list<std::string>& theResults)
 {
   // create a directory in the root document if it is not yet exist
-  if (this == Model_PluginManager::get()->rootDocument().get()) {
+  if (this == Model_Session::get()->rootDocument().get()) {
 #ifdef WIN32
     CreateDirectory(theFileName, NULL);
 #else
@@ -196,7 +196,7 @@ bool Model_Document::save(const char* theFileName, std::list<std::string>& theRe
 
 void Model_Document::close()
 {
-  boost::shared_ptr<ModelAPI_PluginManager> aPM = Model_PluginManager::get();
+  boost::shared_ptr<ModelAPI_Session> aPM = Model_Session::get();
   if (this != aPM->rootDocument().get() && this == aPM->currentDocument().get()) {
     aPM->setCurrentDocument(aPM->rootDocument());
   }
@@ -253,7 +253,7 @@ void Model_Document::finishOperation()
   // just to be sure that everybody knows that changes were performed
 
   if (!myDoc->HasOpenCommand() && myNestedNum != -1)
-    boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())
+    boost::static_pointer_cast<Model_Session>(Model_Session::get())
         ->setCheckTransactions(false);  // for nested transaction commit
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
@@ -261,7 +261,7 @@ void Model_Document::finishOperation()
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
   if (!myDoc->HasOpenCommand() && myNestedNum != -1)
-    boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())
+    boost::static_pointer_cast<Model_Session>(Model_Session::get())
         ->setCheckTransactions(true);  // for nested transaction commit
 
   if (myNestedNum != -1)  // this nested transaction is owervritten
@@ -392,7 +392,7 @@ FeaturePtr Model_Document::addFeature(std::string theID)
 {
   TDF_Label anEmptyLab;
   FeaturePtr anEmptyFeature;
-  FeaturePtr aFeature = ModelAPI_PluginManager::get()->createFeature(theID);
+  FeaturePtr aFeature = ModelAPI_Session::get()->createFeature(theID);
   boost::shared_ptr<Model_Document> aDocToAdd = boost::dynamic_pointer_cast<Model_Document>(
       aFeature->documentToAdd());
   if (aFeature) {
@@ -655,7 +655,7 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
   boost::shared_ptr<ModelAPI_Document> aThis = 
     Model_Application::getApplication()->getDocument(myID);
   // after all updates, sends a message that groups of features were created or updated
-  boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())
+  boost::static_pointer_cast<Model_Session>(Model_Session::get())
     ->setCheckTransactions(false);
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->activateFlushes(false);
@@ -667,7 +667,7 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
     TDF_Label aFeatureLabel = aLabIter.Value()->Label();
     if (!myObjs.IsBound(aFeatureLabel)) {  // a new feature is inserted
       // create a feature
-      FeaturePtr aNewObj = ModelAPI_PluginManager::get()->createFeature(
+      FeaturePtr aNewObj = ModelAPI_Session::get()->createFeature(
           TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(aLabIter.Value())->Get())
               .ToCString());
       if (!aNewObj) {  // somethig is wrong, most probably, the opened document has invalid structure
@@ -739,7 +739,7 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
   }
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-  boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())
+  boost::static_pointer_cast<Model_Session>(Model_Session::get())
     ->setCheckTransactions(true);
   myExecuteFeatures = true;
 }
index 7b407252052d97afed27e17a523034b7a5fe7e50..7024925edb0609f01bc96f74538e597d24f43678 100644 (file)
@@ -160,7 +160,7 @@ class Model_Document : public ModelAPI_Document
   void updateResults(FeaturePtr theFeature);
 
   friend class Model_Application;
-  friend class Model_PluginManager;
+  friend class Model_Session;
   friend class DFBrowser;
 
  private:
diff --git a/src/Model/Model_PluginManager.cpp b/src/Model/Model_PluginManager.cpp
deleted file mode 100644 (file)
index ad5767a..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-// File:        Model_PluginManager.cxx
-// Created:     20 Mar 2014
-// Author:      Mikhail PONIKAROV
-
-#include <Model_PluginManager.h>
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_Plugin.h>
-#include <Model_Data.h>
-#include <Model_Document.h>
-#include <Model_Application.h>
-#include <Model_Events.h>
-#include <Model_Validator.h>
-#include <Events_Loop.h>
-#include <Events_Error.h>
-#include <Config_FeatureMessage.h>
-#include <Config_ValidatorMessage.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();
-
-FeaturePtr Model_PluginManager::createFeature(string theFeatureID)
-{
-  if (this != myImpl)
-    return myImpl->createFeature(theFeatureID);
-
-  LoadPluginsInfo();
-  if (myPlugins.find(theFeatureID) != myPlugins.end()) {
-    myCurrentPluginName = myPlugins[theFeatureID];
-    if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) {
-      // load plugin library if not yet done
-      Config_ModuleReader::loadLibrary(myCurrentPluginName);
-    }
-    if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
-      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 + "'");
-    }
-  } else {
-    Events_Error::send(string("Feature '") + theFeatureID + "' not found in any plugin");
-  }
-
-  return FeaturePtr();  // return nothing
-}
-
-boost::shared_ptr<ModelAPI_Document> Model_PluginManager::rootDocument()
-{
-  return boost::shared_ptr<ModelAPI_Document>(
-      Model_Application::getApplication()->getDocument("root"));
-}
-
-bool Model_PluginManager::hasRootDocument()
-{
-  return Model_Application::getApplication()->hasDocument("root");
-}
-
-boost::shared_ptr<ModelAPI_Document> Model_PluginManager::currentDocument()
-{
-  if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id()))
-    myCurrentDoc = rootDocument();
-  return myCurrentDoc;
-}
-
-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;
-  myCheckTransactions = true;
-  ModelAPI_PluginManager::setPluginManager(boost::shared_ptr<ModelAPI_PluginManager>(this));
-  // register the configuration reading listener
-  Events_Loop* aLoop = Events_Loop::loop();
-  static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent");
-  aLoop->registerListener(this, kFeatureEvent);
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_VALIDATOR_LOADED));
-}
-
-void Model_PluginManager::processEvent(const Events_Message* theMessage)
-{
-  static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent");
-  static const Events_ID kValidatorEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
-  if (theMessage->eventID() == kFeatureEvent) {
-    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 if (theMessage->eventID() == kValidatorEvent) {
-    const Config_ValidatorMessage* aMsg = dynamic_cast<const Config_ValidatorMessage*>(theMessage);
-    if (aMsg) {
-      if (aMsg->attributeId().empty()) {  // feature validator
-        validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->parameters());
-      } else {  // attribute validator
-        validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->attributeId(),
-                                      aMsg->parameters());
-      }
-    }
-  } else {  // create/update/delete
-    if (myCheckTransactions && !rootDocument()->isOperation())
-      Events_Error::send("Modification of data structure outside of the transaction");
-  }
-}
-
-void Model_PluginManager::LoadPluginsInfo()
-{
-  if (myPluginsInfoLoaded)  // nothing to do
-    return;
-
-  // Read plugins information from XML files
-  Config_ModuleReader aXMLReader("FeatureRegisterEvent");
-  aXMLReader.readAll();
-}
-
-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()
-{
-  static Model_ValidatorsFactory* aFactory = new Model_ValidatorsFactory;
-  return aFactory;
-}
diff --git a/src/Model/Model_PluginManager.h b/src/Model/Model_PluginManager.h
deleted file mode 100644 (file)
index a1187a1..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-// File:        Model_PluginManager.hxx
-// Created:     20 Mar 2014
-// Author:      Mikhail PONIKAROV
-
-#ifndef Model_PluginManager_H_
-#define Model_PluginManager_H_
-
-#include "Model.h"
-#include <ModelAPI_PluginManager.h>
-#include <ModelAPI_Feature.h>
-
-#include <Events_Listener.h>
-#include <map>
-
-class Model_Document;
-
-/**\class Model_PluginManager
- * \ingroup DataModel
- * \brief Object that knows (from the initial XML file) which
- * plugin contains which feature, loads and stores reference to loaded plugins by
- * the feature functionality request.
- */
-class Model_PluginManager : public ModelAPI_PluginManager, public Events_Listener
-{
-  bool myPluginsInfoLoaded;  ///< it true if plugins information is loaded
-  /// map of feature IDs to plugin name
-  std::map<std::string, std::string> myPlugins;
-  std::map<std::string, ModelAPI_Plugin*> myPluginObjs;  ///< instances of the already plugins
-  std::string myCurrentPluginName;  ///< name of the plugin that must be loaded currently
-  boost::shared_ptr<ModelAPI_Document> myCurrentDoc;  ///< current working document
-  bool myCheckTransactions;  ///< if true, generates error if document is updated outside of transaction
- public:
-  /// Returns the root document of the application (that may contains sub-documents)
-  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> rootDocument();
-
-  /// Return true if root document has been already created
-  MODEL_EXPORT virtual bool hasRootDocument();
-
-  /// Returns the current document that used for current work in the application
-  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> currentDocument();
-
-  /// Defines the current document that used for current work in the application
-  MODEL_EXPORT virtual void setCurrentDocument(boost::shared_ptr<ModelAPI_Document> theDoc);
-
-  /// Registers the plugin that creates features.
-  /// It is obligatory for each plugin to call this function on loading to be found by 
-  /// the plugin manager on call of the feature)
-  MODEL_EXPORT virtual void registerPlugin(ModelAPI_Plugin* thePlugin);
-
-  /// Processes the configuration file reading
-  MODEL_EXPORT virtual void processEvent(const Events_Message* theMessage);
-
-  /// Copies the document to the new one wit hthe given id
-  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> copy(
-      boost::shared_ptr<ModelAPI_Document> theSource, std::string theID);
-
-  /// Returns the validators factory: the only one instance per application
-  MODEL_EXPORT virtual ModelAPI_ValidatorsFactory* validators();
-
-  void setCheckTransactions(const bool theCheck)
-  {
-    myCheckTransactions = theCheck;
-  }
-
-  /// Is called only once, on startup of the application
-  Model_PluginManager();
-
- protected:
-  /// Loads (if not done yet) the information about the features and plugins
-  void LoadPluginsInfo();
-
-  /// Creates the feature object using plugins functionality
-  virtual FeaturePtr createFeature(std::string theFeatureID);
-};
-
-#endif
index cdafeb6d0e7ae59a9603ea6b3063d17a5e577a27..6d1afbf48bff9c9dd87c5021403bb44531113518 100644 (file)
@@ -5,7 +5,7 @@
 #include <Model_ResultPart.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeDocRef.h>
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 
 boost::shared_ptr<ModelAPI_Document> Model_ResultPart::partDoc()
 {
@@ -40,5 +40,5 @@ void Model_ResultPart::activate()
     }
   }
   if (aDocRef->value())
-    ModelAPI_PluginManager::get()->setCurrentDocument(aDocRef->value());
+    ModelAPI_Session::get()->setCurrentDocument(aDocRef->value());
 }
diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp
new file mode 100644 (file)
index 0000000..730b6ec
--- /dev/null
@@ -0,0 +1,171 @@
+// File:        Model_Session.cxx
+// Created:     20 Mar 2014
+// Author:      Mikhail PONIKAROV
+
+#include <Model_Session.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Plugin.h>
+#include <Model_Data.h>
+#include <Model_Document.h>
+#include <Model_Application.h>
+#include <Model_Events.h>
+#include <Model_Validator.h>
+#include <Events_Loop.h>
+#include <Events_Error.h>
+#include <Config_FeatureMessage.h>
+#include <Config_ValidatorMessage.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_Session* myImpl = new Model_Session();
+
+FeaturePtr Model_Session::createFeature(string theFeatureID)
+{
+  if (this != myImpl)
+    return myImpl->createFeature(theFeatureID);
+
+  LoadPluginsInfo();
+  if (myPlugins.find(theFeatureID) != myPlugins.end()) {
+    myCurrentPluginName = myPlugins[theFeatureID];
+    if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) {
+      // load plugin library if not yet done
+      Config_ModuleReader::loadLibrary(myCurrentPluginName);
+    }
+    if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
+      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 + "'");
+    }
+  } else {
+    Events_Error::send(string("Feature '") + theFeatureID + "' not found in any plugin");
+  }
+
+  return FeaturePtr();  // return nothing
+}
+
+boost::shared_ptr<ModelAPI_Document> Model_Session::rootDocument()
+{
+  return boost::shared_ptr<ModelAPI_Document>(
+      Model_Application::getApplication()->getDocument("root"));
+}
+
+bool Model_Session::hasRootDocument()
+{
+  return Model_Application::getApplication()->hasDocument("root");
+}
+
+boost::shared_ptr<ModelAPI_Document> Model_Session::currentDocument()
+{
+  if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id()))
+    myCurrentDoc = rootDocument();
+  return myCurrentDoc;
+}
+
+void Model_Session::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_Session::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_Session::Model_Session()
+{
+  myPluginsInfoLoaded = false;
+  myCheckTransactions = true;
+  ModelAPI_Session::setSession(boost::shared_ptr<ModelAPI_Session>(this));
+  // register the configuration reading listener
+  Events_Loop* aLoop = Events_Loop::loop();
+  static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent");
+  aLoop->registerListener(this, kFeatureEvent);
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_VALIDATOR_LOADED));
+}
+
+void Model_Session::processEvent(const Events_Message* theMessage)
+{
+  static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent");
+  static const Events_ID kValidatorEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
+  if (theMessage->eventID() == kFeatureEvent) {
+    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 if (theMessage->eventID() == kValidatorEvent) {
+    const Config_ValidatorMessage* aMsg = dynamic_cast<const Config_ValidatorMessage*>(theMessage);
+    if (aMsg) {
+      if (aMsg->attributeId().empty()) {  // feature validator
+        validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->parameters());
+      } else {  // attribute validator
+        validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->attributeId(),
+                                      aMsg->parameters());
+      }
+    }
+  } else {  // create/update/delete
+    if (myCheckTransactions && !rootDocument()->isOperation())
+      Events_Error::send("Modification of data structure outside of the transaction");
+  }
+}
+
+void Model_Session::LoadPluginsInfo()
+{
+  if (myPluginsInfoLoaded)  // nothing to do
+    return;
+
+  // Read plugins information from XML files
+  Config_ModuleReader aXMLReader("FeatureRegisterEvent");
+  aXMLReader.readAll();
+}
+
+void Model_Session::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_Session::validators()
+{
+  static Model_ValidatorsFactory* aFactory = new Model_ValidatorsFactory;
+  return aFactory;
+}
diff --git a/src/Model/Model_Session.h b/src/Model/Model_Session.h
new file mode 100644 (file)
index 0000000..cc1494a
--- /dev/null
@@ -0,0 +1,76 @@
+// File:        Model_Session.hxx
+// Created:     20 Mar 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef Model_Session_H_
+#define Model_Session_H_
+
+#include "Model.h"
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Feature.h>
+
+#include <Events_Listener.h>
+#include <map>
+
+class Model_Document;
+
+/**\class Model_Session
+ * \ingroup DataModel
+ * \brief Object that knows (from the initial XML file) which
+ * plugin contains which feature, loads and stores reference to loaded plugins by
+ * the feature functionality request.
+ */
+class Model_Session : public ModelAPI_Session, public Events_Listener
+{
+  bool myPluginsInfoLoaded;  ///< it true if plugins information is loaded
+  /// map of feature IDs to plugin name
+  std::map<std::string, std::string> myPlugins;
+  std::map<std::string, ModelAPI_Plugin*> myPluginObjs;  ///< instances of the already plugins
+  std::string myCurrentPluginName;  ///< name of the plugin that must be loaded currently
+  boost::shared_ptr<ModelAPI_Document> myCurrentDoc;  ///< current working document
+  bool myCheckTransactions;  ///< if true, generates error if document is updated outside of transaction
+ public:
+  /// Returns the root document of the application (that may contains sub-documents)
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> rootDocument();
+
+  /// Return true if root document has been already created
+  MODEL_EXPORT virtual bool hasRootDocument();
+
+  /// Returns the current document that used for current work in the application
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> currentDocument();
+
+  /// Defines the current document that used for current work in the application
+  MODEL_EXPORT virtual void setCurrentDocument(boost::shared_ptr<ModelAPI_Document> theDoc);
+
+  /// Registers the plugin that creates features.
+  /// It is obligatory for each plugin to call this function on loading to be found by 
+  /// the plugin manager on call of the feature)
+  MODEL_EXPORT virtual void registerPlugin(ModelAPI_Plugin* thePlugin);
+
+  /// Processes the configuration file reading
+  MODEL_EXPORT virtual void processEvent(const Events_Message* theMessage);
+
+  /// Copies the document to the new one wit hthe given id
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> copy(
+      boost::shared_ptr<ModelAPI_Document> theSource, std::string theID);
+
+  /// Returns the validators factory: the only one instance per application
+  MODEL_EXPORT virtual ModelAPI_ValidatorsFactory* validators();
+
+  void setCheckTransactions(const bool theCheck)
+  {
+    myCheckTransactions = theCheck;
+  }
+
+  /// Is called only once, on startup of the application
+  Model_Session();
+
+ protected:
+  /// Loads (if not done yet) the information about the features and plugins
+  void LoadPluginsInfo();
+
+  /// Creates the feature object using plugins functionality
+  virtual FeaturePtr createFeature(std::string theFeatureID);
+};
+
+#endif
index 875d22dd1ad567ddfa7f43f6ed3a91f9e7bbeae6..380d12b3f0f52dfa072ec4ce7ff4bb269336fa62 100644 (file)
@@ -117,7 +117,7 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
 
       if (boost::dynamic_pointer_cast<Model_Document>(theFeature->document())->executeFeatures() ||
           !theFeature->isPersistentResult()) {
-        ModelAPI_ValidatorsFactory* aFactory = ModelAPI_PluginManager::get()->validators();
+        ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
         if (aFactory->validate(theFeature)) {
           try {
             theFeature->execute();
index f6f42b3cffc615371204ac532117bd18d965d691..0312954859cb0a1709f89591fb436e424ac4763e 100644 (file)
@@ -17,7 +17,7 @@
  * Allows to get a validator by the feature identifier and 
  * the attribute identifier (if attribute is validated).
  * All accessible validators mustbe registered by the ID string first.
- * The instance of this factory can be get in the PluginManager.
+ * The instance of this factory can be get in the Session.
  * Keeps the validator objects alive and just returns one of it by request.
  * All the needed information is provided to the validator as an argument,
  * this allows to work with them independently from the feature specific object.
@@ -70,10 +70,10 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
 
  protected:
   void addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const;
-  /// Get instance from PluginManager
+  /// Get instance from Session
   Model_ValidatorsFactory();
 
-  friend class Model_PluginManager;
+  friend class Model_Session;
 };
 
 #endif
index ccac1a79e606cb1349438fdfa8ffc0ded4eec812..9af7ad47a800884d7d7d2a07fc99bdb01d9a12fa 100644 (file)
@@ -5,7 +5,7 @@ INCLUDE(UnitTest)
 
 SET(PROJECT_HEADERS
     ModelAPI.h
-    ModelAPI_PluginManager.h
+    ModelAPI_Session.h
     ModelAPI_Plugin.h
     ModelAPI_Feature.h
     ModelAPI_Data.h
@@ -36,7 +36,7 @@ SET(PROJECT_HEADERS
 
 SET(PROJECT_SOURCES
     ModelAPI_Feature.cpp
-    ModelAPI_PluginManager.cpp
+    ModelAPI_Session.cpp
     ModelAPI_Tools.cpp
 )
 
index dbcb59eaf3cccc62f13c0bdf06c36dcc3a45a2ea..c8fddd2f80a00c3f695fb563f26e7fd0ce238616 100644 (file)
@@ -5,7 +5,7 @@
   #include "GeomAPI_Shape.h"
   #include "ModelAPI.h"
   #include "ModelAPI_Document.h"
-  #include "ModelAPI_PluginManager.h"
+  #include "ModelAPI_Session.h"
   #include "ModelAPI_Object.h"
   #include "ModelAPI_Feature.h"
   #include "ModelAPI_Data.h"
@@ -44,7 +44,7 @@
 %shared_ptr(GeomAPI_Interface)
 %shared_ptr(GeomAPI_Shape)
 %shared_ptr(ModelAPI_Document)
-%shared_ptr(ModelAPI_PluginManager)
+%shared_ptr(ModelAPI_Session)
 %shared_ptr(ModelAPI_Object)
 %shared_ptr(ModelAPI_Feature)
 %shared_ptr(ModelAPI_Data)
@@ -63,7 +63,7 @@
 %include "GeomAPI_Interface.h"
 %include "GeomAPI_Shape.h"
 %include "ModelAPI_Document.h"
-%include "ModelAPI_PluginManager.h"
+%include "ModelAPI_Session.h"
 %include "ModelAPI_Object.h"
 %include "ModelAPI_Feature.h"
 %include "ModelAPI_Data.h"
index 488c8e55ffc7f861a8dfd75823efbdd31d8fa872..72fdcd9b320025bf4a9bb3f13fcc8ae334f109ef 100644 (file)
@@ -88,7 +88,7 @@ void ModelAPI_Feature::eraseResults()
 
 boost::shared_ptr<ModelAPI_Document> ModelAPI_Feature::documentToAdd()
 {
-  return ModelAPI_PluginManager::get()->currentDocument();
+  return ModelAPI_Session::get()->currentDocument();
 }
 
 ModelAPI_Feature::~ModelAPI_Feature()
index ef1212afc7156b1f32412d5315fe2ed080f330e3..2c252429df3943d7e9530b33a8945a6bd7f58975 100644 (file)
@@ -6,7 +6,7 @@
 #define ModelAPI_Feature_H_
 
 #include "ModelAPI_Object.h"
-#include "ModelAPI_PluginManager.h"
+#include "ModelAPI_Session.h"
 
 #include <string>
 #include <list>
diff --git a/src/ModelAPI/ModelAPI_PluginManager.cpp b/src/ModelAPI/ModelAPI_PluginManager.cpp
deleted file mode 100644 (file)
index 52f14de..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-// File:        ModelAPI_PluginManager.hxx
-// Created:     20 Mar 2014
-// Author:      Mikhail PONIKAROV
-
-#include <ModelAPI_PluginManager.h>
-// to avoid unresolved ModelAPI_Document()
-#include <ModelAPI_Document.h>
-// to avoid unresolved ModelAPI_Feature()
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_Object.h>
-// to avoid unresolved ModelAPI_Data()
-#include <ModelAPI_Data.h>
-// to avoid unresolved ModelAPI_Plugin()
-#include <ModelAPI_Plugin.h>
-#include <ModelAPI_Attribute.h>
-#include <ModelAPI_AttributeDocRef.h>
-#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeBoolean.h>
-#include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_AttributeString.h>
-#include <ModelAPI_AttributeReference.h>
-#include <ModelAPI_AttributeRefAttr.h>
-#include <ModelAPI_AttributeRefList.h>
-#include <ModelAPI_Events.h>
-#include <ModelAPI_Validator.h>
-
-#include <Config_ModuleReader.h>
-
-#ifdef WIN32
-#include <windows.h>
-#else
-#include <dlfcn.h>
-#endif
-
-using namespace std;
-
-#ifdef _DEBUG
-#include <iostream>
-#endif
-
-/// Manager that will be initialized from Model package, one per application
-boost::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
-
-ModelAPI_PluginManager::ModelAPI_PluginManager()
-{
-}
-
-void ModelAPI_PluginManager::setPluginManager(boost::shared_ptr<ModelAPI_PluginManager> theManager)
-{
-  MY_MANAGER = theManager;
-}
-
-boost::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
-{
-  if (!MY_MANAGER) {  // import Model library that implements this interface of ModelAPI
-    Config_ModuleReader::loadLibrary("Model");
-  }
-  return MY_MANAGER;
-}
-
-const ModelAPI_EventCreator* MY_API_CREATOR = 0;  ///< instance of the events creator, one pre application
-
-const ModelAPI_EventCreator* ModelAPI_EventCreator::get()
-{
-  if (!MY_API_CREATOR) {  // import Model library that implements this interface of ModelAPI
-    Config_ModuleReader::loadLibrary("Model");
-  }
-  return MY_API_CREATOR;
-}
-
-void ModelAPI_EventCreator::set(const ModelAPI_EventCreator* theCreator)
-{
-  MY_API_CREATOR = theCreator;
-}
diff --git a/src/ModelAPI/ModelAPI_PluginManager.h b/src/ModelAPI/ModelAPI_PluginManager.h
deleted file mode 100644 (file)
index 90a59a9..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-// File:        ModelAPI_PluginManager.hxx
-// Created:     20 Mar 2014
-// Author:      Mikhail PONIKAROV
-
-#ifndef ModelAPI_PluginManager_H_
-#define ModelAPI_PluginManager_H_
-
-#include "ModelAPI.h"
-#include <string>
-#include <boost/shared_ptr.hpp>
-
-class ModelAPI_Feature;
-class ModelAPI_Plugin;
-class ModelAPI_Document;
-class ModelAPI_ValidatorsFactory;
-
-/**\class ModelAPI_PluginManager
- * \ingroup DataModel
- * \brief Object that knows (from the initial XML file) which
- * plugin contains which feature, loads and stores reference to loaded plugins by
- * the feature functionality request.
- */
-
-class MODELAPI_EXPORT ModelAPI_PluginManager
-{
- public:
-  /// Returns the real implementation (the alone instance per application) of the plugin manager
-  static boost::shared_ptr<ModelAPI_PluginManager> get();
-
-  /// Registers the plugin that creates features.
-  /// It is obligatory for each plugin to call this function on loading to be found by 
-  /// the plugin manager on call of the feature)
-  virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0;
-
-  /// Returns the root document of the application (that may contains sub-documents)
-  virtual boost::shared_ptr<ModelAPI_Document> rootDocument() = 0;
-
-  /// Return true if root document has been already created
-  virtual bool hasRootDocument() = 0;
-
-  /// Returns the current document that used for current work in the application
-  virtual boost::shared_ptr<ModelAPI_Document> currentDocument() = 0;
-
-  /// Defines the current document that used for current work in the application
-  virtual void setCurrentDocument(boost::shared_ptr<ModelAPI_Document> theDoc) = 0;
-
-  /// Copies the document to the new one wit hthe given id
-  virtual boost::shared_ptr<ModelAPI_Document> copy(boost::shared_ptr<ModelAPI_Document> theSource,
-                                                    std::string theID) = 0;
-
-  /// Returns the validators factory: the only one instance per application
-  virtual ModelAPI_ValidatorsFactory* validators() = 0;
-
-  /// Is needed for python wrapping by swig, call Get to get an instance
-  ModelAPI_PluginManager();
-
-  /// To virtually destroy the fields of successors
-  virtual ~ModelAPI_PluginManager()
-  {
-  }
-
- protected:
-  /// Creates the feature object using plugins functionality
-  virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
-
-  static void setPluginManager(boost::shared_ptr<ModelAPI_PluginManager> theManager);
-
-  friend class Model_Document;
-};
-
-typedef boost::shared_ptr<ModelAPI_PluginManager> PluginManagerPtr;
-
-#endif
diff --git a/src/ModelAPI/ModelAPI_Session.cpp b/src/ModelAPI/ModelAPI_Session.cpp
new file mode 100644 (file)
index 0000000..1a6ebf6
--- /dev/null
@@ -0,0 +1,74 @@
+// File:        ModelAPI_Session.hxx
+// Created:     20 Mar 2014
+// Author:      Mikhail PONIKAROV
+
+#include <ModelAPI_Session.h>
+// to avoid unresolved ModelAPI_Document()
+#include <ModelAPI_Document.h>
+// to avoid unresolved ModelAPI_Feature()
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
+// to avoid unresolved ModelAPI_Data()
+#include <ModelAPI_Data.h>
+// to avoid unresolved ModelAPI_Plugin()
+#include <ModelAPI_Plugin.h>
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeDocRef.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Validator.h>
+
+#include <Config_ModuleReader.h>
+
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <dlfcn.h>
+#endif
+
+using namespace std;
+
+#ifdef _DEBUG
+#include <iostream>
+#endif
+
+/// Manager that will be initialized from Model package, one per application
+boost::shared_ptr<ModelAPI_Session> MY_MANAGER;
+
+ModelAPI_Session::ModelAPI_Session()
+{
+}
+
+void ModelAPI_Session::setSession(boost::shared_ptr<ModelAPI_Session> theManager)
+{
+  MY_MANAGER = theManager;
+}
+
+boost::shared_ptr<ModelAPI_Session> ModelAPI_Session::get()
+{
+  if (!MY_MANAGER) {  // import Model library that implements this interface of ModelAPI
+    Config_ModuleReader::loadLibrary("Model");
+  }
+  return MY_MANAGER;
+}
+
+const ModelAPI_EventCreator* MY_API_CREATOR = 0;  ///< instance of the events creator, one pre application
+
+const ModelAPI_EventCreator* ModelAPI_EventCreator::get()
+{
+  if (!MY_API_CREATOR) {  // import Model library that implements this interface of ModelAPI
+    Config_ModuleReader::loadLibrary("Model");
+  }
+  return MY_API_CREATOR;
+}
+
+void ModelAPI_EventCreator::set(const ModelAPI_EventCreator* theCreator)
+{
+  MY_API_CREATOR = theCreator;
+}
diff --git a/src/ModelAPI/ModelAPI_Session.h b/src/ModelAPI/ModelAPI_Session.h
new file mode 100644 (file)
index 0000000..0c6df49
--- /dev/null
@@ -0,0 +1,73 @@
+// File:        ModelAPI_Session.hxx
+// Created:     20 Mar 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef ModelAPI_Session_H_
+#define ModelAPI_Session_H_
+
+#include "ModelAPI.h"
+#include <string>
+#include <boost/shared_ptr.hpp>
+
+class ModelAPI_Feature;
+class ModelAPI_Plugin;
+class ModelAPI_Document;
+class ModelAPI_ValidatorsFactory;
+
+/**\class ModelAPI_Session
+ * \ingroup DataModel
+ * \brief Object that knows (from the initial XML file) which
+ * plugin contains which feature, loads and stores reference to loaded plugins by
+ * the feature functionality request.
+ */
+
+class MODELAPI_EXPORT ModelAPI_Session
+{
+ public:
+  /// Returns the real implementation (the alone instance per application) of the plugin manager
+  static boost::shared_ptr<ModelAPI_Session> get();
+
+  /// Registers the plugin that creates features.
+  /// It is obligatory for each plugin to call this function on loading to be found by 
+  /// the plugin manager on call of the feature)
+  virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0;
+
+  /// Returns the root document of the application (that may contains sub-documents)
+  virtual boost::shared_ptr<ModelAPI_Document> rootDocument() = 0;
+
+  /// Return true if root document has been already created
+  virtual bool hasRootDocument() = 0;
+
+  /// Returns the current document that used for current work in the application
+  virtual boost::shared_ptr<ModelAPI_Document> currentDocument() = 0;
+
+  /// Defines the current document that used for current work in the application
+  virtual void setCurrentDocument(boost::shared_ptr<ModelAPI_Document> theDoc) = 0;
+
+  /// Copies the document to the new one with the given id
+  virtual boost::shared_ptr<ModelAPI_Document> copy(boost::shared_ptr<ModelAPI_Document> theSource,
+                                                    std::string theID) = 0;
+
+  /// Returns the validators factory: the only one instance per application
+  virtual ModelAPI_ValidatorsFactory* validators() = 0;
+
+  /// Is needed for python wrapping by swig, call Get to get an instance
+  ModelAPI_Session();
+
+  /// To virtually destroy the fields of successors
+  virtual ~ModelAPI_Session()
+  {
+  }
+
+ protected:
+  /// Creates the feature object using plugins functionality
+  virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
+
+  static void setSession(boost::shared_ptr<ModelAPI_Session> theManager);
+
+  friend class Model_Document;
+};
+
+typedef boost::shared_ptr<ModelAPI_Session> SessionPtr;
+
+#endif
index a3e378856fe3538a94031d99f364c7c1260e2180..f4ecd19237962db93ece8d287c2bdc49358719c5 100644 (file)
@@ -47,7 +47,7 @@ typedef boost::shared_ptr<ModelAPI_Validator> ValidatorPtr;
  * Allows to get a validator by the feature identifier and 
  * the attribute identifier (if attribute is validated).
  * All accessible validators mustbe registered by the ID string first.
- * The instance of this factory can be get in the PluginManager.
+ * The instance of this factory can be get in the Session.
  * Keeps the validator objects alive and just returns one of it by request.
  * All the needed information is provided to the validator as an argument,
  * this allows to work with them independently from the feature specific object.
@@ -87,7 +87,7 @@ class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
   virtual bool validate(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
 
  protected:
-  /// Get instance from PluginManager
+  /// Get instance from Session
   ModelAPI_ValidatorsFactory()
   {
   }
index e873562e5c4fc930f423a112c082e22aadd9c56f..fec4856da9cae6729063311ad520ba795ca57aa1 100644 (file)
@@ -10,7 +10,7 @@
 #include "ModuleBase_ModelWidget.h"
 
 #include <ModelAPI_Document.h>
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -51,7 +51,7 @@ bool ModuleBase_IOperation::canBeCommitted() const
 
 boost::shared_ptr<ModelAPI_Document> ModuleBase_IOperation::document() const
 {
-  return ModelAPI_PluginManager::get()->rootDocument();
+  return ModelAPI_Session::get()->rootDocument();
 }
 
 void ModuleBase_IOperation::start()
index 50d2478adabb7fcdbd3ce764783338a194870634..30062efc4ff272badda30a9454a1d6c0b940003f 100644 (file)
@@ -98,7 +98,7 @@ bool ModuleBase_Operation::canBeCommitted() const
     /*    FeaturePtr aFeature = feature();
      std::string aId = aFeature->getKind();
 
-     PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+     SessionPtr aMgr = ModelAPI_Session::get();
      ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
      std::list<ModelAPI_Validator*> aValidators;
      aFactory->validators(aId, aValidators);
index e7c510a8385a0cfaea7d3fa94b6e5eb16246289a..6586a491a104783222dc1d23b58a43ffa35636c6 100644 (file)
@@ -71,7 +71,7 @@ bool ModuleBase_WidgetFeature::setValue(ModuleBase_WidgetValue* theValue)
 
 bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject, bool theSendEvent)
 {
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
   std::list<ModelAPI_Validator*> aValidators;
   std::list<std::list<std::string> > anArguments;
index cf2bcbc7c3bcc2c5acaddfebbfd7a7d2d051d236..bb42c3373eb3c905f60c97ad68c66b4d3dd02888 100644 (file)
@@ -109,7 +109,7 @@ XGUI_Workshop* PartSet_Module::workshop() const
 void PartSet_Module::createFeatures()
 {
   //Registering of validators
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
   aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
   aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
index 727a97915e6b791b5c7c6a7a6b6d136d83657f6c..f67a1e06a4d0a71d3d345ea0a30c08f597560e8f 100644 (file)
@@ -132,7 +132,7 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop)
 
   if (aPreviewOp) {
     // create a line
-    boost::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_PluginManager::get()->rootDocument();
+    boost::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_Session::get()->rootDocument();
     FeaturePtr aFeature = aDoc->addFeature(SketchPlugin_Line::ID());
     if (aFeature)  // TODO: generate an error if feature was not created
       aFeature->execute();
index 92c66ffbe9f87ad8cebd72ebd89ae07460a1f367..f301c8e0abdf482bda1b8f1188f77fb6f3359412 100644 (file)
@@ -171,7 +171,7 @@ FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theVie
 
 boost::shared_ptr<ModelAPI_Document> PartSet_Tools::document()
 {
-  return ModelAPI_PluginManager::get()->rootDocument();
+  return ModelAPI_Session::get()->rootDocument();
 }
 
 void PartSet_Tools::setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
index 7f94e6943b48dc7f47c925de3681f0d343c6ec70..f8ebfd9006d1f522e90b164d0bf47c4f1a56488e 100644 (file)
@@ -20,7 +20,7 @@ void PartSetPlugin_Duplicate::initAttributes()
   PartSetPlugin_Part::initAttributes();
   data()->addAttribute(ORIGIN_REF(), ModelAPI_AttributeRefAttr::type());
 
-  boost::shared_ptr<ModelAPI_PluginManager> aPManager = ModelAPI_PluginManager::get();
+  boost::shared_ptr<ModelAPI_Session> aPManager = ModelAPI_Session::get();
   boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
   boost::shared_ptr<ModelAPI_ResultPart> aSource;  // searching for source document attribute
   for (int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
index e01c02bb0814c803cc5421576be65547e9479e15..739f63629c9319a745b31936ccc8743be4ba8b57 100644 (file)
@@ -3,7 +3,7 @@
 // Author:      Mikhail PONIKAROV
 
 #include "PartSetPlugin_Part.h"
-#include "ModelAPI_PluginManager.h"
+#include "ModelAPI_Session.h"
 #include "ModelAPI_Document.h"
 #include "ModelAPI_Data.h"
 #include "ModelAPI_AttributeDocRef.h"
@@ -32,7 +32,7 @@ void PartSetPlugin_Part::execute()
   
   if (!aDocRef->value()) {  // create a document if not yet created
     boost::shared_ptr<ModelAPI_Document> aPartSetDoc =
-        ModelAPI_PluginManager::get()->rootDocument();
+        ModelAPI_Session::get()->rootDocument();
     aDocRef->setValue(aPartSetDoc->subDocument(data()->name()));
   }
   */
@@ -40,5 +40,5 @@ void PartSetPlugin_Part::execute()
 
 boost::shared_ptr<ModelAPI_Document> PartSetPlugin_Part::documentToAdd()
 {
-  return ModelAPI_PluginManager::get()->rootDocument();
+  return ModelAPI_Session::get()->rootDocument();
 }
index 6dfc437041f02573fc5eefe2a4d73f4be8c77b52..7f331fd76f14f0a097889940621b5900fb19163b 100644 (file)
@@ -2,7 +2,7 @@
 #include "PartSetPlugin_Part.h"
 #include "PartSetPlugin_Duplicate.h"
 #include "PartSetPlugin_Remove.h"
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
 
 using namespace std;
@@ -13,7 +13,7 @@ static PartSetPlugin_Plugin* MY_INSTANCE = new PartSetPlugin_Plugin();
 PartSetPlugin_Plugin::PartSetPlugin_Plugin()
 {
   // register this plugin
-  ModelAPI_PluginManager::get()->registerPlugin(this);
+  ModelAPI_Session::get()->registerPlugin(this);
 }
 
 FeaturePtr PartSetPlugin_Plugin::createFeature(string theFeatureID)
index 28ee6b7978b7766dc2597ca6bc093d3917a4e975..d6053e5dc2516c6a5c4560c97a8bc4fdf818615f 100644 (file)
@@ -11,7 +11,7 @@
 
 void PartSetPlugin_Remove::execute()
 {
-  boost::shared_ptr<ModelAPI_PluginManager> aPManager = ModelAPI_PluginManager::get();
+  boost::shared_ptr<ModelAPI_Session> aPManager = ModelAPI_Session::get();
   boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
   boost::shared_ptr<ModelAPI_Document> aCurrent;
   boost::shared_ptr<PartSetPlugin_Part> a;
index 6fcb0c4003277fb5eaeaa6096119847b25ff003a..90f54d5604785d6f5e08e72b605e5d5a007b6fce 100644 (file)
@@ -12,7 +12,7 @@
 #include "SketchPlugin_ConstraintRadius.h"
 #include "SketchPlugin_Validators.h"
 #include "SketchPlugin_ResultValidators.h"
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Validator.h>
 
@@ -25,7 +25,7 @@ static SketchPlugin_Plugin* MY_INSTANCE = new SketchPlugin_Plugin();
 
 SketchPlugin_Plugin::SketchPlugin_Plugin()
 {
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
   aFactory->registerValidator("SketchPlugin_DistanceAttrValidator",
                               new SketchPlugin_DistanceAttrValidator);
@@ -36,7 +36,7 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
   aFactory->registerValidator("SketchPlugin_ResultArcValidator", new SketchPlugin_ResultArcValidator);
 
   // register this plugin
-  ModelAPI_PluginManager::get()->registerPlugin(this);
+  ModelAPI_Session::get()->registerPlugin(this);
 
   // register sketcher properties
   Config_PropManager::registerProp("Sketch planes", "planes_color", "Color", Config_Prop::Color,
index 2d135af004a96510b752f87fe7a533187ea759e4..14f5aaa9bf69b4d5295157ef9ccd868ef4571d9b 100644 (file)
@@ -15,7 +15,7 @@ bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
                                                  const ObjectPtr& theObject) const
 {
   std::string aParamA = theArguments.front();
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
 
   // If the object is not a line then it is accepted
index 4a2cf08eee22be617261246917b57b5b0daf55fc..480fae603d3562e63e9d66be2d8a273983929895 100644 (file)
@@ -56,7 +56,7 @@ SketchSolver_ConstraintManager::~SketchSolver_ConstraintManager()
 
 // ============================================================================
 //  Function: processEvent
-//  Class:    SketchSolver_PluginManager
+//  Class:    SketchSolver_Session
 //  Purpose:  listen the event loop and process the message
 // ============================================================================
 void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessage)
@@ -136,7 +136,7 @@ void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessa
 
 // ============================================================================
 //  Function: changeWorkplane
-//  Class:    SketchSolver_PluginManager
+//  Class:    SketchSolver_Session
 //  Purpose:  update workplane by given parameters of the sketch
 // ============================================================================
 bool SketchSolver_ConstraintManager::changeWorkplane(
@@ -167,7 +167,7 @@ bool SketchSolver_ConstraintManager::changeWorkplane(
 
 // ============================================================================
 //  Function: changeConstraint
-//  Class:    SketchSolver_PluginManager
+//  Class:    SketchSolver_Session
 //  Purpose:  create/update the constraint and place it into appropriate group
 // ============================================================================
 bool SketchSolver_ConstraintManager::changeConstraint(
@@ -235,7 +235,7 @@ bool SketchSolver_ConstraintManager::changeConstraint(
 
 // ============================================================================
 //  Function: updateEntity
-//  Class:    SketchSolver_PluginManager
+//  Class:    SketchSolver_Session
 //  Purpose:  update any element on the sketch, which is used by constraints
 // ============================================================================
 void SketchSolver_ConstraintManager::updateEntity(
@@ -286,7 +286,7 @@ void SketchSolver_ConstraintManager::updateEntity(
 
 // ============================================================================
 //  Function: findGroups
-//  Class:    SketchSolver_PluginManager
+//  Class:    SketchSolver_Session
 //  Purpose:  search groups of entities interacting with given constraint
 // ============================================================================
 void SketchSolver_ConstraintManager::findGroups(
@@ -312,7 +312,7 @@ void SketchSolver_ConstraintManager::findGroups(
 
 // ============================================================================
 //  Function: findWorkplaneForConstraint
-//  Class:    SketchSolver_PluginManager
+//  Class:    SketchSolver_Session
 //  Purpose:  search workplane containing given constraint
 // ============================================================================
 boost::shared_ptr<SketchPlugin_Feature> SketchSolver_ConstraintManager::findWorkplaneForConstraint(
@@ -342,7 +342,7 @@ boost::shared_ptr<SketchPlugin_Feature> SketchSolver_ConstraintManager::findWork
 
 // ============================================================================
 //  Function: resolveConstraints
-//  Class:    SketchSolver_PluginManager
+//  Class:    SketchSolver_Session
 //  Purpose:  change entities according to available constraints
 // ============================================================================
 void SketchSolver_ConstraintManager::resolveConstraints()
index c24669c70ad97414ff895c6f29031f73544156da..34c3341471d515eacffb195aa701b84d52ea4d6b 100644 (file)
@@ -106,7 +106,7 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
   QList<ObjectPtr> aObjects = aSelMgr->selection()->selectedObjects();
   int aSelected = aObjects.size();
   if (aSelected > 0) {
-    PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+    SessionPtr aMgr = ModelAPI_Session::get();
     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
     //Process Feature
     if (aSelected == 1) {
index 17dfe99b9a58375909ba875c4f7162583c0f4657..0fcbd794be563e6dd1c141aab7aeee2b3fc31fa0 100644 (file)
@@ -3,7 +3,7 @@
 #include "XGUI_Workshop.h"
 #include "XGUI_Tools.h"
 
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Data.h>
@@ -45,7 +45,7 @@ XGUI_DocumentDataModel::~XGUI_DocumentDataModel()
 
 void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
 {
-  DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+  DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
 
   // Created object event *******************
   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
@@ -155,7 +155,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
 
 void XGUI_DocumentDataModel::rebuildDataTree()
 {
-  DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+  DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
 
   beginResetModel();
   clearModelIndexes();
@@ -200,7 +200,7 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole)
           case HistoryNode:
           {
             int aOffset = historyOffset();
-            DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+            DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
             ObjectPtr aObj = aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset);
             FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
             if (!aFeature)
@@ -242,7 +242,7 @@ QVariant XGUI_DocumentDataModel::headerData(int theSection, Qt::Orientation theO
 int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const
 {
   if (!theParent.isValid()) {
-    DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+    DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
     // Size of external models
     int aVal = historyOffset();
     // Plus history size
@@ -371,7 +371,7 @@ ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const
   if (theIndex.internalId() == PartsFolder)
     return ObjectPtr();
   if (theIndex.internalId() == HistoryNode) {
-    DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+    DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
     int aOffset = historyOffset();
     return aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset);
   }
@@ -529,7 +529,7 @@ QModelIndex XGUI_DocumentDataModel::partIndex(const ResultPartPtr& theObject) co
 QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const
 {
   // Check that this feature belongs to root document
-  DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+  DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
   DocumentPtr aDoc = theObject->document();
   if (aDoc == aRootDoc) {
     // This feature belongs to histrory or top model
index af509801a0b3cc8a9ffe7c13de1549ba6edff07b..c128f3235d88ab3400f19b6facd8054faae04f77 100644 (file)
@@ -3,7 +3,7 @@
 #include "XGUI_Tools.h"
 
 #include <ModelAPI_Data.h>
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Object.h>
 
@@ -83,7 +83,7 @@ void XGUI_DataTree::commitData(QWidget* theEditor)
   if (aEditor) {
     QString aRes = aEditor->text();
     ObjectPtr aFeature = mySelectedData.first();
-    PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+    SessionPtr aMgr = ModelAPI_Session::get();
     aMgr->rootDocument()->startOperation();
     aFeature->data()->setName(qPrintable(aRes));
     aMgr->rootDocument()->finishOperation();
@@ -119,7 +119,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
 
   aLabelLay->addWidget(aLbl);
 
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   DocumentPtr aDoc = aMgr->rootDocument();
   // TODO: Find a name of the root document
 
@@ -226,7 +226,7 @@ void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave)
   myActiveDocLbl->setReadOnly(true);
   if (toSave) {
     // TODO: Save the name of root document
-    PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+    SessionPtr aMgr = ModelAPI_Session::get();
     DocumentPtr aDoc = aMgr->rootDocument();
   } else {
     myActiveDocLbl->setText(myActiveDocLbl->property("OldText").toString());
index d10689f04bcc13445a3a0c2c99352f94672ba222..aa836f4cf581ee939ea733150ef6030a6a9baa51 100644 (file)
@@ -82,7 +82,7 @@ void XGUI_OperationMgr::validateOperation(ModuleBase_Operation* theOperation)
   QString anOperationId = theOperation->id();
   FeaturePtr aFeature = theOperation->feature();
   //Get validators for the Id
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
 
   bool isValid = aFactory->validate(aFeature);
index 6a5ffdc9630f705ebb68b740bcd1619990824a6d..6f6fc8f041563b24abf474234423e978b32dd567 100644 (file)
@@ -1,7 +1,7 @@
 #include "XGUI_PartDataModel.h"
 #include "XGUI_Workshop.h"
 
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
@@ -42,7 +42,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
         case ParamsFolder:
           return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
         case ParamObject: {
-          DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+          DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
           ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row());
           if (aObject)
             return aObject->data()->name().c_str();
@@ -51,7 +51,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
         case ConstructFolder:
           return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex));
         case ConstructObject: {
-          DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+          DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
           ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(),
                                                theIndex.row());
           if (aObject)
@@ -61,7 +61,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
         case BodiesFolder:
           return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex));
         case BodiesObject: {
-          DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+          DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
           ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultBody::group(), theIndex.row());
           if (aObject)
             return aObject->data()->name().c_str();
@@ -103,7 +103,7 @@ int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const
   if (!theParent.isValid())
     return 3;
 
-  DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+  DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
   if (theParent.internalId() == ParamsFolder)
     return aRootDoc->size(ModelAPI_ResultParameters::group());
 
@@ -175,15 +175,15 @@ ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const
     case BodiesFolder:
       return ObjectPtr();
     case ParamObject: {
-      DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+      DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
       return aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row());
     }
     case ConstructObject: {
-      DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+      DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
       return aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row());
     }
     case BodiesObject: {
-      DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+      DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
       return aRootDoc->object(ModelAPI_ResultBody::group(), theIndex.row());
     }
   }
@@ -210,7 +210,7 @@ QModelIndex XGUI_TopDataModel::objectIndex(const ObjectPtr& theObject) const
 {
   QModelIndex aIndex;
   if (theObject) {
-    DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+    DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
     std::string aGroup = theObject->groupName();
     int aNb = aRootDoc->size(aGroup);
     int aRow = -1;
@@ -251,7 +251,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
       // return a name
       switch (theIndex.internalId()) {
         case MyRoot: {
-          DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+          DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
           ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
           if (aObject)
             return boost::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
@@ -325,7 +325,7 @@ QVariant XGUI_PartDataModel::headerData(int section, Qt::Orientation orientation
 int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const
 {
   if (!parent.isValid()) {
-    DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+    DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
     if (aRootDoc->object(ModelAPI_ResultPart::group(), myId))
       return 1;
     else
@@ -410,7 +410,7 @@ bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const
 
 DocumentPtr XGUI_PartDataModel::partDocument() const
 {
-  DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+  DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
   ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
   ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
   return aPart->partDoc();
@@ -420,7 +420,7 @@ ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const
 {
   switch (theIndex.internalId()) {
     case MyRoot: {
-      DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+      DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
       return aRootDoc->object(ModelAPI_ResultPart::group(), myId);
     }
     case ParamsFolder:
@@ -462,7 +462,7 @@ QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
 
 ResultPartPtr XGUI_PartDataModel::part() const
 {
-  DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+  DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
   ObjectPtr aObj = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
   return boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
 }
index 2d37228bae86492e1b38b9abf6090d41c8075e50..3d3937fc639087a78ac1f6045d4cc21110b21477 100644 (file)
@@ -9,7 +9,7 @@
 #include "XGUI_Selection.h"
 
 #include <ModelAPI_Feature.h>
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 #include <ModelAPI_AttributeDocRef.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Result.h>
index 967f560f2d517e2864990bc7afdd20bdd3d259b6..fa036dbbc3ea64eeabbf36c43bdd11f7774117ae 100644 (file)
@@ -24,7 +24,7 @@
 #include "XGUI_Preferences.h"
 
 #include <ModelAPI_Events.h>
-#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Session.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeDocRef.h>
@@ -530,7 +530,7 @@ void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
 {
   QApplication::restoreOverrideCursor();
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   DocumentPtr aDoc = aMgr->rootDocument();
   aDoc->save(theName.toLatin1().constData(), theFileNames);
   QApplication::restoreOverrideCursor();
@@ -539,7 +539,7 @@ void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>&
 //******************************************************
 void XGUI_Workshop::onExit()
 {
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   DocumentPtr aDoc = aMgr->rootDocument();
   if (aDoc->isModified()) {
     int anAnswer = QMessageBox::question(
@@ -581,7 +581,7 @@ void XGUI_Workshop::onNew()
 void XGUI_Workshop::onOpen()
 {
   //save current file before close if modified
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   DocumentPtr aDoc = aMgr->rootDocument();
   if (aDoc->isModified()) {
     //TODO(sbh): re-launch the app?
@@ -667,7 +667,7 @@ bool XGUI_Workshop::onSaveAs()
 void XGUI_Workshop::onUndo()
 {
   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   DocumentPtr aDoc = aMgr->rootDocument();
   if (aDoc->isOperation())
     operationMgr()->abortOperation();
@@ -679,7 +679,7 @@ void XGUI_Workshop::onUndo()
 void XGUI_Workshop::onRedo()
 {
   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   DocumentPtr aDoc = aMgr->rootDocument();
   if (aDoc->isOperation())
     operationMgr()->abortOperation();
@@ -791,7 +791,7 @@ void XGUI_Workshop::updateCommandStatus()
     foreach (XGUI_Command* aCmd, aMenuBar->features())
       aCommands.append(aCmd);
   }
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   if (aMgr->hasRootDocument()) {
     QAction* aUndoCmd;
     QAction* aRedoCmd;
@@ -936,7 +936,7 @@ void XGUI_Workshop::onFeatureTriggered()
 //******************************************************
 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
 {
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   if (theObj) {
     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
     if (aPart) {
@@ -1014,7 +1014,7 @@ void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
 //**************************************************************
 void XGUI_Workshop::activateLastPart()
 {
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   DocumentPtr aDoc = aMgr->rootDocument();
   std::string aGrpName = ModelAPI_ResultPart::group();
   ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
@@ -1032,7 +1032,7 @@ void XGUI_Workshop::deleteObjects(const QList<ObjectPtr>& theList)
       QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
   // ToDo: definbe deleting method
   if (aRes == QMessageBox::Yes) {
-    PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+    SessionPtr aMgr = ModelAPI_Session::get();
     aMgr->rootDocument()->startOperation();
     foreach (ObjectPtr aObj, theList)
     {
@@ -1082,7 +1082,7 @@ void XGUI_Workshop::showOnlyObjects(const QList<ObjectPtr>& theList)
 //**************************************************************
 void XGUI_Workshop::updateCommandsOnViewSelection()
 {
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
   XGUI_Selection* aSelection = mySelector->selection();
   if (aSelection->getSelected().size() == 0)
@@ -1111,14 +1111,14 @@ void XGUI_Workshop::updateCommandsOnViewSelection()
 //**************************************************************
 void XGUI_Workshop::registerValidators() const
 {
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
 }
 
 //**************************************************************
 void XGUI_Workshop::displayAllResults()
 {
-  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  SessionPtr aMgr = ModelAPI_Session::get();
   DocumentPtr aRootDoc = aMgr->rootDocument();
   displayDocumentResults(aRootDoc);
   for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {