1pub mod text;
2
3extern crate core;
4
5use dxf::{Drawing};
6use dxf::entities::EntityType;
7use log::info;
8use dxf::enums::AttachmentPoint;
9
10pub struct Dxf {}
11
12impl Dxf {
13 pub fn load(path: &str) -> String {
14 let drawing = match Drawing::load_file(path) {
15 Ok(e) => e,
16 Err(_) => {
17 return "".to_string();
18 }
19 };
20 let mut x = 0.0;
21 let mut y = 0.0;
22
23 for e in drawing.entities() {
24 match e.specific {
26 EntityType::Circle(ref circle) => {
27 if x < circle.center.x {
28 x = circle.center.x;
29 }
30 if y < circle.center.y {
31 y = circle.center.y;
32 }
33
34
35 }
42 EntityType::Line(ref line) => {
43 if x < line.p1.x {
46 x = line.p1.x;
47 }
48 if x < line.p2.x {
49 x = line.p2.x;
50 }
51 if y < line.p1.y {
52 y = line.p1.y;
53 }
54 if y < line.p2.y {
55 y = line.p2.y;
56 }
57 }
58 EntityType::ModelPoint(ref _model_point) => {
59 }
61 EntityType::Text(ref _data) => {
62 }
64 EntityType::LwPolyline(ref line) => {
65 for vertex in line.vertices.iter() {
66 if x < vertex.x {
67 x = vertex.x;
68 }
69 if y < vertex.y {
70 y = vertex.y;
71 }
72 }
73 }
74 EntityType::Arc(ref arc) => {
75 if x < arc.center.x {
77 x = arc.center.x;
78 }
79 if y < arc.center.y {
80 y = arc.center.y;
81 }
82 }
83 EntityType::RadialDimension(ref _radial) => {}
84 EntityType::RotatedDimension(ref radial) => {
85 if x < radial.dimension_base.definition_point_1.x {
87 x = radial.dimension_base.definition_point_1.x;
88 }
89 if y < radial.dimension_base.definition_point_1.y {
90 y = radial.dimension_base.definition_point_1.y;
91 }
92
93 if x < radial.dimension_base.text_mid_point.x {
94 x = radial.dimension_base.text_mid_point.x;
95 }
96 if y < radial.dimension_base.text_mid_point.y {
97 y = radial.dimension_base.text_mid_point.y;
98 }
99 }
100 EntityType::MText(ref text) => {
101 if x < text.insertion_point.x {
103 x = text.insertion_point.x;
104 }
105 if y < text.insertion_point.y {
106 y = text.insertion_point.y;
107 }
108 }
109 EntityType::DiameterDimension(ref diameter) => {
110 if x < diameter.dimension_base.text_mid_point.x {
112 x = diameter.dimension_base.text_mid_point.x;
113 }
114 if y < diameter.dimension_base.text_mid_point.y {
115 y = diameter.dimension_base.text_mid_point.y;
116 }
117 }
118 EntityType::Insert(ref data) => {
119 if x < data.location.x {
121 x = data.location.x;
122 }
123 if y < data.location.y {
124 y = data.location.y;
125 }
126 }
127 _ => {
128 info!("未知 {:?}",e.specific);
129 }
130 }
131 }
132
133 fn r(max_x: f64, x: f64) -> f64 {
134 x / max_x * 100.0
135 }
136
137 let mut svg = vec![format!(r#"<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">"#)];
138
139 for e in drawing.entities() {
140 let index = e.common.handle.0;
141 match e.specific {
142 EntityType::Circle(ref circle) => {
143 let x_value = r(x, circle.center.x);
144 let y_value = r(y, circle.center.y);
145
146 let r_value = r([x, y].iter().copied().fold(f64::NAN, f64::max), circle.radius);
147 let text = format!(r#"<circle id="circle_{index}" cx="{x_value}%" cy="{y_value}%" r="{r_value}%" />"#);
148 svg.push(text);
149 }
156 EntityType::Line(ref line) => {
157 let x1_value = r(x, line.p1.x);
158 let y1_value = r(y, line.p1.y);
159 let x2_value = r(x, line.p2.x);
160 let y2_value = r(y, line.p2.y);
161 let text = format!(r#"<line id="line_{index}" x1="{x1_value}%" y1="{y1_value}%" x2="{x2_value}%" y2="{y2_value}%" stroke="black" stroke-width="1" />"#);
162 svg.push(text);
163 }
164 EntityType::ModelPoint(ref _model_point) => {
165 }
167 EntityType::Text(ref text) => {
168 info!("文本: {}",text.value);
169 }
170 EntityType::LwPolyline(ref line) => {
171 let mut points = vec![];
172 let mut xy = vec![];
173 for vertex in line.vertices.iter() {
174 if xy.is_empty() {
175 xy.push(r(x, vertex.x));
176 xy.push(r(y, vertex.y));
177 continue;
178 }
179 if xy.len() == 2 {
180 xy.push(r(x, vertex.x));
181 xy.push(r(y, vertex.y));
182 points.push(xy.clone());
183 xy.clear();
184 xy.push(r(x, vertex.x));
185 xy.push(r(y, vertex.y));
186 continue;
187 }
188 }
189 for point in points {
190 let text = format!(r#"<line id="polyline_line_{index}" x1="{}%" y1="{}%" x2="{}%" y2="{}%" stroke="black" stroke-width="1" />"#, point[0], point[1], point[2], point[3]);
191 svg.push(text);
192 }
193 }
194 EntityType::Insert(ref data) => {
195 println!("{:?}", data);
197 }
198 _ => {
199 }
201 }
202 }
203 svg.push("</svg>".to_string());
204 svg.join("")
205 }
206 pub fn ratio(path: &str) -> String {
208 let drawing = Drawing::load_file(path).unwrap();
209 let mut x = 0.0;
210 let mut y = 0.0;
211
212 for e in drawing.entities() {
213 let _index = e.common.handle.0;
214 match e.specific {
215 EntityType::Circle(ref circle) => {
216 if x < circle.center.x {
217 x = circle.center.x;
218 }
219 if y < circle.center.y {
220 y = circle.center.y;
221 }
222
223
224 }
231 EntityType::Line(ref line) => {
232 if x < line.p1.x {
235 x = line.p1.x;
236 }
237 if x < line.p2.x {
238 x = line.p2.x;
239 }
240 if y < line.p1.y {
241 y = line.p1.y;
242 }
243 if y < line.p2.y {
244 y = line.p2.y;
245 }
246 }
247 EntityType::ModelPoint(ref _model_point) => {
248 }
250 EntityType::Text(ref _text) => {
251 }
253 EntityType::LwPolyline(ref line) => {
254 for vertex in line.vertices.iter() {
255 if x < vertex.x {
256 x = vertex.x;
257 }
258 if y < vertex.y {
259 y = vertex.y;
260 }
261 }
262 }
263 _ => {
264 info!("未知 {:?}",e.specific);
265 }
266 }
267 }
268
269 fn r(max_x: f64, x: f64) -> f64 {
270 x / max_x * 100.0
271 }
272
273 let mut svg = vec![format!(r#"<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">"#)];
274
275 for e in drawing.entities() {
276 let index = e.common.handle.0;
277 match e.specific {
278 EntityType::Circle(ref circle) => {
279 let x_value = r(x, circle.center.x);
280 let y_value = r(y, circle.center.y);
281
282 let r_value = r([x, y].iter().copied().fold(f64::NAN, f64::max), circle.radius);
283 let text = format!(r#"<circle id="circle_{index}" cx="{x_value}%" cy="{y_value}%" r="{r_value}%" />"#);
284 svg.push(text);
285 }
292 EntityType::Line(ref line) => {
293 let x1_value = r(x, line.p1.x);
294 let y1_value = r(y, line.p1.y);
295 let x2_value = r(x, line.p2.x);
296 let y2_value = r(y, line.p2.y);
297 let text = format!(r#"<line id="line_{index}" x1="{x1_value}%" y1="{y1_value}%" x2="{x2_value}%" y2="{y2_value}%" stroke="black" stroke-width="1" />"#);
298 svg.push(text);
299 }
300 EntityType::ModelPoint(ref _model_point) => {
301 }
303 EntityType::Text(ref _text) => {
304 }
306 EntityType::LwPolyline(ref line) => {
307 let mut points = vec![];
308 let mut xy = vec![];
309 for vertex in line.vertices.iter() {
310 if xy.is_empty() {
311 xy.push(r(x, vertex.x));
312 xy.push(r(y, vertex.y));
313 continue;
314 }
315 if xy.len() == 2 {
316 xy.push(r(x, vertex.x));
317 xy.push(r(y, vertex.y));
318 points.push(xy.clone());
319 xy.clear();
320 xy.push(r(x, vertex.x));
321 xy.push(r(y, vertex.y));
322 continue;
323 }
324 }
325 for point in points {
326 let text = format!(r#"<line id="polyline_line_{index}" x1="{}%" y1="{}%" x2="{}%" y2="{}%" stroke="black" stroke-width="1" />"#, point[0], point[1], point[2], point[3]);
327 svg.push(text);
328 }
329 }
330 _ => {
331 info!("未知 {:?}",e.specific);
332 }
333 }
334 }
335 svg.push("</svg>".to_string());
336 svg.join("")
337 }
338
339 pub fn size(path: &str, class_id: &str) -> String {
341 let drawing = match Drawing::load_file(path) {
342 Ok(e) => e,
343 Err(_) => {
344 return "".to_string();
345 }
346 };
347
348 let mut x = 0.0;
349 let mut y = 0.0;
350
351 for e in drawing.entities() {
352 match e.specific {
353 EntityType::Circle(ref circle) => {
354 if x < circle.center.x {
355 x = circle.center.x;
356 }
357 if y < circle.center.y {
358 y = circle.center.y;
359 }
360
361
362 }
369 EntityType::Line(ref line) => {
370 if x < line.p1.x {
371 x = line.p1.x;
372 }
373 if x < line.p2.x {
374 x = line.p2.x;
375 }
376 if y < line.p1.y {
377 y = line.p1.y;
378 }
379 if y < line.p2.y {
380 y = line.p2.y;
381 }
382 }
383 EntityType::ModelPoint(ref _model_point) => {}
385 EntityType::Text(ref text) => {
387 if x < text.location.x {
388 x = text.location.x;
389 }
390 if y < text.location.y {
391 y = text.location.y;
392 }
393 }
394 EntityType::LwPolyline(ref line) => {
395 for vertex in line.vertices.iter() {
396 if x < vertex.x {
397 x = vertex.x;
398 }
399 if y < vertex.y {
400 y = vertex.y;
401 }
402 }
403 }
404 EntityType::Arc(ref arc) => {
405 if x < arc.center.x {
407 x = arc.center.x;
408 }
409 if y < arc.center.y {
410 y = arc.center.y;
411 }
412 }
413 EntityType::RadialDimension(ref _radial) => {
414 }
416 EntityType::RotatedDimension(ref radial) => {
417 if x < radial.dimension_base.definition_point_1.x {
419 x = radial.dimension_base.definition_point_1.x;
420 }
421 if y < radial.dimension_base.definition_point_1.y {
422 y = radial.dimension_base.definition_point_1.y;
423 }
424
425 if x < radial.dimension_base.text_mid_point.x {
426 x = radial.dimension_base.text_mid_point.x;
427 }
428 if y < radial.dimension_base.text_mid_point.y {
429 y = radial.dimension_base.text_mid_point.y;
430 }
431 }
432 EntityType::MText(ref text) => {
433 if x < text.insertion_point.x {
435 x = text.insertion_point.x;
436 }
437 if y < text.insertion_point.y {
438 y = text.insertion_point.y;
439 }
440 }
441 EntityType::DiameterDimension(ref diameter) => {
442 if x < diameter.dimension_base.text_mid_point.x {
444 x = diameter.dimension_base.text_mid_point.x;
445 }
446 if y < diameter.dimension_base.text_mid_point.y {
447 y = diameter.dimension_base.text_mid_point.y;
448 }
449 }
450 EntityType::Insert(ref data) => {
451 if x < data.location.x {
453 x = data.location.x;
454 }
455 if y < data.location.y {
456 y = data.location.y;
457 }
458 }
459 EntityType::Spline(ref data) => {
460 for control_point in data.control_points.iter() {
461 if x < control_point.x {
462 x = control_point.x;
463 }
464 if y < control_point.y {
465 y = control_point.y;
466 }
467 }
468 }
469 EntityType::Solid(ref data) => {
470 if x < data.first_corner.x {
471 x = data.first_corner.x;
472 }
473 if y < data.first_corner.y {
474 y = data.first_corner.y;
475 }
476
477 if x < data.second_corner.x {
478 x = data.second_corner.x;
479 }
480 if y < data.second_corner.y {
481 y = data.second_corner.y;
482 }
483 if x < data.third_corner.x {
484 x = data.third_corner.x;
485 }
486 if y < data.third_corner.y {
487 y = data.third_corner.y;
488 }
489 if x < data.fourth_corner.x {
490 x = data.fourth_corner.x;
491 }
492 if y < data.fourth_corner.y {
493 y = data.fourth_corner.y;
494 }
495 }
496 _ => {
497 info!("未知 {:?}",e.specific);
498 }
499 }
500 }
501
502
503 let mut svg = vec![format!(r#"<svg id="svg_{class_id}" width="{}" height="{}" xmlns="http://www.w3.org/2000/svg">"#, x, y)];
504
505 for e in drawing.entities() {
506 let index = e.common.handle.0;
507 match e.specific {
508 EntityType::Circle(ref circle) => {
509 let x_value = circle.center.x;
510 let y_value = circle.center.y;
511 let r_value = circle.radius;
512 let text = format!(r#"<circle class="svg" id="circle_{index}" cx="{x_value}" cy="{y_value}" r="{r_value}" fill="none" stroke="black" stroke-width="0.5" />"#);
513 svg.push(text);
514 }
515 EntityType::Line(ref line) => {
516 let x1_value = line.p1.x;
517 let y1_value = line.p1.y;
518 let x2_value = line.p2.x;
519 let y2_value = line.p2.y;
520 let text = format!(r#"<line class="svg" id="line_{index}" x1="{x1_value}" y1="{y1_value}" x2="{x2_value}" y2="{y2_value}" stroke="black" stroke-width="0.5" />"#);
521 svg.push(text);
522 }
523 EntityType::ModelPoint(ref model_point) => {
524 info!("模型: {:?} {:?}",model_point.location.x,model_point.location.y);
525 }
526 EntityType::Text(ref text) => {
527 let text_x = text.location.x;
529 let text_y = text.location.y;
530 let text_rotate = text.rotation;
531 let text_style_name = text.text_style_name.clone();
532 let text_height = text.text_height;
533 let value = text.value.clone();
534 let text = format!(r#"<text class="svg" x="{text_x}" y="{text_y}" transform="rotate({text_rotate})" font-family="{text_style_name}" font-size="{text_height}">{value}</text>"#);
536 svg.push(text);
537 }
538 EntityType::LwPolyline(ref line) => {
539 let mut points = vec![];
540 for vertex in line.vertices.iter() {
541 points.push(format!("{},{}", vertex.x, vertex.y));
542 }
543 let t = points.join(" ");
544 let text = format!(r#"<polyline class="svg" id="line_{index}" points="{}" fill="none" stroke="black" stroke-width="0.5" />"#, t);
545 svg.push(text);
546 }
547 EntityType::Insert(ref data) => {
549 info!("Insert: {:#?}",data);
550 }
557 EntityType::MText(ref data) => {
558 let text_x = data.insertion_point.x;
559 let text_y = data.insertion_point.y;
560 let value = data.text.clone();
561 let text_style_name = data.text_style_name.clone();
562 let initial_text_height = data.initial_text_height;
563 let anchor = match data.attachment_point {
564 AttachmentPoint::TopLeft => "start",
565 AttachmentPoint::TopCenter => "middle",
566 AttachmentPoint::TopRight => "end",
567 AttachmentPoint::MiddleLeft => "start",
568 AttachmentPoint::MiddleCenter => "middle",
569 AttachmentPoint::MiddleRight => "end",
570 AttachmentPoint::BottomLeft => "start",
571 AttachmentPoint::BottomCenter => "middle",
572 AttachmentPoint::BottomRight => "end"
573 };
574 let text = format!(r#"<text class="svg" id="mtext_{index}" x="{text_x}" y="{text_y}" text-anchor="{anchor}" font-family="{text_style_name}" font-size="{initial_text_height}">{value}</text>"#);
575 svg.push(text);
576 }
577 EntityType::RotatedDimension(ref data) => {
579 let text = format!(r#"<g class="svg" id="g_{index}">"#);
581 svg.push(text);
582
583 let x1_value = data.dimension_base.definition_point_1.x;
584 let y1_value = data.definition_point_2.y;
585 let x2_value = data.definition_point_2.x;
586 let y2_value = data.definition_point_2.y;
587 let text = format!(r#"<line class="svg" id="line1_{index}" x1="{x1_value}" y1="{y1_value}" x2="{x2_value}" y2="{y2_value}" stroke="red" stroke-width="0.3" />"#);
588 svg.push(text);
589
590
591 let x1_value = data.dimension_base.definition_point_1.x;
592 let y1_value = data.dimension_base.definition_point_1.y;
593 let x2_value = data.definition_point_3.x;
594 let y2_value = data.definition_point_3.y;
595 let text = format!(r#"<line class="svg" id="line2_{index}" x1="{x1_value}" y1="{y1_value}" x2="{x2_value}" y2="{y2_value}" stroke="red" stroke-width="0.3" />"#);
596 svg.push(text);
597
598
599 let x1_value = data.dimension_base.definition_point_1.x;
600 let y1_value = data.definition_point_2.y;
601 let x2_value = data.dimension_base.definition_point_1.x;
602 let y2_value = data.dimension_base.definition_point_1.y;
603 let text = format!(r#"<line class="svg" id="line3_{index}" x1="{x1_value}" y1="{y1_value}" x2="{x2_value}" y2="{y2_value}" stroke="red" stroke-width="0.3" />"#);
604 svg.push(text);
605
606
607 let x2_value = data.dimension_base.text_mid_point.x;
608 let y2_value = data.dimension_base.text_mid_point.y;
609 let text_value = data.dimension_base.text.clone();
610 let text_value = symbol(text_value.as_str());
611 let block_name = data.dimension_base.block_name.clone();
612
613 let anchor = match data.dimension_base.attachment_point {
614 AttachmentPoint::TopLeft => "start",
615 AttachmentPoint::TopCenter => "middle",
616 AttachmentPoint::TopRight => "end",
617 AttachmentPoint::MiddleLeft => "start",
618 AttachmentPoint::MiddleCenter => "middle",
619 AttachmentPoint::MiddleRight => "end",
620 AttachmentPoint::BottomLeft => "start",
621 AttachmentPoint::BottomCenter => "middle",
622 AttachmentPoint::BottomRight => "end"
623 };
624
625 let text = format!(r#"<text class="svg" id="RotatedDimension_{index}" x="{x2_value}" y="{y2_value}" text-anchor="{anchor}" font-size="3">{text_value}{block_name}</text>"#);
626 svg.push(text);
627
628 let text = r#"</g>"#.to_string();
629 svg.push(text);
630 }
631 EntityType::DiameterDimension(ref data) => {
633 let x1_value = data.dimension_base.definition_point_1.x;
636 let y1_value = data.dimension_base.definition_point_1.y;
637 let x2_value = data.definition_point_2.x;
638 let y2_value = data.definition_point_2.y;
639 let text = format!(r#"<line class="svg" id="line1_{index}" x1="{x1_value}" y1="{y1_value}" x2="{x2_value}" y2="{y2_value}" stroke="red" stroke-width="0.3" />"#);
640 svg.push(text);
641
642
643 let x1_value = data.dimension_base.text_mid_point.x;
644 let y1_value = data.dimension_base.text_mid_point.y;
645 let x2_value = data.definition_point_2.x;
646 let y2_value = data.definition_point_2.y;
647 let text = format!(r#"<line class="svg" id="line2_{index}" x1="{x1_value}" y1="{y1_value}" x2="{x2_value}" y2="{y2_value}" stroke="red" stroke-width="0.3" />"#);
648 svg.push(text);
649
650 let x1_value = data.dimension_base.text_mid_point.x;
651 let y1_value = data.dimension_base.text_mid_point.y;
652 let x2_value = data.dimension_base.text_mid_point.x - 10.0;
653 let y2_value = data.dimension_base.text_mid_point.y;
654 let text = format!(r#"<line class="svg" id="line2_{index}" x1="{x1_value}" y1="{y1_value}" x2="{x2_value}" y2="{y2_value}" stroke="red" stroke-width="0.3" />"#);
655 svg.push(text);
656
657 let text = data.dimension_base.text.clone();
658 let text_x = data.dimension_base.text_mid_point.x;
659 let text_y = data.dimension_base.text_mid_point.y;
660 let text = symbol(text.as_str());
661 let anchor = match data.dimension_base.attachment_point {
662 AttachmentPoint::TopLeft => "start",
663 AttachmentPoint::TopCenter => "middle",
664 AttachmentPoint::TopRight => "end",
665 AttachmentPoint::MiddleLeft => "start",
666 AttachmentPoint::MiddleCenter => "middle",
667 AttachmentPoint::MiddleRight => "end",
668 AttachmentPoint::BottomLeft => "start",
669 AttachmentPoint::BottomCenter => "middle",
670 AttachmentPoint::BottomRight => "end"
671 };
672
673 let text = format!(r#"<text class="svg" id="diameter_dimension_{index}" x="{text_x}" y="{text_y}" text-anchor="{anchor}" font-size="3">{text}</text>"#);
674 svg.push(text);
675 }
676 EntityType::Arc(ref data) => {
677 let x_value = data.center.x + data.radius * data.start_angle.to_radians().cos();
678 let y_value = data.center.y + data.radius * data.start_angle.to_radians().sin();
679 let radius_value = data.radius;
680 let end_x = data.center.x + data.radius * (data.start_angle + data.end_angle).to_radians().cos();
681 let end_y = data.center.y + data.radius * (data.start_angle + data.end_angle).to_radians().sin();
682
683 let text = format!(r#"<path class="svg" id="diameter_dimension_{index}" d="M {x_value},{y_value} A {radius_value},{radius_value} 0 1,0 {end_x},{end_y}" fill="none" stroke="black" stroke-width="0.3" />"#);
684 svg.push(text);
685 }
686 EntityType::Spline(ref data) => {
687 let x1 = data.control_points[0].x;
689 let y1 = data.control_points[0].y;
690 let x2 = data.control_points[1].x;
691 let y2 = data.control_points[1].y;
692 let x3 = data.control_points[2].x;
693 let y3 = data.control_points[2].y;
694 let x4 = data.control_points[3].x;
695 let y4 = data.control_points[3].y;
696 let text = format!(r#"<path class="svg" id="diameter_dimension_{index}" d="M{x1} {y1} C{x2} {y2},{x3} {y3},{x4} {y4}" fill="none" stroke="black" stroke-width="0.3" />"#);
697 svg.push(text);
698 }
699 EntityType::Solid(ref data) => {
700 let x1 = data.first_corner.x;
702 let y1 = data.first_corner.y;
703 let x2 = data.second_corner.x;
704 let y2 = data.second_corner.y;
705 let x3 = data.third_corner.x;
706 let y3 = data.third_corner.y;
707 let x4 = data.fourth_corner.x;
708 let y4 = data.fourth_corner.y;
709 let text = format!(r#"<path class="svg" id="Solid_{index}" d="M{x1} {y1} L{x2} {y2} L{x3} {y3} L{x4} {y4} Z" fill="none" stroke="black" stroke-width="0.3" />"#);
710 svg.push(text);
711 }
712 EntityType::RadialDimension(ref data) => {
713 let x1_value = data.dimension_base.definition_point_1.x;
715 let y1_value = data.dimension_base.definition_point_1.y;
716 let x2_value = data.definition_point_2.x;
717 let y2_value = data.definition_point_2.y;
718 let text = format!(r#"<line class="svg" id="line1_{index}" x1="{x1_value}" y1="{y1_value}" x2="{x2_value}" y2="{y2_value}" stroke="red" stroke-width="0.3" />"#);
719 svg.push(text);
720
721
722 let x1_value = data.dimension_base.text_mid_point.x;
723 let y1_value = data.dimension_base.text_mid_point.y;
724 let x2_value = data.definition_point_2.x;
725 let y2_value = data.definition_point_2.y;
726 let text = format!(r#"<line class="svg" id="line2_{index}" x1="{x1_value}" y1="{y1_value}" x2="{x2_value}" y2="{y2_value}" stroke="red" stroke-width="0.3" />"#);
727 svg.push(text);
728
729 let x1_value = data.dimension_base.text_mid_point.x;
730 let y1_value = data.dimension_base.text_mid_point.y;
731 let x2_value = data.dimension_base.text_mid_point.x - 10.0;
732 let y2_value = data.dimension_base.text_mid_point.y;
733 let text = format!(r#"<line class="svg" id="line2_{index}" x1="{x1_value}" y1="{y1_value}" x2="{x2_value}" y2="{y2_value}" stroke="red" stroke-width="0.3" />"#);
734 svg.push(text);
735
736 let text = data.dimension_base.text.clone();
737 let text_x = data.dimension_base.text_mid_point.x;
738 let text_y = data.dimension_base.text_mid_point.y;
739 let text = symbol(text.as_str());
740 let anchor = match data.dimension_base.attachment_point {
741 AttachmentPoint::TopLeft => "start",
742 AttachmentPoint::TopCenter => "middle",
743 AttachmentPoint::TopRight => "end",
744 AttachmentPoint::MiddleLeft => "start",
745 AttachmentPoint::MiddleCenter => "middle",
746 AttachmentPoint::MiddleRight => "end",
747 AttachmentPoint::BottomLeft => "start",
748 AttachmentPoint::BottomCenter => "middle",
749 AttachmentPoint::BottomRight => "end"
750 };
751
752 let text = format!(r#"<text class="svg" id="diameter_dimension_{index}" x="{text_x}" y="{text_y}" text-anchor="{anchor}" font-size="3">{text}</text>"#);
753 svg.push(text);
754 }
755 _ => {
756 info!("未知 {:?}",e.specific);
757 }
758 }
759 }
760 svg.push("</svg>".to_string());
761 svg.join("")
762 }
763}
764
765fn symbol(value: &str) -> String {
766 match value {
767 s if s.contains("<>") => s.replace("<>", "⌀"),
769 _ => value.parse().unwrap()
770 }.to_string()
771}