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