diff options
| author | capellancitizen <thecapellancitizen@gmail.com> | 2024-08-20 23:18:13 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-20 23:18:13 -0400 |
| commit | 07f98b0a9b0e5315a2bc83bfa8ab8b6dbd9eaf2b (patch) | |
| tree | 9f9432900e338e2740c83a3cbf54ffdd720c5ff6 /lib | |
| parent | 7cf952dce27173c918340a839694802f332ae26a (diff) | |
Fixed transforms on cloned commands (#3160)
Also, point-upwards now applied to commands that are children
of cloned elements.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/commands.py | 27 | ||||
| -rw-r--r-- | lib/elements/clone.py | 5 |
2 files changed, 24 insertions, 8 deletions
diff --git a/lib/commands.py b/lib/commands.py index 9a352cfe..83798f10 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -155,13 +155,14 @@ class Command(BaseCommand): def clone(self, new_target: inkex.BaseElement) -> inkex.BaseElement: """ - Clone this command and point it to the new target, positioning it relative to the new target the same as the target + Clone this command and point it to the new target, positioning it relative to the new target the same as the target """ - relative_transform = new_target.composed_transform() @ -self.target.composed_transform() + group: inkex.BaseElement = self.connector.getparent() + transform_relative_to_target = -self.target.composed_transform() @ group.composed_transform() # Clone group cloned_group = copy_no_children(self.connector.getparent()) - cloned_group.transform = relative_transform @ cloned_group.transform + cloned_group.transform = new_target.transform @ transform_relative_to_target new_target.getparent().append(cloned_group) symbol = copy_no_children(self.use) @@ -170,7 +171,7 @@ class Command(BaseCommand): # Copy connector connector = copy_no_children(self.connector) - cloned_group.append(connector) + cloned_group.insert(0, connector) if self.symbol_is_end: symbol_attr = CONNECTION_END target_attr = CONNECTION_START @@ -208,15 +209,27 @@ class StandaloneCommand(BaseCommand): return Point(*pos) -def get_command_description(command: str): +def get_command_description(command: str) -> str: return COMMANDS[command] -def find_commands(node: BaseCommand) -> List[Command]: +def point_command_symbols_up(node: inkex.BaseElement) -> None: + """ + Find all command symbols in the subtree and alter their transformations so they're pointing upwards. + """ + xpath = ".//svg:use" + uses = node.xpath(xpath, namespaces=inkex.NSS) + for use in uses: + if use.href.get('id').startswith('inkstitch_'): + point_upwards(use) + + +def find_commands(node: inkex.BaseElement) -> List[Command]: """Find the symbols this node is connected to and return them as Commands""" # find all paths that have this object as a connection - xpath = ".//*[@inkscape:connection-start='#%(id)s' or @inkscape:connection-end='#%(id)s']" % dict(id=node.get('id')) + id = node.get('id') + xpath = f".//*[@inkscape:connection-start='#{id}' or @inkscape:connection-end='#{id}']" connectors = node.getroottree().getroot().xpath(xpath, namespaces=inkex.NSS) # try to turn them into commands diff --git a/lib/elements/clone.py b/lib/elements/clone.py index 91c69740..ce9c2162 100644 --- a/lib/elements/clone.py +++ b/lib/elements/clone.py @@ -12,7 +12,7 @@ from shapely import MultiLineString from ..stitch_plan.stitch_group import StitchGroup -from ..commands import is_command_symbol, find_commands +from ..commands import is_command_symbol, find_commands, point_command_symbols_up from ..i18n import _ from ..svg.svg import copy_no_children from ..svg.path import get_node_transform @@ -163,6 +163,9 @@ class Clone(EmbroideryElement): ret = [cloned_node] + # For aesthetic purposes, transform allof the cloned command symbols so they're facing upwards + point_command_symbols_up(cloned_node) + # We need to copy all commands that were attached directly to the href'd node for command in find_commands(source_node): ret.append(command.clone(cloned_node)) |
