* Render appearance: click, drag and paint to assign, Pick Up, copy and paste, and Remove * Exclude the workspace Shots strip from dialog width checks * Exclude the collapsed Shots control from dialog width checks * Retain assembly cache listings and measure actual dialog bounds * fix: handle toast button rectangles in assignment status * fix: restrict gallery note measurement helper to tests * test: measure assignment help at the catalogue footer * fix: share the command revision snapshot after restacking
This commit is contained in:
1 parent
75035ac4a5
commit
c1925bb219
29 files changed
+1725
-132
No files matched your search
@@ -0,0 +1,77 @@
|
||||
//! Assignment tools share the existing look parser, chain and atomic assignment command.
|
||||
use crate::{Result, Session, params::bad};
|
||||
use serde_json::{Value, json};
|
||||
use solidcraft_doc::appearance::Look;
|
||||
|
||||
pub(in crate::cmd) fn paint(_s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if p.get("done").and_then(Value::as_bool) == Some(true) {
|
||||
return Ok(json!({"done":true}));
|
||||
}
|
||||
let look = super::appearance_look("appearance.paint", p)?.ok_or_else(|| bad("appearance.paint", "choose a look first"))?;
|
||||
Ok(json!({"look": super::look_json(&look)}))
|
||||
}
|
||||
|
||||
fn resolved(s: &mut Session, p: &Value) -> Result<Look> {
|
||||
let chain = super::appearance_chain::chain(s, p)?;
|
||||
let value = chain["steps"].as_array().and_then(|steps| steps.iter().find(|step| !step["look"].is_null())).map(|step| step["look"].clone());
|
||||
if let Some(value) = value {
|
||||
return super::appearance_look("appearance.pick_up", &value)?.ok_or_else(|| bad("appearance.pick_up", "target has no look"));
|
||||
}
|
||||
// Imported paint is outside the four-step chain, but remains the display fallback.
|
||||
let state = s.model.state();
|
||||
let body = p
|
||||
.pointer("/target/body")
|
||||
.and_then(Value::as_str)
|
||||
.and_then(|name| state.body(name))
|
||||
.ok_or_else(|| bad("appearance.pick_up", "target has no resolved look"))?;
|
||||
let displayed = p
|
||||
.pointer("/target/face")
|
||||
.and_then(Value::as_u64)
|
||||
.and_then(|face| usize::try_from(face).ok())
|
||||
.map_or_else(|| s.doc.model_display_look(body), |face| s.doc.model_face_look(body, face));
|
||||
if let Some(look) = displayed {
|
||||
return Ok(look);
|
||||
}
|
||||
let fallback = crate::view::colors::BODY;
|
||||
let color =
|
||||
s.doc.body_color(body).map(|rgb| rgb.map(|v| (v.clamp(0.0, 1.0) * 255.0).round() as u8)).unwrap_or([fallback.0, fallback.1, fallback.2]);
|
||||
Ok(Look { name: "Default".into(), color, opacity: 1.0, pbr: None })
|
||||
}
|
||||
|
||||
pub(in crate::cmd) fn pick_up(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if p.as_object().is_some_and(|p| p.is_empty()) {
|
||||
return Ok(json!({"tool":"pick_up"}));
|
||||
}
|
||||
Ok(json!({"look":super::look_json(&resolved(s, p)?)}))
|
||||
}
|
||||
|
||||
pub(in crate::cmd) fn copy(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let look = resolved(s, p)?;
|
||||
let reply = json!({"look":super::look_json(&look)});
|
||||
s.appearance_clipboard = Some(look);
|
||||
Ok(reply)
|
||||
}
|
||||
|
||||
pub(in crate::cmd) fn favorite(_s: &mut Session, p: &Value) -> Result<Value> {
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Request {
|
||||
look: Value,
|
||||
favorite: bool,
|
||||
}
|
||||
let request: Request = serde_json::from_value(p.clone()).map_err(|e| bad("appearance.favorite", e.to_string()))?;
|
||||
let look = super::appearance_look("appearance.favorite", &request.look)?.ok_or_else(|| bad("appearance.favorite", "give a look"))?;
|
||||
Ok(json!({"look":super::look_json(&look), "favorite":request.favorite}))
|
||||
}
|
||||
|
||||
pub(in crate::cmd) fn paste(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let look = s.appearance_clipboard.as_ref().ok_or_else(|| bad("appearance.paste", "copy a look first"))?;
|
||||
let mut params = p.as_object().cloned().ok_or_else(|| bad("appearance.paste", "give assignment targets"))?;
|
||||
for key in ["appearance", "name", "color", "opacity", "pbr"] {
|
||||
params.remove(key);
|
||||
}
|
||||
for (key, value) in super::look_json(look).as_object().into_iter().flatten() {
|
||||
params.insert(key.clone(), value.clone());
|
||||
}
|
||||
super::appearance(s, &Value::Object(params))
|
||||
}
|
||||
@@ -15,6 +15,9 @@ use crate::{EngineError, Result, Session};
|
||||
#[path = "appearance_chain.rs"]
|
||||
mod appearance_chain;
|
||||
|
||||
#[path = "appearance_gestures.rs"]
|
||||
pub(super) mod appearance_gestures;
|
||||
|
||||
pub static COMMANDS: &[CommandSpec] = &[
|
||||
CommandSpec::new("inspect.colored_components", "Enable Component Colors", colored_components)
|
||||
.at("SOLID", "INSPECT").icon("colored_components").noundo()
|
||||
@@ -49,6 +52,12 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
appearance?: library name or stable starter.* ID (appearance.library) | color: \"#rrggbb\" or [r, g, b] (0–255), opacity? (0–1, default 1); \
|
||||
name?: inert copied look label (requires color, mutually exclusive with appearance); pbr?: {metallic:0..1, roughness:0.045..1, dielectric_ior:1..3} (requires color/appearance and opacity 1); a starter ID or registered starter name resolves its recipe before color overrides; omitted pbr retains that response and pbr: null explicitly clears it. Unavailable glass recipes refuse through either selector. Other custom labels with an explicit color retain legacy scalar behavior. Neither appearance nor color (or color: null): clear, so the face follows its body, the body its component, the component its material",
|
||||
),
|
||||
CommandSpec::new("appearance.copy", "Copy Look", appearance_gestures::copy).icon("copy").noundo().key("Ctrl+Alt+C")
|
||||
.params("target: appearance.chain target. Copies its resolved look to a transient session clipboard. No document change or dialogs."),
|
||||
CommandSpec::new("appearance.paste", "Paste Look", appearance_gestures::paste).icon("paste").key("Ctrl+Alt+V")
|
||||
.params("bodies/faces/components: appearance.assign targets. Applies the copied look atomically in one undo step; no dialogs."),
|
||||
CommandSpec::new("appearance.favorite", "Favourite Look", appearance_gestures::favorite).icon("star").noundo().doc_only()
|
||||
.params("look: appearance.assign look; favorite: bool → validated look and preference request; UI library preference only, no document change or dialogs."),
|
||||
CommandSpec::new("appearance.chain", "Appearance Chain", appearance_chain::chain).icon("inspect").noundo().params(
|
||||
"target: {body: name} | {body: name, face: zero-based model.faces index} | {component: name or id}. Returns steps [{step: face|body|component|material, look: {name,color,opacity,pbr?} or null}] in precedence order and active (step or null). Component material is the common default look of its directly owned bodies, null if mixed/empty. Imported paint is a display fallback outside the four steps. Read-only; no dialogs",
|
||||
),
|
||||
|
||||
@@ -878,3 +878,70 @@ fn appearance_chain_and_replace_process_ten_thousand_entries_with_bounded_output
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn appearance_gestures_copy_paste_preserve_full_resolved_look_and_history() {
|
||||
let mut s = fixture();
|
||||
s.execute(
|
||||
"appearance.assign",
|
||||
&json!({"body":"Specimen","faces":[[5,10,5]],"name":"Sampled","color":"#345678","pbr":{"metallic":0.2,"roughness":0.3,"dielectric_ior":1.6}}),
|
||||
)
|
||||
.unwrap();
|
||||
let face = s.execute("model.faces", &json!({"body":"Specimen"})).unwrap()["faces"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|f| f["point"][2].as_f64() == Some(5.0))
|
||||
.unwrap()["index"]
|
||||
.clone();
|
||||
let before = s.doc.clone();
|
||||
let undo = s.undo.len();
|
||||
let target = json!({"body":"Specimen","face":face});
|
||||
let sampled = s.execute("appearance.pick_up", &json!({"target":target})).unwrap();
|
||||
assert_eq!(sampled["look"]["name"], "Sampled");
|
||||
assert_eq!(s.execute("appearance.copy", &json!({"target":target})).unwrap(), sampled);
|
||||
s.execute("appearance.paint", &sampled["look"]).unwrap();
|
||||
assert!(Arc::ptr_eq(&before, &s.doc));
|
||||
assert_eq!(s.undo.len(), undo);
|
||||
s.execute("appearance.paste", &json!({"bodies":["Specimen"]})).unwrap();
|
||||
assert_eq!(s.undo.len(), undo + 1);
|
||||
assert_eq!(serde_json::to_value(&s.doc.appearances.bodies["Specimen"]).unwrap()["pbr"], sampled["look"]["pbr"]);
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.to_json(), before.to_json());
|
||||
let document = s.doc.clone();
|
||||
let history = (s.undo.len(), s.redo.len());
|
||||
for (id, params) in [
|
||||
("appearance.pick_up", json!({"target":{"body":"missing"}})),
|
||||
("appearance.copy", json!({"target":{"body":"Specimen","face":999999}})),
|
||||
("appearance.paste", json!({"bodies":["Specimen","missing"]})),
|
||||
("appearance.paint", json!({"appearance":"starter.glass.clear-soda-lime"})),
|
||||
] {
|
||||
assert!(s.execute(id, ¶ms).is_err(), "{id}");
|
||||
assert!(Arc::ptr_eq(&document, &s.doc));
|
||||
assert_eq!((s.undo.len(), s.redo.len()), history);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn appearance_gestures_favorite_is_a_validated_transient_request() {
|
||||
let mut s = fixture();
|
||||
let before = s.doc.clone();
|
||||
let state = (s.undo.len(), s.redo.len(), s.revision, s.evaluations, s.is_dirty());
|
||||
for favorite in [true, false] {
|
||||
let reply = s.execute("appearance.favorite", &json!({"look":{"appearance":"Copper"},"favorite":favorite})).unwrap();
|
||||
assert_eq!(reply["look"]["name"], "Copper");
|
||||
assert_eq!(reply["favorite"], favorite);
|
||||
}
|
||||
for params in [
|
||||
json!(null),
|
||||
json!([]),
|
||||
json!({}),
|
||||
json!({"look":{},"favorite":true}),
|
||||
json!({"look":{"color":"#123456"},"favorite":"true"}),
|
||||
json!({"look":{"color":"#123456"},"favorite":true,"extra":1}),
|
||||
] {
|
||||
assert!(s.execute("appearance.favorite", ¶ms).is_err());
|
||||
}
|
||||
assert!(Arc::ptr_eq(&before, &s.doc));
|
||||
assert_eq!((s.undo.len(), s.redo.len(), s.revision, s.evaluations, s.is_dirty()), state);
|
||||
}
|
||||
@@ -35,8 +35,13 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
.doc_only()
|
||||
.params("No parameters. Return to Model Preview; headless echo only, never cancels a job."),
|
||||
waiting!("render.lights.add", "Add Light", "RENDER SCENE", "LIGHTS", "render_scene", "named light creation"),
|
||||
waiting!("appearance.paint", "Paint Appearance", "RENDER APPEARANCE", "APPEARANCE", "appearance", "product picking and appearance painting"),
|
||||
waiting!("appearance.pick_up", "Pick Up Appearance", "RENDER APPEARANCE", "APPEARANCE", "select", "product picking and appearance sampling"),
|
||||
CommandSpec::new("appearance.paint", "Paint Appearance", super::inspect::appearance_gestures::paint)
|
||||
.icon("appearance").key("B").noundo()
|
||||
.params("appearance or color/name/opacity/pbr: appearance.assign look parameters; validates and returns look for ui.start paint. done?: true ends the UI tool. Programmatic calls never open UI."),
|
||||
CommandSpec::new("appearance.pick_up", "Pick Up Appearance", super::inspect::appearance_gestures::pick_up)
|
||||
.icon("select").key("I").noundo()
|
||||
.params("target?: appearance.chain target; returns its resolved look, or requests the UI sampling tool when omitted. Programmatic calls never open UI."),
|
||||
|
||||
waiting!("render.lights.solo", "Solo Light", "RENDER SCENE", "LIGHTS", "render_scene", "light visibility and solo controls"),
|
||||
waiting!("render.compare", "Compare Images", "RENDER", "RESULT", "compare", "retained image comparison"),
|
||||
waiting!("render.batch", "Render All Shots", "RENDER", "BATCH", "render_image", "the saved-shot render queue"),
|
||||
|
||||
@@ -403,6 +403,8 @@ pub struct Session {
|
||||
pub clipboard: Vec<solidcraft_doc::Feature>,
|
||||
/// Sketch geometry copied with `sketch.copy` (pasted by `sketch.paste`).
|
||||
pub sketch_clipboard: Option<cmd::sketch_clipboard::SketchClip>,
|
||||
/// Resolved appearance copied by appearance.copy; transient, outside design/history.
|
||||
pub appearance_clipboard: Option<solidcraft_doc::appearance::Look>,
|
||||
/// Section Analysis: a view cut by a plane (origin, unit normal; the normal side is hidden).
|
||||
pub section: Option<(Vec3, Vec3)>,
|
||||
/// Whether the section's cut faces are hatched (`inspect.section`'s `hatch`; on by default).
|
||||
@@ -585,6 +587,7 @@ impl Session {
|
||||
contact_meshes: Default::default(),
|
||||
clipboard: Vec::new(),
|
||||
sketch_clipboard: None,
|
||||
appearance_clipboard: None,
|
||||
section: None,
|
||||
section_hatch: true,
|
||||
colored_components: None,
|
||||
@@ -1425,6 +1428,7 @@ impl Session {
|
||||
contact_meshes: self.contact_meshes.clone(),
|
||||
clipboard: self.clipboard.clone(),
|
||||
sketch_clipboard: self.sketch_clipboard.clone(),
|
||||
appearance_clipboard: self.appearance_clipboard.clone(),
|
||||
section: None,
|
||||
section_hatch: true,
|
||||
colored_components: None,
|
||||
|
||||
@@ -369,11 +369,14 @@ impl Session {
|
||||
}
|
||||
if let Some(cache) = cache.as_mut() {
|
||||
if !cache.bodies.contains_key(&key) && cache.bodies.len() >= OCCURRENCE_BODIES_CACHED {
|
||||
// Retire one remembered answer, not the whole cache: a burst of other
|
||||
// paths (a Browser reveal, a hover) no longer evicts the active
|
||||
// occurrence's entry and forces a full re-expansion on the next
|
||||
// highlight build (#7502).
|
||||
if let Some(evict) = cache.bodies.keys().next().cloned() {
|
||||
// Retire the deepest path first, preferring direct-body answers over
|
||||
// subtree answers at equal depth, then the greatest full key for a
|
||||
// stable tie break. Broader assembly listings survive bursts of per-copy
|
||||
// queries (#7502). Selecting a victim scans at most 256 cached keys,
|
||||
// avoiding extra eviction bookkeeping while keeping the cache bounded.
|
||||
if let Some(evict) =
|
||||
cache.bodies.keys().max_by(|a, b| a.0.len().cmp(&b.0.len()).then_with(|| b.1.cmp(&a.1)).then_with(|| a.cmp(b))).cloned()
|
||||
{
|
||||
cache.bodies.remove(&evict);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user