inkstitch / pyembroidery

libembroidery/EmbroideryFormats converted to python
MIT License
76 stars 29 forks source link

don't always trim before color change #48

Closed lexelby closed 6 years ago

lexelby commented 6 years ago

EmbEncoder automatically adds a TRIM before all color changes. Can we avoid doing this?

Per https://github.com/inkstitch/inkstitch/issues/228, we need to add an artificial color change in order to properly support the STOP command. The stitches before and after the color block will have the same thread color. We don't want to trim because the color change is only there to allow the user a place to set the stop code.

On my Brother SE400, just adding a color change causes it to cut the thread. It's not a true "trim" since this machine can't actually trim and then continue on sewing; the user has to intervene. Do "real" machines automatically trim when switching to a new color even without a TRIM instruction?

tatarize commented 6 years ago

Yeah, not a hard thing to fix. Though it would seem like it would be more proper to fully support the stop command in a way that the end user wouldn't see in a seamless fashion. Rather than splitting the the block on your end. It should split it on this end. In theory a stop command should, depending on the format, duplicate the written color element in formats where that's a thing, to ensure a stop with distinction from a color change.

Your machine is a real machine, but my machine is single head 15 (13 working) multi-needle swf machine. And since you have thread on different needles and it moves over to the one it's sewing with, there's no way to do a colorchange without trimming. In a number of formats these don't actually do anything because there's no command for that. But, in some it matters and making it overt seems proper.

I'll ofcourse add a setting to disinclude pre-color change trims, but be advised what you're doing seems very much like it belongs in pyembroidery proper. It is supposed to support the stop command overtly. So you should just write STOP to the pattern and expect it to be dealt with properly. If it isn't dealt with properly, it is a pyembroidery bug.

Most of these formats it seem like the goto way to implement STOP is to encode a COLOR_CHANGE to the same color you were just at. In some, this is logged and it cares that you went from color 32 to color 32, in others, it makes no distinction. In the later type this might actually cause issues. If you encode a stop in some formats it would correctly double-write the color in best practices. In others there's no way to do that, so if you don't reflect this back to the end user, they might not know to enter color 32 twice on their machine, thereby invoking a stop.

lexelby commented 6 years ago

Trust me, I'd like nothing more than to let pyembroidery handle all of the STOP logic. Unfortunately, there's really no way around it; Ink/Stitch has to be deeply familiar with how stops work in actual machines.

The reason is mostly described in inkstitch/inkstitch#228. We need to add instructions on the PDF printout to tell the operator when to add the stop code on their machine. That means Ink/Stitch needs to be aware of where the existing color block was split to make room for the stop instruction.

It all stems from the kind of bizarre way that commercial machines handle stops, as I understand it. Rather than telling the machine "stop at this point", you tell it "continue sewing this block with the thread you were already sewing with, and stop afterward".

Since I don't have access to a true commercial machine, I can't actually test whether my understanding of all of this is correct. If you know differently from your machine, please help me understand what I've got wrong.

tatarize commented 6 years ago

Added option for explicit trims. Setting it to false will disable that from happening. Upped the version to 1.2.13 here and on pypi.

tatarize commented 6 years ago

Categorically you tell the machine. Stop at this point.

It depends a bit on the format. In DST and EXP there is absolutely no distinction between color change and stop. You actually just use a color change. And then make sure the machine knows that you are doing a color change to the same needle and that tells it to stop. In some of the other formats the command is also a color change but it actually records the color log for you and you tell it that you are switching to the same needle explicitly. In some other formats you can actually specify the needle but not the colors, so you specify a color change to the colors on the same needle you're already using.

Embroidery machines are stupid. They don't have any memory. They certainly cannot know where the end of a block is or what stop-after means. Stop after what? There's no way to remember any of that. They literally predate computers. Usually the command is overtly just a color change with some implied finagling. Admittedly PEC might actually implement stop by switching to color zero which is applique. I don't know, I don't have a brother machine.

But, suffice it to say you can tell the machine explicitly stop at this exact point. There's absolutely nothing in the machine or format that knows what a block is (except with VP3 which is actually organized into blocks).

tatarize commented 6 years ago

In my commercial machine, the oldest and simplest format is DST is totally supported and STOP is explicitly 00000000 00000000 11000011, in binary. All commands are fed in one after the next and that command forces the machine to stop. It then checks the entered color log for which needle it goes to next and switches to that needle and continues sewing. If that needle you go to next is the one you're currently on the machine remains stop without changing needles until the user hit the go button again. This is done quite often to switch the thread in all the needles. But, it means stop. And it means stop exactly at this point without any cruft about blocks (it doesn't know what that means). It literally just follows really basic commands in order.

tatarize commented 6 years ago

A lot of that stop-after logic is a conceit. It's a way to imply a stop without expressly telling the user that the backend is just going to make an extra colorchange and tell it to colorchange to the same color it was just at. When you're encoding that stuff in blocks, it doesn't make much sense to have a block with zero stitches that really just contains a color_change command, so they often just attach it automatically to stitchblock because it makes the coding easier sometimes. But, it's really just ending up as compiled machine code for the embroidery machine, and that stuff very much does have a stop command, insofar as it has a colorchange command and you just change to the current needle or the current color in the file or on the machine itself.

Stitch blocks themselves are just higher order stuff that makes the programming easier. They aren't a real thing (save in VP3 that actually stores something akin to them in the file).

That stuff isn't how the machines work, it's how the embroidery design programs work. The machines work by following really really really basic commands that tell them go here stitch, go here and block the needle bar, and stop the machine. I think you have a weirdly wrong understanding from how other software tends to work. In a real sense even the stop commands are a midlevel command for do a color change and fiddle with things to make them stop rather than move on to the next needle.

tatarize commented 6 years ago

EG: Premier 2 documentation, how is this plausible if it must work the weird way you think it does?:

Commands Commands are instructions such as the Color Change that changes the thread at the start of a new color block. The Stop tells an embroidery machine to stop without a color change.

Color change and stop commands, and alignment stitches are shown as a single point when selected.

Stitches, color changes and stop commands are inserted at the selected stitch point. If no stitch point is selected, stitches, color changes and stop commands are added to the end of the embroidery,

Stop Commands Use Add Stop to add a Stop command that is used to tell the embroidery machine to stop without a color change. This allows appliqué or a decoration to be added. To visualize appliqué fabric or decorations, use PREMIER+™ 2 Embroidery Extra. Zoom in to the thread where you want to place the Stop, and in 2D Mode, select the stitch. A box appears around the stitch. Click Add Stop , and a Stop command marker appears at that point. If no stitch is selected, the Stop command is placed at the end of all the stitches. The Stop command is represented by a small red circle with an S .