diff options
| -rw-r--r-- | lib/extensions/__init__.py | 80 | ||||
| -rw-r--r-- | lib/extensions/test_swatches.py | 55 | ||||
| -rw-r--r-- | lib/svg/tags.py | 2 | ||||
| -rw-r--r-- | templates/test_swatches.xml | 86 |
4 files changed, 182 insertions, 41 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index d0900f2d..7987a717 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -51,60 +51,62 @@ from .simulator import Simulator from .stitch_plan_preview import StitchPlanPreview from .stitch_plan_preview_undo import StitchPlanPreviewUndo from .stroke_to_lpe_satin import StrokeToLpeSatin +from .test_swatches import TestSwatches from .update_svg import UpdateSvg from .zigzag_line_to_satin import ZigzagLineToSatin from .zip import Zip from.lettering_along_path import LetteringAlongPath -__all__ = extensions = [StitchPlanPreview, - StitchPlanPreviewUndo, - DensityMap, - Install, - Params, - Print, - Input, - Output, - Zip, - Flip, - SelectionToPattern, - SelectionToGuideLine, - ObjectCommands, - ObjectCommandsToggleVisibility, - LayerCommands, - GlobalCommands, +__all__ = extensions = [ApplyThreadlist, + AutoRun, + AutoSatin, + BreakApart, + Cleanup, CommandsScaleSymbols, ConvertToSatin, - StrokeToLpeSatin, - ZigzagLineToSatin, ConvertToStroke, - JumpToStroke, - FillToStroke, CutSatin, - AutoSatin, - AutoRun, + CutworkSegmentation, + DensityMap, + DuplicateParams, + FillToStroke, + Flip, + GeneratePalette, + GlobalCommands, + GradientBlocks, + Input, + Install, + InstallCustomPalette, + JumpToStroke, + LayerCommands, Lettering, - LetteringGenerateJson, - LetteringUpdateJsonGlyphlist, - LetteringRemoveKerning, + LetteringAlongPath, LetteringCustomFontDir, LetteringForceLockStitches, - LetteringAlongPath, + LetteringGenerateJson, + LetteringRemoveKerning, + LetteringUpdateJsonGlyphlist, LettersToFont, - Troubleshoot, - RemoveEmbroiderySettings, - Cleanup, - UpdateSvg, - BreakApart, - GradientBlocks, - ApplyThreadlist, - InstallCustomPalette, - GeneratePalette, + ObjectCommands, + ObjectCommandsToggleVisibility, + Output, PaletteSplitText, PaletteToText, - Simulator, - Reorder, - DuplicateParams, + Params, Preferences, + Print, + RemoveEmbroiderySettings, + Reorder, SelectElements, - CutworkSegmentation] + SelectionToGuideLine, + SelectionToPattern, + Simulator, + StitchPlanPreview, + StitchPlanPreviewUndo, + StrokeToLpeSatin, + TestSwatches, + Troubleshoot, + UpdateSvg, + ZigzagLineToSatin, + Zip] diff --git a/lib/extensions/test_swatches.py b/lib/extensions/test_swatches.py new file mode 100644 index 00000000..a5b12d2f --- /dev/null +++ b/lib/extensions/test_swatches.py @@ -0,0 +1,55 @@ +# Authors: see git history +# +# Copyright (c) 2023 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +from inkex import errormsg + +from ..i18n import _ +from ..svg.tags import EMBROIDERABLE_TAGS +from .base import InkstitchExtension + + +class TestSwatches(InkstitchExtension): + ''' + This generates swatches from selection by altering one param each time. + ''' + def __init__(self, *args, **kwargs): + InkstitchExtension.__init__(self, *args, **kwargs) + self.arg_parser.add_argument("--options") + self.arg_parser.add_argument("--info") + + self.arg_parser.add_argument("-p", "--param", type=str, default="max_stitch_length_mm", dest="param") + self.arg_parser.add_argument("-s", "--start-value", type=float, default="max_stitch_length_mm", dest="start_value") + self.arg_parser.add_argument("-i", "--step", type=float, default="0.5", dest="step") + self.arg_parser.add_argument("-r", "--num-rows", type=int, default="5", dest="num_rows") + self.arg_parser.add_argument("-c", "--num-cols", type=int, default="5", dest="num_cols") + self.arg_parser.add_argument("-d", "--spacing", type=float, default="1", dest="spacing") + + def effect(self): + if not self.svg.selection: + errormsg(_("Please select one or more elements.")) + return + + for element in self.svg.selection: + dimensions = element.bounding_box() + param_value = self.options.start_value + for rows in range(0, self.options.num_rows): + for cols in range(0, self.options.num_cols): + new_element = element.duplicate() + translate_x = cols * dimensions.width + cols * self.options.spacing + translate_y = rows * dimensions.height + rows * self.options.spacing + new_element.transform.add_translate((translate_x, translate_y)) + if new_element.TAG == "g": + for embroidery_element in new_element.iterdescendants(EMBROIDERABLE_TAGS): + # Since this won't effect functionality, we can simply ignore the fact + # that this will also set the value to guide lines etc. + self._set_param(embroidery_element, param_value) + else: + self._set_param(new_element, param_value) + param_value += self.options.step + # remove old element + element.getparent().remove(element) + + def _set_param(self, element, value): + element.set(f'inkstitch:{ self.options.param }', value) diff --git a/lib/svg/tags.py b/lib/svg/tags.py index b99073f1..5713c399 100644 --- a/lib/svg/tags.py +++ b/lib/svg/tags.py @@ -98,7 +98,6 @@ inkstitch_attribs = [ 'underlay_underpath', 'underpath', 'flip', - 'expand_mm', 'clip', # stroke 'stroke_method', @@ -124,7 +123,6 @@ inkstitch_attribs = [ 'satin_method', 'short_stitch_distance_mm', 'short_stitch_inset', - 'running_stitch_length_mm', 'reverse_rails', 'swap_satin_rails', 'center_walk_underlay', diff --git a/templates/test_swatches.xml b/templates/test_swatches.xml new file mode 100644 index 00000000..72ddb124 --- /dev/null +++ b/templates/test_swatches.xml @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension translationdomain="inkstitch" xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <name>Generate Test Swatches from Selection</name> + <id>org.inkstitch.test_swatches</id> + <param name="extension" type="string" gui-hidden="true">test_swatches</param> + <effect> + <object-type>all</object-type> + <effects-menu> + <submenu name="Ink/Stitch" translatable="no"> + <submenu name="Edit" /> + </submenu> + </effects-menu> + </effect> + <param name="options" type="notebook"> + <page name="options" gui-text="Options"> + <param name="param" type="optiongroup" gui-text="Param" appearance="combo"> + <option value="angle">Angle (Fill)</option> + <option value="bean_stitch_repeats">Bean Stitch Repeats (Bean Stitch)</option> + <option value="center_walk_underlay_position">Center Walk Underlay: Position (Satin)</option> + <option value="center_walk_underlay_repeats">Center Walk Underlay: Repeats (Satin)</option> + <option value="center_walk_underlay_stitch_length_mm">center Walk Underlay: Stitch Length mm (Satin)</option> + <option value="contour_underlay_inset_mm">Contour Underlay: Inset mm (Satin)</option> + <option value="contour_underlay_inset_percent">Contour Underlay: Inset percent (Satin)</option> + <option value="contour_underlay_stitch_length_mm">Contour Underlay: Stitch Length mm (Satin)</option> + <option value="end_row_spacing_mm">End Row Spacing mm (Fill)</option> + <option value="expand_mm">Expand mm (Fill)</option> + <option value="exponent">Exponent (Stroke)</option> + <option value="fill_underlay_angle">Fill Underlay: Angle (Fill)</option> + <option value="fill_underlay_inset_mm">Fill Underlay: Inset mm (Fill)</option> + <option value="fill_underlay_max_stitch_length_mm">Fill Underlay: Maximum Stitch Length mm (Fill)</option> + <option value="fill_underlay_row_spacing_mm">Fill Underlay: Row Spacing mm (Fill)</option> + <option value="grid_size_mm">Grid Size mm (Ripple)</option> + <option value="line_count">Line Count (Ripple)</option> + <option value="max_stitch_length_mm">Maximum Stitch Length mm (Fill, Satin)</option> + <option value="meander_angle">Meander Pattern: Angle (Meander Fill)</option> + <option value="meander_scale_percent">Meander Pattern: Scale Percent (Meander Fill)</option> + <option value="min_line_dist_mm">Minimum Line Distanse mm (Ripple)</option> + <option value="min_random_split_length_mm">Minimum Random Split Length mm (Satin)</option> + <option value="pull_compensation_mm">Pull Compensation mm (Satin, ZigZag)</option> + <option value="pull_compensation_percent">Pull Compensation percent (Satin)</option> + <option value="random_split_jitter_percent">Random Split Jitter percent (Satin)</option> + <option value="random_width_decrease_percent">Random Width Decrease percent (Satin)</option> + <option value="random_width_increase_percent">Random width Increase percent (Satin)</option> + <option value="random_zigzag_spacing_percent">Random Zigzag Spacing percent (Satin)</option> + <option value="repeats">Repeats (Fill, Stroke)</option> + <option value="row_spacing_mm">Row Spacing mm (Fill)</option> + <option value="running_stitch_length_mm">Running Stitch Length mm (Stroke, Fill)</option> + <option value="running_stitch_tolerance_mm">Running Stitch Tolerance mm (Stroke, Fill)</option> + <option value="scale_end">Scale End (Ripple)</option> + <option value="scale_start">Scale Start (Ripple)</option> + <option value="short_stitch_distance_mm">Short Stitch: Distance mm (Satin)</option> + <option value="short_stitch_inset">Short Stitch: Inset (Satin)</option> + <option value="skip_end">Skip End (Ripple)</option> + <option value="skip_start">Skip Start (Ripple)</option> + <option value="smoothness_mm">Smoothness mm (Fill)</option> + <option value="split_staggers">Split Staggers (Satin)</option> + <option value="staggers">Staggers (Fill)</option> + <option value="zigzag_spacing_mm">Zigzag Spacing mm (Satin, Zigzag)</option> + <option value="zigzag_underlay_inset_mm">Zigzag Underlay: Inset_mm (Satin)</option> + <option value="zigzag_underlay_inset_percent">Zigzag Underlay: Inset percent (Satin)</option> + <option value="zigzag_underlay_max_stitch_length_mm">ZigZag Underlay: Maximum Stitch Length mm (Satin)</option> + <option value="zigzag_underlay_spacing_mm">Zigzag Underlay: Spacing mm (Satin)</option> + </param> + <param name="start-value" type="float" precision="2" min="0" max="500" + gui-text="Start Value">2.5</param> + <param name="step" type="float" gui-text="Increase by" min="0" max="50" precision="2" + gui-description="Increase by this value with each swatch.">0.5</param> + <param name="num-rows" type="int" gui-text="Rows" min="0" max="50">5</param> + <param name="num-cols" type="int" gui-text="Columns" min="0" max="50">5</param> + <param name="spacing" type="float" gui-text="Spacing" min="0" max="50" + gui-descritpion="Spacing between swatches (user units)">5</param> + </page> + <page name="info" gui-text="Help"> + <label appearance="header">Test Swatches</label> + <label>This extension generates test swatches from a selection.</label> + <label>Test swatches help to find best stitch settings for your design.</label> + <label>Sew them out with the same thread and fabric as the final designs.</label> + <spacer /> + <label>Get more information on our website</label> + <label appearance="url">https://inkstitch.org/docs/edit/#generate-test-swatches-from-selection</label> + </page> + </param> + <script> + {{ command_tag | safe }} + </script> +</inkscape-extension> |
