* fix(ui): finish the open sketch when a modeling feature starts * fix(ui): wait for the marker roll before starting a feature from a sketch * fix(ui): start the feature once the marker is back * test(ui): keep the sketch open in the palette clearance test
This commit is contained in:
@@ -223,6 +223,14 @@ impl SolveApp {
|
||||
let (id, params) = self.deferred_queue.remove(0);
|
||||
let _ = self.run_heavy(&id, params);
|
||||
}
|
||||
if self.deferred.is_none()
|
||||
&& self.deferred_queue.is_empty()
|
||||
&& let Some((id, sketch)) = self.start_after_roll.take()
|
||||
&& self.dialog.is_none()
|
||||
&& self.tool.is_none()
|
||||
{
|
||||
self.start_interactive(&id, Some(sketch));
|
||||
}
|
||||
}
|
||||
|
||||
/// Start evaluating a command ahead. `None` when it should just run: not asked for
|
||||
|
||||
@@ -1000,6 +1000,18 @@ impl Dialog {
|
||||
Dialog::new(Kind::EditParam { name: name.into(), expr: s.doc.param(name).map(|p| p.expr.clone()).unwrap_or_default() }, vec![])
|
||||
}
|
||||
|
||||
/// An Extrude or Revolve started from inside a sketch takes that sketch's profile, as it would
|
||||
/// had the sketch stayed open.
|
||||
pub(crate) fn take_sketch_profile(&mut self, s: &Session, sketch: u64) {
|
||||
if matches!(self.kind, Kind::Extrude { .. } | Kind::Revolve { .. })
|
||||
&& let Some(inp) = self.inputs.first_mut()
|
||||
&& inp.items.is_empty()
|
||||
{
|
||||
inp.items = single_profile(s, sketch);
|
||||
self.advance();
|
||||
}
|
||||
}
|
||||
|
||||
/// Make the first single input still empty (after the filled ones) active.
|
||||
fn advance(&mut self) {
|
||||
if let Some(i) = self.inputs.iter().position(|i| i.items.is_empty()) {
|
||||
@@ -1442,12 +1454,15 @@ fn fillet_edges(s: &Session, sel: &Sel, chain: bool) -> Vec<Sel> {
|
||||
/// the last sketch's while no feature builds from it yet. A used profile (a cube's sketch on its
|
||||
/// bottom face) is only taken when it is picked.
|
||||
fn default_profiles(s: &Session) -> Vec<Sel> {
|
||||
let st = s.world_state();
|
||||
let sid = s.active_sketch.or_else(|| {
|
||||
s.doc.features.iter().rev().find(|f| matches!(f.kind, FeatureKind::Sketch { .. })).map(|f| f.id).filter(|&id| !profiles_used(s, id))
|
||||
});
|
||||
match sid.and_then(|id| st.sketch(id).map(|ss| (id, ss.profiles.len()))) {
|
||||
Some((id, 1)) => vec![Sel::Profile { sketch: id, index: 0 }],
|
||||
sid.map(|id| single_profile(s, id)).unwrap_or_default()
|
||||
}
|
||||
|
||||
fn single_profile(s: &Session, sketch: u64) -> Vec<Sel> {
|
||||
match s.world_state().sketch(sketch).map(|ss| ss.profiles.len()) {
|
||||
Some(1) => vec![Sel::Profile { sketch, index: 0 }],
|
||||
_ => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,6 +451,9 @@ pub struct SolveApp {
|
||||
/// thread, and those asked for meanwhile ([`deferred`]).
|
||||
pub deferred: Option<deferred::Deferred>,
|
||||
pub deferred_queue: Vec<(String, Value)>,
|
||||
/// A feature started from a sketch while the marker rolls back, and that sketch: it starts
|
||||
/// once the marker is back.
|
||||
pub start_after_roll: Option<(String, u64)>,
|
||||
/// A delete's check of what it takes with it or breaks, computing off the window thread
|
||||
/// ([`deferred::DeleteCheck`], #2678).
|
||||
pub delete_check: Option<deferred::DeleteCheck>,
|
||||
@@ -619,6 +622,7 @@ impl SolveApp {
|
||||
applying: None,
|
||||
deferred: None,
|
||||
deferred_queue: Vec::new(),
|
||||
start_after_roll: None,
|
||||
delete_check: None,
|
||||
apply_off_thread: None,
|
||||
#[cfg(test)]
|
||||
@@ -1212,8 +1216,22 @@ impl SolveApp {
|
||||
}
|
||||
return;
|
||||
}
|
||||
let finished_sketch = self.session.active_sketch.filter(|_| ends_sketch(id) && self.interactive(id));
|
||||
if finished_sketch.is_some() {
|
||||
self.finish_sketch();
|
||||
// A feature committed before the marker is back would go in where the sketch was.
|
||||
if self.deferred.is_some() {
|
||||
self.start_after_roll = finished_sketch.map(|sketch| (id.to_string(), sketch));
|
||||
return;
|
||||
}
|
||||
}
|
||||
self.start_interactive(id, finished_sketch);
|
||||
}
|
||||
|
||||
/// The rest of [`SolveApp::start`], once any sketch `id` ends is finished.
|
||||
pub(crate) fn start_interactive(&mut self, id: &str, finished_sketch: Option<u64>) {
|
||||
if let Some(spec) = solidcraft_engine::find_command(id)
|
||||
&& (tools::Tool::for_command(id).is_some() || dialogs::Dialog::for_command(self, id).is_some())
|
||||
&& self.interactive(id)
|
||||
&& id != "sketch.create"
|
||||
{
|
||||
self.last_command = Some((spec.id.to_string(), spec.label.to_string()));
|
||||
@@ -1275,7 +1293,10 @@ impl SolveApp {
|
||||
self.set_status(tools::hint(id), false);
|
||||
return;
|
||||
}
|
||||
if let Some(d) = dialogs::Dialog::for_command(self, id) {
|
||||
if let Some(mut d) = dialogs::Dialog::for_command(self, id) {
|
||||
if let Some(sketch) = finished_sketch {
|
||||
d.take_sketch_profile(&self.session, sketch);
|
||||
}
|
||||
// The pre-selection now belongs to the dialog's inputs.
|
||||
if d.wants_picks() && !self.session.selection.is_empty() {
|
||||
let _ = self.session.execute("select.clear", &json!({}));
|
||||
@@ -1291,6 +1312,11 @@ impl SolveApp {
|
||||
let _ = self.run(id, json!({}));
|
||||
}
|
||||
|
||||
/// Does starting `id` open a tool or a dialog?
|
||||
fn interactive(&self, id: &str) -> bool {
|
||||
tools::Tool::for_command(id).is_some() || dialogs::Dialog::for_command(self, id).is_some()
|
||||
}
|
||||
|
||||
/// Edit a feature: sketches open in sketch mode; other features roll the
|
||||
/// timeline back to just before themselves and reopen their dialog, filled in.
|
||||
pub fn edit_feature(&mut self, id: u64) {
|
||||
@@ -2196,3 +2222,12 @@ pub fn now_ms() -> f64 {
|
||||
mod picker_test_support;
|
||||
#[cfg(test)]
|
||||
mod test_support;
|
||||
|
||||
/// Toolbar panels whose commands build features from the model; they finish an open sketch first.
|
||||
/// Construct, Inspect and Insert keep the sketch open.
|
||||
const SKETCH_ENDING_PANELS: [&str; 3] = ["CREATE", "MODIFY", "ASSEMBLE"];
|
||||
const SKETCH_TAB: &str = "SKETCH";
|
||||
|
||||
fn ends_sketch(id: &str) -> bool {
|
||||
solidcraft_engine::find_command(id).is_some_and(|c| c.tab != SKETCH_TAB && SKETCH_ENDING_PANELS.contains(&c.panel) && c.id != "sketch.create")
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ fn floating_sketch_palette_and_compass_share_measured_clearance() {
|
||||
}
|
||||
if width > 1000.0 {
|
||||
let content = layout.content;
|
||||
h.app.start("solid.extrude");
|
||||
h.app.start("construct.plane.offset");
|
||||
h.settle();
|
||||
let dialog = h.app.viewport.dialog_rect.unwrap();
|
||||
let expected_top = (content.top() + crate::viewport::AXIS_VIEW_CLEARANCE).min((content.bottom() - 360.0).max(content.top()));
|
||||
|
||||
@@ -269,3 +269,67 @@ fn a_tools_shortcut_pressed_again_cycles_its_modes() {
|
||||
assert_eq!(tool(&h), Some("sketch.rectangle.two_point"));
|
||||
assert_eq!(h.app.tool.as_ref().map(|t| t.pts.len()), Some(1), "the placed corner is kept");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_feature_started_in_a_sketch_finishes_the_sketch_and_takes_its_profile() {
|
||||
for cmd in ["solid.extrude", "solid.revolve"] {
|
||||
let mut h = Harness::new();
|
||||
h.app.start("sketch.create");
|
||||
h.step(&json!({"click":{"plane":"XY"}})).unwrap();
|
||||
h.settle();
|
||||
let sketch = h.app.session.active_sketch.expect("sketch opened");
|
||||
h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[20,10]})).unwrap();
|
||||
h.app.start(cmd);
|
||||
h.settle();
|
||||
assert!(h.app.session.active_sketch.is_none(), "{cmd}: sketch still open");
|
||||
assert_eq!(h.app.ui.tab, "MODEL", "{cmd}");
|
||||
let items = h.app.dialog.as_ref().and_then(|d| d.inputs.first()).map(|i| i.items.clone()).unwrap_or_default();
|
||||
assert_eq!(items, vec![Sel::Profile { sketch, index: 0 }], "{cmd}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_extrude_key_in_a_sketch_finishes_the_sketch() {
|
||||
let mut h = Harness::new();
|
||||
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
|
||||
h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[20,10]})).unwrap();
|
||||
press(&mut h, "E");
|
||||
assert!(h.app.session.active_sketch.is_none());
|
||||
assert!(matches!(h.app.dialog.as_ref().map(|d| &d.kind), Some(crate::dialogs::Kind::Extrude { .. })));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_construct_command_keeps_the_sketch_open() {
|
||||
let mut h = Harness::new();
|
||||
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
|
||||
let sketch = h.app.session.active_sketch;
|
||||
h.app.start("construct.plane.offset");
|
||||
h.settle();
|
||||
assert_eq!(h.app.session.active_sketch, sketch);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_feature_started_while_the_marker_rolls_back_waits_for_it() {
|
||||
let mut h = Harness::new();
|
||||
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
|
||||
let sketch = h.app.session.active_sketch.expect("sketch opened");
|
||||
h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[20,10]})).unwrap();
|
||||
h.app.run("sketch.finish", json!({})).unwrap();
|
||||
h.app.run("solid.extrude", json!({"distance": 5})).unwrap();
|
||||
h.app.edit_feature(sketch);
|
||||
h.app.apply_off_thread = Some(std::time::Duration::ZERO);
|
||||
h.app.start("solid.extrude");
|
||||
assert!(h.app.session.active_sketch.is_none());
|
||||
assert!(h.app.deferred.is_some(), "the marker is not rolling back off the window thread");
|
||||
assert!(h.app.dialog.is_none(), "Extrude opened before the marker was back");
|
||||
for _ in 0..500 {
|
||||
if h.app.deferred.is_none() && h.app.deferred_queue.is_empty() {
|
||||
break;
|
||||
}
|
||||
h.frames(1);
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
assert_eq!(h.app.session.doc.marker, None);
|
||||
let items = h.app.dialog.as_ref().and_then(|d| d.inputs.first()).map(|i| i.items.clone()).unwrap_or_default();
|
||||
assert_eq!(items, vec![Sel::Profile { sketch, index: 0 }], "Extrude did not open once the marker was back");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user