diff --git a/src/ant/ant/antService.cc b/src/ant/ant/antService.cc index 2fd33146d..3975255fb 100644 --- a/src/ant/ant/antService.cc +++ b/src/ant/ant/antService.cc @@ -641,11 +641,6 @@ draw_ruler (const ant::Object &ruler, const db::DCplxTrans &trans, bool sel, lay } -// ------------------------------------------------------------- - -// search range for select in pixels -static unsigned int search_range = 5; // TODO: make variable? - // ------------------------------------------------------------- View::View (ant::Service *rulers, const ant::Object *ruler, bool selected) @@ -888,6 +883,12 @@ Service::clear_rulers () reduce_rulers (0); } +double +Service::catch_distance () +{ + return double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); +} + void Service::drag_cancel () { @@ -1046,7 +1047,7 @@ Service::begin_move (lay::Editable::MoveMode mode, const db::DPoint &p, lay::ang m_move_mode = MoveNone; // compute search box - double l = double (search_range) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); db::DBox search_dbox = db::DBox (p, p).enlarged (db::DVector (l, l)); // test, whether we are moving a handle of one selected object @@ -1081,7 +1082,7 @@ Service::begin_move (lay::Editable::MoveMode mode, const db::DPoint &p, lay::ang m_move_mode = MoveNone; // compute search box - double l = double (search_range) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); db::DBox search_dbox = db::DBox (p, p).enlarged (db::DVector (l, l)); // box-selection @@ -1803,7 +1804,7 @@ double Service::click_proximity (const db::DPoint &pos, lay::Editable::SelectionMode mode) { // compute search box - double l = double (search_range) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); db::DBox search_dbox = db::DBox (pos, pos).enlarged (db::DVector (l, l)); // for single-point selections either exclude the current selection or the @@ -1858,7 +1859,7 @@ Service::transient_select (const db::DPoint &pos) bool any_selected = false; // compute search box - double l = double (search_range) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); db::DBox search_dbox = db::DBox (pos, pos).enlarged (db::DVector (l, l)); // point selection: look for the "closest" ruler @@ -1963,7 +1964,7 @@ Service::select (const db::DBox &box, lay::Editable::SelectionMode mode) } else { // compute search box - double l = double (search_range) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); 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 67226e3fa..459e2ca99 100644 --- a/src/ant/ant/antService.h +++ b/src/ant/ant/antService.h @@ -269,6 +269,11 @@ public: */ virtual double click_proximity (const db::DPoint &pos, lay::Editable::SelectionMode mode); + /** + * @brief Gets the catch distance + */ + virtual double catch_distance (); + /** * @brief "select" operation */ diff --git a/src/edt/edt/edtPartialService.cc b/src/edt/edt/edtPartialService.cc index ce00d229c..19ca9129b 100644 --- a/src/edt/edt/edtPartialService.cc +++ b/src/edt/edt/edtPartialService.cc @@ -1094,7 +1094,7 @@ PartialService::timeout () mp_view->clear_transient_selection (); // compute search box - double l = double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); db::DBox search_box = db::DBox (m_hover_point, m_hover_point).enlarged (db::DVector (l, l)); PartialShapeFinder finder (true, m_top_level_sel, db::ShapeIterator::All); @@ -1748,7 +1748,7 @@ PartialService::mouse_click_event (const db::DPoint &p, unsigned int buttons, bo try { // compute search box - double l = double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); db::DBox search_box = db::DBox (p, p).enlarged (db::DVector (l, l)); // check, if there is a selected shape under the mouse - in this case, we do not do a new selection @@ -2324,6 +2324,12 @@ PartialService::enter_edge (const EdgeWithIndex &e, size_t &nmarker, partial_obj } +double +PartialService::catch_distance () +{ + return double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); +} + db::DPoint PartialService::single_selected_point () const { @@ -2551,7 +2557,7 @@ PartialService::partial_select (const db::DBox &box, lay::Editable::SelectionMod clear_partial_transient_selection (); // compute search box - double l = double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); 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 495bae649..bdee61c26 100644 --- a/src/edt/edt/edtPartialService.h +++ b/src/edt/edt/edtPartialService.h @@ -238,6 +238,11 @@ public: */ virtual void transform (const db::DCplxTrans &tr); + /** + * @brief Gets the catch distance + */ + virtual double catch_distance (); + /** * @brief Returns the number of selected objects */ diff --git a/src/edt/edt/edtService.cc b/src/edt/edt/edtService.cc index cc1f85f55..8047460cd 100644 --- a/src/edt/edt/edtService.cc +++ b/src/edt/edt/edtService.cc @@ -825,11 +825,17 @@ Service::has_transient_selection () return ! m_transient_selection.empty (); } +double +Service::catch_distance () +{ + return double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); +} + double Service::click_proximity (const db::DPoint &pos, lay::Editable::SelectionMode mode) { // compute search box - double l = double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); db::DBox search_box = db::DBox (pos, pos).enlarged (db::DVector (l, l)); // for single-point selections either exclude the current selection or the @@ -889,7 +895,7 @@ Service::transient_select (const db::DPoint &pos) } // compute search box - double l = double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); db::DBox search_box = db::DBox (pos, pos).enlarged (db::DVector (l, l)); if (m_cell_inst_service) { @@ -1152,7 +1158,7 @@ bool Service::select (const db::DBox &box, lay::Editable::SelectionMode mode) { // compute search box - double l = double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); 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 dbb27a822..a4c8aae54 100644 --- a/src/edt/edt/edtService.h +++ b/src/edt/edt/edtService.h @@ -162,6 +162,11 @@ public: */ virtual double click_proximity (const db::DPoint &pos, lay::Editable::SelectionMode mode); + /** + * @brief Gets the catch distance + */ + virtual double catch_distance (); + /** * @brief "select" operation */ diff --git a/src/img/img/imgService.cc b/src/img/img/imgService.cc index 0df792140..2bcafcf50 100644 --- a/src/img/img/imgService.cc +++ b/src/img/img/imgService.cc @@ -428,11 +428,6 @@ View::render (const lay::Viewport &vp, lay::ViewObjectCanvas &canvas) } } -// ------------------------------------------------------------- - -// search range for select in pixels -static unsigned int search_range = 5; // TODO: make variable? - // ------------------------------------------------------------- // img::Service implementation @@ -599,7 +594,7 @@ Service::begin_move (lay::Editable::MoveMode mode, const db::DPoint &p, lay::ang widget ()->drag_cancel (); // KLUDGE: every service does this to the same service manager // compute search box - double l = double (search_range) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); db::DBox search_dbox = db::DBox (p, p).enlarged (db::DVector (l, l)); // choose move mode @@ -1104,11 +1099,17 @@ Service::clear_selection () clear_transient_selection (); } +double +Service::catch_distance () +{ + return double (view ()->search_range ()) / widget ()->mouse_event_trans ().mag (); +} + double Service::click_proximity (const db::DPoint &pos, lay::Editable::SelectionMode mode) { // compute search box - double l = double (search_range) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); db::DBox search_dbox = db::DBox (pos, pos).enlarged (db::DVector (l, l)); // for single-point selections either exclude the current selection or the @@ -1142,7 +1143,7 @@ Service::transient_select (const db::DPoint &pos) bool any_selected = false; // compute search box - double l = double (search_range) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); db::DBox search_dbox = db::DBox (pos, pos).enlarged (db::DVector (l, l)); // point selection: look for the "closest" image @@ -1240,7 +1241,7 @@ Service::select (const db::DBox &box, lay::Editable::SelectionMode mode) } else { // compute search box - double l = double (search_range) / widget ()->mouse_event_trans ().mag (); + double l = catch_distance (); 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 b689e8a63..e0c679bca 100644 --- a/src/img/img/imgService.h +++ b/src/img/img/imgService.h @@ -284,7 +284,12 @@ public: */ virtual double click_proximity (const db::DPoint &pos, lay::Editable::SelectionMode mode); - /** + /** + * @brief Gets the catch distance + */ + virtual double catch_distance (); + + /** * @brief "select" operation */ virtual bool select (const db::DBox &box, lay::Editable::SelectionMode mode); diff --git a/src/laybasic/laybasic/layEditable.cc b/src/laybasic/laybasic/layEditable.cc index fedceef0b..d2dff0e4f 100644 --- a/src/laybasic/laybasic/layEditable.cc +++ b/src/laybasic/laybasic/layEditable.cc @@ -143,7 +143,18 @@ Editables::selection_bbox () return sel_bbox; } -void +db::DBox +Editables::selection_catch_bbox () +{ + db::DBox sel_bbox; + for (iterator e = begin (); e != end (); ++e) { + double l = e->catch_distance (); + sel_bbox += e->selection_bbox ().enlarged (db::DVector (l, l)); + } + return sel_bbox; +} + +void Editables::transform (const db::DCplxTrans &tr) { if (selection_size () > 0) { @@ -434,7 +445,7 @@ Editables::begin_move (const db::DPoint &p, lay::angle_constraint_type ac) // sort the plugins found by the proximity std::sort (plugins.begin (), plugins.end (), first_of_pair_cmp_f ()); - if (selection_size () > 0 && selection_bbox ().contains (p)) { + if (selection_size () > 0 && selection_catch_bbox ().contains (p)) { // if anything is selected and we are within the selection bbox, // issue a move operation on all editables: first try a Partial mode begin_move diff --git a/src/laybasic/laybasic/layEditable.h b/src/laybasic/laybasic/layEditable.h index 7f80e4e8a..6b48aa169 100644 --- a/src/laybasic/laybasic/layEditable.h +++ b/src/laybasic/laybasic/layEditable.h @@ -154,6 +154,17 @@ public: return std::numeric_limits::max (); } + /** + * @brief The catch distance + * + * The catch distance is a typical value for the "fuzzyness" of a mouse click. + * It is given in micron. + */ + virtual double catch_distance () + { + return 0.0; + } + /** * @brief transient selection * @@ -577,6 +588,8 @@ private: bool m_move_selection; bool m_any_move_operation; db::DBox m_last_selected_point; + + db::DBox selection_catch_bbox (); }; }