Merge pull request #1722 from ramox81/codex/view-background

# Conflicts:
#	locales/ar-SA/opencadstudio.ftl
#	locales/bg-BG/opencadstudio.ftl
#	locales/cs-CZ/opencadstudio.ftl
#	locales/de-DE/opencadstudio.ftl
#	locales/el-GR/opencadstudio.ftl
#	locales/en-US/opencadstudio.ftl
#	locales/es-ES/opencadstudio.ftl
#	locales/fi-FI/opencadstudio.ftl
#	locales/fr-FR/opencadstudio.ftl
#	locales/hi-IN/opencadstudio.ftl
#	locales/hu-HU/opencadstudio.ftl
#	locales/it-IT/opencadstudio.ftl
#	locales/ja-JP/opencadstudio.ftl
#	locales/ko-KR/opencadstudio.ftl
#	locales/lo-LA/opencadstudio.ftl
#	locales/nl-NL/opencadstudio.ftl
#	locales/pl-PL/opencadstudio.ftl
#	locales/pt-BR/opencadstudio.ftl
#	locales/ru-RU/opencadstudio.ftl
#	locales/tr-TR/opencadstudio.ftl
#	locales/zh-CN/opencadstudio.ftl
#	locales/zh-TW/opencadstudio.ftl
This commit is contained in:
Hakan Seven committed 2026-10-13 07:44:01 +03:00
commit 03445a540d
40 files changed
+1801 -46

No files matched your search

+41 -3
View File
@@ -57,6 +57,8 @@ pub struct ViewInfo {
pub category: String,
pub visual_style: Option<String>,
pub live_section: Option<String>,
/// Saved in paper space.
pub paper_space: bool,
}
/// What -VIEW checks typed names against.
@@ -65,6 +67,10 @@ pub struct ViewNames {
pub views: Vec<ViewInfo>,
pub visual_styles: Vec<String>,
pub live_sections: Vec<String>,
/// On a layout's sheet (no viewport entered): the layout's viewports as
/// (handle, [min x, min y, max x, max y]), one of which takes a
/// model-space view being restored.
pub sheet_viewports: Option<Vec<(u64, [f64; 4])>>,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
@@ -106,6 +112,7 @@ enum Step {
List,
Delete,
Restore,
RestoreViewport(String),
Save,
WindowName,
WindowFirst(String),
@@ -226,9 +233,16 @@ impl DashViewCommand {
let t = text.trim();
match setting {
Setting::Background => match keyword(t, &["Color", "Gradient", "Image", "None"]) {
// The other background types are chosen in their own dialogs.
Some("None") => Self::apply(setting, &view, "NONE"),
Some(_) => CmdResult::Dispatch("-VIEW >SETTINGS".into()),
// The other types are set in the Background dialog.
Some(kind) => CmdResult::Dispatch(format!(
"-VIEW >BACKGROUND {view}\u{1f}{}",
match kind {
"Color" => "SOLID",
"Gradient" => "GRADIENT",
_ => "IMAGE",
}
)),
None => {
self.step = Step::SettingValue(setting, view);
CmdResult::ReportError("Invalid option keyword.".into())
@@ -343,6 +357,7 @@ impl CadCommand for DashViewCommand {
Step::List | Step::SettingViewList(_) => "Enter view name(s) to list <*>:".into(),
Step::Delete => "Enter view name(s) to delete:".into(),
Step::Restore => "Enter view name to restore:".into(),
Step::RestoreViewport(_) => "Select Viewport for view:".into(),
Step::Save | Step::WindowName => "Enter view name to save:".into(),
Step::WindowFirst(_) => "Specify first corner:".into(),
Step::WindowSecond(..) => "Specify opposite corner:".into(),
@@ -414,9 +429,19 @@ impl CadCommand for DashViewCommand {
}
}
Step::Restore => match self.view(t) {
// On a sheet a model-space view goes into a viewport the
// user selects.
Some(view) if !view.paper_space && self.names.sheet_viewports.is_some() => {
self.step = Step::RestoreViewport(view.name.clone());
CmdResult::ReportMeasurement("Restoring Model space view.".into())
}
Some(view) => CmdResult::Dispatch(format!("-VIEW >RESTORE {}", view.name)),
None => Self::end(&format!("Cannot find view \"{t}\".")),
},
Step::RestoreViewport(name) => {
self.step = Step::RestoreViewport(name);
CmdResult::ReportError("*Invalid selection*".into())
}
Step::Save => CmdResult::Dispatch(format!("-VIEW >SAVE {t}")),
Step::WindowName => {
self.step = Step::WindowFirst(t.to_string());
@@ -487,6 +512,19 @@ impl CadCommand for DashViewCommand {
"-VIEW >WINDOW {}\u{1f}{},{}\u{1f}{},{}",
name, first.x, first.y, pt.x, pt.y
)),
Step::RestoreViewport(name) => {
// The topmost viewport under the pick.
let hit = self.names.sheet_viewports.iter().flatten().rev().find(|(_, [x0, y0, x1, y1])| {
pt.x >= *x0 && pt.x <= *x1 && pt.y >= *y0 && pt.y <= *y1
});
match hit {
Some((handle, _)) => CmdResult::Dispatch(format!("-VIEW >RESTOREVP {name}\u{1f}{handle:X}")),
None => {
self.step = Step::RestoreViewport(name);
CmdResult::NeedPoint
}
}
}
step => {
self.step = step;
CmdResult::NeedPoint
@@ -496,7 +534,7 @@ impl CadCommand for DashViewCommand {
fn on_enter(&mut self) -> CmdResult {
match std::mem::replace(&mut self.step, Step::Main) {
Step::Main | Step::Delete | Step::Restore | Step::Save | Step::WindowName => {
Step::Main | Step::Delete | Step::Restore | Step::RestoreViewport(_) | Step::Save | Step::WindowName => {
CmdResult::Dispatch("-VIEW >END".into())
}
Step::Orthographic => CmdResult::Dispatch("-VIEW >PRESET TOP".into()),
+32
View File
@@ -106,6 +106,38 @@ pub fn label_for(mode: Mode) -> &'static str {
.unwrap_or("Wireframe 2D")
}
/// The render mode a named visual style draws as, and whether the name is a
/// style of its own (Realistic, Conceptual, …) rather than one of the modes.
pub fn mode_for_style_name(name: &str) -> Option<(Mode, bool)> {
Some(match name {
"2dWireframe" => (Mode::Wireframe2D, false),
"Wireframe" => (Mode::Wireframe3D, false),
"Hidden" => (Mode::HiddenLine, false),
"Flat" => (Mode::FlatShaded, false),
"FlatWithEdges" => (Mode::FlatShadedWithEdges, false),
"Gouraud" => (Mode::GouraudShaded, false),
"GouraudWithEdges" => (Mode::GouraudShadedWithEdges, false),
"Shaded with edges" => (Mode::GouraudShadedWithEdges, true),
"Realistic" | "Shaded" | "Conceptual" | "Shades of Gray" | "Sketchy" | "X-Ray" => {
(Mode::GouraudShaded, true)
}
_ => return None,
})
}
/// The name of the visual style a render mode is saved as.
pub fn style_name_for(mode: Mode) -> &'static str {
match mode {
Mode::Wireframe2D => "2dWireframe",
Mode::Wireframe3D => "Wireframe",
Mode::HiddenLine => "Hidden",
Mode::FlatShaded => "Flat",
Mode::FlatShadedWithEdges => "FlatWithEdges",
Mode::GouraudShaded => "Gouraud",
Mode::GouraudShadedWithEdges => "GouraudWithEdges",
}
}
/// 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> {