|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
use super::{two_dec, ScaleEntity};
|
|
|
|
|
use dxf::entities::{LwPolyline, Polyline, Solid, Spline};
|
|
|
|
|
use hex_color::HexColor;
|
|
|
|
|
use simple_xml_builder::XMLElement;
|
|
|
|
|
use std::ops::{Add, Mul};
|
|
|
|
|
|
|
|
|
|
@ -79,6 +80,13 @@ impl From<&Polyline> for Polygon {
|
|
|
|
|
|
|
|
|
|
impl From<&LwPolyline> for Polygon {
|
|
|
|
|
fn from(poly: &LwPolyline) -> Self {
|
|
|
|
|
Self::from_lwpolyline_with_color(poly, HexColor::BLACK)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Polygon {
|
|
|
|
|
/// 从DXF LwPolyline实体创建Polygon,支持自定义颜色
|
|
|
|
|
pub fn from_lwpolyline_with_color(poly: &LwPolyline, color: HexColor) -> Self {
|
|
|
|
|
Polygon {
|
|
|
|
|
coordinates: poly
|
|
|
|
|
.vertices
|
|
|
|
|
@ -93,11 +101,10 @@ impl From<&LwPolyline> for Polygon {
|
|
|
|
|
//reasons...I'm trying to think if there is a time we might want to turn it on?
|
|
|
|
|
antialias: false,
|
|
|
|
|
style: if poly.thickness > 0.1 {
|
|
|
|
|
"line-style:normal;line-weight:normal;filling:none;color:black"
|
|
|
|
|
format!("line-style:normal;line-weight:normal;filling:none;color:{}", color.display_rgb())
|
|
|
|
|
} else {
|
|
|
|
|
"line-style:normal;line-weight:thin;filling:none;color:black"
|
|
|
|
|
}
|
|
|
|
|
.into(),
|
|
|
|
|
format!("line-style:normal;line-weight:thin;filling:none;color:{}", color.display_rgb())
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -311,6 +318,10 @@ pub fn is_rounded_rectangle(lwpolyline: &LwPolyline) -> bool {
|
|
|
|
|
|
|
|
|
|
/// 将带圆角的四边形拆分为圆弧和直线段
|
|
|
|
|
pub fn decompose_rounded_rectangle(lwpolyline: &LwPolyline) -> Vec<super::Objects> {
|
|
|
|
|
decompose_rounded_rectangle_with_color(lwpolyline, HexColor::BLACK)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn decompose_rounded_rectangle_with_color(lwpolyline: &LwPolyline, color: HexColor) -> Vec<super::Objects> {
|
|
|
|
|
let mut objects = Vec::new();
|
|
|
|
|
let vertices = &lwpolyline.vertices;
|
|
|
|
|
|
|
|
|
|
@ -320,16 +331,16 @@ pub fn decompose_rounded_rectangle(lwpolyline: &LwPolyline) -> Vec<super::Object
|
|
|
|
|
|
|
|
|
|
if current.bulge.abs() > 1e-10 {
|
|
|
|
|
// 创建圆弧段
|
|
|
|
|
if let Some(arc) = create_arc_from_bulge(current.x, current.y, next.x, next.y, current.bulge) {
|
|
|
|
|
if let Some(arc) = create_arc_from_bulge_with_color(current.x, current.y, next.x, next.y, current.bulge, color) {
|
|
|
|
|
objects.push(super::Objects::Arc(arc));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 创建直线段
|
|
|
|
|
let style = if lwpolyline.thickness > 0.5 {
|
|
|
|
|
"line-style:normal;line-weight:normal;filling:none;color:black"
|
|
|
|
|
format!("line-style:normal;line-weight:normal;filling:none;color:color:{}", color.display_rgb())
|
|
|
|
|
} else {
|
|
|
|
|
"line-style:normal;line-weight:thin;filling:none;color:black"
|
|
|
|
|
}.to_string();
|
|
|
|
|
format!("line-style:normal;line-weight:thin;filling:none;color:color:{}", color.display_rgb())
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let line = super::Line::new(
|
|
|
|
|
current.x,
|
|
|
|
|
@ -346,6 +357,10 @@ pub fn decompose_rounded_rectangle(lwpolyline: &LwPolyline) -> Vec<super::Object
|
|
|
|
|
|
|
|
|
|
/// 根据bulge值创建圆弧
|
|
|
|
|
fn create_arc_from_bulge(start_x: f64, start_y: f64, end_x: f64, end_y: f64, bulge: f64) -> Option<super::Arc> {
|
|
|
|
|
create_arc_from_bulge_with_color(start_x, start_y, end_x, end_y, bulge, HexColor::BLACK)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn create_arc_from_bulge_with_color(start_x: f64, start_y: f64, end_x: f64, end_y: f64, bulge: f64, color: HexColor) -> Option<super::Arc> {
|
|
|
|
|
if bulge.abs() <= 1e-10 {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
@ -442,7 +457,7 @@ fn create_arc_from_bulge(start_x: f64, start_y: f64, end_x: f64, end_y: f64, bul
|
|
|
|
|
// let start_angle = (start_y - center_y).atan2(start_x - center_x).to_degrees();
|
|
|
|
|
// let angle_span = angle.to_degrees().abs();
|
|
|
|
|
|
|
|
|
|
let style = "line-style:normal;line-weight:thin;filling:none;color:black".to_string();
|
|
|
|
|
let style = format!("line-style:normal;line-weight:thin;filling:none;color:{}", color.display_rgb());
|
|
|
|
|
|
|
|
|
|
Some(super::Arc::new(
|
|
|
|
|
center_x-radius,
|
|
|
|
|
|