Skip to content

Drawing tab: Offset, Stretch, Enlarge ,Spot Co-ordinate, Chamfer, Fillet tools, Move with base point + dimension input for shapes - #541

Closed
ghostship25 wants to merge 4 commits into
OpenAEC-Foundation:mainfrom
ghostship25:feature/drawing-cad-edit-tools
Closed

ghostship25 wants to merge 4 commits into
OpenAEC-Foundation:mainfrom
ghostship25:feature/drawing-cad-edit-tools

Conversation

@ghostship25

Copy link
Copy Markdown
Contributor

Goal

Three CAD-style editing operations in the Drawing tab — two of them already sitting there as disabled "Coming soon" placeholders — plus the ability to draw shapes by entering dimensions instead of dragging.

What's in this PR

Editing tools (Drawing tab → Edit group)

Tool Behaviour
Offset Type a distance (existing CAD input HUD, in the document's measured units) → click the side. Produces a parallel copy: lines/arrows/walls offset perpendicular, boxes/circles/regular polygons grow outward or shrink inward (click outside vs. inside), polyline/L-shape contours are offset along their angle bisectors so corners stay sharp. The distance is remembered while the tool is active, so you can keep clicking sides.
Stretch Drag a crossing window over the corners that should move → click a base point → drag. Only the vertices inside the window move; the rest of the shape stays put (right edge of a rectangle extends, left edge stays). Works on lines, boxes/circles, polylines, freehand paths and point shapes.
Enlarge Select objects → click the ribbon button (base point defaults to the selection centre) or click the canvas for a custom base point → type a factor (1.5, 0.5) + Enter. Live preview while typing; Escape restores the original geometry. Text scales with the shape, line weights stay unchanged.

Dimension input for shapes (Drawing tab → Draw group)

A click (instead of a drag) with Rectangle, Circle, Ellipse, Polygon or L-shape now opens the same CAD input HUD used by the line tool:

  • 500,300 + Enter → rectangle 500 × 300 (width × height, in measured units)
  • 240 + Enter → circle with Ø240, or a 150 × 150 square for the rectangle tool
  • 100<45 (polar) and =400,300 (absolute) also work, matching the existing coord-input formats
  • the shape follows the cursor quadrant, so you can still steer with the mouse while typing
  • a live preview shows while you type; Escape or a new click cancels

The Draw-group tooltips now mention it: "Rectangle — click, then type e.g. 500,300 + Enter".

Implementation notes

  • Geometry lives in three new pure, DOM-free modules with unit tests: js/annotations/offset-geometry.js, stretch-geometry.js, scale-geometry.js
  • Tools follow the existing tool contract (onPointerDown/Move/Up/Escape/Deactivate, state._typeLengthCommit, recordAdd/recordBulkModify undo records, status-bar guidance)
  • Ribbon buttons: the dr-offset/dr-stretch placeholders are replaced and dr-enlarge is added; registration in js/tools/tools/index.js
  • Strings added to js/i18n/locales/en/ribbon.json only — other locales fall back to English (fallbackLng: 'en'), so no translations are blocked
  • Read-only (PDF/A) and no-document states are handled the same way as the neighbouring tools

Acceptance criteria / verification

  • npx tsc --noEmit — clean
  • npm run test:unit — 2987 tests, 0 failures (25 new tests covering offset/stretch/scale geometry, added to scripts/unit-testlijst.txt)
  • npx vite build — clean
  • Manual browser run (npx vite) on a blank document:
    • typed 400,200 → rectangle measured 400 × 200 ✅
    • typed 240 on circle → Ø240 ✅, typed 150 on rectangle → 150 × 150 ✅
    • Offset 10 + click outside → copy grew 400×200 → 420×220 at −10 offset ✅
    • Stretch window on the right edge + drag 50 → width 400 → 450, x unchanged ✅
    • Enlarge 1.5 → 450×200 → 675×300 around the same centre ✅

Out of scope

Fillet, Chamfer and Spot Coord remain "Coming soon" placeholders, as before.


Happy to re-work anything — I saw the note in CONTRIBUTING.md that a clear description is sometimes preferred over a code PR; this branch is meant to make the intent concrete and can be re-implemented against the current code if that is easier.

🤖 Generated with Codebuff

Fills in the three CAD-style editing operations the Drawing tab left as
"Coming soon" placeholders (Offset, Stretch) and adds Enlarge (AutoCAD
SCALE), and lets users draw rectangles, circles, ellipses, polygons and
L-shapes by typing exact dimensions instead of dragging.

- Offset: type a distance with the existing CAD input, click a side and get
  a parallel copy — lines/arrows/walls (perpendicular), boxes/circles
  (outward or inward), polyline contours (bisector offsetting)
- Stretch: drag a crossing window over the vertices that should move, then
  a base point + drag; the rest of the shape stays put
- Enlarge: scale the selection about a base point by a typed factor
  (1.5 / 0.5), with a live preview that reverts on Escape
- Shape tools: a click (instead of a drag) now opens dimension input —
  type "500,300" for width x height, or one value for a square/diameter,
  Enter to draw; tooltips mention it
- New pure geometry modules (offset/stretch/scale) with 25 unit tests,
  registered in scripts/unit-testlijst.txt
- New English ribbon strings; other locales fall back to English

Verified: tsc --noEmit, 2987 unit tests, vite build, and manual browser
tests (400x200 rect, 240 diameter circle, +10 offset, +50 stretch,
1.5x enlarge).

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
ghostship25 and others added 3 commits October 9, 2026 12:11
… guide Extend

The floating W/H badge only committed on Enter, so a typed size was
silently discarded whenever focus left the field (clicking the canvas
deselected first and reverted the field). Commit now also runs on blur
and, via a document-level capture listener, just before a click-away
deselect — tracked by a dirty flag so a plain focus change without
edits stays undo-clean.

The badge now also covers circles (a round circle keeps both axes
equal, as one undo step) and polygons (both axes scale by the same
factor so the shape stays regular); polylines are excluded because
their x/y/width/height is only a derived bounding box.

Extend gave no feedback at all: clicking anything but a line was a
silent no-op, which read as "the tool does nothing". It now announces
its two-step workflow in the status bar and explains non-line picks
and non-intersecting lines, started through a new startExtendTool()
entry point from the ribbon.

Verified in the browser: blur/click-away/Enter commits for rectangle,
circle and polygon, one-step undo for the linked circle resize, exact
intersection geometry and all three Extend messages, plus Stretch
(right edge only, x untouched) and Enlarge (exact ×1.5). Typecheck,
2987 unit tests and the production build all pass.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
…splacement

The coord-input HUD only rendered once the first character was typed,
and at the last raw cursor position — so after clicking a ribbon button
the user got no clue where to type the enlarge factor at all. The HUD
now stays visible for the whole time a tool has input capture active,
shows a tool-specific placeholder (factor / dx,dy / distance / length),
and anchors to the tool's input point when the cursor is not over the
page instead of drifting to a stale corner.

Stretch could only be dragged, with no way to state an exact x/y
displacement. The base-point phase now also opens coord-input capture:
typing "50,0" or "100<45" plus Enter applies that displacement (same
scale-unit conversion and undo path as the drag), while a bare number
without direction is rejected with a hint.

Enlarge no longer activates into a dead end when nothing is selected —
it captures the selection before switching tools and otherwise keeps
the current tool while telling the user to select first.

Verified in the browser: enlarge HUD visible immediately with its
placeholder positioned over the page, typed 1.25 scales exactly
1.25 on both axes and hides the HUD; stretch typed 50,0 grows the
right edge by exactly 50 with x untouched, -30,0 shrinks by 30; the
line tool still draws with its new placeholder shown; the empty-
selection guard leaves the tool untouched. Typecheck, 2987 unit tests
and the production build all pass.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
Replace the three "Coming soon" placeholders with working CAD tools:
- Fillet/Chamfer (corner-tools.js): two-click corner editing on lines,
  arrows and walls; trim one endpoint per line and add the arc/chamfer
  segment as one undo step. Pure geometry in corner-geometry.js with
  13 unit tests. Typed radius (fillet) or distance(s) "d1,d2" (chamfer)
  via the CAD coord-input, remembered between uses.
- Spot Coord (spot-coord-tool.js): one click labels the X,Y coordinates
  of a point with a leader, in scale-region-aware document units;
  reuses the measureDistance annotation type.
- Move button now runs the AutoCAD-style base-point flow ('mv') instead
  of synthesizing a G keypress: click 1 picks the snapped base point,
  then drag or type a displacement like 50,0 + Enter.

Verified in the browser against the live app (tool contexts, keyboard
path, undo/redo transactions); tsc, unit tests and build all pass.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@ghostship25 ghostship25 changed the title Drawing tab: Offset, Stretch, Enlarge tools + dimension input for shapes Drawing tab: Offset, Stretch, Enlarge ,Spot Co-ordinate, Chamfer, Fillet tools, Move with base point + dimension input for shapes Oct 12, 2026
@DutchSailor

Copy link
Copy Markdown
Collaborator

Thank you, @ghostship25! Your drawing tools are in release 2026.42.0 (#576) as one squashed commit under your name, together with review fixes: locked and hidden objects are not edited, arc segments are kept on stretch, enlarge and offset, measurement labels update after an edit, and an interrupted Enlarge preview is undoable. The PR is closed manually because the commits were squashed into the release.

philip-tam pushed a commit to philip-tam/open-pdf-studio that referenced this pull request Oct 14, 2026
…rdinate tools (OpenAEC-Foundation#541)

Adds Offset, Stretch, Enlarge, Fillet, Chamfer and Spot Coordinate to the
Drawing tab, Move with a base point, and typed dimensions for boxes,
circles, ellipses, polygons and L-shapes.
philip-tam pushed a commit to philip-tam/open-pdf-studio that referenced this pull request Oct 14, 2026
- Lao (OpenAEC-Foundation#537): register 'lo' in the language list, count 40 locales in the
  locale tests, and use one wording for Shift Page.
- Pages per sheet (OpenAEC-Foundation#540): flush lazily embedded images and fonts before
  placing pages, so raster prints no longer give blank cells.
- Drawing tools (OpenAEC-Foundation#541): never edit locked, hidden or locked-layer objects;
  keep arc segments on stretch, enlarge and offset; update measurement
  labels after an edit; keep spot coordinates on recalculation; fix typed
  shape dimensions; undo for an interrupted enlarge preview; offset copies
  through the duplication primitive.
- Flattened copy (OpenAEC-Foundation#542): keep hidden layers hidden and warn about form
  field values before saving.
- Add Text (OpenAEC-Foundation#543): only move the start point when the text does not fit.
- Translations: every key that exists in English is now translated in all
  39 other languages, including the backlog of earlier releases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants