fix(mleader): repair creation and editing

This commit is contained in:
Hakan Seven committed 2026-08-28 19:36:48 +03:00
commit ff1f873633
40 files changed
+4504 -1754

No files matched your search

+137 -57
View File
@@ -1502,54 +1502,113 @@ pub fn apply_mleader_style(
entity: &mut acadrust::entities::MultiLeader,
style: &acadrust::objects::MultiLeaderStyle,
) {
use acadrust::entities::MultiLeaderPropertyOverrideFlags as F;
let flags = entity.property_override_flags;
entity.style_handle = Some(style.handle);
entity.content_type = (style.content_type as i16).into();
entity.path_type = (style.path_type as i16).into();
entity.line_color = style.line_color;
entity.line_type_handle = style.line_type_handle;
entity.line_weight = style.line_weight;
entity.enable_landing = style.enable_landing;
entity.enable_dogleg = style.enable_dogleg;
entity.dogleg_length = style.landing_distance;
entity.arrowhead_handle = style.arrowhead_handle;
entity.arrowhead_size = style.arrowhead_size;
entity.context.arrowhead_size = style.arrowhead_size;
entity.context.landing_gap = style.landing_gap;
entity.text_style_handle = style.text_style_handle;
entity.text_color = style.text_color;
entity.text_frame = style.text_frame;
entity.text_height = style.text_height;
entity.context.text_height = style.text_height;
entity.context.text_style_handle = style.text_style_handle;
entity.context.text_color = style.text_color;
entity.text_left_attachment = (style.text_left_attachment as i16).into();
entity.text_right_attachment = (style.text_right_attachment as i16).into();
entity.text_top_attachment = (style.text_top_attachment as i16).into();
entity.text_bottom_attachment = (style.text_bottom_attachment as i16).into();
entity.text_attachment_direction = (style.text_attachment_direction as i16).into();
entity.text_alignment = (style.text_alignment as i16).into();
entity.text_angle_type = (style.text_angle_type as i16).into();
if !flags.contains(F::CONTENT_TYPE) {
entity.content_type = (style.content_type as i16).into();
}
if !flags.contains(F::PATH_TYPE) {
entity.path_type = (style.path_type as i16).into();
}
if !flags.contains(F::LINE_COLOR) {
entity.line_color = style.line_color;
}
if !flags.contains(F::LEADER_LINE_TYPE) {
entity.line_type_handle = style.line_type_handle;
}
if !flags.contains(F::LEADER_LINE_WEIGHT) {
entity.line_weight = style.line_weight;
}
if !flags.contains(F::ENABLE_LANDING) {
entity.enable_landing = style.enable_landing;
}
if !flags.contains(F::ENABLE_DOGLEG) {
entity.enable_dogleg = style.enable_dogleg;
}
if !flags.contains(F::LANDING_DISTANCE) {
entity.dogleg_length = style.landing_distance;
}
if !flags.contains(F::LANDING_GAP) {
entity.context.landing_gap = style.landing_gap;
}
if !flags.contains(F::ARROWHEAD) {
entity.arrowhead_handle = style.arrowhead_handle;
}
if !flags.contains(F::ARROWHEAD_SIZE) {
entity.arrowhead_size = style.arrowhead_size;
entity.context.arrowhead_size = style.arrowhead_size;
}
if !flags.contains(F::TEXT_STYLE) {
entity.text_style_handle = style.text_style_handle;
}
if !flags.contains(F::TEXT_COLOR) {
entity.text_color = style.text_color;
}
if !flags.contains(F::TEXT_FRAME) {
entity.text_frame = style.text_frame;
}
if !flags.contains(F::TEXT_HEIGHT) {
entity.text_height = style.text_height;
entity.context.text_height = style.text_height;
}
if !flags.contains(F::TEXT_LEFT_ATTACHMENT) {
entity.text_left_attachment = (style.text_left_attachment as i16).into();
}
if !flags.contains(F::TEXT_RIGHT_ATTACHMENT) {
entity.text_right_attachment = (style.text_right_attachment as i16).into();
}
if !flags.contains(F::TEXT_TOP_ATTACHMENT) {
entity.text_top_attachment = (style.text_top_attachment as i16).into();
}
if !flags.contains(F::TEXT_BOTTOM_ATTACHMENT) {
entity.text_bottom_attachment = (style.text_bottom_attachment as i16).into();
}
if !flags.contains(F::TEXT_ATTACHMENT_DIRECTION) {
entity.text_attachment_direction = (style.text_attachment_direction as i16).into();
}
if !flags.contains(F::TEXT_ALIGNMENT) {
entity.text_alignment = (style.text_alignment as i16).into();
}
if !flags.contains(F::TEXT_ANGLE) {
entity.text_angle_type = (style.text_angle_type as i16).into();
}
entity.context.text_left_attachment = entity.text_left_attachment;
entity.context.text_right_attachment = entity.text_right_attachment;
entity.context.text_top_attachment = entity.text_top_attachment;
entity.context.text_bottom_attachment = entity.text_bottom_attachment;
entity.context.text_alignment = entity.text_alignment;
entity.block_content_handle = style.block_content_handle;
entity.block_content_color = style.block_content_color;
entity.block_connection_type = (style.block_content_connection as i16).into();
entity.block_rotation = style.block_content_rotation;
entity.block_scale = Vector3::new(
style.block_content_scale_x,
style.block_content_scale_y,
style.block_content_scale_z,
);
entity.scale_factor = style.scale_factor;
entity.context.block_content_handle = style.block_content_handle;
entity.context.block_content_color = style.block_content_color;
entity.context.text_style_handle = entity.text_style_handle;
entity.context.text_color = entity.text_color;
if !flags.contains(F::BLOCK_CONTENT) {
entity.block_content_handle = style.block_content_handle;
}
if !flags.contains(F::BLOCK_CONTENT_COLOR) {
entity.block_content_color = style.block_content_color;
}
if !flags.contains(F::BLOCK_CONTENT_CONNECTION) {
entity.block_connection_type = (style.block_content_connection as i16).into();
}
if !flags.contains(F::BLOCK_CONTENT_ROTATION) {
entity.block_rotation = style.block_content_rotation;
}
if !flags.contains(F::BLOCK_CONTENT_SCALE) {
entity.block_scale = Vector3::new(
style.block_content_scale_x,
style.block_content_scale_y,
style.block_content_scale_z,
);
}
if !flags.contains(F::SCALE_FACTOR) {
entity.scale_factor = style.scale_factor;
entity.context.scale_factor = style.scale_factor;
}
entity.context.block_content_handle = entity.block_content_handle;
entity.context.block_content_color = entity.block_content_color;
entity.context.block_connection_type = entity.block_connection_type;
entity.context.block_rotation = style.block_content_rotation;
entity.context.block_rotation = entity.block_rotation;
entity.context.block_content_scale = entity.block_scale;
entity.context.scale_factor = style.scale_factor;
entity.enable_annotation_scale = style.is_annotative;
match entity.content_type {
acadrust::entities::LeaderContentType::MText => {
@@ -1567,7 +1626,9 @@ pub fn apply_mleader_style(
}
}
for root in &mut entity.context.leader_roots {
root.landing_distance = style.landing_distance;
if !flags.contains(F::LANDING_DISTANCE) {
root.landing_distance = entity.dogleg_length;
}
root.text_attachment_direction = entity.text_attachment_direction;
for line in &mut root.lines {
use acadrust::entities::LeaderLinePropertyOverrideFlags as F;
@@ -1575,19 +1636,19 @@ pub fn apply_mleader_style(
line.path_type = entity.path_type;
}
if !line.override_flags.contains(F::LINE_COLOR) {
line.line_color = style.line_color;
line.line_color = entity.line_color;
}
if !line.override_flags.contains(F::LINE_TYPE) {
line.line_type_handle = style.line_type_handle;
line.line_type_handle = entity.line_type_handle;
}
if !line.override_flags.contains(F::LINE_WEIGHT) {
line.line_weight = style.line_weight;
line.line_weight = entity.line_weight;
}
if !line.override_flags.contains(F::ARROWHEAD) {
line.arrowhead_handle = style.arrowhead_handle;
line.arrowhead_handle = entity.arrowhead_handle;
}
if !line.override_flags.contains(F::ARROWHEAD_SIZE) {
line.arrowhead_size = style.arrowhead_size;
line.arrowhead_size = entity.arrowhead_size;
}
}
}
@@ -1597,6 +1658,16 @@ fn apply_mleader_style_at_display_scale(
style: &acadrust::objects::MultiLeaderStyle,
display_scale: f64,
) {
use acadrust::entities::MultiLeaderPropertyOverrideFlags as F;
let old_scale = entity.context.scale_factor.max(1.0e-12);
let landing_gap = entity.context.landing_gap / old_scale;
let landing_distances = entity
.context
.leader_roots
.iter()
.map(|root| root.landing_distance / old_scale)
.collect::<Vec<_>>();
apply_mleader_style(entity, style);
let scale = if display_scale.is_finite()
@@ -1610,18 +1681,27 @@ fn apply_mleader_style_at_display_scale(
// Context sizes are stored at their display scale.
entity.context.scale_factor = scale;
entity.context.text_height =
style.text_height * scale;
entity.context.text_height = entity.text_height * scale;
entity.context.arrowhead_size = entity.arrowhead_size * scale;
entity.context.landing_gap = if entity.property_override_flags.contains(F::LANDING_GAP) {
landing_gap * scale
} else {
style.landing_gap * scale
};
entity.context.arrowhead_size =
style.arrowhead_size * scale;
entity.context.landing_gap =
style.landing_gap * scale;
for root in &mut entity.context.leader_roots {
root.landing_distance =
style.landing_distance * scale;
for (index, root) in entity.context.leader_roots.iter_mut().enumerate() {
root.landing_distance = if entity
.property_override_flags
.contains(F::LANDING_DISTANCE)
{
landing_distances
.get(index)
.copied()
.unwrap_or(entity.dogleg_length)
* scale
} else {
entity.dogleg_length * scale
};
root.text_attachment_direction =
entity.text_attachment_direction;