From: Sergey BELASH Date: Mon, 17 Nov 2014 14:43:13 +0000 (+0300) Subject: Merge branch 'master' into BR_PYTHON_PLUGIN X-Git-Tag: V_0.7.0_rc1~57^2~3^2~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=acebef0bc5fb22dc9672e0046085b896e957af56;hp=e0982cb7a97874070e00a25c7c4c0faf1716afc2;p=modules%2Fshaper.git Merge branch 'master' into BR_PYTHON_PLUGIN --- diff --git a/CMakeLists.txt b/CMakeLists.txt index ac61b73e9..116d25f5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ ADD_SUBDIRECTORY (src/GeomDataAPI) ADD_SUBDIRECTORY (src/PartSetPlugin) ADD_SUBDIRECTORY (src/ConstructionPlugin) ADD_SUBDIRECTORY (src/FeaturesPlugin) +ADD_SUBDIRECTORY (src/PythonFeaturesPlugin) ADD_SUBDIRECTORY (src/SketchPlugin) ADD_SUBDIRECTORY (src/SketchSolver) ADD_SUBDIRECTORY (src/ModuleBase) diff --git a/linux_env.sh b/linux_env.sh index fcbe77b86..b58d16324 100644 --- a/linux_env.sh +++ b/linux_env.sh @@ -37,7 +37,8 @@ export PATH=${CASROOT}:${PATH} #------ 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:${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 + diff --git a/msvc10_env.bat b/msvc10_env.bat index fd95eec28..f4964d462 100644 --- a/msvc10_env.bat +++ b/msvc10_env.bat @@ -127,7 +127,7 @@ set PATH=%CMAKEDIR%\bin;%PATH% @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 diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt index ab42ba193..ecf41b60b 100644 --- a/src/Config/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -1,7 +1,8 @@ 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 @@ -42,6 +43,7 @@ SET(XML_RESOURCES SET(PROJECT_LIBRARIES Events ${LIBXML2_LIBRARIES} + ${PYTHON_LIBRARIES} ) SOURCE_GROUP ("Resource Files" FILES ${XML_RESOURCES}) diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index d7ed62fab..62c5f59af 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -77,11 +77,14 @@ const static char* CONTAINER_PAGE_NAME = "title"; /* * 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_ */ diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index f2fcda4b7..83b16f27d 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -14,6 +14,9 @@ #include #include +// Have to be included before std headers +#include + //Necessary for cerr #include @@ -23,8 +26,10 @@ #include #endif +std::map Config_ModuleReader::myPluginTypes; + Config_ModuleReader::Config_ModuleReader(const char* theEventGenerated) - : Config_XMLReader("plugins.xml"), + : Config_XMLReader(PLUGIN_FILE), myEventGenerated(theEventGenerated) { } @@ -56,7 +61,10 @@ void Config_ModuleReader::processNode(xmlNodePtr theNode) if (isNode(theNode, NODE_PLUGIN, NULL)) { std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG); std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY); - std::list aFeatures = importPlugin(aPluginLibrary, aPluginConf); + std::string aPluginScript = getProperty(theNode, PLUGIN_SCRIPT); + std::string aPluginName = addPlugin(aPluginLibrary, aPluginScript, aPluginConf); + + std::list aFeatures = importPlugin(aPluginName, aPluginConf); std::list::iterator it = aFeatures.begin(); for (; it != aFeatures.end(); it++) { myFeaturesInFiles[*it] = aPluginConf; @@ -70,19 +78,70 @@ bool Config_ModuleReader::processChildren(xmlNodePtr theNode) } std::list 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(); } - 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"; + /* aquire python thread */ + PyGILState_STATE 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); @@ -91,16 +150,15 @@ void Config_ModuleReader::loadLibrary(const std::string 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); + } } diff --git a/src/Config/Config_ModuleReader.h b/src/Config/Config_ModuleReader.h index 18962f348..137afbeae 100644 --- a/src/Config/Config_ModuleReader.h +++ b/src/Config/Config_ModuleReader.h @@ -17,16 +17,25 @@ 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& 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); @@ -34,9 +43,13 @@ class Config_ModuleReader : public Config_XMLReader std::list 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 myFeaturesInFiles; + static std::map myPluginTypes; const char* myEventGenerated; }; diff --git a/src/Config/plugins.xml b/src/Config/plugins.xml index 396f565a9..474b0ba07 100644 --- a/src/Config/plugins.xml +++ b/src/Config/plugins.xml @@ -4,7 +4,8 @@ + - + diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.h b/src/ConstructionPlugin/ConstructionPlugin_Plugin.h index 143b786e5..79f48abe5 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.h @@ -16,7 +16,6 @@ class CONSTRUCTIONPLUGIN_EXPORT ConstructionPlugin_Plugin : public ModelAPI_Plug virtual FeaturePtr createFeature(std::string theFeatureID); public: - /// Is needed for python wrapping by swig ConstructionPlugin_Plugin(); }; diff --git a/src/ExchangePlugin/ExchangePlugin_Plugin.h b/src/ExchangePlugin/ExchangePlugin_Plugin.h index 5cb5f20f0..d614028f1 100644 --- a/src/ExchangePlugin/ExchangePlugin_Plugin.h +++ b/src/ExchangePlugin/ExchangePlugin_Plugin.h @@ -16,7 +16,6 @@ class EXCHANGEPLUGIN_EXPORT ExchangePlugin_Plugin : public ModelAPI_Plugin virtual FeaturePtr createFeature(std::string theFeatureID); public: - /// Is needed for python wrapping by swig ExchangePlugin_Plugin(); }; diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.h b/src/FeaturesPlugin/FeaturesPlugin_Plugin.h index 560a2242a..e56ac83ea 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.h @@ -16,7 +16,6 @@ class FEATURESPLUGIN_EXPORT FeaturesPlugin_Plugin : public ModelAPI_Plugin virtual FeaturePtr createFeature(std::string theFeatureID); public: - /// Is needed for python wrapping by swig FeaturesPlugin_Plugin(); }; diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index 2718fa980..9ee8694c8 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -58,7 +58,7 @@ SET(PROJECT_LIBRARIES ADD_DEFINITIONS(-DGEOMAPI_EXPORTS ${CAS_DEFINITIONS}) ADD_LIBRARY(GeomAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) -SET(CMAKE_SWIG_FLAGS "") +SET(CMAKE_SWIG_FLAGS -threads -Wall) SET_SOURCE_FILES_PROPERTIES(GeomAPI.i PROPERTIES CPLUSPLUS ON) SET_SOURCE_FILES_PROPERTIES(GeomAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow") diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index 5656a0ad8..ef36a838e 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -41,7 +41,7 @@ SET(PROJECT_LIBRARIES 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") diff --git a/src/GeomDataAPI/CMakeLists.txt b/src/GeomDataAPI/CMakeLists.txt index d956835d1..b9e1488b7 100644 --- a/src/GeomDataAPI/CMakeLists.txt +++ b/src/GeomDataAPI/CMakeLists.txt @@ -10,7 +10,7 @@ SET(PROJECT_HEADERS 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") diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 23e7a2621..16a4d07f0 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -92,8 +92,9 @@ void Model_Session::redo() FeaturePtr Model_Session::createFeature(string theFeatureID) { - if (this != myImpl) + if (this != myImpl) { return myImpl->createFeature(theFeatureID); + } if (myPlugins.find(theFeatureID) != myPlugins.end()) { std::pair& aPlugin = myPlugins[theFeatureID]; // plugin and doc kind @@ -106,7 +107,7 @@ FeaturePtr Model_Session::createFeature(string theFeatureID) myCurrentPluginName = aPlugin.first; if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) { // load plugin library if not yet done - Config_ModuleReader::loadLibrary(myCurrentPluginName); + Config_ModuleReader::loadPlugin(myCurrentPluginName); } if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) { FeaturePtr aCreated = myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID); diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index bbc99cbb1..5df84da6a 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -47,8 +47,9 @@ SET(PROJECT_SOURCES SET(PROJECT_LIBRARIES Config ) +SET(CMAKE_SWIG_FLAGS -threads -Wall) +ADD_DEFINITIONS(-DMODELAPI_EXPORTS -DSWIG_TYPE_TABLE=ModelAPI) -ADD_DEFINITIONS(-DMODELAPI_EXPORTS) ADD_LIBRARY(ModelAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) SET_TARGET_PROPERTIES(ModelAPI PROPERTIES LINKER_LANGUAGE CXX) TARGET_LINK_LIBRARIES(ModelAPI ${PROJECT_LIBRARIES}) @@ -60,7 +61,6 @@ INCLUDE_DIRECTORIES( ../GeomAlgoAPI ) -SET(CMAKE_SWIG_FLAGS "") SET_SOURCE_FILES_PROPERTIES(ModelAPI.i PROPERTIES CPLUSPLUS ON) # "-includeall" is not needed: it starts to follow the standard inludes (like "string") without success diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index ba16e8f1c..cc31faa0f 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -1,5 +1,13 @@ /* ModelAPI.i */ -%module ModelAPI +%module(directors="1") ModelAPI +%feature("director:except") { + if ($error != NULL) { + PyErr_Print(); + std::cerr << std::endl; + throw Swig::DirectorMethodException(); + } +} + %{ #include "GeomAPI_Interface.h" #include "GeomAPI_Shape.h" @@ -8,6 +16,7 @@ #include "ModelAPI_Session.h" #include "ModelAPI_Object.h" #include "ModelAPI_Feature.h" + #include "ModelAPI_Plugin.h" #include "ModelAPI_CompositeFeature.h" #include "ModelAPI_Data.h" #include "ModelAPI_Attribute.h" @@ -44,13 +53,19 @@ %include "std_string.i" %include "std_list.i" +// directors +%feature("director") ModelAPI_Plugin; +%feature("director") ModelAPI_Object; +%feature("director") ModelAPI_Feature; + // boost pointers -%include +%include "boost_shared_ptr.i" // For ModelAPI_ResultConstruction.shape() %shared_ptr(GeomAPI_Interface) %shared_ptr(GeomAPI_Shape) %shared_ptr(ModelAPI_Document) %shared_ptr(ModelAPI_Session) +%shared_ptr(ModelAPI_Plugin) %shared_ptr(ModelAPI_Object) %shared_ptr(ModelAPI_Feature) %shared_ptr(ModelAPI_CompositeFeature) @@ -76,6 +91,7 @@ %include "GeomAPI_Shape.h" %include "ModelAPI_Document.h" %include "ModelAPI_Session.h" +%include "ModelAPI_Plugin.h" %include "ModelAPI_Object.h" %include "ModelAPI_Feature.h" %include "ModelAPI_CompositeFeature.h" @@ -101,9 +117,24 @@ %template(ResultList) std::list >; template boost::shared_ptr boost_cast(boost::shared_ptr theObject); + +// Feature casts +%template(modelAPI_Feature) boost_cast; %template(modelAPI_CompositeFeature) boost_cast; -%template(modelAPI_ResultConstruction) boost_cast; -%template(modelAPI_ResultBody) boost_cast; -%template(modelAPI_ResultPart) boost_cast; +// Result casts +%template(modelAPI_ResultConstruction) boost_cast; +%template(modelAPI_ResultBody) boost_cast; +%template(modelAPI_ResultPart) boost_cast; +// Attribute casts +%template(modelAPI_AttributeDocRef) boost_cast; +%template(modelAPI_AttributeDouble) boost_cast; +%template(modelAPI_AttributeInteger) boost_cast; +%template(modelAPI_AttributeString) boost_cast; +%template(modelAPI_AttributeReference) boost_cast; +%template(modelAPI_AttributeRefAttr) boost_cast; +%template(modelAPI_AttributeBoolean) boost_cast; +%template(modelAPI_AttributeSelection) boost_cast; +%template(modelAPI_AttributeSelectionList) boost_cast; +%template(modelAPI_AttributeRefList) boost_cast; diff --git a/src/ModelAPI/ModelAPI_Plugin.h b/src/ModelAPI/ModelAPI_Plugin.h index 5222b4c7b..04a997436 100644 --- a/src/ModelAPI/ModelAPI_Plugin.h +++ b/src/ModelAPI/ModelAPI_Plugin.h @@ -26,13 +26,6 @@ class MODELAPI_EXPORT ModelAPI_Plugin virtual ~ModelAPI_Plugin() { } - - protected: - /// Is needed for python wrapping by swig - ModelAPI_Plugin() - { - } - ; }; #endif diff --git a/src/ModelAPI/ModelAPI_Session.cpp b/src/ModelAPI/ModelAPI_Session.cpp index db8a54ca2..ccb0c8f52 100644 --- a/src/ModelAPI/ModelAPI_Session.cpp +++ b/src/ModelAPI/ModelAPI_Session.cpp @@ -44,10 +44,6 @@ using namespace std; /// Manager that will be initialized from Model package, one per application boost::shared_ptr MY_MANAGER; -ModelAPI_Session::ModelAPI_Session() -{ -} - void ModelAPI_Session::setSession(boost::shared_ptr theManager) { MY_MANAGER = theManager; diff --git a/src/ModelAPI/ModelAPI_Session.h b/src/ModelAPI/ModelAPI_Session.h index c97105421..6160e8e23 100644 --- a/src/ModelAPI/ModelAPI_Session.h +++ b/src/ModelAPI/ModelAPI_Session.h @@ -88,9 +88,6 @@ class MODELAPI_EXPORT ModelAPI_Session /// 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() { diff --git a/src/PartSetPlugin/PartSetPlugin_Plugin.h b/src/PartSetPlugin/PartSetPlugin_Plugin.h index e8e9e702b..5d91f7d46 100644 --- a/src/PartSetPlugin/PartSetPlugin_Plugin.h +++ b/src/PartSetPlugin/PartSetPlugin_Plugin.h @@ -16,7 +16,6 @@ class PARTSETPLUGIN_EXPORT PartSetPlugin_Plugin : public ModelAPI_Plugin virtual FeaturePtr createFeature(std::string theFeatureID); public: - /// Is needed for python wrapping by swig PartSetPlugin_Plugin(); }; diff --git a/src/PythonFeaturesPlugin/CMakeLists.txt b/src/PythonFeaturesPlugin/CMakeLists.txt new file mode 100644 index 000000000..bbfe436ea --- /dev/null +++ b/src/PythonFeaturesPlugin/CMakeLists.txt @@ -0,0 +1,13 @@ +INCLUDE(Common) + +SET(PYTHON_FILES + PythonFeaturesPlugin_Box.py + PythonFeaturesPlugin.py +) + +SET(XML_RESSOURCES + plugin-PythonFeatures.xml + box_widget.xml +) + +INSTALL(FILES ${PYTHON_FILES} ${XML_RESSOURCES} DESTINATION plugins) diff --git a/src/PythonFeaturesPlugin/PythonFeaturesPlugin.py b/src/PythonFeaturesPlugin/PythonFeaturesPlugin.py new file mode 100644 index 000000000..4795eaf03 --- /dev/null +++ b/src/PythonFeaturesPlugin/PythonFeaturesPlugin.py @@ -0,0 +1,19 @@ +import ModelAPI +from PythonFeaturesPlugin_Box import PythonFeaturesPlugin_Box + +class PythonFeaturesPlugin(ModelAPI.ModelAPI_Plugin): + + def __init__(self): + ModelAPI.ModelAPI_Plugin.__init__(self) + pass + + def createFeature(self, theFeatureID): + if theFeatureID == PythonFeaturesPlugin_Box.ID(): + return PythonFeaturesPlugin_Box().__disown__() + else: + raise StandardError("No such feature %s"%theFeatureID) + +plugin = PythonFeaturesPlugin() +aSession = ModelAPI.ModelAPI_Session.get() +print "Module loaded. Session", aSession +aSession.registerPlugin(plugin) diff --git a/src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py b/src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py new file mode 100644 index 000000000..b08f98b41 --- /dev/null +++ b/src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py @@ -0,0 +1,46 @@ +import ModelAPI + +class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature): + "Feature to create a box by drawing a sketch and extruding it" + def __init__(self): + ModelAPI.ModelAPI_Feature.__init__(self) + + @staticmethod + def ID(): + return "Box" + + @staticmethod + def WIDTH_ID(): + return "box_width" + + @staticmethod + def LENGTH_ID(): + return "box_length" + + @staticmethod + def HEIGHT_ID(): + return "box_height" + + def getKind(self): + return PythonFeaturesPlugin_Box.ID() + + def initAttributes(self): + # C++ static methods (in example Type() of ModelAPI_AttributeDouble + # should be called like this: moduleName.ClassName_StaticMethod() + self.data().addAttribute(PythonFeaturesPlugin_Box.WIDTH_ID(), ModelAPI.ModelAPI_AttributeDouble_type()) + self.data().addAttribute(PythonFeaturesPlugin_Box.LENGTH_ID(), ModelAPI.ModelAPI_AttributeDouble_type()) + self.data().addAttribute(PythonFeaturesPlugin_Box.HEIGHT_ID(), ModelAPI.ModelAPI_AttributeDouble_type()) + + def execute(self): + aWidth = self.real(PythonFeaturesPlugin_Box.WIDTH_ID()).value() + aLength = self.real(PythonFeaturesPlugin_Box.LENGTH_ID()).value() + aHeight = self.real(PythonFeaturesPlugin_Box.HEIGHT_ID()).value() + print ("Box W:{0} L:{1} H:{2}".format(aWidth, aLength, aHeight)) + # aResult = document().createBody(data()) + # aResult.store(UserPackage.makeBox(aLength, aWidth, aHeight) + # self.setResult(aResult) + + + + + diff --git a/src/PythonFeaturesPlugin/box_widget.xml b/src/PythonFeaturesPlugin/box_widget.xml new file mode 100644 index 000000000..f35231580 --- /dev/null +++ b/src/PythonFeaturesPlugin/box_widget.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/PythonFeaturesPlugin/plugin-PythonFeatures.xml b/src/PythonFeaturesPlugin/plugin-PythonFeatures.xml new file mode 100644 index 000000000..679cd22aa --- /dev/null +++ b/src/PythonFeaturesPlugin/plugin-PythonFeatures.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/SketchPlugin/SketchPlugin_Plugin.h b/src/SketchPlugin/SketchPlugin_Plugin.h index bb81ba781..3b480410b 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.h +++ b/src/SketchPlugin/SketchPlugin_Plugin.h @@ -16,7 +16,6 @@ class SKETCHPLUGIN_EXPORT SketchPlugin_Plugin : public ModelAPI_Plugin virtual FeaturePtr createFeature(std::string theFeatureID); public: - /// Is needed for python wrapping by swig SketchPlugin_Plugin(); };