Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions lib/extensions/remove_embroidery_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ def remove_print_settings(self):
self.remove_element(print_setting)

def remove_params(self):
if not self.svg.selection:
xpath = ".//svg:path|.//svg:circle|.//svg:rect|.//svg:ellipse"
elements = find_elements(self.svg, xpath)
self.remove_inkstitch_attributes(elements)
else:
elements = self.get_selected_elements()
self.remove_inkstitch_attributes(elements)
elements = self.get_elements()
self.remove_inkstitch_attributes(elements, self.options.del_params)

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

def remove_selected_commands(self):
del_option = self.options.del_commands
elements = self.get_selected_elements()
def remove_commands_from_selection(self, elements, del_option):
for element in elements:
if is_command_symbol(element) and (del_option in element.get('xlink:href') or del_option == 'all'):
group = element.getparent()
Expand All @@ -94,15 +87,28 @@ def remove_selected_commands(self):
group.delete()

def remove_commands(self):
elements = self.get_elements()
del_option = self.options.del_commands

# trim and stop params are percepted as commands,
# so let's remove them as well
if del_option in ['all', 'trim']:
self.remove_inkstitch_attributes(elements, 'trim_after')
elif del_option in ['all', 'stop']:
self.remove_inkstitch_attributes(elements, 'stop_after')

if self.svg.selection:
self.remove_selected_commands()
self.remove_commands_from_selection(elements, del_option)
elif self.options.del_commands == "all":
self.remove_all_commands()
else:
self.remove_specific_commands(self.options.del_commands)

def get_selected_elements(self):
return self.svg.selection.get(ShapeElement)
def get_elements(self):
if self.svg.selection:
return self.svg.selection.get(ShapeElement)
else:
return self.svg.descendants().filter(ShapeElement)

def remove_elements(self, xpath):
elements = find_elements(self.svg, xpath)
Expand All @@ -112,8 +118,7 @@ def remove_elements(self, xpath):
def remove_element(self, element):
element.delete()

def remove_inkstitch_attributes(self, elements):
param_to_remove = self.options.del_params
def remove_inkstitch_attributes(self, elements, param_to_remove):
for element in elements:
for attrib in element.attrib:
if attrib.startswith(NSS['inkstitch'], 1):
Expand Down
8 changes: 4 additions & 4 deletions templates/break_apart.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
</param>
</page>
<page name="info" gui-text="Help">
<label>
This extension will try to repair fill shapes and break them apart if necessary.
Holes will be retained. Use on simple or overlapping shapes.
</label>
<label>This extension will try to repair fill shapes and break them apart if necessary.</label>
<label>Holes will be retained.</label>
<spacer />
<label>Use on simple or complex shapes with overlapping subpaths.</label>
<spacer />
<label>More information on our website</label>
<label appearance="url">https://inkstitch.org/docs/fill-tools/#break-apart-fill-objects</label>
Expand Down
Loading