From 20a3dbeaf8e3bfc688e078b9e2b223150053a559 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 8 Sep 2025 18:54:00 +0200 Subject: [PATCH] Some refactoring (generalizing edt:: functions, basing move tool on lay::EditorService and support for 'tab' key (calls 'move by') --- src/edt/edt/edt.pro | 2 - src/edt/edt/edtConfig.cc | 5 -- src/edt/edt/edtConfig.h | 2 - src/edt/edt/edtDialogs.cc | 2 +- src/edt/edt/edtEditorOptionsPages.cc | 2 +- src/edt/edt/edtInstService.cc | 6 +- src/edt/edt/edtMainService.h | 2 +- src/edt/edt/edtMoveTrackerService.cc | 2 +- src/edt/edt/edtPartialService.cc | 36 +++++------ src/edt/edt/edtPartialService.h | 4 +- src/edt/edt/edtPathService.cc | 2 +- src/edt/edt/edtRecentConfigurationPage.cc | 8 +-- src/edt/edt/edtService.cc | 20 +++---- src/edt/edt/edtService.h | 14 ++++- src/edt/edt/edtShapeService.cc | 2 +- src/lay/lay/gsiDeclLayPlugin.cc | 12 ++-- src/laybasic/laybasic/layEditorOptionsPage.cc | 2 + src/laybasic/laybasic/layEditorServiceBase.cc | 7 +-- .../laybasic/layEditorUtils.cc} | 11 +++- .../laybasic/layEditorUtils.h} | 41 ++++++------- src/laybasic/laybasic/layLayoutViewBase.cc | 2 +- src/laybasic/laybasic/layMove.cc | 59 +++++++------------ src/laybasic/laybasic/layMove.h | 17 ++---- src/laybasic/laybasic/laybasic.pro | 2 + src/layui/layui/layLayoutViewFunctions.cc | 2 +- 25 files changed, 122 insertions(+), 142 deletions(-) rename src/{edt/edt/edtUtils.cc => laybasic/laybasic/layEditorUtils.cc} (99%) rename src/{edt/edt/edtUtils.h => laybasic/laybasic/layEditorUtils.h} (81%) diff --git a/src/edt/edt/edt.pro b/src/edt/edt/edt.pro index 886028431..b46609432 100644 --- a/src/edt/edt/edt.pro +++ b/src/edt/edt/edt.pro @@ -80,7 +80,6 @@ HEADERS += \ edtPartialService.h \ edtPlugin.h \ edtService.h \ - edtUtils.h \ edtCommon.h \ edtDistribute.h \ @@ -91,7 +90,6 @@ SOURCES += \ edtPartialService.cc \ edtPlugin.cc \ edtService.cc \ - edtUtils.cc \ gsiDeclEdt.cc \ edtDistribute.cc \ diff --git a/src/edt/edt/edtConfig.cc b/src/edt/edt/edtConfig.cc index 9de28292d..255b9ccbd 100644 --- a/src/edt/edt/edtConfig.cc +++ b/src/edt/edt/edtConfig.cc @@ -28,11 +28,6 @@ namespace edt { -int snap_range_pixels () -{ - return 8; // TODO: make variable -} - // ----------------------------------------------------------------------------- std::string cfg_edit_grid ("edit-grid"); diff --git a/src/edt/edt/edtConfig.h b/src/edt/edt/edtConfig.h index fd8d0bd8f..97964a9e0 100644 --- a/src/edt/edt/edtConfig.h +++ b/src/edt/edt/edtConfig.h @@ -118,8 +118,6 @@ struct EDT_PUBLIC VAlignConverter void from_string (const std::string &s, db::VAlign &a); }; -int EDT_PUBLIC snap_range_pixels (); - } #endif diff --git a/src/edt/edt/edtDialogs.cc b/src/edt/edt/edtDialogs.cc index b31315e86..120a7495f 100644 --- a/src/edt/edt/edtDialogs.cc +++ b/src/edt/edt/edtDialogs.cc @@ -26,7 +26,7 @@ #include "dbLayout.h" #include "edtDialogs.h" -#include "edtUtils.h" +#include "layEditorUtils.h" #include "layObjectInstPath.h" #include "layCellView.h" #include "layLayoutViewBase.h" diff --git a/src/edt/edt/edtEditorOptionsPages.cc b/src/edt/edt/edtEditorOptionsPages.cc index 9db9db7c6..5ed1ac75a 100644 --- a/src/edt/edt/edtEditorOptionsPages.cc +++ b/src/edt/edt/edtEditorOptionsPages.cc @@ -725,7 +725,7 @@ EditorOptionsInstPCellParam::apply (lay::Dispatcher *root) if (pc.first) { const db::PCellDeclaration *pc_decl = layout->pcell_declaration (pc.second); if (pc_decl) { - param = pcell_parameters_to_string (pc_decl->named_parameters (mp_pcell_parameters->get_parameters (&ok))); + param = lay::pcell_parameters_to_string (pc_decl->named_parameters (mp_pcell_parameters->get_parameters (&ok))); } } } diff --git a/src/edt/edt/edtInstService.cc b/src/edt/edt/edtInstService.cc index 765a8513b..3e92d981a 100644 --- a/src/edt/edt/edtInstService.cc +++ b/src/edt/edt/edtInstService.cc @@ -197,7 +197,7 @@ InstService::sync_to_config () dispatcher ()->config_set (cfg_edit_inst_lib_name, m_lib_name); dispatcher ()->config_set (cfg_edit_inst_cell_name, m_cell_or_pcell_name); if (m_is_pcell) { - dispatcher ()->config_set (cfg_edit_inst_pcell_parameters, pcell_parameters_to_string (m_pcell_parameters)); + dispatcher ()->config_set (cfg_edit_inst_pcell_parameters, lay::pcell_parameters_to_string (m_pcell_parameters)); } else { dispatcher ()->config_set (cfg_edit_inst_pcell_parameters, std::string ()); } @@ -531,7 +531,7 @@ InstService::configure (const std::string &name, const std::string &value) if (name == cfg_edit_inst_pcell_parameters) { - std::map pcp = pcell_parameters_from_string (value); + std::map pcp = lay::pcell_parameters_from_string (value); if (pcp != m_pcell_parameters) { m_pcell_parameters = pcp; @@ -772,7 +772,7 @@ InstService::config_finalize () // TODO: it's somewhat questionable to do this inside "config_finalize" as this method is supposed // to reflect changes rather than induce some. if (m_is_pcell) { - dispatcher ()->config_set (cfg_edit_inst_pcell_parameters, pcell_parameters_to_string (m_pcell_parameters)); + dispatcher ()->config_set (cfg_edit_inst_pcell_parameters, lay::pcell_parameters_to_string (m_pcell_parameters)); } else { dispatcher ()->config_set (cfg_edit_inst_pcell_parameters, std::string ()); } diff --git a/src/edt/edt/edtMainService.h b/src/edt/edt/edtMainService.h index c21e94d7c..d8fa67136 100644 --- a/src/edt/edt/edtMainService.h +++ b/src/edt/edt/edtMainService.h @@ -29,10 +29,10 @@ #include "layPlugin.h" #include "layViewObject.h" #include "layMarker.h" +#include "layEditorUtils.h" #include "dbLayout.h" #include "dbShape.h" #include "dbClipboard.h" -#include "edtUtils.h" #include #include diff --git a/src/edt/edt/edtMoveTrackerService.cc b/src/edt/edt/edtMoveTrackerService.cc index 1798ece0d..32a7e2cfa 100644 --- a/src/edt/edt/edtMoveTrackerService.cc +++ b/src/edt/edt/edtMoveTrackerService.cc @@ -61,7 +61,7 @@ MoveTrackerService::issue_edit_events () call_editor_hooks (m_editor_hooks, &edt::EditorHooks::begin_edits); // build the transformation variants cache - TransformationVariants tv (view ()); + lay::TransformationVariants tv (view ()); std::vector services = view ()->get_plugins (); std::vector sel; diff --git a/src/edt/edt/edtPartialService.cc b/src/edt/edt/edtPartialService.cc index fc04e4a08..0bad58cb0 100644 --- a/src/edt/edt/edtPartialService.cc +++ b/src/edt/edt/edtPartialService.cc @@ -1213,7 +1213,7 @@ PartialService::timeout () partial_objects::const_iterator r = transient_selection.begin (); // build the transformation variants cache - TransformationVariants tv (view ()); + lay::TransformationVariants tv (view ()); const lay::CellView &cv = view ()->cellview (r->first.cv_index ()); @@ -1468,7 +1468,7 @@ PartialService::issue_editor_hook_calls (const tl::weak_collection &sel, const db::DTrans &move_trans, std::map &new_edges, std::map &new_points) +PartialService::modify_shape (lay::TransformationVariants &tv, const db::Shape &shape_in, const lay::ObjectInstPath &path, const std::set &sel, const db::DTrans &move_trans, std::map &new_edges, std::map &new_points) { tl_assert (shape_in.shapes () != 0); db::Shape shape = shape_in; @@ -1642,7 +1642,7 @@ void PartialService::transform_selection (const db::DTrans &move_trans) { // build the transformation variants cache - TransformationVariants tv (view ()); + lay::TransformationVariants tv (view ()); // since a shape reference may become invalid while moving it and // because it creates ambiguities, we treat each shape separately: @@ -1798,7 +1798,7 @@ PartialService::mouse_move_event (const db::DPoint &p, unsigned int buttons, boo set_cursor (lay::Cursor::size_all); - m_alt_ac = ac_from_buttons (buttons); + m_alt_ac = lay::ac_from_buttons (buttons); // drag the vertex or edge/segment if (is_single_point_selection () || is_single_edge_selection ()) { @@ -1862,7 +1862,7 @@ PartialService::mouse_move_event (const db::DPoint &p, unsigned int buttons, boo if (mp_box) { - m_alt_ac = ac_from_buttons (buttons); + m_alt_ac = lay::ac_from_buttons (buttons); m_p2 = p; mp_box->set_points (m_p1, m_p2); @@ -1922,7 +1922,7 @@ PartialService::mouse_press_event (const db::DPoint &p, unsigned int buttons, bo } else if (! mp_box) { - m_alt_ac = ac_from_buttons (buttons); + m_alt_ac = lay::ac_from_buttons (buttons); if (m_selection.empty ()) { @@ -2015,7 +2015,7 @@ PartialService::mouse_click_event (const db::DPoint &p, unsigned int buttons, bo if (m_dragging) { - m_alt_ac = ac_from_buttons (buttons); + m_alt_ac = lay::ac_from_buttons (buttons); if (m_current != m_start) { @@ -2059,7 +2059,7 @@ PartialService::mouse_click_event (const db::DPoint &p, unsigned int buttons, bo view ()->clear_selection (); m_selection = selection; - m_alt_ac = ac_from_buttons (buttons); + m_alt_ac = lay::ac_from_buttons (buttons); lay::Editable::SelectionMode mode = lay::Editable::Replace; bool shift = ((buttons & lay::ShiftButton) != 0); @@ -2192,7 +2192,7 @@ PartialService::mouse_double_click_event (const db::DPoint &p, unsigned int butt if ((buttons & lay::LeftButton) != 0 && prio) { - m_alt_ac = ac_from_buttons (buttons); + m_alt_ac = lay::ac_from_buttons (buttons); close_editor_hooks (false); @@ -2215,7 +2215,7 @@ PartialService::mouse_double_click_event (const db::DPoint &p, unsigned int butt db::DPoint new_point_d = snap (p); // build the transformation variants cache - TransformationVariants tv (view (), true /*per cv and layer*/, false /*per cv*/); + lay::TransformationVariants tv (view (), true /*per cv and layer*/, false /*per cv*/); const std::vector *tv_list = tv.per_cv_and_layer (r->first.cv_index (), r->first.layer ()); if (tv_list && ! tv_list->empty ()) { @@ -2304,7 +2304,7 @@ PartialService::mouse_release_event (const db::DPoint &p, unsigned int buttons, if (prio && mp_box) { - m_alt_ac = ac_from_buttons (buttons); + m_alt_ac = lay::ac_from_buttons (buttons); ui ()->ungrab_mouse (this); @@ -2402,7 +2402,7 @@ PartialService::snap_marker_to_grid (const db::DVector &v, bool &snapped) const db::DVector snapped_to (1.0, 1.0); db::DVector vv = lay::snap_angle (v, move_ac (), &snapped_to); - TransformationVariants tv (view ()); + lay::TransformationVariants tv (view ()); for (auto r = m_selection.begin (); r != m_selection.end (); ++r) { @@ -2548,7 +2548,7 @@ PartialService::selection_bbox () { // build the transformation variants cache // TODO: this is done multiple times - once for each service! - TransformationVariants tv (view ()); + lay::TransformationVariants tv (view ()); const db::DCplxTrans &vp = view ()->viewport ().trans (); lay::TextInfo text_info (view ()); @@ -2938,7 +2938,7 @@ PartialService::single_selected_point () const // build the transformation variants cache and // use only the first one of the explicit transformations // TODO: clarify how this can be implemented in a more generic form or leave it thus. - TransformationVariants tv (view ()); + lay::TransformationVariants tv (view ()); const std::vector *tv_list = tv.per_cv_and_layer (m_selection.begin ()->first.cv_index (), m_selection.begin ()->first.layer ()); const lay::CellView &cv = view ()->cellview (m_selection.begin ()->first.cv_index ()); @@ -2960,7 +2960,7 @@ PartialService::single_selected_edge () const // build the transformation variants cache and // use only the first one of the explicit transformations // TODO: clarify how this can be implemented in a more generic form or leave it thus. - TransformationVariants tv (view ()); + lay::TransformationVariants tv (view ()); const std::vector *tv_list = tv.per_cv_and_layer (m_selection.begin ()->first.cv_index (), m_selection.begin ()->first.layer ()); const lay::CellView &cv = view ()->cellview (m_selection.begin ()->first.cv_index ()); @@ -3042,7 +3042,7 @@ PartialService::do_selection_to_view () if (! m_selection.empty ()) { // build the transformation variants cache - TransformationVariants tv (view ()); + lay::TransformationVariants tv (view ()); for (partial_objects::const_iterator r = m_selection.begin (); r != m_selection.end (); ++r) { @@ -3418,7 +3418,7 @@ PartialService::handle_guiding_shape_changes () // Hint: get_parameters_from_pcell_and_guiding_shapes invalidates the shapes because it resets the changed // guiding shapes. We must not access s->shape after that. - if (! get_parameters_from_pcell_and_guiding_shapes (layout, s->first.cell_index (), parameters_for_pcell)) { + if (! lay::get_parameters_from_pcell_and_guiding_shapes (layout, s->first.cell_index (), parameters_for_pcell)) { return false; } diff --git a/src/edt/edt/edtPartialService.h b/src/edt/edt/edtPartialService.h index 03cdb5bc0..594c73108 100644 --- a/src/edt/edt/edtPartialService.h +++ b/src/edt/edt/edtPartialService.h @@ -30,9 +30,9 @@ #include "layViewObject.h" #include "layRubberBox.h" #include "laySnap.h" +#include "layEditorUtils.h" #include "tlAssert.h" #include "tlDeferredExecution.h" -#include "edtUtils.h" #include "edtConfig.h" #include "edtEditorHooks.h" @@ -400,7 +400,7 @@ private: db::DEdge single_selected_edge () const; bool handle_guiding_shape_changes (); void transform_selection (const db::DTrans &move_trans); - db::Shape modify_shape (TransformationVariants &tv, const db::Shape &shape_in, const lay::ObjectInstPath &path, const std::set &sel, const db::DTrans &move_trans, std::map &new_edges, std::map &new_points); + db::Shape modify_shape (lay::TransformationVariants &tv, const db::Shape &shape_in, const lay::ObjectInstPath &path, const std::set &sel, const db::DTrans &move_trans, std::map &new_edges, std::map &new_points); void open_editor_hooks (); void close_editor_hooks (bool commit); diff --git a/src/edt/edt/edtPathService.cc b/src/edt/edt/edtPathService.cc index f5a39eee2..6879dec56 100644 --- a/src/edt/edt/edtPathService.cc +++ b/src/edt/edt/edtPathService.cc @@ -325,7 +325,7 @@ db::Instance PathService::make_via (const db::SelectedViaDefinition &via_def, double w_bottom, double h_bottom, double w_top, double h_top, const db::DPoint &via_pos) { if (! via_def.via_type.cut.is_null ()) { - edt::set_or_request_current_layer (view (), via_def.via_type.cut, cv_index (), false /*don't make current*/); + lay::set_or_request_current_layer (view (), via_def.via_type.cut, cv_index (), false /*don't make current*/); } std::map params; diff --git a/src/edt/edt/edtRecentConfigurationPage.cc b/src/edt/edt/edtRecentConfigurationPage.cc index e599cf2d4..c2df2e655 100644 --- a/src/edt/edt/edtRecentConfigurationPage.cc +++ b/src/edt/edt/edtRecentConfigurationPage.cc @@ -23,11 +23,11 @@ #if defined(HAVE_QT) #include "edtRecentConfigurationPage.h" -#include "edtUtils.h" #include "layDispatcher.h" #include "layLayoutViewBase.h" #include "layLayerTreeModel.h" #include "layBusy.h" +#include "layEditorUtils.h" #include "dbLibraryManager.h" #include "dbLibrary.h" #include "tlLog.h" @@ -267,7 +267,7 @@ RecentConfigurationPage::render_to (QTreeWidgetItem *item, int column, const std std::map pcp; for (std::list::const_iterator c = m_cfg.begin (); c != m_cfg.end (); ++c, ++pcp_column) { if (c->rendering == RecentConfigurationPage::PCellParameters) { - pcp = pcell_parameters_from_string (values [pcp_column]); + pcp = lay::pcell_parameters_from_string (values [pcp_column]); break; } } @@ -296,7 +296,7 @@ RecentConfigurationPage::render_to (QTreeWidgetItem *item, int column, const std { std::map pcp; try { - pcp = pcell_parameters_from_string (values [column]); + pcp = lay::pcell_parameters_from_string (values [column]); } catch (tl::Exception &ex) { tl::error << tl::to_string (tr ("Configuration error (PCellParameters): ")) << ex.msg (); } @@ -384,7 +384,7 @@ RecentConfigurationPage::item_clicked (QTreeWidgetItem *item) ex.read (cv_index); } - edt::set_or_request_current_layer (view (), lp, cv_index); + lay::set_or_request_current_layer (view (), lp, cv_index); } else { dispatcher ()->config_set (c->cfg_name, v); diff --git a/src/edt/edt/edtService.cc b/src/edt/edt/edtService.cc index d039c7e33..23377fe4f 100644 --- a/src/edt/edt/edtService.cc +++ b/src/edt/edt/edtService.cc @@ -283,7 +283,7 @@ Service::snap (const db::DPoint &p, const db::DPoint &plast, bool connect) const lay::PointSnapToObjectResult Service::snap2_details (const db::DPoint &p) const { - double snap_range = ui ()->mouse_event_trans ().inverted ().ctrans (edt::snap_range_pixels ()); + double snap_range = ui ()->mouse_event_trans ().inverted ().ctrans (lay::snap_range_pixels ()); return lay::obj_snap (m_snap_to_objects ? view () : 0, p, m_edit_grid == db::DVector () ? m_global_grid : m_edit_grid, snap_range); } @@ -296,7 +296,7 @@ Service::snap2 (const db::DPoint &p) const db::DPoint Service::snap2 (const db::DPoint &p, const db::DPoint &plast, bool connect) const { - double snap_range = ui ()->mouse_event_trans ().inverted ().ctrans (edt::snap_range_pixels ()); + double snap_range = ui ()->mouse_event_trans ().inverted ().ctrans (lay::snap_range_pixels ()); return lay::obj_snap (m_snap_to_objects ? view () : 0, plast, p, m_edit_grid == db::DVector () ? m_global_grid : m_edit_grid, connect ? connect_ac () : move_ac (), snap_range).snapped_point; } @@ -593,7 +593,7 @@ Service::selection_bbox () { // build the transformation variants cache // TODO: this is done multiple times - once for each service! - TransformationVariants tv (view ()); + lay::TransformationVariants tv (view ()); const db::DCplxTrans &vp = view ()->viewport ().trans (); lay::TextInfo text_info (view ()); @@ -687,7 +687,7 @@ Service::transform (const db::DCplxTrans &trans, const std::vectoris_editable () && prio && (buttons & lay::RightButton) != 0 && m_editing) { - m_alt_ac = ac_from_buttons (buttons); + m_alt_ac = lay::ac_from_buttons (buttons); do_mouse_transform (p, db::DFTrans (db::DFTrans::r90)); m_alt_ac = lay::AC_Global; return true; @@ -1754,7 +1754,7 @@ Service::do_selection_to_view () m_markers.reserve (selection_size ()); // build the transformation variants cache - TransformationVariants tv (view ()); + lay::TransformationVariants tv (view ()); // prepare a default transformation for empty variants std::vector empty_tv; @@ -1932,7 +1932,7 @@ Service::handle_guiding_shape_changes (const lay::ObjectInstPath &obj, bool comm // Hint: get_parameters_from_pcell_and_guiding_shapes invalidates the shapes because it resets the changed // guiding shapes. We must not access s->shape after that. - if (! get_parameters_from_pcell_and_guiding_shapes (layout, obj.cell_index (), parameters_for_pcell)) { + if (! lay::get_parameters_from_pcell_and_guiding_shapes (layout, obj.cell_index (), parameters_for_pcell)) { return std::make_pair (false, lay::ObjectInstPath ()); } diff --git a/src/edt/edt/edtService.h b/src/edt/edt/edtService.h index fe61999ef..a791187e5 100644 --- a/src/edt/edt/edtService.h +++ b/src/edt/edt/edtService.h @@ -33,10 +33,10 @@ #include "laySnap.h" #include "layObjectInstPath.h" #include "layTextInfo.h" +#include "layEditorUtils.h" #include "tlColor.h" #include "dbLayout.h" #include "dbShape.h" -#include "edtUtils.h" #include "edtConfig.h" #include "tlAssert.h" #include "tlException.h" @@ -55,6 +55,18 @@ class PluginDeclarationBase; // ------------------------------------------------------------- +/** + * @brief A helper class that identifies clipboard data for edt:: + */ +class EDT_PUBLIC ClipboardData + : public db::ClipboardData +{ +public: + ClipboardData () { } +}; + +// ------------------------------------------------------------- + /** * @brief A utility class to implement a selection iterator across all editor services */ diff --git a/src/edt/edt/edtShapeService.cc b/src/edt/edt/edtShapeService.cc index 28dc9a461..4664f777b 100644 --- a/src/edt/edt/edtShapeService.cc +++ b/src/edt/edt/edtShapeService.cc @@ -167,7 +167,7 @@ ShapeEditService::change_edit_layer (const db::LayerProperties &lp) } m_layer = (unsigned int) layer; - edt::set_or_request_current_layer (view (), lp, m_cv_index); + lay::set_or_request_current_layer (view (), lp, m_cv_index); if (editing ()) { close_editor_hooks (false); diff --git a/src/lay/lay/gsiDeclLayPlugin.cc b/src/lay/lay/gsiDeclLayPlugin.cc index 88050e125..b5f7c00ce 100644 --- a/src/lay/lay/gsiDeclLayPlugin.cc +++ b/src/lay/lay/gsiDeclLayPlugin.cc @@ -27,8 +27,8 @@ #include "gsiEnums.h" #include "layEditorOptionsPages.h" #include "layCursor.h" +#include "layEditorUtils.h" #include "edtConfig.h" -#include "edtUtils.h" namespace gsi { @@ -290,7 +290,7 @@ PluginImpl::snap_delta (const db::DVector &v, bool connect, lay::angle_constrain db::DPoint PluginImpl::snap2 (const db::DPoint &p, bool visualize) { - double snap_range = ui ()->mouse_event_trans ().inverted ().ctrans (edt::snap_range_pixels ()); + double snap_range = ui ()->mouse_event_trans ().inverted ().ctrans (lay::snap_range_pixels ()); auto details = lay::obj_snap (m_snap_to_objects ? view () : 0, p, m_edit_grid == db::DVector () ? m_global_grid : m_edit_grid, snap_range); if (visualize) { mouse_cursor_from_snap_details (details); @@ -301,7 +301,7 @@ PluginImpl::snap2 (const db::DPoint &p, bool visualize) db::DPoint PluginImpl::snap2_from_to (const db::DPoint &p, const db::DPoint &plast, bool connect, lay::angle_constraint_type ac, bool visualize) { - double snap_range = ui ()->mouse_event_trans ().inverted ().ctrans (edt::snap_range_pixels ()); + double snap_range = ui ()->mouse_event_trans ().inverted ().ctrans (lay::snap_range_pixels ()); auto details = lay::obj_snap (m_snap_to_objects ? view () : 0, plast, p, m_edit_grid == db::DVector () ? m_global_grid : m_edit_grid, connect ? connect_ac (ac) : move_ac (ac), snap_range); if (visualize) { mouse_cursor_from_snap_details (details); @@ -575,7 +575,7 @@ PluginImpl::add_mouse_cursor_point (const db::Point &p, int cv_index, const db:: return; } - edt::TransformationVariants tv (view ()); + lay::TransformationVariants tv (view ()); const std::vector *tv_list = tv.per_cv_and_layer (cv_index, (unsigned int) layer); if (! tv_list || tv_list->empty ()) { return; @@ -603,7 +603,7 @@ PluginImpl::add_edge_marker_edge (const db::Edge &p, int cv_index, const db::Lay return; } - edt::TransformationVariants tv (view ()); + lay::TransformationVariants tv (view ()); const std::vector *tv_list = tv.per_cv_and_layer (cv_index, (unsigned int) layer); if (! tv_list || tv_list->empty ()) { return; @@ -861,7 +861,7 @@ Class decl_Plugin (decl_PluginBase, "lay", "Plugin", "\n" "This method has been added in version 0.30.4." ) + - method ("ac_from_buttons", &edt::ac_from_buttons, gsi::arg ("buttons"), + method ("ac_from_buttons", &lay::ac_from_buttons, gsi::arg ("buttons"), "@brief Creates an angle constraint from a button combination\n" "This method provides the angle constraints implied by a specific modifier combination, i.e. " "'Shift' will render ortho snapping. Use this function to generate angle constraints following " diff --git a/src/laybasic/laybasic/layEditorOptionsPage.cc b/src/laybasic/laybasic/layEditorOptionsPage.cc index eb2dd7435..0efde1109 100644 --- a/src/laybasic/laybasic/layEditorOptionsPage.cc +++ b/src/laybasic/laybasic/layEditorOptionsPage.cc @@ -123,6 +123,8 @@ EditorOptionsPage::show () } else { return mp_owner->exec_modal (this) ? 1 : 0; } + } else { + return -1; } } diff --git a/src/laybasic/laybasic/layEditorServiceBase.cc b/src/laybasic/laybasic/layEditorServiceBase.cc index 784889dac..21e162963 100644 --- a/src/laybasic/laybasic/layEditorServiceBase.cc +++ b/src/laybasic/laybasic/layEditorServiceBase.cc @@ -379,10 +379,7 @@ bool EditorServiceBase::key_event (unsigned int key, unsigned int buttons) { if (is_active () && key == Qt::Key_Tab && buttons == 0) { - EditorOptionsPage *fp = focus_page (); - if (fp) { - focus_page_open (fp); - } + focus_page_open (focus_page ()); return true; } else { return false; @@ -392,7 +389,7 @@ EditorServiceBase::key_event (unsigned int key, unsigned int buttons) int EditorServiceBase::focus_page_open (EditorOptionsPage *fp) { - return fp->show (); + return fp ? fp->show () : 0; } void diff --git a/src/edt/edt/edtUtils.cc b/src/laybasic/laybasic/layEditorUtils.cc similarity index 99% rename from src/edt/edt/edtUtils.cc rename to src/laybasic/laybasic/layEditorUtils.cc index f4f8d12fa..377fe8f86 100644 --- a/src/edt/edt/edtUtils.cc +++ b/src/laybasic/laybasic/layEditorUtils.cc @@ -25,8 +25,7 @@ #include "dbLayout.h" #include "dbLibrary.h" -#include "edtUtils.h" -#include "edtService.h" +#include "layEditorUtils.h" #include "layCellView.h" #include "layLayoutViewBase.h" @@ -38,10 +37,16 @@ # include #endif -namespace edt { +namespace lay +{ // ------------------------------------------------------------- +int snap_range_pixels () +{ + return 8; // TODO: make variable +} + // Convert buttons to an angle constraint lay::angle_constraint_type ac_from_buttons (unsigned int buttons) diff --git a/src/edt/edt/edtUtils.h b/src/laybasic/laybasic/layEditorUtils.h similarity index 81% rename from src/edt/edt/edtUtils.h rename to src/laybasic/laybasic/layEditorUtils.h index 8c15696a3..50cef1179 100644 --- a/src/edt/edt/edtUtils.h +++ b/src/laybasic/laybasic/layEditorUtils.h @@ -21,15 +21,15 @@ */ -#ifndef HDR_edtUtils -#define HDR_edtUtils +#ifndef HDR_layEditorUtils +#define HDR_layEditorUtils #include #include #include #include -#include "edtCommon.h" +#include "laybasicCommon.h" #include "layObjectInstPath.h" #include "laySnap.h" @@ -41,33 +41,34 @@ namespace lay { - class LayoutViewBase; - class Dispatcher; -} -namespace edt { - -class Service; +class LayoutViewBase; +class Dispatcher; // ------------------------------------------------------------- +/** + * @brief Gets the snap range in pixels + */ +LAYBASIC_PUBLIC int snap_range_pixels (); + /** * @brief Convert a button flag set to an angle constraint * * This implements the standard modifiers for angle constraints - i.e. * ortho for "Shift". */ -EDT_PUBLIC lay::angle_constraint_type ac_from_buttons (unsigned int buttons); +LAYBASIC_PUBLIC lay::angle_constraint_type ac_from_buttons (unsigned int buttons); /** * @brief Serializes PCell parameters to a string */ -EDT_PUBLIC std::string pcell_parameters_to_string (const std::map ¶meters); +LAYBASIC_PUBLIC std::string pcell_parameters_to_string (const std::map ¶meters); /** * @brief Deserializes PCell parameters from a string */ -EDT_PUBLIC std::map pcell_parameters_from_string (const std::string &s); +LAYBASIC_PUBLIC std::map pcell_parameters_from_string (const std::string &s); /** * @brief Fetch PCell parameters from a cell and merge the guiding shapes into them @@ -77,30 +78,22 @@ EDT_PUBLIC std::map pcell_parameters_from_string (cons * @param parameters_for_pcell Will receive the parameters * @return true, if the cell is a PCell and parameters have been fetched */ -EDT_PUBLIC bool +LAYBASIC_PUBLIC +bool get_parameters_from_pcell_and_guiding_shapes (db::Layout *layout, db::cell_index_type cell_index, db::pcell_parameters_type ¶meters_for_pcell); /** * @brief Request to make the given layer the current one (asks whether to create the layer if needed) */ +LAYBASIC_PUBLIC bool set_or_request_current_layer (lay::LayoutViewBase *view, const db::LayerProperties &lp, unsigned int cv_index, bool make_current = true); -/** - * @brief A helper class that identifies clipboard data for edt:: - */ -class EDT_PUBLIC ClipboardData - : public db::ClipboardData -{ -public: - ClipboardData () { } -}; - /** * @brief A cache for the transformation variants for a certain layer and cell view index for a lay::LayoutView */ -class EDT_PUBLIC TransformationVariants +class LAYBASIC_PUBLIC TransformationVariants { public: TransformationVariants (const lay::LayoutViewBase *view, bool per_cv_and_layer = true, bool per_cv = true); diff --git a/src/laybasic/laybasic/layLayoutViewBase.cc b/src/laybasic/laybasic/layLayoutViewBase.cc index 7f399ff29..2a39c5f7a 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.cc +++ b/src/laybasic/laybasic/layLayoutViewBase.cc @@ -5506,7 +5506,7 @@ LayoutViewBase::paste_interactive (bool transient_mode) // operations. trans->close (); - if (mp_move_service && mp_move_service->begin_move (trans.release (), transient_mode)) { + if (mp_move_service && mp_move_service->start_move (trans.release (), transient_mode)) { switch_mode (-1); // move mode } } diff --git a/src/laybasic/laybasic/layMove.cc b/src/laybasic/laybasic/layMove.cc index 3c15c3dd3..920643689 100644 --- a/src/laybasic/laybasic/layMove.cc +++ b/src/laybasic/laybasic/layMove.cc @@ -20,11 +20,10 @@ */ - - #include "layMove.h" #include "layEditable.h" #include "layLayoutViewBase.h" +#include "layEditorUtils.h" #include "laySelector.h" #include "laybasicConfig.h" @@ -35,11 +34,9 @@ namespace lay // MoveService implementation MoveService::MoveService (lay::LayoutViewBase *view) - : lay::ViewService (view->canvas ()), - lay::Plugin (view), + : lay::EditorServiceBase (view), m_dragging (false), m_dragging_transient (false), - m_active (false), mp_editables (view), mp_view (view), m_global_grid (0.001) @@ -52,55 +49,33 @@ MoveService::~MoveService () drag_cancel (); } -void -MoveService::activated () -{ - m_active = true; -} - void MoveService::deactivated () { + EditorServiceBase::deactivated (); m_shift = db::DPoint (); - m_active = false; - mp_view->clear_transient_selection (); + mp_editables->clear_transient_selection (); drag_cancel (); } -lay::angle_constraint_type -ac_from_buttons (unsigned int buttons) -{ - if ((buttons & lay::ShiftButton) != 0) { - if ((buttons & lay::ControlButton) != 0) { - return lay::AC_Any; - } else { - return lay::AC_Ortho; - } - } else { - if ((buttons & lay::ControlButton) != 0) { - return lay::AC_Diagonal; - } else { - return lay::AC_Global; - } - } -} - bool MoveService::configure (const std::string &name, const std::string &value) { + if (lay::EditorServiceBase::configure (name, value)) { + return true; + } + if (name == cfg_grid) { tl::from_string (value, m_global_grid); } + return false; // not taken } bool MoveService::key_event (unsigned int key, unsigned int buttons) { - if (m_active && key == Qt::Key_Tab && buttons == 0) { - if (dispatcher ()) { - dispatcher ()->menu_activated ("cm_sel_move"); - } + if (lay::EditorServiceBase::key_event (key, buttons)) { return true; } @@ -145,6 +120,16 @@ MoveService::key_event (unsigned int key, unsigned int buttons) } } +int +MoveService::focus_page_open (EditorOptionsPage * /*fp*/) +{ + // This method is called on "Tab" by "key_event". "fp" is null as we don't have a focus page registered. + if (is_active () && dispatcher ()) { + dispatcher ()->menu_activated ("cm_sel_move"); + } + return 0; +} + bool MoveService::mouse_move_event (const db::DPoint &p, unsigned int buttons, bool prio) { @@ -256,7 +241,7 @@ MoveService::mouse_press_event (const db::DPoint &p, unsigned int buttons, bool } bool -MoveService::begin_move (db::Transaction *transaction, bool transient_selection) +MoveService::start_move (db::Transaction *transaction, bool transient_selection) { if (m_dragging) { return false; @@ -324,7 +309,7 @@ MoveService::handle_click (const db::DPoint &p, unsigned int buttons, bool drag_ ui ()->hover_reset (); - mp_view->clear_transient_selection (); + mp_editables->clear_transient_selection (); m_dragging = true; m_dragging_transient = drag_transient; diff --git a/src/laybasic/laybasic/layMove.h b/src/laybasic/laybasic/layMove.h index 485c12aaa..b721516b3 100644 --- a/src/laybasic/laybasic/layMove.h +++ b/src/laybasic/laybasic/layMove.h @@ -24,34 +24,28 @@ #define HDR_layMove #include "laybasicCommon.h" -#include "layViewObject.h" -#include "layPlugin.h" +#include "layEditorServiceBase.h" #include "dbManager.h" #include namespace lay { -class Editables; class LayoutViewBase; class LAYBASIC_PUBLIC MoveService : - public lay::ViewService, public lay::Plugin + public lay::EditorServiceBase { public: MoveService (lay::LayoutViewBase *view); ~MoveService (); + bool start_move (db::Transaction *transaction = 0, bool transient_selection = false); + bool configure (const std::string &name, const std::string &value); - bool begin_move (db::Transaction *transaction = 0, bool transient_selection = false); void finish (); void cancel (); - lay::ViewService *view_service_interface () - { - return this; - } - private: virtual bool mouse_press_event (const db::DPoint &p, unsigned int buttons, bool prio); virtual bool mouse_click_event (const db::DPoint &p, unsigned int buttons, bool prio); @@ -61,14 +55,13 @@ private: virtual bool wheel_event (int delta, bool horizontal, const db::DPoint &p, unsigned int buttons, bool prio); virtual bool key_event (unsigned int key, unsigned int buttons); virtual void drag_cancel (); - virtual void activated (); virtual void deactivated (); + int focus_page_open (EditorOptionsPage *fp); bool handle_click (const db::DPoint &p, unsigned int buttons, bool drag_transient, db::Transaction *transaction); bool m_dragging; bool m_dragging_transient; - bool m_active; lay::Editables *mp_editables; lay::LayoutViewBase *mp_view; double m_global_grid; diff --git a/src/laybasic/laybasic/laybasic.pro b/src/laybasic/laybasic/laybasic.pro index 52ce019fc..f6998f621 100644 --- a/src/laybasic/laybasic/laybasic.pro +++ b/src/laybasic/laybasic/laybasic.pro @@ -37,6 +37,7 @@ SOURCES += \ layAbstractMenu.cc \ layEditorOptionsPage.cc \ layEditorOptionsPages.cc \ + layEditorUtils.cc \ layLayoutViewConfig.cc \ layMargin.cc \ laybasicForceLink.cc \ @@ -91,6 +92,7 @@ SOURCES += \ HEADERS += \ layEditorOptionsPage.h \ layEditorOptionsPages.h \ + layEditorUtils.h \ layMargin.h \ laybasicConfig.h \ laybasicForceLink.h \ diff --git a/src/layui/layui/layLayoutViewFunctions.cc b/src/layui/layui/layLayoutViewFunctions.cc index a0b04f0c8..6f1417813 100644 --- a/src/layui/layui/layLayoutViewFunctions.cc +++ b/src/layui/layui/layLayoutViewFunctions.cc @@ -1543,7 +1543,7 @@ void LayoutViewFunctions::cm_sel_move_interactive () { view ()->cancel_edits (); - if (view ()->move_service ()->begin_move ()) { + if (view ()->move_service ()->start_move ()) { view ()->switch_mode (-1); // move mode } }