From 34f70c9aece2bbcbbd9b52e039af266741707b5f Mon Sep 17 00:00:00 2001 From: Howard DaCosta Date: Wed, 17 Nov 2021 20:48:48 -0500 Subject: [PATCH] scrap code for combining grids, will fix when design is fleshed out more --- combine_grids.py | 74 +++++++++++++++++++++++++++++++++++++---------- combine_grids.xml | 7 +++++ 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/combine_grids.py b/combine_grids.py index 88f2771..bbfef8d 100644 --- a/combine_grids.py +++ b/combine_grids.py @@ -1,41 +1,83 @@ from .base import InkstitchExtension -import json -import os import sys from base64 import b64decode from argparse import ArgumentParser, REMAINDER import appdirs import inkex -from inkex import Line, Rectangle, Path +from inkex import Line, Rectangle, Path, Polyline, PathElement import wx import wx.adv from lxml import etree -from ..elements import nodes_to_elements -from ..gui import PresetsPanel, SimulatorPreview, info_dialog -from ..i18n import _ -from ..lettering import Font, FontError -from ..svg import get_correction_transform -from ..svg.tags import (INKSCAPE_LABEL, INKSTITCH_LETTERING, SVG_GROUP_TAG, - SVG_PATH_TAG) -from ..utils import DotDict, cache, get_bundled_dir, get_resource_dir -from .commands import CommandsExtension -from .lettering_custom_font_dir import get_custom_font_dir +from .create_grid import BoundingBoxMetadata +class CombineGridsFrame(wx.Frame): + DEFAULT_FONT = "small_font" + def __init__(self, shape1, shape2, svg, *args, **kwargs): + if sys.platform.startswith('win32'): + import locale + locale.setlocale(locale.LC_ALL, "C") + lc = wx.Locale() + lc.Init(wx.LANGUAGE_DEFAULT) + pass + class CombineGrids(InkstitchExtension): COMMANDS = ["combine_grids"] def __init__(self, *args, **kwargs): self.cancelled = False InkstitchExtension.__init__(self, *args, **kwargs) - for command in self.COMMANDS: - self.arg_parser.add_argument("--%s" % command, type=inkex.Boolean) + self.arg_parser.add_argument("--alignment") + args, _ = self.arg_parser.parse_known_args() + inkex.errormsg("args:{}".format(args.alignment)) + self.is_horizontal_connection = True if args.alignment == 1 else False + self.wires = [] + self.wire_rectangles = [] def cancel(self): self.cancelled = True + def connect_horizontally(self): + rect1, rect2 = self.wire_rectangles + if not rect1.is_horizontally_aligned(rect2): + inkex.errormsg("Unable to horizontally connect the two objects.") + return + leftmost_rectangle = None + letmost_wire = None + other_rectangle = None + other_wire = None + if rect1.left < rect2.left: + leftmost_rectangle = rect1 + letmost_wire = self.wires[0] + other_rectangle = rect2 + other_wire = self.wires[1] + else: + leftmost_rectangle = rect2 + letmost_wire = self.wires[1] + other_rectangle = rect1 + other_wire = self.wires[0] + + def effect(self): - pass + for elem in self.svg.get_selected(): + # inkex.errormsg("things selected:{}".format(len(self.svg.get_selected()))) + inkex.errormsg("type of elem:{}".format(type(elem))) + # have to separate shapes and wires here! + wire_points = [p for p in elem.path.end_points] + if type(elem) == Polyline: + self.wires.append(wire_points) + self.wire_rectangles.append(elem.bounding_box()) + if len(self.wires) != 2: + inkex.errormsg("Please select only two wires to combine!") + return + if self.is_horizontal_connection: + + + + + + + if __name__ == '__main__': diff --git a/combine_grids.xml b/combine_grids.xml index 4a7be1e..0aba2eb 100644 --- a/combine_grids.xml +++ b/combine_grids.xml @@ -11,6 +11,13 @@ + + This extension will try to combine wires together. + + + + +