py3: ported Measure and TechDraw
This commit is contained in:
parent
f2dc8c5d31
commit
e13d4a7882
|
@ -26,24 +26,36 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Base/Console.h>
|
#include <Base/Console.h>
|
||||||
|
#include <Base/PyObjectBase.h>
|
||||||
#include <Base/Interpreter.h>
|
#include <Base/Interpreter.h>
|
||||||
|
|
||||||
#include "Measurement.h"
|
#include "Measurement.h"
|
||||||
#include "MeasurementPy.h"
|
#include "MeasurementPy.h"
|
||||||
|
|
||||||
struct PyMethodDef Measure_methods[] = {
|
namespace Measure {
|
||||||
// {"read" , read, 1},
|
class Module : public Py::ExtensionModule<Module>
|
||||||
{NULL, NULL, 0, NULL} /* end of table marker */
|
{
|
||||||
|
public:
|
||||||
|
Module() : Py::ExtensionModule<Module>("Measure")
|
||||||
|
{
|
||||||
|
initialize("This module is the Measure module."); // register with Python
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~Module() {}
|
||||||
|
|
||||||
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PyObject* initModule()
|
||||||
|
{
|
||||||
|
return (new Module)->module().ptr();
|
||||||
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(module_Measure_doc,
|
} // namespace Measure
|
||||||
"This module is the Measure module.");
|
|
||||||
|
|
||||||
|
|
||||||
/* Python entry */
|
/* Python entry */
|
||||||
extern "C" {
|
PyMOD_INIT_FUNC(Measure)
|
||||||
void MeasureExport initMeasure()
|
|
||||||
{
|
{
|
||||||
// load dependent module
|
// load dependent module
|
||||||
try {
|
try {
|
||||||
|
@ -51,24 +63,18 @@ void MeasureExport initMeasure()
|
||||||
}
|
}
|
||||||
catch(const Base::Exception& e) {
|
catch(const Base::Exception& e) {
|
||||||
PyErr_SetString(PyExc_ImportError, e.what());
|
PyErr_SetString(PyExc_ImportError, e.what());
|
||||||
return;
|
PyMOD_Return(0);
|
||||||
}
|
}
|
||||||
PyObject* measureModule = Py_InitModule3("Measure", Measure_methods, module_Measure_doc); /* mod name, table ptr */
|
PyObject* mod = Measure::initModule();
|
||||||
|
|
||||||
// Add Types to module
|
// Add Types to module
|
||||||
Base::Interpreter().addType(&Measure::MeasurementPy ::Type,measureModule,"Measurement");
|
Base::Interpreter().addType(&Measure::MeasurementPy ::Type,mod,"Measurement");
|
||||||
|
Base::Console().Log("Loading Inspection module... done\n");
|
||||||
Base::Console().Log("Loading Measure module... done\n");
|
|
||||||
|
|
||||||
Measure::Measurement ::init();
|
Measure::Measurement ::init();
|
||||||
|
PyMOD_Return(mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // extern "C"
|
|
||||||
|
|
||||||
// debug print for sketchsolv
|
// debug print for sketchsolv
|
||||||
void debugprint(std::string s)
|
void debugprint(std::string s)
|
||||||
{
|
{
|
||||||
Base::Console().Log(s.c_str());
|
Base::Console().Log(s.c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Base/Console.h>
|
#include <Base/Console.h>
|
||||||
|
#include <Base/PyObjectBase.h>
|
||||||
#include <Base/Interpreter.h>
|
#include <Base/Interpreter.h>
|
||||||
|
|
||||||
#include "DrawPage.h"
|
#include "DrawPage.h"
|
||||||
|
@ -40,11 +41,11 @@
|
||||||
#include "DrawViewDetail.h"
|
#include "DrawViewDetail.h"
|
||||||
|
|
||||||
namespace TechDraw {
|
namespace TechDraw {
|
||||||
extern PyObject* initModule();
|
extern PyObject* initModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Python entry */
|
/* Python entry */
|
||||||
PyMODINIT_FUNC initTechDraw()
|
PyMOD_INIT_FUNC(TechDraw)
|
||||||
{
|
{
|
||||||
// load dependent module
|
// load dependent module
|
||||||
try {
|
try {
|
||||||
|
@ -53,9 +54,9 @@ PyMODINIT_FUNC initTechDraw()
|
||||||
}
|
}
|
||||||
catch(const Base::Exception& e) {
|
catch(const Base::Exception& e) {
|
||||||
PyErr_SetString(PyExc_ImportError, e.what());
|
PyErr_SetString(PyExc_ImportError, e.what());
|
||||||
return;
|
PyMOD_Return(0);
|
||||||
}
|
}
|
||||||
(void)TechDraw::initModule();
|
PyObject* mod = TechDraw::initModule();
|
||||||
Base::Console().Log("Loading TechDraw module... done\n");
|
Base::Console().Log("Loading TechDraw module... done\n");
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,4 +97,5 @@ PyMODINIT_FUNC initTechDraw()
|
||||||
TechDraw::DrawViewMultiPython ::init();
|
TechDraw::DrawViewMultiPython ::init();
|
||||||
TechDraw::DrawTemplatePython ::init();
|
TechDraw::DrawTemplatePython ::init();
|
||||||
TechDraw::DrawViewSymbolPython::init();
|
TechDraw::DrawViewSymbolPython::init();
|
||||||
|
PyMOD_Return(mod);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,11 @@ PyObject* DrawPagePy::addView(PyObject* args)
|
||||||
DrawView* view = pyView->getDrawViewPtr(); //get DrawView for pyView
|
DrawView* view = pyView->getDrawViewPtr(); //get DrawView for pyView
|
||||||
|
|
||||||
int rc = page->addView(view);
|
int rc = page->addView(view);
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
return PyInt_FromLong((long) rc);
|
return PyInt_FromLong((long) rc);
|
||||||
|
#else
|
||||||
|
return PyLong_FromLong((long) rc);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* DrawPagePy::removeView(PyObject* args)
|
PyObject* DrawPagePy::removeView(PyObject* args)
|
||||||
|
@ -60,7 +63,11 @@ PyObject* DrawPagePy::removeView(PyObject* args)
|
||||||
|
|
||||||
int rc = page->removeView(view);
|
int rc = page->removeView(view);
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
return PyInt_FromLong((long) rc);
|
return PyInt_FromLong((long) rc);
|
||||||
|
#else
|
||||||
|
return PyLong_FromLong((long) rc);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
<Documentation>
|
<Documentation>
|
||||||
<UserDocu>Number of geometry in template</UserDocu>
|
<UserDocu>Number of geometry in template</UserDocu>
|
||||||
</Documentation>
|
</Documentation>
|
||||||
<Parameter Name="GeometryCount" Type="Int"/>
|
<Parameter Name="GeometryCount" Type="Long"/>
|
||||||
</Attribute>
|
</Attribute>
|
||||||
</PythonExport>
|
</PythonExport>
|
||||||
</GenerateModel>
|
</GenerateModel>
|
||||||
|
|
|
@ -80,8 +80,16 @@ PyObject* DrawParametricTemplatePy::drawLine(PyObject *args)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
Py::Int DrawParametricTemplatePy::getGeometryCount(void) const
|
Py::Int DrawParametricTemplatePy::getGeometryCount(void) const
|
||||||
{
|
{
|
||||||
int size = getDrawParametricTemplatePtr()->getGeometry().size();
|
int size = getDrawParametricTemplatePtr()->getGeometry().size();
|
||||||
return Py::Int(size);
|
return Py::Int(size);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
Py::Long DrawParametricTemplatePy::getGeometryCount(void) const
|
||||||
|
{
|
||||||
|
int size = getDrawParametricTemplatePtr()->getGeometry().size();
|
||||||
|
return Py::Long(size);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -49,7 +49,11 @@ PyObject* DrawProjGroupPy::removeProjection(PyObject* args)
|
||||||
DrawProjGroup* projGroup = getDrawProjGroupPtr();
|
DrawProjGroup* projGroup = getDrawProjGroupPtr();
|
||||||
int i = projGroup->removeProjection(projType);
|
int i = projGroup->removeProjection(projType);
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
return PyInt_FromLong((long) i);
|
return PyInt_FromLong((long) i);
|
||||||
|
#else
|
||||||
|
return PyLong_FromLong((long) i);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* DrawProjGroupPy::purgeProjections(PyObject* /*args*/)
|
PyObject* DrawProjGroupPy::purgeProjections(PyObject* /*args*/)
|
||||||
|
@ -57,7 +61,11 @@ PyObject* DrawProjGroupPy::purgeProjections(PyObject* /*args*/)
|
||||||
DrawProjGroup* projGroup = getDrawProjGroupPtr();
|
DrawProjGroup* projGroup = getDrawProjGroupPtr();
|
||||||
int i = projGroup->purgeProjections();
|
int i = projGroup->purgeProjections();
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
return PyInt_FromLong((long) i);
|
return PyInt_FromLong((long) i);
|
||||||
|
#else
|
||||||
|
return PyLong_FromLong((long) i);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* DrawProjGroupPy::getItemByLabel(PyObject* args)
|
PyObject* DrawProjGroupPy::getItemByLabel(PyObject* args)
|
||||||
|
|
|
@ -50,7 +50,11 @@ PyObject* DrawSVGTemplatePy::getEditFieldContent(PyObject* args)
|
||||||
}
|
}
|
||||||
std::string content = getDrawSVGTemplatePtr()->EditableTexts[fieldName];
|
std::string content = getDrawSVGTemplatePtr()->EditableTexts[fieldName];
|
||||||
if (!content.empty()) {
|
if (!content.empty()) {
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
result = PyString_FromString(content.c_str());
|
result = PyString_FromString(content.c_str());
|
||||||
|
#else
|
||||||
|
result = PyUnicode_FromString(content.c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,11 @@ PyObject* DrawViewClipPy::getChildViewNames(PyObject* args)
|
||||||
|
|
||||||
std::vector<std::string>::iterator it = strings.begin();
|
std::vector<std::string>::iterator it = strings.begin();
|
||||||
for( ; it != strings.end(); it++) {
|
for( ; it != strings.end(); it++) {
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
PyObject* pString = PyString_FromString(it->c_str()); //TODO: unicode & py3
|
PyObject* pString = PyString_FromString(it->c_str()); //TODO: unicode & py3
|
||||||
|
#else
|
||||||
|
PyObject* pString = PyUnicode_FromString(it->c_str());
|
||||||
|
#endif
|
||||||
//int rc =
|
//int rc =
|
||||||
static_cast<void> (PyList_Append(result, pString));
|
static_cast<void> (PyList_Append(result, pString));
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,11 @@ PyObject* DrawViewCollectionPy::addView(PyObject* args)
|
||||||
|
|
||||||
int i = collect->addView(view);
|
int i = collect->addView(view);
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
return PyInt_FromLong((long) i);
|
return PyInt_FromLong((long) i);
|
||||||
|
#else
|
||||||
|
return PyLong_FromLong((long) i);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* DrawViewCollectionPy::removeView(PyObject* args)
|
PyObject* DrawViewCollectionPy::removeView(PyObject* args)
|
||||||
|
@ -47,7 +51,11 @@ PyObject* DrawViewCollectionPy::removeView(PyObject* args)
|
||||||
|
|
||||||
int i = collect->removeView(view);
|
int i = collect->removeView(view);
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
return PyInt_FromLong((long) i);
|
return PyInt_FromLong((long) i);
|
||||||
|
#else
|
||||||
|
return PyLong_FromLong((long) i);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Base/Console.h>
|
#include <Base/Console.h>
|
||||||
|
#include <Base/PyObjectBase.h>
|
||||||
#include <Gui/Application.h>
|
#include <Gui/Application.h>
|
||||||
#include <Gui/Language/Translator.h>
|
#include <Gui/Language/Translator.h>
|
||||||
#include <Gui/WidgetFactory.h>
|
#include <Gui/WidgetFactory.h>
|
||||||
|
@ -65,21 +66,38 @@ void loadTechDrawResource()
|
||||||
Gui::Translator::instance()->refresh();
|
Gui::Translator::instance()->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* registration table */
|
namespace TechDrawGui {
|
||||||
extern struct PyMethodDef TechDrawGui_Import_methods[];
|
class Module : public Py::ExtensionModule<Module>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Module() : Py::ExtensionModule<Module>("TechDrawGui")
|
||||||
|
{
|
||||||
|
initialize("This module is the TechDrawGui module."); // register with Python
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~Module() {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
PyObject* initModule()
|
||||||
|
{
|
||||||
|
return (new Module)->module().ptr();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace TechDrawGui
|
||||||
|
|
||||||
|
|
||||||
/* Python entry */
|
/* Python entry */
|
||||||
extern "C" {
|
PyMOD_INIT_FUNC(TechDrawGui)
|
||||||
void TechDrawGuiExport initTechDrawGui()
|
|
||||||
{
|
{
|
||||||
if (!Gui::Application::Instance) {
|
if (!Gui::Application::Instance) {
|
||||||
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
|
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
|
||||||
return;
|
PyMOD_Return(0);
|
||||||
}
|
}
|
||||||
|
PyObject* mod = TechDrawGui::initModule();
|
||||||
|
|
||||||
(void) Py_InitModule("TechDrawGui", TechDrawGui_Import_methods); /* mod name, table ptr */
|
Base::Console().Log("Loading TechDrawGui module... done\n");
|
||||||
Base::Console().Log("Loading GUI of TechDraw module... done\n");
|
|
||||||
|
|
||||||
// instantiating the commands
|
// instantiating the commands
|
||||||
CreateTechDrawCommands();
|
CreateTechDrawCommands();
|
||||||
|
@ -113,6 +131,6 @@ void TechDrawGuiExport initTechDrawGui()
|
||||||
|
|
||||||
// add resources and reloads the translators
|
// add resources and reloads the translators
|
||||||
loadTechDrawResource();
|
loadTechDrawResource();
|
||||||
}
|
|
||||||
|
|
||||||
} // extern "C" {
|
PyMOD_Return(mod);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user