CreativeInquiry / PEmbroider

Embroidery Library for Processing
Other
442 stars 28 forks source link

Request for out of bounds warning #53

Closed tatyanade closed 4 years ago

tatyanade commented 4 years ago

When running an embroidery file that is larger than the designated dimensions (ie if the vp3 has a canvas of 300, 300, but there is a stitch at 300,350) it compiles fine, and the machine lets you open the file and place it on the embroidery hoop based off of the stated size not the actual size, which means you can position it so that part of the file is out of range, but it wont let you know. When this happens the machine embroiders till it gets to the problem stitch, and then tells you the file is to large and stops embroidering. This happened to me once when I'd made the PEmbroiderGraphics the incorrect size by accident and also when using the interactive which demo got this far before quitting, you can see the stroke on the middle right hand side is out of bounds: image PEmbroider_interactive_demo_2

Would be great if processing gave the user a warning and refused to write the file if it contains stitches that are out of bounds

LingDong- commented 4 years ago

Added warning: 67f73eacefca4ac3cc5949fc9038795ff9eb7cc4

[PEmbroider] Warning: some stitch(es) are out of bound! ( -400.0 100.0 )
golanlevin commented 4 years ago

Hi @tatyanade , there's no way for Processing to know what are the unit-limits for all of the different machines out there. For our Viking, it's 2400x1500, but that depends on the hoop and the machine. What we can know for sure is if any coordinates are negative, or if any coordinates are bigger than the Processing canvas. Is that good enough? Can you test what Lingdong made here?

tatyanade commented 4 years ago

Hi !

I meant the units of the designated embroidery file not the unit-limits for different machines:

The issue is that the machine(or at least ours) assumes that the file is the size it says it is, and does not cross-reference that with stitch information when letting you place it.

To elaborate, if you only had an 80x80mm hoop, you wouldnt be able to run files bigger than (800,800) which if fine which is fine & makes sense; But! my issue was that if you are working on a file of PEmbroiderGraphics(this, 800, 800) you could for example rendered E.circle(800,800,100) which would go outside of the designated phyiscal size, and this behaves weirdly on the machine - if I had tried to run this specific example on an 80x80 hoop, the machine would let me start, as the file information says it physically fits, and it could get partway done with the embroidery before it reaches a thread outside of the boundaries and then will stop embroidering ( this is frustrating because you would expect it to tell you the file is unrunnable before it starts instead of finding out after already finishing some of it, and could cause you to waste materials. )
. However, if I where to run this same file in the middle of a 240x150 hoop it would be able to run to completion, and it would still be possible to place in a location that is un-embroiderable (an Inconvenience in this situation even if it does run to completion would be that if you had the machine show you the bounding corners of the file it would be incorrect as it has misinformation on the size)

The warning does show when I have something out of bounds, but I think refusing to even write the file might be more appropriate, and would help to avoid unnecessary frustration

LingDong- commented 4 years ago

I'm wondering if it would it be valuable to provide additional options:

If so, how would the option be provided to the user?

golanlevin commented 4 years ago

Hi @tatyanade , could you kindly make recommendations for @LingDong- based on your knowledge of what would be most appropriate. Thanks!

tatyanade commented 4 years ago

I think annoying pop up window makes sense to me - removing out of bounds stitches makes sense for some design (for example for the interactive one i posted that would be what id have chosen if its an option) , moving outside stitches in i dont think would make sense. Extending the canvas would work but i think that is something the user can do for themselves and not something we need to do for them - so I think the way to go would be:

Either a pop up with options for abort (where they can go fix the file) or crop (which cuts off the out of bounds lines), or just E.endDraw(ABORT | CROP)

would also suggest that if optimize() is being called, that out of bounds is checked for at the beginning instead of the end (had tested multiple variants of text_3 example and running it with optimize on my machine[which is an admittedly old laptop] took upwards of 40 minutes) unless something in optimize would cause stitches to be placed out of bounds though i don't think it would - not sure if this is reasonable as optimize is not always called, and the warning, i'm assuming, is being placed in endDraw();

golanlevin commented 4 years ago

Thanks, @tatyanade , these sound like good suggestions. @LingDong- , please see above. :)

LingDong- commented 4 years ago

👌

LingDong- commented 4 years ago

@golanlevin @tatyanade This feature is now added: d7e752e3356aa3c3b8f13c5e977ae566353d6036

Constants are:

ASK   // annoying pop up
ABORT // exit sketch immediately
CROP // discard outside stitches
IGNORE // do nothing about it
WARN // print some warning

The constants can be combined in meaningful ways using + operator:

WARN+ABORT // prints a warning and abort
WARN+CROP // prints a warning before discarding outside stitches

WARN+ASK, WARN+IGNORE also work as user might expect, but are redundant.

Default is ASK.

New API's are:

// use the default handler, i.e. ASK
E.endDraw();
// check out of bounds right before saving file
E.setOutOfBoundsHandler(WARN+CROP);
// ...
E.endDraw();
// check out of bounds right away, at any time
E.checkOutOfBounds(WARN+CROP);
// ... more code, e.g. E.optmize
// same as above, check out of bounds any time, but setting mode only once
E.setOutOfBoundsHandler(WARN+CROP);
// ...
E.checkOutOfBounds();
// ... some code
E.checkOutOfBounds();

Screenshot of the popup:

Screen Shot 2020-06-28 at 6 05 06 PM

Also, as a side product of CROP, a new interactive eraser feature is added to the library! See https://github.com/CreativeInquiry/PEmbroider/commit/d7e752e3356aa3c3b8f13c5e977ae566353d6036#commitcomment-40225721

tatyanade commented 4 years ago

Works great!

golanlevin commented 4 years ago

Really glad to hear this, thanks.