Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions assets/locales/pending/activate-parent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"en": {
"Parent": "Parent",
"cmd.component_activate_parent": "Activate Parent",
"help.component.activate.parent": "Activates the component one level up from the active one, or the design at the top. Use it when you are done with a part you activated, instead of finding its parent in the Browser.",
"ui.heading_active_component": "ACTIVE COMPONENT"
},
"ar": {
"Parent": "الأب",
"cmd.component_activate_parent": "تنشيط المكوّن الأب",
"help.component.activate.parent": "ينشّط المكوّن الأعلى بمستوى واحد من المكوّن النشط، أو التصميم عند القمة. استخدمه عند الانتهاء من جزء نشّطته، بدلًا من البحث عن أبيه في المستعرض.",
"ui.heading_active_component": "المكوّن النشط"
},
"de": {
"Parent": "Übergeordnet",
"cmd.component_activate_parent": "Übergeordnete Komponente aktivieren",
"help.component.activate.parent": "Aktiviert die Komponente eine Ebene über der aktiven, an der Spitze die Konstruktion. Verwenden Sie es, wenn Sie mit einem aktivierten Teil fertig sind, statt die übergeordnete Komponente im Browser zu suchen.",
"ui.heading_active_component": "AKTIVE KOMPONENTE"
},
"he": {
"Parent": "אב",
"cmd.component_activate_parent": "הפעלת רכיב האב",
"help.component.activate.parent": "מפעיל את הרכיב שרמה אחת מעל הרכיב הפעיל, או את התכן בראש העץ. יש להשתמש בו בסיום העבודה על חלק שהופעל, במקום לחפש את רכיב האב שלו בעץ התכן.",
"ui.heading_active_component": "רכיב פעיל"
},
"ja": {
"Parent": "親",
"cmd.component_activate_parent": "親をアクティブ化",
"help.component.activate.parent": "アクティブなコンポーネントの1つ上のコンポーネント(最上位ではデザイン)をアクティブにします。アクティブにした部品の作業が終わったら、ブラウザで親を探す代わりに使います。",
"ui.heading_active_component": "アクティブなコンポーネント"
},
"ko": {
"Parent": "상위",
"cmd.component_activate_parent": "상위 구성 요소 활성화",
"help.component.activate.parent": "활성 구성 요소의 한 단계 위 구성 요소를 활성화하며, 맨 위에서는 디자인을 활성화합니다. 활성화한 부품의 작업을 마쳤을 때 브라우저에서 상위 구성 요소를 찾는 대신 사용하세요.",
"ui.heading_active_component": "활성 구성 요소"
},
"vi": {
"Parent": "Cụm cha",
"cmd.component_activate_parent": "Kích hoạt cụm cha",
"help.component.activate.parent": "Kích hoạt cụm chi tiết cao hơn cụm đang hoạt động một cấp, hoặc thiết kế khi đã ở trên cùng. Dùng khi bạn đã xong với một chi tiết đã kích hoạt, thay vì tìm cụm cha của nó trong Trình duyệt.",
"ui.heading_active_component": "CỤM ĐANG HOẠT ĐỘNG"
},
"zh": {
"Parent": "父级",
"cmd.component_activate_parent": "激活父级",
"help.component.activate.parent": "激活当前激活组件的上一级组件,在最顶层时激活设计。处理完已激活的零件后使用,无需在浏览器中查找其父级。",
"ui.heading_active_component": "激活的组件"
}
}
33 changes: 31 additions & 2 deletions crates/engine/src/cmd/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use solidcraft_doc::{CapturedJoint, CapturedOccurrenceMove, Document, Expr, Feat
use super::CommandSpec;
use crate::params::{bad, bool_, name_or_id_values, str_, string_list, vec3};
use crate::schema::component::{
ActivateParams, ActivateResult, CapturePositionParams, CapturePositionResult, ChildEntry, CompactPlacement, ComponentNode, CopyParams,
CopyResult, CreateParams, CreateResult, CycleColorParams, CycleColorResult, DeleteParams, DeleteResult, DragParams, DragResult,
ActivateParams, ActivateParentParams, ActivateResult, CapturePositionParams, CapturePositionResult, ChildEntry, CompactPlacement, ComponentNode,
CopyParams, CopyResult, CreateParams, CreateResult, CycleColorParams, CycleColorResult, DeleteParams, DeleteResult, DragParams, DragResult,
EditInPlaceParams, EditInPlaceResult, FinishEditParams, FinishEditResult, FromBodiesParams, FromBodiesResult, GroundParams, GroundResult,
HistoryVisibilityParams, HistoryVisibilityResult, ListParams, ListResult, MoveBodiesParams, MoveBodiesResult, MoveFeaturesParams,
MoveFeaturesResult, MoveParams, MoveResult, MoveSketchesParams, MoveSketchesResult, MoveSketchesToPartsParams, MoveSketchesToPartsResult,
Expand All @@ -28,6 +28,7 @@ use crate::schema::{TypedContract, output_schema_for};
use crate::{EngineError, Result, Session};

const ACTIVATE_CONTRACT: TypedContract<ActivateParams> = TypedContract::new();
const ACTIVATE_PARENT_CONTRACT: TypedContract<ActivateParentParams> = TypedContract::new();
const CREATE_CONTRACT: TypedContract<CreateParams> = TypedContract::new();
const DELETE_CONTRACT: TypedContract<DeleteParams> = TypedContract::new();
const FROM_BODIES_CONTRACT: TypedContract<FromBodiesParams> = TypedContract::new();
Expand Down Expand Up @@ -119,6 +120,17 @@ pub static COMMANDS: &[CommandSpec] = &[
.contract(&ACTIVATE_CONTRACT)
.output(output_schema_for::<ActivateResult>)
.params("component: id or name (0 or \"root\" for the design); occurrence?, path?: exact placement used to author shared geometry"),
CommandSpec::new("component.activate.parent", "Activate Parent", crate::checked!("component.activate.parent", activate_parent))
.icon("finish_edit")
.noundo()
.doc_only()
.enabled(below_the_design)
.contract(&ACTIVATE_PARENT_CONTRACT)
.output(output_schema_for::<ActivateResult>)
.params(
"no parameters → active: activates the parent of the active component, at the placement the active one sits in \
(one level up a call; the design at the top); refused while the design itself is active",
),
CommandSpec::new("component.edit_in_place", "Edit in Place", crate::checked!("component.edit_in_place", edit_in_place))
.icon("edit")
.noundo()
Expand Down Expand Up @@ -688,6 +700,23 @@ fn activate(s: &mut Session, p: &Value) -> Result<Value> {
reply(ActivateResult { active: id, param_warnings: Vec::new() })
}

/// `component.activate.parent` is offered only below the design.
fn below_the_design(s: &Session) -> std::result::Result<(), String> {
if s.active_component != 0 { Ok(()) } else { Err("the design is active: it has no parent to return to".into()) }
}

/// The parent is where the active placement's path leads one step short of its end, so a part
/// placed in two assemblies goes back to the one it was activated in.
fn activate_parent(s: &mut Session, _p: &Value) -> Result<Value> {
let mut path = s.active_path();
path.pop();
let parent = s.doc.path_placement(&path).map_or(0, |(component, _)| component);
s.active_component = parent;
s.active_occurrence_path = (!path.is_empty()).then_some(path);
s.revision += 1;
reply(ActivateResult { active: parent, param_warnings: Vec::new() })
}

fn list(s: &mut Session, p: &Value) -> Result<Value> {
let st = s.model.state();
let doc = &s.doc;
Expand Down
34 changes: 34 additions & 0 deletions crates/engine/src/cmd/occurrence_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2916,6 +2916,40 @@ fn component_names_count_characters_not_bytes() {
let error = s.execute("component.rename", &json!({"component": component, "name": "ł".repeat(129)})).unwrap_err().to_string();
assert!(error.contains("1…128 characters"), "{error}");
}

/// Activate Parent goes up one level a call, through the placement the active part sits in, to
/// the design at the top; there it is refused and nothing changes (#18516).
#[test]
fn activate_parent_goes_up_one_level_through_the_active_placement() {
let mut s = Session::default();
let (assembly, first) = created(&mut s, "Assembly");
let (part, _) = created(&mut s, "Part");
run(&mut s, "component.activate", json!({"component": 0}));
let second = run(&mut s, "occurrence.copy", json!({"occurrence": first, "translate": [50, 0, 0]}))["occurrence"].as_u64().unwrap();
let active = |s: &Session| (s.active_component, s.active_occurrence_path.clone());
// The part inside the second placement of the assembly, as a double-click on its face activates it.
let path = s.doc.placements().into_iter().map(|(_, path, _)| path).find(|p| p.len() == 2 && p[0] == second).unwrap();
run(&mut s, "component.activate", json!({"component": part, "occurrence": path[1], "path": path}));
assert_eq!(run(&mut s, "component.activate.parent", json!({}))["active"], json!(assembly));
assert_eq!(active(&s), (assembly, Some(vec![second])), "the assembly the part sits in, not its first placement");
assert_eq!(s.active_component_frame()[3][0], 50.0);
run(&mut s, "component.activate.parent", json!({}));
assert_eq!(active(&s), (0, None));
// At the top: refused, and the design stays active.
let error = s.execute("component.activate.parent", &json!({})).unwrap_err().to_string();
assert!(error.contains("no parent"), "{error}");
assert_eq!(active(&s), (0, None));
// Activated with no placement (the Browser's radio button): up through its first placement.
run(&mut s, "component.activate", json!({"component": part}));
run(&mut s, "component.activate.parent", json!({}));
assert_eq!(active(&s), (assembly, Some(vec![first])));
// A placement that no longer leads to the active component (deleted since) counts as none.
s.active_component = part;
s.active_occurrence_path = Some(vec![999]);
run(&mut s, "component.activate.parent", json!({}));
assert_eq!(active(&s), (assembly, Some(vec![first])));
}

/// The Browser's index of placed bodies (their path, by world name) makes the design's name
/// index once for the whole walk, not once at every placement: naming each placement on its own
/// built the index for every placement, and on a 100-printer assembly that was 14 s inside one
Expand Down
9 changes: 9 additions & 0 deletions crates/engine/src/occurrences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,15 @@ impl Session {
self.occurrence_placement(&path).map(|p| p.world).unwrap_or(IDENTITY)
}

/// The active component's placement as occurrence ids from the top: the one it was activated
/// at while that still leads to it, else its first. Empty for the design.
pub fn active_path(&self) -> Vec<u64> {
match &self.active_occurrence_path {
Some(path) if self.doc.path_placement(path).is_some_and(|(component, _)| component == self.active_component) => path.clone(),
_ => self.doc.first_path(self.active_component),
}
}

pub fn occurrence_visible(&self, path: &[u64]) -> bool {
!self.visibility.hidden_occurrences.iter().any(|hidden| path.starts_with(hidden))
}
Expand Down
9 changes: 8 additions & 1 deletion crates/engine/src/schema/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,14 @@ impl JsonSchema for ActivateParams {
}
}

/// What `component.activate` returns.
/// Make the parent of the active component the active one, at the placement the active one sits
/// in: one level up a call, the design at the top. Refused while the design itself is active. A
/// change of what is active, not an undo step. Replies as `component.activate` does.
#[derive(Debug, Deserialize, JsonSchema)]
#[schemars(deny_unknown_fields)]
pub struct ActivateParentParams {}

/// What `component.activate` and `component.activate.parent` return.
#[derive(Debug, Serialize, JsonSchema)]
pub struct ActivateResult {
/// The active component now, by id.
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/command_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub const DOCUMENTED: &[&str] = &[
"canvas.decal",
"canvas.edit",
"canvas.insert",
"component.activate.parent",
"component.break_link",
"component.capture_position",
"component.create",
Expand Down
101 changes: 101 additions & 0 deletions crates/ui-egui/src/occurrence_ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,107 @@ fn construction_features_keep_their_labels_and_styling() {
assert_eq!(crate::viewport::component_origin_item(&h.app, "XY"), None);
}

/// A part inside an assembly, active, with a closed sketch of its own on XY: (harness, assembly,
/// part).
fn nested_part_active() -> (Harness, u64, u64) {
let mut h = Harness::new();
let assembly = h.app.run("component.create", json!({"name":"Assembly","grounded":false})).unwrap()["component"].as_u64().unwrap();
let part = h.app.run("component.create", json!({"name":"Part","grounded":false})).unwrap()["component"].as_u64().unwrap();
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[20,20]})).unwrap();
h.app.run("sketch.finish", json!({})).unwrap();
h.app.ui.tab = "MODEL".into();
h.settle();
(h, assembly, part)
}

/// While a component other than the design is active, the MODEL tab ends with Activate Parent,
/// which goes up one level a click; with the design active the group is gone (#18516).
#[test]
fn activate_parent_is_on_the_model_tab_only_while_a_component_is_active() {
let (mut h, assembly, _) = nested_part_active();
let group = || crate::scenario::rect_of("panel:MODEL:ACTIVE COMPONENT");
assert!(group().is_some(), "the part is active");
crate::test_support::click(&mut h, "button:component.activate.parent");
assert_eq!(h.app.session.active_component, assembly);
assert!(group().is_some(), "the assembly is active");
crate::test_support::click(&mut h, "button:component.activate.parent");
assert_eq!(h.app.session.active_component, 0);
assert!(group().is_none(), "the design is active: nothing to return from");
assert!(crate::scenario::handle_at("button:component.activate.parent").is_none());
}

/// A double-click on empty space in the view goes up one level, as Activate Parent does: only
/// where nothing is under the pointer, with no window or sketch open, no key held, and
/// "Double-click components" on (#18516).
#[test]
fn a_double_click_in_empty_space_returns_to_the_parent() {
let (mut h, assembly, part) = nested_part_active();
let cam = h.app.cam;
let rect = h.app.viewport.rect.unwrap();
let proj = crate::viewport::projection(&h.app, rect);
let drawable = h.app.viewport.layout.as_ref().unwrap().drawable;
let empty = [(0.3, 0.7), (0.7, 0.7), (0.3, 0.3), (0.7, 0.3), (0.5, 0.85)]
.into_iter()
.map(|(x, y)| drawable.left_top() + egui::vec2(drawable.width() * x, drawable.height() * y))
.find(|p| crate::viewport::pick(&h.app, &proj, *p).is_empty() && !crate::shell::covered(&h.app, *p))
.expect("a spot in the view with nothing under it");
let double = |h: &mut Harness, extra: serde_json::Value| {
// Past egui's double-click window, so this is a new double-click and not a triple.
h.frames(40);
h.app.cam = cam;
let mut click = json!({"x": empty.x, "y": empty.y, "double": true});
click.as_object_mut().unwrap().extend(extra.as_object().unwrap().clone());
h.call("ui.click", click);
crate::test_support::play(h);
};
// Something under the pointer (the part's own sketch): it stays active.
h.step(&json!({"click":{"world":[10,10,0]},"double":true})).unwrap();
crate::test_support::play(&mut h);
assert_eq!(h.app.session.active_component, part, "a double-click on the sketch");
// The preference off, a window open, a sketch open, or Shift held: nothing changes.
h.app.preferences.double_click_components = false;
double(&mut h, json!({}));
assert_eq!(h.app.session.active_component, part, "the preference is off");
h.app.preferences.double_click_components = true;
h.app.start("solid.box");
h.frames(4);
assert!(h.app.dialog.is_some());
double(&mut h, json!({}));
assert_eq!(h.app.session.active_component, part, "a window is open");
crate::dialogs::cancel(&mut h.app);
h.settle();
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
double(&mut h, json!({}));
assert_eq!(h.app.session.active_component, part, "a sketch is open");
h.app.run("sketch.cancel", json!({})).unwrap();
h.settle();
double(&mut h, json!({"shift": true}));
assert_eq!(h.app.session.active_component, part, "Shift is held");
// Up one level a double-click, then the design, where a double-click does nothing.
double(&mut h, json!({}));
assert_eq!(h.app.session.active_component, assembly);
double(&mut h, json!({}));
assert_eq!(h.app.session.active_component, 0);
double(&mut h, json!({}));
assert_eq!(h.app.session.active_component, 0);
assert!(h.app.messages.iter().all(|m| !m.error), "no refusal is shown for the design");
}

/// While the view moves, the pick under the pointer isn't taken, so nothing is under it as far as
/// the view knows: a double-click then is not one in empty space, and the part stays active (#18516).
#[test]
fn a_double_click_while_the_view_moves_keeps_the_part_active() {
let (mut h, _, part) = nested_part_active();
let mut still = solidcraft_viewport::CameraAnim::new(h.app.cam, h.app.cam, h.app.now);
still.duration = 1e9;
h.app.cam_anim = Some(still);
h.step(&json!({"click":{"world":[10,10,0]},"double":true})).unwrap();
crate::test_support::play(&mut h);
assert!(h.app.cam_anim.is_some(), "the view is still moving");
assert_eq!(h.app.session.active_component, part, "a double-click on the sketch while the view moves");
}

#[test]
fn nested_component_move_with_capture_false_preserves_world_expression_and_rebuilds() {
let mut h = Harness::new();
Expand Down
Loading
Loading