sync
This commit is contained in:
parent
c83a9e6d8a
commit
6d23be91a4
@ -82,6 +82,7 @@ impl Component for AppModel {
|
|||||||
set_halign: gtk::Align::Center,
|
set_halign: gtk::Align::Center,
|
||||||
set_spacing: 10,
|
set_spacing: 10,
|
||||||
gtk::Label{
|
gtk::Label{
|
||||||
|
add_css_class: "h1",
|
||||||
set_text: "Rayshon Radar Project Tools"
|
set_text: "Rayshon Radar Project Tools"
|
||||||
},
|
},
|
||||||
gtk::Button {
|
gtk::Button {
|
||||||
|
|||||||
@ -2,7 +2,6 @@ mod app;
|
|||||||
mod history_list;
|
mod history_list;
|
||||||
mod new_project;
|
mod new_project;
|
||||||
mod setting_item;
|
mod setting_item;
|
||||||
|
|
||||||
pub use app::*;
|
pub use app::*;
|
||||||
pub use new_project::*;
|
pub use new_project::*;
|
||||||
pub use setting_item::*;
|
pub use setting_item::*;
|
||||||
@ -1,5 +1,5 @@
|
|||||||
use crate::components::setting_item::{SettingItem, SettingType};
|
use crate::components::setting_item::{SettingItem, SettingType};
|
||||||
use crate::config::CommonConfig;
|
use crate::config::{CommonConfig, RadarConfig};
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use gtk::glib::clone;
|
use gtk::glib::clone;
|
||||||
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt, ToggleButtonExt};
|
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt, ToggleButtonExt};
|
||||||
@ -10,24 +10,32 @@ use relm4::{prelude::*, view};
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use adw::PreferencesPage;
|
||||||
|
use crate::components::NewPageMsg::RadarEdit;
|
||||||
|
|
||||||
#[tracker::track]
|
#[tracker::track]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct NewPageModel {
|
pub struct NewPageModel {
|
||||||
project_name: String,
|
project_name: String,
|
||||||
common_setting: CommonConfig,
|
radar_num: usize,
|
||||||
|
current_idx: usize,
|
||||||
|
radar_configs: Vec<RadarConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum NewPageMsg{
|
pub enum NewPageMsg {
|
||||||
ChangeName(String)
|
ChangeName(String),
|
||||||
|
ChangeRadarNum(usize),
|
||||||
|
SwitchToRadar,
|
||||||
|
RadarEdit(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[relm4::component(pub)]
|
#[relm4::component(pub)]
|
||||||
impl SimpleComponent for NewPageModel {
|
impl Component for NewPageModel {
|
||||||
type Init = ();
|
type Init = ();
|
||||||
type Output = ();
|
type Output = ();
|
||||||
type Input = NewPageMsg;
|
type Input = NewPageMsg;
|
||||||
|
type CommandOutput = ();
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
#[root]
|
#[root]
|
||||||
@ -37,6 +45,7 @@ impl SimpleComponent for NewPageModel {
|
|||||||
#[wrap(Some)]
|
#[wrap(Some)]
|
||||||
set_sidebar = &adw::NavigationPage{
|
set_sidebar = &adw::NavigationPage{
|
||||||
#[wrap(Some)]
|
#[wrap(Some)]
|
||||||
|
#[name = "step"]
|
||||||
set_child=>k::StackSidebar{
|
set_child=>k::StackSidebar{
|
||||||
set_stack: &stack
|
set_stack: &stack
|
||||||
}
|
}
|
||||||
@ -74,13 +83,89 @@ impl SimpleComponent for NewPageModel {
|
|||||||
sender.input(NewPageMsg::ChangeName(s.text().to_string()));
|
sender.input(NewPageMsg::ChangeName(s.text().to_string()));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
#[iterate]
|
add=&adw::EntryRow{
|
||||||
add: model.common_setting.to_settings().iter_mut().map(|v| v.widget()).collect::<Vec<_>>().iter()
|
set_title: "Version",
|
||||||
|
},
|
||||||
|
add=&adw::SpinRow{
|
||||||
|
set_title: "Project Name",
|
||||||
|
// set_range: (0.0, 100.0),
|
||||||
|
set_adjustment: Some(>k::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=>k::Grid{
|
||||||
|
set_hexpand: true,
|
||||||
|
set_column_homogeneous: true,
|
||||||
|
attach[0,0,1,1] = >k::Button {
|
||||||
|
set_label: "Cancel",
|
||||||
|
set_halign: gtk::Align::Start,
|
||||||
|
},
|
||||||
|
attach[1,0,1,1] = >k::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=>k::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] = >k::Label{
|
||||||
|
set_halign: gtk::Align::Start,
|
||||||
|
set_text:"0%"
|
||||||
|
},
|
||||||
|
attach[1,0,1,1] = >k::Label{
|
||||||
|
set_text:"Radar Config"
|
||||||
|
},
|
||||||
|
attach[2,0,1,1] = >k::Label{
|
||||||
|
set_halign: gtk::Align::End,
|
||||||
|
set_text:"0%"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
algorithm_setting = gtk::Box{},
|
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(&common_setting, Some("Common"), "Common"),
|
||||||
|
stack.add_titled(&radar_setting, Some("Radar"), "Radar"),
|
||||||
stack.add_titled(&algorithm_setting, Some("Algorithm"), "Algorithm"),
|
stack.add_titled(&algorithm_setting, Some("Algorithm"), "Algorithm"),
|
||||||
}
|
}
|
||||||
fn init(
|
fn init(
|
||||||
@ -91,19 +176,38 @@ impl SimpleComponent for NewPageModel {
|
|||||||
let config = CommonConfig::default();
|
let config = CommonConfig::default();
|
||||||
let mut model = NewPageModel {
|
let mut model = NewPageModel {
|
||||||
project_name: format!("Project {}", 0),
|
project_name: format!("Project {}", 0),
|
||||||
common_setting: config,
|
radar_num: 1,
|
||||||
|
radar_configs: Vec::new(),
|
||||||
|
current_idx:0,
|
||||||
|
// common_setting: config,
|
||||||
tracker: 0,
|
tracker: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let widgets = view_output!();
|
let widgets = view_output!();
|
||||||
ComponentParts { model, widgets }
|
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();
|
self.reset();
|
||||||
match msg {
|
match msg {
|
||||||
NewPageMsg::ChangeName(name) => {
|
NewPageMsg::ChangeName(name) => {
|
||||||
self.set_project_name(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,16 +12,16 @@ pub struct CommonConfig{
|
|||||||
pub algorithms: Vec<AlgorithmConfig>,
|
pub algorithms: Vec<AlgorithmConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive( Clone, Debug, PartialOrd, PartialEq)]
|
#[derive( Clone, Debug, PartialOrd, PartialEq, Default)]
|
||||||
pub struct RadarConfig{
|
pub struct RadarConfig{
|
||||||
pub name: String,
|
pub name: Rc<RefCell<String>>,
|
||||||
pub _type: String,
|
pub _type: Rc<RefCell<String>>,
|
||||||
loc: [f64;3],
|
loc: Rc<Cell<[f64;3]>>,
|
||||||
az_beam_width: f64,
|
az_beam_width: Rc<Cell<f64>>,
|
||||||
el_beam_width: f64,
|
el_beam_width: Rc<Cell<f64>>,
|
||||||
azs_method: usize,
|
azs_method: Rc<Cell<usize>>,
|
||||||
els_method: usize,
|
els_method: Rc<Cell<usize>>,
|
||||||
r_limit: f64,
|
r_limit: Rc<Cell<f64>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive( Clone, Debug, PartialOrd, PartialEq)]
|
#[derive( Clone, Debug, PartialOrd, PartialEq)]
|
||||||
@ -31,22 +31,29 @@ pub struct AlgorithmConfig {
|
|||||||
// info: HashMap<String, String>
|
// info: HashMap<String, String>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommonConfig{
|
|
||||||
|
impl RadarConfig {
|
||||||
pub fn to_settings(&self) -> Vec<SettingItem>{
|
pub fn to_settings(&self) -> Vec<SettingItem>{
|
||||||
let mut settings = Vec::new();
|
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("Name".to_string(), SettingType::Entry(None, None, None)));
|
||||||
settings.push(SettingItem::new("Version".to_string(), SettingType::Entry(Some(self.version.borrow().clone()), None, Some(self.version.clone()))));
|
settings.push(SettingItem::new("Type".to_string(), SettingType::Entry(None, None, None)));
|
||||||
settings.push(SettingItem::new("Radar Num".to_string(), SettingType::Spin(0.0, 0.0, 100.0, 1.0, Some(self.radar_lens.clone()))));
|
settings.push(SettingItem::new("Location".to_string(), SettingType::Entry(None, None, None)));
|
||||||
for radar in self.radars.iter(){
|
settings.push(SettingItem::new("Azimuth Beam Width".to_string(), SettingType::Entry(None, None, None)));
|
||||||
settings.push(SettingItem::new("Name".to_string(), SettingType::Entry(Some(radar.name.clone()), None, None)));
|
settings.push(SettingItem::new("Elevation Beam Width".to_string(), SettingType::Entry(None,None,None)));
|
||||||
settings.push(SettingItem::new("Type".to_string(), SettingType::Entry(Some(radar._type.clone()), 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("Location".to_string(), SettingType::Entry(Some(format!("{},{},{}", radar.loc[0], radar.loc[1], radar.loc[2])), None, 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("Azimuth Beam Width".to_string(), SettingType::Entry(Some(radar.az_beam_width.to_string()), None, None)));
|
settings.push(SettingItem::new("Range Limit".to_string(), SettingType::Entry(None,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("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
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -7,6 +7,7 @@ use gtk::{
|
|||||||
use std::{ptr, sync::Mutex};
|
use std::{ptr, sync::Mutex};
|
||||||
mod components;
|
mod components;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod widgets;
|
||||||
|
|
||||||
use components::AppModel;
|
use components::AppModel;
|
||||||
const APP_ID: &str = "org.tsuki.rsproject";
|
const APP_ID: &str = "org.tsuki.rsproject";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user