From af6f11c2b3a2d35774ee4150bdf08b8f9c15b5f8 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 18 Apr 2021 14:02:26 +0200 Subject: [PATCH] Fixes #715 (selection box larger than drawn) --- src/ant/ant/antService.cc | 10 +++- src/ant/ant/antService.h | 9 ++- src/edt/edt/edtPartialService.cc | 10 +++- src/edt/edt/edtPartialService.h | 9 ++- src/edt/edt/edtService.cc | 10 +++- src/edt/edt/edtService.h | 9 ++- src/img/img/imgService.cc | 8 ++- src/img/img/imgService.h | 7 ++- .../laybasic/LayoutViewConfigPage2c.ui | 55 +++++++++++++------ src/laybasic/laybasic/layEditable.h | 13 ++++- src/laybasic/laybasic/layLayoutView.cc | 20 +++++++ src/laybasic/laybasic/layLayoutView.h | 17 +++++- .../laybasic/layLayoutViewConfigPages.cc | 6 ++ src/laybasic/laybasic/laybasicConfig.h | 1 + testdata/ruby/layLayoutView.rb | 1 + 15 files changed, 151 insertions(+), 34 deletions(-) diff --git a/src/ant/ant/antService.cc b/src/ant/ant/antService.cc index f9666fd2c..74f8bd9fd 100644 --- a/src/ant/ant/antService.cc +++ b/src/ant/ant/antService.cc @@ -887,7 +887,13 @@ Service::catch_distance () return double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); } -void +double +Service::catch_distance_box () +{ + return double (view ()->search_range_box ()) / widget ()->mouse_event_trans ().mag (); +} + +void Service::drag_cancel () { if (m_drawing) { @@ -2037,7 +2043,7 @@ Service::select (const db::DBox &box, lay::Editable::SelectionMode mode) } else { // compute search box - double l = catch_distance (); + double l = box.is_point () ? catch_distance () : catch_distance_box (); db::DBox search_dbox = box.enlarged (db::DVector (l, l)); if (! box.is_point ()) { diff --git a/src/ant/ant/antService.h b/src/ant/ant/antService.h index 657fc4154..52d6516fb 100644 --- a/src/ant/ant/antService.h +++ b/src/ant/ant/antService.h @@ -276,11 +276,16 @@ public: virtual double click_proximity (const db::DPoint &pos, lay::Editable::SelectionMode mode); /** - * @brief Gets the catch distance + * @brief Gets the catch distance (for single click) */ virtual double catch_distance (); - /** + /** + * @brief Gets the catch distance (for box) + */ + virtual double catch_distance_box (); + + /** * @brief "select" operation */ virtual bool select (const db::DBox &box, lay::Editable::SelectionMode mode); diff --git a/src/edt/edt/edtPartialService.cc b/src/edt/edt/edtPartialService.cc index 6223a0649..abe291b3d 100644 --- a/src/edt/edt/edtPartialService.cc +++ b/src/edt/edt/edtPartialService.cc @@ -2349,7 +2349,13 @@ PartialService::catch_distance () return double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); } -db::DPoint +double +PartialService::catch_distance_box () +{ + return double (view ()->search_range_box ()) / widget ()->mouse_event_trans ().mag (); +} + +db::DPoint PartialService::single_selected_point () const { // build the transformation variants cache and @@ -2576,7 +2582,7 @@ PartialService::partial_select (const db::DBox &box, lay::Editable::SelectionMod clear_partial_transient_selection (); // compute search box - double l = catch_distance (); + double l = box.is_point () ? catch_distance () : catch_distance_box (); db::DBox search_box = box.enlarged (db::DVector (l, l)); bool needs_update = false; diff --git a/src/edt/edt/edtPartialService.h b/src/edt/edt/edtPartialService.h index cc94f27d5..d59b1a64e 100644 --- a/src/edt/edt/edtPartialService.h +++ b/src/edt/edt/edtPartialService.h @@ -235,11 +235,16 @@ public: virtual void transform (const db::DCplxTrans &tr); /** - * @brief Gets the catch distance + * @brief Gets the catch distance (for single click) */ virtual double catch_distance (); - /** + /** + * @brief Gets the catch distance (for box) + */ + virtual double catch_distance_box (); + + /** * @brief Indicates whether objects are selected */ virtual bool has_selection (); diff --git a/src/edt/edt/edtService.cc b/src/edt/edt/edtService.cc index e27414117..6008078a7 100644 --- a/src/edt/edt/edtService.cc +++ b/src/edt/edt/edtService.cc @@ -895,7 +895,13 @@ Service::catch_distance () return double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); } -double +double +Service::catch_distance_box () +{ + return double (view ()->search_range_box ()) / widget ()->mouse_event_trans ().mag (); +} + +double Service::click_proximity (const db::DPoint &pos, lay::Editable::SelectionMode mode) { // compute search box @@ -1231,7 +1237,7 @@ bool Service::select (const db::DBox &box, lay::Editable::SelectionMode mode) { // compute search box - double l = catch_distance (); + double l = box.is_point () ? catch_distance () : catch_distance_box (); db::DBox search_box = box.enlarged (db::DVector (l, l)); bool needs_update = false; diff --git a/src/edt/edt/edtService.h b/src/edt/edt/edtService.h index 129838ddf..28e61a2e9 100644 --- a/src/edt/edt/edtService.h +++ b/src/edt/edt/edtService.h @@ -179,11 +179,16 @@ public: virtual double click_proximity (const db::DPoint &pos, lay::Editable::SelectionMode mode); /** - * @brief Gets the catch distance + * @brief Gets the catch distance (for single click) */ virtual double catch_distance (); - /** + /** + * @brief Gets the catch distance (for box) + */ + virtual double catch_distance_box (); + + /** * @brief "select" operation */ virtual bool select (const db::DBox &box, lay::Editable::SelectionMode mode); diff --git a/src/img/img/imgService.cc b/src/img/img/imgService.cc index ace1ba630..71ab0e8b1 100644 --- a/src/img/img/imgService.cc +++ b/src/img/img/imgService.cc @@ -1153,6 +1153,12 @@ Service::catch_distance () return double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); } +double +Service::catch_distance_box () +{ + return double (view ()->search_range_box ()) / widget ()->mouse_event_trans ().mag (); +} + double Service::click_proximity (const db::DPoint &pos, lay::Editable::SelectionMode mode) { @@ -1293,7 +1299,7 @@ Service::select (const db::DBox &box, lay::Editable::SelectionMode mode) } else { // compute search box - double l = catch_distance (); + double l = box.is_point () ? catch_distance () : catch_distance_box (); db::DBox search_dbox = box.enlarged (db::DVector (l, l)); if (! box.is_point ()) { diff --git a/src/img/img/imgService.h b/src/img/img/imgService.h index e5976ec32..d3739fcfe 100644 --- a/src/img/img/imgService.h +++ b/src/img/img/imgService.h @@ -295,10 +295,15 @@ public: virtual double click_proximity (const db::DPoint &pos, lay::Editable::SelectionMode mode); /** - * @brief Gets the catch distance + * @brief Gets the catch distance for single click */ virtual double catch_distance (); + /** + * @brief Gets the catch distance for box + */ + virtual double catch_distance_box (); + /** * @brief "select" operation */ diff --git a/src/laybasic/laybasic/LayoutViewConfigPage2c.ui b/src/laybasic/laybasic/LayoutViewConfigPage2c.ui index 27e462baa..ec01634f5 100644 --- a/src/laybasic/laybasic/LayoutViewConfigPage2c.ui +++ b/src/laybasic/laybasic/LayoutViewConfigPage2c.ui @@ -214,7 +214,7 @@ QFrame::Raised - + 0 @@ -227,28 +227,14 @@ 0 - - - - Capture range to mouse cursor - - - - - - - 9999 - - - - + pixel - + Qt::Horizontal @@ -261,6 +247,41 @@ + + + + 9999 + + + + + + + Capture range to mouse cursor (single click) + + + + + + + Capture range to mouse cursor (box) + + + + + + + 9999 + + + + + + + pixel + + + diff --git a/src/laybasic/laybasic/layEditable.h b/src/laybasic/laybasic/layEditable.h index a2bfe7de1..59cbcde0d 100644 --- a/src/laybasic/laybasic/layEditable.h +++ b/src/laybasic/laybasic/layEditable.h @@ -156,7 +156,7 @@ public: } /** - * @brief The catch distance + * @brief The catch distance (for single click) * * The catch distance is a typical value for the "fuzzyness" of a mouse click. * It is given in micron. @@ -166,6 +166,17 @@ public: return 0.0; } + /** + * @brief The catch distance (for box) + * + * The catch distance is a typical value for the "fuzzyness" of a box selection. + * It is given in micron. + */ + virtual double catch_distance_box () + { + return 0.0; + } + /** * @brief transient selection * diff --git a/src/laybasic/laybasic/layLayoutView.cc b/src/laybasic/laybasic/layLayoutView.cc index 78c676c0a..1d73fdbb6 100644 --- a/src/laybasic/laybasic/layLayoutView.cc +++ b/src/laybasic/laybasic/layLayoutView.cc @@ -463,6 +463,7 @@ LayoutView::init (db::Manager *mgr, QWidget * /*parent*/) m_always_show_ld = true; m_always_show_layout_index = false; m_search_range = 5; + m_search_range_box = 0; m_layer_properties_lists.push_back (new LayerPropertiesList ()); m_layer_properties_lists.back ()->attach_view (this, (unsigned int) (m_layer_properties_lists.size () - 1)); @@ -1250,6 +1251,13 @@ LayoutView::configure (const std::string &name, const std::string &value) set_search_range (n); return true; + } else if (name == cfg_search_range_box) { + + unsigned int n; + tl::from_string (value, n); + set_search_range_box (n); + return true; + } else if (name == cfg_abstract_mode_enabled) { bool e; @@ -5882,6 +5890,18 @@ LayoutView::set_search_range (unsigned int sr) m_search_range = sr; } +unsigned int +LayoutView::search_range_box () +{ + return m_search_range_box; +} + +void +LayoutView::set_search_range_box (unsigned int sr) +{ + m_search_range_box = sr; +} + void LayoutView::message (const std::string &s, int timeout) { diff --git a/src/laybasic/laybasic/layLayoutView.h b/src/laybasic/laybasic/layLayoutView.h index 75cd1c4d0..93c0545d8 100644 --- a/src/laybasic/laybasic/layLayoutView.h +++ b/src/laybasic/laybasic/layLayoutView.h @@ -2277,17 +2277,29 @@ public: } /** - * @brief Gets the "search range" in pixels + * @brief Gets the "search range" in pixels (for single click) * The search range applies whenever some object is looked up in the vicinity of the * mouse cursor. This value gives the search range in pixels. */ unsigned int search_range (); /** - * @brief Sets the "search range" in pixels + * @brief Sets the "search range" in pixels (for single click) */ void set_search_range (unsigned int sr); + /** + * @brief Gets the "search range" in pixels (for box) + * The search range applies whenever some object is looked up in the vicinity of the + * mouse cursor. This value gives the search range in pixels. + */ + unsigned int search_range_box (); + + /** + * @brief Sets the "search range" in pixels (for box) + */ + void set_search_range_box (unsigned int sr); + /** * @brief Return true, if any cellview is editable */ @@ -2808,6 +2820,7 @@ private: bool m_marker_halo; unsigned int m_search_range; + unsigned int m_search_range_box; bool m_transient_selection_mode; bool m_sel_inside_pcells; diff --git a/src/laybasic/laybasic/layLayoutViewConfigPages.cc b/src/laybasic/laybasic/layLayoutViewConfigPages.cc index 506b63294..fd9d48996 100644 --- a/src/laybasic/laybasic/layLayoutViewConfigPages.cc +++ b/src/laybasic/laybasic/layLayoutViewConfigPages.cc @@ -374,6 +374,10 @@ LayoutViewConfigPage2c::setup (lay::Dispatcher *root) unsigned int sr = 0; root->config_get (cfg_search_range, sr); mp_ui->search_range_spinbx->setValue (sr); + + unsigned int srbox = 0; + root->config_get (cfg_search_range_box, srbox); + mp_ui->search_range_box_spinbx->setValue (srbox); } void @@ -388,6 +392,7 @@ LayoutViewConfigPage2c::commit (lay::Dispatcher *root) root->config_set (cfg_sel_transient_mode, mp_ui->transient_mode_cb->isChecked ()); root->config_set (cfg_sel_inside_pcells_mode, mp_ui->sel_inside_pcells_cb->isChecked ()); root->config_set (cfg_search_range, (unsigned int) mp_ui->search_range_spinbx->value ()); + root->config_set (cfg_search_range_box, (unsigned int) mp_ui->search_range_box_spinbx->value ()); } // ------------------------------------------------------------ @@ -1564,6 +1569,7 @@ public: options.push_back (std::pair (cfg_child_ctx_hollow, "false")); options.push_back (std::pair (cfg_child_ctx_enabled, "false")); options.push_back (std::pair (cfg_search_range, "5")); + options.push_back (std::pair (cfg_search_range_box, "0")); options.push_back (std::pair (cfg_abstract_mode_width, "10.0")); options.push_back (std::pair (cfg_abstract_mode_enabled, "false")); options.push_back (std::pair (cfg_fit_new_cell, "true")); diff --git a/src/laybasic/laybasic/laybasicConfig.h b/src/laybasic/laybasic/laybasicConfig.h index e2f596f54..3cdd575f0 100644 --- a/src/laybasic/laybasic/laybasicConfig.h +++ b/src/laybasic/laybasic/laybasicConfig.h @@ -62,6 +62,7 @@ static const std::string cfg_child_ctx_hollow ("child-context-hollow"); static const std::string cfg_child_ctx_enabled ("child-context-enabled"); static const std::string cfg_search_range ("search-range"); +static const std::string cfg_search_range_box ("search-range-box"); static const std::string cfg_abstract_mode_enabled ("abstract-mode-enabled"); static const std::string cfg_abstract_mode_width ("abstract-mode-width"); diff --git a/testdata/ruby/layLayoutView.rb b/testdata/ruby/layLayoutView.rb index 056e53f82..8ed0b6817 100644 --- a/testdata/ruby/layLayoutView.rb +++ b/testdata/ruby/layLayoutView.rb @@ -183,6 +183,7 @@ class LAYLayoutView_TestClass < TestBase assert_equal(view.has_selection?, false) assert_equal(view.selection_size, 0) + view.set_config("search-range-box", "5") view.select_from(RBA::DBox::new(-1.0, -1.0, 1.0, 1.0)) assert_equal(selection_changed, 1) assert_equal(view.selection_size, 4)