forked from 1b-agent/opencadstudio-upstream
style: rustfmt the tree so the CI lint check passes
This commit is contained in:
1 parent
1317a7b4fd
commit
6025d8be44
128 files changed
+4097
-1676
No files matched your search
+51
-18
@@ -928,7 +928,10 @@ impl OpenCADStudio {
|
||||
let scene = &self.tabs[self.active_tab].scene;
|
||||
let (vw, vh) = scene.selection.borrow().view.vp_size;
|
||||
let (camera, bounds) = scene.viewport_edit_frame((vw, vh)).unwrap_or_else(|| {
|
||||
(scene.camera.borrow().clone(), scene.active_model_tile_bounds(vw, vh))
|
||||
(
|
||||
scene.camera.borrow().clone(),
|
||||
scene.active_model_tile_bounds(vw, vh),
|
||||
)
|
||||
});
|
||||
let local = iced::Rectangle {
|
||||
width: bounds.width,
|
||||
@@ -1007,7 +1010,10 @@ impl OpenCADStudio {
|
||||
"right" => Message::ViewportRightRelease,
|
||||
"middle" => Message::ViewportMiddleRelease,
|
||||
_ => {
|
||||
outcome = Err(failure("invalid_request", "release is left, right or middle"));
|
||||
outcome = Err(failure(
|
||||
"invalid_request",
|
||||
"release is left, right or middle",
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1902,7 +1908,10 @@ impl OpenCADStudio {
|
||||
"refedit_dialog" => {
|
||||
use crate::ui::window::refedit_dialog::RefEditDialogMsg as R;
|
||||
if self.active_modal != Some(crate::app::ModalKind::RefEdit) {
|
||||
return Err(failure("no_dialog", "The Reference Edit dialog is not open"));
|
||||
return Err(failure(
|
||||
"no_dialog",
|
||||
"The Reference Edit dialog is not open",
|
||||
));
|
||||
}
|
||||
let spec = string(req, "value")?;
|
||||
let (key, value) = spec.split_once('=').unwrap_or((spec, ""));
|
||||
@@ -1914,15 +1923,17 @@ impl OpenCADStudio {
|
||||
if key == "cancel" {
|
||||
Message::CloseModal
|
||||
} else {
|
||||
Message::RefEditDialog(match key {
|
||||
"ok" => R::Ok,
|
||||
"level" => R::Level(value.parse().map_err(|_| failure("invalid_value", spec))?),
|
||||
"nested" => R::Nested(flag()?),
|
||||
"attributes" => R::Attributes(flag()?),
|
||||
"lock" => R::Lock(flag()?),
|
||||
"unique" => R::Unique(flag()?),
|
||||
_ => return Err(failure("invalid_value", "Unknown Reference Edit field")),
|
||||
})
|
||||
Message::RefEditDialog(match key {
|
||||
"ok" => R::Ok,
|
||||
"level" => {
|
||||
R::Level(value.parse().map_err(|_| failure("invalid_value", spec))?)
|
||||
}
|
||||
"nested" => R::Nested(flag()?),
|
||||
"attributes" => R::Attributes(flag()?),
|
||||
"lock" => R::Lock(flag()?),
|
||||
"unique" => R::Unique(flag()?),
|
||||
_ => return Err(failure("invalid_value", "Unknown Reference Edit field")),
|
||||
})
|
||||
}
|
||||
}
|
||||
// Ribbon key tips: `show`, `alt` (a lone Alt), `type:<codes>`, `enter`,
|
||||
@@ -1941,10 +1952,18 @@ impl OpenCADStudio {
|
||||
.chars()
|
||||
.map(|ch| K::Char(ch.to_uppercase().collect()))
|
||||
.collect(),
|
||||
_ => return Err(failure("invalid_value", "Use show, alt, type:<codes>, enter, esc or hide")),
|
||||
_ => {
|
||||
return Err(failure(
|
||||
"invalid_value",
|
||||
"Use show, alt, type:<codes>, enter, esc or hide",
|
||||
))
|
||||
}
|
||||
},
|
||||
};
|
||||
let tasks: Vec<_> = inputs.into_iter().map(|input| self.on_keytip(input)).collect();
|
||||
let tasks: Vec<_> = inputs
|
||||
.into_iter()
|
||||
.map(|input| self.on_keytip(input))
|
||||
.collect();
|
||||
return Ok(Task::batch(tasks));
|
||||
}
|
||||
// The -VIEW Background dialog, one field per call: "type=gradient",
|
||||
@@ -1993,9 +2012,15 @@ impl OpenCADStudio {
|
||||
})),
|
||||
"aspect" => Message::PdfDialog(P::BgAspect(value == "1")),
|
||||
"offset" | "scale" => {
|
||||
let pair: Vec<String> = value.split(',').map(|part| part.trim().to_string()).collect();
|
||||
let pair: Vec<String> = value
|
||||
.split(',')
|
||||
.map(|part| part.trim().to_string())
|
||||
.collect();
|
||||
let pair = <[String; 2]>::try_from(pair).map_err(|_| bad())?;
|
||||
if pair.iter().any(|v| v.parse::<f64>().map_or(true, |v| !v.is_finite())) {
|
||||
if pair
|
||||
.iter()
|
||||
.any(|v| v.parse::<f64>().map_or(true, |v| !v.is_finite()))
|
||||
{
|
||||
return Err(bad());
|
||||
}
|
||||
if key == "offset" {
|
||||
@@ -2043,7 +2068,12 @@ impl OpenCADStudio {
|
||||
"apply" => Message::PdfDialog(P::IaApply),
|
||||
"reset" => Message::PdfDialog(P::IaReset),
|
||||
"brightness" | "contrast" | "fade" => {
|
||||
let v: u8 = value.trim().parse().ok().filter(|v| *v <= 100).ok_or_else(bad)?;
|
||||
let v: u8 = value
|
||||
.trim()
|
||||
.parse()
|
||||
.ok()
|
||||
.filter(|v| *v <= 100)
|
||||
.ok_or_else(bad)?;
|
||||
Message::PdfDialog(P::IaValue(row(key)?, v))
|
||||
}
|
||||
"type" => {
|
||||
@@ -2100,7 +2130,10 @@ impl OpenCADStudio {
|
||||
// Choose an entry of the open multi-functional grip menu by its
|
||||
// position (0 = first), as a click on it does.
|
||||
"grip_menu_pick" => {
|
||||
let entries = self.grip_popup.as_ref().map_or(0, |popup| popup.items.len());
|
||||
let entries = self
|
||||
.grip_popup
|
||||
.as_ref()
|
||||
.map_or(0, |popup| popup.items.len());
|
||||
if entries == 0 {
|
||||
return Err(failure("menu_closed", "No grip menu is open"));
|
||||
}
|
||||
|
||||
+33
-35
@@ -862,7 +862,9 @@ impl OpenCADStudio {
|
||||
}
|
||||
}
|
||||
"grips" => self.control_grips(),
|
||||
"keytips" => self.ribbon.keytips_json(req["detail"].as_str() == Some("full")),
|
||||
"keytips" => self
|
||||
.ribbon
|
||||
.keytips_json(req["detail"].as_str() == Some("full")),
|
||||
"xdata_get" => self.xdata_read(&req),
|
||||
"get_selection" => self.control_get_selection(),
|
||||
"text_search" => self.control_text_search(&req).unwrap_or_else(|e| e),
|
||||
@@ -1356,14 +1358,9 @@ impl OpenCADStudio {
|
||||
pub(super) fn control_track(&mut self, task: Task<Message>) -> Task<Message> {
|
||||
let track_zero_unit = self.control.pending.as_ref().is_some_and(|p| {
|
||||
p.request["op"] == "run"
|
||||
&& p.request["cmd"]
|
||||
.as_str()
|
||||
.is_some_and(|cmd| {
|
||||
matches!(
|
||||
cmd.trim().to_ascii_uppercase().as_str(),
|
||||
"SAVE" | "QSAVE"
|
||||
)
|
||||
})
|
||||
&& p.request["cmd"].as_str().is_some_and(|cmd| {
|
||||
matches!(cmd.trim().to_ascii_uppercase().as_str(), "SAVE" | "QSAVE")
|
||||
})
|
||||
});
|
||||
// Most zero-unit tasks are `Task::none()` and have already completed
|
||||
// synchronously. SAVE/QSAVE are the deliberate exception: the command
|
||||
@@ -1870,10 +1867,7 @@ mod tests {
|
||||
.as_nanos(),
|
||||
));
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let saved = request(
|
||||
&mut app,
|
||||
json!({"op":"save","path":path,"overwrite":true}),
|
||||
);
|
||||
let saved = request(&mut app, json!({"op":"save","path":path,"overwrite":true}));
|
||||
assert_eq!(saved["ok"], true, "{saved}");
|
||||
assert_eq!(
|
||||
request(&mut app, json!({"op":"run","cmd":"LINE 0,5 10,5"}))["status"],
|
||||
@@ -1910,10 +1904,7 @@ mod tests {
|
||||
));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join("blocked.dwg");
|
||||
let saved = request(
|
||||
&mut app,
|
||||
json!({"op":"save","path":path,"overwrite":true}),
|
||||
);
|
||||
let saved = request(&mut app, json!({"op":"save","path":path,"overwrite":true}));
|
||||
assert_eq!(saved["ok"], true, "{saved}");
|
||||
// A directory at the target path makes the next write fail
|
||||
// deterministically; the operation must settle as failed instead of
|
||||
@@ -1927,7 +1918,9 @@ mod tests {
|
||||
let qsave = request(&mut app, json!({"op":"run","cmd":"QSAVE"}));
|
||||
assert_eq!(qsave["status"], "failed", "{qsave}");
|
||||
assert!(
|
||||
qsave["error"].as_str().is_some_and(|error| !error.is_empty()),
|
||||
qsave["error"]
|
||||
.as_str()
|
||||
.is_some_and(|error| !error.is_empty()),
|
||||
"{qsave}"
|
||||
);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
@@ -1951,7 +1944,10 @@ mod tests {
|
||||
}))
|
||||
.0;
|
||||
assert_eq!(parked["status"], "accepted", "{parked}");
|
||||
assert!(app.control.capture_frame_pending, "capture should wait for a frame");
|
||||
assert!(
|
||||
app.control.capture_frame_pending,
|
||||
"capture should wait for a frame"
|
||||
);
|
||||
let running = app
|
||||
.control_request(json!({"op":"operation","request_id":"cap-frame"}))
|
||||
.0;
|
||||
@@ -1959,11 +1955,8 @@ mod tests {
|
||||
|
||||
let _frame_task = app.on_control_capture_frame(true);
|
||||
assert!(!app.control.capture_frame_pending);
|
||||
let screenshot = iced::window::Screenshot::new(
|
||||
vec![0u8; 4 * 4 * 4],
|
||||
iced::Size::new(4, 4),
|
||||
1.0,
|
||||
);
|
||||
let screenshot =
|
||||
iced::window::Screenshot::new(vec![0u8; 4 * 4 * 4], iced::Size::new(4, 4), 1.0);
|
||||
app.control_screenshot(path.to_string_lossy().into_owned(), Some(screenshot));
|
||||
let done = app
|
||||
.control_request(json!({"op":"operation","request_id":"cap-frame"}))
|
||||
@@ -2040,14 +2033,13 @@ mod tests {
|
||||
let mut app = OpenCADStudio::new_for_test();
|
||||
request(&mut app, json!({"op":"new"}));
|
||||
request(&mut app, json!({"op":"run","cmd":"LINE 0,0 10,0"}));
|
||||
let handle = request(&mut app, json!({"op":"query","type":"Line"}))["entities"][0]["handle"]
|
||||
let handle = request(&mut app, json!({"op":"query","type":"Line"}))["entities"][0]
|
||||
["handle"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let before = app.control_state()["selection_revision"].as_u64().unwrap();
|
||||
let selected = app.automation_op(&format!(
|
||||
r#"{{"op":"select","handles":["{handle}"]}}"#
|
||||
));
|
||||
let selected = app.automation_op(&format!(r#"{{"op":"select","handles":["{handle}"]}}"#));
|
||||
assert_eq!(selected["ok"], true, "{selected}");
|
||||
let state = app.control_state();
|
||||
assert_eq!(
|
||||
@@ -2056,7 +2048,10 @@ mod tests {
|
||||
"selection revision should increment once: {state}"
|
||||
);
|
||||
assert!(
|
||||
state["selection"].as_array().unwrap().contains(&json!(handle)),
|
||||
state["selection"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.contains(&json!(handle)),
|
||||
"{state}"
|
||||
);
|
||||
let events = app.control_request(json!({"op":"events"})).0;
|
||||
@@ -2064,7 +2059,10 @@ mod tests {
|
||||
assert_eq!(last["kind"], "selection", "{events}");
|
||||
assert_eq!(last["document_id"], state["document_id"], "{events}");
|
||||
assert!(
|
||||
last["selection"].as_array().unwrap().contains(&json!(handle)),
|
||||
last["selection"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.contains(&json!(handle)),
|
||||
"{events}"
|
||||
);
|
||||
}
|
||||
@@ -2268,7 +2266,10 @@ mod tests {
|
||||
fn pending_request_id_reuse_rejects_changed_payload() {
|
||||
let mut app = OpenCADStudio::new_for_test();
|
||||
app.main_window = Some(iced::window::Id::unique());
|
||||
assert_eq!(request(&mut app, json!({"op":"new"}))["status"], "completed");
|
||||
assert_eq!(
|
||||
request(&mut app, json!({"op":"new"}))["status"],
|
||||
"completed"
|
||||
);
|
||||
|
||||
let pending = request(
|
||||
&mut app,
|
||||
@@ -2290,10 +2291,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(changed["code"], "request_id_reused", "{changed}");
|
||||
assert!(
|
||||
changed["error"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.contains("pending-reuse"),
|
||||
changed["error"].as_str().unwrap().contains("pending-reuse"),
|
||||
"{changed}"
|
||||
);
|
||||
|
||||
|
||||
@@ -150,7 +150,10 @@ fn sysvar_batches_validate_atomically_and_undo_as_one_step() {
|
||||
r#"{{"protocol":1,"op":"sysvar","request_id":"sv-atomic-ok","document_id":{doc},"set":{{"ltscale":2.5,"clayer":"Walls"}}}}"#
|
||||
));
|
||||
assert_eq!(r["ok"], true, "{}", r["error"]);
|
||||
assert_eq!(app.tabs[i].scene.document.header.current_layer_name, "Walls");
|
||||
assert_eq!(
|
||||
app.tabs[i].scene.document.header.current_layer_name,
|
||||
"Walls"
|
||||
);
|
||||
assert_eq!(app.tabs[i].scene.document.header.linetype_scale, 2.5);
|
||||
assert_eq!(app.tabs[i].active_layer, "Walls");
|
||||
assert_eq!(app.tabs[i].layers.current_layer, "Walls");
|
||||
@@ -165,7 +168,10 @@ fn sysvar_batches_validate_atomically_and_undo_as_one_step() {
|
||||
assert_eq!(r["ok"], false);
|
||||
assert_eq!(r["code"], "invalid_sysvar_value");
|
||||
assert_eq!(app.tabs[i].scene.document.header.linetype_scale, 2.5);
|
||||
assert_eq!(app.tabs[i].scene.document.header.current_layer_name, "Walls");
|
||||
assert_eq!(
|
||||
app.tabs[i].scene.document.header.current_layer_name,
|
||||
"Walls"
|
||||
);
|
||||
assert_eq!(app.tabs[i].history.undo_stack.len(), history_before + 1);
|
||||
|
||||
// One undo restores both header variables and all current-layer mirrors.
|
||||
@@ -459,7 +465,10 @@ fn entities_create_supports_control_and_fit_point_splines() {
|
||||
.find(|entity| entity["layer"] == "CURVES")
|
||||
.unwrap();
|
||||
assert_eq!(control_entity["degree"], 2, "{control_entity}");
|
||||
assert_eq!(control_entity["control_points"].as_array().unwrap().len(), 3);
|
||||
assert_eq!(
|
||||
control_entity["control_points"].as_array().unwrap().len(),
|
||||
3
|
||||
);
|
||||
assert_eq!(control_entity["weights"], json!([1.0, 2.0, 1.0]));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user