-
-
Save DGriffin91/77390c206a841fc9b87ab0a11df152d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use dxf::entities::*; | |
use dxf::Drawing; | |
#[derive(Debug, Clone)] | |
pub struct DAngularThreePointDimension { | |
pub dxf: AngularThreePointDimension, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DArc { | |
pub dxf: Arc, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DArcAlignedText { | |
pub dxf: ArcAlignedText, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DAttribute { | |
pub dxf: Attribute, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DAttributeDefinition { | |
pub dxf: AttributeDefinition, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DBody { | |
pub dxf: Body, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DCircle { | |
pub dxf: Circle, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DDgnUnderlay { | |
pub dxf: DgnUnderlay, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DDiameterDimension { | |
pub dxf: DiameterDimension, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DDwfUnderlay { | |
pub dxf: DwfUnderlay, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DEllipse { | |
pub dxf: Ellipse, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DFace3D { | |
pub dxf: Face3D, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DHelix { | |
pub dxf: Helix, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DImage { | |
pub dxf: Image, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DInsert { | |
pub dxf: Insert, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DLeader { | |
pub dxf: Leader, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DLight { | |
pub dxf: Light, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DLine { | |
pub dxf: Line, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DLwPolyline { | |
pub dxf: LwPolyline, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DMLine { | |
pub dxf: MLine, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DMText { | |
pub dxf: MText, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DModelPoint { | |
pub dxf: ModelPoint, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DOle2Frame { | |
pub dxf: Ole2Frame, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DOleFrame { | |
pub dxf: OleFrame, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DOrdinateDimension { | |
pub dxf: OrdinateDimension, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DPdfUnderlay { | |
pub dxf: PdfUnderlay, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DPolyline { | |
pub dxf: Polyline, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DProxyEntity { | |
pub dxf: ProxyEntity, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DRText { | |
pub dxf: RText, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DRadialDimension { | |
pub dxf: RadialDimension, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DRay { | |
pub dxf: Ray, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DRegion { | |
pub dxf: Region, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DRotatedDimension { | |
pub dxf: RotatedDimension, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DSection { | |
pub dxf: Section, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DSeqend { | |
pub dxf: Seqend, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DShape { | |
pub dxf: Shape, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DSolid { | |
pub dxf: Solid, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DSolid3D { | |
pub dxf: Solid3D, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DSpline { | |
pub dxf: Spline, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DText { | |
pub dxf: Text, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DTolerance { | |
pub dxf: Tolerance, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DTrace { | |
pub dxf: Trace, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DVertex { | |
pub dxf: Vertex, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DWipeout { | |
pub dxf: Wipeout, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub struct DXLine { | |
pub dxf: XLine, | |
pub common: EntityCommon, | |
} | |
#[derive(Debug, Clone)] | |
pub enum DEntity { | |
DAngularThreePointDimension(DAngularThreePointDimension), | |
DArc(DArc), | |
DArcAlignedText(DArcAlignedText), | |
DAttribute(DAttribute), | |
DAttributeDefinition(DAttributeDefinition), | |
DBody(DBody), | |
DCircle(DCircle), | |
DDgnUnderlay(DDgnUnderlay), | |
DDiameterDimension(DDiameterDimension), | |
DDwfUnderlay(DDwfUnderlay), | |
DEllipse(DEllipse), | |
DFace3D(DFace3D), | |
DHelix(DHelix), | |
DImage(DImage), | |
DInsert(DInsert), | |
DLeader(DLeader), | |
DLight(DLight), | |
DLine(DLine), | |
DLwPolyline(DLwPolyline), | |
DMLine(DMLine), | |
DMText(DMText), | |
DModelPoint(DModelPoint), | |
DOle2Frame(DOle2Frame), | |
DOleFrame(DOleFrame), | |
DOrdinateDimension(DOrdinateDimension), | |
DPdfUnderlay(DPdfUnderlay), | |
DPolyline(DPolyline), | |
DProxyEntity(DProxyEntity), | |
DRText(DRText), | |
DRadialDimension(DRadialDimension), | |
DRay(DRay), | |
DRegion(DRegion), | |
DRotatedDimension(DRotatedDimension), | |
DSection(DSection), | |
DSeqend(DSeqend), | |
DShape(DShape), | |
DSolid(DSolid), | |
DSolid3D(DSolid3D), | |
DSpline(DSpline), | |
DText(DText), | |
DTolerance(DTolerance), | |
DTrace(DTrace), | |
DVertex(DVertex), | |
DWipeout(DWipeout), | |
DXLine(DXLine), | |
} | |
pub fn convert_entity(entity: Entity) -> DEntity { | |
match entity.specific { | |
EntityType::AngularThreePointDimension(specific) => { | |
DEntity::DAngularThreePointDimension(DAngularThreePointDimension { | |
dxf: specific, | |
common: entity.common, | |
}) | |
} | |
EntityType::Arc(specific) => DEntity::DArc(DArc { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::ArcAlignedText(specific) => DEntity::DArcAlignedText(DArcAlignedText { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Attribute(specific) => DEntity::DAttribute(DAttribute { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::AttributeDefinition(specific) => { | |
DEntity::DAttributeDefinition(DAttributeDefinition { | |
dxf: specific, | |
common: entity.common, | |
}) | |
} | |
EntityType::Body(specific) => DEntity::DBody(DBody { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Circle(specific) => DEntity::DCircle(DCircle { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::DgnUnderlay(specific) => DEntity::DDgnUnderlay(DDgnUnderlay { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::DiameterDimension(specific) => { | |
DEntity::DDiameterDimension(DDiameterDimension { | |
dxf: specific, | |
common: entity.common, | |
}) | |
} | |
EntityType::DwfUnderlay(specific) => DEntity::DDwfUnderlay(DDwfUnderlay { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Ellipse(specific) => DEntity::DEllipse(DEllipse { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Face3D(specific) => DEntity::DFace3D(DFace3D { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Helix(specific) => DEntity::DHelix(DHelix { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Image(specific) => DEntity::DImage(DImage { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Insert(specific) => DEntity::DInsert(DInsert { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Leader(specific) => DEntity::DLeader(DLeader { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Light(specific) => DEntity::DLight(DLight { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Line(specific) => DEntity::DLine(DLine { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::LwPolyline(specific) => DEntity::DLwPolyline(DLwPolyline { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::MLine(specific) => DEntity::DMLine(DMLine { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::MText(specific) => DEntity::DMText(DMText { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::ModelPoint(specific) => DEntity::DModelPoint(DModelPoint { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Ole2Frame(specific) => DEntity::DOle2Frame(DOle2Frame { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::OleFrame(specific) => DEntity::DOleFrame(DOleFrame { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::OrdinateDimension(specific) => { | |
DEntity::DOrdinateDimension(DOrdinateDimension { | |
dxf: specific, | |
common: entity.common, | |
}) | |
} | |
EntityType::PdfUnderlay(specific) => DEntity::DPdfUnderlay(DPdfUnderlay { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Polyline(specific) => DEntity::DPolyline(DPolyline { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::ProxyEntity(specific) => DEntity::DProxyEntity(DProxyEntity { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::RText(specific) => DEntity::DRText(DRText { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::RadialDimension(specific) => DEntity::DRadialDimension(DRadialDimension { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Ray(specific) => DEntity::DRay(DRay { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Region(specific) => DEntity::DRegion(DRegion { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::RotatedDimension(specific) => DEntity::DRotatedDimension(DRotatedDimension { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Section(specific) => DEntity::DSection(DSection { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Seqend(specific) => DEntity::DSeqend(DSeqend { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Shape(specific) => DEntity::DShape(DShape { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Solid(specific) => DEntity::DSolid(DSolid { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Solid3D(specific) => DEntity::DSolid3D(DSolid3D { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Spline(specific) => DEntity::DSpline(DSpline { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Text(specific) => DEntity::DText(DText { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Tolerance(specific) => DEntity::DTolerance(DTolerance { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Trace(specific) => DEntity::DTrace(DTrace { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Vertex(specific) => DEntity::DVertex(DVertex { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::Wipeout(specific) => DEntity::DWipeout(DWipeout { | |
dxf: specific, | |
common: entity.common, | |
}), | |
EntityType::XLine(specific) => DEntity::DXLine(DXLine { | |
dxf: specific, | |
common: entity.common, | |
}), | |
} | |
} | |
pub fn convert_entities(dwg: &Drawing) -> Vec<DEntity> { | |
let mut dentities = Vec::new(); | |
for entity in dwg.entities() { | |
dentities.push(convert_entity(entity.clone())); | |
} | |
dentities | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
use std::time::Instant; | |
#[test] | |
fn test_extract_text() { | |
let dwg = | |
Drawing::load_file("./resources/CCLVSingleLines2013.dxf").expect("ERROR LOADING FILE"); | |
let start = Instant::now(); | |
let entities = convert_entities(&dwg); | |
let elapsed = start.elapsed(); | |
println!("convert_entities: {:?}", elapsed); | |
//dbg!(entities); | |
//for entity in entities.iter() {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment