Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FormerLurker/ArcWelderLib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFormerLurker <hochgebe@gmail.com>2020-05-02 18:06:40 +0300
committerFormerLurker <hochgebe@gmail.com>2020-05-02 18:06:40 +0300
commit8d7b572cc7fa7faf795db88a29340b6380090f8f (patch)
tree5c5b2fb251af89e0c9038be84236c6df85d098fb /PyArcWelder/py_arc_welder_extension.cpp
parent4fcf89d4995921b89b579d06052df11b66e4879f (diff)
Add enhanced progress and complete statistics for arc welder. Add ARC_SEGMENTS_PER_SEC to inverse processor.
Diffstat (limited to 'PyArcWelder/py_arc_welder_extension.cpp')
-rw-r--r--PyArcWelder/py_arc_welder_extension.cpp63
1 files changed, 41 insertions, 22 deletions
diff --git a/PyArcWelder/py_arc_welder_extension.cpp b/PyArcWelder/py_arc_welder_extension.cpp
index eaf9923..89410b9 100644
--- a/PyArcWelder/py_arc_welder_extension.cpp
+++ b/PyArcWelder/py_arc_welder_extension.cpp
@@ -39,17 +39,18 @@ int main(int argc, char* argv[])
}
// Add a built-in module, before Py_Initialize
- PyImport_AppendInittab("PyArcWelder", PyInit_PyGcodeArcConverter);
+ PyImport_AppendInittab("PyArcWelder", PyInit_PyArcWelder);
// Pass argv[0] to the Python interpreter
Py_SetProgramName(program);
// Initialize the Python interpreter. Required.
Py_Initialize();
- std::cout << "Initializing threads...";
+ // We are not using threads, do not enable.
+ /*std::cout << "Initializing threads...";
if (!PyEval_ThreadsInitialized()) {
PyEval_InitThreads();
- }
+ }*/
// Optionally import the module; alternatively, import can be deferred until the embedded script imports it.
PyImport_ImportModule("PyArcWelder");
PyMem_RawFree(program);
@@ -62,10 +63,13 @@ int main(int argc, char* argv[])
{
Py_SetProgramName(argv[0]);
Py_Initialize();
+ // We are not using threads, do not enable.
+ /* std::cout << "Initializing threads...";
if (!PyEval_ThreadsInitialized()) {
PyEval_InitThreads();
}
- initPyGcodeArcConverter();
+ */
+ initPyArcWelder();
return 0;
}
@@ -82,61 +86,61 @@ static struct module_state _state;
#endif
// Python 2 module method definition
-static PyMethodDef PyGcodeArcConverterMethods[] = {
+static PyMethodDef PyArcWelderMethods[] = {
{ "ConvertFile", (PyCFunction)ConvertFile, METH_VARARGS ,"Converts segmented curve approximations to actual G2/G3 arcs within the supplied resolution." },
{ NULL, NULL, 0, NULL }
};
// Python 3 module method definition
#if PY_MAJOR_VERSION >= 3
-static int PyGcodeArcConverter_traverse(PyObject* m, visitproc visit, void* arg) {
+static int PyArcWelder_traverse(PyObject* m, visitproc visit, void* arg) {
Py_VISIT(GETSTATE(m)->error);
return 0;
}
-static int PyGcodeArcConverter_clear(PyObject* m) {
+static int PyArcWelder_clear(PyObject* m) {
Py_CLEAR(GETSTATE(m)->error);
return 0;
}
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
- "PyGcodeArcConverter",
+ "PyArcWelder",
NULL,
sizeof(struct module_state),
- PyGcodeArcConverterMethods,
+ PyArcWelderMethods,
NULL,
- PyGcodeArcConverter_traverse,
- PyGcodeArcConverter_clear,
+ PyArcWelder_traverse,
+ PyArcWelder_clear,
NULL
};
#define INITERROR return NULL
PyMODINIT_FUNC
-PyInit_PyGcodeArcConverter(void)
+PyInit_PyArcWelder(void)
#else
#define INITERROR return
-extern "C" void initPyGcodeArcConverter(void)
+extern "C" void initPyArcWelder(void)
#endif
{
- std::cout << "Initializing PyGcodeArcConverter V0.1.0rc1.dev0 - Copyright (C) 2019 Brad Hochgesang...";
+ std::cout << "Initializing PyArcWelder V0.1.0rc1.dev0 - Copyright (C) 2019 Brad Hochgesang.";
#if PY_MAJOR_VERSION >= 3
- std::cout << "Python 3+ Detected...";
+ std::cout << " Python 3+ Detected...";
PyObject* module = PyModule_Create(&moduledef);
#else
- std::cout << "Python 2 Detected...";
- PyObject* module = Py_InitModule("PyGcodeArcConverter", PyGcodeArcConverterMethods);
+ std::cout << " Python 2 Detected...";
+ PyObject* module = Py_InitModule("PyArcWelder", PyArcWelderMethods);
#endif
if (module == NULL)
INITERROR;
struct module_state* st = GETSTATE(module);
- st->error = PyErr_NewException((char*)"PyGcodeArcConverter.Error", NULL, NULL);
+ st->error = PyErr_NewException((char*)"PyArcWelder.Error", NULL, NULL);
if (st->error == NULL) {
Py_DECREF(module);
INITERROR;
@@ -150,7 +154,7 @@ extern "C" void initPyGcodeArcConverter(void)
std::string message = "PyArcWelder V0.1.0rc1.dev0 imported - Copyright (C) 2019 Brad Hochgesang...";
p_py_logger->log(GCODE_CONVERSION, INFO, message);
p_py_logger->set_log_level_by_value(DEBUG);
- std::cout << "complete\r\n";
+ std::cout << " Initialization Complete\r\n";
#if PY_MAJOR_VERSION >= 3
return module;
@@ -191,12 +195,27 @@ extern "C"
p_py_logger->log(GCODE_CONVERSION, INFO, message);
py_arc_welder arc_welder_obj(args.source_file_path, args.target_file_path, p_py_logger, args.resolution_mm, args.g90_g91_influences_extruder, 50, py_progress_callback);
- arc_welder_obj.process();
+ arc_welder_results results = arc_welder_obj.process();
message = "py_gcode_arc_converter.ConvertFile - Arc Conversion Complete.";
p_py_logger->log(GCODE_CONVERSION, INFO, message);
Py_XDECREF(py_progress_callback);
- // For now just return py_none
- return PyTuple_Pack(1, Py_None);
+ // return the arguments
+ PyObject* p_progress = py_arc_welder::build_py_progress(results.progress);
+ if (p_progress == NULL)
+ p_progress = Py_None;
+
+ PyObject* p_results = Py_BuildValue(
+ "{s:i,s:i,s:s,s:O}",
+ u8"success",
+ results.success,
+ u8"cancelled",
+ results.cancelled,
+ u8"message",
+ results.message,
+ u8"progress",
+ p_progress
+ );
+ return p_results;
}
}