Files
cadcraft/crates/engine/tests/it/dim_text_frame.rs
T
dotCooCoo 800b0319ac Dimensions: a negative DIMGAP draws a frame around the dimension text
CADCraft used only the size of DIMGAP, so a negative value (Draw Frame
Around Text on the Text tab of the Dimension Style Manager) placed the text
like a positive one and drew no frame. A dimension whose DIMGAP is below 0
now draws a rectangle around its text: the text box widened by |DIMGAP| on
every side, turned with the text, as four dimension lines in DIMCLRD. On an
arc-length dimension with DIMARCSYM 1 the frame also takes in the arc
symbol over the text. The frame is one of the dimension's lines, so the
screen, plots and PDF draw it, the dimension's *D block holds it, and
EXPLODE turns it into four LINEs. No help page says how this frame combines
with a DIMINSPECT frame; CADCraft draws an inspection frame with round or
angular ends in place of the DIMGAP frame.

The arc symbol over the text now turns with a DIMTEDIT text angle. It was
placed at the angle from before the override, so the text turned and the
symbol did not.
2026-10-24 19:17:58 -07:00

31 lines
1.4 KiB
Rust

//! A negative DIMGAP draws a frame around the dimension text: SETVAR takes the negative value, a
//! new dimension draws the frame, and EXPLODE turns it into four lines.
use cadcraft_engine::Session;
use cadcraft_engine::doc::{EntityKind, Handle};
use serde_json::json;
/// Draw a linear dimension with DIMGAP `gap`, explode it, and return the number of lines the
/// dimension drew and the number of LINEs EXPLODE left.
fn explode_with_gap(gap: f64) -> (usize, usize) {
let mut s = Session::new();
s.execute("setvar", &json!({ "name": "DIMGAP", "value": gap })).unwrap();
let r = s.execute("dimlinear", &json!({ "p1": [0, 0], "p2": [30, 0], "at": [15, 5] })).unwrap();
let h = Handle::parse_hex(r["handle"].as_str().unwrap()).unwrap();
let drawn = match &s.doc().unwrap().entity(h).unwrap().kind {
EntityKind::Dimension(dm) => cadcraft_engine::render::dimension_in(s.doc().unwrap(), dm).lines.len(),
k => panic!("not a dimension: {k:?}"),
};
s.execute("explode", &json!({ "handles": [h.hex()] })).unwrap();
let lines = s.doc().unwrap().model.iter().filter(|e| matches!(e.kind, EntityKind::Line(_))).count();
(drawn, lines)
}
#[test]
fn negative_dimgap_frame_is_drawn_and_exploded() {
let (plain_drawn, plain_lines) = explode_with_gap(0.09);
let (drawn, lines) = explode_with_gap(-0.09);
assert_eq!(drawn, plain_drawn + 4);
assert_eq!(lines, plain_lines + 4);
}