style: apply cargo fmt across workspace

This commit is contained in:
Karim Jerbi committed 2026-10-11 03:14:29 +01:00
1 parent 85710e5454
commit 9cf9ff2c5c
531 files changed
+57740 -33906

No files matched your search

+159 -159
View File
@@ -41,12 +41,10 @@ impl OpenCADStudio {
let is_associative_dimension = matches!(
entity,
codec::EntityType::Dimension(
codec::entities::Dimension::Linear(_)
| codec::entities::Dimension::Aligned(_)
codec::entities::Dimension::Linear(_) | codec::entities::Dimension::Aligned(_)
)
);
let association_enabled =
self.tabs[i].scene.document.header.dimension_associativity == 2;
let association_enabled = self.tabs[i].scene.document.header.dimension_associativity == 2;
let committed = if preserve_commit_layer {
self.commit_entity_handle_preserve_layer(entity)
} else {
@@ -99,8 +97,8 @@ impl OpenCADStudio {
.as_ref()
.and_then(|command| command.nested_copy_symbol_names())
.cloned();
let delta_safe = symbol_names.is_none()
&& entities.iter().all(|entity| self.delta_add_safe(i, entity));
let delta_safe =
symbol_names.is_none() && entities.iter().all(|entity| self.delta_add_safe(i, entity));
let pending = self.begin_undo(i, label, entities.len(), delta_safe);
if let Some(names) = symbol_names {
let retained = self.tabs[i]
@@ -162,8 +160,8 @@ impl OpenCADStudio {
.as_ref()
.and_then(|command| command.nested_copy_symbol_names())
.cloned();
let delta_safe = symbol_names.is_none()
&& entities.iter().all(|entity| self.delta_add_safe(i, entity));
let delta_safe =
symbol_names.is_none() && entities.iter().all(|entity| self.delta_add_safe(i, entity));
let pending = self.begin_undo(i, label, entities.len(), delta_safe);
if let Some(names) = symbol_names {
let retained = self.tabs[i]
@@ -223,24 +221,35 @@ impl OpenCADStudio {
self.update_cont_anchor(&entity);
// ATTDEF's height becomes the next text height (TEXTSIZE), as TEXT's does.
if let codec::EntityType::AttributeDefinition(attribute) = &entity {
if self.tabs[i].active_cmd.as_ref().is_some_and(|cmd| cmd.name().ends_with("ATTDEF")) {
if self.tabs[i]
.active_cmd
.as_ref()
.is_some_and(|cmd| cmd.name().ends_with("ATTDEF"))
{
self.tabs[i].scene.document.header.text_height = attribute.height;
}
}
// A field the committed text shows (FIELD, an ATTDEF Default from the
// Field dialog) is attached once the entity has its handle; the field
// objects are not part of the add delta, so the step is a snapshot.
let text_field = self.tabs[i].active_cmd.as_ref().and_then(|cmd| cmd.text_field());
let text_field = self.tabs[i]
.active_cmd
.as_ref()
.and_then(|cmd| cmd.text_field());
let label = self.history_label_from_active_cmd(i, "ENTITY");
// A block reference whose attribute definitions carry fields gets
// them copied onto its attributes (field objects: snapshot step).
let attribute_fields = match &entity {
codec::EntityType::Insert(insert) if !insert.attributes.is_empty() => {
crate::entities::field::block_has_attribute_fields(&self.tabs[i].scene.document, &insert.block_name)
crate::entities::field::block_has_attribute_fields(
&self.tabs[i].scene.document,
&insert.block_name,
)
}
_ => false,
};
let delta_safe = text_field.is_none() && !attribute_fields && self.delta_add_safe(i, &entity);
let delta_safe =
text_field.is_none() && !attribute_fields && self.delta_add_safe(i, &entity);
let field_value = match &entity {
codec::EntityType::MText(m) => m.value.clone(),
codec::EntityType::AttributeDefinition(a) => a.default_value.clone(),
@@ -250,12 +259,10 @@ impl OpenCADStudio {
let is_associative_dimension = matches!(
entity,
codec::EntityType::Dimension(
codec::entities::Dimension::Linear(_)
| codec::entities::Dimension::Aligned(_)
codec::entities::Dimension::Linear(_) | codec::entities::Dimension::Aligned(_)
)
);
let association_enabled =
self.tabs[i].scene.document.header.dimension_associativity == 2;
let association_enabled = self.tabs[i].scene.document.header.dimension_associativity == 2;
let committed = if preserve_commit_layer {
self.commit_entity_handle_preserve_layer(entity)
} else {
@@ -278,8 +285,13 @@ impl OpenCADStudio {
);
}
if let (Some(handle), true) = (committed, attribute_fields) {
crate::entities::field::attach_attribute_fields(&mut self.tabs[i].scene.document, handle);
self.tabs[i].scene.bump_entities(&[(handle, crate::scene::ChangeKind::Modified)]);
crate::entities::field::attach_attribute_fields(
&mut self.tabs[i].scene.document,
handle,
);
self.tabs[i]
.scene
.bump_entities(&[(handle, crate::scene::ChangeKind::Modified)]);
}
if let Some(handle) = committed {
self.apply_continuous_constraints(i, &[handle]);
@@ -340,99 +352,99 @@ impl OpenCADStudio {
} else {
None
};
let pending = if association_mode == 0 {
let layer = self.tabs[i].active_layer.clone();
if layer != "0" || entity.as_entity().layer().is_empty() {
entity.as_entity_mut().set_layer(layer);
}
crate::scene::view::dispatch::apply_color(
&mut entity,
self.ribbon.active_color,
);
crate::scene::view::dispatch::apply_common_prop(
&mut entity,
"linetype",
&self.ribbon.active_linetype.clone(),
);
crate::scene::view::dispatch::apply_line_weight(
&mut entity,
self.ribbon.active_lineweight,
);
let celtscale = self.tabs[i]
.scene
.document
.header
.current_entity_linetype_scale;
if (celtscale - 1.0).abs() > 1e-9 && celtscale.abs() > 1e-9 {
entity.common_mut().linetype_scale = celtscale;
}
crate::scene::creation_style::apply_current_creation_styles(
&self.tabs[i].scene.document,
&mut entity,
);
if let (Some((layer, style_name)), codec::EntityType::Dimension(dimension)) =
(inherited_dimension, &mut entity)
{
dimension.base_mut().common.layer = layer;
dimension.base_mut().style_name = style_name;
}
let pieces = crate::modules::draw::modify::explode::explode_entity(
&entity,
&self.tabs[i].scene.document,
);
let delta_safe = pieces.iter().all(|piece| self.delta_add_safe(i, piece));
let pending = self.begin_undo(i, label, pieces.len(), delta_safe);
for piece in pieces {
self.tabs[i].scene.add_entity(piece);
}
pending
} else {
let delta_safe = self.delta_add_safe(i, &entity);
let pending = self.begin_undo(i, label, 1, delta_safe);
if let Some(handle) =
self.commit_entity_handle_with_dimension_policy(entity, preserve_base_style)
{
if association_mode == 2 && association_allowed {
let mut changes = vec![(handle, crate::scene::ChangeKind::Modified)];
match association {
crate::command::DimensionAssociationInput::Infer(source) => {
let sources: Vec<_> = source.map_or_else(
|| self.infer_dimension_sources_guarded(i, handle),
|source| {
if single_source_dimension {
vec![Some(source)]
} else {
vec![Some(source), Some(source)]
}
},
);
self.tabs[i]
.scene
.attach_dimension_association(handle, sources.clone());
changes.extend(sources.into_iter().flatten().map(|source| {
(source, crate::scene::ChangeKind::Modified)
}));
}
crate::command::DimensionAssociationInput::Explicit(sources) => {
self.tabs[i].scene.attach_dimension_association_sources(
handle,
sources.clone(),
);
changes.extend(sources.into_iter().flatten().map(|source| {
(source.handle, crate::scene::ChangeKind::Modified)
}));
}
}
changes.sort_by_key(|(handle, _)| handle.value());
changes.dedup_by_key(|(handle, _)| handle.value());
self.tabs[i].scene.bump_entities(&changes);
} else if association_mode == 2 {
// Preserve the acquired viewport and source paths.
self.attach_viewport_dimension_association(i, handle);
let pending =
if association_mode == 0 {
let layer = self.tabs[i].active_layer.clone();
if layer != "0" || entity.as_entity().layer().is_empty() {
entity.as_entity_mut().set_layer(layer);
}
}
pending
};
crate::scene::view::dispatch::apply_color(&mut entity, self.ribbon.active_color);
crate::scene::view::dispatch::apply_common_prop(
&mut entity,
"linetype",
&self.ribbon.active_linetype.clone(),
);
crate::scene::view::dispatch::apply_line_weight(
&mut entity,
self.ribbon.active_lineweight,
);
let celtscale = self.tabs[i]
.scene
.document
.header
.current_entity_linetype_scale;
if (celtscale - 1.0).abs() > 1e-9 && celtscale.abs() > 1e-9 {
entity.common_mut().linetype_scale = celtscale;
}
crate::scene::creation_style::apply_current_creation_styles(
&self.tabs[i].scene.document,
&mut entity,
);
if let (Some((layer, style_name)), codec::EntityType::Dimension(dimension)) =
(inherited_dimension, &mut entity)
{
dimension.base_mut().common.layer = layer;
dimension.base_mut().style_name = style_name;
}
let pieces = crate::modules::draw::modify::explode::explode_entity(
&entity,
&self.tabs[i].scene.document,
);
let delta_safe = pieces.iter().all(|piece| self.delta_add_safe(i, piece));
let pending = self.begin_undo(i, label, pieces.len(), delta_safe);
for piece in pieces {
self.tabs[i].scene.add_entity(piece);
}
pending
} else {
let delta_safe = self.delta_add_safe(i, &entity);
let pending = self.begin_undo(i, label, 1, delta_safe);
if let Some(handle) =
self.commit_entity_handle_with_dimension_policy(entity, preserve_base_style)
{
if association_mode == 2 && association_allowed {
let mut changes = vec![(handle, crate::scene::ChangeKind::Modified)];
match association {
crate::command::DimensionAssociationInput::Infer(source) => {
let sources: Vec<_> = source.map_or_else(
|| self.infer_dimension_sources_guarded(i, handle),
|source| {
if single_source_dimension {
vec![Some(source)]
} else {
vec![Some(source), Some(source)]
}
},
);
self.tabs[i]
.scene
.attach_dimension_association(handle, sources.clone());
changes.extend(
sources
.into_iter()
.flatten()
.map(|source| (source, crate::scene::ChangeKind::Modified)),
);
}
crate::command::DimensionAssociationInput::Explicit(sources) => {
self.tabs[i]
.scene
.attach_dimension_association_sources(handle, sources.clone());
changes.extend(sources.into_iter().flatten().map(|source| {
(source.handle, crate::scene::ChangeKind::Modified)
}));
}
}
changes.sort_by_key(|(handle, _)| handle.value());
changes.dedup_by_key(|(handle, _)| handle.value());
self.tabs[i].scene.bump_entities(&changes);
} else if association_mode == 2 {
// Preserve the acquired viewport and source paths.
self.attach_viewport_dimension_association(i, handle);
}
}
pending
};
self.tabs[i].dirty = true;
self.tabs[i].scene.clear_preview_wire();
self.tabs[i].snap_result = None;
@@ -452,10 +464,7 @@ impl OpenCADStudio {
pub(super) fn handle_commit_dimensions_and_exit(
&mut self,
dimensions: Vec<(
codec::EntityType,
crate::command::DimensionAssociationInput,
)>,
dimensions: Vec<(codec::EntityType, crate::command::DimensionAssociationInput)>,
) {
let i = self.active_tab;
let association_mode = self.tabs[i].scene.document.header.dimension_associativity;
@@ -467,10 +476,7 @@ impl OpenCADStudio {
if layer != "0" || entity.as_entity().layer().is_empty() {
entity.as_entity_mut().set_layer(layer);
}
crate::scene::view::dispatch::apply_color(
&mut entity,
self.ribbon.active_color,
);
crate::scene::view::dispatch::apply_color(&mut entity, self.ribbon.active_color);
crate::scene::view::dispatch::apply_common_prop(
&mut entity,
"linetype",
@@ -521,30 +527,22 @@ impl OpenCADStudio {
continue;
}
let sources = match association {
crate::command::DimensionAssociationInput::Infer(source) => {
source.map_or_else(
|| {
self.infer_dimension_sources_guarded(i, handle)
.into_iter()
.map(|source| {
source.map(
crate::command::DimensionAssociationSource::inferred,
)
})
.collect()
},
|source| {
vec![Some(
crate::command::DimensionAssociationSource::inferred(
source,
),
)]
},
)
}
crate::command::DimensionAssociationInput::Explicit(sources) => {
sources
}
crate::command::DimensionAssociationInput::Infer(source) => source.map_or_else(
|| {
self.infer_dimension_sources_guarded(i, handle)
.into_iter()
.map(|source| {
source.map(crate::command::DimensionAssociationSource::inferred)
})
.collect()
},
|source| {
vec![Some(crate::command::DimensionAssociationSource::inferred(
source,
))]
},
),
crate::command::DimensionAssociationInput::Explicit(sources) => sources,
};
self.tabs[i]
.scene
@@ -591,8 +589,7 @@ impl OpenCADStudio {
let erase_source = erase_source.filter(|handle| {
self.delete_objects != 0 && !self.tabs[i].scene.is_layer_locked(*handle)
});
let pending =
self.begin_undo(i, label, 1 + usize::from(erase_source.is_some()), true);
let pending = self.begin_undo(i, label, 1 + usize::from(erase_source.is_some()), true);
let handle = self.add_solid_model(entity, *solid, history);
if !handle.is_null() {
if let Some(source) = erase_source {
@@ -767,7 +764,9 @@ impl OpenCADStudio {
mut options: Box<crate::scene::CreateBlockOptions>,
) -> Option<Task<Message>> {
let i = self.active_tab;
options.handles.retain(|handle| !self.tabs[i].scene.is_layer_locked(*handle));
options
.handles
.retain(|handle| !self.tabs[i].scene.is_layer_locked(*handle));
if options.handles.is_empty() {
self.command_line
.push_info(crate::t!("No editable objects selected.").as_ref());
@@ -865,8 +864,7 @@ impl OpenCADStudio {
sources.push(handles);
}
if let Some(paths) = hatch.boundary_paths.as_mut() {
for (path, handles) in std::sync::Arc::make_mut(paths).iter_mut().zip(&sources)
{
for (path, handles) in std::sync::Arc::make_mut(paths).iter_mut().zip(&sources) {
path.boundary_handles = handles.clone();
path.flags.set_external(!handles.is_empty());
}
@@ -942,9 +940,8 @@ impl OpenCADStudio {
.bump_entities(&[(handle, crate::scene::ChangeKind::Modified)]);
self.tabs[i].dirty = true;
} else {
self.command_line.push_error(
crate::t!("The selected object is no longer available.").as_ref(),
);
self.command_line
.push_error(crate::t!("The selected object is no longer available.").as_ref());
}
self.tabs[i].scene.clear_preview_wire();
self.tabs[i].active_cmd = None;
@@ -969,13 +966,11 @@ impl OpenCADStudio {
.reassociate_center_mark(target, source, point)
{
self.tabs[i].dirty = true;
self.command_line.push_output(
crate::t!("CENTERREASSOCIATE: center mark associated.").as_ref(),
);
self.command_line
.push_output(crate::t!("CENTERREASSOCIATE: center mark associated.").as_ref());
} else {
self.command_line.push_error(
crate::t!("CENTERREASSOCIATE: the selected source is not circular.")
.as_ref(),
crate::t!("CENTERREASSOCIATE: the selected source is not circular.").as_ref(),
);
}
self.tabs[i].active_cmd = None;
@@ -995,8 +990,7 @@ impl OpenCADStudio {
br.entity_handles
.iter()
.filter_map(|&h| {
if let Some(codec::EntityType::AttributeDefinition(ad)) =
doc.get_entity(h)
if let Some(codec::EntityType::AttributeDefinition(ad)) = doc.get_entity(h)
{
Some(ad.clone())
} else {
@@ -1033,7 +1027,10 @@ impl OpenCADStudio {
self.tabs[i].dirty = true;
self.tabs[i].scene.clear_preview_wire();
// A repeating insertion keeps its command for the next block.
let keep = self.tabs[i].active_cmd.as_ref().is_some_and(|c| c.attreq_continue());
let keep = self.tabs[i]
.active_cmd
.as_ref()
.is_some_and(|c| c.attreq_continue());
if keep {
let prompt = self.tabs[i].active_cmd.as_ref().map(|c| c.prompt());
if let Some(p) = prompt {
@@ -1061,7 +1058,10 @@ impl OpenCADStudio {
let name = ins.block_name.clone();
self.record_block_insert(&name);
}
let keep = self.tabs[i].active_cmd.as_ref().is_some_and(|c| c.attreq_continue());
let keep = self.tabs[i]
.active_cmd
.as_ref()
.is_some_and(|c| c.attreq_continue());
return Some(self.apply_cmd_result(if keep {
CmdResult::CommitEntity(entity)
} else {