I'm too lazy to commit to the latest files
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
use gtk4 as gtk;
|
||||
|
||||
use crate::{
|
||||
model::{models::*, Result},
|
||||
model_utils::hamming_code_seven_four::*,
|
||||
};
|
||||
use gtk::{prelude::*, *};
|
||||
|
||||
pub fn start_hamming_algorithm(input: &TextView, state: bool) -> Result<String> {
|
||||
let (iter_start, iter_end) = input.buffer().bounds();
|
||||
let parsed_input: String = input
|
||||
.buffer()
|
||||
.text(&iter_start, &iter_end, false)
|
||||
.to_string()
|
||||
.trim()
|
||||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let operation = if !state {
|
||||
HammingMode::Encrypt
|
||||
} else {
|
||||
HammingMode::Decrypt
|
||||
};
|
||||
|
||||
hamming(parsed_input, operation)
|
||||
}
|
||||
|
||||
pub fn check_correct_binary_code(input: &str, prepared_input: &str, l: usize) -> (bool, bool) {
|
||||
let first_condition: bool = prepared_input.len() % l == 0;
|
||||
|
||||
|
||||
(first_condition, second_condition)
|
||||
}
|
||||
@@ -6,4 +6,29 @@ use crate::{
|
||||
};
|
||||
use gtk::{prelude::*, *};
|
||||
|
||||
pub fn start_hamming_algorithm(input: &TextView, state: bool) -> Result<String> {
|
||||
let (iter_start, iter_end) = input.buffer().bounds();
|
||||
let parsed_input: String = input
|
||||
.buffer()
|
||||
.text(&iter_start, &iter_end, false)
|
||||
.to_string()
|
||||
.trim()
|
||||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let operation = if !state {
|
||||
HammingMode::Encrypt
|
||||
} else {
|
||||
HammingMode::Decrypt
|
||||
};
|
||||
|
||||
hamming(parsed_input, operation)
|
||||
}
|
||||
|
||||
pub fn check_correct_binary_code(prepared_input: &str, l: usize) -> (bool, bool) {
|
||||
let first_condition: bool = prepared_input.len() % l == 0;
|
||||
|
||||
let second_condition: bool = prepared_input.chars().all(|c| c == '1' || c == '0');
|
||||
|
||||
(first_condition, second_condition)
|
||||
}
|
||||
|
||||
@@ -41,3 +41,88 @@ pub fn parse_fields(all_inputs: Vec<Input<Entry>>) -> Result<SignalReduce> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn update_column_view(column_view: &ColumnView) {
|
||||
column_view.hide();
|
||||
column_view.show();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn column_view_setup_factory(_factory: &SignalListItemFactory, list_item: &ListItem) {
|
||||
list_item
|
||||
.downcast_ref::<ListItem>()
|
||||
.expect("Needs to be ListItem")
|
||||
.set_child(Some(&Label::new(None)));
|
||||
}
|
||||
|
||||
pub fn column_view_bind_factory(
|
||||
_factory: &SignalListItemFactory,
|
||||
list_item: &ListItem,
|
||||
values: SignalReduce,
|
||||
label: &str,
|
||||
) {
|
||||
let cell_value = list_item
|
||||
.downcast_ref::<ListItem>()
|
||||
.expect("Needs to be ListItem")
|
||||
.item()
|
||||
.and_downcast::<Frequency>()
|
||||
.expect("The item has to be an `IntegerObject`.");
|
||||
|
||||
let cell_label = list_item
|
||||
.downcast_ref::<ListItem>()
|
||||
.expect("Needs to be ListItem")
|
||||
.child()
|
||||
.and_downcast::<Label>()
|
||||
.expect("The child has to be a `Label`.");
|
||||
|
||||
cell_value
|
||||
.bind_property("frequency", &cell_label, "label")
|
||||
.sync_create()
|
||||
.build();
|
||||
|
||||
if cell_value.reactive_resist() == 0.0 {
|
||||
cell_value.set_reactive_resist(reactive_resistance_of_capacitor(
|
||||
values.wire_capacity * 10f64.powi(-12),
|
||||
values.length,
|
||||
cell_value.frequency() * 10f64.powi(6),
|
||||
));
|
||||
}
|
||||
|
||||
if cell_value.full_resistance() == 0.0 {
|
||||
cell_value.set_full_resistance(full_resistance_of_capacitor(
|
||||
cell_value.reactive_resist(),
|
||||
values.source_resistance,
|
||||
values.wire_resistance,
|
||||
values.length,
|
||||
));
|
||||
}
|
||||
|
||||
if cell_value.signal_source_voltage() == 0.0 {
|
||||
cell_value.set_signal_source_voltage(
|
||||
voltage_from_signal_source(
|
||||
values.source_voltage * 10f64.powi(-3),
|
||||
cell_value.reactive_resist(),
|
||||
cell_value.full_resistance(),
|
||||
) * 1000.0,
|
||||
);
|
||||
}
|
||||
|
||||
match label {
|
||||
"f, МГц" => {
|
||||
cell_label.set_label(&cell_value.frequency().to_string());
|
||||
}
|
||||
"Xc, Ом" => {
|
||||
cell_label.set_label(format!("{0:.1$}", cell_value.reactive_resist(), 6).as_str());
|
||||
}
|
||||
"Vп, мВ" => {
|
||||
cell_label
|
||||
.set_label(format!("{0:.1$}", cell_value.signal_source_voltage(), 6).as_str());
|
||||
}
|
||||
"ζ" => {
|
||||
let coef: f64 =
|
||||
coef_of_signal_reduce(values.source_voltage, cell_value.signal_source_voltage());
|
||||
|
||||
cell_label.set_label(format!("{0:.1$}", coef, 6).as_str());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user