From 2e6732f59c95355e648285677bb585e53a65c5f0 Mon Sep 17 00:00:00 2001 From: Antonio Date: Sun, 17 Jul 2022 20:54:51 -0400 Subject: [PATCH] initial commit --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 2 + Cargo.lock | 549 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 14 ++ src/main.rs | 232 ++++++++++++++++++++++ 5 files changed, 797 insertions(+) create mode 100644 .DS_Store create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d6524194fca186588e7cc75e916a3a21fab9aa03 GIT binary patch literal 6148 zcmeHKL2uJA6n<{YnlgcU0K^5!64z=B7}F*$p(_Wj1i=ANN!l=?W%1Oc^iWmG5q=Ff zehUAE6MVMcCPE8Ggy22N{_N-X+45({j)_PO=hM4HeIg2wEVg>cHkfUnDO z!_W@pWN1PsYtiEP8x^o?cbSeTrWqY$VJ_tC7#O#vP4Hz_6xhytR(Mg{nM2(~x2ic=I2 z1^#CR?D?RPEQXA=M|X4}b58(Z2X1F5+qZ<}XvUDS_J|gk@>HOwDt=-pPlsP~T*z2^ z^mJ1E_)t8u;unf?qoaTA!byc5B^L!mfu;g&U+vrb|M9Qi|4owAL;+FYpHe_|M$u@9 zDe>L9HaUCOYNR(v)@)qu@q&VayNVHOui~3X&fwR!01O#xkMO|cN5IJ-nJDl_75EO~ C%8H=? literal 0 HcmV?d00001 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73bbc30 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Dockerfile \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..1c9845a --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,549 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "adler32" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bytemuck" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c53dfa917ec274df8ed3c572698f381a24eef2efba9492d797301b72b6db408a" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits 0.2.15", + "serde", + "time", + "winapi", +] + +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c02a4d71819009c192cf4872265391563fd6a84c81ff2c0f2a7026ca4c1d85c" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07db9d94cbd326813772c968ccd25999e5f8ae22f4f8d1b11effa37ef6ce281d" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "once_cell", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "deflate" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174" +dependencies = [ + "adler32", + "byteorder", +] + +[[package]] +name = "dxf" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea9003fc9926c63a280a37f9b0ea318cc40a5da4f8ca0025beae8f4ff22082e2" +dependencies = [ + "byteorder", + "chrono", + "encoding_rs", + "enum_primitive", + "image", + "itertools", + "num", + "uuid", + "xmltree", +] + +[[package]] +name = "dxf2elmt" +version = "0.1.0" +dependencies = [ + "dxf", + "simple-xml-builder", +] + +[[package]] +name = "either" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" + +[[package]] +name = "encoding_rs" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "enum_primitive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4551092f4d519593039259a9ed8daedf0da12e5109c5280338073eaeb81180" +dependencies = [ + "num-traits 0.1.43", +] + +[[package]] +name = "getrandom" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "gif" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3edd93c6756b4dfaf2709eafcc345ba2636565295c198a9cfbf75fa5e3e00b06" +dependencies = [ + "color_quant", + "weezl", +] + +[[package]] +name = "hashbrown" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "image" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1" +dependencies = [ + "bytemuck", + "byteorder", + "color_quant", + "gif", + "jpeg-decoder", + "num-iter", + "num-rational", + "num-traits 0.2.15", + "png", + "scoped_threadpool", + "tiff", +] + +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + +[[package]] +name = "jpeg-decoder" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2" +dependencies = [ + "rayon", +] + +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "miniz_oxide" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" +dependencies = [ + "adler32", +] + +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + +[[package]] +name = "num" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b7a8e9be5e039e2ff869df49155f1c06bd01ade2117ec783e56ab0932b67a8f" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits 0.2.15", +] + +[[package]] +name = "num-bigint" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" +dependencies = [ + "autocfg", + "num-integer", + "num-traits 0.2.15", +] + +[[package]] +name = "num-complex" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747d632c0c558b87dbabbe6a82f3b4ae03720d0646ac5b7b4dae89394be5f2c5" +dependencies = [ + "num-traits 0.2.15", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits 0.2.15", +] + +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits 0.2.15", +] + +[[package]] +name = "num-rational" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits 0.2.15", +] + +[[package]] +name = "num-traits" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" +dependencies = [ + "num-traits 0.2.15", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" + +[[package]] +name = "png" +version = "0.16.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" +dependencies = [ + "bitflags", + "crc32fast", + "deflate", + "miniz_oxide 0.3.7", +] + +[[package]] +name = "rayon" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + +[[package]] +name = "scoped_threadpool" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "serde" +version = "1.0.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" + +[[package]] +name = "simple-xml-builder" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a50cb1e76f89e3c076f7ae0a609c4b0033c26034f740eddbeb761b64b2f42980" +dependencies = [ + "indexmap", +] + +[[package]] +name = "tiff" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437" +dependencies = [ + "jpeg-decoder", + "miniz_oxide 0.4.4", + "weezl", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom", + "serde", +] + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "weezl" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "xml-rs" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c1cb601d29fe2c2ac60a2b2e5e293994d87a1f6fa9687a31a15270f909be9c2" +dependencies = [ + "bitflags", +] + +[[package]] +name = "xmltree" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff8eaee9d17062850f1e6163b509947969242990ee59a35801af437abe041e70" +dependencies = [ + "xml-rs", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..17ad53d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "dxf2elmt" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[profile.release] +strip = true # Automatically strip symbols from the binary. +lto = true + +[dependencies] +dxf = "0.5.0" +simple-xml-builder = "1.1.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..9511c2b --- /dev/null +++ b/src/main.rs @@ -0,0 +1,232 @@ +extern crate dxf; +extern crate simple_xml_builder; + +use std::fs::File; +use dxf::Drawing; +use dxf::entities::*; +use simple_xml_builder::*; +use std::time::*; +use std::env; + +fn main() -> dxf::DxfResult<()>{ + // Start recording time + let now = Instant::now(); + + // Collect file name argument + let args: Vec = env::args().collect(); + let file_name: &str = &format!("{}",args[1]); + + // Load dxf file + let drawing = Drawing::load_file(file_name)?; + println!("{} loaded...", file_name); + + // Intialize counts + let mut circle_count = 0; + let mut line_count = 0; + let mut arc_count = 0; + //let mut spline_count = 0; **TODO** + let mut text_count = 0; + let mut ellipse_count = 0; + let mut polyline_count = 0; + //let mut lwpolyline_count = 0; **TODO** + //let mut solid_count = 0; **TODO** + let mut other_count = 0; + let mut _temp = 0.0; + + // Create output file for .elmt + let mut out_file = File::create(format!("{}.elmt", &file_name[0..file_name.len() - 4])).unwrap(); + println!("{}.elmt was created... \nNow converting {}...", &file_name[0..file_name.len() - 4], file_name); + + // Definition defintion ;) + let mut definition = XMLElement::new("definition"); + definition.add_attribute("height", 10); + definition.add_attribute("width", 10); + definition.add_attribute("hotspot_x", 0); + definition.add_attribute("hotspot_y", 0); + definition.add_attribute("version", "0.80"); + definition.add_attribute("link_type", "simple"); + definition.add_attribute("type", "element"); + + // Define names + let mut names = XMLElement::new("names"); + let mut name = XMLElement::new("name"); + name.add_attribute("lang", "en"); + name.add_text(format!("{}", &file_name[0..file_name.len() - 4])); + names.add_child(name); + definition.add_child(names); + + // Define information + let mut information = XMLElement::new("informations"); + information.add_text("Created using dxf2elmt!"); + definition.add_child(information); + + // Start description + let mut description = XMLElement::new("description"); + + // Loop through all entities, appending to xml file + for e in drawing.entities() { + match e.specific { + EntityType::Circle(ref circle) => { + let mut circle_xml = XMLElement::new("ellipse"); + circle_xml.add_attribute("x", circle.center.x - circle.radius); + circle_xml.add_attribute("y", -circle.center.y - circle.radius); + circle_xml.add_attribute("height", circle.radius * 2.0); + circle_xml.add_attribute("width", circle.radius * 2.0); + circle_xml.add_attribute("antialias", "false"); + + if circle.thickness > 0.5{ + circle_xml.add_attribute("style", "line-style:normal;line-weight:normal;filling:none;color:black"); + }else{ + circle_xml.add_attribute("style", "line-style:normal;line-weight:thin;filling:none;color:black"); + } + description.add_child(circle_xml); + + circle_count += 1; + }, + EntityType::Line(ref line) => { + let mut line_xml = XMLElement::new("line"); + line_xml.add_attribute("x1", line.p1.x); + line_xml.add_attribute("y1", -line.p1.y); + line_xml.add_attribute("length1", 1.5); + line_xml.add_attribute("end1", "none"); + line_xml.add_attribute("x2", line.p2.x); + line_xml.add_attribute("y2", -line.p2.y); + line_xml.add_attribute("length2", 1.5); + line_xml.add_attribute("end2", "none"); + line_xml.add_attribute("antialias", "false"); + + if line.thickness > 0.5{ + line_xml.add_attribute("style", "line-style:normal;line-weight:normal;filling:none;color:black"); + }else{ + line_xml.add_attribute("style", "line-style:normal;line-weight:thin;filling:none;color:black"); + } + description.add_child(line_xml); + + line_count += 1; + }, + EntityType::Arc(ref arc)=> { + let mut arc_xml = XMLElement::new("arc"); + arc_xml.add_attribute("x", arc.center.x - arc.radius); + arc_xml.add_attribute("y", -arc.center.y - arc.radius); + arc_xml.add_attribute("width", arc.radius*2.0); + arc_xml.add_attribute("height", arc.radius*2.0); + + if arc.start_angle < 0.0{ + arc_xml.add_attribute("start", -arc.start_angle); + }else{ + arc_xml.add_attribute("start", arc.start_angle); + } + + if arc.start_angle > arc.end_angle{ + _temp = (360.0 - arc.start_angle) + arc.end_angle; + }else{ + _temp = arc.end_angle - arc.start_angle; + } + if _temp < 0.0{ + arc_xml.add_attribute("angle", -_temp); + }else{ + arc_xml.add_attribute("angle", _temp); + } + + arc_xml.add_attribute("antialias", "false"); + if arc.thickness > 0.1{ + arc_xml.add_attribute("style", "line-style:normal;line-weight:normal;filling:none;color:black"); + }else{ + arc_xml.add_attribute("style", "line-style:normal;line-weight:thin;filling:none;color:black"); + } + description.add_child(arc_xml); + arc_count += 1; + } + // **TODO** + // EntityType::Spline(ref spline)=> { + // spline_count += 1; + // } + EntityType::Text(ref text)=> { + let mut text_xml = XMLElement::new("text"); + text_xml.add_attribute("x", text.location.x); + text_xml.add_attribute("y", -text.location.y); + text_xml.add_attribute("rotation", 0); + text_xml.add_attribute("text", &text.value[..]); + text_xml.add_attribute("font", format!("American Typewriter,{},-1,5,0,0,0,0,0,0,normal", text.text_height.ceil())); + text_xml.add_attribute("antialias", "false"); + if text.thickness > 0.5{ + text_xml.add_attribute("style", "line-style:normal;line-weight:normal;filling:none;color:black"); + }else{ + text_xml.add_attribute("style", "line-style:normal;line-weight:thin;filling:none;color:black"); + } + description.add_child(text_xml); + text_count += 1; + } + EntityType::Ellipse(ref ellipse)=> { + let mut ellipse_xml = XMLElement::new("ellipse"); + ellipse_xml.add_attribute("x", ellipse.center.x - ellipse.major_axis.x); + ellipse_xml.add_attribute("y", -ellipse.center.y - ellipse.major_axis.x * ellipse.minor_axis_ratio); + ellipse_xml.add_attribute("height", ellipse.major_axis.x * 2.0); + ellipse_xml.add_attribute("width", ellipse.major_axis.x * 2.0 * ellipse.minor_axis_ratio); + ellipse_xml.add_attribute("antialias", "false"); + ellipse_xml.add_attribute("style", "line-style:normal;line-weight:thin;filling:none;color:black"); + + description.add_child(ellipse_xml); + + ellipse_count += 1; + } + EntityType::Polyline(ref polyline)=> { + let mut polyline_xml = XMLElement::new("polygon"); + + let mut j: usize = 0; + for _i in &polyline.__vertices_and_handles{ + polyline_xml.add_attribute(format!("x{}", (j+1)), polyline.__vertices_and_handles[j].0.location.x); + polyline_xml.add_attribute(format!("y{}", (j+1)), -polyline.__vertices_and_handles[j].0.location.y); + j += 1; + } + + polyline_xml.add_attribute("antialias", "false"); + if polyline.thickness > 0.1{ + polyline_xml.add_attribute("style", "line-style:normal;line-weight:normal;filling:none;color:black"); + }else{ + polyline_xml.add_attribute("style", "line-style:normal;line-weight:thin;filling:none;color:black"); + } + + description.add_child(polyline_xml); + + polyline_count += 1; + } + + // **TODO** + // EntityType::LwPolyline(ref lwpolyline)=> { + // lwpolyline_count += 1; + // } + // EntityType::Solid(ref solid)=> { + // solid_count += 1; + // } + + _ => { + other_count += 1; + }, + } + } + + // Write to output file + definition.add_child(description); + definition.write(&mut out_file)?; + + println!("Conversion complete!\n"); + + // Print stats + println!("STATS"); + println!("~~~~~~~~~~~~~~~"); + println!("Circles: {}", circle_count); + println!("Lines: {}", line_count); + println!("Arcs: {}", arc_count); + //println!("Splines: {}", spline_count); + println!("Texts: {}", text_count); + println!("Ellipses: {}", ellipse_count); + println!("Polylines: {}", polyline_count); + //println!("LwPolylines: {}", lwpolyline_count); + //println!("Solids: {}", solid_count); + println!("Currently Unsupported: {}", other_count); + + println!("\nTime Elapsed: {} ms",now.elapsed().as_millis()); + + Ok(()) +}