fix(offset): preserve source entity layer

This commit is contained in:
gianlucafiore committed 2026-09-03 16:33:03 -03:00
1 parent 611ea0696b
commit 5ed508ce76
4 files changed
+44 -5

No files matched your search

+14 -2
View File
@@ -840,6 +840,10 @@ impl OpenCADStudio {
fn apply_cmd_result_inner(&mut self, result: CmdResult) -> Task<Message> {
let i = self.active_tab;
let preserve_commit_layer = self.tabs[i]
.active_cmd
.as_ref()
.is_some_and(|command| command.preserve_commit_layer());
match result {
CmdResult::NeedPoint => {
// ATTEDIT finished its entity pick: hand the chosen block off to
@@ -935,7 +939,11 @@ impl OpenCADStudio {
);
let association_enabled =
self.tabs[i].scene.document.header.dimension_associativity == 2;
let committed = self.commit_entity_handle(entity);
let committed = if preserve_commit_layer {
self.commit_entity_handle_preserve_layer(entity)
} else {
self.commit_entity_handle(entity)
};
if is_associative_dimension && association_enabled {
if let Some(handle) = committed {
let sources = self.tabs[i]
@@ -973,7 +981,11 @@ impl OpenCADStudio {
.all(|entity| self.delta_add_safe(i, entity));
let pending = self.begin_undo(i, label, entities.len(), delta_safe);
for entity in entities {
self.commit_entity(entity);
if preserve_commit_layer {
let _ = self.commit_entity_handle_preserve_layer(entity);
} else {
self.commit_entity(entity);
}
}
self.tabs[i].dirty = true;
self.tabs[i].scene.clear_preview_wire();
+22 -3
View File
@@ -2596,14 +2596,33 @@ impl OpenCADStudio {
&mut self,
entity: acadrust::EntityType,
) -> Option<Handle> {
self.commit_entity_handle_with_dimension_policy(entity, false)
self.commit_entity_handle_with_policies(entity, false, false)
}
/// Commit an entity, optionally preserving its source dimension style.
pub(super) fn commit_entity_handle_with_dimension_policy(
&mut self,
entity: acadrust::EntityType,
preserve_dimension_layer_and_style: bool,
) -> Option<Handle> {
self.commit_entity_handle_with_policies(
entity,
preserve_dimension_layer_and_style,
false,
)
}
pub(super) fn commit_entity_handle_preserve_layer(
&mut self,
entity: acadrust::EntityType,
) -> Option<Handle> {
self.commit_entity_handle_with_policies(entity, false, true)
}
fn commit_entity_handle_with_policies(
&mut self,
mut entity: acadrust::EntityType,
preserve_dimension_layer_and_style: bool,
preserve_entity_layer: bool,
) -> Option<Handle> {
let i = self.active_tab;
let tracks_dimension_chain = matches!(
@@ -2692,7 +2711,7 @@ impl OpenCADStudio {
};
if let Some(layer) = explicit_mleader_layer {
entity.as_entity_mut().set_layer(layer);
} else {
} else if !preserve_entity_layer {
let layer = &self.tabs[i].active_layer;
if layer != "0" || entity.as_entity().layer().is_empty() {
entity.as_entity_mut().set_layer(layer.clone());
+5
View File
@@ -1734,6 +1734,11 @@ impl InputKind {
}
pub trait CadCommand: Send {
/// Keep the layer already carried by entities committed by this command
/// instead of replacing it with the current drawing layer.
fn preserve_commit_layer(&self) -> bool {
false
}
/// Short name shown in the command line prompt, e.g. `"LINE"`.
#[allow(dead_code)]
fn name(&self) -> &'static str;
+3
View File
@@ -514,6 +514,9 @@ impl OffsetCommand {
}
impl CadCommand for OffsetCommand {
fn preserve_commit_layer(&self) -> bool {
true
}
fn name(&self) -> &'static str {
"OFFSET"
}