Skip to content

Commit

Permalink
Merge pull request #4 from Brickworks/gui
Browse files Browse the repository at this point in the history
WIP user interface plus some simulation rewrites
  • Loading branch information
philiplinden authored Feb 18, 2024
2 parents 5730733 + 20ec6cb commit be8b1d5
Show file tree
Hide file tree
Showing 15 changed files with 685 additions and 173 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Restore cargo cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cargo/registry/index
Expand All @@ -45,7 +45,7 @@ jobs:
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Restore cargo cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cargo/registry/index
Expand All @@ -66,7 +66,7 @@ jobs:
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Restore cargo cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cargo/registry/index
Expand All @@ -77,7 +77,7 @@ jobs:
${{ runner.os }}-cargo-
- name: Cargo Doc
run: cargo doc --no-deps --target-dir=docs
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: docs
path: docs
Expand All @@ -102,10 +102,10 @@ jobs:
name: docs
path: docs
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v4
with:
path: docs
path: target/doc/${{ github.repository_id }}
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
if: github.event_name != 'pull_request'
15 changes: 1 addition & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# dev files
*.csv
.vscode

# Generated by Cargo
# will have compiled files and executables
Expand All @@ -16,17 +17,3 @@ Cargo.lock
# Added by cargo

/target


# Added by cargo
#
# already existing elements were commented out

#/target


# Added by cargo
#
# already existing elements were commented out

#/target
15 changes: 11 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ license-file = "LICENSE"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log = { version = "0.4", features = ["release_max_level_debug"] }
pretty_env_logger = "0.4.0"
pretty_env_logger = "0.5.0"
libm = "0.2.1"
toml = "0.7"
serde = { version = "1.0.157", features = ["derive", "std"] }
toml = "0.8.10"
clap = { version = "4.1", default-features = false, features = [
"derive",
"std",
Expand All @@ -24,6 +22,15 @@ clap = { version = "4.1", default-features = false, features = [
"suggestions",
] }
csv = "1.2.1"
serde = { version = "1.0.196", features = ["derive"] }
log = { version = "0.4.20", features = ["release_max_level_debug"] }
egui = { version = "0.26.2", features = ["log", "serde"], optional = true }
egui_plot = { version = "0.26.2", features = ["serde"], optional = true }
eframe = { version = "0.26.2", features = ["persistence"], optional = true }

[features]
default = []
gui = ["egui", "egui_plot", "eframe"]

[[bin]]
name = "yahs"
Expand Down
22 changes: 10 additions & 12 deletions config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ barely_inflated_diameter_m = 1.5 # larger balloons have less strain
species = "Helium"
mass_kg = 0.3

[payload.bus]
dry_mass_kg = 1.427
[bus.body]
mass_kg = 1.427
drag_area_m2 = 0.04
drag_coeff = 2.1

[payload.parachute]
area_m2 = 1.1
drag_coeff = 1.3
open_altitude_m = 18_000.0

[payload.control]
controller_path = "../mfc-apps/control_apps"
vent_valve_mass_flow_kg_s = 0.007
dump_valve_mass_flow_kg_s = 0.001
ballast_mass_kg = 0.0
[bus.parachute]
total_mass_kg = 0.2
drogue_area_m2 = 0.2
drogue_drag_coeff = 1.5
main_area_m2 = 1.1
main_drag_coeff = 0.8
deploy_force_n = 100
deploy_time_s = 5.0
37 changes: 26 additions & 11 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use std::path::PathBuf;

use clap::{Parser, Subcommand};
Expand Down Expand Up @@ -30,12 +32,7 @@ enum Commands {
config: PathBuf,

/// Sets a custom output file
#[clap(
short,
long,
value_name = "CSV",
default_value = "./out.csv"
)]
#[clap(short, long, value_name = "CSV", default_value = "./out.csv")]
outpath: PathBuf,
},

Expand All @@ -52,18 +49,25 @@ enum Commands {
/// New value to set
value: String,
},

/// Open a graphical user interface instead of the terminal interface
Gui,
}

pub fn parse_inputs() {
// parse CLI input args and options
let cli = Cli::parse();
match &cli.command {
Commands::Start {
config,
outpath,
} => {
Commands::Start { config, outpath } => {
start_sim(config, outpath);
}
Commands::Gui => {
#[cfg(feature = "gui")]
start_gui();

#[cfg(not(feature = "gui"))]
error!("GUI feature not enabled. Reinstall with `--features gui`")
}
_ => {
error!("Command not implemented yet!")
}
Expand All @@ -81,4 +85,15 @@ pub fn start_sim(config: &PathBuf, outpath: &PathBuf) {
sim.get_sim_output();
rate_sleeper.sleep();
}
}
}

#[cfg(feature = "gui")]
pub fn start_gui() {
use crate::gui;
let native_options = eframe::NativeOptions::default();
let _ = eframe::run_native(
"yet another hab simulator",
native_options,
Box::new(|cc| Box::new(gui::Shell::new(cc))),
);
}
Empty file added src/gui/controls.rs
Empty file.
24 changes: 24 additions & 0 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
mod controls;
mod monitors;
mod shell;

pub use shell::Shell;

/// Something to view in the monitor windows
pub trait View {
fn ui(&mut self, ui: &mut egui::Ui);
}

/// Something to view
pub trait UiPanel {
/// Is the monitor enabled for this integration?
fn is_enabled(&self, _ctx: &egui::Context) -> bool {
true
}

/// `&'static` so we can also use it as a key to store open/close state.
fn name(&self) -> &'static str;

/// Show windows, etc
fn show(&mut self, ctx: &egui::Context, open: &mut bool);
}
Loading

0 comments on commit be8b1d5

Please sign in to comment.