Repository navigation
feat: Start From (Absolute / Current Position / User Origin) with a 9-point job origin #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e07e00d
feat: add the Start From job origin model
switch87 569d3f1
feat(pipeline): place jobs via Start From
switch87 7afe4b3
feat(ui): add Start From controls and a placement outline
switch87 106d0b5
docs: document Start From
switch87 fdfa26b
fix(ui): check Current Position jobs at the head's present position
switch87 49da45d
test: no new Current Position job while the head returns
switch87 dc2ece3
test: guard the AABB unpack before destructuring
switch87 9398a4a
fix(tracing): make the vtracer pixel limit platform-independent
knipknap 0c776f3
test: pin the default Start From output against main
switch87 9d08f58
fix: keep Start From safe on rotated panels, layer WCS and Print & Cut
switch87 9314c2e
docs: document the Start From limits and Print & Cut behaviour
switch87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| """ | ||
| Job origin ("Start From") settings of a document. | ||
|
|
||
| The job origin decides where a job runs on the bed. With ``ABSOLUTE`` | ||
| the job runs exactly where it is placed on the canvas. With | ||
| ``USER_ORIGIN`` and ``CURRENT_POSITION`` the whole job is translated so | ||
| that one of nine points of its bounding box (the anchor) lands on the | ||
| zero point of the active work coordinate system or on the reported | ||
| head position. | ||
| """ | ||
|
|
||
| from dataclasses import dataclass | ||
| from enum import Enum | ||
| from gettext import gettext as _ | ||
| from typing import Any | ||
|
|
||
| from raygeo.geo.types import Point | ||
|
|
||
| # A world-space bounding box as (min_x, min_y, max_x, max_y). | ||
| BBox = tuple[float, float, float, float] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Raygeo has a Rect type for this |
||
|
|
||
|
|
||
| class StartFrom(Enum): | ||
| """Where a job is placed on the machine.""" | ||
|
|
||
| ABSOLUTE = "absolute" | ||
| CURRENT_POSITION = "current_position" | ||
| USER_ORIGIN = "user_origin" | ||
|
|
||
| @property | ||
| def label(self) -> str: | ||
| labels = { | ||
| StartFrom.ABSOLUTE: _("Absolute Coordinates"), | ||
| StartFrom.CURRENT_POSITION: _("Current Position"), | ||
| StartFrom.USER_ORIGIN: _("User Origin"), | ||
| } | ||
| return labels[self] | ||
|
|
||
|
|
||
| class JobAnchor(Enum): | ||
| """ | ||
| One of nine points on the job's bounding box. | ||
|
|
||
| The value holds the fractions along X (left to right) and Y | ||
| (bottom to top) in world space, which is Y-up. | ||
| """ | ||
|
|
||
| TOP_LEFT = (0.0, 1.0) | ||
| TOP = (0.5, 1.0) | ||
| TOP_RIGHT = (1.0, 1.0) | ||
| LEFT = (0.0, 0.5) | ||
| CENTER = (0.5, 0.5) | ||
| RIGHT = (1.0, 0.5) | ||
| BOTTOM_LEFT = (0.0, 0.0) | ||
| BOTTOM = (0.5, 0.0) | ||
| BOTTOM_RIGHT = (1.0, 0.0) | ||
|
|
||
| @property | ||
| def label(self) -> str: | ||
| labels = { | ||
| JobAnchor.TOP_LEFT: _("Top left"), | ||
| JobAnchor.TOP: _("Top center"), | ||
| JobAnchor.TOP_RIGHT: _("Top right"), | ||
| JobAnchor.LEFT: _("Middle left"), | ||
| JobAnchor.CENTER: _("Center"), | ||
| JobAnchor.RIGHT: _("Middle right"), | ||
| JobAnchor.BOTTOM_LEFT: _("Bottom left"), | ||
| JobAnchor.BOTTOM: _("Bottom center"), | ||
| JobAnchor.BOTTOM_RIGHT: _("Bottom right"), | ||
| } | ||
| return labels[self] | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class JobOrigin: | ||
| """The "Start From" mode and job anchor of a document.""" | ||
|
|
||
| start_from: StartFrom = StartFrom.ABSOLUTE | ||
| anchor: JobAnchor = JobAnchor.BOTTOM_LEFT | ||
|
|
||
| @property | ||
| def is_absolute(self) -> bool: | ||
| return self.start_from == StartFrom.ABSOLUTE | ||
|
|
||
| def to_dict(self) -> dict[str, str]: | ||
| return { | ||
| "start_from": self.start_from.value, | ||
| "anchor": self.anchor.name.lower(), | ||
| } | ||
|
|
||
| @classmethod | ||
| def from_dict(cls, data: dict[str, Any] | None) -> "JobOrigin": | ||
| if not data: | ||
| return cls() | ||
| try: | ||
| start_from = StartFrom(data.get("start_from")) | ||
| except ValueError: | ||
| start_from = StartFrom.ABSOLUTE | ||
| anchor_name = str(data.get("anchor", "")).upper() | ||
| anchor = JobAnchor.__members__.get(anchor_name, JobAnchor.BOTTOM_LEFT) | ||
| return cls(start_from=start_from, anchor=anchor) | ||
|
|
||
|
|
||
| # Fractions along X and Y of a bounding box, as in JobAnchor values. | ||
| AnchorFractions = tuple[float, float] | ||
|
|
||
|
|
||
| def anchor_point(rect: BBox, anchor: JobAnchor | AnchorFractions) -> Point: | ||
| """ | ||
| The world-space position of *anchor* on the bounding box. The | ||
| anchor is a JobAnchor or its (x, y) fractions in world space. | ||
| """ | ||
| min_x, min_y, max_x, max_y = rect | ||
| fx, fy = anchor.value if isinstance(anchor, JobAnchor) else anchor | ||
| return (min_x + fx * (max_x - min_x), min_y + fy * (max_y - min_y)) | ||
|
|
||
|
|
||
| def placement_offset( | ||
| rect: BBox, anchor: JobAnchor | AnchorFractions, start_point: Point | ||
| ) -> Point: | ||
| """The translation that moves *anchor* of *rect* onto *start_point*.""" | ||
| ax, ay = anchor_point(rect, anchor) | ||
| return (start_point[0] - ax, start_point[1] - ay) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not use \ sequences for UTF chars; all modern versions of Python support UTF8 natively