forked from 1b-agent/opencadstudio-upstream
feat(view): one list of visual styles behind every way of choosing one
The ribbon offered four styles and dispatched each one's id as a command. Two of those ids were not visual-style commands: "Shaded" carried SOLID, which draws a 2D filled polygon, so choosing it started a draw command; "Hidden" carried HIDDEN, which matched nothing at all, so it did nothing. The intent had been for the button to fire its tool's event, but the dropdown never reads one -- it dispatches the id. Behind that sat two generations of the same feature. The render-mode picker offered the seven styles a viewport can actually be drawn in; everything else -- the ribbon, VSCURRENT, SHADEMODE, VISUALSTYLES and a handful of bare verbs -- went through a binary wireframe-or-shaded flag that could only approximate them, reporting "Hidden (shown shaded)" and "X-Ray (shown as wireframe)" when asked for something it had no way to draw. Four descriptions of one choice, each drifting on its own. There is one list now. Each style names itself once -- mode, label, icon, and the command that applies it -- and the ribbon, the picker, the VISUALSTYLES verb and the interactive prompt all read from it, down to the line that lists the choices, so what is offered cannot disagree with what works. Keywords are the render modes' own names, since there is one set of styles left to name. The binary path is gone rather than kept alongside: its message, its module event, the tool definitions that produced it, the ribbon's special-cased highlight arms, the bare style verbs and the older keyword spellings. X-Ray goes with it -- no render mode draws one, and it was already coming out as a plain wireframe. Three files that had been left holding a single icon constant each fold into the list. Note: ModuleEvent::SetWireframe leaves the plugin API with it. Closes #621 Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
1 parent
5c5c7606a1
commit
b5a1146966
18 files changed
+170
-187
No files matched your search
+16
-42
@@ -103,66 +103,40 @@ impl OpenCADStudio {
|
||||
}
|
||||
}
|
||||
"CLEAR" | "CLR" => return Some(Task::done(Message::ClearScene)),
|
||||
"WIREFRAME" => return Some(Task::done(Message::SetWireframe(true))),
|
||||
// Visual-style commands. OCS renders either a wireframe or a shaded
|
||||
// view; the named styles map onto the closest of the two and the
|
||||
// chosen style is reported so the mapping is explicit. (`SOLID` is
|
||||
// intentionally NOT a visual-style verb — it is the 2D filled-polygon
|
||||
// draw command; the shaded ribbon button drives `SetWireframe`.)
|
||||
"VS" | "VSCURRENT" | "SHADEMODE" => {
|
||||
// One interactive picker behind every verb that asks for a style,
|
||||
// offering exactly what the render-mode widget offers. (#621)
|
||||
"VS" | "VSCURRENT" | "SHADEMODE" | "VISUALSTYLES" => {
|
||||
use crate::command::KeywordCommand;
|
||||
use crate::modules::view::visual_style;
|
||||
let c = KeywordCommand::new(
|
||||
"VSCURRENT",
|
||||
"VSCURRENT visual style [Shaded / Wireframe / Hidden / Realistic / Conceptual / X-ray]:",
|
||||
vec![
|
||||
("Shaded", "SHADED", None),
|
||||
("Wireframe", "WIREFRAME", None),
|
||||
("Hidden", "HIDDEN", None),
|
||||
("Realistic", "REALISTIC", None),
|
||||
("Conceptual", "CONCEPTUAL", None),
|
||||
("X-Ray", "XRAY", None),
|
||||
],
|
||||
visual_style::keyword_prompt(),
|
||||
visual_style::keyword_choices(),
|
||||
);
|
||||
self.command_line.push_info(&c.prompt());
|
||||
self.tabs[i].active_cmd = Some(Box::new(c));
|
||||
}
|
||||
// The named visual-style shortcuts still switch directly, and the
|
||||
// `<name> <style>` argument form (also what the picker dispatches).
|
||||
cmd if cmd == "HIDDENLINE"
|
||||
|| cmd == "XRAY"
|
||||
|| cmd == "REALISTIC"
|
||||
|| cmd == "CONCEPTUAL"
|
||||
|| cmd == "2DWIREFRAME"
|
||||
|| cmd == "3DWIREFRAME"
|
||||
|| cmd.starts_with("VSCURRENT ")
|
||||
// A style by name: `VSCURRENT FLAT`, and what the picker dispatches.
|
||||
cmd if cmd.starts_with("VSCURRENT ")
|
||||
|| cmd.starts_with("SHADEMODE ")
|
||||
|| cmd.starts_with("VS ") =>
|
||||
{
|
||||
let style = match cmd {
|
||||
"VS" | "VSCURRENT" | "SHADEMODE" => String::new(),
|
||||
s if s.starts_with("VS ")
|
||||
|| s.starts_with("VSCURRENT ")
|
||||
|| s.starts_with("SHADEMODE ") =>
|
||||
{
|
||||
cmd.split_whitespace().nth(1).unwrap_or("").to_uppercase()
|
||||
}
|
||||
other => other.to_string(),
|
||||
};
|
||||
let (wireframe, label) = match style.as_str() {
|
||||
"" | "SHADED" | "S" | "REALISTIC" | "CONCEPTUAL" => (false, "Shaded"),
|
||||
"2DWIREFRAME" | "3DWIREFRAME" | "WIREFRAME" | "W" => (true, "Wireframe"),
|
||||
"HIDDENLINE" | "HIDDEN" | "H" => (false, "Hidden (shown shaded)"),
|
||||
"XRAY" | "X" => (true, "X-Ray (shown as wireframe)"),
|
||||
_ => {
|
||||
self.command_line.push_error(
|
||||
"Usage: VSCURRENT <2dwireframe|wireframe|hidden|realistic|conceptual|shaded|xray>",
|
||||
);
|
||||
return Some(Task::none());
|
||||
}
|
||||
use crate::modules::view::visual_style;
|
||||
let style = cmd.split_whitespace().nth(1).unwrap_or("");
|
||||
let Some(mode) = visual_style::mode_for_keyword(style) else {
|
||||
self.command_line
|
||||
.push_error(visual_style::keyword_prompt());
|
||||
return Some(Task::none());
|
||||
};
|
||||
let label = visual_style::label_for(mode);
|
||||
self.command_line
|
||||
.push_output(crate::tf!("Visual style: {label}.").as_ref());
|
||||
return Some(Task::done(Message::SetWireframe(wireframe)));
|
||||
return Some(Task::done(Message::SetRenderMode(mode)));
|
||||
}
|
||||
// CLOSE — close the active drawing tab (with the unsaved-changes
|
||||
// prompt the tab-close handler already runs).
|
||||
|
||||
@@ -327,12 +327,6 @@ inventory::submit!(crate::command::CommandRegistration {
|
||||
// Visual styles (mapped to the wireframe / shaded view).
|
||||
"VSCURRENT",
|
||||
"SHADEMODE",
|
||||
"HIDDENLINE",
|
||||
"XRAY",
|
||||
"REALISTIC",
|
||||
"CONCEPTUAL",
|
||||
"2DWIREFRAME",
|
||||
"3DWIREFRAME",
|
||||
// Raster image brightness / contrast / fade.
|
||||
"ADJUST",
|
||||
// Block list + block-attribute list (command-line forms).
|
||||
@@ -607,7 +601,6 @@ inventory::submit!(crate::command::CommandRegistration {
|
||||
"WB",
|
||||
"WBLOCK",
|
||||
"WEBVERSION",
|
||||
"WIREFRAME",
|
||||
"XA",
|
||||
"XATTACH",
|
||||
"XDATA",
|
||||
|
||||
+12
-20
@@ -1050,26 +1050,18 @@ impl OpenCADStudio {
|
||||
)));
|
||||
}
|
||||
|
||||
// VISUALSTYLES <name> — apply a built-in visual style to the active
|
||||
// viewport via its render mode (the style-definition manager dialog
|
||||
// is not modelled; this applies the standard styles).
|
||||
cmd if cmd == "VISUALSTYLES" || cmd.starts_with("VISUALSTYLES ") => {
|
||||
use acadrust::entities::ViewportRenderMode as VRM;
|
||||
let name = cmd.strip_prefix("VISUALSTYLES").unwrap_or("").trim().to_uppercase();
|
||||
let mode = match name.as_str() {
|
||||
"2DWIREFRAME" | "2D" => Some(VRM::Wireframe2D),
|
||||
"3DWIREFRAME" | "WIREFRAME" | "3D" => Some(VRM::Wireframe3D),
|
||||
"HIDDEN" | "HIDDENLINE" => Some(VRM::HiddenLine),
|
||||
"FLAT" | "FLATSHADED" => Some(VRM::FlatShaded),
|
||||
"REALISTIC" | "SHADED" | "GOURAUD" => Some(VRM::GouraudShaded),
|
||||
"CONCEPTUAL" | "SHADEDWITHEDGES" => Some(VRM::GouraudShadedWithEdges),
|
||||
_ => None,
|
||||
};
|
||||
match mode {
|
||||
Some(m) => return Some(Task::done(Message::SetRenderMode(m))),
|
||||
None => self.command_line.push_info(
|
||||
"VISUALSTYLES <2DWIREFRAME|3DWIREFRAME|HIDDEN|REALISTIC|CONCEPTUAL|SHADED>",
|
||||
),
|
||||
// VISUALSTYLES <name> — put the active viewport in one of the seven
|
||||
// render modes. The style-definition manager is not modelled.
|
||||
cmd if cmd.starts_with("VISUALSTYLES ") => {
|
||||
use crate::modules::view::visual_style;
|
||||
let name = cmd.strip_prefix("VISUALSTYLES").unwrap_or("").trim();
|
||||
match visual_style::mode_for_keyword(name) {
|
||||
Some(mode) => return Some(Task::done(Message::SetRenderMode(mode))),
|
||||
// Listed from the table, so the names offered are the names
|
||||
// that work.
|
||||
None => self
|
||||
.command_line
|
||||
.push_info(visual_style::keyword_prompt()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -1763,11 +1763,10 @@ pub enum Message {
|
||||
OptionsThemeColorChanged(usize, String),
|
||||
/// Switch the interface language and redraw localized views.
|
||||
LanguageChanged(crate::i18n::Language),
|
||||
/// Drop every entity from the active drawing.
|
||||
ClearScene,
|
||||
SetWireframe(bool),
|
||||
/// Set the active tab's render mode (one of acadrust's seven visual
|
||||
/// styles). Replaces the binary `SetWireframe` over time; the older
|
||||
/// message stays for ribbon/CLI back-compat and forwards.
|
||||
/// Set the active tab's render mode — one of the seven visual styles, and
|
||||
/// the only way a style is ever set.
|
||||
SetRenderMode(acadrust::entities::ViewportRenderMode),
|
||||
/// Open or close the active viewport's visual-style flyout.
|
||||
ToggleRenderModeMenu(acadrust::entities::ViewportRenderMode),
|
||||
|
||||
@@ -158,21 +158,6 @@ pub(super) fn on_ribbon_tool_click(&mut self, tool_id: String, event: ModuleEven
|
||||
self.tabs[i].properties = PropertiesPanel::empty();
|
||||
self.command_line.push_output(crate::t!("Scene cleared.").as_ref());
|
||||
}
|
||||
ModuleEvent::SetWireframe(w) => {
|
||||
let i = self.active_tab;
|
||||
self.tabs[i].wireframe = w;
|
||||
self.ribbon.set_wireframe(w);
|
||||
self.tabs[i].visual_style = if w {
|
||||
"Wireframe".into()
|
||||
} else {
|
||||
"Shaded".into()
|
||||
};
|
||||
self.command_line.push_output(if w {
|
||||
"Visual style: Wireframe"
|
||||
} else {
|
||||
"Visual style: Shaded"
|
||||
});
|
||||
}
|
||||
ModuleEvent::ToggleLayers => {
|
||||
return Task::done(Message::ToggleLayers);
|
||||
}
|
||||
|
||||
@@ -1188,18 +1188,6 @@ impl OpenCADStudio {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
Message::SetWireframe(w) => {
|
||||
// Back-compat shim: forward to the new render-mode path so
|
||||
// the ribbon button + WIREFRAME / SOLID command line still
|
||||
// work without duplicating the rendering plumbing.
|
||||
let mode = if w {
|
||||
acadrust::entities::ViewportRenderMode::Wireframe2D
|
||||
} else {
|
||||
acadrust::entities::ViewportRenderMode::FlatShaded
|
||||
};
|
||||
Task::done(Message::SetRenderMode(mode))
|
||||
}
|
||||
|
||||
Message::SetRenderMode(mode) => {
|
||||
self.render_mode_menu_open = false;
|
||||
self.render_mode_preview = None;
|
||||
|
||||
@@ -38,8 +38,8 @@ impl canvas::Program<Message> for RenderModePreview {
|
||||
bounds: Rectangle,
|
||||
_cursor: iced::mouse::Cursor,
|
||||
) -> Vec<canvas::Geometry> {
|
||||
|
||||
use acadrust::entities::ViewportRenderMode as M;
|
||||
|
||||
let mut frame = canvas::Frame::new(renderer, bounds.size());
|
||||
let palette = theme.palette();
|
||||
let ink = palette.background.base.text.scale_alpha(0.86);
|
||||
@@ -214,16 +214,10 @@ pub(super) fn viewport_controls<'a>(
|
||||
render_mode_menu_open: bool,
|
||||
render_mode_preview: Option<acadrust::entities::ViewportRenderMode>,
|
||||
) -> Element<'a, Message> {
|
||||
use acadrust::entities::ViewportRenderMode as M;
|
||||
let render_modes = [
|
||||
RenderModeChoice(M::Wireframe2D),
|
||||
RenderModeChoice(M::Wireframe3D),
|
||||
RenderModeChoice(M::HiddenLine),
|
||||
RenderModeChoice(M::FlatShaded),
|
||||
RenderModeChoice(M::GouraudShaded),
|
||||
RenderModeChoice(M::FlatShadedWithEdges),
|
||||
RenderModeChoice(M::GouraudShadedWithEdges),
|
||||
];
|
||||
let render_modes: Vec<RenderModeChoice> = crate::modules::view::visual_style::VISUAL_STYLES
|
||||
.iter()
|
||||
.map(|style| RenderModeChoice(style.mode))
|
||||
.collect();
|
||||
let danger_btn = move |bytes: &'static [u8],
|
||||
msg: Message,
|
||||
title: String,
|
||||
|
||||
+1
-10
@@ -163,16 +163,7 @@ pub(super) struct RenderModeChoice(pub acadrust::entities::ViewportRenderMode);
|
||||
|
||||
impl std::fmt::Display for RenderModeChoice {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
use acadrust::entities::ViewportRenderMode as M;
|
||||
f.write_str(match self.0 {
|
||||
M::Wireframe2D => "Wireframe 2D",
|
||||
M::Wireframe3D => "Wireframe 3D",
|
||||
M::HiddenLine => "Hidden Line",
|
||||
M::FlatShaded => "Flat Shaded",
|
||||
M::GouraudShaded => "Gouraud Shaded",
|
||||
M::FlatShadedWithEdges => "Flat Shaded + Edges",
|
||||
M::GouraudShadedWithEdges => "Gouraud Shaded + Edges",
|
||||
})
|
||||
f.write_str(crate::modules::view::visual_style::label_for(self.0))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user