Skip to main content

geop_ops_hole/
examples.rs

1//! The examples of holes an editor offers: a mounting plate drilled with
2//! counterbored and tapped holes, and a block with a pipe port.
3
4use geop_core_editor::registry::ExampleSet;
5use geop_core_math::primitives::FrameAxis;
6use geop_core_program::program::Program;
7use geop_core_sketch::PointId;
8use geop_ops_extrude_revolve::{Extent, Extents, ExtrudeArgs, Output};
9use geop_ops_model::datums::origin_plane;
10use geop_ops_model::sketch::{
11    Constraint, Sketch, SketchPlane,
12    figures::{P2, n, rectangle, solved},
13    whole_sketch,
14};
15use geop_ops_model::{Combine, element};
16use geop_ops_sketch::AddSketchArgs;
17
18use crate::{HoleArgs, HoleCentre, HoleKind, Standard, iso::Fit};
19
20/// The examples of this crate, by name.
21pub fn set() -> ExampleSet {
22    ExampleSet {
23        programs: vec![("hole_plate", hole_plate), ("pipe_port", pipe_port)],
24        workspaces: Vec::new(),
25    }
26}
27
28/// A 40 x 40 x 20 mm block with a 1/2 NPT port tapped 15 deep into the
29/// middle of its top (`port`): reamed to the pipe thread's taper, and
30/// carrying the cosmetic thread 1/2-14 NPT — the result is `hole(port)`.
31pub fn pipe_port() -> Program {
32    let mut program = Program::new();
33    let mut outline = Sketch::new();
34    rectangle(&mut outline, [0.0, 0.0], 40.0, 40.0);
35    program.push(
36        "outline",
37        AddSketchArgs::on(
38            SketchPlane::Datum(origin_plane(FrameAxis::Z)),
39            solved(outline),
40        ),
41    );
42    program.push(
43        "block",
44        ExtrudeArgs {
45            sketch: whole_sketch("outline"),
46            extent: Extents::blind(20.0),
47            output: Output::Solid(Combine::NewBody),
48            draft: 0.0,
49        },
50    );
51    let top = || SketchPlane::Face(element("extrude(block,end)"));
52    program.push(
53        "middle",
54        AddSketchArgs::on(top(), fixed_points(&[[20.0, 20.0]])),
55    );
56    program.push(
57        "port",
58        HoleArgs {
59            face: Some(element("extrude(block,end)")),
60            points: vec![HoleCentre::Sketch(whole_sketch("middle"))],
61            kind: HoleKind::Tapped,
62            standard: Standard::Npt { size: "1/2".into() },
63            end: Extent::blind(15.0),
64            drill_point: false,
65            thread_length: None,
66        },
67    );
68    program
69}
70
71/// A sketch of points fixed at `at`.
72fn fixed_points(at: &[P2]) -> Sketch {
73    let mut sketch = Sketch::new();
74    let ids: Vec<PointId> = at
75        .iter()
76        .map(|p| sketch.add_point(n(p[0]), n(p[1])))
77        .collect();
78    for (id, p) in ids.into_iter().zip(at) {
79        sketch.constrain(Constraint::Fix {
80            point: id,
81            x: n(p[0]),
82            y: n(p[1]),
83        });
84    }
85    solved(sketch)
86}
87
88/// A 60 x 40 x 10 mm mounting plate: four counterbored M5 holes through
89/// its corners, at the points of one sketch on its top (`bolts`), and a
90/// tapped M6 hole 8 deep in its middle (`tapped`), which carries the
91/// cosmetic thread M6x1 — the result is `hole(tapped)`.
92pub fn hole_plate() -> Program {
93    let mut program = Program::new();
94    let mut outline = Sketch::new();
95    rectangle(&mut outline, [0.0, 0.0], 60.0, 40.0);
96    program.push(
97        "outline",
98        AddSketchArgs::on(
99            SketchPlane::Datum(origin_plane(FrameAxis::Z)),
100            solved(outline),
101        ),
102    );
103    program.push(
104        "plate",
105        ExtrudeArgs {
106            sketch: whole_sketch("outline"),
107            extent: Extents::blind(10.0),
108            output: Output::Solid(Combine::NewBody),
109            draft: 0.0,
110        },
111    );
112    let points = fixed_points;
113    let top = || SketchPlane::Face(element("extrude(plate,end)"));
114    program.push(
115        "corners",
116        AddSketchArgs::on(
117            top(),
118            points(&[[8.0, 8.0], [52.0, 8.0], [52.0, 32.0], [8.0, 32.0]]),
119        ),
120    );
121    program.push(
122        "bolts",
123        HoleArgs {
124            face: Some(element("extrude(plate,end)")),
125            points: vec![HoleCentre::Sketch(whole_sketch("corners"))],
126            kind: HoleKind::Counterbore,
127            standard: Standard::Iso {
128                size: "M5".into(),
129                fit: Fit::Normal,
130            },
131            end: Extent::ThroughAll,
132            drill_point: false,
133            thread_length: None,
134        },
135    );
136    program.push("middle", AddSketchArgs::on(top(), points(&[[30.0, 20.0]])));
137    program.push(
138        "tapped",
139        HoleArgs {
140            face: Some(element("extrude(plate,end)")),
141            points: vec![HoleCentre::Sketch(whole_sketch("middle"))],
142            kind: HoleKind::Tapped,
143            standard: Standard::Iso {
144                size: "M6".into(),
145                fit: Fit::Normal,
146            },
147            end: Extent::blind(8.0),
148            drill_point: true,
149            thread_length: None,
150        },
151    );
152    program
153}