forked from 1b-agent/opencadstudio-upstream
View backgrounds: image colours as stored, viewport style name, adjust automation
- The background image texture is not an sRGB view: the image is drawn with its own colours, as the solid and gradient colours are. - An entered paper-space viewport shows its named visual style (Realistic, ...) in the render-mode picker, and a mode picked there is recorded as the viewport's visual style. - The view_background automation action takes offset=x,y and scale=x,y. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
b5b505ee9d
commit
064da8829e
8 files changed
+80
-19
No files matched your search
@@ -582,6 +582,8 @@ impl OpenCADStudio {
|
||||
| PdfDialogMsg::BgBrowse
|
||||
| PdfDialogMsg::BgPosition(_)
|
||||
| PdfDialogMsg::BgAspect(_)
|
||||
| PdfDialogMsg::BgOffset(_)
|
||||
| PdfDialogMsg::BgScale(_)
|
||||
| PdfDialogMsg::BgApply) => return self.update_view_background(message),
|
||||
message @ (PdfDialogMsg::SecPerimeter(_)
|
||||
| PdfDialogMsg::SecMaxPoints(_)
|
||||
|
||||
@@ -507,6 +507,8 @@ impl OpenCADStudio {
|
||||
M::BgImage(value) => state.image = value,
|
||||
M::BgPosition(value) => state.position = value,
|
||||
M::BgAspect(on) => state.aspect = on,
|
||||
M::BgOffset(value) => state.offset = value,
|
||||
M::BgScale(value) => state.scale = value,
|
||||
M::BgColor(slot, rgb) => match slot {
|
||||
0 => state.solid = rgb,
|
||||
1 => state.top = rgb,
|
||||
|
||||
@@ -1798,7 +1798,7 @@ impl OpenCADStudio {
|
||||
"ribbon_dropdown" => Message::ToggleRibbonDropdown(string(req, "value")?.into()),
|
||||
// The -VIEW Background dialog, one field per call: "type=gradient",
|
||||
// "color|top|middle|bottom=r,g,b", "three=1", "rotation=30",
|
||||
// "image=<path>", "position=center|stretch|tile", "aspect=1",
|
||||
// "image=<path>", "position=center|stretch|tile", "aspect=1", "offset=x,y" (pixels), "scale=x,y" (non-zero),
|
||||
// "apply" or "cancel".
|
||||
"view_background" => {
|
||||
use crate::ui::window::pdf_dialogs::{BgKind, BgPosition, PdfDialogMsg as P};
|
||||
@@ -1840,6 +1840,21 @@ impl OpenCADStudio {
|
||||
_ => return Err(bad()),
|
||||
})),
|
||||
"aspect" => Message::PdfDialog(P::BgAspect(value == "1")),
|
||||
"offset" | "scale" => {
|
||||
let pair: Vec<f64> = value
|
||||
.split(',')
|
||||
.map(|part| part.trim().parse::<f64>())
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(|_| bad())?;
|
||||
let pair = <[f64; 2]>::try_from(pair).map_err(|_| bad())?;
|
||||
if key == "offset" {
|
||||
Message::PdfDialog(P::BgOffset(pair))
|
||||
} else if pair.iter().all(|v| v.is_finite() && *v != 0.0) {
|
||||
Message::PdfDialog(P::BgScale(pair))
|
||||
} else {
|
||||
return Err(bad());
|
||||
}
|
||||
}
|
||||
_ => return Err(bad()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1084,6 +1084,9 @@ impl OpenCADStudio {
|
||||
// viewport, the picker drives that viewport entity's own
|
||||
// render mode; the model-layout tab style is untouched.
|
||||
if self.tabs[i].scene.set_active_viewport_render_mode(mode) {
|
||||
self.tabs[i]
|
||||
.scene
|
||||
.set_active_visual_style_named(crate::modules::view::visual_style::style_name_for(mode));
|
||||
self.tabs[i].scene.bump_geometry_no_blocks();
|
||||
self.tabs[i].dirty = true;
|
||||
self.command_line
|
||||
|
||||
+20
-13
@@ -182,6 +182,24 @@ impl std::fmt::Display for RenderModeChoice {
|
||||
}
|
||||
}
|
||||
|
||||
/// A named style (Realistic, …) the active viewport draws as, by name.
|
||||
fn named_visual_style(
|
||||
scene: &crate::scene::Scene,
|
||||
mode: codec::entities::ViewportRenderMode,
|
||||
) -> Option<String> {
|
||||
match scene.document.objects.get(&scene.active_visual_style()) {
|
||||
Some(codec::objects::ObjectType::VisualStyle(style)) => {
|
||||
match crate::modules::view::visual_style::mode_for_style_name(&style.description) {
|
||||
Some((named_mode, true)) if named_mode == mode => {
|
||||
Some(crate::t!(style.description.as_str()).into_owned())
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
impl OpenCADStudio {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn view(&self, window_id: window::Id) -> Element<'_, Message> {
|
||||
@@ -1297,18 +1315,7 @@ bg={bg_ms:.1}ms n={view_count}"
|
||||
let rect = tab.scene.active_model_tile_bounds(vw, vh);
|
||||
// Unified control chip: split buttons + render-mode picker +
|
||||
// grid / grid-snap toggles, for the active Model tile.
|
||||
// A named style (Realistic, …) the tile draws as shows by name.
|
||||
let style_name = match tab.scene.document.objects.get(&tab.scene.active_visual_style()) {
|
||||
Some(codec::objects::ObjectType::VisualStyle(style)) => {
|
||||
match crate::modules::view::visual_style::mode_for_style_name(&style.description) {
|
||||
Some((mode, true)) if mode == tab.render_mode => {
|
||||
Some(crate::t!(style.description.as_str()).into_owned())
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let style_name = named_visual_style(&tab.scene, tab.render_mode);
|
||||
let bar = viewport_controls(
|
||||
tab.render_mode,
|
||||
self.show_grid,
|
||||
@@ -1410,7 +1417,7 @@ bg={bg_ms:.1}ms n={view_count}"
|
||||
0,
|
||||
self.render_mode_menu_open,
|
||||
self.render_mode_preview,
|
||||
None,
|
||||
named_visual_style(&tab.scene, vp_mode),
|
||||
);
|
||||
let adaptive: Element<'_, Message> = DensitySwap::new(vec![
|
||||
iced::widget::opaque(bar),
|
||||
|
||||
Reference in new issue
Block a user