mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-14 14:26:45 -04:00
* Multiline attributes: read, draw and save their text A multiline attribute (DXF attribute type 2, or 4 for a definition) has its text as embedded MTEXT after its own groups (`101 Embedded Object`); its own group 1 is empty. CADCraft read only the own groups, so the attribute drew nothing, and a save wrote it back empty: its text was lost. - `Attrib::multiline` keeps the multiline text; `text.value` holds its plain text, which ATTEDIT and the other value editors change; an edited value replaces the contents (`Attrib::multiline_text`). - DXF read: ATTRIB and ATTDEF split at the marker; the MTEXT parsing is shared with MTEXT entities (`mtext_from`). - Drawn as multiline text; ZOOM Extents counts it. - DXF write (2007 and later; earlier versions get one line): attribute type, alignment point and the embedded MTEXT, only what differs from unrotated text, as AutoCAD writes it. - INSERT and ATTSYNC give references the definition's multiline text placed with them; MOVE/ROTATE/SCALE, Properties rotation and scale, annotative scaling and FLATTEN carry it. - Tests: synthetic multiline ATTDEF and ATTRIB (read, drawn, saved, edited, pre-2007 save, damaged embedded groups); engine INSERT, MOVE, ATTEDIT and ATTSYNC. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Multiline attributes: read MTEXT direction from its own groups (#667, as #834 does) #834 moves these lines' fix into the MTEXT reader; the same fix in the shared mtext_from keeps the two compatible. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Attributes keep Verify, Preset and Lock position ATTDEF/ATTRIB flags 4 (verify) and 8 (preset) and Lock position (group 280 after the tag, DXF 2007 and later) were dropped on save. Without Lock position AutoCAD lets an attribute be dragged out of its reference, and its dynamic block actions no longer carry it. A reference's attributes take Lock position from their definitions, as AutoCAD saves them. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Cody Vogt <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Brandon Thomas <[email protected]>
48 lines
1.7 KiB
Rust
48 lines
1.7 KiB
Rust
//! A reference's attributes take Lock position from their definitions; Verify and Preset stay
|
|
//! with the definitions (as AutoCAD saves them).
|
|
|
|
use std::sync::Arc;
|
|
|
|
use cadcraft_engine::Session;
|
|
use cadcraft_engine::doc::{Attrib, AttribModes, Block, Entity, EntityKind, Text};
|
|
use cadcraft_engine::geom::Vec3;
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn references_take_lock_position_from_the_definition() {
|
|
let mut d = cadcraft_engine::doc::Drawing::new_imperial();
|
|
let text = Text {
|
|
insert: Vec3::ZERO,
|
|
align_pt: None,
|
|
height: 2.0,
|
|
value: "X".into(),
|
|
rotation: 0.0,
|
|
width_factor: 1.0,
|
|
oblique: 0.0,
|
|
style: "Standard".into(),
|
|
halign: Default::default(),
|
|
valign: Default::default(),
|
|
};
|
|
let modes = AttribModes { verify: true, preset: true, lock_position: true };
|
|
let def = Attrib {
|
|
tag: "MARK".into(),
|
|
text,
|
|
invisible: false,
|
|
constant: false,
|
|
prompt: "Mark".into(),
|
|
props: Default::default(),
|
|
multiline: None,
|
|
modes,
|
|
};
|
|
let mut b = Block::new("TAG");
|
|
let h = d.new_handle();
|
|
b.entities.push(Entity::new(h, EntityKind::AttDef(def)));
|
|
d.blocks.insert("TAG".into(), Arc::new(b));
|
|
let mut s = Session::empty();
|
|
s.open_drawing(d, "tags", None);
|
|
let r = s.execute("insert", &json!({ "name": "TAG", "at": [10, 5] })).unwrap();
|
|
let h = cadcraft_engine::doc::Handle::parse_hex(r["handle"].as_str().unwrap()).unwrap();
|
|
let Some(EntityKind::Insert(i)) = s.doc().unwrap().entity(h).map(|e| e.kind.clone()) else { panic!("no reference") };
|
|
assert_eq!(i.attribs[0].modes, AttribModes { verify: false, preset: false, lock_position: true });
|
|
}
|