From 00bbda03e585fd528bc478638cac0c4811a0dbf7 Mon Sep 17 00:00:00 2001 From: branchwelder Date: Fri, 18 Feb 2022 16:19:36 -0800 Subject: [PATCH] Outputs basic PES files that work! --- .vscode/settings.json | 3 ++ embroidery/embroidery/Embroidery.css | 3 ++ embroidery/embroidery/Embroidery.jsx | 31 ++++++++++++++ embroidery/embroidery/Embroidery.py | 29 +++++++++++++ embryoid.py | 56 +++++++++++++++++++++++++ requirements.txt | 15 +++++++ tests_input/star.svg | 60 +++++++++++++++++++++++++++ tests_input/test_pattern.svg | 57 +++++++++++++++++++++++++ tests_pes/block_test.pes | Bin 0 -> 1384 bytes tests_pes/star.pes | Bin 0 -> 1235 bytes tests_svg/block_test.svg | 1 + tests_svg/result.svg | 1 + tests_svg/star_test.svg | 1 + 13 files changed, 257 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 embroidery/embroidery/Embroidery.css create mode 100644 embroidery/embroidery/Embroidery.jsx create mode 100644 embroidery/embroidery/Embroidery.py create mode 100644 embryoid.py create mode 100644 requirements.txt create mode 100644 tests_input/star.svg create mode 100644 tests_input/test_pattern.svg create mode 100644 tests_pes/block_test.pes create mode 100644 tests_pes/star.pes create mode 100644 tests_svg/block_test.svg create mode 100644 tests_svg/result.svg create mode 100644 tests_svg/star_test.svg diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..01ee7a8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "terminal.integrated.cwd": "${workspaceFolder}" +} \ No newline at end of file diff --git a/embroidery/embroidery/Embroidery.css b/embroidery/embroidery/Embroidery.css new file mode 100644 index 0000000..e56272f --- /dev/null +++ b/embroidery/embroidery/Embroidery.css @@ -0,0 +1,3 @@ +.background { + background-color: blueviolet; +} diff --git a/embroidery/embroidery/Embroidery.jsx b/embroidery/embroidery/Embroidery.jsx new file mode 100644 index 0000000..e1e9431 --- /dev/null +++ b/embroidery/embroidery/Embroidery.jsx @@ -0,0 +1,31 @@ +import React from "react"; + +import "./TemplateAction.css"; + +export default class Embroidery extends React.Component { + constructor(props) { + super(props); + this.state = { + flag: true, + }; + } + backendMethod() { + fetch("/runBackendMethod", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + method: "templateActionMethod", // The method to run + actionID: this.props.action.id, + }), + }) + .then((res) => res.json()) + .then((asdf) => { + console.log(asdf); + }); + } + render() { + return
Content goes here!
; + } +} diff --git a/embroidery/embroidery/Embroidery.py b/embroidery/embroidery/Embroidery.py new file mode 100644 index 0000000..7e184f0 --- /dev/null +++ b/embroidery/embroidery/Embroidery.py @@ -0,0 +1,29 @@ +from app.planager.workflow.Action import Action + +CONFIG = { + "displayName": "Embroidery", + "inports": { + "templateInput": { + "displayName": "TemplateAction", + "description": "TemplateAction", + } + }, + "outports": { + "templateOutput": { + "displayName": "TemplateAction", + "description": "TemplateAction", + } + }, +} + + +class Embroidery(Action): + def __init__(self): + Action.__init__(self, CONFIG) + + def main(self): + """The main loop; this is what runs when the action is run.""" + print("main loop") + + def templateActionMethod(self, options): + print("template method") diff --git a/embryoid.py b/embryoid.py new file mode 100644 index 0000000..2278a85 --- /dev/null +++ b/embryoid.py @@ -0,0 +1,56 @@ +from rich import print +from pyembroidery import * +from svgpathtools import svg2paths, wsvg +import numpy as np + + +OUTPUT_PES = "pes_tests/" +OUTPUT_SVG = "svg_tests/" + + +class Embryoid: + def __init__(self): + self.pattern = EmbPattern() + + def save_svg(self, fname=OUTPUT_SVG + "design.svg"): + write_svg(self.pattern, fname) + + def save_pes(self, fname=OUTPUT_PES + "design.pes"): + write_pes(self.pattern, fname) + + def add_stitch_block(self, block): + self.pattern.add_block(block) + + def parse_svg(self, fname): + paths, attributes = svg2paths(fname) + print(attributes) + for path in paths: + block = [] + for segment in path._segments: + block.append((segment.start.real, segment.start.imag)) + block.append((path._segments[0].start.real, path._segments[0].start.imag)) + self.pattern.add_block(block, "teal") + + +def solid_block(x_len=100, y_len=100, num_stitches=20): + stitches = [] + stitches_y_coords = np.linspace(0, y_len, num_stitches) + for stitch_y in stitches_y_coords: + stitches.append((0, stitch_y)) + stitches.append((x_len, stitch_y)) + + return stitches + + +def parse(): + e = Embryoid() + e.parse_svg("star.svg") + e.save_svg("star_test.svg") + e.save_pes("result.pes") + + +if __name__ == "__main__": + e = Embryoid() + e.add_stitch_block(solid_block()) + e.save_svg("block_test.svg") + e.save_pes("block_test.pes") diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5882d0c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,15 @@ +black==22.1.0 +click==8.0.3 +colorama==0.4.4 +commonmark==0.9.1 +mypy-extensions==0.4.3 +numpy==1.22.2 +pathspec==0.9.0 +platformdirs==2.5.0 +pyembroidery==1.4.33 +Pygments==2.11.2 +rich==11.2.0 +scipy==1.8.0 +svgpathtools==1.4.4 +svgwrite==1.4.1 +tomli==2.0.1 diff --git a/tests_input/star.svg b/tests_input/star.svg new file mode 100644 index 0000000..e24fb0e --- /dev/null +++ b/tests_input/star.svg @@ -0,0 +1,60 @@ + + + + + + + + + + diff --git a/tests_input/test_pattern.svg b/tests_input/test_pattern.svg new file mode 100644 index 0000000..5d8709c --- /dev/null +++ b/tests_input/test_pattern.svg @@ -0,0 +1,57 @@ + + + + + + + + + + + diff --git a/tests_pes/block_test.pes b/tests_pes/block_test.pes new file mode 100644 index 0000000000000000000000000000000000000000..a6c2a0c392f1f2177f2daa8873c904cc21183a8d GIT binary patch literal 1384 zcmeIwF;Buk6bJBsjiQTDoE(V;<5*S~slsN0N#hqVZH$R9k+?SM;N}-#VPavBg^7iQ zg^7iQr4tKF7bb@Ke=UtKY3O1cOneRZdwq93?%F%Ot=gt(mW~a;h^{aMc5z*;-`5&0 zQsG^GmzaC?3d*k)KFx4=C1GGak?lU)?gLQ7Is00n!ynM5ZQ7w7+NE9EqdnTEeLA26 zI;2B7q9Zz{V>+P|I;B%OqciGLpU&x=F6e>=G@whmq$|3jvUqs|vQCK`>*B7_d~80s zPGKGUNg{^Go#}fN_1%B|*WUo}4wS+`jY5S`r<7K>4Wp#B0y zZ2SlI_Ez};76CiKU1#qrAH-lQILFPsefwr+-?0-*g;F}5&b$Bs^B<)E#$dj%w^^)u z#P$WwbqI~Kd1&3{nNONr27p!^!bT)!`A^x45Sy5pfP6+bq=5E2G(hE zPSxREW?@6V!lg_wE*;jCZ>%Cu*@rZFQSCBU={h~h@W(FZW>%`Tom#~!r@}}?Kz|jC zPIj-s=wAKfzy1dR763A;t*>8;J+TX?u?!%DXoxf1wuCFZGSXP-eW56Zw0f4IYk=f>wormtWQH4@|2_34)mQ& PEo|b4 \ No newline at end of file diff --git a/tests_svg/result.svg b/tests_svg/result.svg new file mode 100644 index 0000000..3ccdde1 --- /dev/null +++ b/tests_svg/result.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests_svg/star_test.svg b/tests_svg/star_test.svg new file mode 100644 index 0000000..af12f64 --- /dev/null +++ b/tests_svg/star_test.svg @@ -0,0 +1 @@ + \ No newline at end of file