forked from 1b-agent/opencadstudio-upstream
feat(styles): green ✓ for current style + resolve it from DWG files
- The current-style marker is now a green ✓ in its own fixed-width column so names stay aligned; rendered as a separate coloured glyph rather than baked into the label string. - Resolve the current text / dimension / multiline style from the handle the DWG header stores into the name the app reads (fix_current_style_names on load). DXF already provides these as names ($TEXTSTYLE / $DIMSTYLE / $CMLSTYLE); DWG only stores handles, so the marker previously always fell back to "Standard". Only overrides when the handle resolves. Note: table and multileader current styles are not surfaced by the file reader (no header name/handle exposed), so those markers still default to the app's active selection until acadrust exposes them. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
885bacd0f6
commit
b3ba3a53d1
3 files changed
+56
-13
No files matched your search
@@ -99,6 +99,7 @@ pub fn load_file(path: &Path) -> Result<CadDocument, String> {
|
||||
.read()
|
||||
.map_err(|e| e.to_string())?;
|
||||
fix_viewport_status_flags(&mut doc);
|
||||
fix_current_style_names(&mut doc);
|
||||
Ok(doc)
|
||||
}
|
||||
"dxf" => {
|
||||
@@ -108,6 +109,7 @@ pub fn load_file(path: &Path) -> Result<CadDocument, String> {
|
||||
.map_err(|e| e.to_string())?;
|
||||
fix_dxf_dimension_rotations(&mut doc);
|
||||
fix_viewport_status_flags(&mut doc);
|
||||
fix_current_style_names(&mut doc);
|
||||
Ok(doc)
|
||||
}
|
||||
_ => Err(format!("Unsupported file format: .{ext}")),
|
||||
@@ -235,6 +237,38 @@ pub fn save(doc: &CadDocument, path: &Path) -> Result<(), String> {
|
||||
|
||||
// ── Post-load fixups ──────────────────────────────────────────────────────
|
||||
|
||||
// Resolve the current text / dimension / multiline style from the handle the
|
||||
// DWG header stores into the *name* the app reads. DXF stores these as names
|
||||
// directly ($TEXTSTYLE / $DIMSTYLE / $CMLSTYLE), but DWG only stores handles,
|
||||
// so without this the current-style markers (and any code keyed on the name)
|
||||
// fall back to "Standard". Only overrides when the handle resolves, leaving the
|
||||
// DXF-provided names intact.
|
||||
fn fix_current_style_names(doc: &mut CadDocument) {
|
||||
use acadrust::objects::ObjectType;
|
||||
|
||||
let h = doc.header.current_text_style_handle;
|
||||
if h.is_valid() {
|
||||
if let Some(name) = doc.text_styles.iter().find(|s| s.handle == h).map(|s| s.name.clone()) {
|
||||
doc.header.current_text_style_name = name;
|
||||
}
|
||||
}
|
||||
let h = doc.header.current_dimstyle_handle;
|
||||
if h.is_valid() {
|
||||
if let Some(name) = doc.dim_styles.iter().find(|s| s.handle == h).map(|s| s.name.clone()) {
|
||||
doc.header.current_dimstyle_name = name;
|
||||
}
|
||||
}
|
||||
let h = doc.header.current_multiline_style_handle;
|
||||
if h.is_valid() {
|
||||
if let Some(name) = doc.objects.values().find_map(|o| match o {
|
||||
ObjectType::MLineStyle(s) if s.handle == h => Some(s.name.clone()),
|
||||
_ => None,
|
||||
}) {
|
||||
doc.header.multiline_style = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Corrupt-entity guard ──────────────────────────────────────────────────
|
||||
//
|
||||
// acadrust's DWG parser occasionally desynchronises on certain files and
|
||||
|
||||
Reference in new issue
Block a user