diff --git a/modeling-cmds/.github/codecov.yml b/.github/codecov.yml similarity index 100% rename from modeling-cmds/.github/codecov.yml rename to .github/codecov.yml diff --git a/modeling-cmds/.github/workflows/ci.yml b/.github/workflows/ci.yml similarity index 100% rename from modeling-cmds/.github/workflows/ci.yml rename to .github/workflows/ci.yml diff --git a/modeling-cmds/src/format.rs b/modeling-cmds/src/format.rs index 7e97e85e..7246797e 100644 --- a/modeling-cmds/src/format.rs +++ b/modeling-cmds/src/format.rs @@ -18,12 +18,14 @@ pub mod step; /// **ST**ereo**L**ithography format. pub mod stl; +/// SolidWorks part (SLDPRT) format. +pub mod sldprt; + /// Output format specifier. #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)] #[serde(tag = "type", rename_all = "snake_case")] #[display(style = "snake_case")] pub enum OutputFormat { - // TODO: Uncomment all these variants and support their options. /// Autodesk Filmbox (FBX) format. #[display("{}: {0}")] Fbx(fbx::export::Options), @@ -52,7 +54,6 @@ pub enum OutputFormat { #[serde(tag = "type", rename_all = "snake_case")] #[display(style = "snake_case")] pub enum InputFormat { - // TODO: Uncomment all these variants and support their options. /// Autodesk Filmbox (FBX) format. #[display("{}: {0}")] Fbx(fbx::import::Options), @@ -67,9 +68,9 @@ pub enum InputFormat { /// The PLY Polygon File Format. #[display("{}: {0}")] Ply(ply::import::Options), - // /// SolidWorks part (SLDPRT) format. - // #[display("{}: {0}")] - // Sldprt(sldprt::import::Options), + /// SolidWorks part (SLDPRT) format. + #[display("{}: {0}")] + Sldprt(sldprt::import::Options), /// ISO 10303-21 (STEP) format. #[display("{}: {0}")] Step(step::ImportOptions), @@ -115,3 +116,36 @@ pub enum Selection { name: String, }, } + +/// Represents an in-memory file with an associated potentially foreign file path. +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +pub struct VirtualFile { + /// Original file path. + pub path: std::path::PathBuf, + /// File payload. + pub data: Vec, +} + +impl VirtualFile { + /// Returns true if the file name has the given extension. + pub fn has_extension(&self, required_extension: &str) -> bool { + self.path + .extension() + .and_then(std::ffi::OsStr::to_str) + .map(|extension| extension.eq_ignore_ascii_case(required_extension)) + .unwrap_or(false) + } + + fn read_fs_impl(path: std::path::PathBuf) -> std::io::Result { + let data = std::fs::read(&path)?; + Ok(Self { path, data }) + } + + /// Read from file system. + pub fn read_fs

(path: P) -> std::io::Result + where + P: Into, + { + Self::read_fs_impl(path.into()) + } +} diff --git a/modeling-cmds/src/format/sldprt.rs b/modeling-cmds/src/format/sldprt.rs new file mode 100644 index 00000000..0bf13cc6 --- /dev/null +++ b/modeling-cmds/src/format/sldprt.rs @@ -0,0 +1,11 @@ +/// Import functionality. +pub mod import { + use parse_display::{Display, FromStr}; + use schemars::JsonSchema; + use serde::{Deserialize, Serialize}; + + /// Options for importing SolidWorks parts. + #[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)] + #[display("")] + pub struct Options {} +}