From eecb62906ca8c81efe092db6979e107b33565422 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 18 Jun 2019 00:50:21 +0200 Subject: [PATCH] Fixed #271 (proposal, more choices for the cell origin on 'make cell') --- src/edt/edt/MakeCellOptionsDialog.ui | 372 ++++++++++++++++-- src/edt/edt/edtDialogs.cc | 54 ++- src/edt/edt/edtDialogs.h | 11 +- src/edt/edt/edtMainService.cc | 17 +- src/edt/edt/edtMainService.h | 2 + src/klayout.pro | 3 + .../laybasic/AlignCellOptionsDialog.ui | 288 ++++++++------ 7 files changed, 580 insertions(+), 167 deletions(-) diff --git a/src/edt/edt/MakeCellOptionsDialog.ui b/src/edt/edt/MakeCellOptionsDialog.ui index 231fc8443..9f9d2ba33 100644 --- a/src/edt/edt/MakeCellOptionsDialog.ui +++ b/src/edt/edt/MakeCellOptionsDialog.ui @@ -1,55 +1,351 @@ - + + MakeCellOptionsDialog - - + + 0 0 - 462 - 159 + 483 + 367 - - Dialog + + Make Cell - - - 9 - - + + 6 + + 9 + + + 9 + + + 9 + + + 9 + - - - Make Cell + + + Name of cell to make from selected shapes and instances: - - - 9 - - + + 6 + + 9 + + + 9 + + + 9 + + + 9 + - - - Name of cell to make from selected shapes and instances: - - + + + + + + + + + 0 + 0 + + + + Put origin relative to cell's bounding bo&x at ... + + + true + + - + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 6 + + + 9 + + + 9 + + + 9 + + + 9 + + + + + Qt::Horizontal + + + + 64 + 20 + + + + + + + + QFrame::Box + + + QFrame::Plain + + + + 15 + + + 15 + + + 15 + + + 15 + + + 6 + + + + + ... + + + + :/ct.png:/ct.png + + + + 31 + 31 + + + + true + + + + + + + ... + + + + :/lt.png:/lt.png + + + + 31 + 31 + + + + true + + + + + + + ... + + + + :/rt.png:/rt.png + + + + 31 + 31 + + + + true + + + + + + + ... + + + + :/lc.png:/lc.png + + + + 31 + 31 + + + + true + + + + + + + ... + + + + :/cc.png:/cc.png + + + + 31 + 31 + + + + true + + + + + + + ... + + + + :/rc.png:/rc.png + + + + 31 + 31 + + + + true + + + + + + + ... + + + + :/lb.png:/lb.png + + + + 31 + 31 + + + + true + + + + + + + ... + + + + :/cb.png:/cb.png + + + + 31 + 31 + + + + true + + + + + + + ... + + + + :/rb.png:/rb.png + + + + 31 + 31 + + + + true + + + + + + + + + + Qt::Horizontal + + + + 88 + 20 + + + + + + - + Qt::Vertical - + 20 16 @@ -58,18 +354,20 @@ - - + + Qt::Horizontal - - QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - + + + buttonBox @@ -77,11 +375,11 @@ MakeCellOptionsDialog accept() - + 248 254 - + 157 274 @@ -93,11 +391,11 @@ MakeCellOptionsDialog reject() - + 316 260 - + 286 274 diff --git a/src/edt/edt/edtDialogs.cc b/src/edt/edt/edtDialogs.cc index 9755f19d9..b1a932cba 100644 --- a/src/edt/edt/edtDialogs.cc +++ b/src/edt/edt/edtDialogs.cc @@ -336,28 +336,80 @@ MakeCellOptionsDialog::MakeCellOptionsDialog (QWidget *parent) : QDialog (parent) { setupUi (this); + + setObjectName (QString::fromUtf8 ("make_cell_options_dialog")); + + QToolButton *buttons[3][3] = { { lb, cb, rb }, { lc, cc, rc }, { lt, ct, rt } }; + + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + connect (buttons[i][j], SIGNAL (clicked ()), this, SLOT (button_clicked ())); + } + } } bool -MakeCellOptionsDialog::exec_dialog (const db::Layout &layout, std::string &name) +MakeCellOptionsDialog::exec_dialog (const db::Layout &layout, std::string &name, int &mode_x, int &mode_y) { do { BEGIN_PROTECTED + + QToolButton *buttons[3][3] = { { lb, cb, rb }, { lc, cc, rc }, { lt, ct, rt } }; + + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + buttons[i][j]->setChecked (j - 1 == mode_x && i - 1 == mode_y); + } + } + + origin_groupbox->setChecked (mode_x >= -1); + if (QDialog::exec ()) { + + if (origin_groupbox->isChecked ()) { + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + if (buttons[i][j]->isChecked ()) { + mode_x = j - 1; + mode_y = i - 1; + } + } + } + } else { + mode_x = mode_y = -2; + } + name = tl::to_string (cell_name_le->text ()); if (name.empty ()) { throw tl::Exception (tl::to_string (QObject::tr ("Cell name must not be empty"))); } else if (layout.cell_by_name (name.c_str ()).first) { throw tl::Exception (tl::to_string (QObject::tr ("A cell with that name already exists: ")) + name); } + return true; + } else { return false; } + END_PROTECTED } while (true); } +void +MakeCellOptionsDialog::button_clicked () +{ + QToolButton *buttons[3][3] = { { lb, cb, rb }, { lc, cc, rc }, { lt, ct, rt } }; + + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + if (buttons [i][j] != sender ()) { + buttons [i][j]->setChecked (false); + } + } + } +} + // -------------------------------------------------------------------------------- // RoundCornerOptionsDialog implementation diff --git a/src/edt/edt/edtDialogs.h b/src/edt/edt/edtDialogs.h index 9fc17919b..165cc650a 100644 --- a/src/edt/edt/edtDialogs.h +++ b/src/edt/edt/edtDialogs.h @@ -134,9 +134,14 @@ class MakeCellOptionsDialog : public QDialog, private Ui::MakeCellOptionsDialog { +Q_OBJECT + public: MakeCellOptionsDialog (QWidget *parent); - bool exec_dialog (const db::Layout &layout, std::string &name); + bool exec_dialog (const db::Layout &layout, std::string &name, int &mode_x, int &mode_y); + +private slots: + void button_clicked (); }; /** @@ -146,6 +151,8 @@ class MakeArrayOptionsDialog : public QDialog, private Ui::MakeArrayOptionsDialog { +Q_OBJECT + public: MakeArrayOptionsDialog (QWidget *parent); bool exec_dialog (db::DVector &a, unsigned int &na, db::DVector &b, unsigned int &nb); @@ -160,6 +167,8 @@ class RoundCornerOptionsDialog : public QDialog, private Ui::RoundCornerOptionsDialog { +Q_OBJECT + public: RoundCornerOptionsDialog (QWidget *parent); ~RoundCornerOptionsDialog (); diff --git a/src/edt/edt/edtMainService.cc b/src/edt/edt/edtMainService.cc index 975293cfc..5e572fc5b 100644 --- a/src/edt/edt/edtMainService.cc +++ b/src/edt/edt/edtMainService.cc @@ -58,11 +58,11 @@ MainService::MainService (db::Manager *manager, lay::LayoutView *view, lay::Plug m_flatten_insts_levels (std::numeric_limits::max ()), m_flatten_prune (false), m_align_hmode (0), m_align_vmode (0), m_align_visible_layers (false), + m_origin_mode_x (-1), m_origin_mode_y (-1), m_origin_visible_layers_for_bbox (false), m_array_a (0.0, 1.0), m_array_b (1.0, 0.0), m_array_na (1), m_array_nb (1) -{ - // collect the options pages and build the options dialog - std::vector edt_services = mp_view->get_plugins (); +{ + // .. nothing yet .. } MainService::~MainService () @@ -912,7 +912,7 @@ MainService::cm_make_cell () const lay::CellView &cv = view ()->cellview (cv_index); - if (dialog.exec_dialog (cv->layout (), m_make_cell_name)) { + if (dialog.exec_dialog (cv->layout (), m_make_cell_name, m_origin_mode_x, m_origin_mode_y)) { // Compute the selection's bbox to establish a good origin for the new cell db::Box selection_bbox; @@ -940,8 +940,13 @@ MainService::cm_make_cell () db::Cell &target_cell = cv->layout ().cell (target_ci); // create target cell instance - db::Instance target_cell_inst = cv.cell ()->insert (db::CellInstArray (db::CellInst (target_ci), db::Trans (selection_bbox.lower_left () - db::Point ()))); - db::ICplxTrans to = db::ICplxTrans (db::Trans (db::Point () - selection_bbox.lower_left ())); + db::Vector ref; + if (m_origin_mode_x >= -1) { + ref = db::Vector (selection_bbox.left () + ((m_origin_mode_x + 1) * selection_bbox.width ()) / 2, selection_bbox.bottom () + ((m_origin_mode_y + 1) * selection_bbox.height ()) / 2); + } + + db::Instance target_cell_inst = cv.cell ()->insert (db::CellInstArray (db::CellInst (target_ci), db::Trans (ref))); + db::ICplxTrans to = db::ICplxTrans (db::Trans (-ref)); for (std::vector::const_iterator es = edt_services.begin (); es != edt_services.end (); ++es) { diff --git a/src/edt/edt/edtMainService.h b/src/edt/edt/edtMainService.h index 5f32f493f..67aa8755d 100644 --- a/src/edt/edt/edtMainService.h +++ b/src/edt/edt/edtMainService.h @@ -201,6 +201,8 @@ private: int m_align_vmode; bool m_align_visible_layers; std::string m_make_cell_name; + int m_origin_mode_x, m_origin_mode_y; + bool m_origin_visible_layers_for_bbox; db::DVector m_array_a, m_array_b; unsigned int m_array_na, m_array_nb; diff --git a/src/klayout.pro b/src/klayout.pro index 2ecee1271..e208dd664 100644 --- a/src/klayout.pro +++ b/src/klayout.pro @@ -99,3 +99,6 @@ plugins.depends += lib rdb db } unit_tests.depends += plugins $$MAIN_DEPENDS + +RESOURCES += \ + laybasic/laybasic/layResources.qrc diff --git a/src/laybasic/laybasic/AlignCellOptionsDialog.ui b/src/laybasic/laybasic/AlignCellOptionsDialog.ui index de09130ee..8e556df7b 100644 --- a/src/laybasic/laybasic/AlignCellOptionsDialog.ui +++ b/src/laybasic/laybasic/AlignCellOptionsDialog.ui @@ -1,7 +1,8 @@ - + + AlignCellOptionsDialog - - + + 0 0 @@ -9,52 +10,68 @@ 342 - - Align Cell + + Adjust Cell Origin - - - 9 - - + + 6 + + 9 + + + 9 + + + 9 + + + 9 + - - + + Put origin relative to cell's bounding box at ... - - - - 0 - 0 + + + 0 0 - + QFrame::NoFrame - + QFrame::Raised - - + + + 6 + + 9 - - 6 + + 9 + + + 9 + + + 9 - + Qt::Horizontal - + 64 20 @@ -63,187 +80,205 @@ - - + + QFrame::Box - + QFrame::Plain - - + + 15 - + + 15 + + + 15 + + + 15 + + 6 - - - + + + ... - - :/ct.png + + + :/ct.png:/ct.png - + 31 31 - + true - - - + + + ... - - :/lt.png + + + :/lt.png:/lt.png - + 31 31 - + true - - - + + + ... - - :/rt.png + + + :/rt.png:/rt.png - + 31 31 - + true - - - + + + ... - - :/lc.png + + + :/lc.png:/lc.png - + 31 31 - + true - - - + + + ... - - :/cc.png + + + :/cc.png:/cc.png - + 31 31 - + true - - - + + + ... - - :/rc.png + + + :/rc.png:/rc.png - + 31 31 - + true - - - + + + ... - - :/lb.png + + + :/lb.png:/lb.png - + 31 31 - + true - - - + + + ... - - :/cb.png + + + :/cb.png:/cb.png - + 31 31 - + true - - - + + + ... - - :/rb.png + + + :/rb.png:/rb.png - + 31 31 - + true @@ -253,10 +288,10 @@ - + Qt::Horizontal - + 88 20 @@ -268,28 +303,28 @@ - - + + Use visible layers only for bounding box - - + + Adjust instances in parents - + Qt::Vertical - + QSizePolicy::Fixed - + 20 8 @@ -298,26 +333,35 @@ - - + + QFrame::NoFrame - + QFrame::Raised - - + + + 6 + + 0 - - 6 + + 0 + + + 0 + + + 0 - + Qt::Horizontal - + 209 20 @@ -326,18 +370,18 @@ - - + + Ok - + true - - + + Cancel @@ -362,7 +406,7 @@ vis_only_cbx - + @@ -371,11 +415,11 @@ AlignCellOptionsDialog accept() - + 237 203 - + 147 81 @@ -387,11 +431,11 @@ AlignCellOptionsDialog reject() - + 325 202 - + 325 57