diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2019-08-06 04:42:48 +0200 |
|---|---|---|
| committer | Lex Neva <lexelby@users.noreply.github.com> | 2019-08-05 22:42:48 -0400 |
| commit | 077f7ea72ba38790bf030d3181c44787fef953b6 (patch) | |
| tree | 1cd8bf2896d587735c98eee06589f4c88bee3aa9 /lib/elements/validation.py | |
| parent | cdb8d1d0d4a6dba9a1eb146167b1aef01de0e9d6 (diff) | |
add Troubleshoot extension (#465)
adds an extension to help you understand what's wrong with an object and how to fix it, e.g. "invalid" fill shapes
Diffstat (limited to 'lib/elements/validation.py')
| -rw-r--r-- | lib/elements/validation.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/elements/validation.py b/lib/elements/validation.py new file mode 100644 index 00000000..41098922 --- /dev/null +++ b/lib/elements/validation.py @@ -0,0 +1,41 @@ +from shapely.geometry import Point as ShapelyPoint + +from ..utils import Point as InkstitchPoint + + +class ValidationMessage(object): + '''Holds information about a problem with an element. + + Attributes: + name - A short descriptor for the problem, such as "dangling rung" + description - A detailed description of the problem, such as + "One or more rungs does not intersect both rails." + position - An optional position where the problem occurs, + to aid the user in correcting it. type: Point or tuple of (x, y) + steps_to_solve - A list of operations necessary to solve the problem + ''' + + # Subclasses will fill these in. + name = None + description = None + steps_to_solve = [] + + def __init__(self, position=None): + if isinstance(position, ShapelyPoint): + position = (position.x, position.y) + + self.position = InkstitchPoint(*position) + + +class ValidationError(ValidationMessage): + """A problem that will prevent the shape from being embroidered.""" + pass + + +class ValidationWarning(ValidationMessage): + """A problem that won't prevent a shape from being embroidered. + + The user will almost certainly want to fix the warning, but if they + don't, Ink/Stitch will do its best to process the object. + """ + pass |
