Implemented fix for issue-1662 (Strong default grids)

This commit is contained in:
Matthias Koefferlein 2024-03-24 12:48:53 +01:00
parent 3b0a34b955
commit 376058f34b
8 changed files with 178 additions and 48 deletions

View File

@ -347,12 +347,10 @@ Technology::get_display_string () const
return d; return d;
} }
std::vector<double> static void
Technology::default_grid_list () const parse_default_grids (const std::string &s, std::vector<double> &grids, double &default_grid)
{ {
tl::Extractor ex (m_default_grids.c_str ()); tl::Extractor ex (s.c_str ());
std::vector<double> grids;
// convert the list of grids to a list of doubles // convert the list of grids to a list of doubles
while (! ex.at_end ()) { while (! ex.at_end ()) {
@ -361,12 +359,32 @@ Technology::default_grid_list () const
break; break;
} }
grids.push_back (g); grids.push_back (g);
if (ex.test ("!")) {
default_grid = g;
}
ex.test (","); ex.test (",");
} }
}
std::vector<double>
Technology::default_grid_list () const
{
std::vector<double> grids;
double default_grid = 0.0;
parse_default_grids (m_default_grids, grids, default_grid);
return grids; return grids;
} }
double
Technology::default_grid () const
{
std::vector<double> grids;
double default_grid = 0.0;
parse_default_grids (m_default_grids, grids, default_grid);
return default_grid;
}
tl::XMLElementList tl::XMLElementList
Technology::xml_elements () Technology::xml_elements ()
{ {

View File

@ -480,6 +480,15 @@ public:
*/ */
std::vector<double> default_grid_list () const; std::vector<double> default_grid_list () const;
/**
* @brief Gets the default grid (strong grid), parsed from the list
*
* The default grid is the one marked with an exclamation mark in the
* grid list (e.g. "0.01!,0.02,0.05"). If there is not such default
* grid, this method returns zero.
*/
double default_grid () const;
/** /**
* @brief Sets the default default grids * @brief Sets the default default grids
*/ */

View File

@ -136,7 +136,7 @@ gsi::Class<db::TechnologyComponent> technology_component_decl ("db", "Technology
DB_PUBLIC gsi::Class<db::TechnologyComponent> &decl_dbTechnologyComponent () { return technology_component_decl; } DB_PUBLIC gsi::Class<db::TechnologyComponent> &decl_dbTechnologyComponent () { return technology_component_decl; }
static void static void
set_default_grid_list (db::Technology *tech, const std::vector<double> &grids) set_default_grid_list2 (db::Technology *tech, const std::vector<double> &grids, double default_grid)
{ {
std::string r; std::string r;
for (auto g = grids.begin (); g != grids.end (); ++g) { for (auto g = grids.begin (); g != grids.end (); ++g) {
@ -144,10 +144,19 @@ set_default_grid_list (db::Technology *tech, const std::vector<double> &grids)
r += ","; r += ",";
} }
r += tl::micron_to_string (*g); r += tl::micron_to_string (*g);
if (db::coord_traits<db::DCoord>::equals (*g, default_grid)) {
r += "!";
}
} }
tech->set_default_grids (r); tech->set_default_grids (r);
} }
static void
set_default_grid_list (db::Technology *tech, const std::vector<double> &grids)
{
set_default_grid_list2 (tech, grids, 0.0);
}
gsi::Class<db::Technology> technology_decl ("db", "Technology", gsi::Class<db::Technology> technology_decl ("db", "Technology",
gsi::method ("name", &db::Technology::name, gsi::method ("name", &db::Technology::name,
"@brief Gets the name of the technology" "@brief Gets the name of the technology"
@ -238,12 +247,32 @@ gsi::Class<db::Technology> technology_decl ("db", "Technology",
"\n" "\n"
"This property has been introduced in version 0.28.17." "This property has been introduced in version 0.28.17."
) + ) +
gsi::method ("default_grid", &db::Technology::default_grid,
"@brief Gets the default grid\n"
"\n"
"The default grid is a specific one from the default grid list.\n"
"It indicates the one that is taken if the current grid is not matching one of "
"the default grids.\n"
"\n"
"To set the default grid, use \\set_default_grids.\n"
"\n"
"This property has been introduced in version 0.29."
) +
gsi::method_ext ("default_grids=", &set_default_grid_list, gsi::arg ("grids"), gsi::method_ext ("default_grids=", &set_default_grid_list, gsi::arg ("grids"),
"@brief Sets the default grids\n" "@brief Sets the default grids\n"
"If not empty, this list replaces the global grid list for this technology.\n" "If not empty, this list replaces the global grid list for this technology.\n"
"Note that this method will reset the default grid (see \\default_grid). Use "
"\\set_default_grids to set the default grids and the strong default one.\n"
"\n" "\n"
"This property has been introduced in version 0.28.17." "This property has been introduced in version 0.28.17."
) + ) +
gsi::method_ext ("set_default_grids", &set_default_grid_list2, gsi::arg ("grids"), gsi::arg ("default_grid", 0.0),
"@brief Sets the default grids and the strong default one\n"
"See \\default_grids and \\default_grid for a description of this property.\n"
"Note that the default grid has to be a member of the 'grids' array to become active.\n"
"\n"
"This method has been introduced in version 0.29."
) +
gsi::method ("layer_properties_file", &db::Technology::layer_properties_file, gsi::method ("layer_properties_file", &db::Technology::layer_properties_file,
"@brief Gets the path of the layer properties file\n" "@brief Gets the path of the layer properties file\n"
"\n" "\n"

View File

@ -1,67 +1,75 @@
<ui version="4.0" > <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainConfigPage3</class> <class>MainConfigPage3</class>
<widget class="QFrame" name="MainConfigPage3" > <widget class="QFrame" name="MainConfigPage3">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>475</width> <width>504</width>
<height>81</height> <height>180</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string>Settings</string> <string>Settings</string>
</property> </property>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout">
<property name="margin" > <property name="spacing">
<number>9</number>
</property>
<property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="margin" stdset="0">
<number>9</number>
</property>
<item> <item>
<widget class="QGroupBox" name="groupBox" > <widget class="QGroupBox" name="groupBox">
<property name="title" > <property name="title">
<string>Default Grids</string> <string>Default Grids</string>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout">
<property name="margin" > <property name="margin" stdset="0">
<number>9</number> <number>9</number>
</property> </property>
<property name="spacing" > <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<item row="0" column="2" > <item row="0" column="0">
<widget class="QLabel" name="textLabel1_4" > <widget class="QLabel" name="textLabel1">
<property name="text" > <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Grids for &quot;View&quot; menu</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="textLabel1_4">
<property name="text">
<string>µm (g1,g2,...)</string> <string>µm (g1,g2,...)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1" > <item row="0" column="1">
<widget class="QLineEdit" name="grids_edit" > <widget class="QLineEdit" name="grids_edit">
<property name="sizePolicy" > <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0" > <item row="1" column="0" colspan="3">
<widget class="QLabel" name="textLabel1" > <widget class="QLabel" name="label">
<property name="sizePolicy" > <property name="text">
<sizepolicy> <string>&lt;html&gt;You can declare one grid a strong default to enforce an editing grid from this list. To do so, add an exclamation mark - e.g. &quot;0.01!,0.02,0.05&quot;.
<hsizetype>5</hsizetype> &lt;br/&gt;&lt;b&gt;Note&lt;/b&gt;: the general default grids can be overridden by technology specific default grids.&lt;/html&gt;</string>
<vsizetype>5</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="text" > <property name="wordWrap">
<string>Grids for "View" menu</string> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
@ -70,7 +78,7 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<layoutdefault spacing="6" margin="11" /> <layoutdefault spacing="6" margin="11"/>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>625</width> <width>625</width>
<height>587</height> <height>616</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -331,6 +331,9 @@ properties</string>
<property name="text"> <property name="text">
<string>The default database unit is used as database unit for freshly created layouts</string> <string>The default database unit is used as database unit for freshly created layouts</string>
</property> </property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="12" column="0" colspan="4"> <item row="12" column="0" colspan="4">
@ -352,7 +355,10 @@ properties</string>
<item row="11" column="1" colspan="3"> <item row="11" column="1" colspan="3">
<widget class="QLabel" name="label_15"> <widget class="QLabel" name="label_15">
<property name="text"> <property name="text">
<string>These grids are available for selection from the &quot;View&quot; menu</string> <string>These grids are available for selection from the &quot;View&quot; menu and will override the general ones. You can declare one grid as a strong default to enforce an editing grid from this list. To do so, add an exclamation mark to the grid - e.g. &quot;0.01!,0.02,0.05&quot;.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -175,9 +175,11 @@ MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled)
m_disable_tab_selected (false), m_disable_tab_selected (false),
m_exited (false), m_exited (false),
dm_do_update_menu (this, &MainWindow::do_update_menu), dm_do_update_menu (this, &MainWindow::do_update_menu),
dm_do_update_grids (this, &MainWindow::do_update_grids),
dm_do_update_mru_menus (this, &MainWindow::do_update_mru_menus), dm_do_update_mru_menus (this, &MainWindow::do_update_mru_menus),
dm_exit (this, &MainWindow::exit), dm_exit (this, &MainWindow::exit),
m_grid_micron (0.001), m_grid_micron (0.001),
m_default_grid (0.0),
m_default_grids_updated (true), m_default_grids_updated (true),
m_new_layout_current_panel (false), m_new_layout_current_panel (false),
m_synchronized_views (false), m_synchronized_views (false),
@ -583,7 +585,7 @@ MainWindow::technology_changed ()
} }
m_default_grids_updated = true; // potentially ... m_default_grids_updated = true; // potentially ...
dm_do_update_menu (); dm_do_update_grids ();
} }
void void
@ -939,7 +941,7 @@ MainWindow::config_finalize ()
// Update the default grids menu if necessary // Update the default grids menu if necessary
if (m_default_grids_updated) { if (m_default_grids_updated) {
dm_do_update_menu (); dm_do_update_grids ();
} }
// make the changes visible in the setup form if the form is visible // make the changes visible in the setup form if the form is visible
@ -972,6 +974,7 @@ MainWindow::configure (const std::string &name, const std::string &value)
tl::Extractor ex (value.c_str ()); tl::Extractor ex (value.c_str ());
m_default_grids.clear (); m_default_grids.clear ();
m_default_grid = 0.0;
m_default_grids_updated = true; m_default_grids_updated = true;
// convert the list of grids to a list of doubles // convert the list of grids to a list of doubles
@ -980,6 +983,9 @@ MainWindow::configure (const std::string &name, const std::string &value)
if (! ex.try_read (g)) { if (! ex.try_read (g)) {
break; break;
} }
if (ex.test ("!")) {
m_default_grid = g;
}
m_default_grids.push_back (g); m_default_grids.push_back (g);
ex.test (","); ex.test (",");
} }
@ -4041,6 +4047,38 @@ MainWindow::menu_changed ()
dm_do_update_menu (); dm_do_update_menu ();
} }
void
MainWindow::do_update_grids ()
{
const std::vector<double> *grids = &m_default_grids;
double default_grid = m_default_grid;
std::vector<double> tech_grids;
lay::TechnologyController *tc = lay::TechnologyController::instance ();
if (tc && tc->active_technology ()) {
tech_grids = tc->active_technology ()->default_grid_list ();
if (! tech_grids.empty ()) {
grids = &tech_grids;
default_grid = tc->active_technology ()->default_grid ();
}
}
if (default_grid > db::epsilon) {
for (auto g = grids->begin (); g != grids->end (); ++g) {
if (db::coord_traits<db::DCoord>::equals (*g, m_grid_micron)) {
default_grid = 0.0;
break;
}
}
}
if (default_grid > db::epsilon) {
dispatcher ()->config_set (cfg_grid, default_grid);
}
do_update_menu ();
}
void void
MainWindow::do_update_menu () MainWindow::do_update_menu ()
{ {
@ -4082,7 +4120,7 @@ MainWindow::do_update_menu ()
lay::Action *ga = new lay::ConfigureAction (gs, cfg_grid, tl::to_string (*g)); lay::Action *ga = new lay::ConfigureAction (gs, cfg_grid, tl::to_string (*g));
ga->set_checkable (true); ga->set_checkable (true);
ga->set_checked (fabs (*g - m_grid_micron) < 1e-10); ga->set_checked (db::coord_traits<db::DCoord>::equals (*g, m_grid_micron));
for (std::vector<std::string>::const_iterator t = group.begin (); t != group.end (); ++t) { for (std::vector<std::string>::const_iterator t = group.begin (); t != group.end (); ++t) {
menu ()->insert_item (*t + ".end", name, ga); menu ()->insert_item (*t + ".end", name, ga);

View File

@ -706,6 +706,7 @@ protected slots:
protected: protected:
void update_content (); void update_content ();
void do_update_menu (); void do_update_menu ();
void do_update_grids ();
void do_update_mru_menus (); void do_update_mru_menus ();
bool eventFilter (QObject *watched, QEvent *event); bool eventFilter (QObject *watched, QEvent *event);
@ -753,6 +754,7 @@ private:
bool m_disable_tab_selected; bool m_disable_tab_selected;
bool m_exited; bool m_exited;
tl::DeferredMethod<MainWindow> dm_do_update_menu; tl::DeferredMethod<MainWindow> dm_do_update_menu;
tl::DeferredMethod<MainWindow> dm_do_update_grids;
tl::DeferredMethod<MainWindow> dm_do_update_mru_menus; tl::DeferredMethod<MainWindow> dm_do_update_mru_menus;
tl::DeferredMethod<MainWindow> dm_exit; tl::DeferredMethod<MainWindow> dm_exit;
QTimer m_message_timer; QTimer m_message_timer;
@ -765,6 +767,7 @@ private:
std::string m_initial_technology; std::string m_initial_technology;
double m_grid_micron; double m_grid_micron;
std::vector<double> m_default_grids; std::vector<double> m_default_grids;
double m_default_grid;
bool m_default_grids_updated; bool m_default_grids_updated;
std::vector<std::pair<std::string, std::string> > m_key_bindings; std::vector<std::pair<std::string, std::string> > m_key_bindings;
bool m_new_layout_current_panel; bool m_new_layout_current_panel;

View File

@ -105,10 +105,29 @@ END
tech.default_grids = [] tech.default_grids = []
assert_equal(tech.default_grids.collect { |g| "%.12g" % g }.join(","), "") assert_equal(tech.default_grids.collect { |g| "%.12g" % g }.join(","), "")
assert_equal("%.12g" % tech.default_grid, "0")
tech.default_grids = [0.001, 0.01, 0.2] tech.default_grids = [0.001, 0.01, 0.2]
assert_equal(tech.default_grids.collect { |g| "%.12g" % g }.join(","), "0.001,0.01,0.2") assert_equal(tech.default_grids.collect { |g| "%.12g" % g }.join(","), "0.001,0.01,0.2")
tech.default_grids = [1] tech.default_grids = [1]
assert_equal(tech.default_grids.collect { |g| "%.12g" % g }.join(","), "1") assert_equal(tech.default_grids.collect { |g| "%.12g" % g }.join(","), "1")
assert_equal("%.12g" % tech.default_grid, "0")
# setting the default grid
tech.set_default_grids([0.01,0.02,0.05], 0.02)
assert_equal(tech.default_grids.collect { |g| "%.12g" % g }.join(","), "0.01,0.02,0.05")
assert_equal("%.12g" % tech.default_grid, "0.02")
# default grid must be a member of the default grid list
tech.set_default_grids([0.01,0.02,0.05], 0.2)
assert_equal(tech.default_grids.collect { |g| "%.12g" % g }.join(","), "0.01,0.02,0.05")
assert_equal("%.12g" % tech.default_grid, "0")
# "default_grids=" resets the default grid
tech.set_default_grids([0.01,0.02,0.05], 0.02)
assert_equal("%.12g" % tech.default_grid, "0.02")
tech.default_grids = [1]
assert_equal(tech.default_grids.collect { |g| "%.12g" % g }.join(","), "1")
assert_equal("%.12g" % tech.default_grid, "0")
tech.default_base_path = "/default/path" tech.default_base_path = "/default/path"
assert_equal(tech.default_base_path, "/default/path") assert_equal(tech.default_base_path, "/default/path")