Merge pull request #2028 from KLayout/bugfix/issue-2025

Fixed issue #2025 (brackets get added on PCell parameters)
This commit is contained in:
Matthias Köfferlein 2025-04-27 14:34:52 +02:00 committed by GitHub
commit 89d5bf0df1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 48 additions and 2 deletions

View File

@ -47,6 +47,31 @@
namespace edt
{
static std::string variant_list_to_string (const tl::Variant &value)
{
if (! value.is_list ()) {
tl::Variant v = tl::Variant::empty_list ();
v.push (value);
return v.to_parsable_string ();
}
for (auto i = value.begin (); i != value.end (); ++i) {
if (! i->is_a_string () || std::string (i->to_string ()).find (",") != std::string::npos) {
return value.to_parsable_string ();
}
}
// otherwise we can plainly combine the strings with ","
std::string res;
for (auto i = value.begin (); i != value.end (); ++i) {
if (i != value.begin ()) {
res += ",";
}
res += i->to_string ();
}
return res;
}
static void set_value (const db::PCellParameterDeclaration &p, QWidget *widget, const tl::Variant &value)
{
if (p.get_choices ().empty ()) {
@ -91,7 +116,7 @@ static void set_value (const db::PCellParameterDeclaration &p, QWidget *widget,
QLineEdit *le = dynamic_cast<QLineEdit *> (widget);
if (le) {
le->blockSignals (true);
le->setText (value.to_qstring ());
le->setText (tl::to_qstring (variant_list_to_string (value)));
le->blockSignals (false);
}
}
@ -905,8 +930,29 @@ PCellParametersPage::get_parameters_internal (db::ParameterStates &states, bool
{
QLineEdit *le = dynamic_cast<QLineEdit *> (m_widgets [r]);
if (le) {
std::vector<std::string> values = tl::split (tl::to_string (le->text ()), ",");
std::string s = tl::to_string (le->text ());
// try parsing a bracketed expression
tl::Extractor ex (s.c_str ());
if (*ex.skip () == '(') {
tl::Variant v;
try {
ex.read (v);
ps.set_value (v);
break;
} catch (...) {
// ignore errors
}
} else if (ex.at_end ()) {
ps.set_value (tl::Variant::empty_list ());
break;
}
// otherwise: plain splitting at comma
std::vector<std::string> values = tl::split (s, ",");
ps.set_value (tl::Variant (values.begin (), values.end ()));
}
}
break;