Salome HOME
Merge branch 'master' of newgeom:newgeom.git into BR_PYTHON_PLUGIN
[modules/shaper.git] / src / Model / Model_Session.cpp
index 51f97e0f717c628408167d9eb638e4798cd07433..a42eb204696b7283251aae226a13b145bf6cc8e0 100644 (file)
@@ -21,6 +21,9 @@
 #include <TDF_RelocationTable.hxx>
 #include <TDF_ClosureTool.hxx>
 
+// TEST
+#include <Python.h>
+
 using namespace std;
 
 static Model_Session* myImpl = new Model_Session();
@@ -91,22 +94,30 @@ void Model_Session::redo()
 
 FeaturePtr Model_Session::createFeature(string theFeatureID)
 {
-  if (this != myImpl)
+  if (this != myImpl) {
     return myImpl->createFeature(theFeatureID);
+  }
 
   LoadPluginsInfo();
   if (myPlugins.find(theFeatureID) != myPlugins.end()) {
     std::pair<std::string, std::string>& aPlugin = myPlugins[theFeatureID]; // plugin and doc kind
     if (!aPlugin.second.empty() && aPlugin.second != activeDocument()->kind()) {
       Events_Error::send(
-          string("Feature '") + theFeatureID + "' can not be created in document '"
+          string("Feature '") + theFeatureID + "' can be created only in document '"
               + aPlugin.second + "' by the XML definition");
       return FeaturePtr();
     }
     myCurrentPluginName = aPlugin.first;
     if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) {
       // load plugin library if not yet done
-      Config_ModuleReader::loadLibrary(myCurrentPluginName);
+      //TODO: Get info from Config about python libraries
+      if (myCurrentPluginName.compare(string("PythonFeaturesPlugin")) == 0) {
+        Py_Initialize();
+        PyObject* module = PyImport_ImportModule(myCurrentPluginName.c_str());
+        assert(module != NULL);
+      } else {
+        Config_ModuleReader::loadLibrary(myCurrentPluginName);
+      }
     }
     if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
       FeaturePtr aCreated = myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
@@ -191,7 +202,7 @@ boost::shared_ptr<ModelAPI_Document> Model_Session::copy(
   aRT->SetRelocation(aSourceRoot, aTargetRoot);
   TDF_CopyTool::Copy(aDS, aRT);
 
-  aNew->synchronizeFeatures();
+  aNew->synchronizeFeatures(false, true);
   return aNew;
 }
 
@@ -204,9 +215,9 @@ Model_Session::Model_Session()
   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_OBJECT_CREATED), 0, true);
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED), 0, true);
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED), 0, true);
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_VALIDATOR_LOADED));
 }