#------ NewGEOM ------
export NEWGEOM_ROOT_DIR=${ROOT_DIR}/install
export PATH=${NEWGEOM_ROOT_DIR}/bin:${NEWGEOM_ROOT_DIR}/plugins:${PATH}
-export PYTHONPATH=${NEWGEOM_ROOT_DIR}/swig:${NEW_GEOM_ROOT_DIR}/plugins:${PYTHONPATH}
+export PYTHONPATH=${NEWGEOM_ROOT_DIR}/swig:${NEWGEOM_ROOT_DIR}/plugins:${PYTHONPATH}
export LD_LIBRARY_PATH=${NEWGEOM_ROOT_DIR}/bin:${NEWGEOM_ROOT_DIR}/swig:${NEWGEOM_ROOT_DIR}/plugins:${LD_LIBRARY_PATH}
export NEW_GEOM_CONFIG_FILE=${NEWGEOM_ROOT_DIR}/plugins
export NewGeomResources=${NEWGEOM_ROOT_DIR}/resources
@SET NEW_GEOM_CONFIG_FILE=%ROOT_DIR%\install\plugins
@SET PATH=%ROOT_DIR%\install\plugins;%ROOT_DIR%\install\bin;%PATH%
-@SET PYTHONPATH=%ROOT_DIR%\install\swig;%PYTHONPATH%
+@SET PYTHONPATH=%ROOT_DIR%\install\swig;%ROOT_DIR%\install\plugins;%PYTHONPATH%
@REM -------------------------
@REM PTHREAD
INCLUDE(Common)
INCLUDE(XMLProcessing)
-INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Events)
+INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Events
+ ${PYTHON_INCLUDE_DIRS})
SET(PROJECT_HEADERS
Config_def.h
SET(PROJECT_LIBRARIES
Events
${LIBXML2_LIBRARIES}
+ ${PYTHON_LIBRARIES}
)
SOURCE_GROUP ("Resource Files" FILES ${XML_RESOURCES})
/*
* Hardcoded xml entities of plugins.xml
*/
+
+const static char* PLUGIN_FILE = "plugins.xml";
const static char* NODE_PLUGIN = "plugin";
const static char* NODE_PLUGINS = "plugins";
const static char* PLUGINS_MODULE = "module";
const static char* PLUGIN_CONFIG = "configuration";
const static char* PLUGIN_LIBRARY = "library";
+const static char* PLUGIN_SCRIPT = "script";
#endif /* CONFIG_KEYWORDS_H_ */
#include <libxml/parser.h>
#include <libxml/tree.h>
+#include <Python.h>
+
//Necessary for cerr
#include <iostream>
#include <dlfcn.h>
#endif
+std::map<std::string, Config_ModuleReader::PluginType> Config_ModuleReader::myPluginTypes;
+
Config_ModuleReader::Config_ModuleReader(const char* theEventGenerated)
- : Config_XMLReader("plugins.xml"),
+ : Config_XMLReader(PLUGIN_FILE),
myEventGenerated(theEventGenerated)
{
}
if (isNode(theNode, NODE_PLUGIN, NULL)) {
std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG);
std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY);
- std::list<std::string> aFeatures = importPlugin(aPluginLibrary, aPluginConf);
+ std::string aPluginScript = getProperty(theNode, PLUGIN_SCRIPT);
+ std::string aPluginName = addPlugin(aPluginLibrary, aPluginScript, aPluginConf);
+
+ std::list<std::string> aFeatures = importPlugin(aPluginName, aPluginConf);
std::list<std::string>::iterator it = aFeatures.begin();
for (; it != aFeatures.end(); it++) {
myFeaturesInFiles[*it] = aPluginConf;
}
std::list<std::string> Config_ModuleReader::importPlugin(const std::string& thePluginLibrary,
- const std::string& thePluginFile)
+ const std::string& thePluginXmlConf)
{
- if (thePluginFile.empty()) { //probably a third party library
+ if (thePluginXmlConf.empty()) { //probably a third party library
loadLibrary(thePluginLibrary);
return std::list<std::string>();
}
- Config_FeatureReader aReader = Config_FeatureReader(thePluginFile, thePluginLibrary,
+ Config_FeatureReader aReader = Config_FeatureReader(thePluginXmlConf,
+ thePluginLibrary,
myEventGenerated);
aReader.readAll();
return aReader.features();
}
+std::string Config_ModuleReader::addPlugin(const std::string& aPluginLibrary,
+ const std::string& aPluginScript,
+ const std::string& aPluginConf)
+{
+ PluginType aType = PluginType::Binary;
+ std::string aPluginName;
+ if (!aPluginLibrary.empty()) {
+ aPluginName = aPluginLibrary;
+ if (aPluginConf.empty()) {
+ aType = PluginType::Intrenal;
+ }
+ } else if (!aPluginScript.empty()) {
+ aPluginName = aPluginScript;
+ aType = PluginType::Python;
+ }
+ if(!aPluginName.empty()) {
+ myPluginTypes[aPluginName] = aType;
+
+ }
+ return aPluginName;
+}
+
+void Config_ModuleReader::loadPlugin(const std::string thePluginName)
+{
+ PluginType aType = PluginType::Binary;
+ if(myPluginTypes.find(thePluginName) != myPluginTypes.end()) {
+ aType = myPluginTypes.at(thePluginName);
+ }
+ switch (aType) {
+ case PluginType::Python:
+ loadScript(thePluginName);
+ break;
+ case PluginType::Binary:
+ case PluginType::Intrenal:
+ default:
+ loadLibrary(thePluginName);
+ break;
+ }
+}
+
+void Config_ModuleReader::loadScript(const std::string theFileName)
+{
+ std::string aPythonFile = theFileName + ".py";
+ PyGILState_STATE gstate;
+
+ /* aquire python thread */
+ gstate = PyGILState_Ensure();
+
+ PyObject* module = PyImport_ImportModule(aPythonFile.c_str());
+
+ /* release python thread */
+ PyGILState_Release(gstate);
+}
+
void Config_ModuleReader::loadLibrary(const std::string theLibName)
{
std::string aFileName = library(theLibName);
#ifdef WIN32
HINSTANCE aModLib = ::LoadLibrary(aFileName.c_str());
- if (!aModLib && theLibName != "DFBrowser") { // don't shor error for internal debugging tool
- std::string errorMsg = "Failed to load " + aFileName;
- std::cerr << errorMsg << std::endl;
- Events_Error::send(errorMsg);
- }
#else
void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY | RTLD_GLOBAL );
- if ( !aModLib && theLibName != "DFBrowser") { // don't shor error for internal debugging tool
- std::cerr << "Failed to load " << aFileName.c_str() << std::endl;
- }
#endif
+ if(!aModLib && theLibName != "DFBrowser") { // don't show error for internal debugging tool
+ std::string anErrorMsg = "Failed to load " + aFileName;
+ #ifndef WIN32
+ anErrorMsg += ": " + std::string(dlerror());
+ #endif
+ Events_Error::send(anErrorMsg);
+ }
}
class Config_ModuleReader : public Config_XMLReader
{
+ enum PluginType {
+ Binary = 0,
+ Intrenal = 1,
+ Python = 2
+ };
public:
- CONFIG_EXPORT Config_ModuleReader(const char* theEventGenerated = 0);CONFIG_EXPORT virtual ~Config_ModuleReader();
+ CONFIG_EXPORT Config_ModuleReader(const char* theEventGenerated = 0);
+ CONFIG_EXPORT virtual ~Config_ModuleReader();
CONFIG_EXPORT const std::map<std::string, std::string>& featuresInFiles() const;
CONFIG_EXPORT std::string getModuleName();
+ CONFIG_EXPORT static void loadPlugin(const std::string thePluginName);
/// loads the library with specific name, appends "lib*.dll" or "*.so" depending on the platform
CONFIG_EXPORT static void loadLibrary(const std::string theLibName);
+ /// loads the python module with specified name
+ CONFIG_EXPORT static void loadScript(const std::string theFileName);
protected:
void processNode(xmlNodePtr aNode);
std::list<std::string> importPlugin(const std::string& thePluginLibrary,
const std::string& thePluginFile);
+ std::string addPlugin(const std::string& aPluginLibrary,
+ const std::string& aPluginScript,
+ const std::string& aPluginConf);
private:
std::map<std::string, std::string> myFeaturesInFiles;
+ static std::map<std::string, PluginType> myPluginTypes;
const char* myEventGenerated;
};
<plugin library="SketchPlugin" configuration="plugin-Sketch.xml"/>
<plugin library="ConstructionPlugin" configuration="plugin-Construction.xml"/>
<plugin library="FeaturesPlugin" configuration="plugin-Features.xml"/>
- <plugin library="PythonFeaturesPlugin" configuration="plugin-PythonFeatures.xml"/>
<plugin library="ExchangePlugin" configuration="plugin-Exchange.xml"/>
+ <plugin script="PythonFeaturesPlugin" configuration="plugin-PythonFeatures.xml"/>
<plugin library="SketchSolver"/>
<plugin library="GeomValidators"/>
- <plugin library="DFBrowser"/>
+ <plugin library="DFBrowser" internal="true"/>
</plugins>
ADD_DEFINITIONS(-DGEOMAPI_EXPORTS ${CAS_DEFINITIONS})
ADD_LIBRARY(GeomAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-SET(CMAKE_SWIG_FLAGS "")
+SET(CMAKE_SWIG_FLAGS "-Wall")
SET_SOURCE_FILES_PROPERTIES(GeomAPI.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(GeomAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow")
ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
ADD_LIBRARY(GeomAlgoAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-SET(CMAKE_SWIG_FLAGS "")
+SET(CMAKE_SWIG_FLAGS "-Wall")
SET_SOURCE_FILES_PROPERTIES(GeomAlgoAPI.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(GeomAlgoAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow")
GeomDataAPI_Point2D.h
)
-SET(CMAKE_SWIG_FLAGS "")
+SET(CMAKE_SWIG_FLAGS "-Wall")
SET_SOURCE_FILES_PROPERTIES(GeomDataAPI.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(GeomDataAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow")
#include <TDF_RelocationTable.hxx>
#include <TDF_ClosureTool.hxx>
-// TEST
-#include <Python.h>
-
using namespace std;
static Model_Session* myImpl = new Model_Session();
myCurrentPluginName = aPlugin.first;
if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) {
// load plugin library if not yet done
- //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);
- }
+ Config_ModuleReader::loadPlugin(myCurrentPluginName);
}
if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
FeaturePtr aCreated = myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
../GeomAlgoAPI
)
-SET(CMAKE_SWIG_FLAGS "")
+SET(CMAKE_SWIG_FLAGS "-Wall")
SET_SOURCE_FILES_PROPERTIES(ModelAPI.i PROPERTIES CPLUSPLUS ON)
# "-includeall" is not needed: it starts to follow the standard inludes (like "string") without success
%include "std_string.i"
%include "std_list.i"
+// directors
+%feature("director") ModelAPI_Plugin;
+// %feature("director") ModelAPI_Object;
+// %feature("director") ModelAPI_Feature;
+// %feature("director") ModelAPI_CompositeFeature;
+
// boost pointers
%include <boost_shared_ptr.i>
// For ModelAPI_ResultConstruction.shape()
%shared_ptr(ModelAPI_ResultConstruction)
%shared_ptr(ModelAPI_ResultBody)
%shared_ptr(ModelAPI_ResultPart)
-%feature("director") ModelAPI_Plugin;
// all supported interfaces
%include "GeomAPI_Interface.h"
%include "ModelAPI_Document.h"
%include "ModelAPI_Session.h"
%include "ModelAPI_Object.h"
+// %nodefaultctor ModelAPI_Plugin;
%include "ModelAPI_Plugin.h"
%include "ModelAPI_Feature.h"
%include "ModelAPI_CompositeFeature.h"
ModelAPI_Plugin()
{
}
- ;
};
#endif
-from ModelAPI import *
-import PythonFeaturesPlugin_Box
+import ModelAPI
+from PythonFeaturesPlugin_Box import PythonFeaturesPlugin_Box
-class PythonFeaturesPlugin(ModelAPI_Plugin):
+class PythonFeaturesPlugin(ModelAPI.ModelAPI_Plugin):
+
def __init__(self):
- ModelAPI_Plugin.__init__(self)
+ ModelAPI.ModelAPI_Plugin.__init__(self)
pass
def createFeature(self, theFeatureID):
raise StandardError("No such feature %s"%theFeatureID)
plugin = PythonFeaturesPlugin()
-ModelAPI_Session_get().registerPlugin(plugin)
-
+aSession = ModelAPI.ModelAPI_Session.get()
+print "Module loaded. Session", aSession
+aSession.registerPlugin(plugin)
def __init__(self):
pass
- def ID(self):
+ @staticmethod
+ def ID():
return "Box"
- def WIDTH_ID(self):
+ @staticmethod
+ def WIDTH_ID():
return "box_width"
- def LENGTH_ID(self):
+ @staticmethod
+ def LENGTH_ID():
return "box_length"
- def HEIGHT_ID(self):
+ @staticmethod
+ def HEIGHT_ID():
return "box_height"
def initAttributes(self):
- self.data().addAttribute(self.WIDTH_ID(), ModelAPI_AttributeDouble.type())
- self.data().addAttribute(self.LENGTH_ID(), ModelAPI_AttributeDouble.type())
- self.data().addAttribute(self.HEIGHT_ID(), ModelAPI_AttributeDouble.type())
+ self.data().addAttribute(PythonFeaturesPlugin_Box.WIDTH_ID(), ModelAPI_AttributeDouble.type())
+ self.data().addAttribute(PythonFeaturesPlugin_Box.LENGTH_ID(), ModelAPI_AttributeDouble.type())
+ self.data().addAttribute(PythonFeaturesPlugin_Box.HEIGHT_ID(), ModelAPI_AttributeDouble.type())
def execute(self):
- aWidth = self.data().attribute(self.WIDTH_ID()).value()
- aLength = self.data().attribute(self.LENGTH_ID()).value()
- aHeight = self.data().attribute(self.HEIGHT_ID()).value()
+ aWidth = self.attribute(PythonFeaturesPlugin_Box.WIDTH_ID()).value()
+ aLength = self.attribute(PythonFeaturesPlugin_Box.LENGTH_ID()).value()
+ aHeight = self.attribute(PythonFeaturesPlugin_Box.HEIGHT_ID()).value()
aResult = document().createBody(data())
#aResult.store(UserPackage.makeBox(aLength, aWidth, aHeight)