diff --git a/src/Mod/Robot/App/AppRobot.cpp b/src/Mod/Robot/App/AppRobot.cpp
index 0f961b0f0..999646875 100644
--- a/src/Mod/Robot/App/AppRobot.cpp
+++ b/src/Mod/Robot/App/AppRobot.cpp
@@ -29,9 +29,12 @@
#include
#include
+#include
+#include
#include "Robot6AxisPy.h"
#include "Robot6Axis.h"
+#include "Simulation.h"
#include "TrajectoryPy.h"
#include "Trajectory.h"
#include "PropertyTrajectory.h"
@@ -43,15 +46,50 @@
#include "TrajectoryCompound.h"
#include "TrajectoryDressUpObject.h"
-extern struct PyMethodDef Robot_methods[];
+namespace Robot {
+class Module : public Py::ExtensionModule
+{
+public:
+ Module() : Py::ExtensionModule("Robot")
+ {
+ add_varargs_method("simulateToFile",&Module::simulateToFile,
+ "simulateToFile(Robot,Trajectory,TickSize,FileName) - runs the simulation and write the result to a file."
+ );
+ initialize("This module is the Robot module."); // register with Python
+ }
-PyDoc_STRVAR(module_Robot_doc,
-"This module is the Robot module.");
+ virtual ~Module() {}
+
+private:
+ Py::Object simulateToFile(const Py::Tuple& args)
+ {
+ PyObject *pcRobObj;
+ PyObject *pcTracObj;
+ float tick;
+ char* FileName;
+
+ if (!PyArg_ParseTuple(args.ptr(), "O!O!fs", &(Robot6AxisPy::Type), &pcRobObj,
+ &(TrajectoryPy::Type), &pcTracObj,
+ &tick,&FileName))
+ throw Py::Exception();
+
+ try {
+ Robot::Trajectory &Trac = * static_cast(pcTracObj)->getTrajectoryPtr();
+ Robot::Robot6Axis &Rob = * static_cast(pcRobObj)->getRobot6AxisPtr();
+ Simulation Sim(Trac,Rob);
+ }
+ catch (const Base::Exception& e) {
+ throw Py::RuntimeError(e.what());
+ }
+
+ return Py::Float(0.0);
+ }
+};
+} // namespace Robot
/* Python entry */
-extern "C" {
-void RobotExport initRobot()
+PyMODINIT_FUNC initRobot()
{
// load dependent module
try {
@@ -62,10 +100,9 @@ void RobotExport initRobot()
return;
}
- PyObject* robotModule = Py_InitModule3("Robot", Robot_methods, module_Robot_doc); /* mod name, table ptr */
+ PyObject* robotModule = (new Robot::Module())->module().ptr();
Base::Console().Log("Loading Robot module... done\n");
-
// Add Types to module
Base::Interpreter().addType(&Robot::Robot6AxisPy ::Type,robotModule,"Robot6Axis");
Base::Interpreter().addType(&Robot::WaypointPy ::Type,robotModule,"Waypoint");
@@ -75,7 +112,7 @@ void RobotExport initRobot()
// NOTE: To finish the initialization of our own type objects we must
// call PyType_Ready, otherwise we run into a segmentation fault, later on.
// This function is responsible for adding inherited slots from a type's base class.
-
+
Robot::Robot6Axis ::init();
Robot::RobotObject ::init();
Robot::TrajectoryObject ::init();
@@ -86,5 +123,3 @@ void RobotExport initRobot()
Robot::TrajectoryCompound ::init();
Robot::TrajectoryDressUpObject ::init();
}
-
-} // extern "C"
diff --git a/src/Mod/Robot/App/AppRobotPy.cpp b/src/Mod/Robot/App/AppRobotPy.cpp
deleted file mode 100644
index 6bd8513e4..000000000
--- a/src/Mod/Robot/App/AppRobotPy.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de) *
- * *
- * This file is part of the FreeCAD CAx development system. *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Library General Public *
- * License as published by the Free Software Foundation; either *
- * version 2 of the License, or (at your option) any later version. *
- * *
- * This library is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU Library General Public License for more details. *
- * *
- * You should have received a copy of the GNU Library General Public *
- * License along with this library; see the file COPYING.LIB. If not, *
- * write to the Free Software Foundation, Inc., 59 Temple Place, *
- * Suite 330, Boston, MA 02111-1307, USA *
- * *
- ***************************************************************************/
-
-
-#include "PreCompiled.h"
-#ifndef _PreComp_
-# include
-#endif
-
-#include
-#include
-
-#include "TrajectoryPy.h"
-#include "Robot6AxisPy.h"
-#include "Simulation.h"
-
-#include "RobotAlgos.h"
-
-using namespace Robot;
-
-static PyObject *
-simulateToFile(PyObject *self, PyObject *args)
-{
- PyObject *pcRobObj;
- PyObject *pcTracObj;
- float tick;
- char* FileName;
-
- if (!PyArg_ParseTuple(args, "O!O!fs", &(Robot6AxisPy::Type), &pcRobObj,
- &(TrajectoryPy::Type), &pcTracObj,
- &tick,&FileName
- ) )
- return NULL; // NULL triggers exception
-
- PY_TRY {
- Robot::Trajectory &Trac = * static_cast(pcTracObj)->getTrajectoryPtr();
- Robot::Robot6Axis &Rob = * static_cast(pcRobObj)->getRobot6AxisPtr();
- Simulation Sim(Trac,Rob);
-
-
-
- } PY_CATCH;
-
- return Py::new_reference_to(Py::Float(0.0));
-
-}
-
-
-/* registration table */
-struct PyMethodDef Robot_methods[] = {
- {"simulateToFile" ,simulateToFile ,METH_VARARGS,
- "void simulateToFile(Robot,Trajectory,TickSize,FileName) - runs the simulation and write the result to a file."},
- {NULL, NULL} /* end of table marker */
-};
diff --git a/src/Mod/Robot/App/CMakeLists.txt b/src/Mod/Robot/App/CMakeLists.txt
index 837482984..ceea3063b 100644
--- a/src/Mod/Robot/App/CMakeLists.txt
+++ b/src/Mod/Robot/App/CMakeLists.txt
@@ -45,7 +45,6 @@ SET(Python_SRCS
SET(Mod_SRCS
AppRobot.cpp
- AppRobotPy.cpp
PreCompiled.cpp
PreCompiled.h
)
diff --git a/src/Mod/Robot/Gui/AppRobotGui.cpp b/src/Mod/Robot/Gui/AppRobotGui.cpp
index 0b9c20c40..9e5e9066c 100644
--- a/src/Mod/Robot/Gui/AppRobotGui.cpp
+++ b/src/Mod/Robot/Gui/AppRobotGui.cpp
@@ -26,6 +26,9 @@
# include
#endif
+#include
+#include
+
#include
#include
#include
@@ -50,15 +53,26 @@ void loadRobotResource()
Gui::Translator::instance()->refresh();
}
-/* registration table */
-extern struct PyMethodDef RobotGui_Import_methods[];
+namespace RobotGui {
+class Module : public Py::ExtensionModule
+{
+public:
+ Module() : Py::ExtensionModule("RobotGui")
+ {
+ initialize("This module is the RobotGui module."); // register with Python
+ }
+
+ virtual ~Module() {}
+
+private:
+};
+} // namespace RobotGui
/* Python entry */
-extern "C" {
-void RobotGuiExport initRobotGui()
+PyMODINIT_FUNC initRobotGui()
{
- if (!Gui::Application::Instance) {
+ if (!Gui::Application::Instance) {
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
return;
}
@@ -82,7 +96,7 @@ void RobotGuiExport initRobotGui()
PyErr_SetString(PyExc_ImportError, e.what());
return;
}
- (void) Py_InitModule("RobotGui", RobotGui_Import_methods); /* mod name, table ptr */
+ (void)new RobotGui::Module();
Base::Console().Log("Loading GUI of Robot module... done\n");
// instantiating the commands
@@ -93,14 +107,12 @@ void RobotGuiExport initRobotGui()
// addition objects
RobotGui::Workbench ::init();
- RobotGui::ViewProviderRobotObject ::init();
- RobotGui::ViewProviderTrajectory ::init();
- RobotGui::ViewProviderEdge2TracObject ::init();
- RobotGui::ViewProviderTrajectoryCompound ::init();
- RobotGui::ViewProviderTrajectoryDressUp ::init();
+ RobotGui::ViewProviderRobotObject ::init();
+ RobotGui::ViewProviderTrajectory ::init();
+ RobotGui::ViewProviderEdge2TracObject ::init();
+ RobotGui::ViewProviderTrajectoryCompound ::init();
+ RobotGui::ViewProviderTrajectoryDressUp ::init();
// add resources and reloads the translators
loadRobotResource();
}
-
-} // extern "C" {
diff --git a/src/Mod/Robot/Gui/AppRobotGuiPy.cpp b/src/Mod/Robot/Gui/AppRobotGuiPy.cpp
deleted file mode 100644
index c006ecd41..000000000
--- a/src/Mod/Robot/Gui/AppRobotGuiPy.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2008 Werner Mayer *
- * *
- * This file is part of the FreeCAD CAx development system. *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Library General Public *
- * License as published by the Free Software Foundation; either *
- * version 2 of the License, or (at your option) any later version. *
- * *
- * This library is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU Library General Public License for more details. *
- * *
- * You should have received a copy of the GNU Library General Public *
- * License along with this library; see the file COPYING.LIB. If not, *
- * write to the Free Software Foundation, Inc., 59 Temple Place, *
- * Suite 330, Boston, MA 02111-1307, USA *
- * *
- ***************************************************************************/
-
-
-#include "PreCompiled.h"
-#ifndef _PreComp_
-# include
-#endif
-
-
-/* registration table */
-struct PyMethodDef RobotGui_Import_methods[] = {
- {NULL, NULL} /* end of table marker */
-};
diff --git a/src/Mod/Robot/Gui/CMakeLists.txt b/src/Mod/Robot/Gui/CMakeLists.txt
index 6c17aa893..611c0d546 100644
--- a/src/Mod/Robot/Gui/CMakeLists.txt
+++ b/src/Mod/Robot/Gui/CMakeLists.txt
@@ -62,7 +62,6 @@ SOURCE_GROUP("Qt" FILES ${PartDesignGui_MOC_SRCS})
SET(RobotGui_SRCS_Module
AppRobotGui.cpp
- AppRobotGuiPy.cpp
Resources/Robot.qrc
PreCompiled.cpp
PreCompiled.h
@@ -94,7 +93,7 @@ SET(RobotGui_SRCS_ViewProvider
SOURCE_GROUP("ViewProvider" FILES ${RobotGui_SRCS_ViewProvider})
SET(RobotGui_SRCS_TaskBoxes
- TaskRobot6Axis.ui
+ TaskRobot6Axis.ui
TaskRobot6Axis.cpp
TaskRobot6Axis.h
TaskTrajectory.ui
@@ -125,21 +124,21 @@ SET(RobotGui_SRCS_TaskDlg
TaskDlgSimulate.cpp
TaskDlgEdge2Trac.h
TaskDlgEdge2Trac.cpp
- TaskDlgTrajectoryCompound.h
- TaskDlgTrajectoryCompound.cpp
- TaskDlgTrajectoryDressUp.h
- TaskDlgTrajectoryDressUp.cpp
+ TaskDlgTrajectoryCompound.h
+ TaskDlgTrajectoryCompound.cpp
+ TaskDlgTrajectoryDressUp.h
+ TaskDlgTrajectoryDressUp.cpp
)
SOURCE_GROUP("Task_Dialogs" FILES ${RobotGui_SRCS_TaskDlg})
SET(RobotGui_SRCS
${RobotGui_UIC_HDRS}
${RobotResource_SRCS}
- ${RobotGui_SRCS_Module}
- ${RobotGui_SRCS_ViewProvider}
- ${RobotGui_SRCS_Commands}
- ${RobotGui_SRCS_TaskBoxes}
- ${RobotGui_SRCS_TaskDlg}
+ ${RobotGui_SRCS_Module}
+ ${RobotGui_SRCS_ViewProvider}
+ ${RobotGui_SRCS_Commands}
+ ${RobotGui_SRCS_TaskBoxes}
+ ${RobotGui_SRCS_TaskDlg}
)