diff --git a/src/laybasic/laybasic/laybasicConfig.h b/src/laybasic/laybasic/laybasicConfig.h
index 1b33e6455..eb99c9d4b 100644
--- a/src/laybasic/laybasic/laybasicConfig.h
+++ b/src/laybasic/laybasic/laybasicConfig.h
@@ -43,6 +43,7 @@ static const std::string cfg_grid_grid_color ("grid-grid-color");
static const std::string cfg_grid_style0 ("grid-style0");
static const std::string cfg_grid_style1 ("grid-style1");
static const std::string cfg_grid_style2 ("grid-style2");
+static const std::string cfg_grid_density ("grid-density");
static const std::string cfg_grid_visible ("grid-visible");
static const std::string cfg_grid_micron ("grid-micron");
static const std::string cfg_grid_show_ruler ("grid-show-ruler");
diff --git a/src/layview/layview/GridNetConfigPage.ui b/src/layview/layview/GridNetConfigPage.ui
index 34db49143..427129ba0 100644
--- a/src/layview/layview/GridNetConfigPage.ui
+++ b/src/layview/layview/GridNetConfigPage.ui
@@ -7,7 +7,7 @@
0
0
483
- 341
+ 361
@@ -59,6 +59,23 @@
6
+ -
+
+
+ Far style
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+ Show ruler
+
+
+
-
-
@@ -108,7 +125,122 @@
- -
+
-
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+ Grid
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+
+ -
+
+
+ Ruler
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+ Axis
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+ Close style
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+ Color (all)
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
+
+
+
+ -
Color
@@ -118,14 +250,17 @@
- -
-
-
- Qt::Horizontal
+
-
+
+
+ Style
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
- -
+
-
-
@@ -169,30 +304,23 @@
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
+
-
+
-
+ Color
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
- -
-
-
- Qt::Horizontal
+
-
+
+
+ Color
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
@@ -245,141 +373,37 @@
- -
-
-
- Far style
-
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
-
-
-
- -
-
-
- Close style
-
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
-
-
-
- -
-
-
- Color (all)
-
-
- Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
-
-
-
- -
-
-
-
-
-
-
- -
-
-
- Grid
-
-
-
- -
-
-
- Show Ruler
-
-
-
- -
-
-
-
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
- Style
-
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
-
-
-
- -
-
-
- Color
-
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
-
-
-
- -
-
-
- Axis
-
-
-
- -
-
-
- Color
-
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
-
-
-
- -
-
-
- Ruler
-
-
-
- -
+
-
Qt::Horizontal
+ -
+
+
+ 1
+
+
+
+ -
+
+
+ Min. spacing
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+ (Font height units)
+
+
+
diff --git a/src/layview/layview/layGridNet.cc b/src/layview/layview/layGridNet.cc
index 2cc8c85a2..b960579b1 100644
--- a/src/layview/layview/layGridNet.cc
+++ b/src/layview/layview/layGridNet.cc
@@ -41,6 +41,8 @@ namespace lay
// ------------------------------------------------------------
// Helper functions to get and set the configuration
+int default_density = 4;
+
static struct {
lay::GridNet::GridStyle style;
const char *string;
@@ -79,6 +81,20 @@ GridNetStyleConverter::to_string (lay::GridNet::GridStyle style)
return "";
}
+void
+GridNetDensityConverter::from_string (const std::string &value, int &density)
+{
+ density = default_density; // original default
+ tl::Extractor ex (value.c_str ());
+ ex.try_read (density);
+}
+
+std::string
+GridNetDensityConverter::to_string (int density)
+{
+ return tl::to_string (density);
+}
+
// ------------------------------------------------------------
// Implementation of the GridNetPluginDeclaration
@@ -92,6 +108,7 @@ GridNetPluginDeclaration::get_options (std::vector < std::pair (cfg_grid_style0, GridNetStyleConverter ().to_string (lay::GridNet::Invisible)));
options.push_back (std::pair (cfg_grid_style1, GridNetStyleConverter ().to_string (lay::GridNet::Dots)));
options.push_back (std::pair (cfg_grid_style2, GridNetStyleConverter ().to_string (lay::GridNet::TenthDottedLines)));
+ options.push_back (std::pair (cfg_grid_density, ""));
options.push_back (std::pair (cfg_grid_visible, tl::to_string (true)));
options.push_back (std::pair (cfg_grid_show_ruler, tl::to_string (true)));
// grid-micron is not configured here since some other entity is supposed to do this.
@@ -122,7 +139,8 @@ GridNet::GridNet (LayoutViewBase *view)
lay::Plugin (view),
mp_view (view),
m_visible (false), m_show_ruler (true), m_grid (1.0),
- m_style0 (Invisible), m_style1 (Invisible), m_style2 (Invisible)
+ m_style0 (Invisible), m_style1 (Invisible), m_style2 (Invisible),
+ m_density (default_density)
{
// .. nothing yet ..
}
@@ -175,6 +193,12 @@ GridNet::configure (const std::string &name, const std::string &value)
GridNetStyleConverter ().from_string (value, style);
need_update = test_and_set (m_style2, style);
+ } else if (name == cfg_grid_density) {
+
+ int density = 0;
+ GridNetDensityConverter ().from_string (value, density);
+ need_update = test_and_set (m_density, density);
+
} else if (name == cfg_grid_show_ruler) {
bool sr = false;
@@ -246,13 +270,14 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
// fw is the basic unit of the ruler geometry
int fwr = lay::FixedFont::get_font (bmp_canvas->font_resolution ()).width ();
+ int threshold = std::min (1000, m_density * fwr);
double dgrid = trans.ctrans (m_grid);
GridStyle style = m_style1;
// compute major grid and switch to secondary style if necessary
int s = 0;
- while (dgrid < fwr * 4) {
+ while (dgrid < threshold) {
if (s == 0) {
dgrid *= 2.0;
} else if (s == 1) {
@@ -279,56 +304,6 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
int nx = int (dbworld.width () / grid + eps) + 2;
int ny = int (dbworld.height () / grid + eps) + 2;
- if (m_show_ruler && dgrid < vp.width () * 0.2) {
-
- int rh = int (floor (0.5 + fwr * 0.8));
- int xoffset = int (floor (0.5 + fwr * 2.5));
- int yoffset = int (floor (0.5 + fwr * 2.5));
-
- painter.fill_rect (db::Point (xoffset, vp.height () - yoffset - rh / 2),
- db::Point (xoffset + int (floor (0.5 + dgrid)), vp.height () - yoffset + rh / 2),
- ruler_color);
-
- painter.draw_rect (db::Point (xoffset + int (floor (0.5 + dgrid)), vp.height () - yoffset - rh / 2),
- db::Point (xoffset + int (floor (0.5 + 2 * dgrid)), vp.height () - yoffset + rh / 2),
- ruler_color);
-
- painter.draw_text (tl::sprintf ("%g \265m", grid * 2).c_str (),
- db::Point (xoffset + int (floor (0.5 + trans.ctrans (2 * grid))), vp.height () - yoffset - rh / 2 - 2),
- ruler_color, -1, 1);
-
- if (mp_view->global_trans ().fp_trans () != db::DFTrans ()) {
-
- // draw a small "F" indicating any global transformation
- db::Point pts[] = {
- db::Point (-4, -5),
- db::Point (-4, 5),
- db::Point (4, 5),
- db::Point (4, 3),
- db::Point (-2, 3),
- db::Point (-2, 1),
- db::Point (3, 1),
- db::Point (3, -1),
- db::Point (-2, -1),
- db::Point (-2, -5),
- db::Point (-4, -5)
- };
-
- db::Polygon poly;
- poly.assign_hull (&pts[0], &pts[0] + (sizeof (pts) / sizeof (pts[0])));
- poly.transform (db::FTrans (mp_view->global_trans ().fp_trans ()));
-
- for (db::Polygon::polygon_edge_iterator e = poly.begin_edge (); !e.at_end (); ++e) {
- db::Point p0 (xoffset + 2 * rh, vp.height () - yoffset - rh * 5);
- db::Point p1 = p0 + db::Vector (int (floor (0.5 + (*e).p1 ().x () * 0.1 * rh * 4)), -int (floor (0.5 + (*e).p1 ().y () * 0.1 * rh * 4)));
- db::Point p2 = p0 + db::Vector (int (floor (0.5 + (*e).p2 ().x () * 0.1 * rh * 4)), -int (floor (0.5 + (*e).p2 ().y () * 0.1 * rh * 4)));
- painter.draw_line (p1, p2, ruler_color);
- }
-
- }
-
- }
-
// draw grid
if (style == Dots || style == TenthDottedLines ||
style == DottedLines || style == LightDottedLines) {
@@ -549,6 +524,56 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
}
+ if (m_show_ruler && dgrid < vp.width () * 0.4) {
+
+ int rh = int (floor (0.5 + fwr * 0.8));
+ int xoffset = int (floor (0.5 + fwr * 2.5));
+ int yoffset = int (floor (0.5 + fwr * 2.5));
+
+ painter.fill_rect (db::Point (xoffset, vp.height () - yoffset - rh / 2),
+ db::Point (xoffset + int (floor (0.5 + dgrid)), vp.height () - yoffset + rh / 2),
+ ruler_color);
+
+ painter.draw_rect (db::Point (xoffset + int (floor (0.5 + dgrid)), vp.height () - yoffset - rh / 2),
+ db::Point (xoffset + int (floor (0.5 + 2 * dgrid)), vp.height () - yoffset + rh / 2),
+ ruler_color);
+
+ painter.draw_text (tl::sprintf ("%g \265m", grid * 2).c_str (),
+ db::Point (xoffset + int (floor (0.5 + trans.ctrans (2 * grid))), vp.height () - yoffset - rh / 2 - 2),
+ ruler_color, -1, 1);
+
+ if (mp_view->global_trans ().fp_trans () != db::DFTrans ()) {
+
+ // draw a small "F" indicating any global transformation
+ db::Point pts[] = {
+ db::Point (-4, -5),
+ db::Point (-4, 5),
+ db::Point (4, 5),
+ db::Point (4, 3),
+ db::Point (-2, 3),
+ db::Point (-2, 1),
+ db::Point (3, 1),
+ db::Point (3, -1),
+ db::Point (-2, -1),
+ db::Point (-2, -5),
+ db::Point (-4, -5)
+ };
+
+ db::Polygon poly;
+ poly.assign_hull (&pts[0], &pts[0] + (sizeof (pts) / sizeof (pts[0])));
+ poly.transform (db::FTrans (mp_view->global_trans ().fp_trans ()));
+
+ for (db::Polygon::polygon_edge_iterator e = poly.begin_edge (); !e.at_end (); ++e) {
+ db::Point p0 (xoffset + 2 * rh, vp.height () - yoffset - rh * 5);
+ db::Point p1 = p0 + db::Vector (int (floor (0.5 + (*e).p1 ().x () * 0.1 * rh * 4)), -int (floor (0.5 + (*e).p1 ().y () * 0.1 * rh * 4)));
+ db::Point p2 = p0 + db::Vector (int (floor (0.5 + (*e).p2 ().x () * 0.1 * rh * 4)), -int (floor (0.5 + (*e).p2 ().y () * 0.1 * rh * 4)));
+ painter.draw_line (p1, p2, ruler_color);
+ }
+
+ }
+
+ }
+
}
}
diff --git a/src/layview/layview/layGridNet.h b/src/layview/layview/layGridNet.h
index 89b63c3f0..d75dcde37 100644
--- a/src/layview/layview/layGridNet.h
+++ b/src/layview/layview/layGridNet.h
@@ -87,6 +87,7 @@ private:
GridStyle m_style0;
GridStyle m_style1;
GridStyle m_style2;
+ int m_density;
};
class GridNetStyleConverter
@@ -96,6 +97,13 @@ public:
std::string to_string (lay::GridNet::GridStyle style);
};
+class GridNetDensityConverter
+{
+public:
+ void from_string (const std::string &value, int &density);
+ std::string to_string (int density);
+};
+
}
#endif
diff --git a/src/layview/layview/layGridNetConfigPage.cc b/src/layview/layview/layGridNetConfigPage.cc
index 6736f72f1..900a31b53 100644
--- a/src/layview/layview/layGridNetConfigPage.cc
+++ b/src/layview/layview/layGridNetConfigPage.cc
@@ -94,6 +94,10 @@ GridNetConfigPage::setup (lay::Dispatcher *root)
style = lay::GridNet::Invisible;
root->config_get (cfg_grid_style2, style, GridNetStyleConverter ());
mp_ui->style2_cbx->setCurrentIndex (int (style));
+
+ int density = 0;
+ root->config_get (cfg_grid_density, density, GridNetDensityConverter ());
+ mp_ui->grid_density_sb->setValue (density);
}
void
@@ -108,6 +112,7 @@ GridNetConfigPage::commit (lay::Dispatcher *root)
root->config_set (cfg_grid_style0, lay::GridNet::GridStyle (mp_ui->style0_cbx->currentIndex ()), GridNetStyleConverter ());
root->config_set (cfg_grid_style1, lay::GridNet::GridStyle (mp_ui->style1_cbx->currentIndex ()), GridNetStyleConverter ());
root->config_set (cfg_grid_style2, lay::GridNet::GridStyle (mp_ui->style2_cbx->currentIndex ()), GridNetStyleConverter ());
+ root->config_set (cfg_grid_density, mp_ui->grid_density_sb->value (), GridNetDensityConverter ());
}
} // namespace lay