2024-03-17 20:34:12 +03:00
|
|
|
use gtk4 as gtk;
|
|
|
|
|
2024-04-14 19:13:15 +03:00
|
|
|
use crate::{
|
2024-04-18 11:23:13 +03:00
|
|
|
controller::event_handlers::button_event_handlers::*,
|
2024-04-19 00:30:51 +03:00
|
|
|
model::{
|
|
|
|
builder_traits::Product,
|
|
|
|
model::{EventHandler, SchemeCharacteristics},
|
|
|
|
},
|
2024-04-14 19:13:15 +03:00
|
|
|
view::{
|
|
|
|
components::{input::Input, wrapper::Wrapper},
|
|
|
|
properties::*,
|
2024-03-17 20:34:12 +03:00
|
|
|
},
|
2024-04-19 00:30:51 +03:00
|
|
|
view_utils::signal_reduce_input_utils::start_algorithm,
|
2024-03-17 20:34:12 +03:00
|
|
|
};
|
2024-04-14 19:13:15 +03:00
|
|
|
use gtk::{prelude::*, Align, WrapMode, *};
|
2024-03-17 20:34:12 +03:00
|
|
|
|
|
|
|
pub fn signal_reducing_page(wrapper: &Box) {
|
2024-04-14 19:13:15 +03:00
|
|
|
let (input_height, monospace, input_alignment, input_wrapping): (i32, bool, Align, WrapMode) =
|
|
|
|
(24, true, Align::Fill, WrapMode::Word);
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-14 19:13:15 +03:00
|
|
|
let input_label_alignment = Alignment {
|
|
|
|
horizontal: Align::Start,
|
|
|
|
vertical: Align::Fill,
|
|
|
|
};
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
let wire_length_input: Input = Input::builder()
|
2024-04-14 19:13:15 +03:00
|
|
|
.set_label("l, м:")
|
2024-03-17 20:34:12 +03:00
|
|
|
.set_margins(MarginData::EqualsMargin(5))
|
2024-04-14 19:13:15 +03:00
|
|
|
.set_align(input_label_alignment)
|
2024-04-19 00:30:51 +03:00
|
|
|
.build(monospace, input_wrapping, input_height);
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
let resistance_per_meter_input: Input = Input::builder()
|
2024-04-14 19:13:15 +03:00
|
|
|
.set_label("Rм, Ом:")
|
2024-03-17 20:34:12 +03:00
|
|
|
.set_margins(MarginData::EqualsMargin(5))
|
2024-04-14 19:13:15 +03:00
|
|
|
.set_align(input_label_alignment)
|
2024-04-19 00:30:51 +03:00
|
|
|
.build(monospace, input_wrapping, input_height);
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
let capacity_per_meter_input: Input = Input::builder()
|
2024-04-14 19:13:15 +03:00
|
|
|
.set_label("Cм, пФ:")
|
2024-03-17 20:34:12 +03:00
|
|
|
.set_margins(MarginData::EqualsMargin(5))
|
2024-04-14 19:13:15 +03:00
|
|
|
.set_align(input_label_alignment)
|
2024-04-19 00:30:51 +03:00
|
|
|
.build(monospace, input_wrapping, input_height);
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-14 19:13:15 +03:00
|
|
|
let wrapper_first_row = Wrapper::col_builder()
|
|
|
|
.halign(Align::Fill)
|
|
|
|
.hexpand(true)
|
|
|
|
.spacing(5)
|
|
|
|
.build();
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
let first_row_elements: Vec<&Input> = vec![
|
2024-04-16 20:45:31 +03:00
|
|
|
&wire_length_input,
|
|
|
|
&resistance_per_meter_input,
|
|
|
|
&capacity_per_meter_input,
|
|
|
|
];
|
|
|
|
|
|
|
|
for elem in first_row_elements {
|
2024-04-19 00:30:51 +03:00
|
|
|
let input: Box = elem.clone().get();
|
|
|
|
|
|
|
|
input.set_halign(input_alignment);
|
|
|
|
input.set_hexpand(true);
|
2024-04-16 20:45:31 +03:00
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
wrapper_first_row.append(&input);
|
2024-04-16 20:45:31 +03:00
|
|
|
}
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
let info_signal_voltage_input: Input = Input::builder()
|
2024-04-14 19:13:15 +03:00
|
|
|
.set_label("Vи, мВ:")
|
2024-03-17 20:34:12 +03:00
|
|
|
.set_margins(MarginData::EqualsMargin(5))
|
2024-04-14 19:13:15 +03:00
|
|
|
.set_align(input_label_alignment)
|
2024-04-19 00:30:51 +03:00
|
|
|
.build(monospace, input_wrapping, input_height);
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
let resistance_of_info_voltage_source_input: Input = Input::builder()
|
2024-04-14 19:13:15 +03:00
|
|
|
.set_label("Rи, Ом:")
|
2024-03-17 20:34:12 +03:00
|
|
|
.set_margins(MarginData::EqualsMargin(5))
|
2024-04-14 19:13:15 +03:00
|
|
|
.set_align(input_label_alignment)
|
2024-04-19 00:30:51 +03:00
|
|
|
.build(monospace, input_wrapping, input_height);
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
let info_voltage_source_frequency_input: Input = Input::builder()
|
2024-04-14 19:13:15 +03:00
|
|
|
.set_label("f, мГц:")
|
2024-03-17 20:34:12 +03:00
|
|
|
.set_margins(MarginData::EqualsMargin(5))
|
2024-04-14 19:13:15 +03:00
|
|
|
.set_align(input_label_alignment)
|
2024-04-19 00:30:51 +03:00
|
|
|
.build(monospace, input_wrapping, input_height);
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-14 19:13:15 +03:00
|
|
|
let wrapper_second_row = Wrapper::col_builder()
|
|
|
|
.halign(Align::Fill)
|
|
|
|
.hexpand(true)
|
|
|
|
.spacing(5)
|
|
|
|
.build();
|
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
let second_row_elements: Vec<&Input> = vec![
|
2024-04-16 20:45:31 +03:00
|
|
|
&info_signal_voltage_input,
|
|
|
|
&resistance_of_info_voltage_source_input,
|
|
|
|
&info_voltage_source_frequency_input,
|
|
|
|
];
|
|
|
|
|
|
|
|
for elem in second_row_elements {
|
2024-04-19 00:30:51 +03:00
|
|
|
let input: Box = elem.clone().get();
|
|
|
|
|
|
|
|
input.set_halign(input_alignment);
|
|
|
|
input.set_hexpand(true);
|
2024-04-16 20:45:31 +03:00
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
wrapper_second_row.append(&input);
|
2024-04-16 20:45:31 +03:00
|
|
|
}
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
let all_text_views: Vec<TextView> = vec![
|
|
|
|
wire_length_input.get_input(),
|
|
|
|
resistance_per_meter_input.get_input(),
|
|
|
|
capacity_per_meter_input.get_input(),
|
|
|
|
info_signal_voltage_input.get_input(),
|
|
|
|
resistance_of_info_voltage_source_input.get_input(),
|
|
|
|
info_voltage_source_frequency_input.get_input(),
|
|
|
|
];
|
|
|
|
|
2024-04-18 11:23:13 +03:00
|
|
|
let main_wrapper = Wrapper::row_builder().spacing(5).build();
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-18 11:23:13 +03:00
|
|
|
main_wrapper.append(&wrapper_first_row);
|
|
|
|
main_wrapper.append(&wrapper_second_row);
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-04-18 11:23:13 +03:00
|
|
|
let calculate_button = Button::builder()
|
|
|
|
.label("Расчитать")
|
|
|
|
.halign(Align::End)
|
|
|
|
.set_margin(MarginData::MultipleMargin((10, 5, 0, 0)))
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let table_header_labels = vec!["f, Гц", "Xc, пФ", "Vп, мВ", "ζ"];
|
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
let table_header = ColumnView::builder()
|
|
|
|
.focusable(false)
|
|
|
|
.reorderable(true)
|
|
|
|
.halign(Align::Fill)
|
2024-04-18 11:23:13 +03:00
|
|
|
.hexpand(true)
|
|
|
|
.build();
|
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
for table_header_label in table_header_labels {
|
|
|
|
let column = ColumnViewColumn::builder()
|
|
|
|
.title(table_header_label)
|
|
|
|
.fixed_width(200)
|
|
|
|
.expand(true)
|
2024-04-18 11:23:13 +03:00
|
|
|
.build();
|
2024-04-19 00:30:51 +03:00
|
|
|
|
|
|
|
table_header.append_column(&column);
|
2024-04-18 11:23:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let table_of_calculated_values = Frame::builder()
|
|
|
|
.height_request(64)
|
|
|
|
.hexpand(true)
|
|
|
|
.child(&table_header)
|
|
|
|
.halign(Align::Fill)
|
|
|
|
.set_margin(MarginData::MultipleMargin((10, 5, 0, 0)))
|
|
|
|
.build();
|
|
|
|
|
2024-04-19 00:30:51 +03:00
|
|
|
let errors_label: Label = Label::new(Some(""));
|
|
|
|
let errors_label_for_handler: Label = errors_label.clone();
|
|
|
|
|
2024-04-18 11:23:13 +03:00
|
|
|
EventHandler::new(calculate_button.clone(), move |_| {
|
2024-04-19 00:30:51 +03:00
|
|
|
start_algorithm(&errors_label_for_handler, &all_text_views)
|
2024-04-18 11:23:13 +03:00
|
|
|
})
|
|
|
|
.on_click();
|
|
|
|
|
|
|
|
main_wrapper.append(&calculate_button);
|
|
|
|
main_wrapper.append(&table_of_calculated_values);
|
2024-04-19 00:30:51 +03:00
|
|
|
main_wrapper.append(&errors_label);
|
2024-04-18 11:23:13 +03:00
|
|
|
|
|
|
|
wrapper.append(&main_wrapper);
|
2024-04-14 19:13:15 +03:00
|
|
|
}
|