diff options
author | FormerLurker <hochgebe@gmail.com> | 2020-11-16 18:00:56 +0300 |
---|---|---|
committer | FormerLurker <hochgebe@gmail.com> | 2020-11-16 18:00:56 +0300 |
commit | 0f57a03f82a555a9b6d3afdfb133457c72455d54 (patch) | |
tree | b5403a38d5ecd473f727b34e48099c9e35ba320c /PyArcWelder | |
parent | b995df6e38d0185f32f06cac87e781249975b738 (diff) |
Add the job guid to the py arguments and progress updates. Add additional progress data.
Diffstat (limited to 'PyArcWelder')
-rw-r--r-- | PyArcWelder/py_arc_welder.cpp | 16 | ||||
-rw-r--r-- | PyArcWelder/py_arc_welder.h | 5 | ||||
-rw-r--r-- | PyArcWelder/py_arc_welder_extension.cpp | 32 | ||||
-rw-r--r-- | PyArcWelder/py_arc_welder_extension.h | 20 |
4 files changed, 49 insertions, 24 deletions
diff --git a/PyArcWelder/py_arc_welder.cpp b/PyArcWelder/py_arc_welder.cpp index 0eacf39..fc185fe 100644 --- a/PyArcWelder/py_arc_welder.cpp +++ b/PyArcWelder/py_arc_welder.cpp @@ -22,13 +22,17 @@ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include "py_arc_welder.h" -PyObject* py_arc_welder::build_py_progress(const arc_welder_progress& progress) +PyObject* py_arc_welder::build_py_progress(const arc_welder_progress& progress, std::string guid) { std::string segment_statistics = progress.segment_statistics.str(); + PyObject* pyGuid = gcode_arc_converter::PyUnicode_SafeFromString(guid); + if (pyGuid == NULL) + return NULL; PyObject* pyMessage = gcode_arc_converter::PyUnicode_SafeFromString(segment_statistics); if (pyMessage == NULL) return NULL; - 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}", + 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}", "percent_complete", progress.percent_complete, //1 "seconds_elapsed", @@ -60,7 +64,10 @@ PyObject* py_arc_welder::build_py_progress(const arc_welder_progress& progress) "source_file_total_count", progress.segment_statistics.total_count_source, //15 "target_file_total_count", - progress.segment_statistics.total_length_target //16 + progress.segment_statistics.total_count_target, //16 + "total_count_reduction_percent", + total_count_reduction_percent //17 + ); if (py_progress == NULL) @@ -71,12 +78,13 @@ PyObject* py_arc_welder::build_py_progress(const arc_welder_progress& progress) // else it crashes in python 2.7. Looking forward to retiring this backwards // compatible code... PyDict_SetItemString(py_progress, "segment_statistics_text", pyMessage); + PyDict_SetItemString(py_progress, "guid", pyGuid); return py_progress; } bool py_arc_welder::on_progress_(const arc_welder_progress& progress) { - PyObject* py_dict = py_arc_welder::build_py_progress(progress); + PyObject* py_dict = py_arc_welder::build_py_progress(progress, guid_); if (py_dict == NULL) { return false; diff --git a/PyArcWelder/py_arc_welder.h b/PyArcWelder/py_arc_welder.h index ffa4561..4d0e56b 100644 --- a/PyArcWelder/py_arc_welder.h +++ b/PyArcWelder/py_arc_welder.h @@ -35,6 +35,7 @@ class py_arc_welder : public arc_welder { public: py_arc_welder( + std::string guid, std::string source_path, std::string target_path, py_logger* logger, @@ -54,13 +55,15 @@ public: g90_g91_influences_extruder, buffer_size ){ + guid_ = guid; py_progress_callback_ = py_progress_callback; } virtual ~py_arc_welder() { } - static PyObject* build_py_progress(const arc_welder_progress& progress); + static PyObject* build_py_progress(const arc_welder_progress& progress, std::string guid); protected: + std::string guid_; virtual bool on_progress_(const arc_welder_progress& progress); private: PyObject* py_progress_callback_; diff --git a/PyArcWelder/py_arc_welder_extension.cpp b/PyArcWelder/py_arc_welder_extension.cpp index d22500e..634d30c 100644 --- a/PyArcWelder/py_arc_welder_extension.cpp +++ b/PyArcWelder/py_arc_welder_extension.cpp @@ -190,13 +190,13 @@ extern "C" std::string message = "py_gcode_arc_converter.ConvertFile - Beginning Arc Conversion."; 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.path_tolerance_percent, args.max_radius_mm, args.g90_g91_influences_extruder, DEFAULT_GCODE_BUFFER_SIZE, py_progress_callback); + py_arc_welder arc_welder_obj(args.guid, args.source_path, args.target_path, p_py_logger, args.resolution_mm, args.path_tolerance_percent, args.max_radius_mm, args.g90_g91_influences_extruder, DEFAULT_GCODE_BUFFER_SIZE, py_progress_callback); 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); // return the arguments - PyObject* p_progress = py_arc_welder::build_py_progress(results.progress); + PyObject* p_progress = py_arc_welder::build_py_progress(results.progress, args.guid); if (p_progress == NULL) p_progress = Py_None; @@ -204,7 +204,7 @@ extern "C" "{s:i,s:i,s:s,s:O}", "success", results.success, - "cancelled", + "is_cancelled", results.cancelled, "message", results.message.c_str(), @@ -222,25 +222,35 @@ static bool ParseArgs(PyObject* py_args, py_gcode_arc_args& args, PyObject** py_ "Parsing GCode Conversion Args." ); + // Extract the job guid + PyObject* py_guid = PyDict_GetItemString(py_args, "guid"); + if (py_guid == NULL) + { + std::string message = "ParseArgs - Unable to retrieve the guid parameter from the args."; + p_py_logger->log_exception(GCODE_CONVERSION, message); + return false; + } + args.guid = gcode_arc_converter::PyUnicode_SafeAsString(py_guid); + // Extract the source file path - PyObject* py_source_file_path = PyDict_GetItemString(py_args, "source_file_path"); - if (py_source_file_path == NULL) + PyObject* py_source_path = PyDict_GetItemString(py_args, "source_path"); + if (py_source_path == NULL) { - std::string message = "ParseArgs - Unable to retrieve the source_file_path parameter from the args."; + std::string message = "ParseArgs - Unable to retrieve the source_path parameter from the args."; p_py_logger->log_exception(GCODE_CONVERSION, message); return false; } - args.source_file_path = gcode_arc_converter::PyUnicode_SafeAsString(py_source_file_path); + args.source_path = gcode_arc_converter::PyUnicode_SafeAsString(py_source_path); // Extract the target file path - PyObject* py_target_file_path = PyDict_GetItemString(py_args, "target_file_path"); - if (py_target_file_path == NULL) + PyObject* py_target_path = PyDict_GetItemString(py_args, "target_path"); + if (py_target_path == NULL) { - std::string message = "ParseArgs - Unable to retrieve the target_file_path parameter from the args."; + std::string message = "ParseArgs - Unable to retrieve the target_path parameter from the args."; p_py_logger->log_exception(GCODE_CONVERSION, message); return false; } - args.target_file_path = gcode_arc_converter::PyUnicode_SafeAsString(py_target_file_path); + args.target_path = gcode_arc_converter::PyUnicode_SafeAsString(py_target_path); // Extract the resolution in millimeters PyObject* py_resolution_mm = PyDict_GetItemString(py_args, "resolution_mm"); diff --git a/PyArcWelder/py_arc_welder_extension.h b/PyArcWelder/py_arc_welder_extension.h index 84e50ec..f288c9a 100644 --- a/PyArcWelder/py_arc_welder_extension.h +++ b/PyArcWelder/py_arc_welder_extension.h @@ -43,8 +43,9 @@ extern "C" struct py_gcode_arc_args { py_gcode_arc_args() { - source_file_path = ""; - target_file_path = ""; + guid = ""; + source_path = ""; + target_path = ""; resolution_mm = DEFAULT_RESOLUTION_MM; path_tolerance_percent = ARC_LENGTH_PERCENT_TOLERANCE_DEFAULT; max_radius_mm = DEFAULT_MAX_RADIUS_MM; @@ -52,24 +53,27 @@ struct py_gcode_arc_args { log_level = 0; } py_gcode_arc_args( - std::string source_file_path_, - std::string target_file_path_, + std::string guid_, + std::string source_path_, + std::string target_path_, double resolution_mm_, double path_tolerance_percent_, double max_radius_mm_, bool g90_g91_influences_extruder_, int log_level_ ) { - source_file_path = source_file_path_; - target_file_path = target_file_path_; + guid = guid_; + source_path = source_path_; + target_path = target_path_; resolution_mm = resolution_mm_; path_tolerance_percent = path_tolerance_percent_; max_radius_mm = max_radius_mm_; g90_g91_influences_extruder = g90_g91_influences_extruder_; log_level = log_level_; } - std::string source_file_path; - std::string target_file_path; + std::string guid; + std::string source_path; + std::string target_path; double resolution_mm; double path_tolerance_percent; bool g90_g91_influences_extruder; |