forked from 1b-agent/opencadstudio-upstream
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
9ee809d389
commit
30c5ccbba1
10 files changed
+395
-1
No files matched your search
@@ -235,6 +235,69 @@ pub fn set(doc: &mut CadDocument, handle: Handle, code: i16, value: Option<XData
|
||||
write_pairs(doc, handle, kept);
|
||||
}
|
||||
|
||||
/// Set — or, with `value: None`, clear — a single override on an entity that
|
||||
/// is **not yet in the document** (a command's pending commit), leaving the
|
||||
/// other overrides intact.
|
||||
///
|
||||
/// The document-backed [`set`] additionally registers the `ACAD` APPID; that
|
||||
/// APPID is present in every drawing OCS writes, and committing the entity
|
||||
/// goes through the normal add path, so an uncommitted write needs no
|
||||
/// document. Keeping the override on the entity means it is part of the single
|
||||
/// committed object and rides the ordinary undo/redo history.
|
||||
pub fn set_on_entity(entity: &mut EntityType, code: i16, value: Option<XDataValue>) {
|
||||
let common = entity.common_mut();
|
||||
let mut kept: Vec<(i16, XDataValue)> = pairs(&common.extended_data)
|
||||
.into_iter()
|
||||
.filter(|(c, _)| *c != code)
|
||||
.collect();
|
||||
if let Some(v) = value {
|
||||
kept.push((code, v));
|
||||
}
|
||||
|
||||
let legacy = common.extended_data.get_record("ACAD_DSTYLE").is_some()
|
||||
&& common
|
||||
.extended_data
|
||||
.get_record("ACAD")
|
||||
.is_some_and(|rec| {
|
||||
!matches!(rec.values.first(), Some(XDataValue::String(n)) if n == "DSTYLE")
|
||||
});
|
||||
let app = if legacy { "ACAD_DSTYLE" } else { "ACAD" };
|
||||
|
||||
let values = if kept.is_empty() {
|
||||
None
|
||||
} else {
|
||||
let mut vals = Vec::new();
|
||||
if !legacy {
|
||||
vals.push(XDataValue::String("DSTYLE".to_string()));
|
||||
}
|
||||
vals.push(XDataValue::ControlString("{".to_string()));
|
||||
for (code, value) in kept {
|
||||
vals.push(XDataValue::Integer16(code));
|
||||
vals.push(value);
|
||||
}
|
||||
vals.push(XDataValue::ControlString("}".to_string()));
|
||||
Some(vals)
|
||||
};
|
||||
|
||||
let mut rebuilt = ExtendedData::new();
|
||||
for record in common.extended_data.records() {
|
||||
if record.application_name != app
|
||||
&& !(!legacy && record.application_name == "ACAD_DSTYLE")
|
||||
{
|
||||
rebuilt.add_record(record.clone());
|
||||
}
|
||||
}
|
||||
if let Some(vals) = values {
|
||||
let mut record = acadrust::xdata::ExtendedDataRecord::new(app);
|
||||
for v in vals {
|
||||
record.add_value(v);
|
||||
}
|
||||
rebuilt.add_record(record);
|
||||
}
|
||||
rebuilt.raw_dwg_eed = common.extended_data.raw_dwg_eed.clone();
|
||||
common.extended_data = rebuilt;
|
||||
}
|
||||
|
||||
pub fn property_real_code(field: &str) -> Option<i16> {
|
||||
Some(match field {
|
||||
"dim_arrow_size" => DIMASZ,
|
||||
|
||||
Reference in new issue
Block a user