svg2gcode 4.0.5__tar.gz → 4.0.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/PKG-INFO +1 -1
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/__init__.py +1 -1
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/compiler/_compiler.py +140 -86
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/compiler/interfaces/_abstract_interface.py +8 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/compiler/interfaces/_gcode.py +15 -2
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/svg_parser/_parser_methods.py +27 -2
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/LICENSE +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/README.md +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/pyproject.toml +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/__main__.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_examples/README.md +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_examples/gcode_output.zip +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_examples/kye_circle_paws_orig copy.svg +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_examples/kye_circle_paws_orig.svg +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_examples/letterandsigns.svg +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_examples/nonzero_evenodd.svg +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/LICENSE +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/__init__.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/compiler/__init__.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/compiler/interfaces/__init__.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/compiler/interfaces/_fan_controlled_gcode.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/css_color.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/formulas.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/__init__.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/_abstract_chain.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/_abstract_curve.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/_circular_arc.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/_cubic_bazier.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/_elliptical_arc.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/_line.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/_line_segment_chain.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/_matrix.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/_quadratic_bazier.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/_raster_image.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/_smooth_arc_chain.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/geometry/_vector.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/svg_parser/__init__.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/svg_parser/_path.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/svg_parser/_transformation.py +0 -0
- {svg2gcode-4.0.5 → svg2gcode-4.0.6}/svg2gcode/svg_to_gcode/svg_parser/debug_methods.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: svg2gcode
|
|
3
|
-
Version: 4.0.
|
|
3
|
+
Version: 4.0.6
|
|
4
4
|
Summary: svg2gcode: convert an SVG (Scalable Vector Graphic) image to gcode.
|
|
5
5
|
Keywords: scalable vector graphics,svg,image,laser cutter,laser engraving
|
|
6
6
|
Author-email: Johannes Noordanus <mailjohannes.mailnoordanus@gmail.com>
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
- paths are drawn in a vector graphics way including 'fill' and 'stroke'.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
import sys
|
|
8
9
|
import os
|
|
9
10
|
import re
|
|
10
11
|
import logging
|
|
@@ -18,6 +19,7 @@ import base64
|
|
|
18
19
|
from datetime import datetime
|
|
19
20
|
from operator import itemgetter
|
|
20
21
|
from PIL import Image
|
|
22
|
+
from pathlib import Path
|
|
21
23
|
import numpy as np
|
|
22
24
|
import numpy.typing as npt
|
|
23
25
|
|
|
@@ -109,10 +111,10 @@ class Compiler:
|
|
|
109
111
|
self.interface.set_machine_parameters(self.settings)
|
|
110
112
|
|
|
111
113
|
if custom_header is None:
|
|
112
|
-
custom_header = []
|
|
114
|
+
custom_header = [self.interface.set_fan_state('M9', force = True)]
|
|
113
115
|
|
|
114
116
|
if custom_footer is None:
|
|
115
|
-
custom_footer = [self.interface.laser_off(), self.interface.program_end()]
|
|
117
|
+
custom_footer = [self.interface.laser_off(), self.interface.set_fan_state('M9', force = True), self.interface.program_end()]
|
|
116
118
|
|
|
117
119
|
self.header = [self.interface.code_initialize(),
|
|
118
120
|
self.interface.set_unit(self.settings["unit"]),
|
|
@@ -205,12 +207,8 @@ class Compiler:
|
|
|
205
207
|
|
|
206
208
|
# laser off, fan on or off, M3 or M4 burn mode
|
|
207
209
|
header_gc = ["M5"]
|
|
208
|
-
if
|
|
209
|
-
|
|
210
|
-
header_gc += ['M8']
|
|
211
|
-
else:
|
|
212
|
-
# make sure fan is off
|
|
213
|
-
header_gc += ['M9']
|
|
210
|
+
fan_state = 'M8' if self.settings["fan"] == FAN_ON or self.settings["fan"] == FAN_ENGRAVE else 'M9'
|
|
211
|
+
header_gc += [self.interface.set_fan_state(fan_state, force = self.settings["splitfile"])]
|
|
214
212
|
|
|
215
213
|
header_gc += ['M3' if self.settings["laser_mode"] == "constant" else 'M4']
|
|
216
214
|
|
|
@@ -228,9 +226,36 @@ class Compiler:
|
|
|
228
226
|
"""
|
|
229
227
|
self.svg_file_name = svg_file_name
|
|
230
228
|
|
|
229
|
+
def ext_check(expected_extension, filename):
|
|
230
|
+
|
|
231
|
+
suffixes = expected_extension.split(',')
|
|
232
|
+
|
|
233
|
+
for suffix in suffixes:
|
|
234
|
+
if filename.lower().endswith(suffix):
|
|
235
|
+
return True
|
|
236
|
+
|
|
237
|
+
return False
|
|
238
|
+
|
|
239
|
+
# check file extentions
|
|
240
|
+
suffixes = '.svg,.vect'
|
|
241
|
+
if not ext_check(suffixes, svg_file_name):
|
|
242
|
+
logger.error(f"Error: unknown input file extension '{Path(svg_file_name).suffix}', vector file extension should be one of '{suffixes}', exit ...")
|
|
243
|
+
sys.exit(1)
|
|
244
|
+
suffixes = '.gc,.gcode'
|
|
245
|
+
if not ext_check(suffixes, file_name):
|
|
246
|
+
logger.error(f"Error: unknown output file extension '{Path(file_name).suffix}', gcode file extension should be one of '{suffixes}', exit ...")
|
|
247
|
+
sys.exit(1)
|
|
248
|
+
|
|
231
249
|
# generate gcode for 'path' and 'image' svg tags (calculate bbox)
|
|
250
|
+
# results accumulate in:
|
|
251
|
+
# - self.body (path gcode)
|
|
252
|
+
# - self.gcode (image gcode)
|
|
232
253
|
self.append_curves(curves)
|
|
233
254
|
|
|
255
|
+
# check svg file content
|
|
256
|
+
if len(self.body) == 0 and len(self.gcode) == 0:
|
|
257
|
+
logger.error(f"No paths and images to draw, input file '{svg_file_name}' is no vector file?")
|
|
258
|
+
|
|
234
259
|
header = '\n'.join(self.header) + '\n'
|
|
235
260
|
footer = '\n'.join(self.footer) + '\n'
|
|
236
261
|
|
|
@@ -301,7 +326,7 @@ class Compiler:
|
|
|
301
326
|
else:
|
|
302
327
|
# move to the next line_chain: set laser mode, set laser power to 0 (cutting is off),
|
|
303
328
|
# set movement speed, (no rapid) move to start of chain, set laser to power
|
|
304
|
-
code += [self.interface.set_laser_mode(self.settings["laser_mode"]), self.interface.set_laser_power_value(0,
|
|
329
|
+
code += [self.interface.set_laser_mode(self.settings["laser_mode"]), self.interface.set_laser_power_value(0,fan_on = False),
|
|
305
330
|
self.interface.set_movement_speed(movement_speed), self.interface.linear_move(start.x, start.y),
|
|
306
331
|
self.interface.set_laser_power_value(laser_power, fan_on = fan_set)]
|
|
307
332
|
|
|
@@ -314,6 +339,10 @@ class Compiler:
|
|
|
314
339
|
# set laser power and fan
|
|
315
340
|
code += [self.interface.set_laser_power_value(laser_power, fan_on = fan_set)]
|
|
316
341
|
|
|
342
|
+
if not fan_set:
|
|
343
|
+
#set fan off
|
|
344
|
+
code += [self.interface.set_fan_state('M9')]
|
|
345
|
+
|
|
317
346
|
for line in line_chain:
|
|
318
347
|
code.append(self.interface.linear_move(line.end.x, line.end.y))
|
|
319
348
|
self.boundingbox.update(line.end)
|
|
@@ -929,8 +958,15 @@ class Compiler:
|
|
|
929
958
|
# set inversed b&w value (and apply alpha channel, when available)
|
|
930
959
|
inverse_bw = round(Image2gcode.linear_power(css_color.parse_css_color2bw8(fill_color),
|
|
931
960
|
self.settings["maximum_image_laser_power"]) * fill_alpha)
|
|
961
|
+
|
|
962
|
+
fan_set = self.settings["fan"] == FAN_ON or self.settings["fan"] == FAN_ENGRAVE
|
|
932
963
|
# set laser power and fan when 'on' or 'engrave'
|
|
933
|
-
code += [self.interface.set_laser_power_value(inverse_bw, fan_on =
|
|
964
|
+
code += [self.interface.set_laser_power_value(inverse_bw, fan_on = fan_set)]
|
|
965
|
+
|
|
966
|
+
# but set it off when needed
|
|
967
|
+
if not fan_set:
|
|
968
|
+
#set fan off
|
|
969
|
+
code += [self.interface.set_fan_state('M9')]
|
|
934
970
|
|
|
935
971
|
# fill from left to right and reverse
|
|
936
972
|
lefttoright = True
|
|
@@ -965,92 +1001,110 @@ class Compiler:
|
|
|
965
1001
|
lefttoright = not lefttoright
|
|
966
1002
|
|
|
967
1003
|
# turn laser and fan off
|
|
968
|
-
code += [self.interface.laser_off(fan_off = (self.settings["fan"] == FAN_ON or self.settings["fan"] == FAN_ENGRAVE))]
|
|
1004
|
+
#code += [self.interface.laser_off(fan_off = (self.settings["fan"] == FAN_ON or self.settings["fan"] == FAN_ENGRAVE))]
|
|
969
1005
|
code += [f"\n; end {fill_rule} fill '{name_id}'\n"]
|
|
970
1006
|
# append gcode
|
|
971
1007
|
self.body.extend(code)
|
|
972
1008
|
|
|
973
1009
|
# Render 'stroke' attribute
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
#
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
#
|
|
991
|
-
|
|
1010
|
+
steps = []
|
|
1011
|
+
|
|
1012
|
+
# get style info
|
|
1013
|
+
(stroke_width,
|
|
1014
|
+
stroke_color,
|
|
1015
|
+
stroke_alpha,
|
|
1016
|
+
fill_color,
|
|
1017
|
+
fill_alpha,
|
|
1018
|
+
fill_rule,
|
|
1019
|
+
style_pathcut) = get_style_info_of_line_chain(path_curves[name_id][0])
|
|
1020
|
+
|
|
1021
|
+
if (style_pathcut is not None and style_pathcut == 'true') or self.settings["pathcut"]:
|
|
1022
|
+
# cut path
|
|
1023
|
+
self.body.extend([f"\n; cut path (pathcut set) '{name_id}'"])
|
|
1024
|
+
# set laser power and fan when 'on' or 'engrave'
|
|
1025
|
+
for line_chain in path_curves[name_id]:
|
|
1026
|
+
# catternate lines and remove all 'non move' lines.
|
|
1027
|
+
line_chain = straighten_line_chain(line_chain)
|
|
992
1028
|
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1029
|
+
if line_chain.chain_size() == 0:
|
|
1030
|
+
# no lines need no drawing
|
|
1031
|
+
continue
|
|
996
1032
|
render_pathwidth(line_chain, [0], None, None, boundingbox)
|
|
997
|
-
elif stroke_color is not None and len(stroke_color):
|
|
998
|
-
# Get stroke alpha channel (opacity)
|
|
999
|
-
# stroke opacity attribute overrides rgba property
|
|
1000
|
-
if stroke_alpha is None:
|
|
1001
|
-
stroke_alpha = 1
|
|
1002
|
-
rgba = css_color.parse_css_color(stroke_color)
|
|
1003
|
-
if len(rgba) == 4:
|
|
1004
|
-
stroke_alpha = rgba[3]
|
|
1005
1033
|
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1034
|
+
self.body.extend([f"\n; end cut path '{name_id}'\n"])
|
|
1035
|
+
elif stroke_color is not None and len(stroke_color):
|
|
1036
|
+
# Get stroke alpha channel (opacity)
|
|
1037
|
+
# stroke opacity attribute overrides rgba property
|
|
1038
|
+
if stroke_alpha is None:
|
|
1039
|
+
stroke_alpha = 1
|
|
1040
|
+
rgba = css_color.parse_css_color(stroke_color)
|
|
1041
|
+
if len(rgba) == 4:
|
|
1042
|
+
stroke_alpha = rgba[3]
|
|
1043
|
+
|
|
1044
|
+
# engrave values
|
|
1045
|
+
# set inversed b&w value (and apply alpha channel, when available)
|
|
1046
|
+
inverse_bw = round(Image2gcode.linear_power(css_color.parse_css_color2bw8(stroke_color),
|
|
1047
|
+
self.settings["maximum_image_laser_power"]) * stroke_alpha)
|
|
1048
|
+
# set laser head movement speed
|
|
1049
|
+
speed = self.settings["image_movement_speed"]
|
|
1050
|
+
|
|
1051
|
+
# handle option color_coded
|
|
1052
|
+
if self.settings["color_coded"]:
|
|
1053
|
+
# get color_coded info
|
|
1054
|
+
ignorepath, cutpath, engravepath = self.parse_color_coded(stroke_color)
|
|
1055
|
+
|
|
1056
|
+
if not ignorepath:
|
|
1057
|
+
|
|
1058
|
+
if cutpath:
|
|
1059
|
+
# color_coded set cut path for this stroke_color
|
|
1060
|
+
self.body.extend([f"\n; --color_coded cut path '{name_id}' (with stroke color '{stroke_color}')"])
|
|
1061
|
+
for line_chain in path_curves[name_id]:
|
|
1062
|
+
# catternate lines and remove all 'non move' lines.
|
|
1063
|
+
line_chain = straighten_line_chain(line_chain)
|
|
1064
|
+
|
|
1065
|
+
if line_chain.chain_size() == 0:
|
|
1066
|
+
# no lines need no drawing
|
|
1067
|
+
continue
|
|
1023
1068
|
render_pathwidth(line_chain, [0], None, None, boundingbox)
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1069
|
+
self.body.extend([f"\n; end --color_coded: cut path '{name_id}'\n"])
|
|
1070
|
+
elif inverse_bw:
|
|
1071
|
+
if engravepath:
|
|
1072
|
+
|
|
1073
|
+
# Get steps (offsets) for the lines that make the border
|
|
1074
|
+
steps = get_steps(stroke_width, pixel_size)
|
|
1028
1075
|
|
|
1029
|
-
|
|
1030
|
-
|
|
1076
|
+
self.body.extend([f"\n; --color_coded: engrave path '{name_id}' with stroke color '{stroke_color}'"])
|
|
1077
|
+
for line_chain in path_curves[name_id]:
|
|
1078
|
+
# catternate lines and remove all 'non move' lines.
|
|
1079
|
+
line_chain = straighten_line_chain(line_chain)
|
|
1031
1080
|
|
|
1032
|
-
|
|
1081
|
+
if line_chain.chain_size() == 0:
|
|
1082
|
+
# no lines need no drawing
|
|
1083
|
+
continue
|
|
1033
1084
|
render_pathwidth(line_chain, steps, inverse_bw, speed, boundingbox)
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1085
|
+
self.body.extend([f"\n; end --color_coded: engrave path '{name_id}'\n"])
|
|
1086
|
+
else:
|
|
1087
|
+
self.body.extend([f"\n; --color_coded: engrave not set for stroke color '{stroke_color}' of path '{name_id}'"])
|
|
1088
|
+
else:
|
|
1089
|
+
# ignore path
|
|
1090
|
+
self.body.extend([f"\n; --color_coded: ignore path '{name_id}' with stroke color '{stroke_color}'"])
|
|
1091
|
+
|
|
1092
|
+
elif inverse_bw:
|
|
1093
|
+
# Get steps (offsets) for the lines that make the border
|
|
1094
|
+
steps = get_steps(stroke_width, pixel_size)
|
|
1095
|
+
|
|
1096
|
+
# color_coded isn't set: engrave path with stroke color
|
|
1097
|
+
self.body.extend([f"\n; engrave path (default) '{name_id}' with stroke color '{stroke_color}'"])
|
|
1098
|
+
for line_chain in path_curves[name_id]:
|
|
1099
|
+
# catternate lines and remove all 'non move' lines.
|
|
1100
|
+
line_chain = straighten_line_chain(line_chain)
|
|
1101
|
+
|
|
1102
|
+
if line_chain.chain_size() == 0:
|
|
1103
|
+
# no lines need no drawing
|
|
1104
|
+
continue
|
|
1049
1105
|
render_pathwidth(line_chain, steps, inverse_bw, speed, boundingbox)
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
logger.warning(f"cannot engrave path '{name_id}': no stroke color set")
|
|
1056
|
-
self.body.extend([f"\n; cannot engrave path '{name_id}': no stroke color set"])
|
|
1106
|
+
self.body.extend([f"\n; end engrave path '{name_id}'\n"])
|
|
1107
|
+
else:
|
|
1108
|
+
# cannot engrave path (ignore)
|
|
1109
|
+
logger.warning(f"cannot engrave path '{name_id}': no stroke color set")
|
|
1110
|
+
self.body.extend([f"\n; cannot engrave path '{name_id}': no stroke color set"])
|
|
@@ -163,3 +163,11 @@ class Interface:
|
|
|
163
163
|
:return: Appropriate command. If not implemented return ''.
|
|
164
164
|
"""
|
|
165
165
|
pass
|
|
166
|
+
|
|
167
|
+
def set_fan_state(self, fan_state: str) -> str:
|
|
168
|
+
"""
|
|
169
|
+
Optional method, if implemented set fan state to gcode command on or off.
|
|
170
|
+
Only switch for a new state.
|
|
171
|
+
:return: fan_state or ''
|
|
172
|
+
"""
|
|
173
|
+
pass
|
|
@@ -30,6 +30,7 @@ class Gcode(Interface):
|
|
|
30
30
|
self._bounding_box = None
|
|
31
31
|
self._unit = None
|
|
32
32
|
self._machine_params = None
|
|
33
|
+
self._fan_state = "M9" # fan is off
|
|
33
34
|
|
|
34
35
|
# Round outputs to the same number of significant figures as the operational tolerance.
|
|
35
36
|
self.precision = abs(round(math.log(TOLERANCES["operation"], 10)))
|
|
@@ -160,10 +161,21 @@ class Gcode(Interface):
|
|
|
160
161
|
|
|
161
162
|
return command + ''
|
|
162
163
|
|
|
164
|
+
def set_fan_state(self, fan_state: str, force = False) -> str:
|
|
165
|
+
# set fan to a new state or return ''
|
|
166
|
+
if force or (fan_state != '' and self._fan_state != fan_state):
|
|
167
|
+
# new state
|
|
168
|
+
self._fan_state = fan_state
|
|
169
|
+
return "\n" + fan_state
|
|
170
|
+
|
|
171
|
+
# not a new state
|
|
172
|
+
return ''
|
|
173
|
+
|
|
163
174
|
def laser_off(self, fan_off = True):
|
|
164
175
|
self._laser_mode = 'M5'
|
|
165
176
|
self._laser_mode_changed = True
|
|
166
|
-
|
|
177
|
+
new_state = "M9" if self._machine_params['fan'] and fan_off else ''
|
|
178
|
+
new_mode = "M5" + self.set_fan_state(new_state) # laser off, (fan off when available)
|
|
167
179
|
return f"{new_mode}"
|
|
168
180
|
|
|
169
181
|
def set_laser_power(self, power, fan_on = True):
|
|
@@ -183,7 +195,8 @@ class Gcode(Interface):
|
|
|
183
195
|
self._next_laser_power = machine_value
|
|
184
196
|
|
|
185
197
|
# (fan on when available), laser_on
|
|
186
|
-
|
|
198
|
+
new_state = "M8" if self._machine_params['fan'] and fan_on else ''
|
|
199
|
+
new_mode = self.set_fan_state(new_state) + ("\n" + self._laser_mode if self._laser_mode_changed else '')
|
|
187
200
|
self._laser_mode_changed = False
|
|
188
201
|
# return laser mode (M3 constant laser power or M4 dynamic laser power) when laser mode changed
|
|
189
202
|
return f"; F{self._next_speed} {self._unit}/min, power S{machine_value}{new_mode}"
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"""Tree functions"""
|
|
2
|
+
import sys
|
|
2
3
|
import re
|
|
4
|
+
import logging
|
|
3
5
|
|
|
4
6
|
from xml.etree import ElementTree
|
|
5
7
|
from typing import List
|
|
@@ -8,6 +10,10 @@ from copy import deepcopy
|
|
|
8
10
|
from svg2gcode.svg_to_gcode.svg_parser import Path, Transformation
|
|
9
11
|
from svg2gcode.svg_to_gcode.geometry import Curve, RasterImage
|
|
10
12
|
|
|
13
|
+
# Setup logger, add filter to display messages only once.
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
logging.basicConfig(format="[%(levelname)s] %(message)s")
|
|
16
|
+
logger.setLevel(logging.INFO)
|
|
11
17
|
|
|
12
18
|
NAMESPACES = {'svg': 'http://www.w3.org/2000/svg',
|
|
13
19
|
'xlink':'http://www.w3.org/1999/xlink'}
|
|
@@ -227,7 +233,15 @@ def parse_string(svg_string: str, transform_origin=True, viewbox=None, draw_hidd
|
|
|
227
233
|
:pram origin: translate origin to (origin[0],origin[1]), when None set viewbox upper left to (0,0)
|
|
228
234
|
:return: A list of geometric curves describing the svg. Use the Compiler sub-module to compile them to gcode.
|
|
229
235
|
"""
|
|
230
|
-
|
|
236
|
+
try:
|
|
237
|
+
root = ElementTree.fromstring(svg_string)
|
|
238
|
+
except ElementTree.ParseError as e:
|
|
239
|
+
line, column = e.position
|
|
240
|
+
logger.error(f"Parsing - reading interpreting - of the .svg string failed! Error: '{e}'")
|
|
241
|
+
logger.error(f"Location the error: line {line}, column {column}")
|
|
242
|
+
logger.error(f"Exiting ...")
|
|
243
|
+
sys.exit(1)
|
|
244
|
+
|
|
231
245
|
addParentInfo(root)
|
|
232
246
|
return parse_root(root, transform_origin, viewbox, draw_hidden, origin=delta_origin, scale=scale_factor, rotate=rotate_deg)
|
|
233
247
|
|
|
@@ -246,6 +260,17 @@ def parse_file(file_path: str, transform_origin=True, viewbox=None, draw_hidden=
|
|
|
246
260
|
:param origin: translate origin to (origin[0],origin[1]), when None set viewbox upper left to (0,0)
|
|
247
261
|
:return: A list of geometric curves describing the svg. Use the Compiler sub-module to compile them to gcode.
|
|
248
262
|
"""
|
|
249
|
-
|
|
263
|
+
|
|
264
|
+
try:
|
|
265
|
+
root = ElementTree.parse(file_path).getroot()
|
|
266
|
+
except ElementTree.ParseError as e:
|
|
267
|
+
line, column = e.position
|
|
268
|
+
logger.error(f"Parsing - reading interpreting - of the .svg file '{file_path}' failed! Error: '{e}'")
|
|
269
|
+
logger.error(f"Location the error: line {line}, column {column}")
|
|
270
|
+
logger.error(f"Exiting ...")
|
|
271
|
+
sys.exit(1)
|
|
272
|
+
|
|
250
273
|
addParentInfo(root)
|
|
251
274
|
return parse_root(root, transform_origin, viewbox, draw_hidden, origin=delta_origin, scale=scale_factor, rotate=rotate_deg)
|
|
275
|
+
|
|
276
|
+
#return parse_root(root, transform_origin, viewbox, draw_hidden, origin=delta_origin, scale=scale_factor, rotate=rotate_deg)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|