From 5578b01f033a55f543d449d170396a0ffdb97a3f Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 23 Nov 2024 23:38:53 +0100 Subject: [PATCH] Some refactoring with the goal to support "move by" with "clone interactive" --- src/ant/ant/antService.cc | 3 -- src/img/img/imgService.cc | 3 -- src/laybasic/laybasic/layEditable.cc | 22 ++++++++++-- src/laybasic/laybasic/layEditable.h | 42 ++++++++++++++++++---- src/laybasic/laybasic/layLayoutViewBase.cc | 31 ++++++++++++++-- src/laybasic/laybasic/layLayoutViewBase.h | 16 ++++++++- src/laybasic/laybasic/layMove.cc | 21 ++++++++--- src/laybasic/laybasic/layMove.h | 2 ++ src/laybasic/laybasic/layViewObject.h | 2 +- src/layui/layui/layLayoutViewFunctions.cc | 11 +++--- src/layview/layview/layLayoutView_qt.cc | 11 ++++++ src/layview/layview/layLayoutView_qt.h | 5 +++ 12 files changed, 138 insertions(+), 31 deletions(-) diff --git a/src/ant/ant/antService.cc b/src/ant/ant/antService.cc index 8477b6231..e380df795 100644 --- a/src/ant/ant/antService.cc +++ b/src/ant/ant/antService.cc @@ -1382,9 +1382,6 @@ dragging_what (const ant::Object *robj, const db::DBox &search_dbox, ant::Servic bool Service::begin_move (lay::Editable::MoveMode mode, const db::DPoint &p, lay::angle_constraint_type /*ac*/) { - // cancel any pending move or drag operations, reset mp_active_ruler - ui ()->drag_cancel (); // KLUDGE: every service does this to the same service manager - clear_transient_selection (); // choose move mode diff --git a/src/img/img/imgService.cc b/src/img/img/imgService.cc index 249e1a0f9..3c50e0531 100644 --- a/src/img/img/imgService.cc +++ b/src/img/img/imgService.cc @@ -588,9 +588,6 @@ Service::mouse_move_event (const db::DPoint & /*p*/, unsigned int /*buttons*/, b bool Service::begin_move (lay::Editable::MoveMode mode, const db::DPoint &p, lay::angle_constraint_type /*ac*/) { - // cancel any pending move or drag operations - widget ()->drag_cancel (); // KLUDGE: every service does this to the same service manager - // compute search box double l = catch_distance (); db::DBox search_dbox = db::DBox (p, p).enlarged (db::DVector (l, l)); diff --git a/src/laybasic/laybasic/layEditable.cc b/src/laybasic/laybasic/layEditable.cc index 17cc210d3..98290689d 100644 --- a/src/laybasic/laybasic/layEditable.cc +++ b/src/laybasic/laybasic/layEditable.cc @@ -165,9 +165,9 @@ Editables::selection_catch_bbox () } void -Editables::transform (const db::DCplxTrans &t, db::Transaction *transaction) +Editables::transform (const db::DCplxTrans &t) { - std::unique_ptr trans_holder (transaction ? transaction : new db::Transaction (manager (), tl::to_string (tr ("Transform")))); + std::unique_ptr trans_holder (new db::Transaction (manager (), tl::to_string (tr ("Transform")))); if (has_selection ()) { @@ -639,15 +639,31 @@ Editables::edit_cancel () } } +void +Editables::edit_finish () +{ + clear_previous_selection (); + for (iterator e = begin (); e != end (); ++e) { + e->edit_finish (); + } +} + void Editables::cancel_edits () { - // cancel any edit operations for (iterator e = begin (); e != end (); ++e) { e->edit_cancel (); } } +void +Editables::finish_edits () +{ + for (iterator e = begin (); e != end (); ++e) { + e->edit_finish (); + } +} + void Editables::show_properties () { diff --git a/src/laybasic/laybasic/layEditable.h b/src/laybasic/laybasic/layEditable.h index 486223981..779677db8 100644 --- a/src/laybasic/laybasic/layEditable.h +++ b/src/laybasic/laybasic/layEditable.h @@ -332,6 +332,20 @@ public: // .. by default, nothing is implemented .. } + /** + * @brief Finishes any pending operations + * + * This event is sent whenever a pending operation such as + * a move operation should be finished. + * In contrast to "edit_cancel", this version is supposed + * not to rollback, for example if transactions are involved. + */ + virtual void edit_finish () + { + // by default maps to edit_cancel + edit_cancel (); + } + /** * @brief Indicates if any objects are selected */ @@ -457,14 +471,11 @@ public: db::DBox selection_bbox (); /** - * @brief transform the selection + * @brief Transforms the selection * * The transformation is given in micron units. - * - * If a transaction is given, the operation will be appended to this pending transaction. - * The Editables object takes ownership over the Transaction object. */ - void transform (const db::DCplxTrans &tr, db::Transaction *transaction = 0); + virtual void transform (const db::DCplxTrans &tr); /** * @brief Enable or disable a certain editable @@ -565,9 +576,18 @@ public: /** * @brief Cancel any pending operations + * + * This method calls "edit_cancel" on all services and resets selection tracking. */ void edit_cancel (); + /** + * @brief Finishes any pending operations + * + * This method calls "edit_finish" on all services and resets selection tracking. + */ + void edit_finish (); + /** * @brief Editable iterator: begin */ @@ -633,11 +653,21 @@ protected: * @brief Cancel all edit operations * * This method can be overridden in order to implement special behaviour on cancel - * of edits (i.e. release the mouse). + * of edits (e.g. clean up markers). * Make sure, the base implementation is called as well. */ virtual void cancel_edits (); + /** + * @brief Finishes all edit operations + * + * This method can be overridden in order to implement special behaviour on finishing + * of edits (e.g. clean up markers). In contrast to "cancel_edits", this method + * is expected not to rollback any operations - i.e. undo transactions. + * Make sure, the base implementation is called as well. + */ + virtual void finish_edits (); + private: friend class Editable; diff --git a/src/laybasic/laybasic/layLayoutViewBase.cc b/src/laybasic/laybasic/layLayoutViewBase.cc index 46dfca454..6d6f9ab11 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.cc +++ b/src/laybasic/laybasic/layLayoutViewBase.cc @@ -3983,12 +3983,41 @@ LayoutViewBase::redraw () mp_canvas->redraw_new (layers); } +void +LayoutViewBase::transform (const db::DCplxTrans &tr) +{ + finish_edits (); + lay::Editables::transform (tr); +} + void LayoutViewBase::cancel_edits () { + // the move service takes a special role here as it manages the + // transaction for the collective move operation. + mp_move_service->cancel (); + // cancel all drag and pending edit operations such as move operations. mp_canvas->drag_cancel (); lay::Editables::cancel_edits (); + + // re-enable edit mode + enable_edits (true); +} + +void +LayoutViewBase::finish_edits () +{ + // the move service takes a special role here as it manages the + // transaction for the collective move operation. + mp_move_service->finish (); + + // cancel all drag operations + mp_canvas->drag_cancel (); + lay::Editables::finish_edits (); + + // re-enable edit mode + enable_edits (true); } void @@ -3996,8 +4025,6 @@ LayoutViewBase::cancel () { // cancel all drags and pending edit operations such as move operations. cancel_edits (); - // re-enable edit mode - enable_edits (true); // and clear the selection clear_selection (); } diff --git a/src/laybasic/laybasic/layLayoutViewBase.h b/src/laybasic/laybasic/layLayoutViewBase.h index 85257d42f..2682e8477 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.h +++ b/src/laybasic/laybasic/layLayoutViewBase.h @@ -2666,6 +2666,13 @@ public: */ void cancel_edits (); + /** + * @brief Finishes all edit operations and maintains selection + * + * In contrast to "cancel_edits" there is no rollback of operations applied already. + */ + void finish_edits (); + /** * @brief Select all levels of hierarchy available */ @@ -2696,7 +2703,14 @@ public: */ void ensure_selection_visible (); - /** + /** + * @brief Transforms the selection + * + * The transformation is given in micron units. + */ + virtual void transform (const db::DCplxTrans &tr); + + /** * @brief Select a cell by index for a certain cell view * * This will be forwarded to select_cell or select_cell_fit depending diff --git a/src/laybasic/laybasic/layMove.cc b/src/laybasic/laybasic/layMove.cc index 4bc22e7d0..28266bfb9 100644 --- a/src/laybasic/laybasic/layMove.cc +++ b/src/laybasic/laybasic/layMove.cc @@ -302,6 +302,7 @@ MoveService::handle_click (const db::DPoint &p, unsigned int buttons, bool drag_ if (! m_dragging) { mp_transaction.reset (trans_holder.release ()); + ui ()->drag_cancel (); if (mp_editables->begin_move (p, ac_from_buttons (buttons))) { @@ -337,21 +338,31 @@ MoveService::handle_click (const db::DPoint &p, unsigned int buttons, bool drag_ } void -MoveService::drag_cancel () -{ +MoveService::drag_cancel () +{ m_shift = db::DPoint (); if (m_dragging) { - - mp_editables->edit_cancel (); ui ()->ungrab_mouse (this); - m_dragging = false; + } +} +void +MoveService::cancel () +{ + if (m_dragging) { if (mp_transaction.get ()) { mp_transaction->cancel (); } mp_transaction.reset (0); + } +} +void +MoveService::finish () +{ + if (m_dragging) { + mp_transaction.reset (0); } } diff --git a/src/laybasic/laybasic/layMove.h b/src/laybasic/laybasic/layMove.h index 8e3daf124..ea0bf2758 100644 --- a/src/laybasic/laybasic/layMove.h +++ b/src/laybasic/laybasic/layMove.h @@ -43,6 +43,8 @@ public: 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 (); private: virtual bool mouse_press_event (const db::DPoint &p, unsigned int buttons, bool prio); diff --git a/src/laybasic/laybasic/layViewObject.h b/src/laybasic/laybasic/layViewObject.h index 89698149e..994f7eca1 100644 --- a/src/laybasic/laybasic/layViewObject.h +++ b/src/laybasic/laybasic/layViewObject.h @@ -276,7 +276,7 @@ public: virtual void set_colors (tl::Color /*background*/, tl::Color /*text*/) { } /** - * @brief This method is called when a drag operation should be cancelled + * @brief This method is called when a mouse tracking operation should be cancelled */ virtual void drag_cancel () { } diff --git a/src/layui/layui/layLayoutViewFunctions.cc b/src/layui/layui/layLayoutViewFunctions.cc index da5bdafad..20ec394b2 100644 --- a/src/layui/layui/layLayoutViewFunctions.cc +++ b/src/layui/layui/layLayoutViewFunctions.cc @@ -1199,8 +1199,7 @@ LayoutViewFunctions::do_cm_duplicate (bool interactive) try { bool transient_mode = ! view ()->has_selection (); view ()->copy_view_objects (); - view ()->clear_selection (); - view ()->cancel (); + view ()->cancel_edits (); if (interactive) { view ()->paste_interactive (transient_mode); } else { @@ -1217,8 +1216,7 @@ void LayoutViewFunctions::do_cm_paste (bool interactive) { if (! db::Clipboard::instance ().empty ()) { - view ()->cancel (); - view ()->clear_selection (); + view ()->cancel_edits (); if (interactive) { view ()->paste_interactive (); } else { @@ -1330,9 +1328,7 @@ LayoutViewFunctions::cm_reload () void LayoutViewFunctions::do_transform (const db::DCplxTrans &tr) { - // end move operations, cancel edit operations - view ()->cancel_edits (); - view ()->lay::Editables::transform (tr); + view ()->transform (tr); } void @@ -1545,6 +1541,7 @@ LayoutViewFunctions::cm_sel_scale () void LayoutViewFunctions::cm_sel_move_interactive () { + view ()->cancel_edits (); if (view ()->move_service ()->begin_move ()) { view ()->switch_mode (-1); // move mode } diff --git a/src/layview/layview/layLayoutView_qt.cc b/src/layview/layview/layLayoutView_qt.cc index 7fb3d76e4..7bce16caa 100644 --- a/src/layview/layview/layLayoutView_qt.cc +++ b/src/layview/layview/layLayoutView_qt.cc @@ -1439,6 +1439,17 @@ LayoutView::cancel_edits () LayoutViewBase::cancel_edits (); } +void +LayoutView::finish_edits () +{ + // closes the property dialog + if (mp_properties_dialog) { + mp_properties_dialog->hide (); + } + + LayoutViewBase::finish_edits (); +} + void LayoutView::activate () { diff --git a/src/layview/layview/layLayoutView_qt.h b/src/layview/layview/layLayoutView_qt.h index 4c626a6d6..f81d737ca 100644 --- a/src/layview/layview/layLayoutView_qt.h +++ b/src/layview/layview/layLayoutView_qt.h @@ -459,6 +459,11 @@ public: */ void cancel_edits (); + /** + * @brief Finishes all edit operations and maintains selection + */ + void finish_edits (); + /** * @brief Select all levels of hierarchy available */