Porównaj commity

...

7 Commity

Autor SHA1 Wiadomość Data
tatarize 7268266882 Add optional ct0 write test 2023-10-27 08:35:08 -07:00
tatarize 8667d117c3 Add optional ct0 writer for tbf 2023-10-27 08:34:30 -07:00
tatarize 1aefcc73c6 Remove unused load/save test 2023-10-27 07:53:09 -07:00
tatarize f03351531b Change position of 0d1a 2023-10-27 06:42:18 -07:00
tatarize c14647a3ad Update test_need_tbf writing of range 2023-10-27 06:30:54 -07:00
tatarize f23cc2b07d Fix writer's count of needle set values 2023-10-27 06:30:16 -07:00
tatarize d52295661a update test file 2023-10-27 06:17:13 -07:00
2 zmienionych plików z 65 dodań i 6 usunięć

Wyświetl plik

@ -11,6 +11,9 @@ EXPLICIT_TRIM = True
def write(pattern, f, settings=None):
if settings is not None and "ct0" in settings:
ct0 = settings.get("ct0")
write_ct0(pattern, ct0)
bounds = pattern.bounds()
name = pattern.get_metadata("name", "Untitled")
@ -19,7 +22,7 @@ def write(pattern, f, settings=None):
f.write(b"\x20") # space
write_string_utf8(f, "LA:%-16s\r" % name)
write_string_utf8(f, "ST:%7d\r" % pattern.count_stitches())
write_string_utf8(f, "CO:%3d\r" % pattern.count_color_changes())
write_string_utf8(f, "CO:%3d\r" % pattern.count_needle_sets())
write_string_utf8(f, "+X:%5d\r" % abs(bounds[2]))
write_string_utf8(f, "-X:%5d\r" % abs(bounds[0]))
@ -73,7 +76,7 @@ def write(pattern, f, settings=None):
write_int_8(f, 0x20)
# Padding to 501
for i in range(f.tell(), 0x501):
for i in range(f.tell(), 0x376):
f.write(b"\x20") # space
# Seen in only some files.
@ -117,3 +120,44 @@ def write(pattern, f, settings=None):
break
# Terminal character.
f.write(b"\x1a")
def write_ct0(pattern, filename, settings=None):
with open(filename, "wb") as f:
_write_ct0(pattern, f, settings=settings)
def _write_ct0(pattern, f, settings=None):
write_string_utf8(f, "TAJ-DGML-PULSE 1-1A 2060(550.0")
write_int_8(f, 0x81)
write_string_utf8(f, "~400.0)S 2.00")
for i in range(f.tell(), 0x60):
f.write(b"\x20")
write_string_utf8(f, "DC1:100\rDC2:100\rDC3: 0\rDC4:N\rDC5:S\r")
for i in range(f.tell(), 0x108):
f.write(b"\x20")
write_string_utf8(f, "NS1:11")
index = 0
for stitch in pattern.stitches:
data = stitch[2] & COMMAND_MASK
if data == NEEDLE_SET:
flag, thread, needle, order = decode_embroidery_command(stitch[2])
write_int_8(f, needle + 0x30)
write_int_8(f, 0x31)
index += 1
for i in range(f.tell(), 0x30D):
f.write(b"\x20")
write_string_utf8(f, "\rRP0:N\rRP1: \rRP2: \rRP3: \rRP4: \rRP5: \rRP6: \rRP7: \rST1:")
for i in range(f.tell(), 0x434):
f.write(b"\x20")
write_string_utf8(f, "ST0:0\rAO1:0\rAO2:0\rAO3:0\rOF1: \rOF2: \rOF3: \rNS2:")
for i in range(index):
write_int_8(f, 0x30)
for i in range(f.tell(), 0x583):
f.write(b"\x20")
write_string_utf8(f, "\rNS3:")
for i in range(f.tell(), 0x778):
f.write(b"\x20")
write_string_utf8(f, "\r\x1A")
for i in range(f.tell(), 0x790):
f.write(b"\x20")

Wyświetl plik

@ -213,8 +213,10 @@ class TestConverts(unittest.TestCase):
self.addCleanup(os.remove, file2)
def test_needle_tbf_range(self):
file1 = "test_range.tbf"
file1 = "test_range8.tbf"
file2 = "test_range8.ct0"
pattern = EmbPattern()
pattern.metadata("name", "colorswitch8")
pattern += "red"
pattern += "blue"
pattern += "green"
@ -224,11 +226,24 @@ class TestConverts(unittest.TestCase):
pattern += "khaki"
pattern += "oldlace"
pattern.needle_change(needle=7)
pattern.needle_change(needle=4)
pattern += (0, 0), (0, 100), (100, 100), (100, 0), (0, 0)
write_tbf(pattern, file1)
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 360.0 / 3)
pattern.needle_change(needle=5)
pattern += (0, 0), (0, 100), (100, 100), (100, 0), (0, 0)
pattern.add_command(MATRIX_TRANSLATE, 25, 25)
pattern.add_command(MATRIX_ROTATE, 360.0 / 3)
pattern.needle_change(needle=6)
pattern += (0, 0), (0, 100), (100, 100), (100, 0), (0, 0)
write_tbf(pattern, file1, settings={"ct0": file2})
f_pattern = read_tbf(file1)
self.assertNotEqual(len(f_pattern.threadlist), 1)
self.assertEqual(f_pattern.count_stitch_commands(STITCH), 5)
self.assertEqual(f_pattern.count_stitch_commands(STITCH), 3 * 5)
self.addCleanup(os.remove, file1)
self.addCleanup(os.remove, file2)