//! Graphical entity types.
//!
//! This module contains all 41 supported CAD entity types — from simple
//! primitives ([`Line`], [`Circle`], [`Arc`]) through complex objects
//! ([`Hatch`], [`Spline`], [`MultiLeader`], [`Mesh`]).
//!
//! Every entity carries [`EntityCommon`] data (layer, color, line weight,
//! handle, etc.) alongside its type-specific fields.
//!
//! Entities are stored in [`CadDocument`](crate::document::CadDocument) and
//! wrapped in the [`EntityType`] enum for heterogeneous collections.

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 mtext_format;
pub mod spline;
pub mod helix;
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 surface;
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, MTextColumnData, AttachmentPoint, DrawingDirection};
pub use spline::{Spline, SplineFlags};
pub use helix::{Helix, HelixConstraint};
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 surface::{Surface, SurfaceKind};
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;

/// Base trait for all CAD entities
pub trait Entity {
    /// Get the entity's unique handle
    fn handle(&self) -> Handle;

    /// Set the entity's handle
    fn set_handle(&mut self, handle: Handle);

    /// Get the entity's layer name
    fn layer(&self) -> &str;

    /// Set the entity's layer name
    fn set_layer(&mut self, layer: String);

    /// Get the entity's color
    fn color(&self) -> Color;

    /// Set the entity's color
    fn set_color(&mut self, color: Color);

    /// Get the entity's line weight
    fn line_weight(&self) -> LineWeight;

    /// Set the entity's line weight
    fn set_line_weight(&mut self, weight: LineWeight);

    /// Get the entity's transparency
    fn transparency(&self) -> Transparency;

    /// Set the entity's transparency
    fn set_transparency(&mut self, transparency: Transparency);

    /// Check if the entity is invisible
    fn is_invisible(&self) -> bool;

    /// Set the entity's visibility
    fn set_invisible(&mut self, invisible: bool);

    /// Get the bounding box of the entity
    fn bounding_box(&self) -> BoundingBox3D;

    /// Transform the entity by a translation vector
    fn translate(&mut self, offset: Vector3);

    /// Get the entity type name
    fn entity_type(&self) -> &'static str;
    
    /// Apply a general transform to the entity
    /// 
    /// This is the main transformation method. Default implementation
    /// only supports translation for backward compatibility.
    fn apply_transform(&mut self, transform: &Transform) {
        // Default: extract translation and apply
        let origin = Vector3::ZERO;
        let translated = transform.apply(origin);
        self.translate(translated);
    }
    
    /// Apply rotation around an axis
    fn apply_rotation(&mut self, axis: Vector3, angle: f64) {
        self.apply_transform(&Transform::from_rotation(axis, angle));
    }
    
    /// Apply uniform scaling
    fn apply_scaling(&mut self, scale: f64) {
        self.apply_transform(&Transform::from_scale(scale));
    }
    
    /// Apply non-uniform scaling
    fn apply_scaling_xyz(&mut self, scale: Vector3) {
        self.apply_transform(&Transform::from_scaling(scale));
    }
    
    /// Apply scaling with a specific origin point
    fn apply_scaling_with_origin(&mut self, scale: Vector3, origin: Vector3) {
        self.apply_transform(&Transform::from_scaling_with_origin(scale, origin));
    }
    
    /// Apply a mirror transform with entity-specific corrections
    ///
    /// Override this for entities that need post-processing after mirroring
    /// (e.g., arc angle swaps, bulge negation, face winding reversal).
    fn apply_mirror(&mut self, transform: &Transform) {
        self.apply_transform(transform);
    }
    
    /// Mirror the entity across the YZ plane (negate X coordinates)
    fn mirror_x(&mut self) {
        self.apply_mirror(&Transform::from_mirror_x());
    }
    
    /// Mirror the entity across the XZ plane (negate Y coordinates)
    fn mirror_y(&mut self) {
        self.apply_mirror(&Transform::from_mirror_y());
    }
    
    /// Mirror the entity across the XY plane (negate Z coordinates)
    fn mirror_z(&mut self) {
        self.apply_mirror(&Transform::from_mirror_z());
    }
    
    /// Mirror the entity across a line defined by two points (in the XY plane)
    fn mirror_about_line(&mut self, p1: Vector3, p2: Vector3) {
        self.apply_mirror(&Transform::from_mirror_line(p1, p2));
    }
    
    /// Mirror the entity across an arbitrary plane
    fn mirror_about_plane(&mut self, point: Vector3, normal: Vector3) {
        self.apply_mirror(&Transform::from_mirror_plane(point, normal));
    }
}

/// Common entity data shared by all entities
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EntityCommon {
    /// Unique handle
    pub handle: Handle,
    /// Layer name
    pub layer: String,
    /// Color
    pub color: Color,
    /// Line weight
    pub line_weight: LineWeight,
    /// Linetype name (empty string = "ByLayer")
    pub linetype: String,
    /// Linetype scale factor (default 1.0)
    pub linetype_scale: f64,
    /// Transparency
    pub transparency: Transparency,
    /// Visibility flag
    pub invisible: bool,
    /// Extended data (XDATA)
    pub extended_data: crate::xdata::ExtendedData,
    /// Raw entity graphic data bytes (stored for DWG round-trip; None otherwise).
    #[cfg_attr(feature = "serde", serde(skip))]
    pub graphic_data: Option<Vec<u8>>,
    /// Reactor handles — objects attached as reactors ({ACAD_REACTORS})
    pub reactors: Vec<Handle>,
    /// Extended dictionary handle ({ACAD_XDICTIONARY}) — hard-owner handle to a Dictionary
    pub xdictionary_handle: Option<Handle>,
    /// Owner handle (soft pointer, code 330)
    pub owner_handle: Handle,

    // ── DWG round-trip fields (not exposed via DXF) ──
    /// Material flags (BB: 00=bylayer, 01=byblock, 10=reserved, 11=handle) — R2007+
    #[cfg_attr(feature = "serde", serde(skip))]
    pub material_flags: u8,
    /// Material handle (only valid when material_flags == 0b11) — R2007+
    #[cfg_attr(feature = "serde", serde(skip))]
    pub material_handle: Option<Handle>,
    /// Shadow flags (RC) — R2007+
    #[cfg_attr(feature = "serde", serde(skip))]
    pub shadow_flags: u8,
    /// Plotstyle flags (BB: 00=bylayer, 01=byblock, 10=reserved, 11=handle) — R2000+
    #[cfg_attr(feature = "serde", serde(skip))]
    pub plotstyle_flags: u8,
    /// Plotstyle handle (only valid when plotstyle_flags == 0b11) — R2000+
    #[cfg_attr(feature = "serde", serde(skip))]
    pub plotstyle_handle: Option<Handle>,
    /// Entity mode (0=owned, 1=paper, 2=model) — raw DWG value for round-trip
    #[cfg_attr(feature = "serde", serde(skip))]
    pub entity_mode: Option<u8>,
    /// R2013+ `has_ds_data` bit: the entity's modeler geometry (3DSOLID/REGION/
    /// BODY/SURFACE) is stored as a SAB blob in the `AcDb:AcDsPrototype_1b`
    /// data-store section rather than inline. Set by the DWG reader; the writer
    /// re-derives it from the presence of ACIS data. Not part of the logical
    /// model, so skipped for serde.
    #[cfg_attr(feature = "serde", serde(skip))]
    pub has_ds_data: bool,
}

impl EntityCommon {
    /// Create new common entity data with defaults
    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(),
            graphic_data: None,
            reactors: Vec::new(),
            xdictionary_handle: None,
            owner_handle: Handle::NULL,
            material_flags: 0,
            material_handle: None,
            shadow_flags: 0,
            plotstyle_flags: 0,
            plotstyle_handle: None,
            entity_mode: None,
            has_ds_data: false,
        }
    }

    /// Create with a specific layer
    pub fn with_layer(layer: impl Into<String>) -> Self {
        EntityCommon {
            layer: layer.into(),
            ..Self::new()
        }
    }

    /// Check whether a linetype name is set (not empty and not "ByLayer")
    pub fn has_linetype(&self) -> bool {
        !self.linetype.is_empty() && self.linetype != "ByLayer"
    }
}

impl Default for EntityCommon {
    fn default() -> Self {
        Self::new()
    }
}

/// Enumeration of all entity types for type-safe storage
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EntityType {
    /// Point entity
    Point(Point),
    /// Line entity
    Line(Line),
    /// Circle entity
    Circle(Circle),
    /// Arc entity
    Arc(Arc),
    /// Ellipse entity
    Ellipse(Ellipse),
    /// 3D Polyline entity
    Polyline(Polyline),
    /// 2D Polyline entity (heavy polyline)
    Polyline2D(Polyline2D),
    /// 3D Polyline entity (new style)
    Polyline3D(Polyline3D),
    /// Lightweight polyline entity
    LwPolyline(LwPolyline),
    /// Text entity
    Text(Text),
    /// Multi-line text entity
    MText(MText),
    /// Spline entity
    Spline(Spline),
    /// Helix entity (spline-derived 3D spiral)
    Helix(Helix),
    /// Dimension entity
    Dimension(Dimension),
    /// Hatch entity
    Hatch(Hatch),
    /// Solid entity
    Solid(Solid),
    /// 3D Face entity
    Face3D(Face3D),
    /// Insert entity (block reference)
    Insert(Insert),
    /// Block entity (block definition start)
    Block(Block),
    /// BlockEnd entity (block definition end)
    BlockEnd(BlockEnd),
    /// Ray entity (semi-infinite line)
    Ray(Ray),
    /// XLine entity (construction line, infinite)
    XLine(XLine),
    /// Viewport entity (paper space viewport)
    Viewport(Viewport),
    /// Attribute definition entity
    AttributeDefinition(AttributeDefinition),
    /// Attribute entity (block attribute instance)
    AttributeEntity(AttributeEntity),
    /// Leader entity
    Leader(Leader),
    /// MultiLeader entity
    MultiLeader(MultiLeader),
    /// MLine (multiline) entity
    MLine(MLine),
    /// Mesh entity
    Mesh(Mesh),
    /// RasterImage entity
    RasterImage(RasterImage),
    /// Solid3D entity
    Solid3D(Solid3D),
    /// Region entity
    Region(Region),
    /// Body entity
    Body(Body),
    /// Surface entity (ACAD_SURFACE family: lofted/swept/extruded/etc.)
    Surface(Surface),
    /// Table entity
    Table(Table),
    /// Tolerance entity (geometric tolerancing)
    Tolerance(Tolerance),
    /// PolyfaceMesh entity
    PolyfaceMesh(PolyfaceMesh),
    /// Wipeout entity
    Wipeout(Wipeout),
    /// Shape entity
    Shape(Shape),
    /// Underlay entity (PDF, DWF, DGN)
    Underlay(Underlay),
    /// End-of-sequence marker
    Seqend(Seqend),
    /// OLE2 embedded object
    Ole2Frame(Ole2Frame),
    /// Polygon mesh (3D surface mesh)
    PolygonMesh(PolygonMeshEntity),
    /// Unknown / unsupported entity type (common fields only)
    Unknown(UnknownEntity),
}

impl EntityType {
    /// Get a reference to the entity trait object
    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::Helix(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::Surface(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,
        }
    }

    /// Get a mutable reference to the entity trait object
    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::Helix(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::Surface(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,
        }
    }

    /// Get a reference to the entity's common data
    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::Helix(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::Surface(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,
        }
    }

    /// Get a mutable reference to the entity's common data
    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::Helix(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::Surface(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,
        }
    }
}

