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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// SPDX-License-Identifier: ISC
use crate::point::Point3;
use crate::value::GroupValue;
/// A DIMENSION entity.
///
/// The visual representation is stored in an anonymous block referenced
/// by `block_name`. Rendering a DIMENSION is equivalent to inserting
/// that block at the origin.
#[derive(Debug, Clone, Copy, Default)]
pub struct Dimension<'a> {
/// Anonymous block name containing the visual geometry.
///
/// This block is auto-generated by AutoCAD and contains the
/// lines, arrowheads, and text that make up the dimension's
/// appearance. Rendering the dimension is equivalent to inserting
/// this block at the origin.
pub block_name: &'a [u8],
/// Dimension style name.
pub style_name: &'a [u8],
/// Definition point.
///
/// The meaning depends on the dimension type. For linear
/// dimensions this is on the dimension line; for angular
/// dimensions it is the arc's center.
pub definition_point: Point3,
/// Middle point of dimension text.
pub text_midpoint: Point3,
/// Insertion point for clones of a dimension.
pub clone_insertion_point: Point3,
/// Definition point for linear and angular dimensions.
pub linear_or_angular_point1: Point3,
/// Second definition point for linear and angular dimensions.
pub linear_or_angular_point2: Point3,
/// Definition point for diameter, radius, and angular dimensions.
pub diameter_or_radius_point: Point3,
/// Arc definition point for angular dimensions.
pub arc_point: Point3,
/// Explicit dimension text override.
///
/// Empty when the default measurement text should be used.
/// A single space `b" "` suppresses the text entirely.
pub text_override: &'a [u8],
/// Dimension type flags.
///
/// The lower 4 bits encode the dimension type:
///
/// | Value | Type |
/// |------:|----------------------|
/// | 0 | Rotated / horizontal |
/// | 1 | Aligned |
/// | 2 | Angular |
/// | 3 | Diameter |
/// | 4 | Radius |
/// | 5 | Angular (3-point) |
/// | 6 | Ordinate |
///
/// Bit `0b100_0000` indicates the block reference is referenced
/// by this entity. Bit `0b1000_0000` indicates the dimension text
/// was positioned explicitly by the user.
pub flags: i16,
/// Attachment point for dimension text.
///
/// 1–9 in a 3×3 grid (same encoding as
/// [`MText::attachment_point`](crate::entity::MText::attachment_point)).
pub attachment_point: i16,
/// Leader length for radius and diameter dimensions.
pub leader_length: f64,
/// Text line-spacing factor.
///
/// Valid range 0.25–4.00.
pub text_line_spacing_factor: f64,
/// Rotation angle of the dimension line in degrees.
///
/// Used for rotated linear dimensions.
pub rotation_angle: f64,
/// Horizontal direction for the dimension entity.
///
/// Angle in the XY plane of the entity's coordinate system.
pub horizontal_direction: f64,
/// Extension line oblique angle in degrees.
///
/// Used for linear dimensions with non-perpendicular extension lines.
pub oblique_angle: f64,
/// Rotation angle of the dimension text in degrees.
pub text_rotation: f64,
}
impl<'a> Dimension<'a> {
pub(crate) fn feed(&mut self, code: u16, val: &GroupValue<'a>) {
match code {
1 => {
if let Some(s) = val.as_str_bytes() {
self.text_override = s;
}
}
2 => {
if let Some(s) = val.as_str_bytes() {
self.block_name = s;
}
}
3 => {
if let Some(s) = val.as_str_bytes() {
self.style_name = s;
}
}
70 => {
if let Some(v) = val.as_i16() {
self.flags = v;
}
}
71 => {
if let Some(v) = val.as_i16() {
self.attachment_point = v;
}
}
_ => {
if let Some(v) = val.as_f64() {
match code {
10 => self.definition_point.x = v,
20 => self.definition_point.y = v,
30 => self.definition_point.z = v,
11 => self.text_midpoint.x = v,
21 => self.text_midpoint.y = v,
31 => self.text_midpoint.z = v,
12 => self.clone_insertion_point.x = v,
22 => self.clone_insertion_point.y = v,
32 => self.clone_insertion_point.z = v,
13 => self.linear_or_angular_point1.x = v,
23 => self.linear_or_angular_point1.y = v,
33 => self.linear_or_angular_point1.z = v,
14 => self.linear_or_angular_point2.x = v,
24 => self.linear_or_angular_point2.y = v,
34 => self.linear_or_angular_point2.z = v,
15 => self.diameter_or_radius_point.x = v,
25 => self.diameter_or_radius_point.y = v,
35 => self.diameter_or_radius_point.z = v,
16 => self.arc_point.x = v,
26 => self.arc_point.y = v,
36 => self.arc_point.z = v,
40 => self.leader_length = v,
41 => self.text_line_spacing_factor = v,
50 => self.rotation_angle = v,
51 => self.horizontal_direction = v,
52 => self.oblique_angle = v,
53 => self.text_rotation = v,
_ => {}
}
}
}
}
}
}