From b0ad8687a4f865c2f3a5f47019df0083335f6ecd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 21 Nov 2022 13:44:30 +0100 Subject: [PATCH 1/2] Remove model generation feature --- crates/fj-app/src/args.rs | 4 --- crates/fj-app/src/main.rs | 5 ---- crates/fj-app/src/model_crate.rs | 50 -------------------------------- 3 files changed, 59 deletions(-) delete mode 100644 crates/fj-app/src/model_crate.rs diff --git a/crates/fj-app/src/args.rs b/crates/fj-app/src/args.rs index 4ee2dc0e5d..b8ab53e0ac 100644 --- a/crates/fj-app/src/args.rs +++ b/crates/fj-app/src/args.rs @@ -12,10 +12,6 @@ pub struct Args { /// The model to open pub model: Option, - /// Create a new model with this name - #[arg(short, long, value_name = "MODEL_NAME")] - pub new: Option, - /// Export model to this path #[arg(short, long, value_name = "PATH")] pub export: Option, diff --git a/crates/fj-app/src/main.rs b/crates/fj-app/src/main.rs index 6f7cc4587d..e8ab235a5e 100644 --- a/crates/fj-app/src/main.rs +++ b/crates/fj-app/src/main.rs @@ -14,7 +14,6 @@ mod args; mod config; -mod model_crate; mod path; use anyhow::{anyhow, Context}; @@ -50,10 +49,6 @@ fn main() -> anyhow::Result<()> { tolerance: args.tolerance, }; - if let Some(model_name) = args.new { - return model_crate::create(&model_name); - } - let model = model_path.map(|m| m.load_model(parameters)).transpose()?; if let Some(export_path) = args.export { diff --git a/crates/fj-app/src/model_crate.rs b/crates/fj-app/src/model_crate.rs deleted file mode 100644 index 738fa216ba..0000000000 --- a/crates/fj-app/src/model_crate.rs +++ /dev/null @@ -1,50 +0,0 @@ -use include_dir::{include_dir, Dir}; -use std::{fs, path::Path}; - -static MODEL_TEMPLATE: Dir = include_dir!("$CARGO_MANIFEST_DIR/model-template"); - -pub fn create(model_name: &str) -> anyhow::Result<()> { - let path = Path::new(model_name); - fs::create_dir_all(path)?; - MODEL_TEMPLATE.extract(path)?; - post_process_model_files(path, model_name)?; - println!("Model '{model_name}' created"); - Ok(()) -} - -fn post_process_model_files( - path: &Path, - model_name: &str, -) -> anyhow::Result<()> { - replace_in_file( - &path.join("Cargo.toml"), - [ - ( - "name = \"model-template\"".to_string(), - format!("name = \"{model_name}\""), - ), - ( - r#"path = "../../fj""#.to_owned(), - ["version = \"", &fj::version::VERSION_PKG.to_string(), "\""] - .concat(), - ), - ], - )?; - replace_in_file( - &path.join("README.md"), - [("# Model Template".to_string(), format!("# {model_name}"))], - )?; - Ok(()) -} - -fn replace_in_file( - path: &Path, - replacements: impl IntoIterator, -) -> anyhow::Result<()> { - let mut content = fs::read_to_string(path)?; - for (from, to) in replacements { - content = content.replace(&from, &to); - } - fs::write(path, content)?; - Ok(()) -} From 7eb4b0b31b3f7ec1fd02ac67ddea600c0a049f2b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 21 Nov 2022 13:45:05 +0100 Subject: [PATCH 2/2] Remove unused model template --- Cargo.lock | 7 ----- Cargo.toml | 1 - crates/fj-app/model-template/Cargo.toml | 7 ----- crates/fj-app/model-template/README.md | 10 ------- crates/fj-app/model-template/src/lib.rs | 40 ------------------------- 5 files changed, 65 deletions(-) delete mode 100644 crates/fj-app/model-template/Cargo.toml delete mode 100644 crates/fj-app/model-template/README.md delete mode 100644 crates/fj-app/model-template/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index d7fa542654..7667015efb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2136,13 +2136,6 @@ dependencies = [ "windows-sys 0.42.0", ] -[[package]] -name = "model-template" -version = "0.1.0" -dependencies = [ - "fj", -] - [[package]] name = "naga" version = "0.9.0" diff --git a/Cargo.toml b/Cargo.toml index 11f0fcd784..c64a9ef160 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,6 @@ resolver = "2" members = [ "crates/fj", "crates/fj-app", - "crates/fj-app/model-template", "crates/fj-export", "crates/fj-host", "crates/fj-interop", diff --git a/crates/fj-app/model-template/Cargo.toml b/crates/fj-app/model-template/Cargo.toml deleted file mode 100644 index 17cde83735..0000000000 --- a/crates/fj-app/model-template/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "model-template" -version = "0.1.0" -edition = "2021" - -[dependencies.fj] -path = "../../fj" diff --git a/crates/fj-app/model-template/README.md b/crates/fj-app/model-template/README.md deleted file mode 100644 index c43f251154..0000000000 --- a/crates/fj-app/model-template/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Model Template - -This is a Fornjot model that has been freshly generated! [**Fornjot**][Fornjot] is a next-generation, code-first CAD application. [**Check out the website**][Fornjot] to learn more! - -Fornjot models are written in Rust, and a Fornjot model is just a Cargo package. If you don't fully understand what's going on here, check out the Rust documentation: [**https://www.rust-lang.org/learn**](https://www.rust-lang.org/learn) - -Once you feel ready to dive in, get your favorite editor and check out `src/lib.rs`, which contains the source code for this model. - - -[Fornjot]: https://www.fornjot.app/ diff --git a/crates/fj-app/model-template/src/lib.rs b/crates/fj-app/model-template/src/lib.rs deleted file mode 100644 index 3d17756808..0000000000 --- a/crates/fj-app/model-template/src/lib.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::f64::consts::PI; - -#[fj::model] -pub fn model( - #[param(default = 5, min = 3)] num_points: u64, - #[param(default = 1.0, min = 1.0)] r1: f64, - #[param(default = 2.0, min = 2.0)] r2: f64, - #[param(default = 1.0)] h: f64, -) -> fj::Shape { - let num_vertices = num_points * 2; - let vertex_iter = (0..num_vertices).map(|i| { - let angle = - fj::Angle::from_rad(2. * PI / num_vertices as f64 * i as f64); - let radius = if i % 2 == 0 { r1 } else { r2 }; - (angle, radius) - }); - - // Now that we got that iterator prepared, generating the vertices is just a - // bit of trigonometry. - let mut outer = Vec::new(); - let mut inner = Vec::new(); - for (angle, radius) in vertex_iter { - let (sin, cos) = angle.rad().sin_cos(); - - let x = cos * radius; - let y = sin * radius; - - outer.push([x, y]); - inner.push([x / 2., y / 2.]); - } - - let outer = fj::Sketch::from_points(outer); - let inner = fj::Sketch::from_points(inner); - - let footprint = fj::Difference2d::from_shapes([outer.into(), inner.into()]); - - let star = fj::Sweep::from_path(footprint.into(), [0., 0., h]); - - star.into() -}