|
|
|
|
@ -201,15 +201,16 @@ impl Circularity for LwPolyline {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 实现Definition的方法
|
|
|
|
|
// 最后返回文本的definition标签了
|
|
|
|
|
impl Definition {
|
|
|
|
|
// 创建新的 Definition 实例
|
|
|
|
|
// 创建新的 Definition 实例,对应elmt的<definition>标签 传入参数:文件名, 步长, dxf图纸
|
|
|
|
|
pub fn new(name: impl Into<String>, spline_step: u32, drw: &Drawing) -> Self {
|
|
|
|
|
/*for st in drw.styles() {
|
|
|
|
|
dbg!(st);
|
|
|
|
|
}*/
|
|
|
|
|
// 缩放处理
|
|
|
|
|
// 根据制图系统的类型缩放处理
|
|
|
|
|
let scale_factor = Self::scale_factor(drw.header.default_drawing_units);
|
|
|
|
|
// 创建description
|
|
|
|
|
// 创建description,对应elmt的<description>标签,里面就是实际的画图元素标签
|
|
|
|
|
let description = {
|
|
|
|
|
let mut description: Description = (drw, spline_step).into();
|
|
|
|
|
description.scale(scale_factor, scale_factor);
|
|
|
|
|
@ -847,87 +848,96 @@ impl<'a> ObjectsBuilder<'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
EntityType::LwPolyline(lwpolyline) => match lwpolyline.vertices.len() {
|
|
|
|
|
0 | 1 => Err("Error empty LwPolyline"),
|
|
|
|
|
2 => {
|
|
|
|
|
if lwpolyline.vertices[0].bulge != 0.0 {
|
|
|
|
|
match Arc::try_from(lwpolyline) {
|
|
|
|
|
Ok(mut arc) => {
|
|
|
|
|
arc.update_line_style(&update_line_style);
|
|
|
|
|
arc.scale(self.scale_fact.x, self.scale_fact.y);
|
|
|
|
|
arc.x += self.offset.x;
|
|
|
|
|
arc.y -= self.offset.y;
|
|
|
|
|
return Ok(Objects::Arc(arc));
|
|
|
|
|
}
|
|
|
|
|
Err(_) => {
|
|
|
|
|
// Arc转换失败,继续执行下面的Line转换
|
|
|
|
|
EntityType::LwPolyline(lwpolyline) => {
|
|
|
|
|
// 获取颜色
|
|
|
|
|
let color = if let Some(aci_index) = self.ent.common.color.index() {
|
|
|
|
|
aci_to_hex_color(aci_index)
|
|
|
|
|
} else {
|
|
|
|
|
HexColor::from_u32(self.ent.common.color_24_bit as u32)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
match lwpolyline.vertices.len() {
|
|
|
|
|
0 | 1 => Err("Error empty LwPolyline"),
|
|
|
|
|
2 => {
|
|
|
|
|
if lwpolyline.vertices[0].bulge != 0.0 {
|
|
|
|
|
match Arc::try_from_lwpolyline_with_color(lwpolyline, color) {
|
|
|
|
|
Ok(mut arc) => {
|
|
|
|
|
arc.update_line_style(&update_line_style);
|
|
|
|
|
arc.scale(self.scale_fact.x, self.scale_fact.y);
|
|
|
|
|
arc.x += self.offset.x;
|
|
|
|
|
arc.y -= self.offset.y;
|
|
|
|
|
return Ok(Objects::Arc(arc));
|
|
|
|
|
}
|
|
|
|
|
Err(_) => {
|
|
|
|
|
// Arc转换失败,继续执行下面的Line转换
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut line = Line::try_from(lwpolyline)?;
|
|
|
|
|
|
|
|
|
|
// 根据line_type_name更新线型样式
|
|
|
|
|
line.update_line_style(&update_line_style);
|
|
|
|
|
|
|
|
|
|
line.scale(self.scale_fact.x, self.scale_fact.y);
|
|
|
|
|
|
|
|
|
|
line.x1 += self.offset.x;
|
|
|
|
|
line.y1 -= self.offset.y;
|
|
|
|
|
|
|
|
|
|
line.x2 += self.offset.x;
|
|
|
|
|
line.y2 -= self.offset.y;
|
|
|
|
|
let mut line = Line::try_from_lwpolyline_with_color(lwpolyline, color)?;
|
|
|
|
|
|
|
|
|
|
Ok(Objects::Line(line))
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
|
|
|
|
if let Ok(mut ellipse) = Ellipse::try_from(lwpolyline) {
|
|
|
|
|
// 根据line_type_name更新线型样式
|
|
|
|
|
ellipse.update_line_style(&update_line_style);
|
|
|
|
|
line.update_line_style(&update_line_style);
|
|
|
|
|
|
|
|
|
|
ellipse.scale(self.scale_fact.x, self.scale_fact.y);
|
|
|
|
|
line.scale(self.scale_fact.x, self.scale_fact.y);
|
|
|
|
|
|
|
|
|
|
ellipse.x += self.offset.x;
|
|
|
|
|
ellipse.y -= self.offset.y;
|
|
|
|
|
line.x1 += self.offset.x;
|
|
|
|
|
line.y1 -= self.offset.y;
|
|
|
|
|
|
|
|
|
|
Ok(Objects::Ellipse(ellipse))
|
|
|
|
|
} else if polygon::is_rounded_rectangle(lwpolyline) {
|
|
|
|
|
// 拆分圆角四边形为圆弧和直线段
|
|
|
|
|
let mut decomposed_objects = polygon::decompose_rounded_rectangle(lwpolyline);
|
|
|
|
|
|
|
|
|
|
// 对每个对象应用缩放和偏移
|
|
|
|
|
for obj in &mut decomposed_objects {
|
|
|
|
|
obj.scale(self.scale_fact.x, self.scale_fact.y);
|
|
|
|
|
match obj {
|
|
|
|
|
Objects::Arc(ref mut arc) => {
|
|
|
|
|
arc.x += self.offset.x;
|
|
|
|
|
arc.y -= self.offset.y;
|
|
|
|
|
}
|
|
|
|
|
Objects::Line(ref mut line) => {
|
|
|
|
|
line.x1 += self.offset.x;
|
|
|
|
|
line.y1 -= self.offset.y;
|
|
|
|
|
line.x2 += self.offset.x;
|
|
|
|
|
line.y2 -= self.offset.y;
|
|
|
|
|
line.x2 += self.offset.x;
|
|
|
|
|
line.y2 -= self.offset.y;
|
|
|
|
|
|
|
|
|
|
Ok(Objects::Line(line))
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
|
|
|
|
if let Ok(mut ellipse) = Ellipse::try_from_lwpolyline_with_color(lwpolyline, color) {
|
|
|
|
|
// 根据line_type_name更新线型样式
|
|
|
|
|
ellipse.update_line_style(&update_line_style);
|
|
|
|
|
|
|
|
|
|
ellipse.scale(self.scale_fact.x, self.scale_fact.y);
|
|
|
|
|
|
|
|
|
|
ellipse.x += self.offset.x;
|
|
|
|
|
ellipse.y -= self.offset.y;
|
|
|
|
|
|
|
|
|
|
Ok(Objects::Ellipse(ellipse))
|
|
|
|
|
} else if polygon::is_rounded_rectangle(lwpolyline) {
|
|
|
|
|
// 拆分圆角四边形为圆弧和直线段
|
|
|
|
|
let mut decomposed_objects = polygon::decompose_rounded_rectangle_with_color(lwpolyline, color);
|
|
|
|
|
|
|
|
|
|
// 对每个对象应用缩放和偏移
|
|
|
|
|
for obj in &mut decomposed_objects {
|
|
|
|
|
obj.scale(self.scale_fact.x, self.scale_fact.y);
|
|
|
|
|
match obj {
|
|
|
|
|
Objects::Arc(ref mut arc) => {
|
|
|
|
|
arc.x += self.offset.x;
|
|
|
|
|
arc.y -= self.offset.y;
|
|
|
|
|
}
|
|
|
|
|
Objects::Line(ref mut line) => {
|
|
|
|
|
line.x1 += self.offset.x;
|
|
|
|
|
line.y1 -= self.offset.y;
|
|
|
|
|
line.x2 += self.offset.x;
|
|
|
|
|
line.y2 -= self.offset.y;
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(Objects::Group(decomposed_objects))
|
|
|
|
|
} else {
|
|
|
|
|
let mut poly: Polygon = lwpolyline.into();
|
|
|
|
|
|
|
|
|
|
Ok(Objects::Group(decomposed_objects))
|
|
|
|
|
} else {
|
|
|
|
|
let mut poly: Polygon = Polygon::from_lwpolyline_with_color(lwpolyline, color);
|
|
|
|
|
|
|
|
|
|
// 根据line_type_name更新线型样式
|
|
|
|
|
poly.update_line_style(&update_line_style);
|
|
|
|
|
// 根据line_type_name更新线型样式
|
|
|
|
|
poly.update_line_style(&update_line_style);
|
|
|
|
|
|
|
|
|
|
poly.scale(self.scale_fact.x, self.scale_fact.y);
|
|
|
|
|
poly.scale(self.scale_fact.x, self.scale_fact.y);
|
|
|
|
|
|
|
|
|
|
for cord in &mut poly.coordinates {
|
|
|
|
|
cord.x += self.offset.x;
|
|
|
|
|
cord.y -= self.offset.y;
|
|
|
|
|
}
|
|
|
|
|
for cord in &mut poly.coordinates {
|
|
|
|
|
cord.x += self.offset.x;
|
|
|
|
|
cord.y -= self.offset.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(Objects::Polygon(poly))
|
|
|
|
|
Ok(Objects::Polygon(poly))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|