mirror of https://github.com/KLayout/klayout.git
Implemented fix for issue-1662 (Strong default grids)
This commit is contained in:
parent
3b0a34b955
commit
376058f34b
|
|
@ -347,12 +347,10 @@ Technology::get_display_string () const
|
|||
return d;
|
||||
}
|
||||
|
||||
std::vector<double>
|
||||
Technology::default_grid_list () const
|
||||
static void
|
||||
parse_default_grids (const std::string &s, std::vector<double> &grids, double &default_grid)
|
||||
{
|
||||
tl::Extractor ex (m_default_grids.c_str ());
|
||||
|
||||
std::vector<double> grids;
|
||||
tl::Extractor ex (s.c_str ());
|
||||
|
||||
// convert the list of grids to a list of doubles
|
||||
while (! ex.at_end ()) {
|
||||
|
|
@ -361,12 +359,32 @@ Technology::default_grid_list () const
|
|||
break;
|
||||
}
|
||||
grids.push_back (g);
|
||||
if (ex.test ("!")) {
|
||||
default_grid = g;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
Technology::xml_elements ()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -480,6 +480,15 @@ public:
|
|||
*/
|
||||
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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
||||
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;
|
||||
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 += tl::micron_to_string (*g);
|
||||
if (db::coord_traits<db::DCoord>::equals (*g, default_grid)) {
|
||||
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::method ("name", &db::Technology::name,
|
||||
"@brief Gets the name of the technology"
|
||||
|
|
@ -238,12 +247,32 @@ gsi::Class<db::Technology> technology_decl ("db", "Technology",
|
|||
"\n"
|
||||
"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"),
|
||||
"@brief Sets the default grids\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"
|
||||
"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,
|
||||
"@brief Gets the path of the layer properties file\n"
|
||||
"\n"
|
||||
|
|
|
|||
|
|
@ -1,67 +1,75 @@
|
|||
<ui version="4.0" >
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainConfigPage3</class>
|
||||
<widget class="QFrame" name="MainConfigPage3" >
|
||||
<property name="geometry" >
|
||||
<widget class="QFrame" name="MainConfigPage3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>475</width>
|
||||
<height>81</height>
|
||||
<width>504</width>
|
||||
<height>180</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<property name="windowTitle">
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="margin" >
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<layout class="QVBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" stdset="0">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<property name="title" >
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Default Grids</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<layout class="QGridLayout">
|
||||
<property name="margin" stdset="0">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="2" >
|
||||
<widget class="QLabel" name="textLabel1_4" >
|
||||
<property name="text" >
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="textLabel1">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Grids for "View" menu</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="textLabel1_4">
|
||||
<property name="text">
|
||||
<string>µm (g1,g2,...)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" >
|
||||
<widget class="QLineEdit" name="grids_edit" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>7</hsizetype>
|
||||
<vsizetype>0</vsizetype>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="grids_edit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" >
|
||||
<widget class="QLabel" name="textLabel1" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>5</hsizetype>
|
||||
<vsizetype>5</vsizetype>
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string><html>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. "0.01!,0.02,0.05".
|
||||
<br/><b>Note</b>: the general default grids can be overridden by technology specific default grids.</html></string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Grids for "View" menu</string>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
@ -70,7 +78,7 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11" />
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>625</width>
|
||||
<height>587</height>
|
||||
<height>616</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
|
@ -331,6 +331,9 @@ properties</string>
|
|||
<property name="text">
|
||||
<string>The default database unit is used as database unit for freshly created layouts</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="0" colspan="4">
|
||||
|
|
@ -352,7 +355,10 @@ properties</string>
|
|||
<item row="11" column="1" colspan="3">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="text">
|
||||
<string>These grids are available for selection from the "View" menu</string>
|
||||
<string>These grids are available for selection from the "View" 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. "0.01!,0.02,0.05".</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
|||
|
|
@ -175,9 +175,11 @@ MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled)
|
|||
m_disable_tab_selected (false),
|
||||
m_exited (false),
|
||||
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_exit (this, &MainWindow::exit),
|
||||
m_grid_micron (0.001),
|
||||
m_default_grid (0.0),
|
||||
m_default_grids_updated (true),
|
||||
m_new_layout_current_panel (false),
|
||||
m_synchronized_views (false),
|
||||
|
|
@ -583,7 +585,7 @@ MainWindow::technology_changed ()
|
|||
}
|
||||
|
||||
m_default_grids_updated = true; // potentially ...
|
||||
dm_do_update_menu ();
|
||||
dm_do_update_grids ();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -939,7 +941,7 @@ MainWindow::config_finalize ()
|
|||
|
||||
// Update the default grids menu if necessary
|
||||
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
|
||||
|
|
@ -972,6 +974,7 @@ MainWindow::configure (const std::string &name, const std::string &value)
|
|||
|
||||
tl::Extractor ex (value.c_str ());
|
||||
m_default_grids.clear ();
|
||||
m_default_grid = 0.0;
|
||||
m_default_grids_updated = true;
|
||||
|
||||
// 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)) {
|
||||
break;
|
||||
}
|
||||
if (ex.test ("!")) {
|
||||
m_default_grid = g;
|
||||
}
|
||||
m_default_grids.push_back (g);
|
||||
ex.test (",");
|
||||
}
|
||||
|
|
@ -4041,6 +4047,38 @@ MainWindow::menu_changed ()
|
|||
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
|
||||
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));
|
||||
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) {
|
||||
menu ()->insert_item (*t + ".end", name, ga);
|
||||
|
|
|
|||
|
|
@ -706,6 +706,7 @@ protected slots:
|
|||
protected:
|
||||
void update_content ();
|
||||
void do_update_menu ();
|
||||
void do_update_grids ();
|
||||
void do_update_mru_menus ();
|
||||
bool eventFilter (QObject *watched, QEvent *event);
|
||||
|
||||
|
|
@ -753,6 +754,7 @@ private:
|
|||
bool m_disable_tab_selected;
|
||||
bool m_exited;
|
||||
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_exit;
|
||||
QTimer m_message_timer;
|
||||
|
|
@ -765,6 +767,7 @@ private:
|
|||
std::string m_initial_technology;
|
||||
double m_grid_micron;
|
||||
std::vector<double> m_default_grids;
|
||||
double m_default_grid;
|
||||
bool m_default_grids_updated;
|
||||
std::vector<std::pair<std::string, std::string> > m_key_bindings;
|
||||
bool m_new_layout_current_panel;
|
||||
|
|
|
|||
|
|
@ -105,10 +105,29 @@ END
|
|||
|
||||
tech.default_grids = []
|
||||
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]
|
||||
assert_equal(tech.default_grids.collect { |g| "%.12g" % g }.join(","), "0.001,0.01,0.2")
|
||||
tech.default_grids = [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"
|
||||
assert_equal(tech.default_base_path, "/default/path")
|
||||
|
|
|
|||
Loading…
Reference in New Issue