Colored components (feature request #2507) (#2877)

* feat: add colored components inspection toggle

* feat: persist component colors and add cycling controls

* feat: assign component colors in creation order

* fix: update component color menu integration and translations

* fix: proper description for pending format change.

* fix: deleted duplicated format change description from docs/pending.

* Compare the component colour counter in the features-only check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Vadim Kalinsky <vadim@kalinsky.com>
Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vadim Kalinsky
2026-10-25 21:11:03 +00:00
committed by GitHub
parent 5fbe058051
commit 59cad5f0bb
27 changed files with 488 additions and 20 deletions
+13
View File
@@ -28,6 +28,9 @@ mod transfer;
mod occurrence_tests;
pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("component.cycle_color", "Cycle Component Color", cycle_color)
.icon("colored_components").doc_only()
.params("component: id or name; saves the next identification colour and enables Component Colors; shared by every instance, separate from appearances"),
CommandSpec::new("component.create", "New Component", new_component)
.at("SOLID", "ASSEMBLE")
.icon("component")
@@ -565,3 +568,13 @@ pub fn to_active_frame(s: &Session, kind: &mut FeatureKind) {
kind.transform_geometry(&inv);
}
}
fn cycle_color(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "component.cycle_color";
let id = component(s, p, "component", cmd)?;
let next = solidcraft_doc::component_color::next_color(s.doc.component_identification_color(id));
let c = s.doc_mut().components.iter_mut().find(|c| c.id == id).ok_or_else(|| bad(cmd, "choose a component below the design root"))?;
c.identification_color = Some(next);
s.colored_components = Some(());
Ok(json!({"component": id, "color": next}))
}
+1
View File
@@ -257,6 +257,7 @@ pub(super) fn paste(
if let Some(added) = scratch.doc_mut().components.iter_mut().find(|x| x.id == new) {
added.metadata = c.metadata.clone();
added.properties = c.properties.clone();
added.identification_color = c.identification_color;
}
components.insert(*old, new);
if *old != component {
+16
View File
@@ -8,6 +8,9 @@ use crate::params::{bad, bool_, str_, string_list};
use crate::{EngineError, Result, Session};
pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("inspect.colored_components", "Enable Component Colors", colored_components)
.at("SOLID", "INSPECT").icon("colored_components").noundo()
.params("enabled?: bool (omitted: toggle); temporary component colours, without changing appearances"),
CommandSpec::new("inspect.measure", "Measure", measure)
.at("SOLID", "INSPECT")
.icon("measure")
@@ -724,3 +727,16 @@ fn material_list(s: &mut Session, _p: &Value) -> Result<Value> {
.collect::<Result<Vec<_>>>()?;
Ok(json!({"materials": built_in.chain(user).collect::<Vec<_>>()}))
}
fn colored_components(s: &mut Session, p: &Value) -> Result<Value> {
if p.get("enabled").is_some_and(|v| !v.is_boolean()) {
return Err(bad("inspect.colored_components", "enabled must be a boolean"));
}
let enabled = bool_(p, "enabled").unwrap_or(s.colored_components.is_none());
if enabled && s.colored_components.is_none() {
s.colored_components = Some(());
} else if !enabled {
s.colored_components = None;
}
Ok(json!({"enabled": enabled}))
}
+6 -2
View File
@@ -215,12 +215,16 @@ impl CommandSpec {
}
pub fn info(&self, s: &Session) -> CommandInfo {
let e = (self.enabled)(s);
let (label, icon) = match self.id {
"inspect.colored_components" if s.colored_components.is_some() => ("Disable Component Colors", "colored_components_off"),
_ => (self.label, self.icon),
};
CommandInfo {
id: self.id,
label: self.label,
label,
tab: self.tab,
panel: self.panel,
icon: self.icon,
icon,
shortcut: self.shortcut,
params: self.params,
enabled: e.is_ok(),