Refactoring, displaying move vector also in partial mode

This commit is contained in:
Matthias Koefferlein
2026-01-15 13:34:52 +01:00
parent 9fe22869ed
commit 900ac4bc0f
15 changed files with 85 additions and 129 deletions
-155
View File
@@ -1,155 +0,0 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2025 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _HDR_gsiDeclLayPlugin
#define _HDR_gsiDeclLayPlugin
#include "gsiDecl.h"
#include "gsiDeclBasic.h"
#include "layEditorServiceBase.h"
#include "layLayoutViewBase.h"
namespace gsi
{
class PluginImpl
: public lay::EditorServiceBase
{
public:
PluginImpl ();
void init (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher);
void grab_mouse ();
void ungrab_mouse ();
void set_cursor (int c);
virtual void menu_activated (const std::string &symbol);
db::DPoint snap (db::DPoint p) const;
db::DVector snap_vector (db::DVector v) const;
db::DPoint snap_from_to (const db::DPoint &p, const db::DPoint &plast, bool connect, lay::angle_constraint_type ac) const;
db::DVector snap_delta (const db::DVector &v, bool connect, lay::angle_constraint_type ac) const;
db::DPoint snap2 (const db::DPoint &p, bool visualize);
db::DPoint snap2_from_to (const db::DPoint &p, const db::DPoint &plast, bool connect, lay::angle_constraint_type ac, bool visualize);
// Captures some edt space configuration events for convencience
void configure_edt (const std::string &name, const std::string &value);
// NOTE: The implementation does not allow to bypass the base class configuration call
bool configure_impl (const std::string &name, const std::string &value);
// for testing
void configure_test (const std::string &name, const std::string &value);
virtual bool configure (const std::string &name, const std::string &value);
// NOTE: The implementation does not allow to bypass the base class configuration call
virtual void config_finalize_impl ();
virtual void config_finalize ();
virtual bool key_event (unsigned int key, unsigned int buttons);
virtual bool shortcut_override_event (unsigned int key, unsigned int buttons);
virtual bool mouse_press_event (const db::DPoint &p, unsigned int buttons, bool prio) ;
bool mouse_press_event_noref (db::DPoint p, unsigned int buttons, bool prio);
virtual bool mouse_click_event (const db::DPoint &p, unsigned int buttons, bool prio);
bool mouse_click_event_noref (db::DPoint p, unsigned int buttons, bool prio);
virtual bool mouse_double_click_event (const db::DPoint &p, unsigned int buttons, bool prio);
bool mouse_double_click_event_noref (db::DPoint p, unsigned int buttons, bool prio);
virtual bool leave_event (bool prio);
virtual bool enter_event (bool prio);
virtual bool mouse_move_event (const db::DPoint &p, unsigned int buttons, bool prio);
bool mouse_move_event_noref (db::DPoint p, unsigned int buttons, bool prio);
virtual bool mouse_release_event (const db::DPoint &p, unsigned int buttons, bool prio);
bool mouse_release_event_noref (db::DPoint p, unsigned int buttons, bool prio);
virtual bool wheel_event (int delta, bool horizontal, const db::DPoint &p, unsigned int buttons, bool prio);
bool wheel_event_noref (int delta, bool horizontal, db::DPoint p, unsigned int buttons, bool prio);
void activated_impl ();
virtual void activated ();
void deactivated_impl ();
virtual void deactivated ();
virtual void drag_cancel ();
virtual void update ();
void add_mouse_cursor_dpoint (const db::DPoint &p, bool emphasize);
void add_mouse_cursor_point (const db::Point &p, int cv_index, const db::LayerProperties &lp, bool emphasize);
void add_edge_marker_dedge (const db::DEdge &p, bool emphasize);
void add_edge_marker_edge (const db::Edge &p, int cv_index, const db::LayerProperties &lp, bool emphasize);
// for testing
bool has_tracking_position_test () const;
virtual bool has_tracking_position () const;
// for testing
db::DPoint tracking_position_test () const;
virtual db::DPoint tracking_position () const;
virtual int focus_page_open ();
virtual lay::ViewService *view_service_interface ()
{
return this;
}
lay::LayoutViewBase *view () const
{
return const_cast<lay::LayoutViewBase *> (mp_view.get ());
}
lay::Dispatcher *dispatcher () const
{
return const_cast<lay::Dispatcher *> (mp_dispatcher.get ());
}
gsi::Callback f_menu_activated;
gsi::Callback f_configure;
gsi::Callback f_config_finalize;
gsi::Callback f_key_event;
gsi::Callback f_shortcut_override_event;
gsi::Callback f_mouse_press_event;
gsi::Callback f_mouse_click_event;
gsi::Callback f_mouse_double_click_event;
gsi::Callback f_leave_event;
gsi::Callback f_enter_event;
gsi::Callback f_mouse_move_event;
gsi::Callback f_mouse_release_event;
gsi::Callback f_wheel_event;
gsi::Callback f_activated;
gsi::Callback f_deactivated;
gsi::Callback f_drag_cancel;
gsi::Callback f_update;
gsi::Callback f_has_tracking_position;
gsi::Callback f_tracking_position;
gsi::Callback f_focus_page_open;
private:
tl::weak_ptr<lay::LayoutViewBase> mp_view;
tl::weak_ptr<lay::Dispatcher> mp_dispatcher;
// Angle constraints and grids
lay::angle_constraint_type m_connect_ac, m_move_ac;
db::DVector m_edit_grid;
bool m_snap_to_objects;
bool m_snap_objects_to_grid;
db::DVector m_global_grid;
lay::angle_constraint_type connect_ac (lay::angle_constraint_type ac) const;
lay::angle_constraint_type move_ac (lay::angle_constraint_type ac) const;
};
}
#endif
@@ -72,11 +72,11 @@ EditorOptionsPage::show ()
return -1;
} else if (m_toolbox_widget) {
set_focus ();
return -1;
return 1;
} else if (mp_owner) {
if (! is_modal_page ()) {
mp_owner->make_page_current (this);
return -1;
return 1;
} else {
return mp_owner->exec_modal (this) ? 1 : 0;
}
@@ -372,8 +372,7 @@ bool
EditorServiceBase::key_event (unsigned int key, unsigned int /*buttons*/)
{
if (is_active () && (key == lay::KeyTab || key == lay::KeyBacktab)) {
focus_page_open ();
return true;
return focus_page_open () >= 0;
} else {
return false;
}
@@ -393,7 +392,7 @@ int
EditorServiceBase::focus_page_open ()
{
auto fp = focus_page ();
return fp ? fp->show () : 0;
return fp ? fp->show () : -1;
}
void
+34 -1
View File
@@ -33,6 +33,7 @@
#include "layLayoutCanvas.h"
#include "layRedrawThread.h"
#include "layLayoutViewBase.h"
#include "layEditorOptionsPage.h"
#include "layMarker.h"
#if defined(HAVE_QT)
# include "gtf.h"
@@ -238,7 +239,12 @@ LayoutCanvas::init_ui (QWidget *parent)
void
LayoutCanvas::key_event (unsigned int key, unsigned int buttons)
{
if (! (buttons & lay::ShiftButton)) {
if (int (key) == lay::KeyTab || int (key) == lay::KeyBacktab) {
auto page = first_toolbox_widget ();
if (page) {
page->set_focus ();
}
} else if (! (buttons & lay::ShiftButton)) {
if (int (key) == lay::KeyDown) {
down_arrow_key_pressed ();
} else if (int (key) == lay::KeyUp) {
@@ -261,6 +267,33 @@ LayoutCanvas::key_event (unsigned int key, unsigned int buttons)
}
}
bool
LayoutCanvas::shortcut_override_event (unsigned int key, unsigned int /*buttons*/)
{
if (int (key) == lay::KeyTab || int (key) == lay::KeyBacktab) {
return first_toolbox_widget () != 0;
} else {
return false;
}
}
lay::EditorOptionsPage *
LayoutCanvas::first_toolbox_widget ()
{
auto pages = mp_view->editor_options_pages ();
if (! pages) {
return 0;
}
auto pv = pages->editor_options_pages ();
for (auto p = pv.begin (); p != pv.end (); ++p) {
if ((*p)->is_toolbox_widget () && (*p)->is_visible ()) {
return *p;
}
}
return 0;
}
void
LayoutCanvas::set_image_cache_size (size_t sz)
{
+4
View File
@@ -50,6 +50,7 @@ namespace lay
class LayoutViewBase;
class RedrawThread;
class EditorOptionsPage;
/**
* @brief A class representing one entry in the image cache
@@ -459,7 +460,10 @@ private:
tl::Mutex m_mutex;
virtual void key_event (unsigned int key, unsigned int buttons);
virtual bool shortcut_override_event (unsigned int key, unsigned int buttons);
virtual void resize_event (unsigned int width, unsigned int height);
lay::EditorOptionsPage *first_toolbox_widget ();
#if defined(HAVE_QT)
virtual void gtf_probe ();
virtual void paint_event ();
+2 -2
View File
@@ -4169,7 +4169,7 @@ LayoutViewBase::cancel_edits ()
// the move service takes a special role here as it manages the
// transaction for the collective move operation.
if (mp_move_service) {
mp_move_service->cancel ();
mp_move_service->cancel_transaction ();
}
// cancel all drag and pending edit operations such as move operations.
@@ -4186,7 +4186,7 @@ LayoutViewBase::finish_edits ()
// the move service takes a special role here as it manages the
// transaction for the collective move operation.
if (mp_move_service) {
mp_move_service->finish ();
mp_move_service->finish_transaction ();
}
// cancel all drag operations
+2 -2
View File
@@ -425,7 +425,7 @@ MoveService::drag_cancel ()
}
void
MoveService::cancel ()
MoveService::cancel_transaction ()
{
if (m_dragging) {
if (mp_transaction.get ()) {
@@ -436,7 +436,7 @@ MoveService::cancel ()
}
void
MoveService::finish ()
MoveService::finish_transaction ()
{
if (m_dragging) {
mp_transaction.reset (0);
+2 -2
View File
@@ -48,8 +48,8 @@ public:
bool configure (const std::string &name, const std::string &value);
void function (const std::string &name, const std::string &value);
void finish ();
void cancel ();
void finish_transaction ();
void cancel_transaction ();
private:
virtual bool mouse_press_event (const db::DPoint &p, unsigned int buttons, bool prio);
+1 -1
View File
@@ -711,7 +711,7 @@ ViewObjectUI::send_shortcut_override_event(unsigned int key, unsigned int button
}
if (! done) {
key_event (key, buttons);
done = shortcut_override_event (key, buttons);
}
return done;
+8
View File
@@ -852,6 +852,14 @@ public:
*/
virtual void key_event (unsigned int /*key*/, unsigned int /*buttons*/) { }
/**
* @brief Handler for remaining shortcut override events
*
* This event handler is called if no ViewObject requested handling
* of this event.
*/
virtual bool shortcut_override_event (unsigned int /*key*/, unsigned int /*buttons*/) { return false; }
#if defined(HAVE_QT)
/**
* @brief The drag enter event
-1
View File
@@ -91,7 +91,6 @@ SOURCES += \
layUtils.cc \
HEADERS += \
gsiDeclLayPlugin.h \
layEditorOptionsPage.h \
layEditorUtils.h \
layMargin.h \