mirror of https://github.com/KLayout/klayout.git
Implemented relative mode for marker browser config. Can read existing config.
This commit is contained in:
parent
3f80d7bbe1
commit
3642cff120
|
|
@ -28,6 +28,8 @@
|
|||
namespace lay
|
||||
{
|
||||
|
||||
static const double delta = 1e-10;
|
||||
|
||||
Margin::Margin (double value, bool relative)
|
||||
: m_relative_value (0.0), m_absolute_value (0.0), m_relative_mode (relative)
|
||||
{
|
||||
|
|
@ -38,21 +40,27 @@ Margin::Margin (double value, bool relative)
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Margin::operator== (const lay::Margin &other) const
|
||||
{
|
||||
return m_relative_mode == other.m_relative_mode &&
|
||||
fabs (m_absolute_value - other.m_absolute_value) < delta &&
|
||||
fabs (m_relative_value - other.m_relative_value) < delta;
|
||||
}
|
||||
|
||||
std::string
|
||||
Margin::to_string () const
|
||||
{
|
||||
const double min_value = 1e-10;
|
||||
|
||||
std::string res;
|
||||
if (m_relative_mode) {
|
||||
res = std::string ("*") + tl::to_string (m_relative_value);
|
||||
if (fabs (m_absolute_value) > min_value) {
|
||||
if (fabs (m_absolute_value) > delta) {
|
||||
res += " ";
|
||||
res += tl::to_string (m_absolute_value);
|
||||
}
|
||||
} else {
|
||||
res = tl::to_string (m_absolute_value);
|
||||
if (fabs (m_relative_value) > min_value) {
|
||||
if (fabs (m_relative_value) > delta) {
|
||||
res += " *";
|
||||
res += tl::to_string (m_relative_value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,19 @@ public:
|
|||
*/
|
||||
Margin (double value = 0.0, bool relative = false);
|
||||
|
||||
/**
|
||||
* @brief Equality
|
||||
*/
|
||||
bool operator== (const lay::Margin &other) const;
|
||||
|
||||
/**
|
||||
* @brief Inequality
|
||||
*/
|
||||
bool operator!= (const lay::Margin &other) const
|
||||
{
|
||||
return ! operator== (other);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the relative value
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<property name="margin" stdset="0">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
|
|
@ -26,14 +26,15 @@
|
|||
<string>Marker Browser</string>
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
<property name="margin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="2" column="3">
|
||||
<widget class="QLineEdit" name="le_max_markers"/>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Maximum number of markers to show</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<spacer>
|
||||
|
|
@ -87,7 +88,7 @@
|
|||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="4">
|
||||
<item row="0" column="1" colspan="5">
|
||||
<widget class="QComboBox" name="cbx_context">
|
||||
<item>
|
||||
<property name="text">
|
||||
|
|
@ -116,20 +117,6 @@
|
|||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLineEdit" name="le_window">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Maximum number of markers to show</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="textLabel1_3">
|
||||
<property name="text">
|
||||
|
|
@ -137,12 +124,11 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QLabel" name="textLabel2">
|
||||
<property name="text">
|
||||
<string>µm</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item row="2" column="3" colspan="3">
|
||||
<widget class="QLineEdit" name="le_max_markers"/>
|
||||
</item>
|
||||
<item row="1" column="3" colspan="3">
|
||||
<widget class="lay::MarginWidget" name="mgn_window" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
|
@ -150,6 +136,14 @@
|
|||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>lay::MarginWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>layWidgets.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
|||
|
|
@ -1077,6 +1077,81 @@ ColorButton::browse_selected ()
|
|||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// MarginWidget implementation
|
||||
|
||||
MarginWidget::MarginWidget (QWidget *parent, const char *name)
|
||||
: QFrame (parent)
|
||||
{
|
||||
if (name) {
|
||||
setObjectName (name);
|
||||
}
|
||||
|
||||
setFrameStyle (QFrame::NoFrame);
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout (this);
|
||||
layout->setMargin (0);
|
||||
|
||||
QLineEdit *le = new QLineEdit (this);
|
||||
mp_abs_edit = le;
|
||||
le->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Preferred));
|
||||
layout->addWidget (le);
|
||||
|
||||
le = new QLineEdit (this);
|
||||
mp_rel_edit = le;
|
||||
le->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Preferred));
|
||||
layout->addWidget (le);
|
||||
|
||||
QComboBox *mode = new QComboBox (this);
|
||||
mode->addItem (tl::to_qstring ("µm"));
|
||||
mode->addItem (tl::to_qstring ("%"));
|
||||
mode->setCurrentIndex (0);
|
||||
mp_mode_cb = mode;
|
||||
layout->addWidget (mode);
|
||||
|
||||
connect (mode, SIGNAL (currentIndexChanged (int)), this, SLOT (mode_selection_changed ()));
|
||||
|
||||
mode_selection_changed ();
|
||||
}
|
||||
|
||||
lay::Margin
|
||||
MarginWidget::get_margin () const
|
||||
{
|
||||
bool rel_mode = mp_mode_cb->currentIndex () == 1;
|
||||
double rel = 0.0, abs = 0.0;
|
||||
tl::from_string (tl::to_string (mp_rel_edit->text ()), rel);
|
||||
tl::from_string (tl::to_string (mp_abs_edit->text ()), abs);
|
||||
|
||||
lay::Margin m;
|
||||
m.set_relative_mode (rel_mode);
|
||||
m.set_absolute_value (abs);
|
||||
m.set_relative_value (rel * 0.01);
|
||||
return m;
|
||||
}
|
||||
|
||||
void
|
||||
MarginWidget::set_margin (const lay::Margin &margin)
|
||||
{
|
||||
mp_abs_edit->setText (tl::to_qstring (tl::to_string (margin.absolute_value ())));
|
||||
mp_rel_edit->setText (tl::to_qstring (tl::to_string (margin.relative_value () * 100.0)));
|
||||
mp_mode_cb->setCurrentIndex (margin.relative_mode () ? 1 : 0);
|
||||
mode_selection_changed ();
|
||||
}
|
||||
|
||||
void
|
||||
MarginWidget::mode_selection_changed ()
|
||||
{
|
||||
bool rel_mode = mp_mode_cb->currentIndex () == 1;
|
||||
// NOTE: first hiding and then showing avoids layout flicker ..
|
||||
mp_rel_edit->hide ();
|
||||
mp_abs_edit->hide ();
|
||||
if (rel_mode) {
|
||||
mp_rel_edit->show ();
|
||||
} else {
|
||||
mp_abs_edit->show ();
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// DecoratedLineEdit implementation
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#define HDR_layWidgets
|
||||
|
||||
#include "layuiCommon.h"
|
||||
#include "layMargin.h"
|
||||
|
||||
#include "tlObject.h"
|
||||
#include "tlDeferredExecution.h"
|
||||
|
|
@ -316,6 +317,32 @@ private slots:
|
|||
virtual void selected ();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Margin edit box
|
||||
*
|
||||
* This class implements a special widget to edit a lay::Margin object.
|
||||
* This object allows specification of a relative or absolute margin.
|
||||
*/
|
||||
class LAYUI_PUBLIC MarginWidget
|
||||
: public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MarginWidget (QWidget *parent, const char *name = 0);
|
||||
|
||||
lay::Margin get_margin () const;
|
||||
void set_margin (const lay::Margin &margin);
|
||||
|
||||
protected slots:
|
||||
void mode_selection_changed ();
|
||||
|
||||
private:
|
||||
QLineEdit *mp_abs_edit;
|
||||
QLineEdit *mp_rel_edit;
|
||||
QComboBox *mp_mode_cb;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Color chooser button
|
||||
*
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include "layConverters.h"
|
||||
#include "layDispatcher.h"
|
||||
#include "layUtils.h"
|
||||
#include "layMargin.h"
|
||||
|
||||
#include "ui_MarkerBrowserConfigPage.h"
|
||||
#include "ui_MarkerBrowserConfigPage2.h"
|
||||
|
|
@ -159,9 +160,11 @@ MarkerBrowserConfigPage::setup (lay::Dispatcher *root)
|
|||
mp_ui->cbx_window->setCurrentIndex (int (wmode));
|
||||
|
||||
// window dimension
|
||||
double wdim = 1.0;
|
||||
root->config_get (cfg_rdb_window_dim, wdim);
|
||||
mp_ui->le_window->setText (tl::to_qstring (tl::to_string (wdim)));
|
||||
lay::Margin wdim (1.0);
|
||||
std::string wdim_str = wdim.to_string ();
|
||||
root->config_get (cfg_rdb_window_dim, wdim_str);
|
||||
wdim = lay::Margin::from_string (wdim_str);
|
||||
mp_ui->mgn_window->set_margin (wdim);
|
||||
|
||||
// max. marker count
|
||||
unsigned int max_marker_count = 1000;
|
||||
|
|
@ -175,21 +178,18 @@ MarkerBrowserConfigPage::setup (lay::Dispatcher *root)
|
|||
void
|
||||
MarkerBrowserConfigPage::window_changed (int m)
|
||||
{
|
||||
mp_ui->le_window->setEnabled (m == int (rdb::FitMarker) || m == int (rdb::CenterSize));
|
||||
mp_ui->mgn_window->setEnabled (m == int (rdb::FitMarker) || m == int (rdb::CenterSize));
|
||||
}
|
||||
|
||||
void
|
||||
MarkerBrowserConfigPage::commit (lay::Dispatcher *root)
|
||||
{
|
||||
double dim = 1.0;
|
||||
tl::from_string_ext (tl::to_string (mp_ui->le_window->text ()), dim);
|
||||
|
||||
unsigned int max_markers_count = 1000;
|
||||
tl::from_string_ext (tl::to_string (mp_ui->le_max_markers->text ()), max_markers_count);
|
||||
|
||||
root->config_set (cfg_rdb_context_mode, rdb::context_mode_type (mp_ui->cbx_context->currentIndex ()), MarkerBrowserContextModeConverter ());
|
||||
root->config_set (cfg_rdb_window_mode, rdb::window_type (mp_ui->cbx_window->currentIndex ()), MarkerBrowserWindowModeConverter ());
|
||||
root->config_set (cfg_rdb_window_dim, dim);
|
||||
root->config_set (cfg_rdb_window_dim, mp_ui->mgn_window->get_margin ().to_string ());
|
||||
root->config_set (cfg_rdb_max_marker_count, max_markers_count);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -470,9 +470,8 @@ MarkerBrowserDialog::configure (const std::string &name, const std::string &valu
|
|||
|
||||
} else if (name == cfg_rdb_window_dim) {
|
||||
|
||||
double wdim = m_window_dim;
|
||||
tl::from_string (value, wdim);
|
||||
if (fabs (wdim - m_window_dim) > 1e-6) {
|
||||
lay::Margin wdim = lay::Margin::from_string (value);
|
||||
if (wdim != m_window_dim) {
|
||||
m_window_dim = wdim;
|
||||
need_update = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "layuiCommon.h"
|
||||
#include "layBrowser.h"
|
||||
#include "layMargin.h"
|
||||
#include "tlColor.h"
|
||||
#include "rdbMarkerBrowser.h"
|
||||
|
||||
|
|
@ -78,7 +79,7 @@ private:
|
|||
Ui::MarkerBrowserDialog *mp_ui;
|
||||
context_mode_type m_context;
|
||||
window_type m_window;
|
||||
double m_window_dim;
|
||||
lay::Margin m_window_dim;
|
||||
unsigned int m_max_marker_count;
|
||||
tl::Color m_marker_color;
|
||||
int m_marker_line_width;
|
||||
|
|
|
|||
|
|
@ -1838,7 +1838,7 @@ MarkerBrowserPage::marker_double_clicked (const QModelIndex &)
|
|||
}
|
||||
|
||||
void
|
||||
MarkerBrowserPage::set_window (rdb::window_type window, double window_dim, rdb::context_mode_type context)
|
||||
MarkerBrowserPage::set_window (rdb::window_type window, const lay::Margin &window_dim, rdb::context_mode_type context)
|
||||
{
|
||||
if (window != m_window || window_dim != m_window_dim || context != m_context) {
|
||||
m_window = window;
|
||||
|
|
@ -2280,15 +2280,17 @@ MarkerBrowserPage::do_update_markers ()
|
|||
|
||||
if (mp_view && ! m_markers_bbox.empty ()) {
|
||||
|
||||
double wdim = m_window_dim.get (m_markers_bbox);
|
||||
|
||||
if (m_window == FitCell) {
|
||||
mp_view->zoom_fit ();
|
||||
} else if (m_window == FitMarker) {
|
||||
mp_view->zoom_box (m_markers_bbox.enlarged (db::DVector (m_window_dim, m_window_dim)));
|
||||
mp_view->zoom_box (m_markers_bbox.enlarged (db::DVector (wdim, wdim)));
|
||||
} else if (m_window == Center) {
|
||||
mp_view->pan_center (m_markers_bbox.p1 () + (m_markers_bbox.p2 () - m_markers_bbox.p1 ()) * 0.5);
|
||||
} else if (m_window == CenterSize) {
|
||||
double w = std::max (m_markers_bbox.width (), m_window_dim);
|
||||
double h = std::max (m_markers_bbox.height (), m_window_dim);
|
||||
double w = std::max (m_markers_bbox.width (), wdim);
|
||||
double h = std::max (m_markers_bbox.height (), wdim);
|
||||
db::DPoint center (m_markers_bbox.p1 () + (m_markers_bbox.p2 () - m_markers_bbox.p1 ()) * 0.5);
|
||||
db::DVector d (w * 0.5, h * 0.5);
|
||||
mp_view->zoom_box (db::DBox (center - d, center + d));
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "ui_MarkerBrowserPage.h"
|
||||
#include "rdbMarkerBrowser.h"
|
||||
#include "layMargin.h"
|
||||
#include "tlDeferredExecution.h"
|
||||
#include "tlColor.h"
|
||||
#include "dbBox.h"
|
||||
|
|
@ -137,7 +138,7 @@ public:
|
|||
/**
|
||||
* @brief Set the window type and window dimensions
|
||||
*/
|
||||
void set_window (rdb::window_type window_type, double window_dim, rdb::context_mode_type context);
|
||||
void set_window (rdb::window_type window_type, const lay::Margin &window_dim, rdb::context_mode_type context);
|
||||
|
||||
/**
|
||||
* @brief Set the maximum number of markers shown in the marker selection list
|
||||
|
|
@ -212,7 +213,7 @@ private:
|
|||
bool m_in_directory_selection_change;
|
||||
rdb::context_mode_type m_context;
|
||||
rdb::window_type m_window;
|
||||
double m_window_dim;
|
||||
lay::Margin m_window_dim;
|
||||
size_t m_max_marker_count;
|
||||
tl::Color m_marker_color;
|
||||
int m_marker_line_width;
|
||||
|
|
|
|||
Loading…
Reference in New Issue