kopia lustrzana https://github.com/inkstitch/inkstitch
stuff
rodzic
6a23fe868b
commit
b70e0e7fa8
|
@ -28,7 +28,7 @@
|
||||||
<_option value="csv">Embroidermodder 2 CSV</_option>
|
<_option value="csv">Embroidermodder 2 CSV</_option>
|
||||||
<_option value="gcode">Franklin G-Code</_option>
|
<_option value="gcode">Franklin G-Code</_option>
|
||||||
</param>
|
</param>
|
||||||
<param name="filename" type="string" _gui-text="File">embroider-output.exp</param>
|
<param name="path" type="string" _gui-text="Directory"></param>
|
||||||
<effect>
|
<effect>
|
||||||
<object-type>all</object-type>
|
<object-type>all</object-type>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
|
|
47
embroider.py
47
embroider.py
|
@ -650,10 +650,14 @@ class Embroider(inkex.Effect):
|
||||||
choices=["melco", "csv", "gcode"],
|
choices=["melco", "csv", "gcode"],
|
||||||
dest="output_format", default="melco",
|
dest="output_format", default="melco",
|
||||||
help="File output format")
|
help="File output format")
|
||||||
self.OptionParser.add_option("-F", "--filename",
|
self.OptionParser.add_option("-P", "--path",
|
||||||
action="store", type="string",
|
action="store", type="string",
|
||||||
dest="filename", default="embroider-output.exp",
|
dest="path", default=".",
|
||||||
help="Name (and possibly path) of output file")
|
help="Directory in which to store output file")
|
||||||
|
self.OptionParser.add_option("-b", "--max-backups",
|
||||||
|
action="store", type="int",
|
||||||
|
dest="max_backups", default=5,
|
||||||
|
help="Max number of backups of output files to keep.")
|
||||||
self.patches = []
|
self.patches = []
|
||||||
|
|
||||||
def get_sort_order(self, threadcolor, node):
|
def get_sort_order(self, threadcolor, node):
|
||||||
|
@ -961,6 +965,33 @@ class Embroider(inkex.Effect):
|
||||||
|
|
||||||
process(self.document.getroot())
|
process(self.document.getroot())
|
||||||
|
|
||||||
|
def get_output_path(self):
|
||||||
|
svg_filename = self.document.getroot().get(inkex.addNS('docname', 'sodipodi'))
|
||||||
|
csv_filename = svg_filename.replace('.svg', '.csv')
|
||||||
|
output_path = os.path.join(self.options.path, csv_filename)
|
||||||
|
|
||||||
|
def add_suffix(path, suffix):
|
||||||
|
if suffix > 0:
|
||||||
|
path = "%s.%s" % (path, suffix)
|
||||||
|
|
||||||
|
return path
|
||||||
|
|
||||||
|
def move_if_exists(path, suffix=0):
|
||||||
|
source = add_suffix(path, suffix)
|
||||||
|
|
||||||
|
if suffix >= self.options.max_backups:
|
||||||
|
return
|
||||||
|
|
||||||
|
dest = add_suffix(path, suffix + 1)
|
||||||
|
|
||||||
|
if os.path.exists(source):
|
||||||
|
move_if_exists(path, suffix + 1)
|
||||||
|
os.rename(source, dest)
|
||||||
|
|
||||||
|
move_if_exists(output_path)
|
||||||
|
|
||||||
|
return output_path
|
||||||
|
|
||||||
def effect(self):
|
def effect(self):
|
||||||
# Printing anything other than a valid SVG on stdout blows inkscape up.
|
# Printing anything other than a valid SVG on stdout blows inkscape up.
|
||||||
old_stdout = sys.stdout
|
old_stdout = sys.stdout
|
||||||
|
@ -1007,7 +1038,7 @@ class Embroider(inkex.Effect):
|
||||||
self.hide_layers()
|
self.hide_layers()
|
||||||
|
|
||||||
eo = EmbroideryObject(self.patchList, self.row_spacing_px)
|
eo = EmbroideryObject(self.patchList, self.row_spacing_px)
|
||||||
emb = eo.emit_file(self.options.filename, self.options.output_format,
|
emb = eo.emit_file(self.get_output_path(), self.options.output_format,
|
||||||
self.collapse_len_px, self.options.add_preamble)
|
self.collapse_len_px, self.options.add_preamble)
|
||||||
|
|
||||||
new_layer = inkex.etree.SubElement(self.document.getroot(),
|
new_layer = inkex.etree.SubElement(self.document.getroot(),
|
||||||
|
@ -1207,12 +1238,16 @@ class Embroider(inkex.Effect):
|
||||||
patch = Patch(color=threadcolor, sortorder=sortorder)
|
patch = Patch(color=threadcolor, sortorder=sortorder)
|
||||||
|
|
||||||
def offset_stitches(pos1, pos2, offset_px):
|
def offset_stitches(pos1, pos2, offset_px):
|
||||||
if pos1 == pos2:
|
distance = (pos1 - pos2).length()
|
||||||
|
|
||||||
|
if (pos1 - pos2).length() < 0.0001:
|
||||||
# if they're the same, we don't know which direction
|
# if they're the same, we don't know which direction
|
||||||
# to offset in, so we have to just return the points
|
# to offset in, so we have to just return the points
|
||||||
return pos1, pos2
|
return pos1, pos2
|
||||||
|
|
||||||
print pos1, pos2
|
# don't offset so far that pos1 and pos2 switch places
|
||||||
|
if offset_px < -distance/2.0:
|
||||||
|
offset_px = -distance/2.0
|
||||||
|
|
||||||
midpoint = (pos2 + pos1) * 0.5
|
midpoint = (pos2 + pos1) * 0.5
|
||||||
pos1 = pos1 + (pos1 - midpoint).unit() * offset_px
|
pos1 = pos1 + (pos1 - midpoint).unit() * offset_px
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
|
<_name>Reorder</_name>
|
||||||
|
<id>lexelby.embroider.reorder</id>
|
||||||
|
<dependency type="executable" location="extensions">reorder.py</dependency>
|
||||||
|
<dependency type="executable" location="extensions">inkex.py</dependency>
|
||||||
|
<effect>
|
||||||
|
<object-type>all</object-type>
|
||||||
|
<effects-menu>
|
||||||
|
<submenu _name="Embroidery"/>
|
||||||
|
</effects-menu>
|
||||||
|
</effect>
|
||||||
|
<script>
|
||||||
|
<command reldir="extensions" interpreter="python">reorder.py</command>
|
||||||
|
</script>
|
||||||
|
</inkscape-extension>
|
|
@ -0,0 +1,38 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
#
|
||||||
|
# Remove selected objects from the document and readd them in the order they
|
||||||
|
# were selected.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
sys.path.append("/usr/share/inkscape/extensions")
|
||||||
|
import os
|
||||||
|
import inkex
|
||||||
|
|
||||||
|
|
||||||
|
class Reorder(inkex.Effect):
|
||||||
|
def get_selected_in_order(self):
|
||||||
|
selected = []
|
||||||
|
|
||||||
|
for i in self.options.ids:
|
||||||
|
path = '//*[@id="%s"]' % i
|
||||||
|
for node in self.document.xpath(path, namespaces=inkex.NSS):
|
||||||
|
selected.append(node)
|
||||||
|
|
||||||
|
return selected
|
||||||
|
|
||||||
|
def effect(self):
|
||||||
|
objects = self.get_selected_in_order()
|
||||||
|
|
||||||
|
for obj in objects[1:]:
|
||||||
|
obj.getparent().remove(obj)
|
||||||
|
|
||||||
|
insert_parent = objects[0].getparent()
|
||||||
|
insert_pos = insert_parent.index(objects[0])
|
||||||
|
|
||||||
|
insert_parent.remove(objects[0])
|
||||||
|
|
||||||
|
insert_parent[insert_pos:insert_pos] = objects
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
e = Reorder()
|
||||||
|
e.affect()
|
Ładowanie…
Reference in New Issue