Skip to main content

brep_app/workbench/
drawing.rs

1//! The "Drawing" workbench — the mode in which drawing SHEETS are made: saved
2//! PMI views placed on paper, dimensioned, sectioned and detailed.
3//!
4//! Like PMI it is NOT feature creation: the `includes` predicate rejects every
5//! catalogue entry, and the history stays fully editable as everywhere. What
6//! it adds is the **Sheets** panel — its own, claimed by no other workbench but
7//! All — and the sheet's tools as buttons in the workbench row. The views a
8//! sheet places are captured and annotated from the PMI tab; this one only
9//! reads them.
10//!
11//! Leaving the workbench closes an open sheet (`app.rs` drives that off the
12//! Sheets panel's visibility), for the reason PMI leaving deactivates its view:
13//! a workbench that hides the Sheets pane must not leave the central tile
14//! drawing paper.
15//!
16//! # The buttons
17//!
18//! **Add sheet** and **Place view** are always offered. The rest are offered
19//! only while a sheet is OPEN ([`WorkbenchButton::when`]), so the row grows when
20//! the viewport turns to paper and shrinks back when it does not: **Back to
21//! 3D**, the six dimension constructions ([`DIM_TOOLS`]), the two ordinate sets
22//! ([`ORD_TOOLS`]), the SECTION VIEW ([`SECTION_BUTTON_ID`]) and the DETAIL VIEW
23//! ([`DETAIL_BUTTON_ID`]).
24//!
25//! # The workflow is the PMI annotation buttons'
26//!
27//! A construction button is momentary: it CREATES its object on the open sheet
28//! with nothing picked yet and opens the object's dialog in the Sheets pane.
29//! What the object measures or cuts is then picked from the dialog's reference
30//! rows with the same reference picker every other dialog uses — Select, click
31//! anchors on the paper, Finish — and where its line sits is a field of the
32//! dialog (and a drag of its value box on the paper). There is no armed tool
33//! and no click that means "place".
34//!
35//! Fit and zoom are NOT here: the main toolbar's own Zoom-to-fit fits the open
36//! sheet's paper (`BrepApp::zoom_to_fit`) and the wheel zooms the paper the way
37//! it zooms the 3D scene, so neither needs a second button.
38
39use super::{ButtonState, FeatureInfo, Workbench, WorkbenchButton};
40use brep_render::sheets::dimension::{
41    ALIGNED, ANGULAR, DIAMETRAL, HORIZONTAL, LINEAR, RADIAL, VERTICAL,
42};
43
44/// The Sheets panel's id (claim + registration key).
45pub const SHEETS_PANEL_ID: &str = "sheets";
46
47/// **Add sheet** — a new sheet at the default paper size, opened on the paper.
48pub const ADD_SHEET_BUTTON_ID: &str = "drawing.add_sheet";
49
50/// **Place view** — place a saved PMI view on the open sheet and open the
51/// placement's dialog, where the view, position and scale are chosen.
52pub const PLACE_VIEW_BUTTON_ID: &str = "drawing.place_view";
53
54/// The **Back to 3D** button id — leaving the open sheet. The Sheets pane's own
55/// row menu (**Close sheet**) and its `Open` tick still do the same thing; this
56/// is the copy that lives where every other mode's actions live, so leaving the
57/// paper never means hunting for a pane.
58pub const SHEET_CLOSE_BUTTON_ID: &str = "drawing.sheet_close";
59
60/// The six dimension constructions the open sheet offers, as
61/// `(button id, kind, alignment)` — ONE table, read by the buttons below and by
62/// `BrepApp::dispatch_workbench_button`, which creates that kind. The ids
63/// are the whole contract: a script presses
64/// `workbench:btn:drawing.dim.horizontal`, or names the same id to the
65/// `workbench_button` command.
66///
67/// An ANGULAR construction has no alignment to carry — its direction is the
68/// two picked edges' — so it files [`ALIGNED`] the way the two radial
69/// constructions do: the column is a linear dimension's and nothing else reads
70/// it.
71pub const DIM_TOOLS: &[(&str, &str, &str)] = &[
72    ("drawing.dim.horizontal", LINEAR, HORIZONTAL),
73    ("drawing.dim.vertical", LINEAR, VERTICAL),
74    ("drawing.dim.aligned", LINEAR, ALIGNED),
75    ("drawing.dim.angular", ANGULAR, ALIGNED),
76    ("drawing.dim.radius", RADIAL, ALIGNED),
77    ("drawing.dim.diameter", DIAMETRAL, ALIGNED),
78];
79
80/// The `(kind, alignment)` a dimension button creates, or `None` for any other id.
81pub fn dim_tool(id: &str) -> Option<(&'static str, &'static str)> {
82    DIM_TOOLS
83        .iter()
84        .find(|(button, _, _)| *button == id)
85        .map(|(_, kind, alignment)| (*kind, *alignment))
86}
87
88/// The two ORDINATE SET constructions, as `(button id, axis)` — the same
89/// one-table rule the dimensions follow. They are a separate table because an
90/// ordinate set is a separate OBJECT.
91pub const ORD_TOOLS: &[(&str, &str)] = &[
92    ("drawing.ord.horizontal", HORIZONTAL),
93    ("drawing.ord.vertical", VERTICAL),
94];
95
96/// The axis an ordinate button creates, or `None` for any other id.
97pub fn ord_tool(id: &str) -> Option<&'static str> {
98    ORD_TOOLS.iter().find(|(button, _)| *button == id).map(|(_, axis)| *axis)
99}
100
101/// The SECTION VIEW button id. One button, so it needs no table: a section has
102/// no kinds and no axes, only a cutting line on a placed view.
103pub const SECTION_BUTTON_ID: &str = "drawing.section";
104
105/// The INSERT BOM TABLE button id: one table per sheet, so one button that
106/// inserts it (or, once inserted, opens the sheet's dialog on its columns).
107pub const BOM_BUTTON_ID: &str = "drawing.bom";
108
109/// The DETAIL VIEW button id: a circle on a placed view, redrawn larger.
110pub const DETAIL_BUTTON_ID: &str = "drawing.detail";
111
112/// No creatable features: sheets are not history features.
113fn includes(_feature: &FeatureInfo<'_>) -> bool {
114    false
115}
116
117/// A sheet is open — the condition every paper tool is offered under. With no
118/// paper on screen there is nothing to close and nothing to dimension.
119fn sheet_is_open(state: &ButtonState) -> bool {
120    state.engine.sheet_open().is_some()
121}
122
123static BUTTONS: &[WorkbenchButton] = &[
124    WorkbenchButton {
125        id: ADD_SHEET_BUTTON_ID,
126        glyph: "\u{E077}",
127        ribbon_path: "Home/Drawing/Add sheet", size: crate::workbench::CommandSize::Compact, tooltip: "Add sheet \u{2014} a new drawing sheet at the default paper size, opened on the paper",
128        when: None,
129        pressed: None,
130        disabled: None,
131        caption: None,
132        menu: &[],
133    },
134    WorkbenchButton {
135        id: PLACE_VIEW_BUTTON_ID,
136        glyph: "\u{E078}",
137        ribbon_path: "Home/Drawing/Place view", size: crate::workbench::CommandSize::Compact, tooltip: "Place view \u{2014} put a saved PMI view on the open sheet and open its dialog",
138        when: None,
139        pressed: None,
140        disabled: None,
141        caption: None,
142        menu: &[],
143    },
144    // --- the OPEN SHEET's tools, in row order: the way out first, then the
145    // six constructions, the two ordinate sets, the section and the detail.
146    WorkbenchButton {
147        id: SHEET_CLOSE_BUTTON_ID,
148        glyph: "\u{E068}",
149        ribbon_path: "Home/Drawing/Back to 3D", size: crate::workbench::CommandSize::Compact, tooltip: "Back to 3D (close the open sheet; it keeps its contents)",
150        when: Some(sheet_is_open),
151        pressed: None,
152        disabled: None,
153        caption: None,
154        menu: &[],
155    },
156    WorkbenchButton {
157        id: "drawing.dim.horizontal",
158        glyph: "\u{E069}",
159        ribbon_path: "Home/Drawing/Horizontal dimension", size: crate::workbench::CommandSize::Compact, tooltip: "Horizontal dimension \u{2014} the horizontal distance between two anchors",
160        when: Some(sheet_is_open),
161        pressed: None,
162        disabled: None,
163        caption: None,
164        menu: &[],
165    },
166    WorkbenchButton {
167        id: "drawing.dim.vertical",
168        glyph: "\u{E06A}",
169        ribbon_path: "Home/Drawing/Vertical dimension", size: crate::workbench::CommandSize::Compact, tooltip: "Vertical dimension \u{2014} the vertical distance between two anchors",
170        when: Some(sheet_is_open),
171        pressed: None,
172        disabled: None,
173        caption: None,
174        menu: &[],
175    },
176    WorkbenchButton {
177        id: "drawing.dim.aligned",
178        glyph: "\u{E06B}",
179        ribbon_path: "Home/Drawing/Aligned dimension", size: crate::workbench::CommandSize::Compact, tooltip: "Aligned dimension \u{2014} the true distance between two anchors",
180        when: Some(sheet_is_open),
181        pressed: None,
182        disabled: None,
183        caption: None,
184        menu: &[],
185    },
186    WorkbenchButton {
187        id: "drawing.dim.angular",
188        glyph: "\u{E06F}",
189        ribbon_path: "Home/Drawing/Angular dimension", size: crate::workbench::CommandSize::Compact, tooltip: "Angular dimension \u{2014} the angle between two straight edges AS THIS VIEW PROJECTS THEM",
190        when: Some(sheet_is_open),
191        pressed: None,
192        disabled: None,
193        caption: None,
194        menu: &[],
195    },
196    WorkbenchButton {
197        id: "drawing.dim.radius",
198        glyph: "\u{E06C}",
199        ribbon_path: "Home/Drawing/Radius dimension", size: crate::workbench::CommandSize::Compact, tooltip: "Radius dimension \u{2014} a projected circle's radius (R6.000)",
200        when: Some(sheet_is_open),
201        pressed: None,
202        disabled: None,
203        caption: None,
204        menu: &[],
205    },
206    WorkbenchButton {
207        id: "drawing.dim.diameter",
208        glyph: "\u{E06D}",
209        ribbon_path: "Home/Drawing/Diameter dimension", size: crate::workbench::CommandSize::Compact, tooltip: "Diameter dimension \u{2014} a projected circle's diameter (\u{2300}12.000)",
210        when: Some(sheet_is_open),
211        pressed: None,
212        disabled: None,
213        caption: None,
214        menu: &[],
215    },
216    WorkbenchButton {
217        id: "drawing.ord.horizontal",
218        glyph: "\u{E070}",
219        ribbon_path: "Home/Drawing/Horizontal ordinate set", size: crate::workbench::CommandSize::Compact, tooltip: "Horizontal ordinate set \u{2014} a datum, then a run of members reading their distance along the paper's X",
220        when: Some(sheet_is_open),
221        pressed: None,
222        disabled: None,
223        caption: None,
224        menu: &[],
225    },
226    WorkbenchButton {
227        id: "drawing.ord.vertical",
228        glyph: "\u{E071}",
229        ribbon_path: "Home/Drawing/Vertical ordinate set", size: crate::workbench::CommandSize::Compact, tooltip: "Vertical ordinate set \u{2014} a datum, then a run of members reading their distance up the paper",
230        when: Some(sheet_is_open),
231        pressed: None,
232        disabled: None,
233        caption: None,
234        menu: &[],
235    },
236    WorkbenchButton {
237        id: SECTION_BUTTON_ID,
238        glyph: "\u{E072}",
239        ribbon_path: "Home/Drawing/Section view", size: crate::workbench::CommandSize::Compact, tooltip: "Section view \u{2014} a new section; pick its cutting line on a placed view in its dialog",
240        when: Some(sheet_is_open),
241        pressed: None,
242        disabled: None,
243        caption: None,
244        menu: &[],
245    },
246    WorkbenchButton {
247        id: BOM_BUTTON_ID,
248        glyph: "\u{E08E}",
249        ribbon_path: "Home/Drawing/BOM table", size: crate::workbench::CommandSize::Compact, tooltip: "BOM table \u{2014} insert the sheet's BOM table (one per sheet) and open the sheet's dialog, where its columns, position and column width are chosen",
250        when: Some(sheet_is_open),
251        pressed: None,
252        disabled: None,
253        caption: None,
254        menu: &[],
255    },
256    WorkbenchButton {
257        id: DETAIL_BUTTON_ID,
258        glyph: "\u{E074}",
259        ribbon_path: "Home/Drawing/Detail view", size: crate::workbench::CommandSize::Compact, tooltip: "Detail view \u{2014} a new detail; pick its circle's centre and rim on a placed view in its dialog",
260        when: Some(sheet_is_open),
261        pressed: None,
262        disabled: None,
263        caption: None,
264        menu: &[],
265    },
266];
267
268static PANELS: &[&str] = &[SHEETS_PANEL_ID];
269
270pub static DRAWING: Workbench = Workbench {
271    id: "drawing",
272    label: "Drawing",
273    glyph: "\u{E075}",
274    includes,
275    buttons: BUTTONS,
276    panels: PANELS,
277};