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
+83
-83
@@ -2,7 +2,10 @@ use super::*;
|
||||
|
||||
/// The first PE_URL string is the URL; later strings describe the link.
|
||||
pub(crate) fn pe_url_of(entity: &EntityType) -> Option<&str> {
|
||||
entity.common().extended_data.get_record("PE_URL")
|
||||
entity
|
||||
.common()
|
||||
.extended_data
|
||||
.get_record("PE_URL")
|
||||
.and_then(|record| {
|
||||
record.values.iter().find_map(|value| match value {
|
||||
codec::xdata::XDataValue::String(text) => Some(text.trim()),
|
||||
@@ -32,17 +35,17 @@ impl Scene {
|
||||
/// Clicking/copying/deleting either side expands to the complete pair.
|
||||
/// Every LEADER that points at `annotation`, resolved once per
|
||||
/// `geometry_epoch` rather than by walking the document per handle.
|
||||
fn leaders_by_annotation(
|
||||
&self,
|
||||
) -> std::cell::Ref<'_, (u64, HashMap<Handle, Vec<Handle>>)> {
|
||||
fn leaders_by_annotation(&self) -> std::cell::Ref<'_, (u64, HashMap<Handle, Vec<Handle>>)> {
|
||||
{
|
||||
let cache = self.leaders_by_annotation_cache.borrow();
|
||||
if cache.as_ref().is_some_and(|(epoch, _)| *epoch == self.geometry_epoch) {
|
||||
if cache
|
||||
.as_ref()
|
||||
.is_some_and(|(epoch, _)| *epoch == self.geometry_epoch)
|
||||
{
|
||||
drop(cache);
|
||||
return std::cell::Ref::map(
|
||||
self.leaders_by_annotation_cache.borrow(),
|
||||
|c| c.as_ref().unwrap(),
|
||||
);
|
||||
return std::cell::Ref::map(self.leaders_by_annotation_cache.borrow(), |c| {
|
||||
c.as_ref().unwrap()
|
||||
});
|
||||
}
|
||||
}
|
||||
let mut by_annotation: HashMap<Handle, Vec<Handle>> = HashMap::default();
|
||||
@@ -56,8 +59,7 @@ impl Scene {
|
||||
}
|
||||
}
|
||||
}
|
||||
*self.leaders_by_annotation_cache.borrow_mut() =
|
||||
Some((self.geometry_epoch, by_annotation));
|
||||
*self.leaders_by_annotation_cache.borrow_mut() = Some((self.geometry_epoch, by_annotation));
|
||||
std::cell::Ref::map(self.leaders_by_annotation_cache.borrow(), |c| {
|
||||
c.as_ref().unwrap()
|
||||
})
|
||||
@@ -104,14 +106,14 @@ impl Scene {
|
||||
if handles.is_empty() {
|
||||
return;
|
||||
}
|
||||
let doomed: HashSet<Handle> =
|
||||
self.expanded_with_leaders(handles).into_iter().collect();
|
||||
let doomed: HashSet<Handle> = self.expanded_with_leaders(handles).into_iter().collect();
|
||||
let mut changed = false;
|
||||
for handle in &doomed {
|
||||
changed |= self.selected.remove(handle);
|
||||
}
|
||||
if changed {
|
||||
self.selected_order.retain(|handle| !doomed.contains(handle));
|
||||
self.selected_order
|
||||
.retain(|handle| !doomed.contains(handle));
|
||||
self.bump_selection_set();
|
||||
}
|
||||
}
|
||||
@@ -175,7 +177,9 @@ impl Scene {
|
||||
/// UI picks still use `select_entity` and its leader/annotation expansion.
|
||||
#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
|
||||
pub(crate) fn replace_selection_exact(&mut self, handles: &[Handle]) {
|
||||
if self.selected_handles_in_order() == handles { return; }
|
||||
if self.selected_handles_in_order() == handles {
|
||||
return;
|
||||
}
|
||||
self.selected_constraint = None;
|
||||
self.selected = handles.iter().copied().collect();
|
||||
self.selected_order = handles.to_vec();
|
||||
@@ -324,9 +328,7 @@ impl Scene {
|
||||
fn qselect_candidate_handles(&self, scope: crate::app::QSelectScope) -> Vec<Handle> {
|
||||
match scope {
|
||||
crate::app::QSelectScope::CurrentSpace => self.current_layout_entity_handles(),
|
||||
crate::app::QSelectScope::CurrentSelection => {
|
||||
self.selected_handles_in_order()
|
||||
}
|
||||
crate::app::QSelectScope::CurrentSelection => self.selected_handles_in_order(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,26 +442,24 @@ impl Scene {
|
||||
} else {
|
||||
match (property_field, op) {
|
||||
(None, _) | (_, QSelectOp::Any) => true,
|
||||
(Some(field), op) => {
|
||||
match self.entity_property_value(e, field) {
|
||||
Some(actual) => match op {
|
||||
QSelectOp::Eq => actual.eq_ignore_ascii_case(value),
|
||||
QSelectOp::Neq => !actual.eq_ignore_ascii_case(value),
|
||||
QSelectOp::Gt | QSelectOp::Lt => {
|
||||
match (
|
||||
crate::entities::common::parse_f64(&actual),
|
||||
crate::entities::common::parse_f64(value),
|
||||
) {
|
||||
(Some(a), Some(b)) if matches!(op, QSelectOp::Gt) => a > b,
|
||||
(Some(a), Some(b)) => a < b,
|
||||
_ => false,
|
||||
}
|
||||
(Some(field), op) => match self.entity_property_value(e, field) {
|
||||
Some(actual) => match op {
|
||||
QSelectOp::Eq => actual.eq_ignore_ascii_case(value),
|
||||
QSelectOp::Neq => !actual.eq_ignore_ascii_case(value),
|
||||
QSelectOp::Gt | QSelectOp::Lt => {
|
||||
match (
|
||||
crate::entities::common::parse_f64(&actual),
|
||||
crate::entities::common::parse_f64(value),
|
||||
) {
|
||||
(Some(a), Some(b)) if matches!(op, QSelectOp::Gt) => a > b,
|
||||
(Some(a), Some(b)) => a < b,
|
||||
_ => false,
|
||||
}
|
||||
QSelectOp::Any => true,
|
||||
},
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
QSelectOp::Any => true,
|
||||
},
|
||||
None => false,
|
||||
},
|
||||
}
|
||||
};
|
||||
let matches_filter = type_ok && prop_ok;
|
||||
@@ -499,10 +499,7 @@ impl Scene {
|
||||
// Incremental: fold the changes since the cached epoch into the set.
|
||||
if let Some(since) = cached_epoch {
|
||||
if let Some(deltas) = self.replay_since(since) {
|
||||
if deltas
|
||||
.iter()
|
||||
.all(|(_, kind)| *kind == ChangeKind::Added)
|
||||
{
|
||||
if deltas.iter().all(|(_, kind)| *kind == ChangeKind::Added) {
|
||||
let mut cache = self.layout_type_names_cache.borrow_mut();
|
||||
if let Some((epoch, _, present, names)) = cache.as_mut() {
|
||||
let mut added = false;
|
||||
@@ -523,8 +520,7 @@ impl Scene {
|
||||
// Only rebuild the list when the set actually moved;
|
||||
// otherwise the existing `Arc` is still the answer.
|
||||
if added {
|
||||
*names =
|
||||
std::sync::Arc::new(present.iter().cloned().collect());
|
||||
*names = std::sync::Arc::new(present.iter().cloned().collect());
|
||||
}
|
||||
*epoch = self.geometry_epoch;
|
||||
return std::sync::Arc::clone(names);
|
||||
@@ -533,8 +529,7 @@ impl Scene {
|
||||
}
|
||||
}
|
||||
|
||||
let mut present: std::collections::BTreeSet<String> =
|
||||
std::collections::BTreeSet::new();
|
||||
let mut present: std::collections::BTreeSet<String> = std::collections::BTreeSet::new();
|
||||
if let Some(record) = self
|
||||
.document
|
||||
.block_records
|
||||
@@ -588,17 +583,17 @@ impl Scene {
|
||||
type_name: Option<&str>,
|
||||
scope: crate::app::QSelectScope,
|
||||
) -> Vec<crate::app::QSelectPropertyChoice> {
|
||||
use crate::app::{QSelectPropertyChoice, QSelectValueEditor};
|
||||
use crate::entities::traits::{entity_type_name, EntityTypeOps};
|
||||
use crate::scene::model::object::PropValue;
|
||||
use crate::app::{QSelectPropertyChoice, QSelectValueEditor};
|
||||
|
||||
let candidate_handles: Vec<Handle> = self
|
||||
.qselect_candidate_handles(scope)
|
||||
.into_iter()
|
||||
.filter(|h| {
|
||||
self.document.get_entity(*h).is_some_and(|entity| {
|
||||
type_name.is_none_or(|t| entity_type_name(entity) == t)
|
||||
})
|
||||
self.document
|
||||
.get_entity(*h)
|
||||
.is_some_and(|entity| type_name.is_none_or(|t| entity_type_name(entity) == t))
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -617,15 +612,18 @@ impl Scene {
|
||||
.map(|linetype| linetype.name.clone()),
|
||||
);
|
||||
|
||||
let choice = |field: &str, label: String, editor: QSelectValueEditor| {
|
||||
QSelectPropertyChoice {
|
||||
let choice =
|
||||
|field: &str, label: String, editor: QSelectValueEditor| QSelectPropertyChoice {
|
||||
field: field.to_string(),
|
||||
label,
|
||||
editor,
|
||||
}
|
||||
};
|
||||
};
|
||||
let mut out = vec![
|
||||
choice("handle", crate::t!("Handle").into_owned(), QSelectValueEditor::Text),
|
||||
choice(
|
||||
"handle",
|
||||
crate::t!("Handle").into_owned(),
|
||||
QSelectValueEditor::Text,
|
||||
),
|
||||
choice(
|
||||
"color",
|
||||
crate::t!("Color").into_owned(),
|
||||
@@ -756,17 +754,19 @@ impl Scene {
|
||||
}
|
||||
QSelectValueEditor::Choice(values)
|
||||
}
|
||||
PropValue::ColorChoice(_)
|
||||
| PropValue::NamedColorChoice { .. } => QSelectValueEditor::Choice(vec![
|
||||
"ByLayer".into(),
|
||||
"ByBlock".into(),
|
||||
]),
|
||||
PropValue::LwChoice(_)
|
||||
| PropValue::FieldLwChoice { .. } => QSelectValueEditor::Choice(vec![
|
||||
"ByLayer".into(),
|
||||
"ByBlock".into(),
|
||||
"Default".into(),
|
||||
]),
|
||||
PropValue::ColorChoice(_) | PropValue::NamedColorChoice { .. } => {
|
||||
QSelectValueEditor::Choice(vec![
|
||||
"ByLayer".into(),
|
||||
"ByBlock".into(),
|
||||
])
|
||||
}
|
||||
PropValue::LwChoice(_) | PropValue::FieldLwChoice { .. } => {
|
||||
QSelectValueEditor::Choice(vec![
|
||||
"ByLayer".into(),
|
||||
"ByBlock".into(),
|
||||
"Default".into(),
|
||||
])
|
||||
}
|
||||
PropValue::LinetypeChoice(_) => {
|
||||
QSelectValueEditor::Choice(linetype_options.clone())
|
||||
}
|
||||
@@ -782,10 +782,7 @@ impl Scene {
|
||||
QSelectValueEditor::Choice(patterns)
|
||||
}
|
||||
PropValue::BoolToggle { .. } => {
|
||||
QSelectValueEditor::Choice(vec![
|
||||
"false".into(),
|
||||
"true".into(),
|
||||
])
|
||||
QSelectValueEditor::Choice(vec!["false".into(), "true".into()])
|
||||
}
|
||||
PropValue::AttrText { .. } => QSelectValueEditor::Text,
|
||||
PropValue::Stepper { .. }
|
||||
@@ -826,7 +823,10 @@ impl Scene {
|
||||
continue;
|
||||
};
|
||||
if let Some(value) = self.entity_property_value(entity, &property.field) {
|
||||
if !options.iter().any(|option| option.eq_ignore_ascii_case(&value)) {
|
||||
if !options
|
||||
.iter()
|
||||
.any(|option| option.eq_ignore_ascii_case(&value))
|
||||
{
|
||||
options.push(value);
|
||||
}
|
||||
}
|
||||
@@ -842,11 +842,7 @@ impl Scene {
|
||||
/// `"ByLayer"` / `"7"` / `"0.30mm"` are stable; everything else
|
||||
/// goes through `geometry_properties()` and pulls the matching
|
||||
/// row's value out.
|
||||
pub fn entity_property_value(
|
||||
&self,
|
||||
entity: &codec::EntityType,
|
||||
field: &str,
|
||||
) -> Option<String> {
|
||||
pub fn entity_property_value(&self, entity: &codec::EntityType, field: &str) -> Option<String> {
|
||||
use crate::entities::traits::EntityTypeOps;
|
||||
use crate::scene::model::object::PropValue;
|
||||
match field {
|
||||
@@ -919,8 +915,7 @@ impl Scene {
|
||||
PropValue::EditChoice { value, .. } => value,
|
||||
PropValue::ColorChoice(c) => Self::format_color(c),
|
||||
PropValue::NamedColorChoice { name, .. } => name,
|
||||
PropValue::LwChoice(lw)
|
||||
| PropValue::FieldLwChoice { value: lw, .. } => {
|
||||
PropValue::LwChoice(lw) | PropValue::FieldLwChoice { value: lw, .. } => {
|
||||
Self::format_lineweight(lw)
|
||||
}
|
||||
PropValue::LinetypeChoice(s) => s,
|
||||
@@ -985,7 +980,10 @@ impl Scene {
|
||||
if let ObjectType::ClassObject(object) = object {
|
||||
if let codec::objects::ClassObjectData::SectionManager(manager) = &object.data {
|
||||
for §ion in &manager.sections {
|
||||
managers_by_section.entry(section).or_default().push(*handle);
|
||||
managers_by_section
|
||||
.entry(section)
|
||||
.or_default()
|
||||
.push(*handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1012,10 +1010,8 @@ impl Scene {
|
||||
},
|
||||
_ => None,
|
||||
});
|
||||
let section_managers: Vec<Handle> = managers_by_section
|
||||
.get(&h)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
let section_managers: Vec<Handle> =
|
||||
managers_by_section.get(&h).cloned().unwrap_or_default();
|
||||
// Delta-undo: capture the removed entity so an undo can re-insert it.
|
||||
if self.is_recording_undo() {
|
||||
let before = self.document.get_entity_arc(h);
|
||||
@@ -1365,7 +1361,11 @@ mod tests {
|
||||
|
||||
scene.add_entity(EntityType::Circle(Circle::new()));
|
||||
let third = scene.entity_type_names_in_layout();
|
||||
assert_eq!(third.as_slice(), ["Circle", "Line"], "a new type must appear");
|
||||
assert_eq!(
|
||||
third.as_slice(),
|
||||
["Circle", "Line"],
|
||||
"a new type must appear"
|
||||
);
|
||||
|
||||
// The incremental answer has to be the answer a full walk gives.
|
||||
scene.layout_type_names_cache.borrow_mut().take();
|
||||
|
||||
Reference in new issue
Block a user