From 5bd73bb8bfda7e834fc974b50ee19e94dd618e24 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 3 Aug 2020 20:20:25 +0200 Subject: [PATCH] 'tap' now changes the current layer while editing and also initiates polygons, paths and boxes. --- src/edt/edt/edtMainService.cc | 7 +++++++ src/edt/edt/edtService.cc | 19 +++++++++++++++---- src/edt/edt/edtService.h | 19 +++++++++++++++++++ src/edt/edt/edtServiceImpl.cc | 15 +++++++++++++-- src/edt/edt/edtServiceImpl.h | 8 +++++--- 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/edt/edt/edtMainService.cc b/src/edt/edt/edtMainService.cc index 1fd2d3340..95274dad8 100644 --- a/src/edt/edt/edtMainService.cc +++ b/src/edt/edt/edtMainService.cc @@ -1997,9 +1997,16 @@ MainService::cm_tap () QAction *action = menu->exec (mp); if (action) { + int index = action->data ().toInt (); lay::LayerPropertiesConstIterator iter = tapped_layers [index]; view ()->set_current_layer (iter); + + edt::Service *es = dynamic_cast (view ()->view_object_widget ()->active_service ()); + if (es) { + es->tap (pt); + } + } } diff --git a/src/edt/edt/edtService.cc b/src/edt/edt/edtService.cc index 0e5986b5c..f8dd7ee84 100644 --- a/src/edt/edt/edtService.cc +++ b/src/edt/edt/edtService.cc @@ -710,8 +710,7 @@ Service::mouse_move_event (const db::DPoint &p, unsigned int buttons, bool prio) // in this mode, ignore exceptions here since it is rather annoying to have messages popping // up then. try { - do_begin_edit (p); - m_editing = true; + begin_edit (p); } catch (...) { set_edit_marker (0); } @@ -744,8 +743,7 @@ Service::mouse_press_event (const db::DPoint &p, unsigned int buttons, bool prio view ()->cancel (); // cancel any pending edit operations and clear the selection set_edit_marker (0); - do_begin_edit (p); - m_editing = true; + begin_edit (p); } else { if (do_mouse_click (p)) { @@ -1432,6 +1430,19 @@ Service::move_markers (const db::DTrans &t) } } +void +Service::begin_edit (const db::DPoint &p) +{ + do_begin_edit (p); + m_editing = true; +} + +void +Service::tap (const db::DPoint & /*initial*/) +{ + // .. nothing here .. +} + void Service::selection_to_view () { diff --git a/src/edt/edt/edtService.h b/src/edt/edt/edtService.h index cb4812f79..6e93219cb 100644 --- a/src/edt/edt/edtService.h +++ b/src/edt/edt/edtService.h @@ -44,6 +44,10 @@ #include #include +namespace lay { + class LayerPropertiesConstIterator; +} + namespace edt { class Service; @@ -344,6 +348,11 @@ public: */ virtual void edit_cancel (); + /** + * @brief Triggered by tap - gives the new layer and if required the initial point + */ + virtual void tap (const db::DPoint &initial); + /** * @brief Delete the selected rulers * @@ -383,6 +392,11 @@ protected: */ void selection_to_view (); + /** + * @brief starts editing at the given point. + */ + void begin_edit (const db::DPoint &p); + /** * @brief Reimplemented by the specific implementation of the shape editors * @@ -528,6 +542,11 @@ protected: return m_max_shapes_of_instances; } + bool editing () const + { + return m_editing; + } + private: // The layout view that the editor service is attached to lay::LayoutView *mp_view; diff --git a/src/edt/edt/edtServiceImpl.cc b/src/edt/edt/edtServiceImpl.cc index 691bff357..8e73c2775 100644 --- a/src/edt/edt/edtServiceImpl.cc +++ b/src/edt/edt/edtServiceImpl.cc @@ -69,17 +69,18 @@ void ShapeEditService::get_edit_layer () { lay::LayerPropertiesConstIterator cl = view ()->current_layer (); + if (cl.is_null ()) { throw tl::Exception (tl::to_string (QObject::tr ("Please select a layer first"))); } if (! cl->visible (true)) { lay::TipDialog td (QApplication::activeWindow (), - tl::to_string (QObject::tr ("You are about to draw on a hidden layer. The result won't be visible.")), + tl::to_string (QObject::tr ("You are about to draw on a hidden layer. The result won't be visible.")), "drawing-on-invisible-layer"); td.exec_dialog (); } - + int cv_index = cl->cellview_index (); const lay::CellView &cv = view ()->cellview (cv_index); int layer = cl->layer_index (); @@ -128,6 +129,16 @@ ShapeEditService::get_edit_layer () } } +void +ShapeEditService::tap (const db::DPoint &initial) +{ + if (editing ()) { + get_edit_layer (); + } else { + begin_edit (initial); + } +} + /** * @brief Deliver a good interpolation between two points m and p * diff --git a/src/edt/edt/edtServiceImpl.h b/src/edt/edt/edtServiceImpl.h index 60955035b..3fdad1ef2 100644 --- a/src/edt/edt/edtServiceImpl.h +++ b/src/edt/edt/edtServiceImpl.h @@ -32,6 +32,7 @@ namespace lay { class CellView; + class LayerPropertiesConstIterator; } namespace edt @@ -57,10 +58,11 @@ protected: db::Cell &cell () const { return *mp_cell; } db::Layout &layout () const { return *mp_layout; } - void do_mouse_move_inactive (const db::DPoint &p); + virtual void do_mouse_move_inactive (const db::DPoint &p); + virtual void tap (const db::DPoint &initial); + + virtual bool configure (const std::string &name, const std::string &value); - bool configure (const std::string &name, const std::string &value); - protected: std::pair interpolate (const db::DPoint &m, const db::DPoint &o, const db::DPoint &p) const; void deliver_shape (const db::Polygon &poly);