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
// SPDX-License-Identifier: ISC
use crate::point::Point3;
use crate::value::GroupValue;
use alloc::vec::Vec;
/// A LEADER entity — a sequence of vertices forming an annotation leader line.
#[derive(Debug, Clone, Default)]
pub struct Leader<'a> {
/// Dimension style name.
pub style_name: &'a [u8],
/// Arrowhead flag.
///
/// 0 = disabled, 1 = enabled.
pub arrowhead_flag: i16,
/// Leader path type.
///
/// | Value | Meaning |
/// |------:|----------------|
/// | 0 | Straight lines |
/// | 1 | Spline |
pub path_type: i16,
/// Hook line direction flag.
///
/// 0 = hook line is the opposite direction from the horizontal
/// vector, 1 = same direction.
pub hook_line_direction: i16,
/// Leader creation flag.
///
/// | Value | Meaning |
/// |------:|-----------|
/// | 0 | Text |
/// | 1 | Tolerance |
/// | 2 | Block |
/// | 3 | None |
pub creation_flag: i16,
/// Hook line flag.
///
/// 0 = no hook line, 1 = has hook line.
pub hook_line_flag: i16,
/// Text annotation height.
pub annotation_height: f64,
/// Text annotation width.
pub annotation_width: f64,
/// Horizontal direction vector.
pub horizontal_direction: Point3,
/// Offset of last leader vertex from block reference insertion point.
pub block_offset: Point3,
/// Offset of last leader vertex from annotation placement point.
pub annotation_offset: Point3,
/// Vertex list.
pub vertices: Vec<Point3>,
/// In-progress vertex being accumulated.
current_pt: Option<Point3>,
}
impl<'a> Leader<'a> {
pub(crate) fn feed(&mut self, code: u16, val: &GroupValue<'a>) {
match code {
3 => {
if let Some(s) = val.as_str_bytes() {
self.style_name = s;
}
}
10 => {
if let Some(pt) = self.current_pt.take() {
self.vertices.push(pt);
}
self.current_pt = Some(Point3 {
x: val.as_f64().unwrap_or(0.0),
..Default::default()
});
}
20 => {
if let Some(ref mut pt) = self.current_pt {
pt.y = val.as_f64().unwrap_or(0.0);
}
}
30 => {
if let Some(ref mut pt) = self.current_pt {
pt.z = val.as_f64().unwrap_or(0.0);
}
}
71 => {
if let Some(v) = val.as_i16() {
self.arrowhead_flag = v;
}
}
72 => {
if let Some(v) = val.as_i16() {
self.path_type = v;
}
}
73 => {
if let Some(v) = val.as_i16() {
self.creation_flag = v;
}
}
74 => {
if let Some(v) = val.as_i16() {
self.hook_line_direction = v;
}
}
75 => {
if let Some(v) = val.as_i16() {
self.hook_line_flag = v;
}
}
_ => {
if let Some(v) = val.as_f64() {
match code {
40 => self.annotation_height = v,
41 => self.annotation_width = v,
211 => self.horizontal_direction.x = v,
221 => self.horizontal_direction.y = v,
231 => self.horizontal_direction.z = v,
212 => self.block_offset.x = v,
222 => self.block_offset.y = v,
232 => self.block_offset.z = v,
213 => self.annotation_offset.x = v,
223 => self.annotation_offset.y = v,
233 => self.annotation_offset.z = v,
_ => {}
}
}
}
}
}
pub(crate) fn finish(&mut self) {
if let Some(pt) = self.current_pt.take() {
self.vertices.push(pt);
}
}
}