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-11-28 03:20:29 +0300
committerFormerLurker <hochgebe@gmail.com>2020-11-28 03:20:29 +0300
commit7da85eb0a6d659885b4a16fce7a0ba15ecbe0e39 (patch)
tree113b82b09851a545fd5666deab1b790cc52635d0 /PyArcWelder
parent359b6e92bf252a9ab6485179aee7f3148108aa86 (diff)
Fix Python unicode logging issues. Add sin approximation to inverse processor. Fix log levels and progress output. Add firmware compensation statistics.
Diffstat (limited to 'PyArcWelder')
-rw-r--r--PyArcWelder/py_arc_welder.cpp27
-rw-r--r--PyArcWelder/py_arc_welder_extension.cpp15
-rw-r--r--PyArcWelder/py_logger.cpp4
-rw-r--r--PyArcWelder/python_helpers.cpp9
-rw-r--r--PyArcWelder/python_helpers.h1
5 files changed, 34 insertions, 22 deletions
diff --git a/PyArcWelder/py_arc_welder.cpp b/PyArcWelder/py_arc_welder.cpp
index fc185fe..36588f2 100644
--- a/PyArcWelder/py_arc_welder.cpp
+++ b/PyArcWelder/py_arc_welder.cpp
@@ -32,7 +32,7 @@ PyObject* py_arc_welder::build_py_progress(const arc_welder_progress& progress,
if (pyMessage == NULL)
return NULL;
double total_count_reduction_percent = progress.segment_statistics.get_total_count_reduction_percent();
- PyObject* py_progress = Py_BuildValue("{s:d,s:d,s:d,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:f,s:f,s:f,s:f,s:i,s:i,s:f}",
+ PyObject* py_progress = Py_BuildValue("{s:d,s:d,s:d,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:f,s:f,s:f,s:f,s:i,s:i,s:f}",
"percent_complete",
progress.percent_complete, //1
"seconds_elapsed",
@@ -47,26 +47,28 @@ PyObject* py_arc_welder::build_py_progress(const arc_welder_progress& progress,
progress.points_compressed, //6
"arcs_created",
progress.arcs_created, //7
+ "num_firmware_compensations",
+ progress.num_firmware_compensations, //8
"source_file_position",
- progress.source_file_position, //8
+ progress.source_file_position, //9
"source_file_size",
- progress.source_file_size, //9
+ progress.source_file_size, //10
"target_file_size",
- progress.target_file_size, //10
+ progress.target_file_size, //11
"compression_ratio",
- progress.compression_ratio, //11
+ progress.compression_ratio, //12
"compression_percent",
- progress.compression_percent, //12
+ progress.compression_percent, //13
"source_file_total_length",
- progress.segment_statistics.total_length_source, //13
+ progress.segment_statistics.total_length_source, //14
"target_file_total_length",
- progress.segment_statistics.total_length_target, //14
+ progress.segment_statistics.total_length_target, //15
"source_file_total_count",
- progress.segment_statistics.total_count_source, //15
+ progress.segment_statistics.total_count_source, //16
"target_file_total_count",
- progress.segment_statistics.total_count_target, //16
+ progress.segment_statistics.total_count_target, //17
"total_count_reduction_percent",
- total_count_reduction_percent //17
+ total_count_reduction_percent //18
);
@@ -98,6 +100,7 @@ bool py_arc_welder::on_progress_(const arc_welder_progress& progress)
PyGILState_STATE gstate = PyGILState_Ensure();
PyObject* pContinueProcessing = PyObject_CallObject(py_progress_callback_, func_args);
+ PyGILState_Release(gstate);
Py_DECREF(func_args);
Py_DECREF(py_dict);
bool continue_processing;
@@ -118,6 +121,6 @@ bool py_arc_welder::on_progress_(const arc_welder_progress& progress)
}
Py_DECREF(pContinueProcessing);
}
- PyGILState_Release(gstate);
+
return continue_processing;
}
diff --git a/PyArcWelder/py_arc_welder_extension.cpp b/PyArcWelder/py_arc_welder_extension.cpp
index 5f7553c..e9d85ca 100644
--- a/PyArcWelder/py_arc_welder_extension.cpp
+++ b/PyArcWelder/py_arc_welder_extension.cpp
@@ -28,6 +28,7 @@
#include "arc_welder.h"
#include "py_logger.h"
#include "python_helpers.h"
+#include "version.h"
#if PY_MAJOR_VERSION >= 3
int main(int argc, char* argv[])
@@ -47,10 +48,10 @@ int main(int argc, char* argv[])
// Initialize the Python interpreter. Required.
Py_Initialize();
// We are not using threads, do not enable.
- /*std::cout << "Initializing threads...";
+ 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);
@@ -126,8 +127,9 @@ PyInit_PyArcWelder(void)
extern "C" void initPyArcWelder(void)
#endif
{
- std::cout << "Initializing PyArcWelder V0.1.0rc1.dev2 - Copyright (C) 2019 Brad Hochgesang.";
-
+ std::cout << "Initializing PyArcWelder";
+ std::cout << "\nVersion: " << GIT_TAGGED_VERSION << ", Branch: " << GIT_BRANCH << ", BuildDate: " << BUILD_DATE;
+ std::cout << "\nCopyright(C) " << COPYRIGHT_DATE << " - " << AUTHOR;
#if PY_MAJOR_VERSION >= 3
std::cout << " Python 3+ Detected...";
PyObject* module = PyModule_Create(&moduledef);
@@ -159,7 +161,7 @@ extern "C" void initPyArcWelder(void)
p_py_logger->initialize_loggers();
std::string message = "PyArcWelder V0.1.0rc1.dev2 imported - Copyright (C) 2019 Brad Hochgesang...";
p_py_logger->log(GCODE_CONVERSION, INFO, message);
- p_py_logger->set_log_level_by_value(DEBUG);
+ p_py_logger->set_log_level(ERROR);
std::cout << " Initialization Complete\r\n";
#if PY_MAJOR_VERSION >= 3
@@ -190,8 +192,7 @@ extern "C"
{
return NULL;
}
- p_py_logger->set_log_level_by_value(args.log_level);
-
+ p_py_logger->set_log_level(args.log_level);
std::string message = "py_gcode_arc_converter.ConvertFile - Beginning Arc Conversion.";
p_py_logger->log(GCODE_CONVERSION, INFO, message);
diff --git a/PyArcWelder/py_logger.cpp b/PyArcWelder/py_logger.cpp
index 1020331..0418ef5 100644
--- a/PyArcWelder/py_logger.cpp
+++ b/PyArcWelder/py_logger.cpp
@@ -203,7 +203,7 @@ void py_logger::log(const int logger_type, const int log_level, const std::strin
return;
}
}
- PyObject* pyMessage = gcode_arc_converter::PyUnicode_SafeFromString(message);
+ PyObject* pyMessage = gcode_arc_converter::PyBytesOrString_FromString(message);
if (pyMessage == NULL)
{
std::cout << "Unable to convert the log message '" << message.c_str() << "' to a PyString/Unicode message.\r\n";
@@ -222,7 +222,6 @@ void py_logger::log(const int logger_type, const int log_level, const std::strin
{
std::cout << "Logging.arc_welder_log - null was returned from the specified logger.\r\n";
PyErr_SetString(PyExc_ValueError, "Logging.arc_welder_log - null was returned from the specified logger.");
- return;
}
else
{
@@ -234,7 +233,6 @@ void py_logger::log(const int logger_type, const int log_level, const std::strin
// return an error.
PyErr_Print();
PyErr_Clear();
- return;
}
}
else
diff --git a/PyArcWelder/python_helpers.cpp b/PyArcWelder/python_helpers.cpp
index acaae19..3eaa39c 100644
--- a/PyArcWelder/python_helpers.cpp
+++ b/PyArcWelder/python_helpers.cpp
@@ -72,6 +72,15 @@ namespace gcode_arc_converter {
#endif
}
+ PyObject* PyBytesOrString_FromString(std::string str)
+ {
+#if PY_MAJOR_VERSION >= 3
+ return PyBytes_FromString(str.c_str());
+#else
+ return PyString_FromString(str.c_str());
+#endif
+ }
+
double PyFloatOrInt_AsDouble(PyObject* py_double_or_int)
{
if (PyFloat_CheckExact(py_double_or_int))
diff --git a/PyArcWelder/python_helpers.h b/PyArcWelder/python_helpers.h
index 93ad23d..80d59ed 100644
--- a/PyArcWelder/python_helpers.h
+++ b/PyArcWelder/python_helpers.h
@@ -34,6 +34,7 @@ namespace gcode_arc_converter {
const char* PyUnicode_SafeAsString(PyObject* py);
PyObject* PyString_SafeFromString(const char* str);
PyObject* PyUnicode_SafeFromString(std::string str);
+ PyObject* PyBytesOrString_FromString(std::string str);
double PyFloatOrInt_AsDouble(PyObject* py_double_or_int);
long PyIntOrLong_AsLong(PyObject* value);
bool PyFloatLongOrInt_Check(PyObject* value);