WIP: reworked drag&drop from library view into canvas - now will switch to instance mode and take parameters from the instance options rather than popping up a PCell dialog and using mag 1, no mirror, no rotation etc.

This commit is contained in:
Matthias Koefferlein 2020-08-10 19:51:36 +02:00
parent 701f690053
commit 4ffae9668e
5 changed files with 39 additions and 251 deletions

View File

@ -21,7 +21,6 @@ HEADERS = \
edtServiceImpl.h \
edtUtils.h \
edtCommon.h \
edtPCellParametersDialog.h \
edtDistribute.h
FORMS = \
@ -61,7 +60,6 @@ SOURCES = \
edtServiceImpl.cc \
edtUtils.cc \
gsiDeclEdt.cc \
edtPCellParametersDialog.cc \
edtDistribute.cc
INCLUDEPATH += $$TL_INC $$GSI_INC $$LAYBASIC_INC $$DB_INC

View File

@ -1,65 +0,0 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2020 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "edtPCellParametersDialog.h"
#include <QPushButton>
namespace edt
{
PCellParametersDialog::PCellParametersDialog (QWidget *parent)
: QDialog (parent)
{
setupUi (this);
connect (buttons->button (QDialogButtonBox::Apply), SIGNAL (clicked ()), this, SLOT (apply_pressed ()));
}
void
PCellParametersDialog::apply_pressed ()
{
emit parameters_changed ();
parameters_changed_event ();
}
std::vector<tl::Variant>
PCellParametersDialog::get_parameters ()
{
return parameters->get_parameters ();
}
void
PCellParametersDialog::set_parameters (const std::vector<tl::Variant> &p)
{
parameters->set_parameters (p);
}
int
PCellParametersDialog::exec (const db::Layout *layout, lay::LayoutView *view, int cv_index, const db::PCellDeclaration *pcell_decl, const db::pcell_parameters_type &p)
{
parameters->setup (layout, view, cv_index, pcell_decl, p);
return QDialog::exec ();
}
}

View File

@ -1,86 +0,0 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2020 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef HDR_edtPCellParametersDialog
#define HDR_edtPCellParametersDialog
#include "dbPCellDeclaration.h"
#include "ui_PCellParametersDialog.h"
#include <QDialog>
namespace lay
{
class LayoutView;
}
namespace edt
{
/**
* @brief A QScrollArea that displays and allows editing PCell parameters
*/
class PCellParametersDialog
: public QDialog, private Ui::PCellParametersDialog
{
Q_OBJECT
public:
/**
* @brief Constructor: create a dialog showing the given parameters
* @param parent The parent widget
*/
PCellParametersDialog (QWidget *parent);
/**
* @brief Executes the parameter dialog
* @param layout The layout in which the PCell instance resides
* @param view The layout view from which to take layers for example
* @param cv_index The index of the cellview in "view"
* @param pcell_decl The PCell declaration
* @param parameters The parameter values to show (if empty, the default values are used)
*/
int exec (const db::Layout *layout, lay::LayoutView *view, int cv_index, const db::PCellDeclaration *pcell_decl, const db::pcell_parameters_type &p);
/**
* @brief Get the current parameters
*/
std::vector<tl::Variant> get_parameters ();
/**
* @brief Sets the given parameters as values
*/
void set_parameters (const std::vector<tl::Variant> &values);
tl::Event parameters_changed_event;
signals:
void parameters_changed ();
private slots:
void apply_pressed ();
};
}
#endif

View File

@ -25,7 +25,6 @@
#include "edtServiceImpl.h"
#include "edtPropertiesPages.h"
#include "edtInstPropertiesPage.h"
#include "edtPCellParametersDialog.h"
#include "edtService.h"
#include "dbEdge.h"
#include "dbLibrary.h"
@ -1130,17 +1129,14 @@ InstService::get_default_layer_for_pcell ()
bool
InstService::drag_enter_event (const db::DPoint &p, const lay::DragDropDataBase *data)
{
{
const lay::CellDragDropData *cd = dynamic_cast <const lay::CellDragDropData *> (data);
if (view ()->is_editable () && cd && (cd->layout () == & view ()->active_cellview ()->layout () || cd->library ())) {
view ()->cancel ();
set_edit_marker (0);
m_cv_index = view ()->active_cellview_index ();
m_in_drag_drop = true;
// configure from the drag/drop data
if (cd->library ()) {
if (m_lib_name != cd->library ()->get_name ()) {
m_lib_name = cd->library ()->get_name ();
@ -1155,38 +1151,45 @@ InstService::drag_enter_event (const db::DPoint &p, const lay::DragDropDataBase
if (cd->is_pcell ()) {
const db::PCellDeclaration *pcell_decl = cd->layout ()->pcell_declaration (cd->cell_index ());
if (pcell_decl) {
if (! pcell_decl) {
return false;
}
if (m_cell_or_pcell_name != pcell_decl->name ()) {
m_cell_or_pcell_name = pcell_decl->name ();
m_pcell_parameters.clear ();
if (m_cell_or_pcell_name != pcell_decl->name ()) {
m_cell_or_pcell_name = pcell_decl->name ();
m_pcell_parameters.clear ();
}
m_is_pcell = true;
// NOTE: we reuse previous parameters for convenience unless PCell or library has changed
const std::vector<db::PCellParameterDeclaration> &pd = pcell_decl->parameter_declarations();
for (std::vector<db::PCellParameterDeclaration>::const_iterator i = pd.begin (); i != pd.end (); ++i) {
if (i->get_type () == db::PCellParameterDeclaration::t_layer && !i->is_hidden () && !i->is_readonly () && i->get_default ().is_nil ()) {
m_pcell_parameters.insert (std::make_pair (i->get_name (), get_default_layer_for_pcell ()));
} else {
m_pcell_parameters.insert (std::make_pair (i->get_name (), i->get_default ()));
}
m_is_pcell = true;
// NOTE: we reuse previous parameters for convenience unless PCell or library has changed
const std::vector<db::PCellParameterDeclaration> &pd = pcell_decl->parameter_declarations();
for (std::vector<db::PCellParameterDeclaration>::const_iterator i = pd.begin (); i != pd.end (); ++i) {
if (i->get_type () == db::PCellParameterDeclaration::t_layer && !i->is_hidden () && !i->is_readonly () && i->get_default ().is_nil ()) {
m_pcell_parameters.insert (std::make_pair (i->get_name (), get_default_layer_for_pcell ()));
} else {
m_pcell_parameters.insert (std::make_pair (i->get_name (), i->get_default ()));
}
}
do_begin_edit (p);
return true;
}
} else if (cd->layout ()->is_valid_cell_index (cd->cell_index ())) {
m_cell_or_pcell_name = cd->layout ()->cell_name (cd->cell_index ());
do_begin_edit (p);
return true;
} else {
return false;
}
sync_to_config ();
m_in_drag_drop = true;
view ()->switch_mode (plugin_declaration ()->id ());
do_begin_edit (p);
// action taken.
return true;
}
return false;
@ -1203,7 +1206,7 @@ InstService::drag_move_event (const db::DPoint &p, const lay::DragDropDataBase *
}
}
void
void
InstService::drag_leave_event ()
{
if (m_in_drag_drop) {
@ -1212,7 +1215,7 @@ InstService::drag_leave_event ()
}
}
bool
bool
InstService::selection_applies (const lay::ObjectInstPath &sel) const
{
return sel.is_cell_inst ();
@ -1221,53 +1224,8 @@ InstService::selection_applies (const lay::ObjectInstPath &sel) const
bool
InstService::drop_event (const db::DPoint & /*p*/, const lay::DragDropDataBase * /*data*/)
{
if (m_in_drag_drop) {
const lay::CellView &cv = view ()->cellview (m_cv_index);
if (! cv.is_valid ()) {
return false;
}
make_cell (cv);
bool accepted = true;
if (m_has_valid_cell && mp_pcell_decl) {
std::vector<tl::Variant> pv = mp_pcell_decl->map_parameters (m_pcell_parameters);
// Turn off the drag cursor for the modal dialog
QApplication::restoreOverrideCursor ();
// for PCells dragged show the parameter dialog for a chance to edit the initial parameters
if (! mp_pcell_parameters_dialog.get ()) {
mp_pcell_parameters_dialog.reset (new edt::PCellParametersDialog (view ()));
mp_pcell_parameters_dialog->parameters_changed_event.add (this, &InstService::apply_edits);
}
if (! mp_pcell_parameters_dialog->exec (mp_current_layout, view (), m_cv_index, mp_pcell_decl, pv)) {
accepted = false;
} else {
m_has_valid_cell = false;
m_pcell_parameters = mp_pcell_decl->named_parameters (mp_pcell_parameters_dialog->get_parameters ());
}
}
set_edit_marker (0);
if (accepted) {
do_finish_edit ();
} else {
do_cancel_edit ();
}
sync_to_config ();
return true;
} else {
return false;
}
m_in_drag_drop = false;
return false;
}
void
@ -1538,6 +1496,8 @@ InstService::do_cancel_edit ()
m_has_valid_cell = false;
m_in_drag_drop = false;
set_edit_marker (0);
// clean up any proxy cells created so far
const lay::CellView &cv = view ()->cellview (m_cv_index);
if (cv.is_valid ()) {
@ -1651,16 +1611,6 @@ InstService::config_finalize ()
edt::Service::config_finalize ();
}
void
InstService::apply_edits()
{
if (mp_pcell_decl && mp_pcell_parameters_dialog.get ()) {
m_pcell_parameters = mp_pcell_decl->named_parameters (mp_pcell_parameters_dialog->get_parameters ());
}
sync_to_config ();
}
void
InstService::update_marker ()
{
@ -1685,14 +1635,9 @@ InstService::get_inst (db::CellInstArray &inst)
// compute the instance's transformation
db::VCplxTrans pt = (db::CplxTrans (cv->layout ().dbu ()) * m_trans).inverted ();
db::ICplxTrans trans;
if (m_in_drag_drop) {
trans = db::ICplxTrans (1.0, 0.0, false, pt * m_disp - db::Point ());
} else {
trans = db::ICplxTrans (m_scale, m_angle, m_mirror, pt * m_disp - db::Point ());
}
db::ICplxTrans trans = db::ICplxTrans (m_scale, m_angle, m_mirror, pt * m_disp - db::Point ());
if (! m_in_drag_drop && m_array && m_rows > 0 && m_columns > 0) {
if (m_array && m_rows > 0 && m_columns > 0) {
db::Vector row = db::Vector (pt * db::DVector (m_row_x, m_row_y));
db::Vector column = db::Vector (pt * db::DVector (m_column_x, m_column_y));
inst = db::CellInstArray (db::CellInst (ci.second), trans, row, column, m_rows, m_columns);

View File

@ -38,8 +38,6 @@ namespace lay
namespace edt
{
class PCellParametersDialog;
/**
* @brief Implementation of the edt::Service for generic shape editing
*/
@ -245,10 +243,8 @@ private:
const db::PCellDeclaration *mp_pcell_decl;
int m_cv_index;
db::ICplxTrans m_trans;
std::auto_ptr<edt::PCellParametersDialog> mp_pcell_parameters_dialog;
void update_marker ();
void apply_edits ();
bool get_inst (db::CellInstArray &inst);
std::pair<bool, db::cell_index_type> make_cell (const lay::CellView &cv);
tl::Variant get_default_layer_for_pcell ();