Skip to content

Commit 9d2bd50

Browse files
authored
remove command param along with commands (trim and stop) (#4074)
1 parent a927cc1 commit 9d2bd50

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

lib/extensions/remove_embroidery_settings.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,8 @@ def remove_print_settings(self):
3636
self.remove_element(print_setting)
3737

3838
def remove_params(self):
39-
if not self.svg.selection:
40-
xpath = ".//svg:path|.//svg:circle|.//svg:rect|.//svg:ellipse"
41-
elements = find_elements(self.svg, xpath)
42-
self.remove_inkstitch_attributes(elements)
43-
else:
44-
elements = self.get_selected_elements()
45-
self.remove_inkstitch_attributes(elements)
39+
elements = self.get_elements()
40+
self.remove_inkstitch_attributes(elements, self.options.del_params)
4641

4742
def remove_all_commands(self):
4843
xpath = ".//svg:g[starts-with(@id,'command_group')]"
@@ -76,9 +71,7 @@ def remove_specific_commands(self, command):
7671
symbols = f".//*[starts-with(@id, 'inkstitch_{command}')]"
7772
self.remove_elements(symbols)
7873

79-
def remove_selected_commands(self):
80-
del_option = self.options.del_commands
81-
elements = self.get_selected_elements()
74+
def remove_commands_from_selection(self, elements, del_option):
8275
for element in elements:
8376
if is_command_symbol(element) and (del_option in element.get('xlink:href') or del_option == 'all'):
8477
group = element.getparent()
@@ -94,15 +87,28 @@ def remove_selected_commands(self):
9487
group.delete()
9588

9689
def remove_commands(self):
90+
elements = self.get_elements()
91+
del_option = self.options.del_commands
92+
93+
# trim and stop params are percepted as commands,
94+
# so let's remove them as well
95+
if del_option in ['all', 'trim']:
96+
self.remove_inkstitch_attributes(elements, 'trim_after')
97+
elif del_option in ['all', 'stop']:
98+
self.remove_inkstitch_attributes(elements, 'stop_after')
99+
97100
if self.svg.selection:
98-
self.remove_selected_commands()
101+
self.remove_commands_from_selection(elements, del_option)
99102
elif self.options.del_commands == "all":
100103
self.remove_all_commands()
101104
else:
102105
self.remove_specific_commands(self.options.del_commands)
103106

104-
def get_selected_elements(self):
105-
return self.svg.selection.get(ShapeElement)
107+
def get_elements(self):
108+
if self.svg.selection:
109+
return self.svg.selection.get(ShapeElement)
110+
else:
111+
return self.svg.descendants().filter(ShapeElement)
106112

107113
def remove_elements(self, xpath):
108114
elements = find_elements(self.svg, xpath)
@@ -112,8 +118,7 @@ def remove_elements(self, xpath):
112118
def remove_element(self, element):
113119
element.delete()
114120

115-
def remove_inkstitch_attributes(self, elements):
116-
param_to_remove = self.options.del_params
121+
def remove_inkstitch_attributes(self, elements, param_to_remove):
117122
for element in elements:
118123
for attrib in element.attrib:
119124
if attrib.startswith(NSS['inkstitch'], 1):

templates/break_apart.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
</param>
1313
</page>
1414
<page name="info" gui-text="Help">
15-
<label>
16-
This extension will try to repair fill shapes and break them apart if necessary.
17-
Holes will be retained. Use on simple or overlapping shapes.
18-
</label>
15+
<label>This extension will try to repair fill shapes and break them apart if necessary.</label>
16+
<label>Holes will be retained.</label>
17+
<spacer />
18+
<label>Use on simple or complex shapes with overlapping subpaths.</label>
1919
<spacer />
2020
<label>More information on our website</label>
2121
<label appearance="url">https://inkstitch.org/docs/fill-tools/#break-apart-fill-objects</label>

0 commit comments

Comments
 (0)