feat(section): add testing section

This commit is contained in:
doryan 2024-08-10 01:19:29 +04:00
parent 01f61e4286
commit 0d2987a968

View File

@ -23,8 +23,6 @@ use gtk4 as gtk;
pub fn signal_reducing_page(wrapper: &Box) { pub fn signal_reducing_page(wrapper: &Box) {
let values = Rc::new(Cell::new(SignalReduce::default())); let values = Rc::new(Cell::new(SignalReduce::default()));
let last_query: Vec<TreeIter> = Vec::new();
let info_bar = InfoBar::get_instance(); let info_bar = InfoBar::get_instance();
let (input_height, monospace, input_wrapping): (i32, bool, WrapMode) = let (input_height, monospace, input_wrapping): (i32, bool, WrapMode) =
@ -40,22 +38,15 @@ pub fn signal_reducing_page(wrapper: &Box) {
vertical: Align::Fill, vertical: Align::Fill,
}; };
let input_labels: [&str; 6] = [ let input_labels: [&str; 6] = ["l, м:", "Rм, Ом", "Cм, пФ:", "Rи, Ом:", "Vи, мВ", "f, мГц:"];
"l, м:",
"Rм, Ом:",
"Cм, пФ:",
"Vи, мВ",
"Rи, Ом:",
"f, мГц:",
];
let all_inputs: Vec<Input> = input_labels let all_inputs: Vec<Input> = input_labels
.iter() .iter()
.map(move |label| { .map(move |label| {
Input::builder() Input::builder()
.set_label(label) .label(label)
.set_margins(MarginData::EqualsMargin(5)) .margins(MarginData::EqualsMargin(6))
.set_align(input_label_alignment) .align(input_label_alignment)
.build(monospace, input_wrapping, input_height) .build(monospace, input_wrapping, input_height)
}) })
.collect(); .collect();
@ -68,7 +59,7 @@ pub fn signal_reducing_page(wrapper: &Box) {
} }
input_block.attach( input_block.attach(
&elem.clone().get(), elem.clone().get(),
(id as i32) - (3 * row_position), (id as i32) - (3 * row_position),
row_position, row_position,
1, 1,
@ -78,16 +69,24 @@ pub fn signal_reducing_page(wrapper: &Box) {
let calculate_button = Button::builder().label("Расчитать").build(); let calculate_button = Button::builder().label("Расчитать").build();
let result_table_headers_labels: [&str; 4] = ["f, МГц", "Xc, пФ", "Vп, мВ", "ζ"]; let result_table_headers_labels: [&str; 4] = ["f, МГц", "Xc, Ом", "Vп, мВ", "ζ"];
let model = gio::ListStore::new::<ResultValue>(); let model = gio::ListStore::new::<Frequency>();
let model_for_events = model.clone();
let cloned_model = model.clone(); for number in (0..=100).step_by(5) {
if number == 0 {
model.append(&Frequency::new(1.0));
} else if (number >= 70 && number % 10 == 0) || (number < 70 && number % 5 == 0) {
model.append(&Frequency::new(number as f64));
}
}
let selection_model = SingleSelection::new(Some(model)); let selection_model = NoSelection::new(Some(model));
let result_table = ColumnView::builder() let result_table = ColumnView::builder()
.reorderable(true) .reorderable(true)
.show_row_separators(true)
.model(&selection_model) .model(&selection_model)
.build(); .build();
@ -108,7 +107,7 @@ pub fn signal_reducing_page(wrapper: &Box) {
.downcast_ref::<ListItem>() .downcast_ref::<ListItem>()
.expect("Needs to be ListItem") .expect("Needs to be ListItem")
.item() .item()
.and_downcast::<ResultValue>() .and_downcast::<Frequency>()
.expect("The item has to be an `IntegerObject`."); .expect("The item has to be an `IntegerObject`.");
let cell_label = list_item let cell_label = list_item
@ -118,38 +117,42 @@ pub fn signal_reducing_page(wrapper: &Box) {
.and_downcast::<Label>() .and_downcast::<Label>()
.expect("The child has to be a `Label`."); .expect("The child has to be a `Label`.");
let result_values = values_for_factory.clone().get(); let result_values = values_for_factory.get();
let reactive_resist: f64 = reactive_resistance_of_capacitor( let reactive_resist: f64 = reactive_resistance_of_capacitor(
result_values.2, result_values.wire_capacity * 10f64.powi(-12),
result_values.0, result_values.length,
cell_value.value(), cell_value.frequency() * 10f64.powi(6),
); );
let full_resistance: f64 = full_resistance_of_capacitor( let full_resistance: f64 = full_resistance_of_capacitor(
reactive_resist, reactive_resist,
result_values.4, result_values.source_resistance,
result_values.1, result_values.wire_resistance,
result_values.0, result_values.length,
); );
let signal_source_voltage: f64 = let signal_source_voltage: f64 = voltage_from_signal_source(
voltage_from_signal_source(result_values.3, reactive_resist, full_resistance); result_values.source_voltage * 10f64.powi(-3),
reactive_resist,
let coef: f64 = coef_of_signal_reduce(signal_source_voltage, signal_source_voltage); full_resistance,
) * 1000.0;
match label { match label {
"f, МГц" => { "f, МГц" => {
cell_label.set_label(&cell_value.value().to_string()); cell_label.set_label(&cell_value.frequency().to_string());
} }
"Xc, пФ" => { "Xc, Ом" => {
cell_label.set_label(&reactive_resist.to_string()); cell_label.set_label(format!("{0:.1$}", reactive_resist, 6).as_str());
} }
"Vп, мВ" => { "Vп, мВ" => {
cell_label.set_label(&signal_source_voltage.to_string()); cell_label.set_label(format!("{0:.1$}", signal_source_voltage, 6).as_str());
} }
"ζ" => { "ζ" => {
cell_label.set_label(&coef.to_string()); let coef: f64 =
coef_of_signal_reduce(result_values.source_voltage, signal_source_voltage);
cell_label.set_label(format!("{0:.1$}", coef, 6).as_str());
} }
_ => {} _ => {}
} }
@ -175,14 +178,12 @@ pub fn signal_reducing_page(wrapper: &Box) {
.vexpand(true) .vexpand(true)
.build(); .build();
EventHandler::new(calculate_button.clone(), move |_| { calculate_button.connect_clicked(move |_| match parse_fields(all_inputs.clone()) {
match parse_fields(all_inputs.clone()) {
Ok(results) => { Ok(results) => {
values.set(results); values.set(results);
let tree_iter: TreeIter = cloned_model.append(&ResultValue::new(results.5)); model_for_events.items_changed(0, 0, 18);
model_for_events.items_changed(18, 18, 0);
last_query.append(tree_iter);
} }
Err(error) => { Err(error) => {
let error_kind: Option<&str> = get_error_message(error); let error_kind: Option<&str> = get_error_message(error);
@ -190,9 +191,7 @@ pub fn signal_reducing_page(wrapper: &Box) {
info_bar.set_text_label(error_kind); info_bar.set_text_label(error_kind);
info_bar.show_infobar(5u64); info_bar.show_infobar(5u64);
} }
} });
})
.on_click();
wrapper.append(&input_block); wrapper.append(&input_block);
wrapper.append(&calculate_button); wrapper.append(&calculate_button);