This commit is contained in:
Tsuki 2024-02-25 10:56:24 +08:00
parent c83a9e6d8a
commit 6d23be91a4
5 changed files with 145 additions and 33 deletions

View File

@ -82,6 +82,7 @@ impl Component for AppModel {
set_halign: gtk::Align::Center,
set_spacing: 10,
gtk::Label{
add_css_class: "h1",
set_text: "Rayshon Radar Project Tools"
},
gtk::Button {

View File

@ -2,7 +2,6 @@ mod app;
mod history_list;
mod new_project;
mod setting_item;
pub use app::*;
pub use new_project::*;
pub use setting_item::*;

View File

@ -1,5 +1,5 @@
use crate::components::setting_item::{SettingItem, SettingType};
use crate::config::CommonConfig;
use crate::config::{CommonConfig, RadarConfig};
use adw::prelude::*;
use gtk::glib::clone;
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt, ToggleButtonExt};
@ -10,24 +10,32 @@ use relm4::{prelude::*, view};
use std::cell::RefCell;
use std::path::PathBuf;
use std::rc::Rc;
use adw::PreferencesPage;
use crate::components::NewPageMsg::RadarEdit;
#[tracker::track]
#[derive(Debug)]
pub struct NewPageModel {
project_name: String,
common_setting: CommonConfig,
radar_num: usize,
current_idx: usize,
radar_configs: Vec<RadarConfig>,
}
#[derive(Debug)]
pub enum NewPageMsg {
ChangeName(String)
ChangeName(String),
ChangeRadarNum(usize),
SwitchToRadar,
RadarEdit(usize),
}
#[relm4::component(pub)]
impl SimpleComponent for NewPageModel {
impl Component for NewPageModel {
type Init = ();
type Output = ();
type Input = NewPageMsg;
type CommandOutput = ();
view! {
#[root]
@ -37,6 +45,7 @@ impl SimpleComponent for NewPageModel {
#[wrap(Some)]
set_sidebar = &adw::NavigationPage{
#[wrap(Some)]
#[name = "step"]
set_child=&gtk::StackSidebar{
set_stack: &stack
}
@ -74,13 +83,89 @@ impl SimpleComponent for NewPageModel {
sender.input(NewPageMsg::ChangeName(s.text().to_string()));
}
},
#[iterate]
add: model.common_setting.to_settings().iter_mut().map(|v| v.widget()).collect::<Vec<_>>().iter()
add=&adw::EntryRow{
set_title: "Version",
},
add=&adw::SpinRow{
set_title: "Project Name",
// set_range: (0.0, 100.0),
set_adjustment: Some(&gtk::Adjustment::new(0.0, 0.0, 100.0, 1.0, 0.0, 0.0)),
set_value: model.radar_num as f64,
set_numeric: true,
connect_value_notify[sender] => move |s| {
sender.input(NewPageMsg::ChangeRadarNum(s.value() as usize));
}
},
// #[iterate]
// add: model.common_setting.to_settings().iter_mut().map(|v| v.widget()).collect::<Vec<_>>().iter()
},
add=&adw::PreferencesGroup{
add=&gtk::Grid{
set_hexpand: true,
set_column_homogeneous: true,
attach[0,0,1,1] = &gtk::Button {
set_label: "Cancel",
set_halign: gtk::Align::Start,
},
attach[1,0,1,1] = &gtk::Button {
set_label: "Next",
set_halign: gtk::Align::End,
connect_clicked[sender, stack] => move |_| {
sender.input(NewPageMsg::SwitchToRadar);
stack.set_visible_child_name("Radar");
}
}
},
add=&gtk::Box{
set_hexpand: true,
set_halign: gtk::Align::Center,
#[name="progress"]
gtk::Box{
set_orientation: gtk::Orientation::Vertical,
gtk::ProgressBar{
set_margin_top: 30,
set_fraction:0.0
},
gtk::Grid{
set_margin_top: 10,
set_column_homogeneous: true,
add_css_class: "content",
attach[0,0,1,1] = &gtk::Label{
set_halign: gtk::Align::Start,
set_text:"0%"
},
attach[1,0,1,1] = &gtk::Label{
set_text:"Radar Config"
},
attach[2,0,1,1] = &gtk::Label{
set_halign: gtk::Align::End,
set_text:"0%"
},
}
}
}
}
}
},
algorithm_setting = gtk::Box{},
radar_setting=gtk::Box{
set_orientation: gtk::Orientation::Vertical,
set_valign: gtk::Align::Center,
gtk::Button{
set_label: "Add Radar",
connect_clicked[sender] => move |_| {
sender.input(NewPageMsg::RadarEdit(0));
}
},
#[name="radar_stack"]
adw::ViewStack{
}
},
stack.add_titled(&common_setting, Some("Common"), "Common"),
stack.add_titled(&radar_setting, Some("Radar"), "Radar"),
stack.add_titled(&algorithm_setting, Some("Algorithm"), "Algorithm"),
}
fn init(
@ -91,19 +176,38 @@ impl SimpleComponent for NewPageModel {
let config = CommonConfig::default();
let mut model = NewPageModel {
project_name: format!("Project {}", 0),
common_setting: config,
radar_num: 1,
radar_configs: Vec::new(),
current_idx:0,
// common_setting: config,
tracker: 0,
};
let widgets = view_output!();
ComponentParts { model, widgets }
}
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
fn update(&mut self, msg: Self::Input, sender: ComponentSender<Self>, root: &Self::Root) {
self.reset();
match msg {
NewPageMsg::ChangeName(name) => {
self.set_project_name(name);
}
NewPageMsg::ChangeRadarNum(num) => {
}
NewPageMsg::SwitchToRadar => {
let mut a = Vec::new();
for _ in 0..self.radar_num {
a.push(RadarConfig::default());
}
self.set_radar_configs(a);
}
NewPageMsg::RadarEdit(index) => {
let idx = self.get_current_idx();
self.set_current_idx(idx + 1);
}
}
}
}

View File

@ -12,16 +12,16 @@ pub struct CommonConfig{
pub algorithms: Vec<AlgorithmConfig>,
}
#[derive( Clone, Debug, PartialOrd, PartialEq)]
#[derive( Clone, Debug, PartialOrd, PartialEq, Default)]
pub struct RadarConfig{
pub name: String,
pub _type: String,
loc: [f64;3],
az_beam_width: f64,
el_beam_width: f64,
azs_method: usize,
els_method: usize,
r_limit: f64,
pub name: Rc<RefCell<String>>,
pub _type: Rc<RefCell<String>>,
loc: Rc<Cell<[f64;3]>>,
az_beam_width: Rc<Cell<f64>>,
el_beam_width: Rc<Cell<f64>>,
azs_method: Rc<Cell<usize>>,
els_method: Rc<Cell<usize>>,
r_limit: Rc<Cell<f64>>,
}
#[derive( Clone, Debug, PartialOrd, PartialEq)]
@ -31,22 +31,29 @@ pub struct AlgorithmConfig {
// info: HashMap<String, String>
}
impl CommonConfig{
impl RadarConfig {
pub fn to_settings(&self) -> Vec<SettingItem>{
let mut settings = Vec::new();
// settings.push(SettingItem::new("Name".to_string(), SettingType::Entry(Some(self.name.borrow().clone()), None, Some(self.name.clone()))));
settings.push(SettingItem::new("Version".to_string(), SettingType::Entry(Some(self.version.borrow().clone()), None, Some(self.version.clone()))));
settings.push(SettingItem::new("Radar Num".to_string(), SettingType::Spin(0.0, 0.0, 100.0, 1.0, Some(self.radar_lens.clone()))));
for radar in self.radars.iter(){
settings.push(SettingItem::new("Name".to_string(), SettingType::Entry(Some(radar.name.clone()), None, None)));
settings.push(SettingItem::new("Type".to_string(), SettingType::Entry(Some(radar._type.clone()), None, None)));
settings.push(SettingItem::new("Location".to_string(), SettingType::Entry(Some(format!("{},{},{}", radar.loc[0], radar.loc[1], radar.loc[2])), None, None)));
settings.push(SettingItem::new("Azimuth Beam Width".to_string(), SettingType::Entry(Some(radar.az_beam_width.to_string()), None, None)));
settings.push(SettingItem::new("Elevation Beam Width".to_string(), SettingType::Entry(Some(radar.el_beam_width.to_string()), None, None)));
settings.push(SettingItem::new("Name".to_string(), SettingType::Entry(None, None, None)));
settings.push(SettingItem::new("Type".to_string(), SettingType::Entry(None, None, None)));
settings.push(SettingItem::new("Location".to_string(), SettingType::Entry(None, None, None)));
settings.push(SettingItem::new("Azimuth Beam Width".to_string(), SettingType::Entry(None, None, None)));
settings.push(SettingItem::new("Elevation Beam Width".to_string(), SettingType::Entry(None,None,None)));
settings.push(SettingItem::new("Azimuth Method".to_string(), SettingType::Select(vec!["1".to_string(), "2".to_string(), "3".to_string()], None)));
settings.push(SettingItem::new("Elevation Method".to_string(), SettingType::Select(vec!["1".to_string(), "2".to_string(), "3".to_string()], None)));
settings.push(SettingItem::new("Range Limit".to_string(), SettingType::Entry(Some(radar.r_limit.to_string()), None, None)));
}
settings.push(SettingItem::new("Range Limit".to_string(), SettingType::Entry(None,None,None)));
settings
}
pub fn to_preferences_group(&self) -> adw::PreferencesGroup {
use adw::prelude::*;
let group = adw::PreferencesGroup::default();
let mut settings = self.to_settings();
for setting in settings.iter_mut(){
group.add(&setting.widget());
}
group
}
}

View File

@ -7,6 +7,7 @@ use gtk::{
use std::{ptr, sync::Mutex};
mod components;
mod config;
mod widgets;
use components::AppModel;
const APP_ID: &str = "org.tsuki.rsproject";