Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI element that displays model compiling status #911

Merged
merged 8 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/fj-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 4 additions & 2 deletions crates/fj-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
//
Expand Down Expand Up @@ -62,7 +64,7 @@ fn main() -> anyhow::Result<()> {
};

if let Some(path) = args.export {
let shape = model.load_once(&parameters)?;
let shape = model.load_once(&parameters, &mut status)?;
let shape = shape_processor.process(&shape)?;

export(&shape.mesh, &path)?;
Expand All @@ -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(())
}
4 changes: 4 additions & 0 deletions crates/fj-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
21 changes: 14 additions & 7 deletions crates/fj-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

mod platform;

use fj_interop::status_report::StatusReport;
use std::{
collections::{HashMap, HashSet},
ffi::OsStr,
Expand Down Expand Up @@ -82,15 +83,21 @@ impl Model {
pub fn load_once(
&self,
arguments: &Parameters,
status: &mut StatusReport,
) -> Result<fj::Shape, Error> {
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);
}

Expand Down Expand Up @@ -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<fj::Shape> {
pub fn receive(&self, status: &mut StatusReport) -> Option<fj::Shape> {
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) => {
Expand Down
1 change: 1 addition & 0 deletions crates/fj-interop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
pub mod debug;
pub mod mesh;
pub mod processed_shape;
pub mod status_report;
31 changes: 31 additions & 0 deletions crates/fj-interop/src/status_report.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
6 changes: 6 additions & 0 deletions crates/fj-viewer/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions crates/fj-window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 9 additions & 4 deletions crates/fj-window/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)?;
Expand All @@ -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(
Expand Down Expand Up @@ -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);
}
}
Expand Down