1616from ..svg import PIXELS_PER_MM , generate_unique_id , get_correction_transform
1717from ..svg .tags import INKSCAPE_LABEL , INKSTITCH_ATTRIBS
1818from ..utils .threading import check_stop_flag
19- from .utils .autoroute import (add_elements_to_group , add_jumps ,
20- create_new_group , find_path ,
19+ from .utils .autoroute import (add_elements_to_group , add_jumps , find_path ,
2120 get_starting_and_ending_nodes ,
2221 preserve_original_groups ,
2322 remove_original_elements )
@@ -119,7 +118,7 @@ def _get_segments(self):
119118 self .segments .append ([seg , self ._elements [i ]])
120119
121120
122- def autorun (elements , preserve_order = False , break_up = None , starting_point = None , ending_point = None , trim = False ):
121+ def autorun (elements , preserve_order = False , break_up = None , starting_point = None , ending_point = None , trim = False , group = None ):
123122 graph = build_graph (elements , preserve_order , break_up )
124123
125124 graph = add_jumps (graph , elements , preserve_order )
@@ -130,14 +129,11 @@ def autorun(elements, preserve_order=False, break_up=None, starting_point=None,
130129 path = find_path (graph , starting_point , ending_point )
131130 path = add_path_attribs (path )
132131
133- new_elements , trims , original_parents = path_to_elements (graph , path , trim )
132+ new_elements , trims , original_parents = path_to_elements (graph , path , trim , group )
134133
135134 if preserve_order :
136135 preserve_original_groups (new_elements , original_parents , transform = False )
137136 else :
138- parent = elements [0 ].node .getparent ()
139- insert_index = parent .index (elements [0 ].node )
140- group = create_new_group (parent , insert_index , _ ("Auto-Route" ), False )
141137 add_elements_to_group (new_elements , group )
142138
143139 if trim :
@@ -195,7 +191,7 @@ def add_path_attribs(path):
195191 return path
196192
197193
198- def path_to_elements (graph , path , trim ): # noqa: C901
194+ def path_to_elements (graph , path , trim , parent = None ): # noqa: C901
199195 element_list = []
200196 original_parents = []
201197 trims = []
@@ -217,7 +213,7 @@ def path_to_elements(graph, path, trim): # noqa: C901
217213 end_coord = graph .nodes [end ]['point' ]
218214 # create a new element if we hit an other original element to keep it's properties
219215 if el and element and el != element and d and not direction == 'underpath' :
220- element_list .append (create_element (d , position , path_direction , el ))
216+ element_list .append (create_element (d , position , path_direction , el , parent ))
221217 original_parents .append (el .node .getparent ())
222218 d = ""
223219 position += 1
@@ -234,7 +230,7 @@ def path_to_elements(graph, path, trim): # noqa: C901
234230 # create a new element if direction (purpose) changes
235231 if direction != path_direction :
236232 if d :
237- element_list .append (create_element (d , position , path_direction , el ))
233+ element_list .append (create_element (d , position , path_direction , el , parent ))
238234 original_parents .append (el .node .getparent ())
239235 d = ""
240236 position += 1
@@ -246,7 +242,7 @@ def path_to_elements(graph, path, trim): # noqa: C901
246242 d += f", { end_coord .x } { end_coord .y } "
247243 elif el and d :
248244 # this is a jump, so complete the element whose path we've been building
249- element_list .append (create_element (d , position , path_direction , el ))
245+ element_list .append (create_element (d , position , path_direction , el , parent ))
250246 original_parents .append (el .node .getparent ())
251247 d = ""
252248
@@ -257,17 +253,19 @@ def path_to_elements(graph, path, trim): # noqa: C901
257253 position += 1
258254
259255 if d :
260- element_list .append (create_element (d , position , path_direction , el ))
256+ element_list .append (create_element (d , position , path_direction , el , parent ))
261257 original_parents .append (el .node .getparent ())
262258
263259 return element_list , trims , original_parents
264260
265261
266- def create_element (path , position , direction , element ):
262+ def create_element (path , position , direction , element , parent = None ): # noqa: C901
267263 if not path :
268264 return
269265
270266 el_id = f"{ direction } _{ position } _"
267+ if parent is None :
268+ parent = element .node .getparent ()
271269
272270 index = position + 1
273271 if direction == "autorun" :
@@ -276,7 +274,7 @@ def create_element(path, position, direction, element):
276274 path_type = 'autorun-top'
277275 else :
278276 label = _ ("AutoRun Underpath %d" ) % index
279- dasharray = '2 1.1 '
277+ dasharray = '3 0.5 '
280278 path_type = 'autorun-underpath'
281279
282280 node = inkex .PathElement ()
@@ -287,13 +285,14 @@ def create_element(path, position, direction, element):
287285 node .set ("style" , element .node .style )
288286 node .style ["fill" ] = 'none'
289287 node .style ["stroke-dasharray" ] = dasharray
290- node .transform = get_correction_transform (element . node . getparent () , child = True )
288+ node .transform = get_correction_transform (parent , child = True )
291289 node .apply_transform ()
292290
293291 # Set Ink/Stitch attributes
294292 stitch_length = element .node .get (INKSTITCH_ATTRIBS ['running_stitch_length_mm' ], '' )
295293 tolerance = element .node .get (INKSTITCH_ATTRIBS ['running_stitch_tolerance_mm' ], '' )
296294 repeats = int (element .node .get (INKSTITCH_ATTRIBS ['repeats' ], 1 ))
295+ stroke_method = element .node .get ('inkstitch:stroke_method' , '' )
297296 if repeats % 2 == 0 :
298297 repeats -= 1
299298
@@ -309,6 +308,8 @@ def create_element(path, position, direction, element):
309308 node .set (INKSTITCH_ATTRIBS ['running_stitch_length_mm' ], stitch_length )
310309 if tolerance :
311310 node .set (INKSTITCH_ATTRIBS ['running_stitch_tolerance_mm' ], tolerance )
311+ if stroke_method == 'manual_stitch' :
312+ node .set ('inkstitch:stroke_method' , stroke_method )
312313 return Stroke (node )
313314
314315
0 commit comments