Add Ctrl+D duplicate tool to sketcher - #369
Open
knipknap wants to merge 3 commits into
Open
Conversation
Add Mirror Vertically and Mirror Horizontally toolbar buttons that mirror the current selection in-place across the bounding-box center. Constraints spanning the selection boundary are dropped; internal constraints are preserved. Chirality-sensitive constraints (AngleConstraint) are negated or dropped if expression-based. Key changes: - MirrorCommand with MirrorAxis/MirrorDirection enum - Polymorphic Entity.mirror() (Bezier flips cp deltas, Arc toggles clockwise) - Polymorphic Constraint.mirror() / is_mirror_compatible() (AngleConstraint negates signed value) - Constraint.get_referenced_point_ids()/get_referenced_entity_ids() refactored from depends_on_* for reuse - Bezier.get_state()/set_state() extended to include cp1/cp2 for snapshot-based undo - SHOW_IN_PIE flag on SketchTool to exclude mirror from pie menu - Toolbar buttons after fill color selector with separator - 24 unit tests covering prepare, execute, undo, and all edge cases Refs #358
…ow it saves the document
Ctrl+D duplicates the current selection in-place: selected entities and their points are copied with fresh IDs, internal constraints (all references within the selection) are copied and remapped to the duplicates. Constraints referencing geometry outside the selection are not copied, matching the mirror tools' behavior. Fixed points (e.g. the origin) are duplicated as movable points. After duplicating, only the copies are selected. Undo removes the duplicates and restores the previous state. Also fixes a hit-testing z-order issue: entities and points were hit-tested in list order while rendering draws in list order, so overlapping geometry (e.g. fresh duplicates drawn on top) picked the wrong item on click/drag. Hit testing now iterates in reverse draw order so topmost geometry wins. Key changes: - DuplicateCommand with prepare() for pure parameter resolution, deepcopy-based duplication and ID remapping - SketchElement.duplicate_selection() re-selects the new copies - Ctrl+D handled in SketchEditor key handling - Hit testing in hittest.py reversed to respect z-order - 21 new tests (command behavior, undo, hit-test z-order) Based on feat/sketcher-mirror-tools (#366), which must be merged to main first.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Prerequisite
feat/sketcher-mirror-tools), which must be merged to main first. Please merge that PR before this one.Summary
Adds
Ctrl+Din the sketcher to duplicate the selected entities and constraints in-place, following the same conventions as the mirror tools from #366:Hit-testing z-order fix
While testing it turned out that dragging after a duplicate grabbed the original line instead of the duplicate on top. Root cause:
SketchHitTesteriterated entities/points in list order, while rendering draws in list order too — so overlapping geometry was hit-tested bottom-first while being drawn top-last. Hit testing now iterates in reverse draw order so topmost geometry wins (nearest point still wins over a merely tied one).Key changes
DuplicateCommand(sketcher/core/commands/duplicate.py) with pureprepare()resolution, deepcopy-based duplication and ID remappingSketchElement.duplicate_selection()re-selects the new copiesCtrl+Dhandled inSketchEditor.handle_key_presshittest.py