Less expression evaluation for more robustness

This commit is contained in:
Matthias Koefferlein
2021-12-16 00:23:06 +01:00
parent 3ef28c8a9d
commit a6d4c80c6c
40 changed files with 267 additions and 179 deletions
@@ -69,7 +69,7 @@ CIFReaderOptionPage::commit (db::FormatSpecificReaderOptions *o, const db::Techn
{
db::CIFReaderOptions *options = dynamic_cast<db::CIFReaderOptions *> (o);
if (options) {
tl::from_string (tl::to_string (mp_ui->dbu_le->text ()), options->dbu);
tl::from_string_ext (tl::to_string (mp_ui->dbu_le->text ()), options->dbu);
if (options->dbu > 1000.0 || options->dbu < 1e-9) {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid value for database unit")));
}
@@ -75,24 +75,24 @@ DXFReaderOptionPage::commit (db::FormatSpecificReaderOptions *o, const db::Techn
{
db::DXFReaderOptions *options = dynamic_cast<db::DXFReaderOptions *> (o);
if (options) {
tl::from_string (tl::to_string (mp_ui->dbu_le->text ()), options->dbu);
tl::from_string_ext (tl::to_string (mp_ui->dbu_le->text ()), options->dbu);
if (options->dbu > 1000.0 || options->dbu < 1e-9) {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid value for database unit")));
}
tl::from_string (tl::to_string (mp_ui->unit_le->text ()), options->unit);
tl::from_string_ext (tl::to_string (mp_ui->unit_le->text ()), options->unit);
if (options->unit > 1e9 || options->unit < 1e-9) {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid value for the unit")));
}
tl::from_string (tl::to_string (mp_ui->text_scaling_le->text ()), options->text_scaling);
tl::from_string_ext (tl::to_string (mp_ui->text_scaling_le->text ()), options->text_scaling);
if (options->text_scaling > 10000 || options->text_scaling < 1) {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid value for the text scaling")));
}
tl::from_string (tl::to_string(mp_ui->circle_points_le->text ()), options->circle_points);
tl::from_string_ext (tl::to_string(mp_ui->circle_points_le->text ()), options->circle_points);
if (options->circle_points < 4 || options->circle_points > 1000000) {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid value for the number of points for arc interpolation")));
}
tl::from_string (tl::to_string(mp_ui->circle_accuracy_le->text ()), options->circle_accuracy);
tl::from_string (tl::to_string(mp_ui->contour_accuracy_le->text ()), options->contour_accuracy);
tl::from_string_ext (tl::to_string(mp_ui->circle_accuracy_le->text ()), options->circle_accuracy);
tl::from_string_ext (tl::to_string(mp_ui->contour_accuracy_le->text ()), options->contour_accuracy);
options->polyline_mode = mp_ui->polyline2poly_cbx->currentIndex ();
options->render_texts_as_polygons = mp_ui->render_texts_as_polygons_cbx->isChecked ();
options->keep_other_cells = mp_ui->keep_other_cells_cbx->isChecked ();
@@ -83,7 +83,7 @@ GDS2WriterOptionPage::commit (db::FormatSpecificWriterOptions *o, const db::Tech
options->write_file_properties = mp_ui->write_file_properties->isChecked ();
options->no_zero_length_paths = mp_ui->no_zero_length_paths->isChecked ();
tl::from_string (tl::to_string (mp_ui->max_vertex_le->text ()), n);
tl::from_string_ext (tl::to_string (mp_ui->max_vertex_le->text ()), n);
if (! options->multi_xy_records) {
if (n > 8191) {
throw tl::Exception (tl::to_string (QObject::tr ("Maximum number of vertices must not exceed 8191")));
@@ -95,7 +95,7 @@ GDS2WriterOptionPage::commit (db::FormatSpecificWriterOptions *o, const db::Tech
options->max_vertex_count = n;
n = 32000;
tl::from_string (tl::to_string (mp_ui->cell_name_length_le->text ()), n);
tl::from_string_ext (tl::to_string (mp_ui->cell_name_length_le->text ()), n);
if (n > 32000) {
throw tl::Exception (tl::to_string (QObject::tr ("Maximum cell name length must not exceed 32000")));
}
@@ -391,7 +391,7 @@ LEFDEFReaderOptionsEditor::commit (db::FormatSpecificReaderOptions *options, con
data->set_produce_pin_names (produce_pin_names->isChecked ());
double dbu_value = 0.0;
tl::from_string (tl::to_string (dbu->text ()), dbu_value);
tl::from_string_ext (tl::to_string (dbu->text ()), dbu_value);
if (dbu_value < 1e-7) {
throw tl::Exception (tl::to_string (tr ("Invalid database unit value (must be non-null and positive)")));
}
@@ -80,12 +80,12 @@ MAGReaderOptionPage::commit (db::FormatSpecificReaderOptions *o, const db::Techn
db::MAGReaderOptions *options = dynamic_cast<db::MAGReaderOptions *> (o);
if (options) {
tl::from_string (tl::to_string (mp_ui->dbu_le->text ()), options->dbu);
tl::from_string_ext (tl::to_string (mp_ui->dbu_le->text ()), options->dbu);
if (options->dbu > 1000.0 || options->dbu < 1e-9) {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid value for database unit")));
}
tl::from_string (tl::to_string (mp_ui->lambda_le->text ()), options->lambda);
tl::from_string_ext (tl::to_string (mp_ui->lambda_le->text ()), options->lambda);
if (options->lambda > 10000000.0 || options->lambda < 1e-9) {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid value for lambda")));
}
@@ -73,7 +73,7 @@ MAGWriterOptionPage::commit (db::FormatSpecificWriterOptions *o, const db::Techn
QString l = mp_ui->lambda_le->text ().trimmed ();
options->lambda = 0.0;
if (! l.isEmpty ()) {
tl::from_string (tl::to_string (l), options->lambda);
tl::from_string_ext (tl::to_string (l), options->lambda);
}
options->tech = tl::to_string (mp_ui->tech_le->text ().trimmed ());
options->write_timestamp = ! mp_ui->zero_ts_cbx->isChecked ();
@@ -1024,8 +1024,8 @@ GerberImportDialog::commit_page ()
mp_data->num_metal_layers = -1;
mp_data->num_via_types = -1;
tl::from_string (tl::to_string (mp_ui->num_metal_le->text ()), mp_data->num_metal_layers);
tl::from_string (tl::to_string (mp_ui->num_via_le->text ()), mp_data->num_via_types);
tl::from_string_ext (tl::to_string (mp_ui->num_metal_le->text ()), mp_data->num_metal_layers);
tl::from_string_ext (tl::to_string (mp_ui->num_via_le->text ()), mp_data->num_via_types);
if (mp_data->num_metal_layers < 0) {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid number of metal layers")));
@@ -1297,12 +1297,12 @@ GerberImportDialog::commit_page ()
mp_data->merge_flag = mp_ui->merge_cb->isChecked ();
mp_data->invert_negative_layers = mp_ui->invert_cb->isChecked ();
tl::from_string (tl::to_string (mp_ui->border_le->text ()), mp_data->border);
tl::from_string_ext (tl::to_string (mp_ui->border_le->text ()), mp_data->border);
bool import_into = (mp_data->mode == db::GerberImportData::ModeIntoLayout);
if (! import_into) {
tl::from_string (tl::to_string (mp_ui->dbu_le->text ()), mp_data->dbu);
tl::from_string_ext (tl::to_string (mp_ui->dbu_le->text ()), mp_data->dbu);
if (mp_data->dbu < 1e-6) {
throw tl::Exception (tl::to_string (QObject::tr ("Database unit must not be negative or zero")));
}
@@ -242,10 +242,10 @@ void
NetTracerConfigPage::commit (lay::Dispatcher *root)
{
double dim = 1.0;
tl::from_string (tl::to_string (le_window->text ()), dim);
tl::from_string_ext (tl::to_string (le_window->text ()), dim);
unsigned int max_shapes_highlighted = 10000;
tl::from_string (tl::to_string (le_max_markers->text ()), max_shapes_highlighted);
tl::from_string_ext (tl::to_string (le_max_markers->text ()), max_shapes_highlighted);
root->config_set (cfg_nt_window_mode, lay::nt_window_type (cbx_window->currentIndex ()), NetTracerWindowModeConverter ());
root->config_set (cfg_nt_window_dim, dim);
@@ -262,7 +262,7 @@ NetTracerConfigPage::commit (lay::Dispatcher *root)
} else {
try {
int s;
tl::from_string (tl::to_string (lw_le->text ()), s);
tl::from_string_ext (tl::to_string (lw_le->text ()), s);
root->config_set (cfg_nt_marker_line_width, s);
} catch (...) { }
}
@@ -272,7 +272,7 @@ NetTracerConfigPage::commit (lay::Dispatcher *root)
} else {
try {
int s;
tl::from_string (tl::to_string (vs_le->text ()), s);
tl::from_string_ext (tl::to_string (vs_le->text ()), s);
root->config_set (cfg_nt_marker_vertex_size, s);
} catch (...) { }
}
@@ -1427,7 +1427,7 @@ NetTracerDialog::get_trace_depth()
try {
QString depth = depth_le->text ().trimmed ();
if (! depth.isEmpty ()) {
tl::from_string (tl::to_string (depth), n);
tl::from_string_ext (tl::to_string (depth), n);
if (n < 0 || n > double (std::numeric_limits<size_t>::max ())) {
n = 0.0;
}
@@ -132,7 +132,7 @@ D25View::scale_value_edited ()
{
double f = mp_ui->d25_view->scale_factor ();
try {
tl::from_string (tl::to_string (mp_ui->zoom_factor->text ()), f);
tl::from_string_ext (tl::to_string (mp_ui->zoom_factor->text ()), f);
f = std::min (1e6, std::max (1e-6, f));
} catch (...) {
// ignore exceptions
@@ -146,7 +146,7 @@ D25View::vscale_value_edited ()
{
double f = mp_ui->d25_view->vscale_factor ();
try {
tl::from_string (tl::to_string (mp_ui->vzoom_factor->text ()), f);
tl::from_string_ext (tl::to_string (mp_ui->vzoom_factor->text ()), f);
f = std::min (1e6, std::max (1e-6, f));
} catch (...) {
// ignore exceptions