Measure paper-space dimensions through the viewport they were picked in

DIMLINEAR / DIMALIGNED / DIMRADIUS / DIMDIAMETER / DIMANGULAR created on a
sheet now report the model measurement of the geometry seen through a
viewport, at any viewport scale, while definition points, the dimension line
and the text stay in paper coordinates and the annotation keeps its sheet
size (DIMSCALE is untouched).

A viewport frame is a similarity - uniform scale plus in-plane twist - so
projecting the model span onto the paper axis and compensating gives exactly
the raw paper measurement times 1/scale. No geometry is rewritten: the
compensation is persisted once as a negative DIMLFAC override on the
dimension and applied once by the linear formatter, so preview text,
dimension text, the properties measurement row and DXF/DWG export all agree.
User measurement multipliers fold into the same magnitude, and an explicit
text override still bypasses formatting entirely, so it is never re-scaled.
Angular dimensions are never compensated - a similarity preserves angles.

Mixed input (one point through viewport A, another through viewport B or on
the sheet) is refused rather than silently mis-measured: the command line
explains why and the dimension falls back to plain paper measurement.

A dimension measured through a viewport is left unassociated: its definition
points are projected paper coordinates, so inferring a paper-space
association would bind it to geometry that is not there. PR3 records the real
dimension -> viewport -> entity chain.

The result is one ordinary dimension entity carrying one style override, so
undo/redo works through the existing history with no new out-of-document
state.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
Christopher OverbeckandClaude Fable 5.1 committed 2026-09-15 12:40:44 -05:00
1 parent 9ee809d389
commit 30c5ccbba1
10 files changed
+395 -1

No files matched your search

+22 -1
View File
@@ -454,6 +454,17 @@ impl OpenCADStudio {
}
}
if matches!(&input, StepInput::Point(_)) { self.refresh_command_point_pick_context(i); }
// PR2: remember which viewport (if any) each dimension point was
// picked through, before the command turns it into geometry.
if let StepInput::Point(p) = &input {
if self.tabs[i]
.active_cmd
.as_ref()
.is_some_and(|command| command.measures_through_viewports())
{
self.record_dimension_accepted_snap(i, *p);
}
}
let ctrl = self.ctrl_down;
let shift = self.shift_down;
let result: Option<CmdResult> = {
@@ -2106,6 +2117,15 @@ impl OpenCADStudio {
acadrust::entities::Dimension::Ordinate(_)
)
);
// PR2: a dimension placed on the sheet but measuring model
// geometry through a viewport carries the compensation as a
// negative DIMLFAC override. It is deliberately *not*
// associated: its definition points are projected paper
// coordinates, so inferring a paper-space association would
// bind it to geometry that is not there. PR3 records the real
// dimension -> viewport -> entity chain.
let measured_through_viewport =
self.apply_viewport_dimension_measurement(i, &mut entity);
let inherited_dimension = if preserve_base_style {
match &entity {
acadrust::EntityType::Dimension(dimension) => Some((
@@ -2172,7 +2192,7 @@ impl OpenCADStudio {
entity,
preserve_base_style,
) {
if association_mode == 2 {
if association_mode == 2 && !measured_through_viewport {
let mut changes = vec![
(handle, crate::scene::ChangeKind::Modified),
];
@@ -2216,6 +2236,7 @@ impl OpenCADStudio {
self.tabs[i].dirty = true;
self.tabs[i].scene.clear_preview_wire();
self.tabs[i].snap_result = None;
self.clear_dimension_accepted_snaps();
if let Some(pd) = pending {
self.commit_undo_delta(i, pd);
}