1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Arc Welder: Anti-Stutter Python Extension for the OctoPrint Arc Welder plugin.
//
// Compresses many G0/G1 commands into G2/G3(arc) commands where possible, ensuring the tool paths stay within the specified resolution.
// This reduces file size and the number of gcodes per second.
//
// Copyright(C) 2020 - Brad Hochgesang
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 Affero General Public License for more details.
//
//
// You can contact the author at the following email address:
// FormerLurker@pm.me
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "py_arc_welder.h"
PyObject* py_arc_welder::build_py_progress(arc_welder_progress progress)
{
PyObject* py_progress = Py_BuildValue("{s:d,s:d,s:d,s:i,s:i,s:i,s:i,s:i,s:i}",
u8"percent_complete",
progress.percent_complete,
u8"seconds_elapsed",
progress.seconds_elapsed,
u8"seconds_remaining",
progress.seconds_remaining,
u8"gcodes_processed",
progress.gcodes_processed,
u8"lines_processed",
progress.lines_processed,
u8"points_compressed",
progress.points_compressed,
u8"arcs_created",
progress.arcs_created,
u8"source_file_size",
progress.source_file_size,
u8"target_file_size",
progress.target_file_size
);
return py_progress;
}
bool py_arc_welder::on_progress_(arc_welder_progress progress)
{
PyObject* py_dict = py_arc_welder::build_py_progress(progress);
if (py_dict == NULL)
return NULL;
PyObject* func_args = Py_BuildValue("(O)", py_dict);
if (func_args == NULL)
{
Py_DECREF(py_dict);
return true;
}
PyGILState_STATE gstate = PyGILState_Ensure();
PyObject* pContinueProcessing = PyObject_CallObject(py_progress_callback_, func_args);
Py_DECREF(func_args);
Py_DECREF(py_dict);
bool continue_processing;
if (pContinueProcessing == NULL)
{
// no return value was supply, assume true, but without decrefing pContinueProcessing
continue_processing = true;
}
else
{
if (pContinueProcessing == Py_None)
{
continue_processing = true;
}
else
{
continue_processing = PyLong_AsLong(pContinueProcessing) > 0;
}
Py_DECREF(pContinueProcessing);
}
PyGILState_Release(gstate);
return continue_processing;
}
|