forked from 1b-agent/opencadstudio-upstream
style: apply cargo fmt across workspace
This commit is contained in:
1 parent
85710e5454
commit
9cf9ff2c5c
531 files changed
+57740
-33906
No files matched your search
+70
-38
@@ -179,8 +179,8 @@ fn apply_text_defaults(doc: &CadDocument, entity: &mut EntityType) {
|
||||
if style_name.trim().is_empty() {
|
||||
style_name.clone_from(&active.style_name);
|
||||
}
|
||||
let resolved = named_text_style(doc, style_name)
|
||||
.unwrap_or_else(|| TextStyle::new(style_name.clone()));
|
||||
let resolved =
|
||||
named_text_style(doc, style_name).unwrap_or_else(|| TextStyle::new(style_name.clone()));
|
||||
match entity {
|
||||
EntityType::Text(text) => {
|
||||
if resolved.height > 1.0e-9 {
|
||||
@@ -209,9 +209,8 @@ fn apply_text_defaults(doc: &CadDocument, entity: &mut EntityType) {
|
||||
attribute.oblique_angle = resolved.oblique_angle;
|
||||
}
|
||||
if attribute.text_generation_flags == 0 {
|
||||
attribute.text_generation_flags =
|
||||
(if resolved.flags.backward { 2 } else { 0 })
|
||||
| (if resolved.flags.upside_down { 4 } else { 0 });
|
||||
attribute.text_generation_flags = (if resolved.flags.backward { 2 } else { 0 })
|
||||
| (if resolved.flags.upside_down { 4 } else { 0 });
|
||||
}
|
||||
}
|
||||
EntityType::AttributeDefinition(attribute) => {
|
||||
@@ -225,9 +224,8 @@ fn apply_text_defaults(doc: &CadDocument, entity: &mut EntityType) {
|
||||
attribute.oblique_angle = resolved.oblique_angle;
|
||||
}
|
||||
if attribute.text_generation_flags == 0 {
|
||||
attribute.text_generation_flags =
|
||||
(if resolved.flags.backward { 2 } else { 0 })
|
||||
| (if resolved.flags.upside_down { 4 } else { 0 });
|
||||
attribute.text_generation_flags = (if resolved.flags.backward { 2 } else { 0 })
|
||||
| (if resolved.flags.upside_down { 4 } else { 0 });
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@@ -239,7 +237,10 @@ fn apply_dimension_defaults(doc: &CadDocument, entity: &mut EntityType) {
|
||||
match entity {
|
||||
EntityType::Dimension(dimension) => {
|
||||
if entity_uses_default_style(&dimension.base().style_name) {
|
||||
dimension.base_mut().style_name.clone_from(&active.style_name);
|
||||
dimension
|
||||
.base_mut()
|
||||
.style_name
|
||||
.clone_from(&active.style_name);
|
||||
}
|
||||
}
|
||||
EntityType::Leader(leader) => {
|
||||
@@ -252,9 +253,11 @@ fn apply_dimension_defaults(doc: &CadDocument, entity: &mut EntityType) {
|
||||
}
|
||||
EntityType::Tolerance(tolerance) => {
|
||||
if entity_uses_default_style(&tolerance.dimension_style_name) {
|
||||
tolerance.dimension_style_name.clone_from(&active.style_name);
|
||||
tolerance.dimension_style_handle = (!active.style_handle.is_null())
|
||||
.then_some(active.style_handle);
|
||||
tolerance
|
||||
.dimension_style_name
|
||||
.clone_from(&active.style_name);
|
||||
tolerance.dimension_style_handle =
|
||||
(!active.style_handle.is_null()).then_some(active.style_handle);
|
||||
tolerance.text_height = active.text_height;
|
||||
tolerance.dimension_gap = active.gap;
|
||||
}
|
||||
@@ -267,35 +270,46 @@ fn apply_object_defaults(doc: &CadDocument, entity: &mut EntityType) {
|
||||
match entity {
|
||||
EntityType::MultiLeader(leader) if leader.style_handle.is_none() => {
|
||||
let name = doc.header.current_mleader_style_name.trim();
|
||||
if let Some(style) = doc.objects.iter().find_map(|(handle, object)| match object {
|
||||
ObjectType::MultiLeaderStyle(style) if style.name.eq_ignore_ascii_case(name) => {
|
||||
let mut style = style.clone();
|
||||
style.handle = *handle;
|
||||
Some(style)
|
||||
}
|
||||
_ => None,
|
||||
}) {
|
||||
if let Some(style) = doc
|
||||
.objects
|
||||
.iter()
|
||||
.find_map(|(handle, object)| match object {
|
||||
ObjectType::MultiLeaderStyle(style)
|
||||
if style.name.eq_ignore_ascii_case(name) =>
|
||||
{
|
||||
let mut style = style.clone();
|
||||
style.handle = *handle;
|
||||
Some(style)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
{
|
||||
crate::scene::annotative::apply_mleader_style(leader, &style);
|
||||
}
|
||||
}
|
||||
EntityType::Table(table) if table.table_style_handle.is_none() => {
|
||||
let name = doc.header.current_table_style_name.trim();
|
||||
table.table_style_handle = doc.objects.iter().find_map(|(handle, object)| match object {
|
||||
ObjectType::TableStyle(style) if style.name.eq_ignore_ascii_case(name) => {
|
||||
Some(*handle)
|
||||
}
|
||||
_ => None,
|
||||
});
|
||||
table.table_style_handle =
|
||||
doc.objects
|
||||
.iter()
|
||||
.find_map(|(handle, object)| match object {
|
||||
ObjectType::TableStyle(style) if style.name.eq_ignore_ascii_case(name) => {
|
||||
Some(*handle)
|
||||
}
|
||||
_ => None,
|
||||
});
|
||||
}
|
||||
EntityType::MLine(mline) if mline.style_handle.is_none() => {
|
||||
let name = doc.header.multiline_style.trim();
|
||||
if let Some((handle, style_name)) =
|
||||
doc.objects.iter().find_map(|(handle, object)| match object {
|
||||
ObjectType::MLineStyle(style) if style.name.eq_ignore_ascii_case(name) => {
|
||||
Some((*handle, style.name.clone()))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
doc.objects
|
||||
.iter()
|
||||
.find_map(|(handle, object)| match object {
|
||||
ObjectType::MLineStyle(style) if style.name.eq_ignore_ascii_case(name) => {
|
||||
Some((*handle, style.name.clone()))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
{
|
||||
mline.style_handle = Some(handle);
|
||||
mline.style_name = style_name;
|
||||
@@ -317,7 +331,10 @@ pub(crate) fn parse_current_transparency(value: &str) -> Option<codec::types::Tr
|
||||
match value.trim().to_ascii_uppercase().as_str() {
|
||||
"BYLAYER" | "-1" => Some(Transparency::ByLayer),
|
||||
"BYBLOCK" | "-2" => Some(Transparency::ByBlock),
|
||||
value => value.parse::<u8>().ok().filter(|value| *value <= 90)
|
||||
value => value
|
||||
.parse::<u8>()
|
||||
.ok()
|
||||
.filter(|value| *value <= 90)
|
||||
.map(|value| Transparency::from_percent(value as f64 / 100.0)),
|
||||
}
|
||||
}
|
||||
@@ -338,11 +355,26 @@ mod transparency_tests {
|
||||
|
||||
#[test]
|
||||
fn parses_supported_current_transparency_values() {
|
||||
assert_eq!(parse_current_transparency("ByLayer"), Some(Transparency::ByLayer));
|
||||
assert_eq!(parse_current_transparency("-1"), Some(Transparency::ByLayer));
|
||||
assert_eq!(parse_current_transparency("ByBlock"), Some(Transparency::ByBlock));
|
||||
assert_eq!(parse_current_transparency("-2"), Some(Transparency::ByBlock));
|
||||
assert_eq!(parse_current_transparency("25"), Some(Transparency::Explicit(64)));
|
||||
assert_eq!(
|
||||
parse_current_transparency("ByLayer"),
|
||||
Some(Transparency::ByLayer)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_current_transparency("-1"),
|
||||
Some(Transparency::ByLayer)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_current_transparency("ByBlock"),
|
||||
Some(Transparency::ByBlock)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_current_transparency("-2"),
|
||||
Some(Transparency::ByBlock)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_current_transparency("25"),
|
||||
Some(Transparency::Explicit(64))
|
||||
);
|
||||
assert!(parse_current_transparency("91").is_none());
|
||||
assert!(parse_current_transparency("25.5").is_none());
|
||||
assert!(parse_current_transparency("invalid").is_none());
|
||||
|
||||
Reference in new issue
Block a user