use crate::types::{BoundingBox3D, Color, Handle, LineWeight, Transform, Transparency, Vector3};
pub mod point;
pub mod line;
pub mod circle;
pub mod arc;
pub mod ellipse;
pub mod polyline;
pub mod polyline3d;
pub mod lwpolyline;
pub mod text;
pub mod mtext;
pub mod spline;
pub mod dimension;
pub mod hatch;
pub mod solid;
pub mod face3d;
pub mod insert;
pub mod block;
pub mod ray;
pub mod xline;
pub mod viewport;
pub mod attribute_definition;
pub mod attribute_entity;
pub mod leader;
pub mod multileader;
pub mod mline;
pub mod mesh;
pub mod raster_image;
pub mod solid3d;
pub mod acis;
pub mod table;
pub mod tolerance;
pub mod polyface_mesh;
pub mod wipeout;
pub mod shape;
pub mod underlay;
pub mod seqend;
pub mod ole2frame;
pub mod polygon_mesh;
pub mod unknown_entity;
pub mod explode;
pub mod translate;
pub mod transform;
pub mod mirror;
pub use point::Point;
pub use line::Line;
pub use circle::Circle;
pub use arc::Arc;
pub use ellipse::Ellipse;
pub use polyline::{Polyline, Polyline2D, Vertex2D, Vertex3D, PolylineFlags, VertexFlags, SmoothSurfaceType};
pub use polyline3d::{Polyline3D, Vertex3DPolyline, Polyline3DFlags};
pub use lwpolyline::{LwPolyline, LwVertex};
pub use text::{Text, TextHorizontalAlignment, TextVerticalAlignment};
pub use mtext::{MText, AttachmentPoint, DrawingDirection};
pub use spline::{Spline, SplineFlags};
pub use dimension::*;
pub use hatch::*;
pub use solid::Solid;
pub use face3d::{Face3D, InvisibleEdgeFlags};
pub use insert::Insert;
pub use block::{Block, BlockEnd};
pub use ray::Ray;
pub use xline::XLine;
pub use viewport::{Viewport, ViewportStatusFlags, ViewportRenderMode, StandardView, GridFlags};
pub use attribute_definition::{AttributeDefinition, AttributeFlags, HorizontalAlignment, VerticalAlignment, MTextFlag};
pub use attribute_entity::AttributeEntity;
pub use leader::{Leader, LeaderPathType, LeaderCreationType, HooklineDirection};
pub use multileader::{
MultiLeader, MultiLeaderBuilder, MultiLeaderAnnotContext,
LeaderRoot, LeaderLine, BlockAttribute, StartEndPointPair,
LeaderContentType, MultiLeaderPathType, TextAttachmentType, TextAngleType,
BlockContentConnectionType, TextAttachmentDirectionType, TextAttachmentPointType,
TextAlignmentType, FlowDirectionType, LineSpacingStyle,
MultiLeaderPropertyOverrideFlags, LeaderLinePropertyOverrideFlags,
};
pub use mline::{
MLine, MLineBuilder, MLineVertex, MLineSegment,
MLineStyle, MLineStyleElement, MLineJustification, MLineFlags, MLineStyleFlags,
};
pub use mesh::{Mesh, MeshBuilder, MeshEdge, MeshFace};
pub use raster_image::{
RasterImage, RasterImageBuilder, ImageDefinition, ClipBoundary,
ClipMode, ClipType, ImageDisplayFlags, ImageDisplayQuality, ResolutionUnit,
};
pub use solid3d::{
Solid3D, Region, Body, Wire, Silhouette, AcisData,
WireType, AcisVersion,
};
pub use table::{
Table, TableBuilder, TableCell, TableRow, TableColumn,
CellContent, CellValue, CellStyle, CellBorder, CellRange,
CellType, CellValueType, ValueUnitType, BorderType,
TableCellContentType, CellStyleType, BreakFlowDirection,
CellEdgeFlags, CellStateFlags, CellStylePropertyFlags,
BorderPropertyFlags, ContentLayoutFlags, BreakOptionFlags,
};
pub use tolerance::{Tolerance, gdt_symbols};
pub use polyface_mesh::{
PolyfaceMesh, PolyfaceVertex, PolyfaceFace,
PolyfaceMeshFlags, PolyfaceVertexFlags, PolyfaceSmoothType,
};
pub use wipeout::{
Wipeout, WipeoutDisplayFlags, WipeoutClipType, WipeoutClipMode,
};
pub use shape::{Shape, standard_shapes, gdt_shapes};
pub use underlay::{
Underlay, UnderlayDefinition, UnderlayType, UnderlayDisplayFlags,
PdfUnderlay, DwfUnderlay, DgnUnderlay,
PdfUnderlayDefinition, DwfUnderlayDefinition, DgnUnderlayDefinition,
};
pub use seqend::Seqend;
pub use ole2frame::{Ole2Frame, OleObjectType};
pub use polygon_mesh::{
PolygonMesh as PolygonMeshEntity, PolygonMeshVertex, PolygonMeshFlags, SurfaceSmoothType,
};
pub use unknown_entity::UnknownEntity;
pub trait Entity {
fn handle(&self) -> Handle;
fn set_handle(&mut self, handle: Handle);
fn layer(&self) -> &str;
fn set_layer(&mut self, layer: String);
fn color(&self) -> Color;
fn set_color(&mut self, color: Color);
fn line_weight(&self) -> LineWeight;
fn set_line_weight(&mut self, weight: LineWeight);
fn transparency(&self) -> Transparency;
fn set_transparency(&mut self, transparency: Transparency);
fn is_invisible(&self) -> bool;
fn set_invisible(&mut self, invisible: bool);
fn bounding_box(&self) -> BoundingBox3D;
fn translate(&mut self, offset: Vector3);
fn entity_type(&self) -> &'static str;
fn apply_transform(&mut self, transform: &Transform) {
let origin = Vector3::ZERO;
let translated = transform.apply(origin);
self.translate(translated);
}
fn apply_rotation(&mut self, axis: Vector3, angle: f64) {
self.apply_transform(&Transform::from_rotation(axis, angle));
}
fn apply_scaling(&mut self, scale: f64) {
self.apply_transform(&Transform::from_scale(scale));
}
fn apply_scaling_xyz(&mut self, scale: Vector3) {
self.apply_transform(&Transform::from_scaling(scale));
}
fn apply_scaling_with_origin(&mut self, scale: Vector3, origin: Vector3) {
self.apply_transform(&Transform::from_scaling_with_origin(scale, origin));
}
fn apply_mirror(&mut self, transform: &Transform) {
self.apply_transform(transform);
}
fn mirror_x(&mut self) {
self.apply_mirror(&Transform::from_mirror_x());
}
fn mirror_y(&mut self) {
self.apply_mirror(&Transform::from_mirror_y());
}
fn mirror_z(&mut self) {
self.apply_mirror(&Transform::from_mirror_z());
}
fn mirror_about_line(&mut self, p1: Vector3, p2: Vector3) {
self.apply_mirror(&Transform::from_mirror_line(p1, p2));
}
fn mirror_about_plane(&mut self, point: Vector3, normal: Vector3) {
self.apply_mirror(&Transform::from_mirror_plane(point, normal));
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EntityCommon {
pub handle: Handle,
pub layer: String,
pub color: Color,
pub line_weight: LineWeight,
pub linetype: String,
pub linetype_scale: f64,
pub transparency: Transparency,
pub invisible: bool,
pub extended_data: crate::xdata::ExtendedData,
pub reactors: Vec<Handle>,
pub xdictionary_handle: Option<Handle>,
pub owner_handle: Handle,
}
impl EntityCommon {
pub fn new() -> Self {
EntityCommon {
handle: Handle::NULL,
layer: "0".to_string(),
color: Color::ByLayer,
line_weight: LineWeight::ByLayer,
linetype: String::new(),
linetype_scale: 1.0,
transparency: Transparency::OPAQUE,
invisible: false,
extended_data: crate::xdata::ExtendedData::new(),
reactors: Vec::new(),
xdictionary_handle: None,
owner_handle: Handle::NULL,
}
}
pub fn with_layer(layer: impl Into<String>) -> Self {
EntityCommon {
layer: layer.into(),
..Self::new()
}
}
pub fn has_linetype(&self) -> bool {
!self.linetype.is_empty() && self.linetype != "ByLayer"
}
}
impl Default for EntityCommon {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EntityType {
Point(Point),
Line(Line),
Circle(Circle),
Arc(Arc),
Ellipse(Ellipse),
Polyline(Polyline),
Polyline2D(Polyline2D),
Polyline3D(Polyline3D),
LwPolyline(LwPolyline),
Text(Text),
MText(MText),
Spline(Spline),
Dimension(Dimension),
Hatch(Hatch),
Solid(Solid),
Face3D(Face3D),
Insert(Insert),
Block(Block),
BlockEnd(BlockEnd),
Ray(Ray),
XLine(XLine),
Viewport(Viewport),
AttributeDefinition(AttributeDefinition),
AttributeEntity(AttributeEntity),
Leader(Leader),
MultiLeader(MultiLeader),
MLine(MLine),
Mesh(Mesh),
RasterImage(RasterImage),
Solid3D(Solid3D),
Region(Region),
Body(Body),
Table(Table),
Tolerance(Tolerance),
PolyfaceMesh(PolyfaceMesh),
Wipeout(Wipeout),
Shape(Shape),
Underlay(Underlay),
Seqend(Seqend),
Ole2Frame(Ole2Frame),
PolygonMesh(PolygonMeshEntity),
Unknown(UnknownEntity),
}
impl EntityType {
pub fn as_entity(&self) -> &dyn Entity {
match self {
EntityType::Point(e) => e,
EntityType::Line(e) => e,
EntityType::Circle(e) => e,
EntityType::Arc(e) => e,
EntityType::Ellipse(e) => e,
EntityType::Polyline(e) => e,
EntityType::Polyline2D(e) => e,
EntityType::Polyline3D(e) => e,
EntityType::LwPolyline(e) => e,
EntityType::Text(e) => e,
EntityType::MText(e) => e,
EntityType::Spline(e) => e,
EntityType::Dimension(e) => e,
EntityType::Hatch(e) => e,
EntityType::Solid(e) => e,
EntityType::Face3D(e) => e,
EntityType::Insert(e) => e,
EntityType::Block(e) => e,
EntityType::BlockEnd(e) => e,
EntityType::Ray(e) => e,
EntityType::XLine(e) => e,
EntityType::Viewport(e) => e,
EntityType::AttributeDefinition(e) => e,
EntityType::AttributeEntity(e) => e,
EntityType::Leader(e) => e,
EntityType::MultiLeader(e) => e,
EntityType::MLine(e) => e,
EntityType::Mesh(e) => e,
EntityType::RasterImage(e) => e,
EntityType::Solid3D(e) => e,
EntityType::Region(e) => e,
EntityType::Body(e) => e,
EntityType::Table(e) => e,
EntityType::Tolerance(e) => e,
EntityType::PolyfaceMesh(e) => e,
EntityType::Wipeout(e) => e,
EntityType::Shape(e) => e,
EntityType::Underlay(e) => e,
EntityType::Seqend(e) => e,
EntityType::Ole2Frame(e) => e,
EntityType::PolygonMesh(e) => e,
EntityType::Unknown(e) => e,
}
}
pub fn as_entity_mut(&mut self) -> &mut dyn Entity {
match self {
EntityType::Point(e) => e,
EntityType::Line(e) => e,
EntityType::Circle(e) => e,
EntityType::Arc(e) => e,
EntityType::Ellipse(e) => e,
EntityType::Polyline(e) => e,
EntityType::Polyline2D(e) => e,
EntityType::Polyline3D(e) => e,
EntityType::LwPolyline(e) => e,
EntityType::MText(e) => e,
EntityType::Text(e) => e,
EntityType::Spline(e) => e,
EntityType::Dimension(e) => e,
EntityType::Hatch(e) => e,
EntityType::Solid(e) => e,
EntityType::Face3D(e) => e,
EntityType::Insert(e) => e,
EntityType::Block(e) => e,
EntityType::BlockEnd(e) => e,
EntityType::Ray(e) => e,
EntityType::XLine(e) => e,
EntityType::Viewport(e) => e,
EntityType::AttributeDefinition(e) => e,
EntityType::AttributeEntity(e) => e,
EntityType::Leader(e) => e,
EntityType::MultiLeader(e) => e,
EntityType::MLine(e) => e,
EntityType::Mesh(e) => e,
EntityType::RasterImage(e) => e,
EntityType::Solid3D(e) => e,
EntityType::Region(e) => e,
EntityType::Body(e) => e,
EntityType::Table(e) => e,
EntityType::Tolerance(e) => e,
EntityType::PolyfaceMesh(e) => e,
EntityType::Wipeout(e) => e,
EntityType::Shape(e) => e,
EntityType::Underlay(e) => e,
EntityType::Seqend(e) => e,
EntityType::Ole2Frame(e) => e,
EntityType::PolygonMesh(e) => e,
EntityType::Unknown(e) => e,
}
}
pub fn common(&self) -> &EntityCommon {
match self {
EntityType::Point(e) => &e.common,
EntityType::Line(e) => &e.common,
EntityType::Circle(e) => &e.common,
EntityType::Arc(e) => &e.common,
EntityType::Ellipse(e) => &e.common,
EntityType::Polyline(e) => &e.common,
EntityType::Polyline2D(e) => &e.common,
EntityType::Polyline3D(e) => &e.common,
EntityType::LwPolyline(e) => &e.common,
EntityType::Text(e) => &e.common,
EntityType::MText(e) => &e.common,
EntityType::Spline(e) => &e.common,
EntityType::Dimension(e) => &e.base().common,
EntityType::Hatch(e) => &e.common,
EntityType::Solid(e) => &e.common,
EntityType::Face3D(e) => &e.common,
EntityType::Insert(e) => &e.common,
EntityType::Block(e) => &e.common,
EntityType::BlockEnd(e) => &e.common,
EntityType::Ray(e) => &e.common,
EntityType::XLine(e) => &e.common,
EntityType::Viewport(e) => &e.common,
EntityType::AttributeDefinition(e) => &e.common,
EntityType::AttributeEntity(e) => &e.common,
EntityType::Leader(e) => &e.common,
EntityType::MultiLeader(e) => &e.common,
EntityType::MLine(e) => &e.common,
EntityType::Mesh(e) => &e.common,
EntityType::RasterImage(e) => &e.common,
EntityType::Solid3D(e) => &e.common,
EntityType::Region(e) => &e.common,
EntityType::Body(e) => &e.common,
EntityType::Table(e) => &e.common,
EntityType::Tolerance(e) => &e.common,
EntityType::PolyfaceMesh(e) => &e.common,
EntityType::Wipeout(e) => &e.common,
EntityType::Shape(e) => &e.common,
EntityType::Underlay(e) => &e.common,
EntityType::Seqend(e) => &e.common,
EntityType::Ole2Frame(e) => &e.common,
EntityType::PolygonMesh(e) => &e.common,
EntityType::Unknown(e) => &e.common,
}
}
pub fn common_mut(&mut self) -> &mut EntityCommon {
match self {
EntityType::Point(e) => &mut e.common,
EntityType::Line(e) => &mut e.common,
EntityType::Circle(e) => &mut e.common,
EntityType::Arc(e) => &mut e.common,
EntityType::Ellipse(e) => &mut e.common,
EntityType::Polyline(e) => &mut e.common,
EntityType::Polyline2D(e) => &mut e.common,
EntityType::Polyline3D(e) => &mut e.common,
EntityType::LwPolyline(e) => &mut e.common,
EntityType::Text(e) => &mut e.common,
EntityType::MText(e) => &mut e.common,
EntityType::Spline(e) => &mut e.common,
EntityType::Dimension(e) => &mut e.base_mut().common,
EntityType::Hatch(e) => &mut e.common,
EntityType::Solid(e) => &mut e.common,
EntityType::Face3D(e) => &mut e.common,
EntityType::Insert(e) => &mut e.common,
EntityType::Block(e) => &mut e.common,
EntityType::BlockEnd(e) => &mut e.common,
EntityType::Ray(e) => &mut e.common,
EntityType::XLine(e) => &mut e.common,
EntityType::Viewport(e) => &mut e.common,
EntityType::AttributeDefinition(e) => &mut e.common,
EntityType::AttributeEntity(e) => &mut e.common,
EntityType::Leader(e) => &mut e.common,
EntityType::MultiLeader(e) => &mut e.common,
EntityType::MLine(e) => &mut e.common,
EntityType::Mesh(e) => &mut e.common,
EntityType::RasterImage(e) => &mut e.common,
EntityType::Solid3D(e) => &mut e.common,
EntityType::Region(e) => &mut e.common,
EntityType::Body(e) => &mut e.common,
EntityType::Table(e) => &mut e.common,
EntityType::Tolerance(e) => &mut e.common,
EntityType::PolyfaceMesh(e) => &mut e.common,
EntityType::Wipeout(e) => &mut e.common,
EntityType::Shape(e) => &mut e.common,
EntityType::Underlay(e) => &mut e.common,
EntityType::Seqend(e) => &mut e.common,
EntityType::Ole2Frame(e) => &mut e.common,
EntityType::PolygonMesh(e) => &mut e.common,
EntityType::Unknown(e) => &mut e.common,
}
}
}