summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/extensions/__init__.py6
-rw-r--r--lib/extensions/print_pdf.py2
-rw-r--r--lib/extensions/remove_embroidery_settings.py79
-rw-r--r--lib/stitches/auto_satin.py2
-rw-r--r--lib/svg/rendering.py59
5 files changed, 112 insertions, 36 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py
index d6d0e279..38276a64 100644
--- a/lib/extensions/__init__.py
+++ b/lib/extensions/__init__.py
@@ -2,17 +2,18 @@ from auto_satin import AutoSatin
from convert_to_satin import ConvertToSatin
from cut_satin import CutSatin
from embroider import Embroider
-from lib.extensions.troubleshoot import Troubleshoot
from flip import Flip
from global_commands import GlobalCommands
from input import Input
from install import Install
from layer_commands import LayerCommands
from lettering import Lettering
+from lib.extensions.troubleshoot import Troubleshoot
from object_commands import ObjectCommands
from output import Output
from params import Params
from print_pdf import Print
+from remove_embroidery_settings import RemoveEmbroiderySettings
from simulate import Simulate
from zip import Zip
@@ -33,4 +34,5 @@ __all__ = extensions = [Embroider,
CutSatin,
AutoSatin,
Lettering,
- Troubleshoot]
+ Troubleshoot,
+ RemoveEmbroiderySettings]
diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py
index befb7861..387e246b 100644
--- a/lib/extensions/print_pdf.py
+++ b/lib/extensions/print_pdf.py
@@ -199,7 +199,7 @@ class Print(InkstitchExtension):
def render_svgs(self, stitch_plan, realistic=False):
svg = deepcopy(self.document).getroot()
- render_stitch_plan(svg, stitch_plan, realistic)
+ render_stitch_plan(svg, stitch_plan, realistic, visual_commands=False)
self.strip_namespaces(svg)
diff --git a/lib/extensions/remove_embroidery_settings.py b/lib/extensions/remove_embroidery_settings.py
new file mode 100644
index 00000000..c467e797
--- /dev/null
+++ b/lib/extensions/remove_embroidery_settings.py
@@ -0,0 +1,79 @@
+import inkex
+
+from ..commands import find_commands
+from .base import InkstitchExtension
+
+
+class RemoveEmbroiderySettings(InkstitchExtension):
+ def __init__(self, *args, **kwargs):
+ InkstitchExtension.__init__(self, *args, **kwargs)
+ self.OptionParser.add_option("-p", "--del_params", dest="del_params", type="inkbool", default=True)
+ self.OptionParser.add_option("-c", "--del_commands", dest="del_commands", type="inkbool", default=False)
+ self.OptionParser.add_option("-d", "--del_print", dest="del_print", type="inkbool", default=False)
+
+ def effect(self):
+ if self.options.del_params:
+ self.remove_params()
+ if self.options.del_commands:
+ self.remove_commands()
+ if self.options.del_print:
+ self.remove_print_settings()
+
+ def remove_print_settings(self):
+ print_settings = "svg:metadata//*"
+ print_settings = self.find_elements(print_settings)
+ for print_setting in print_settings:
+ if print_setting.prefix == "inkstitch":
+ self.remove_element(print_setting)
+
+ def remove_params(self):
+ if not self.selected:
+ xpath = ".//svg:path"
+ elements = self.find_elements(xpath)
+ self.remove_embroider_attributes(elements)
+ else:
+ for node in self.selected:
+ elements = self.get_selected_elements(node)
+ self.remove_embroider_attributes(elements)
+
+ def remove_commands(self):
+ if not self.selected:
+ commands = ".//*[starts-with(@inkscape:label, 'Ink/Stitch Command:')]"
+ self.remove_elements(commands)
+
+ symbols = ".//*[starts-with(@id, 'inkstitch_')]"
+ self.remove_elements(symbols)
+ else:
+ for node in self.selected:
+ elements = self.get_selected_elements(node)
+ for element in elements:
+ for command in find_commands(element):
+ group = command.connector.getparent()
+ group.getparent().remove(group)
+
+ def get_selected_elements(self, element_id):
+ xpath = ".//svg:path[@id='%s']" % element_id
+ elements = self.find_elements(xpath)
+ if not elements:
+ xpath = ".//svg:g[@id='%s']//svg:path" % element_id
+ elements = self.find_elements(xpath)
+ return elements
+
+ def find_elements(self, xpath):
+ svg = self.document.getroot()
+ elements = svg.xpath(xpath, namespaces=inkex.NSS)
+ return elements
+
+ def remove_elements(self, xpath):
+ elements = self.find_elements(xpath)
+ for element in elements:
+ self.remove_element(element)
+
+ def remove_element(self, element):
+ element.getparent().remove(element)
+
+ def remove_embroider_attributes(self, elements):
+ for element in elements:
+ for attrib in element.attrib:
+ if attrib.startswith('embroider_'):
+ del element.attrib[attrib]
diff --git a/lib/stitches/auto_satin.py b/lib/stitches/auto_satin.py
index 75b13176..4ce356ce 100644
--- a/lib/stitches/auto_satin.py
+++ b/lib/stitches/auto_satin.py
@@ -201,7 +201,7 @@ class RunningStitch(object):
# Technically a Stroke object's underlying path could have multiple
# subpaths. We don't have a particularly good way of dealing with
# that so we'll just use the first one.
- self.path = path_or_stroke.shape.geoms[0]
+ self.path = shgeo.LineString(path_or_stroke.paths[0])
original_element = path_or_stroke
else:
self.path = path_or_stroke
diff --git a/lib/svg/rendering.py b/lib/svg/rendering.py
index 074380a7..2711f12a 100644
--- a/lib/svg/rendering.py
+++ b/lib/svg/rendering.py
@@ -5,13 +5,10 @@ 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
-from ..utils import cache
-from .tags import SVG_GROUP_TAG, INKSCAPE_LABEL, INKSCAPE_GROUPMODE, SVG_PATH_TAG, SVG_DEFS_TAG
-from .units import PIXELS_PER_MM
-from .units import get_viewbox_transform
-
+from ..utils import Point, cache
# The stitch vector path looks like this:
# _______
@@ -172,21 +169,19 @@ def color_block_to_realistic_stitches(color_block, svg, destination):
color = color_block.color.visible_on_white.darker.to_hex_str()
start = point_list[0]
for point in point_list[1:]:
- destination.append(inkex.etree.Element(
- SVG_PATH_TAG,
- {'style': simplestyle.formatStyle(
- {
- 'fill': color,
- 'stroke': 'none',
- 'filter': 'url(#realistic-stitch-filter)'
- }),
- 'd': realistic_stitch(start, point),
- 'transform': get_correction_transform(svg)
- }))
+ destination.append(inkex.etree.Element(SVG_PATH_TAG, {
+ 'style': simplestyle.formatStyle({
+ 'fill': color,
+ 'stroke': 'none',
+ 'filter': 'url(#realistic-stitch-filter)'
+ }),
+ 'd': realistic_stitch(start, point),
+ 'transform': get_correction_transform(svg)
+ }))
start = point
-def color_block_to_paths(color_block, svg, destination):
+def color_block_to_paths(color_block, svg, destination, visual_commands):
# If we try to import these above, we get into a mess of circular
# imports.
from ..commands import add_commands
@@ -199,23 +194,23 @@ def color_block_to_paths(color_block, svg, destination):
for point_list in color_block_to_point_lists(color_block):
if first:
first = False
- else:
+ elif 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,
- 'stroke-width': "0.4",
- 'fill': 'none'}),
- 'd': "M" + " ".join(" ".join(str(coord) for coord in point) for point in point_list),
- 'transform': get_correction_transform(svg),
- 'embroider_manual_stitch': 'true'
- })
+ path = inkex.etree.Element(SVG_PATH_TAG, {
+ 'style': simplestyle.formatStyle({
+ 'stroke': color,
+ 'stroke-width': "0.4",
+ 'fill': 'none'
+ }),
+ 'd': "M" + " ".join(" ".join(str(coord) for coord in point) for point in point_list),
+ 'transform': get_correction_transform(svg),
+ 'embroider_manual_stitch': 'true'
+ })
destination.append(path)
- if path is not None:
+ if path is not None and visual_commands:
if color_block.trim_after:
add_commands(Stroke(path), ["trim"])
@@ -223,7 +218,7 @@ def color_block_to_paths(color_block, svg, destination):
add_commands(Stroke(path), ["stop"])
-def render_stitch_plan(svg, stitch_plan, realistic=False):
+def render_stitch_plan(svg, stitch_plan, realistic=False, visual_commands=True):
layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']")
if layer is None:
layer = inkex.etree.Element(SVG_GROUP_TAG,
@@ -247,7 +242,7 @@ def render_stitch_plan(svg, stitch_plan, realistic=False):
if realistic:
color_block_to_realistic_stitches(color_block, svg, group)
else:
- color_block_to_paths(color_block, svg, group)
+ color_block_to_paths(color_block, svg, group, visual_commands)
if realistic:
defs = svg.find(SVG_DEFS_TAG)