merge origin/main: unify our web branch with 277 upstream commits

Conflicts resolved as unions of behavior wherever possible:

- #1350 (set_properties numeric CAS): kept our stricter
  json_values_match (guards u64>f64 precision loss); upstream's
  duplicate removed.
- #1351 (web open-from-bytes): our implementation wins (guarded
  queue, settle semantics, protocol 2) using upstream's validation
  helper so both sides' tests pass.
- #1358/#1359 (Windows printer routing/media): merged both engines —
  upstream's route planning, media tables, GDI raster path and driver
  options on top of our level-2 enumeration fallback, true-default
  resolution, quoted printto params, existence probe, and error
  descriptions.
- #1360 (plot-style leniency): decompress_ctb now carries both our
  CTBVER1/STBVER1 container tags and structured flag, and upstream's
  lenient reader with Windows-1252 handling.
- 3D snapping precedence: upstream's F4 3D osnap system takes
  precedence over our #1030 solid edge wires when the mesh cache has
  geometry edges; our wires remain the fallback for triangle-only
  caches and mesh entities (both test suites pass).
- Fixed upstream-side bugs surfaced by the merge: parametric arc
  grips impl/test contradiction, psetupin test path separators, and
  our pdf_raster regression where the new dpi argument was threaded
  but ignored (GDI 300-DPI would have cached at 150).
- ocs_save repinned to the upstream acadrust rev; docs/command-
  reference.md regenerated (the staleness test caught it).
This commit is contained in:
Afonsop committed 2026-09-21 13:33:39 +01:00
commit 55e3a6a9e2
323 files changed
+82297 -4351

No files matched your search

+149
View File
@@ -0,0 +1,149 @@
// Regression: text INSIDE a block must reach the GPU at neutral vertex depth
// with its composed child rank carried in `WireModel::depth_override`, so the
// upload resolves it against the insert's scene-graph entry
// (depths[insert] + override * half) — the same composition the wipeout/hatch
// fills get. Baking the raw per-block rank into the vertices instead sinks
// text with a negative rank below its own block's wipes (the "G-3" mark
// labels of BS33-11) and catapults text with a positive rank above later
// draw-order geometry.
//
// The scene mirrors the real-world shape of the bug: a block whose children
// are [wipeout, line, text], inserted into a drawing big enough that the
// insert's child band is as fine-grained as a real one.
use acadrust::entities::{Insert, Text, Wipeout};
use acadrust::tables::BlockRecord;
use acadrust::types::Vector3;
use acadrust::EntityType;
use OpenCADStudio::scene::cache::block_cache::{expand_insert, BlockCache};
use OpenCADStudio::scene::view::render::InheritStyle;
use OpenCADStudio::scene::Scene;
use OpenCADStudio::scene::WireModel;
const DRAW_ORDER_BIAS: f32 = 0.001;
const DEPTH_QUANTA: f32 = 16_777_216.0; // 2^24 (Depth24Plus)
#[test]
fn block_text_depth_composes_through_the_instance_path() {
let mut scene = Scene::new();
let br_h = acadrust::Handle::new(scene.document.next_handle());
let mut br = BlockRecord::new("MARK");
br.handle = br_h;
scene.document.block_records.add(br).unwrap();
// Child 0: the wipeout the text is drawn after (the text must win).
let mut wipe = Wipeout::new();
wipe.insertion_point = Vector3::new(-10.0, -10.0, 0.0);
wipe.u_vector = Vector3::new(20.0, 0.0, 0.0);
wipe.v_vector = Vector3::new(0.0, 20.0, 0.0);
let mut wipe_e = EntityType::Wipeout(wipe);
wipe_e.common_mut().owner_handle = br_h;
let wipe_handle = scene.document.add_entity(wipe_e).unwrap();
// Child 1: a spacer so the text sits two sibling steps above the wipe,
// the same gap as the real BS33-11 mark blocks.
let mut spacer = acadrust::entities::Line::default();
spacer.start = Vector3::new(-10.0, -10.0, 0.0);
spacer.end = Vector3::new(10.0, 10.0, 0.0);
let mut spacer_e = EntityType::Line(spacer);
spacer_e.common_mut().owner_handle = br_h;
let _ = scene.document.add_entity(spacer_e).unwrap();
// Child 2: the text.
let mut txt = Text::new();
txt.value = "G-3".to_string();
txt.height = 2.5;
txt.insertion_point = Vector3::new(0.0, 0.0, 0.0);
let mut txt_e = EntityType::Text(txt);
txt_e.common_mut().owner_handle = br_h;
let text_handle = scene.document.add_entity(txt_e).unwrap();
// A large model space, so the insert's child band compresses to the
// fine granularity real drawings have (~600 top-level entities puts the
// per-sibling spacing at a handful of 24-bit quanta, where an oversized
// wipeout depth bias would swallow it).
for i in 0..600 {
let mut line = acadrust::entities::Line::default();
line.start = Vector3::new(f64::from(i) * 10.0 - 3000.0, -50.0, 0.0);
line.end = Vector3::new(f64::from(i) * 10.0 - 3000.0, 50.0, 0.0);
let _ = scene.document.add_entity(EntityType::Line(line));
}
let ins = Insert::new("MARK", Vector3::new(0.0, 0.0, 0.0));
let ins_handle = scene.add_entity(EntityType::Insert(ins));
let depths = scene.draw_depth_map();
let [ins_d, ins_half] = depths
.get(&ins_handle.value())
.copied()
.expect("insert must be ranked");
let text_label = depths
.get(&text_handle.value())
.expect("block children must be ranked")[0];
let wipe_label = depths.get(&wipe_handle.value()).expect("wipe ranked")[0];
assert!(
text_label > wipe_label,
"precondition: the drawing orders the text after the wipeout"
);
let cache = BlockCache::build(
&scene.document, 1.0, None, true, [0.0, 0.0, 0.0, 1.0], None, &depths,
);
let wires = expand_insert(
&scene.document, &cache, &Insert::new("MARK", Vector3::new(0.0, 0.0, 0.0)),
ins_handle,
[1.0, 1.0, 1.0, 1.0], 0, 0.0, [0.0; 8], 1.0,
InheritStyle { color: [1.0, 1.0, 1.0, 1.0], pat_len: 0.0, pat: [0.0; 8], lw_px: 1.0 },
0, false, false, 1.0, None, None, false, [0.0, 0.0, 0.0, 1.0], 1.0,
OpenCADStudio::scene::BlockScalePolicy::FromInsert, false,
)
.expect("block defn cached");
let text_wires: Vec<&WireModel> =
wires.iter().filter(|w| !w.text_verts.is_empty()).collect();
assert!(
!text_wires.is_empty(),
"block TEXT must tessellate into glyph quads"
);
// The wire is named after its insert (decimal handle), and the upload
// resolves that name against the depth map: this is the composition the
// GPU finally sees.
for w in &text_wires {
assert!(
w.text_verts.iter().all(|v| v.draw_depth == 0.0),
"glyph vertices must stay at neutral depth; the instance path owns it"
);
assert_eq!(
w.depth_override,
Some(text_label),
"the wire must carry the text's child rank as its depth override"
);
let resolved = w
.name
.parse::<u64>()
.ok()
.and_then(|h| depths.get(&h).copied());
let instance = match (resolved, w.depth_override) {
(Some([d, half]), Some(local)) => d + local * half,
(Some([d, _]), None) => d,
_ => 0.0,
};
assert_eq!(
instance,
ins_d + text_label * ins_half,
"instance depth must compose to depths[insert] + label * half"
);
// The wipeout mask, composed the same way the scene graph does it.
let mask = ins_d + wipe_label * ins_half;
let margin_quanta =
(instance - mask) * DRAW_ORDER_BIAS * DEPTH_QUANTA;
let bias = OpenCADStudio::scene::pipeline::WIPEOUT_DEPTH_BIAS_QUANTA as f32;
assert!(
margin_quanta > bias + 2.0,
"text drawn after its block's wipeout must clear it by more than \
the wipeout depth bias plus headroom, got {margin_quanta} quanta"
);
}
}
+10
View File
@@ -0,0 +1,10 @@
# Viewport association fixture
`viewport_associations.dxf` contains line, circle, arc, polyline, spline,
block-instance, and intersection references through a 1:2 viewport.
`src/app/viewport_dimension_tests.rs` tests refresh and intersection source edits.
Each dimension stores `DIMLFAC=-2` and `ACAD_DIMASSOC_CALC_DIMLFAC=-2` so its paper
definition points measure in model units. The spline tangent from `(0, 300)`
touches `(90, 283.125)` at parameter `0.75`; tests verify its tangency and preserve
the dimension if an edited reference cannot resolve.
File diff suppressed because it is too large. Load diff
+29
View File
@@ -0,0 +1,29 @@
Page-setup fixtures saved by a commercial CAD application (2016 release, DXF
AC1027 and the matching DWG). Provided by Panos for the plotting parity track;
the drawing holds one 10 m line (`$INSUNITS` = 6, metres) and three paper
layouts, each with a viewport of that line and its dimension:
| Layout | Device | Media (`4`) | `44`×`45` | `73` | `72` | `142`/`143` | `147` | `75` |
|---|---|---|---|---|---|---|---|---|
| `A4 1-100` | `DWG To PDF.pc3` | `ISO_A4_(297.00_x_210.00_MM)` | 297 × 210 | 0 | mm | 1 / 1 | 25.4 | 16 |
| `A3 - plotter` | system printer `HPB602DE (HP OfficeJet Pro 7740 series)` | `A3` | 297.01 × 419.99 | 1 | mm | 1 / 1 | 25.4 | 16 |
| `ARCH D - PLOTTER` | the application's second PDF plotter configuration (`… PDF (High Quality Print).pc3`) | `ARCH_D_(36.00_x_24.00_Inches)` | 914.4 × 609.6 | 0 | in | 1 / 25.4 | 0.03937 | 16 |
What the file establishes (see `src/app/update/file.rs`, `plot_settings_from_dialog`):
- A landscape sheet is written either as the driver's own landscape medium
with rotation 0 (the PDF driver lists both orientations) or as a portrait
medium with rotation 90 (system printers) — rotation is relative to the
medium's orientation, and the medium's exact driver dimensions are kept.
- Margins (`40`–`43`, mm) belong to the medium's own edges: the PDF driver's
A4 has 5.79375 left/right and 17.79375 bottom/top. Layout limits (`10`/`20`)
put the sheet at minus the *displayed* margins: at rotation 90 the medium's
top margin (20.02) becomes the layout's left one, its left margin (5.00) the
layout's bottom one.
- Plot flags `70` = 672 on every layout: draw viewports first, print
lineweights, plot with plot styles — the "use standard scale" bit stays clear
even with a standard code in `75`; the model tab (fit to paper) sets it.
- `147` is `142/143` × 25.4 on millimetre page setups and `142/143` itself on
inch ones.
- An inch page setup over a millimetre paper space stores "1:1" as
`1 in = 25.4 units` (`75` = 16 kept).
Binary file not shown.
File diff suppressed because it is too large. Load diff
+3 -1
View File
@@ -1,8 +1,10 @@
const STORAGE_SHADER: &str = include_str!("../src/shaders/hatch.wgsl");
const TEXTURE_SHADER: &str = include_str!("../src/shaders/hatch_texture.wgsl");
const DRAW_ORDER_SHADER: &str = include_str!("../src/shaders/draw_order.wgsl");
fn assert_all_family_lod(source: &str, name: &str) {
let module = naga::front::wgsl::parse_str(source)
let composed = format!("{DRAW_ORDER_SHADER}\n{source}");
let module = naga::front::wgsl::parse_str(&composed)
.unwrap_or_else(|error| panic!("{name} WGSL must parse: {error}"));
naga::valid::Validator::new(
naga::valid::ValidationFlags::all(),
+4 -2
View File
@@ -1,11 +1,13 @@
#[test]
fn adaptive_text_sampling_passes_derivative_uniformity_validation() {
let draw_order = include_str!("../src/shaders/draw_order.wgsl");
for (name, source) in [
("text", include_str!("../src/shaders/text.wgsl")),
("block text", include_str!("../src/shaders/block_text.wgsl")),
] {
let module = naga::front::wgsl::parse_str(source)
.unwrap_or_else(|error| panic!("{name}: {}", error.emit_to_string(source)));
let composed = format!("{draw_order}\n{source}");
let module = naga::front::wgsl::parse_str(&composed)
.unwrap_or_else(|error| panic!("{name}: {}", error.emit_to_string(&composed)));
naga::valid::Validator::new(
naga::valid::ValidationFlags::all(),
naga::valid::Capabilities::empty(),
+80
View File
@@ -0,0 +1,80 @@
//! `UCS FACE` turns a pick on a solid into a drawing plane. The plane is only
//! as good as the face lookup underneath it, so this covers that half: given a
//! body and a point on one of its faces, does the right face come back, and is
//! its outward normal the one a sketch should be built on?
//!
//! The axis construction on top of that normal is unit-tested beside
//! `ucs_from_normal` in `src/app/helpers.rs`, which is `pub(crate)` and so out
//! of reach from here.
use acadrust::{entities::Circle, types::Vector3, EntityType};
use OpenCADStudio::scene::model::{presspull_model, solid_model};
/// Extrude a disc into a puck 10 units tall, centred on the origin.
fn puck() -> cadkernel::brep::Body {
let entity = EntityType::Circle(Circle::from_center_radius(
Vector3::new(0.0, 0.0, 0.0),
100.0,
));
let body = presspull_model::extrusion_body(&entity, [0.0, 0.0, 10.0])
.expect("a closed circular profile extrudes");
assert!(body.validate().is_empty(), "extrusion produced a valid body");
body
}
/// The two flat ends point away from the material, in opposite directions.
/// Getting this wrong is what would make a sketch land inside the solid, or
/// extrude back into it.
#[test]
fn opposite_faces_report_opposite_outward_normals() {
let body = puck();
let top = solid_model::nearest_planar_face(&body, [0.0, 0.0, 10.0])
.expect("the top cap is planar");
let bottom = solid_model::nearest_planar_face(&body, [0.0, 0.0, 0.0])
.expect("the bottom cap is planar");
assert_ne!(top, bottom, "the caps are distinct faces");
let top_normal = solid_model::planar_face_normal(&body, top).expect("top cap has a normal");
let bottom_normal =
solid_model::planar_face_normal(&body, bottom).expect("bottom cap has a normal");
assert!(
(top_normal[2] - 1.0).abs() < 1e-9,
"top cap should point +Z, got {top_normal:?}"
);
assert!(
(bottom_normal[2] + 1.0).abs() < 1e-9,
"bottom cap should point -Z, got {bottom_normal:?}"
);
}
/// A pick anywhere on a cap resolves to that cap, not merely to the one
/// nearest the origin. A sketch is started by clicking somewhere on a face,
/// rarely at its centre.
#[test]
fn an_off_centre_pick_still_lands_on_its_own_face() {
let body = puck();
let centre = solid_model::nearest_planar_face(&body, [0.0, 0.0, 10.0]).unwrap();
let off_centre = solid_model::nearest_planar_face(&body, [60.0, -25.0, 10.0]).unwrap();
assert_eq!(centre, off_centre, "both picks are on the top cap");
}
/// The curved side is not a plane, so it cannot become a sketch plane. The
/// lookup has to decline rather than hand back a nonsense normal.
#[test]
fn the_curved_side_is_not_offered_as_a_plane() {
let body = puck();
// Halfway up the barrel, on its surface.
let face = solid_model::nearest_planar_face(&body, [100.0, 0.0, 5.0]);
if let Some(face) = face {
// A planar cap may still be the nearest planar face; what must never
// happen is the barrel itself being reported as planar.
let normal = solid_model::planar_face_normal(&body, face)
.expect("whatever came back claims to be planar, so it has a normal");
assert!(
normal[2].abs() > 1e-9,
"a cap normal has Z; a barrel wall wrongly called planar would not"
);
}
}