1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/// Errors that can occur during CAD operations.
#[derive(Debug)]
pub enum Error {
/// STEP file read failed (invalid format or corrupted data).
StepReadFailed,
/// BRep file read failed (invalid format or corrupted data).
BrepReadFailed,
/// STEP file write failed.
StepWriteFailed,
/// BRep file write failed.
BrepWriteFailed,
/// Triangulation/meshing failed.
TriangulationFailed,
/// Boolean operation (fuse/cut/common) failed.
BooleanOperationFailed,
/// Shape cleaning (UnifySameDomain) failed.
CleanFailed,
/// Helix edge construction failed (e.g. degenerate parameters).
HelixFailed,
/// Extrusion (`Solid::extrude`) failed: empty profile, zero-length
/// direction, or profile not closed.
ExtrudeFailed,
/// Pipe sweep (`Solid::sweep`) failed: profile not closed, edges not
/// connectable into a wire, or `BRepOffsetAPI_MakePipe` returned no shape.
SweepFailed,
/// Shell / hollow (`Solid::shell` via `BRepOffsetAPI_MakeThickSolid`)
/// failed: thickness sign incompatible with geometry, sharp corners
/// yielding a self-intersecting offset surface, or OCCT internal failure.
ShellFailed,
/// Fillet (`Solid::fillet_edges` via `BRepFilletAPI_MakeFillet`) failed:
/// radius too large for the local geometry, tangent discontinuity along
/// the selected edge chain, or an edge not belonging to `self` was passed.
FilletFailed,
/// Chamfer (`Solid::chamfer_edges` via `BRepFilletAPI_MakeChamfer`) failed:
/// distance too large for the local geometry, tangent discontinuity along
/// the selected edge chain, or an edge not belonging to `self` was passed.
ChamferFailed,
/// Lofting (`Solid::loft` / `BRepOffsetAPI_ThruSections`) failed: section
/// count too low, section wire ill-formed, or OCCT internal failure.
/// The string identifies which precondition or stage failed.
LoftFailed(String),
/// B-spline solid (`Solid::bspline`) construction failed: grid too small,
/// surface interpolation rejected the input, or sewing/capping failed.
/// The string identifies which stage failed and with what parameters.
BsplineFailed(String),
/// Edge construction failed due to degenerate input (e.g. collinear arc
/// points, zero-length line, negative radius). The string describes which
/// constructor failed and with which parameters.
InvalidEdge(String),
/// SVG export (HLR projection) failed.
SvgExportFailed,
/// STL write failed.
StlWriteFailed,
/// Invalid color string (unrecognized name or invalid hex format).
InvalidColor(String),
/// Unknown error.
Unknown(String),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::StepReadFailed => write!(f, "STEP read failed"),
Error::BrepReadFailed => write!(f, "BRep read failed"),
Error::StepWriteFailed => write!(f, "STEP write failed"),
Error::BrepWriteFailed => write!(f, "BRep write failed"),
Error::TriangulationFailed => write!(f, "Triangulation failed"),
Error::BooleanOperationFailed => write!(f, "Boolean operation failed"),
Error::CleanFailed => write!(f, "Shape clean failed"),
Error::HelixFailed => write!(f, "Helix failed"),
Error::ExtrudeFailed => write!(f, "Extrude failed"),
Error::SweepFailed => write!(f, "Sweep failed"),
Error::ShellFailed => write!(f, "Shell failed"),
Error::FilletFailed => write!(f, "Fillet failed"),
Error::ChamferFailed => write!(f, "Chamfer failed"),
Error::LoftFailed(msg) => write!(f, "Loft failed: {}", msg),
Error::BsplineFailed(msg) => write!(f, "Bspline failed: {}", msg),
Error::InvalidEdge(msg) => write!(f, "Invalid edge: {}", msg),
Error::SvgExportFailed => write!(f, "SVG export failed"),
Error::StlWriteFailed => write!(f, "STL write failed"),
Error::InvalidColor(s) => write!(f, "Invalid color: \"{}\"", s),
Error::Unknown(msg) => write!(f, "Unknown error: {}", msg),
}
}
}
impl std::error::Error for Error {}