Files
OneCAD-Draft/src/modules/view/visual_style.rs
T
Hakan SevenandClaude Opus 5.5 f537aff75c feat: node graph overlay; move to opencadcodec/opencadkernel/opencadgraph
The codec and kernel repositories and crates are renamed opencadcodec and
opencadkernel. Inside OCS they are depended on under short keys, so code
reads `codec::`, `kernel::` and the new `graph::` (opencadgraph, the node
graph engine). File-format and protocol spellings stay as they were: the
ACIS product id `acadrust`, the ACADRUST_* switches and the plugin
version keys `acadrust_version` / `acadrust_source`.

A button left of MCP on the command line opens a translucent node graph
over the viewport, with a palette of object, input, math, logic, list,
text and geometry nodes added by click or drag. An object node owns
drawing entities and its rows are the Properties panel's own rows for
them: the single-object page is extracted from refresh_properties as
entity_property_sections, values use the control protocol's
property_json, and writes go through set_property_value with a property
target override, so the panel, MCP and the graph share one read/write
path. A list reaching an object row makes one entity per element. Each
graph action is one undo step; the canvas pans and zooms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 07:34:23 +03:00

118 lines
4.1 KiB
Rust

// The visual styles a viewport can be drawn in, in one list.
//
// Three places offer the same choice and used to describe it separately: the
// Visual Style dropdown on the ribbon, the render-mode picker with its preview
// cube, and the VISUALSTYLES command. The ribbon's copy had drifted furthest —
// it named four styles, two of which reached nothing (its "Shaded" carried the
// id `SOLID`, which is the 2D solid *drawing* command, and `HIDDEN` matched no
// command at all). Naming each style once, next to the command that applies it,
// is what keeps the three in step. (#621)
use codec::entities::ViewportRenderMode as Mode;
use crate::modules::IconKind;
const WIREFRAME_ICON: IconKind =
IconKind::Svg(include_bytes!("../../../assets/icons/wireframe.svg"));
const HIDDEN_ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/hidden.svg"));
const SHADED_ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/solid.svg"));
pub struct VisualStyle {
pub mode: Mode,
/// What the user sees, wherever the style is offered.
pub label: &'static str,
/// The command line that applies it. Ribbon items dispatch this verbatim,
/// so it doubles as the item's identity for the checkmark and the
/// last-used-tool memory. The keyword is the render mode's own name — there
/// is one set of styles now, so there is one set of names for them.
pub command: &'static str,
pub icon: IconKind,
}
/// Every style, in the order they are offered — wireframes, then hidden line,
/// then the shaded ones, each pair plain before with-edges.
pub const VISUAL_STYLES: &[VisualStyle] = &[
VisualStyle {
mode: Mode::Wireframe2D,
label: "Wireframe 2D",
command: "VISUALSTYLES WIREFRAME2D",
icon: WIREFRAME_ICON,
},
VisualStyle {
mode: Mode::Wireframe3D,
label: "Wireframe 3D",
command: "VISUALSTYLES WIREFRAME3D",
icon: WIREFRAME_ICON,
},
VisualStyle {
mode: Mode::HiddenLine,
label: "Hidden Line",
command: "VISUALSTYLES HIDDENLINE",
icon: HIDDEN_ICON,
},
VisualStyle {
mode: Mode::FlatShaded,
label: "Flat Shaded",
command: "VISUALSTYLES FLATSHADED",
icon: SHADED_ICON,
},
VisualStyle {
mode: Mode::GouraudShaded,
label: "Gouraud Shaded",
command: "VISUALSTYLES GOURAUDSHADED",
icon: SHADED_ICON,
},
VisualStyle {
mode: Mode::FlatShadedWithEdges,
label: "Flat Shaded + Edges",
command: "VISUALSTYLES FLATSHADEDWITHEDGES",
icon: SHADED_ICON,
},
VisualStyle {
mode: Mode::GouraudShadedWithEdges,
label: "Gouraud Shaded + Edges",
command: "VISUALSTYLES GOURAUDSHADEDWITHEDGES",
icon: SHADED_ICON,
},
];
impl VisualStyle {
/// The bare keyword, without the verb its `command` spells out.
pub fn keyword(&self) -> &'static str {
self.command
.strip_prefix("VISUALSTYLES ")
.unwrap_or(self.command)
}
}
/// The choices an interactive style prompt offers, in table order.
pub fn keyword_choices() -> Vec<(&'static str, &'static str, Option<&'static str>)> {
VISUAL_STYLES
.iter()
.map(|style| (style.label, style.keyword(), None))
.collect()
}
/// Stable source used by the shared command prompt translator.
pub fn keyword_prompt() -> &'static str {
"Visual style [Wireframe 2D/Wireframe 3D/Hidden Line/Flat Shaded/Gouraud Shaded/Flat Shaded + Edges/Gouraud Shaded + Edges]:"
}
pub fn label_for(mode: Mode) -> &'static str {
VISUAL_STYLES
.iter()
.find(|style| style.mode == mode)
.map(|style| style.label)
.unwrap_or("Wireframe 2D")
}
/// The style a style keyword names. Only the seven exist; nothing maps onto a
/// nearest neighbour, because there is no longer anything else to map from.
pub fn mode_for_keyword(keyword: &str) -> Option<Mode> {
let keyword = keyword.trim().to_uppercase();
VISUAL_STYLES
.iter()
.find(|style| style.keyword() == keyword)
.map(|style| style.mode)
}