summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2020-04-25 14:45:27 +0200
committerGitHub <noreply@github.com>2020-04-25 14:45:27 +0200
commit319905087661bc44a560afff6c574b6545d21115 (patch)
tree249f7c5ff6f023df1a1bdd3933b7bc0377232658 /lib
parent1d3b89111e627b3662a7ec2749bb3dcfe694be66 (diff)
Namespaced Attributes (#657)
Diffstat (limited to 'lib')
-rw-r--r--lib/commands.py30
-rw-r--r--lib/elements/auto_fill.py4
-rw-r--r--lib/elements/element.py24
-rw-r--r--lib/extensions/convert_to_satin.py9
-rw-r--r--lib/extensions/remove_embroidery_settings.py8
-rw-r--r--lib/stitches/auto_satin.py29
-rw-r--r--lib/svg/rendering.py8
-rw-r--r--lib/svg/tags.py59
8 files changed, 129 insertions, 42 deletions
diff --git a/lib/commands.py b/lib/commands.py
index c7b8698d..b92d79cf 100644
--- a/lib/commands.py
+++ b/lib/commands.py
@@ -1,19 +1,22 @@
-from copy import deepcopy
import os
-from random import random
import sys
+from copy import deepcopy
+from random import random
+
+from shapely import geometry as shgeo
import cubicsuperpath
import inkex
-from shapely import geometry as shgeo
import simpletransform
-from .i18n import _, N_
-from .svg import apply_transforms, get_node_transform, get_correction_transform, get_document, generate_unique_id
-from .svg.tags import SVG_DEFS_TAG, SVG_GROUP_TAG, SVG_PATH_TAG, SVG_USE_TAG, SVG_SYMBOL_TAG, \
- CONNECTION_START, CONNECTION_END, CONNECTOR_TYPE, XLINK_HREF, INKSCAPE_LABEL
-from .utils import cache, get_bundled_dir, Point
-
+from .i18n import N_, _
+from .svg import (apply_transforms, generate_unique_id,
+ get_correction_transform, get_document, get_node_transform)
+from .svg.tags import (CONNECTION_END, CONNECTION_START, CONNECTOR_TYPE,
+ INKSCAPE_LABEL, INKSTITCH_ATTRIBS, SVG_DEFS_TAG,
+ SVG_GROUP_TAG, SVG_PATH_TAG, SVG_SYMBOL_TAG,
+ SVG_USE_TAG, XLINK_HREF)
+from .utils import Point, cache, get_bundled_dir
COMMANDS = {
# L10N command attached to an object
@@ -346,7 +349,7 @@ def get_command_pos(element, index, total):
def remove_legacy_param(element, command):
if command == "trim" or command == "stop":
# If they had the old "TRIM after" or "STOP after" attributes set,
- # automatically delete them. THe new commands will do the same
+ # automatically delete them. The new commands will do the same
# thing.
#
# If we didn't delete these here, then things would get confusing.
@@ -359,6 +362,13 @@ def remove_legacy_param(element, command):
if attribute in element.node.attrib:
del element.node.attrib[attribute]
+ # Attributes have changed to be namespaced.
+ # Let's check for them as well, they might have automatically changed.
+ attribute = INKSTITCH_ATTRIBS["%s_after" % command]
+
+ if attribute in element.node.attrib:
+ del element.node.attrib[attribute]
+
def add_commands(element, commands):
document = get_document(element.node)
diff --git a/lib/elements/auto_fill.py b/lib/elements/auto_fill.py
index 04da3288..b574c8bf 100644
--- a/lib/elements/auto_fill.py
+++ b/lib/elements/auto_fill.py
@@ -53,9 +53,9 @@ class AutoFill(Fill):
return max(self.get_float_param("running_stitch_length_mm", 1.5), 0.01)
@property
- @param('fill_underlay', _('Underlay'), type='toggle', group=_('AutoFill Underlay'), default=False)
+ @param('fill_underlay', _('Underlay'), type='toggle', group=_('AutoFill Underlay'), default=True)
def fill_underlay(self):
- return self.get_boolean_param("fill_underlay", default=False)
+ return self.get_boolean_param("fill_underlay", default=True)
@property
@param('fill_underlay_angle',
diff --git a/lib/elements/element.py b/lib/elements/element.py
index f39280fc..83e3978f 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -8,7 +8,7 @@ from cspsubdiv import cspsubdiv
from ..commands import find_commands
from ..i18n import _
from ..svg import PIXELS_PER_MM, apply_transforms, convert_length, get_doc_size
-from ..svg.tags import INKSCAPE_LABEL
+from ..svg.tags import INKSCAPE_LABEL, INKSTITCH_ATTRIBS
from ..utils import cache
@@ -72,6 +72,16 @@ class EmbroideryElement(object):
def __init__(self, node):
self.node = node
+ legacy_attribs = False
+ for attrib in self.node.attrib:
+ if attrib.startswith('embroider_'):
+ # update embroider_ attributes to namespaced attributes
+ self.replace_legacy_param(attrib)
+ legacy_attribs = True
+ if legacy_attribs and not self.get_param('fill_underlay', ""):
+ # defaut setting for fill_underlay has changed
+ self.set_param('fill_underlay', False)
+
@property
def id(self):
return self.node.get('id')
@@ -85,13 +95,16 @@ class EmbroideryElement(object):
# The 'param' attribute is set by the 'param' decorator defined above.
if hasattr(prop.fget, 'param'):
params.append(prop.fget.param)
-
return params
+ def replace_legacy_param(self, param):
+ value = self.node.get(param, "").strip()
+ self.set_param(param[10:], value)
+ del self.node.attrib[param]
+
@cache
def get_param(self, param, default):
- value = self.node.get("embroider_" + param, "").strip()
-
+ value = self.node.get(INKSTITCH_ATTRIBS[param], "").strip()
return value or default
@cache
@@ -131,7 +144,8 @@ class EmbroideryElement(object):
return value
def set_param(self, name, value):
- self.node.set("embroider_%s" % name, str(value))
+ param = INKSTITCH_ATTRIBS[name]
+ self.node.set(param, str(value))
@property
@cache
diff --git a/lib/extensions/convert_to_satin.py b/lib/extensions/convert_to_satin.py
index f3924659..e2b287dd 100644
--- a/lib/extensions/convert_to_satin.py
+++ b/lib/extensions/convert_to_satin.py
@@ -1,17 +1,18 @@
import math
from itertools import chain, groupby
-import inkex
import numpy
from numpy import diff, setdiff1d, sign
from shapely import geometry as shgeo
-from .base import InkstitchExtension
+import inkex
+
from ..elements import Stroke
from ..i18n import _
from ..svg import PIXELS_PER_MM, get_correction_transform
-from ..svg.tags import SVG_PATH_TAG
+from ..svg.tags import INKSTITCH_ATTRIBS, SVG_PATH_TAG
from ..utils import Point
+from .base import InkstitchExtension
class SelfIntersectionError(Exception):
@@ -309,6 +310,6 @@ class ConvertToSatin(InkstitchExtension):
"style": path_style,
"transform": correction_transform,
"d": d,
- "embroider_satin_column": "true",
+ INKSTITCH_ATTRIBS['satin_column']: "true",
}
)
diff --git a/lib/extensions/remove_embroidery_settings.py b/lib/extensions/remove_embroidery_settings.py
index d87a216a..d39c7e94 100644
--- a/lib/extensions/remove_embroidery_settings.py
+++ b/lib/extensions/remove_embroidery_settings.py
@@ -30,11 +30,11 @@ class RemoveEmbroiderySettings(InkstitchExtension):
if not self.selected:
xpath = ".//svg:path"
elements = self.find_elements(xpath)
- self.remove_embroider_attributes(elements)
+ self.remove_inkstitch_attributes(elements)
else:
for node in self.selected:
elements = self.get_selected_elements(node)
- self.remove_embroider_attributes(elements)
+ self.remove_inkstitch_attributes(elements)
def remove_commands(self):
if not self.selected:
@@ -83,8 +83,8 @@ class RemoveEmbroiderySettings(InkstitchExtension):
def remove_element(self, element):
element.getparent().remove(element)
- def remove_embroider_attributes(self, elements):
+ def remove_inkstitch_attributes(self, elements):
for element in elements:
for attrib in element.attrib:
- if attrib.startswith('embroider_'):
+ if attrib.startswith(inkex.NSS['inkstitch'], 1):
del element.attrib[attrib]
diff --git a/lib/stitches/auto_satin.py b/lib/stitches/auto_satin.py
index 4ce356ce..9edff53c 100644
--- a/lib/stitches/auto_satin.py
+++ b/lib/stitches/auto_satin.py
@@ -1,20 +1,23 @@
-from itertools import chain, izip
import math
+from itertools import chain, izip
-import cubicsuperpath
-import inkex
+import networkx as nx
from shapely import geometry as shgeo
from shapely.geometry import Point as ShapelyPoint
-import simplestyle
-import networkx as nx
+import cubicsuperpath
+import inkex
+import simplestyle
from ..commands import add_commands
-from ..elements import Stroke, SatinColumn
+from ..elements import SatinColumn, Stroke
from ..i18n import _
-from ..svg import PIXELS_PER_MM, line_strings_to_csp, get_correction_transform, generate_unique_id
-from ..svg.tags import SVG_PATH_TAG, SVG_GROUP_TAG, INKSCAPE_LABEL
-from ..utils import Point as InkstitchPoint, cut, cache
+from ..svg import (PIXELS_PER_MM, generate_unique_id, get_correction_transform,
+ line_strings_to_csp)
+from ..svg.tags import (INKSCAPE_LABEL, INKSTITCH_ATTRIBS, SVG_GROUP_TAG,
+ SVG_PATH_TAG)
+from ..utils import Point as InkstitchPoint
+from ..utils import cache, cut
class SatinSegment(object):
@@ -209,9 +212,9 @@ class RunningStitch(object):
self.original_element = original_element
self.style = original_element.node.get('style', '')
self.running_stitch_length = \
- original_element.node.get('embroider_running_stitch_length_mm', '') or \
- original_element.node.get('embroider_center_walk_underlay_stitch_length_mm', '') or \
- original_element.node.get('embroider_contour_underlay_stitch_length_mm', '')
+ original_element.node.get(INKSTITCH_ATTRIBS['running_stitch_length_mm'], '') or \
+ original_element.node.get(INKSTITCH_ATTRIBS['center_walk_underlay_stitch_length_mm'], '') or \
+ original_element.node.get(INKSTITCH_ATTRIBS['contour_underlay_stitch_length_mm'], '')
def to_element(self):
node = inkex.etree.Element(SVG_PATH_TAG)
@@ -222,7 +225,7 @@ class RunningStitch(object):
style['stroke-dasharray'] = "0.5,0.5"
style = simplestyle.formatStyle(style)
node.set("style", style)
- node.set("embroider_running_stitch_length_mm", self.running_stitch_length)
+ node.set(INKSTITCH_ATTRIBS['running_stitch_length_mm'], self.running_stitch_length)
stroke = Stroke(node)
diff --git a/lib/svg/rendering.py b/lib/svg/rendering.py
index 2711f12a..5860ceef 100644
--- a/lib/svg/rendering.py
+++ b/lib/svg/rendering.py
@@ -5,10 +5,11 @@ import simplepath
import simplestyle
import simpletransform
-from .tags import INKSCAPE_GROUPMODE, INKSCAPE_LABEL, SVG_DEFS_TAG, SVG_GROUP_TAG, SVG_PATH_TAG
-from .units import PIXELS_PER_MM, get_viewbox_transform
from ..i18n import _
from ..utils import Point, cache
+from .tags import (INKSCAPE_GROUPMODE, INKSCAPE_LABEL, INKSTITCH_ATTRIBS,
+ SVG_DEFS_TAG, SVG_GROUP_TAG, SVG_PATH_TAG)
+from .units import PIXELS_PER_MM, get_viewbox_transform
# The stitch vector path looks like this:
# _______
@@ -198,6 +199,7 @@ def color_block_to_paths(color_block, svg, destination, visual_commands):
add_commands(Stroke(destination[-1]), ["trim"])
color = color_block.color.visible_on_white.to_hex_str()
+
path = inkex.etree.Element(SVG_PATH_TAG, {
'style': simplestyle.formatStyle({
'stroke': color,
@@ -206,7 +208,7 @@ def color_block_to_paths(color_block, svg, destination, visual_commands):
}),
'd': "M" + " ".join(" ".join(str(coord) for coord in point) for point in point_list),
'transform': get_correction_transform(svg),
- 'embroider_manual_stitch': 'true'
+ INKSTITCH_ATTRIBS['manual_stitch']: 'true'
})
destination.append(path)
diff --git a/lib/svg/tags.py b/lib/svg/tags.py
index 55af113a..3e444513 100644
--- a/lib/svg/tags.py
+++ b/lib/svg/tags.py
@@ -1,5 +1,6 @@
import inkex
+
# This is used below and added to the document in ../extensions/base.py.
inkex.NSS['inkstitch'] = 'http://inkstitch.org/namespace'
@@ -13,15 +14,71 @@ SVG_GROUP_TAG = inkex.addNS('g', 'svg')
SVG_SYMBOL_TAG = inkex.addNS('symbol', 'svg')
SVG_USE_TAG = inkex.addNS('use', 'svg')
+EMBROIDERABLE_TAGS = (SVG_PATH_TAG, SVG_POLYLINE_TAG)
+
INKSCAPE_LABEL = inkex.addNS('label', 'inkscape')
INKSCAPE_GROUPMODE = inkex.addNS('groupmode', 'inkscape')
CONNECTION_START = inkex.addNS('connection-start', 'inkscape')
CONNECTION_END = inkex.addNS('connection-end', 'inkscape')
CONNECTOR_TYPE = inkex.addNS('connector-type', 'inkscape')
+
XLINK_HREF = inkex.addNS('href', 'xlink')
+
SODIPODI_NAMEDVIEW = inkex.addNS('namedview', 'sodipodi')
SODIPODI_GUIDE = inkex.addNS('guide', 'sodipodi')
SODIPODI_ROLE = inkex.addNS('role', 'sodipodi')
+
INKSTITCH_LETTERING = inkex.addNS('lettering', 'inkstitch')
-EMBROIDERABLE_TAGS = (SVG_PATH_TAG, SVG_POLYLINE_TAG)
+INKSTITCH_ATTRIBS = {}
+# Fill
+inkstitch_attribs = [
+ 'ties',
+ 'trim_after',
+ 'stop_after',
+ # fill
+ 'angle',
+ 'auto_fill',
+ 'expand_mm',
+ 'fill_underlay',
+ 'fill_underlay_angle',
+ 'fill_underlay_inset_mm',
+ 'fill_underlay_max_stitch_length_mm',
+ 'fill_underlay_row_spacing_mm',
+ 'fill_underlay_skip_last',
+ 'max_stitch_length_mm',
+ 'row_spacing_mm',
+ 'end_row_spacing_mm',
+ 'skip_last',
+ 'staggers',
+ 'underlay_underpath',
+ 'underpath',
+ 'flip',
+ 'expand_mm',
+ # stroke
+ 'manual_stitch',
+ 'bean_stitch_repeats',
+ 'repeats',
+ 'running_stitch_length_mm',
+ # satin column
+ 'satin_column',
+ 'satin_column',
+ 'running_stitch_length_mm',
+ 'center_walk_underlay',
+ 'center_walk_underlay_stitch_length_mm',
+ 'contour_underlay',
+ 'contour_underlay_stitch_length_mm',
+ 'contour_underlay_inset_mm',
+ 'zigzag_underlay',
+ 'zigzag_spacing_mm',
+ 'zigzag_underlay_inset_mm',
+ 'zigzag_underlay_spacing_mm',
+ 'e_stitch',
+ 'pull_compensation_mm',
+ 'stroke_first',
+ # Legacy
+ 'embroider_trim_after',
+ 'embroider_stop_after'
+ ]
+for attrib in inkstitch_attribs:
+ INKSTITCH_ATTRIBS[attrib] = inkex.addNS(attrib, 'inkstitch')