svg2gcode 2.0.0__tar.gz → 2.1.0__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.
Files changed (34) hide show
  1. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/PKG-INFO +3 -1
  2. {svg2gcode-2.0.0/svg2gcode → svg2gcode-2.1.0}/README.md +2 -0
  3. {svg2gcode-2.0.0 → svg2gcode-2.1.0/svg2gcode}/README.md +2 -0
  4. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/__init__.py +1 -1
  5. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/__main__.py +3 -1
  6. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/svg_parser/_parser_methods.py +47 -32
  7. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/LICENSE +0 -0
  8. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/pyproject.toml +0 -0
  9. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/.DS_Store +0 -0
  10. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/__init__.py +0 -0
  11. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/compiler/__init__.py +0 -0
  12. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/compiler/_compiler.py +0 -0
  13. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/compiler/interfaces/__init__.py +0 -0
  14. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/compiler/interfaces/_abstract_interface.py +0 -0
  15. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/compiler/interfaces/_fan_controlled_gcode.py +0 -0
  16. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/compiler/interfaces/_gcode.py +0 -0
  17. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/formulas.py +0 -0
  18. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/__init__.py +0 -0
  19. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/_abstract_chain.py +0 -0
  20. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/_abstract_curve.py +0 -0
  21. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/_circular_arc.py +0 -0
  22. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/_cubic_bazier.py +0 -0
  23. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/_elliptical_arc.py +0 -0
  24. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/_line.py +0 -0
  25. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/_line_segment_chain.py +0 -0
  26. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/_matrix.py +0 -0
  27. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/_quadratic_bazier.py +0 -0
  28. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/_raster_image.py +0 -0
  29. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/_smooth_arc_chain.py +0 -0
  30. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/geometry/_vector.py +0 -0
  31. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/svg_parser/__init__.py +0 -0
  32. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/svg_parser/_path.py +0 -0
  33. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/svg_parser/_transformation.py +0 -0
  34. {svg2gcode-2.0.0 → svg2gcode-2.1.0}/svg2gcode/svg_to_gcode/svg_parser/debug_methods.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: svg2gcode
3
- Version: 2.0.0
3
+ Version: 2.1.0
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>
@@ -84,6 +84,8 @@ options:
84
84
  (default), 0 is no G0 moves
85
85
  --noise <default:0> reduces image noise by not emitting pixels with power lower or equal than this setting
86
86
  --constantburn use constant burn mode M3 (a bit more dangerous!), instead of dynamic burn mode M4
87
+ --origin Xdelta Ydelta
88
+ translate origin by (Xdelta,Ydelta) (default not set)
87
89
  --xmaxtravel <default:300>
88
90
  machine x-axis lengh in mm
89
91
  --ymaxtravel <default:400>
@@ -71,6 +71,8 @@ options:
71
71
  (default), 0 is no G0 moves
72
72
  --noise <default:0> reduces image noise by not emitting pixels with power lower or equal than this setting
73
73
  --constantburn use constant burn mode M3 (a bit more dangerous!), instead of dynamic burn mode M4
74
+ --origin Xdelta Ydelta
75
+ translate origin by (Xdelta,Ydelta) (default not set)
74
76
  --xmaxtravel <default:300>
75
77
  machine x-axis lengh in mm
76
78
  --ymaxtravel <default:400>
@@ -71,6 +71,8 @@ options:
71
71
  (default), 0 is no G0 moves
72
72
  --noise <default:0> reduces image noise by not emitting pixels with power lower or equal than this setting
73
73
  --constantburn use constant burn mode M3 (a bit more dangerous!), instead of dynamic burn mode M4
74
+ --origin Xdelta Ydelta
75
+ translate origin by (Xdelta,Ydelta) (default not set)
74
76
  --xmaxtravel <default:300>
75
77
  machine x-axis lengh in mm
76
78
  --ymaxtravel <default:400>
@@ -1,4 +1,4 @@
1
1
  """
2
2
  svg2gcode: convert an SVG (Scalable Vector Graphic) image to gcode.
3
3
  """
4
- __version__ = "2.0.0"
4
+ __version__ = "2.1.0"
@@ -26,7 +26,7 @@ def svg2gcode(args) -> int:
26
26
  'showimage':args.showimage, 'x_axis_maximum_travel':args.xmaxtravel,'y_axis_maximum_travel':args.ymaxtravel, 'image_noise':args.noise,
27
27
  'laser_mode':"constant" if args.constantburn else "dynamic" })
28
28
  # emit gcode for svg
29
- gcode_compiler.compile_to_file(args.gcode, parse_file(args.svg), passes=1)
29
+ gcode_compiler.compile_to_file(args.gcode, parse_file(args.svg, delta_origin=args.origin), passes=1)
30
30
 
31
31
  except Exception as error:
32
32
  print(error)
@@ -69,6 +69,8 @@ def main() -> int:
69
69
  parser.add_argument('--noise', default=noise_default, metavar="<default:" +str(noise_default)+ ">",
70
70
  type=int, help='reduces image noise by not emitting pixels with power lower or equal than this setting')
71
71
  parser.add_argument('--constantburn', action='store_true', default=False, help='use constant burn mode M3 (a bit more dangerous!), instead of dynamic burn mode M4')
72
+ parser.add_argument('--origin', default=None, nargs=2, metavar=('Xdelta', 'Ydelta'),
73
+ type=float, help="translate origin by (Xdelta,Ydelta) (default not set)")
72
74
  parser.add_argument('--xmaxtravel', default=xmaxtravel_default, metavar="<default:" +str(xmaxtravel_default)+ ">",
73
75
  type=int, help="machine x-axis lengh in mm")
74
76
  parser.add_argument('--ymaxtravel', default=ymaxtravel_default, metavar="<default:" +str(ymaxtravel_default)+ ">",
@@ -19,7 +19,7 @@ def _has_style(element: ElementTree.Element, key: str, value: str) -> bool:
19
19
  return element.get(key) == value or (element.get("style") and f"{key}:{value}" in element.get("style"))
20
20
 
21
21
 
22
- def add_viewbox_transformation(transformation: Transformation, transform_origin, vwbox):
22
+ def add_viewbox_transformation(transformation: Transformation, transform_origin, vwbox, origin):
23
23
  """
24
24
  Transform SVG coordinate system to a math-cartesion coordinate system and correct its origin.
25
25
  When viewBox is missing the 'height' value of the viewport is used.
@@ -50,16 +50,28 @@ def add_viewbox_transformation(transformation: Transformation, transform_origin,
50
50
  # viewBox "width" and "height" represent the dimensions of the 'svg'
51
51
  # (a rectangle - left upper at (vwbox['x'],vwbox['y']) - in user space)
52
52
 
53
+ # Set origin back at viewbox position after flip updown and add
54
+ # the user specified origin.
55
+ # When no user origin is specified, this translation is skipped,
56
+ # which effectively places the viewbox lower left (mind you after
57
+ # flipupdown) at (0,0) (so the canvas has positive coordinates only).
58
+
59
+ # (transformations are in reverse order see 'Note' below)
60
+ if origin is not None and ((vwbox["x"] + origin[0]) or (vwbox["y"] + origin[1])):
61
+ up_transformation.add_translation(vwbox["x"] + origin[0],vwbox["y"] + origin[1])
62
+
53
63
  # Note: If A and B are the matrices of two linear transformations, then the effect of first applying A and then B
54
64
  # to a column vector x is given by B(Ax) == (BA)x
55
65
  # So, in the below case, transformation order is 'scale' first and 'translation' second.
66
+
67
+ # this effectively does a flip updown to set a carthesian coordinate system (origin at bottom left) gcode uses
56
68
  up_transformation.add_translation(0, vwbox["height"]) # Translation
57
69
  up_transformation.add_scale(1, -1) # T * Scale
58
70
  # applying it to a vector: # T * S * Vector(x,y)
59
71
 
60
72
  # viewBox "x" and "y" represent the upper left corner of the document.
61
- # when non zero, the upper left corner should be corrected to (0,0)
62
- # (a laser or CNC machine has a positive workarea only, which should be as large as possible)
73
+ # when non zero, the upper left corner should be corrected to (0,0) for
74
+ # the above flip updown to work correctly
63
75
  if vwbox["x"] or vwbox["y"]:
64
76
  up_transformation.add_translation(-vwbox["x"],-vwbox["y"])
65
77
 
@@ -97,7 +109,7 @@ def get_viewBox(root: ElementTree.Element) -> {}:
97
109
 
98
110
 
99
111
  def parse_root(root: ElementTree.Element, transform_origin=True, viewbox=None, draw_hidden=False,
100
- visible_root=True, root_transformation=None) -> List[Curve]:
112
+ visible_root=True, root_transformation=None, origin=None) -> List[Curve]:
101
113
 
102
114
  """
103
115
  Recursively parse an etree root's children into geometric curves.
@@ -109,6 +121,7 @@ def parse_root(root: ElementTree.Element, transform_origin=True, viewbox=None, d
109
121
  :param transform_origin: Whether or not to transform input coordinates from the svg coordinate system to standard
110
122
  cartesian system. Depends on viewBox height for calculations.
111
123
  :param draw_hidden: Whether or not to draw hidden elements based on their display, visibility and opacity attributes.
124
+ :param origin: translate origin to (origin[0],origin[1]); when None set viewbox upper left to (0,0)
112
125
  :param visible_root: Specifies whether or the root is visible. (Inheritance can be overridden)
113
126
  :param root_transformation: Specifies whether the root's transformation. (Transformations are inheritable)
114
127
  :return: A list of geometric curves describing the svg. Use the Compiler sub-module to compile them to gcode.
@@ -153,7 +166,7 @@ def parse_root(root: ElementTree.Element, transform_origin=True, viewbox=None, d
153
166
  if draw_hidden or visible:
154
167
  if element.tag == "{%s}path" % NAMESPACES["svg"]:
155
168
  path = Path(element.attrib['d'],
156
- add_viewbox_transformation(transformation, transform_origin, viewbox))
169
+ add_viewbox_transformation(transformation, transform_origin, viewbox, origin))
157
170
  curves.extend(path.curves)
158
171
  else:
159
172
  if element.tag == "{%s}image" % NAMESPACES["svg"]:
@@ -161,45 +174,47 @@ def parse_root(root: ElementTree.Element, transform_origin=True, viewbox=None, d
161
174
 
162
175
  # instantiate curve (image)
163
176
  ri = RasterImage(element.attrib, element.attrib["{%s}href" % NAMESPACES["xlink"]],
164
- add_viewbox_transformation(transformation, transform_origin, viewbox))
177
+ add_viewbox_transformation(transformation, transform_origin, viewbox, origin))
165
178
  curves.append(ri)
166
179
 
167
180
  # Continue the recursion
168
- curves.extend(parse_root(element, transform_origin, viewbox, draw_hidden, visible, transformation))
181
+ curves.extend(parse_root(element, transform_origin, viewbox, draw_hidden, visible, transformation, origin))
169
182
 
170
183
  # ToDo implement shapes class
171
184
  return curves
172
185
 
173
186
 
174
- def parse_string(svg_string: str, transform_origin=True, viewbox=None, draw_hidden=False) -> List[Curve]:
187
+ def parse_string(svg_string: str, transform_origin=True, viewbox=None, draw_hidden=False, delta_origin=None) -> List[Curve]:
175
188
  """
176
- Recursively parse an svg string into geometric curves. (Wrapper for parse_root)
177
-
178
- :param svg_string: The etree element who's children should be recursively parsed. The root will not be drawn.
179
- :param viewbox: ViewBox of the SVG, used to transform it to a math-cartesion coordinate system and
180
- correct its origin. When the viewBox is missing the viewport (of the root) is used. If the root
181
- does not contain a viewBox or viewport, it must be either manually specified or transform must be False.
182
- :param transform_origin: Whether or not to transform input coordinates from the svg coordinate system to standard cartesian
183
- system. Depends on canvas_height for calculations.
184
- :param draw_hidden: Whether or not to draw hidden elements based on their display, visibility and opacity attributes.
185
- :return: A list of geometric curves describing the svg. Use the Compiler sub-module to compile them to gcode.
189
+ Recursively parse an svg string into geometric curves. (Wrapper for parse_root)
190
+
191
+ :param svg_string: The etree element who's children should be recursively parsed. The root will not be drawn.
192
+ :param viewbox: ViewBox of the SVG, used to transform it to a math-cartesion coordinate system and
193
+ correct its origin. When the viewBox is missing the viewport (of the root) is used. If the root
194
+ does not contain a viewBox or viewport, it must be either manually specified or transform must be False.
195
+ :param transform_origin: Whether or not to transform input coordinates from the svg coordinate system to standard cartesian
196
+ system. Depends on canvas_height for calculations.
197
+ :param draw_hidden: Whether or not to draw hidden elements based on their display, visibility and opacity attributes.
198
+ :pram origin: translate origin to (origin[0],origin[1]), when None set viewbox upper left to (0,0)
199
+ :return: A list of geometric curves describing the svg. Use the Compiler sub-module to compile them to gcode.
186
200
  """
187
201
  root = ElementTree.fromstring(svg_string)
188
- return parse_root(root, transform_origin, viewbox, draw_hidden)
202
+ return parse_root(root, transform_origin, viewbox, draw_hidden, origin=delta_origin)
203
+
189
204
 
205
+ def parse_file(file_path: str, transform_origin=True, viewbox=None, draw_hidden=False, delta_origin=None) -> List[Curve]:
206
+ """
207
+ Recursively parse an svg file into geometric curves. (Wrapper for parse_root)
190
208
 
191
- def parse_file(file_path: str, transform_origin=True, viewbox=None, draw_hidden=False) -> List[Curve]:
209
+ :param file_path: The etree element who's children should be recursively parsed. The root will not be drawn.
210
+ :param viewbox: ViewBox of the SVG, used to transform it to a math-cartesion coordinate system and
211
+ correct its origin. When the viewBox is missing the viewport (of the root) is used. If the root
212
+ does not contain a viewBox or viewport, it must be either manually specified or transform must be False.
213
+ :param transform_origin: Whether or not to transform input coordinates from the svg coordinate system to standard cartesian
214
+ system. Depends on canvas_height for calculations.
215
+ :param draw_hidden: Whether or not to draw hidden elements based on their display, visibility and opacity attributes.
216
+ :param origin: translate origin to (origin[0],origin[1]), when None set viewbox upper left to (0,0)
217
+ :return: A list of geometric curves describing the svg. Use the Compiler sub-module to compile them to gcode.
192
218
  """
193
- Recursively parse an svg file into geometric curves. (Wrapper for parse_root)
194
-
195
- :param file_path: The etree element who's children should be recursively parsed. The root will not be drawn.
196
- :param viewbox: ViewBox of the SVG, used to transform it to a math-cartesion coordinate system and
197
- correct its origin. When the viewBox is missing the viewport (of the root) is used. If the root
198
- does not contain a viewBox or viewport, it must be either manually specified or transform must be False.
199
- :param transform_origin: Whether or not to transform input coordinates from the svg coordinate system to standard cartesian
200
- system. Depends on canvas_height for calculations.
201
- :param draw_hidden: Whether or not to draw hidden elements based on their display, visibility and opacity attributes.
202
- :return: A list of geometric curves describing the svg. Use the Compiler sub-module to compile them to gcode.
203
- """
204
219
  root = ElementTree.parse(file_path).getroot()
205
- return parse_root(root, transform_origin, viewbox, draw_hidden)
220
+ return parse_root(root, transform_origin, viewbox, draw_hidden, origin=delta_origin)
File without changes
File without changes