fix(styles): apply active creation defaults

Resolve style properties before editors and previews open.
Use absolute annotation multipliers for style-driven objects.

Refs #401

Refs #431
This commit is contained in:
Hakan Seven committed 2026-08-03 16:43:58 +03:00
1 parent 53cf31f33d
commit de2707a23e
14 files changed
+676 -129

No files matched your search

+53 -3
View File
@@ -49,7 +49,11 @@ impl OpenCADStudio {
// quick leader-plus-annotation operation.
"LEADER" | "QLEADER" => {
use crate::modules::annotate::leader_cmd::LeaderCommand;
let new_cmd = LeaderCommand::new();
let defaults = crate::scene::creation_style::current_dimension_defaults(
&self.tabs[i].scene.document,
);
let multiplier = self.tabs[i].scene.creation_annotation_multiplier();
let new_cmd = LeaderCommand::with_defaults(defaults, multiplier);
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
@@ -486,7 +490,31 @@ impl OpenCADStudio {
"MLEADER" => {
use crate::modules::annotate::mleader_cmd::MLeaderCommand;
let new_cmd = MLeaderCommand::new();
let name = self.tabs[i]
.scene
.document
.header
.current_mleader_style_name
.clone();
let style = self.tabs[i]
.scene
.document
.objects
.iter()
.find_map(|(handle, object)| match object {
acadrust::objects::ObjectType::MultiLeaderStyle(style)
if style.name.eq_ignore_ascii_case(&name) =>
{
let mut style = style.clone();
style.handle = *handle;
Some(style)
}
_ => None,
});
let multiplier = self.tabs[i].scene.creation_annotation_multiplier();
let new_cmd = style.map_or_else(MLeaderCommand::new, |style| {
MLeaderCommand::with_style(style, multiplier)
});
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
@@ -500,7 +528,29 @@ impl OpenCADStudio {
"TABLE" => {
use crate::modules::annotate::table_cmd::TableCommand;
let cmd = TableCommand::new();
let name = self.tabs[i]
.scene
.document
.header
.current_table_style_name
.clone();
let style = self.tabs[i]
.scene
.document
.objects
.iter()
.find_map(|(handle, object)| match object {
acadrust::objects::ObjectType::TableStyle(style)
if style.name.eq_ignore_ascii_case(&name) =>
{
Some((*handle, style.clone()))
}
_ => None,
});
let multiplier = self.tabs[i].scene.creation_annotation_multiplier();
let cmd = style.as_ref().map_or_else(TableCommand::new, |(handle, style)| {
TableCommand::with_style(*handle, style, multiplier)
});
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
+41 -5
View File
@@ -13,8 +13,28 @@ impl OpenCADStudio {
"MLINE" => {
use crate::modules::draw::draw::mline::MlineCommand;
let style = self.tabs[i].scene.document.header.multiline_style.clone();
let cmd_obj = MlineCommand::with_style(style);
let style_name = self.tabs[i].scene.document.header.multiline_style.clone();
let style = self.tabs[i]
.scene
.document
.objects
.iter()
.find_map(|(handle, object)| match object {
acadrust::objects::ObjectType::MLineStyle(style)
if style.name.eq_ignore_ascii_case(&style_name) =>
{
Some((*handle, style.elements.len()))
}
_ => None,
});
let (style_handle, element_count) = style
.map(|(handle, count)| (Some(handle), count))
.unwrap_or((None, 2));
let cmd_obj = MlineCommand::with_style(
style_name,
style_handle,
element_count,
);
self.command_line.push_info(&cmd_obj.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd_obj));
}
@@ -47,7 +67,15 @@ impl OpenCADStudio {
"ATTDEF" => {
use crate::modules::draw::draw::attdef::AttdefCommand;
let cmd = AttdefCommand::new();
let defaults = crate::scene::creation_style::current_text_defaults(
&self.tabs[i].scene.document,
);
let cmd = AttdefCommand::with_text_defaults(
defaults.height,
defaults.style_name,
defaults.width_factor,
defaults.oblique_angle,
);
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
@@ -1049,7 +1077,11 @@ impl OpenCADStudio {
// ── Annotate commands ──────────────────────────────────────────
"TEXT" => {
use crate::modules::annotate::text::TextCommand;
let new_cmd = TextCommand::new();
let height = crate::scene::creation_style::current_text_defaults(
&self.tabs[i].scene.document,
)
.height;
let new_cmd = TextCommand::with_height(height);
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
@@ -1080,7 +1112,11 @@ impl OpenCADStudio {
"MTEXT" => {
use crate::modules::annotate::mtext::MTextCommand;
let new_cmd = MTextCommand::new();
let height = crate::scene::creation_style::current_text_defaults(
&self.tabs[i].scene.document,
)
.height;
let new_cmd = MTextCommand::with_height(height);
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
+4 -68
View File
@@ -1848,74 +1848,10 @@ impl OpenCADStudio {
entity.common_mut().linetype_scale = celtscale;
}
// A new dimension inherits the document's current dimension style
// (DIMSTYLE) instead of staying at the entity "Standard" default. Only
// fill in when still at the default so an explicitly-styled dimension
// is preserved. See #92.
if let acadrust::EntityType::Dimension(ref mut d) = entity {
let cur = self.tabs[i]
.scene
.document
.header
.current_dimstyle_name
.clone();
let s = d.base().style_name.clone();
if (s.is_empty() || s.eq_ignore_ascii_case("Standard")) && !cur.is_empty() {
d.base_mut().style_name = cur;
}
}
// MultiLeader / Table inherit the document's current style (#92). These
// styles live in the objects dictionary, so resolve the current style
// name to its object handle. Left untouched when the command already
// assigned a style or no matching style object exists.
match &mut entity {
acadrust::EntityType::MultiLeader(ml) if ml.style_handle.is_none() => {
let name = self.tabs[i]
.scene
.document
.header
.current_mleader_style_name
.clone();
if !name.is_empty() {
let found =
self.tabs[i].scene.document.objects.iter().find_map(|(h, o)| match o {
acadrust::objects::ObjectType::MultiLeaderStyle(s)
if s.name.eq_ignore_ascii_case(&name) =>
{
Some((*h, s.clone()))
}
_ => None,
});
if let Some((h, s)) = found {
debug_assert_eq!(h, s.handle);
crate::scene::annotative::apply_mleader_style(ml, &s);
}
}
}
acadrust::EntityType::Table(t) if t.table_style_handle.is_none() => {
let name = self.tabs[i]
.scene
.document
.header
.current_table_style_name
.clone();
if !name.is_empty() {
t.table_style_handle =
self.tabs[i].scene.document.objects.iter().find_map(|(h, o)| {
match o {
acadrust::objects::ObjectType::TableStyle(s)
if s.name.eq_ignore_ascii_case(&name) =>
{
Some(*h)
}
_ => None,
}
});
}
}
_ => {}
}
crate::scene::creation_style::apply_current_creation_styles(
&self.tabs[i].scene.document,
&mut entity,
);
let text_style_annotative = match &entity {
acadrust::EntityType::Text(text) => {