Namespaced Attributes (#657)

pull/643/head
Kaalleen 2020-04-25 14:45:27 +02:00 zatwierdzone przez GitHub
rodzic 1d3b89111e
commit 3199050876
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
8 zmienionych plików z 129 dodań i 42 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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',

Wyświetl plik

@ -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

Wyświetl plik

@ -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",
}
)

Wyświetl plik

@ -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]

Wyświetl plik

@ -1,20 +1,23 @@
from itertools import chain, izip
import math
from itertools import chain, izip
import networkx as nx
from shapely import geometry as shgeo
from shapely.geometry import Point as ShapelyPoint
import cubicsuperpath
import inkex
from shapely import geometry as shgeo
from shapely.geometry import Point as ShapelyPoint
import simplestyle
import networkx as nx
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)

Wyświetl plik

@ -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)

Wyświetl plik

@ -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')