diff --git a/Cargo.lock b/Cargo.lock index 6996f7c3b..2dec5f3af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -846,6 +846,7 @@ dependencies = [ "fj", "fj-export", "fj-host", + "fj-interop", "fj-kernel", "fj-math", "fj-operations", @@ -872,6 +873,7 @@ version = "0.10.0" dependencies = [ "cargo_metadata", "fj", + "fj-interop", "libloading", "notify", "thiserror", @@ -958,6 +960,7 @@ name = "fj-window" version = "0.10.0" dependencies = [ "fj-host", + "fj-interop", "fj-operations", "fj-viewer", "futures", diff --git a/crates/fj-app/Cargo.toml b/crates/fj-app/Cargo.toml index 0456a1967..4bd2cb1b4 100644 --- a/crates/fj-app/Cargo.toml +++ b/crates/fj-app/Cargo.toml @@ -65,3 +65,7 @@ features = ["derive"] [dependencies.tracing-subscriber] version = "0.3.15" features = ["env-filter", "fmt"] + +[dependencies.fj-interop] +version = "0.10.0" +path = "../fj-interop" diff --git a/crates/fj-app/src/main.rs b/crates/fj-app/src/main.rs index 6982fec48..845f30abb 100644 --- a/crates/fj-app/src/main.rs +++ b/crates/fj-app/src/main.rs @@ -20,6 +20,7 @@ use std::path::PathBuf; use anyhow::{anyhow, Context as _}; use fj_export::export; use fj_host::{Model, Parameters}; +use fj_interop::status_report::StatusReport; use fj_operations::shape_processor::ShapeProcessor; use fj_window::run::run; use tracing_subscriber::fmt::format; @@ -28,6 +29,7 @@ use tracing_subscriber::EnvFilter; use crate::{args::Args, config::Config}; fn main() -> anyhow::Result<()> { + let mut status = StatusReport::new(); // Respect `RUST_LOG`. If that's not defined or erroneous, log warnings and // above. // @@ -62,7 +64,7 @@ fn main() -> anyhow::Result<()> { }; if let Some(path) = args.export { - let shape = model.load_once(¶meters)?; + let shape = model.load_once(¶meters, &mut status)?; let shape = shape_processor.process(&shape)?; export(&shape.mesh, &path)?; @@ -71,7 +73,7 @@ fn main() -> anyhow::Result<()> { } let watcher = model.load_and_watch(parameters)?; - run(watcher, shape_processor)?; + run(watcher, shape_processor, status)?; Ok(()) } diff --git a/crates/fj-host/Cargo.toml b/crates/fj-host/Cargo.toml index 14cfa480a..10e21b967 100644 --- a/crates/fj-host/Cargo.toml +++ b/crates/fj-host/Cargo.toml @@ -24,3 +24,7 @@ cargo_metadata = "0.15.0" [dependencies.fj] version = "0.10.0" path = "../fj" + +[dependencies.fj-interop] +version = "0.10.0" +path = "../fj-interop" diff --git a/crates/fj-host/src/lib.rs b/crates/fj-host/src/lib.rs index ad644be93..e76a3b9b2 100644 --- a/crates/fj-host/src/lib.rs +++ b/crates/fj-host/src/lib.rs @@ -17,6 +17,7 @@ mod platform; +use fj_interop::status_report::StatusReport; use std::{ collections::{HashMap, HashSet}, ffi::OsStr, @@ -82,15 +83,21 @@ impl Model { pub fn load_once( &self, arguments: &Parameters, + status: &mut StatusReport, ) -> Result { let manifest_path = self.manifest_path.display().to_string(); - let status = Command::new("cargo") + let mut command_root = Command::new("cargo"); + + let command = command_root .arg("build") - .args(["--manifest-path", &manifest_path]) - .status()?; + .args(["--manifest-path", &manifest_path]); + let exit_status = command.status()?; - if !status.success() { + if exit_status.success() { + status.update_status("Model compiled successfully!"); + } else { + status.update_status("Error compiling the model!"); return Err(Error::Compile); } @@ -260,16 +267,16 @@ impl Watcher { /// /// Returns `None`, if the model has not changed since the last time this /// method was called. - pub fn receive(&self) -> Option { + pub fn receive(&self, status: &mut StatusReport) -> Option { match self.channel.try_recv() { Ok(()) => { - let shape = match self.model.load_once(&self.parameters) { + let shape = match self.model.load_once(&self.parameters, status) + { Ok(shape) => shape, Err(Error::Compile) => { // It would be better to display an error in the UI, // where the user can actually see it. Issue: // https://github.com/hannobraun/fornjot/issues/30 - println!("Error compiling model"); return None; } Err(err) => { diff --git a/crates/fj-interop/src/lib.rs b/crates/fj-interop/src/lib.rs index 88d430744..7e8cfa384 100644 --- a/crates/fj-interop/src/lib.rs +++ b/crates/fj-interop/src/lib.rs @@ -17,3 +17,4 @@ pub mod debug; pub mod mesh; pub mod processed_shape; +pub mod status_report; diff --git a/crates/fj-interop/src/status_report.rs b/crates/fj-interop/src/status_report.rs new file mode 100644 index 000000000..7478fede1 --- /dev/null +++ b/crates/fj-interop/src/status_report.rs @@ -0,0 +1,31 @@ +//! Struct to store and update status messages + +/// Struct to store and update status messages +pub struct StatusReport { + status: String, +} + +impl StatusReport { + /// Create a new ``StatusReport`` instance with a blank status + pub fn new() -> Self { + Self { + status: String::new(), + } + } + + /// Update the status + pub fn update_status(&mut self, status: &str) { + self.status = status.to_string(); + } + + /// Get current status + pub fn status(&self) -> &str { + self.status.as_str() + } +} + +impl Default for StatusReport { + fn default() -> Self { + Self::new() + } +} diff --git a/crates/fj-viewer/src/graphics/renderer.rs b/crates/fj-viewer/src/graphics/renderer.rs index cd2179e46..3e2dbcfbe 100644 --- a/crates/fj-viewer/src/graphics/renderer.rs +++ b/crates/fj-viewer/src/graphics/renderer.rs @@ -1,5 +1,6 @@ use std::{io, mem::size_of}; +use fj_interop::status_report::StatusReport; use fj_math::{Aabb, Point}; use thiserror::Error; use tracing::debug; @@ -304,6 +305,7 @@ impl Renderer { camera: &Camera, config: &mut DrawConfig, window: &egui_winit::winit::window::Window, + status: &mut StatusReport, ) -> Result<(), DrawError> { let aspect_ratio = self.surface_config.width as f64 / self.surface_config.height as f64; @@ -428,6 +430,10 @@ impl Renderer { egui::SidePanel::left("fj-left-panel").show(&self.egui.context, |ui| { ui.add_space(16.0); + ui.label(format!("Status Report:\n{}", status.status())); + + ui.add_space(16.0); + ui.group(|ui| { ui.checkbox(&mut config.draw_model, "Render model") .on_hover_text_at_pointer("Toggle with 1"); diff --git a/crates/fj-window/Cargo.toml b/crates/fj-window/Cargo.toml index 42b33fbf1..a60e1dee2 100644 --- a/crates/fj-window/Cargo.toml +++ b/crates/fj-window/Cargo.toml @@ -32,3 +32,7 @@ path = "../fj-operations" [dependencies.fj-viewer] version = "0.10.0" path = "../fj-viewer" + +[dependencies.fj-interop] +version = "0.10.0" +path = "../fj-interop" diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index 4264a48a4..310bf965c 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -6,6 +6,7 @@ use std::error; use fj_host::Watcher; +use fj_interop::status_report::StatusReport; use fj_operations::shape_processor::ShapeProcessor; use fj_viewer::{ camera::Camera, @@ -30,6 +31,7 @@ use crate::window::{self, Window}; pub fn run( watcher: Watcher, shape_processor: ShapeProcessor, + mut status: StatusReport, ) -> Result<(), Error> { let event_loop = EventLoop::new(); let window = Window::new(&event_loop)?; @@ -49,7 +51,7 @@ pub fn run( event_loop.run(move |event, _, control_flow| { trace!("Handling event: {:?}", event); - if let Some(new_shape) = watcher.receive() { + if let Some(new_shape) = watcher.receive(&mut status) { match shape_processor.process(&new_shape) { Ok(new_shape) => { renderer.update_geometry( @@ -174,9 +176,12 @@ pub fn run( if let (Some(shape), Some(camera)) = (&shape, &mut camera) { camera.update_planes(&shape.aabb); - if let Err(err) = - renderer.draw(camera, &mut draw_config, window.window()) - { + if let Err(err) = renderer.draw( + camera, + &mut draw_config, + window.window(), + &mut status, + ) { warn!("Draw error: {}", err); } }