diff --git a/src/edt/edt/edtService.cc b/src/edt/edt/edtService.cc index 4fad85754..904c91574 100644 --- a/src/edt/edt/edtService.cc +++ b/src/edt/edt/edtService.cc @@ -62,7 +62,6 @@ ac_from_buttons (unsigned int buttons) Service::Service (db::Manager *manager, lay::LayoutView *view, db::ShapeIterator::flags_type flags) : lay::EditorServiceBase (view), - lay::Plugin (view), db::Object (manager), mp_view (view), mp_transient_marker (0), @@ -83,7 +82,6 @@ Service::Service (db::Manager *manager, lay::LayoutView *view, db::ShapeIterator Service::Service (db::Manager *manager, lay::LayoutView *view) : lay::EditorServiceBase (view), - lay::Plugin (view), db::Object (manager), mp_view (view), mp_transient_marker (0), @@ -261,6 +259,8 @@ Service::configure (const std::string &name, const std::string &value) tl::from_string (value, m_hier_copy_mode); service_configuration_changed (); + } else { + lay::EditorServiceBase::configure (name, value); } return false; // not taken @@ -813,7 +813,7 @@ Service::activated () void Service::deactivated () { - clear_mouse_cursors (); + lay::EditorServiceBase::deactivated (); edit_cancel (); diff --git a/src/edt/edt/edtService.h b/src/edt/edt/edtService.h index 22ff094e3..b24871cf6 100644 --- a/src/edt/edt/edtService.h +++ b/src/edt/edt/edtService.h @@ -72,7 +72,6 @@ std::map pcell_parameters_from_string (const std::stri class EDT_PUBLIC Service : public lay::EditorServiceBase, - public lay::Plugin, public db::Object { public: @@ -216,22 +215,6 @@ public: return m_color; } - /** - * @brief Obtain the lay::ViewService interface - */ - lay::ViewService *view_service_interface () - { - return this; - } - - /** - * @brief Obtain the lay::Editable interface - */ - lay::Editable *editable_interface () - { - return this; - } - /** * @brief Get the selection container */ diff --git a/src/lay/lay/layMainWindow.cc b/src/lay/lay/layMainWindow.cc index 03f9732c7..425f8485f 100644 --- a/src/lay/lay/layMainWindow.cc +++ b/src/lay/lay/layMainWindow.cc @@ -4236,6 +4236,7 @@ public: menu_entries.push_back (lay::menu_item ("cm_reset_window_state", "reset_window_state", at, tl::to_string (QObject::tr ("Restore Window")))), menu_entries.push_back (lay::separator ("selection_group", at)); menu_entries.push_back (lay::config_menu_item ("transient_selection", at, tl::to_string (QObject::tr ("Highlight Object Under Mouse")), cfg_sel_transient_mode, "?")); + menu_entries.push_back (lay::config_menu_item ("mouse_tracking", at, tl::to_string (QObject::tr ("Mouse tracking")), cfg_tracking_cursor_enabled, "?")); at = "help_menu.end"; menu_entries.push_back (lay::menu_item ("cm_show_all_tips", "show_all_tips", at, tl::to_string (QObject::tr ("Show All Tips")))); diff --git a/src/laybasic/laybasic/LayoutViewConfigPage2d.ui b/src/laybasic/laybasic/LayoutViewConfigPage2d.ui new file mode 100644 index 000000000..0a9fc17f5 --- /dev/null +++ b/src/laybasic/laybasic/LayoutViewConfigPage2d.ui @@ -0,0 +1,151 @@ + + + LayoutViewConfigPage2d + + + + 0 + 0 + 608 + 318 + + + + Settings + + + + 6 + + + 9 + + + 9 + + + 9 + + + 9 + + + + + Mouse tracking + + + true + + + + 9 + + + 9 + + + 9 + + + 9 + + + 6 + + + + + The color in which the rulers are drawn + + + + + + + + + + Qt::Horizontal + + + + 71 + 31 + + + + + + + + Cursor color + + + + + + + With mouse tracking enabled, a cursor will appear which indicates the snapped mouse position and whether the mouse snaps to objects. + + + true + + + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + lay::ColorButton + QPushButton +
layWidgets.h
+
+
+ + color_pb + + + +
diff --git a/src/laybasic/laybasic/layEditorServiceBase.cc b/src/laybasic/laybasic/layEditorServiceBase.cc index e05df5bec..1d8aad213 100644 --- a/src/laybasic/laybasic/layEditorServiceBase.cc +++ b/src/laybasic/laybasic/layEditorServiceBase.cc @@ -23,6 +23,8 @@ #include "layEditorServiceBase.h" #include "layViewport.h" #include "layLayoutView.h" +#include "laybasicConfig.h" +#include "layConverters.h" namespace lay { @@ -47,15 +49,50 @@ make_circle (double r, const db::DPoint ¢er, db::DPolygon &poly, bool as_hol } } -class MouseCursorViewObject +class TrackingCursorBase : public lay::ViewObject { public: - MouseCursorViewObject (lay::ViewObjectWidget *widget, const db::DPoint &pt, bool solid) - : lay::ViewObject (widget, false), m_pt (pt), m_solid (solid) + TrackingCursorBase (lay::EditorServiceBase *service, lay::ViewObjectWidget *widget) + : lay::ViewObject (widget, false), mp_service (service) { } + uint32_t cursor_color (lay::ViewObjectCanvas &canvas) const + { + QColor color; + if (mp_service) { + color = mp_service->tracking_cursor_color (); + } + if (! color.isValid ()) { + color = canvas.foreground_color (); + } + return color.rgb (); + } + virtual void render (const lay::Viewport &vp, lay::ViewObjectCanvas &canvas) + { + if (mp_service && mp_service->tracking_cursor_enabled ()) { + do_render (vp, canvas); + } + } + +protected: + virtual void do_render (const lay::Viewport &vp, lay::ViewObjectCanvas &canvas) = 0; + +private: + lay::EditorServiceBase *mp_service; +}; + +class MouseCursorViewObject + : public TrackingCursorBase +{ +public: + MouseCursorViewObject (lay::EditorServiceBase *service, lay::ViewObjectWidget *widget, const db::DPoint &pt, bool solid) + : TrackingCursorBase (service, widget), m_pt (pt), m_solid (solid) + { } + +protected: + virtual void do_render (const lay::Viewport &vp, lay::ViewObjectCanvas &canvas) { int dither_pattern = 0; // solid int cross_dither_pattern = 6; // dotted @@ -64,10 +101,10 @@ public: std::vector ops; ops.resize (1); - ops[0] = lay::ViewOp (canvas.foreground_color ().rgb (), lay::ViewOp::Copy, 0, (unsigned int) dither_pattern, 0, lay::ViewOp::Rect, lw, 0); + ops[0] = lay::ViewOp (cursor_color (canvas), lay::ViewOp::Copy, 0, (unsigned int) dither_pattern, 0, lay::ViewOp::Rect, lw, 0); lay::CanvasPlane *plane = canvas.plane (ops); - ops[0] = lay::ViewOp (canvas.foreground_color ().rgb (), lay::ViewOp::Copy, 0, (unsigned int) cross_dither_pattern, 0, lay::ViewOp::Rect, lw, 0); + ops[0] = lay::ViewOp (cursor_color (canvas), lay::ViewOp::Copy, 0, (unsigned int) cross_dither_pattern, 0, lay::ViewOp::Rect, lw, 0); lay::CanvasPlane *cross_plane = canvas.plane (ops); lay::Renderer &r = canvas.renderer (); @@ -95,14 +132,15 @@ private: }; class EdgeMarkerViewObject - : public lay::ViewObject + : public TrackingCursorBase { public: - EdgeMarkerViewObject (lay::ViewObjectWidget *widget, const db::DEdge &edge, bool solid) - : lay::ViewObject (widget, false), m_edge (edge), m_solid (solid) + EdgeMarkerViewObject (lay::EditorServiceBase *service, lay::ViewObjectWidget *widget, const db::DEdge &edge, bool solid) + : TrackingCursorBase (service, widget), m_edge (edge), m_solid (solid) { } - virtual void render (const lay::Viewport &vp, lay::ViewObjectCanvas &canvas) +protected: + virtual void do_render (const lay::Viewport &vp, lay::ViewObjectCanvas &canvas) { if (m_edge.is_degenerate ()) { return; @@ -115,10 +153,10 @@ public: std::vector ops; ops.resize (1); - ops[0] = lay::ViewOp (canvas.foreground_color ().rgb (), lay::ViewOp::Copy, solid_style, 0, 0, lay::ViewOp::Rect, lw, 0); + ops[0] = lay::ViewOp (cursor_color (canvas), lay::ViewOp::Copy, solid_style, 0, 0, lay::ViewOp::Rect, lw, 0); lay::CanvasPlane *arrow_plane = canvas.plane (ops); - ops[0] = lay::ViewOp (canvas.foreground_color ().rgb (), lay::ViewOp::Copy, m_solid ? solid_style : dashed_style, 1, 0, lay::ViewOp::Rect, lw, 0); + ops[0] = lay::ViewOp (cursor_color (canvas), lay::ViewOp::Copy, m_solid ? solid_style : dashed_style, 1, 0, lay::ViewOp::Rect, lw, 0); lay::CanvasPlane *edge_plane = canvas.plane (ops); lay::Renderer &r = canvas.renderer (); @@ -166,7 +204,9 @@ private: EditorServiceBase::EditorServiceBase (lay::LayoutView *view) : lay::ViewService (view->view_object_widget ()), - lay::Editable (view) + lay::Editable (view), + lay::Plugin (view), + m_cursor_enabled (true) { // .. nothing yet .. } @@ -179,13 +219,13 @@ EditorServiceBase::~EditorServiceBase () void EditorServiceBase::add_mouse_cursor (const db::DPoint &pt, bool emphasize) { - m_mouse_cursor_markers.push_back (new MouseCursorViewObject (widget (), pt, emphasize)); + m_mouse_cursor_markers.push_back (new MouseCursorViewObject (this, widget (), pt, emphasize)); } void EditorServiceBase::add_edge_marker (const db::DEdge &e, bool emphasize) { - m_mouse_cursor_markers.push_back (new EdgeMarkerViewObject (widget (), e, emphasize)); + m_mouse_cursor_markers.push_back (new EdgeMarkerViewObject (this, widget (), e, emphasize)); } void @@ -197,4 +237,46 @@ EditorServiceBase::clear_mouse_cursors () m_mouse_cursor_markers.clear (); } +bool +EditorServiceBase::configure (const std::string &name, const std::string &value) +{ + bool needs_update = false; + + if (name == cfg_tracking_cursor_color) { + + QColor color; + lay::ColorConverter ().from_string (value, color); + + if (color != m_cursor_color) { + m_cursor_color = color; + needs_update = true; + } + + } else if (name == cfg_tracking_cursor_enabled) { + + bool f = m_cursor_enabled; + tl::from_string (value, f); + if (f != m_cursor_enabled) { + m_cursor_enabled = f; + needs_update = true; + } + + } + + if (needs_update) { + for (std::vector::iterator r = m_mouse_cursor_markers.begin (); r != m_mouse_cursor_markers.end (); ++r) { + (*r)->redraw (); + } + } + + // NOTE: we don't take the value as other services may be interested too. + return false; +} + +void +EditorServiceBase::deactivated () +{ + clear_mouse_cursors (); +} + } diff --git a/src/laybasic/laybasic/layEditorServiceBase.h b/src/laybasic/laybasic/layEditorServiceBase.h index 1c28ccbee..962388e15 100644 --- a/src/laybasic/laybasic/layEditorServiceBase.h +++ b/src/laybasic/laybasic/layEditorServiceBase.h @@ -27,6 +27,7 @@ #include "laybasicCommon.h" #include "layEditable.h" #include "layViewObject.h" +#include "layPlugin.h" namespace lay { @@ -38,7 +39,8 @@ namespace lay */ class LAYBASIC_PUBLIC EditorServiceBase : public lay::ViewService, - public lay::Editable + public lay::Editable, + public lay::Plugin { public: /** @@ -51,6 +53,22 @@ public: */ ~EditorServiceBase (); + /** + * @brief Obtain the lay::ViewService interface + */ + lay::ViewService *view_service_interface () + { + return this; + } + + /** + * @brief Obtain the lay::Editable interface + */ + lay::Editable *editable_interface () + { + return this; + } + /** * @brief Adds a mouse cursor to the given point */ @@ -66,9 +84,31 @@ public: */ void clear_mouse_cursors (); + /** + * @brief Gets the tracking cursor color + */ + QColor tracking_cursor_color () const + { + return m_cursor_color; + } + + /** + * @brief Gets a value indicating whether the tracking cursor is enabled + */ + bool tracking_cursor_enabled () const + { + return m_cursor_enabled; + } + +protected: + virtual bool configure (const std::string &name, const std::string &value); + virtual void deactivated (); + private: // The marker representing the mouse cursor std::vector m_mouse_cursor_markers; + QColor m_cursor_color; + bool m_cursor_enabled; }; } diff --git a/src/laybasic/laybasic/layLayoutViewConfigPages.cc b/src/laybasic/laybasic/layLayoutViewConfigPages.cc index 30c4aa6bb..d2e66440e 100644 --- a/src/laybasic/laybasic/layLayoutViewConfigPages.cc +++ b/src/laybasic/laybasic/layLayoutViewConfigPages.cc @@ -31,6 +31,7 @@ #include "ui_LayoutViewConfigPage2a.h" #include "ui_LayoutViewConfigPage2b.h" #include "ui_LayoutViewConfigPage2c.h" +#include "ui_LayoutViewConfigPage2d.h" #include "ui_LayoutViewConfigPage3a.h" #include "ui_LayoutViewConfigPage3b.h" #include "ui_LayoutViewConfigPage3c.h" @@ -389,6 +390,42 @@ LayoutViewConfigPage2c::commit (lay::Dispatcher *root) root->config_set (cfg_search_range, (unsigned int) mp_ui->search_range_spinbx->value ()); } +// ------------------------------------------------------------ +// LayoutConfigPage2d implementation + +LayoutViewConfigPage2d::LayoutViewConfigPage2d (QWidget *parent) + : lay::ConfigPage (parent) +{ + mp_ui = new Ui::LayoutViewConfigPage2d (); + mp_ui->setupUi (this); +} + +LayoutViewConfigPage2d::~LayoutViewConfigPage2d () +{ + delete mp_ui; + mp_ui = 0; +} + +void +LayoutViewConfigPage2d::setup (lay::Dispatcher *root) +{ + QColor color; + root->config_get (cfg_tracking_cursor_color, color, lay::ColorConverter ()); + mp_ui->color_pb->set_color (color); + + bool enabled = 0; + root->config_get (cfg_tracking_cursor_enabled, enabled); + mp_ui->tracking_cb->setChecked (enabled); +} + +void +LayoutViewConfigPage2d::commit (lay::Dispatcher *root) +{ + lay::ColorConverter cc; + root->config_set (cfg_tracking_cursor_color, mp_ui->color_pb->get_color (), cc); + root->config_set (cfg_tracking_cursor_enabled, mp_ui->tracking_cb->isChecked ()); +} + // ------------------------------------------------------------ // LayoutConfigPage3a implementation @@ -1516,6 +1553,8 @@ public: options.push_back (std::pair (cfg_sel_halo, "true")); options.push_back (std::pair (cfg_sel_transient_mode, "true")); options.push_back (std::pair (cfg_sel_inside_pcells_mode, "false")); + options.push_back (std::pair (cfg_tracking_cursor_enabled, "true")); + options.push_back (std::pair (cfg_tracking_cursor_color, cc.to_string (QColor ()))); options.push_back (std::pair (cfg_background_color, cc.to_string (QColor ()))); options.push_back (std::pair (cfg_ctx_color, cc.to_string (QColor ()))); options.push_back (std::pair (cfg_ctx_dimming, "50")); @@ -1571,6 +1610,7 @@ public: pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Display|Optimization")), new LayoutViewConfigPage3f (parent))); pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Application|Selection")), new LayoutViewConfigPage2c (parent))); + pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Application|Tracking")), new LayoutViewConfigPage2d (parent))); pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Application|Layer Properties")), new LayoutViewConfigPage5 (parent))); pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Application|Units")), new LayoutViewConfigPage3c (parent))); diff --git a/src/laybasic/laybasic/layLayoutViewConfigPages.h b/src/laybasic/laybasic/layLayoutViewConfigPages.h index 10ffb7a23..1170a6a19 100644 --- a/src/laybasic/laybasic/layLayoutViewConfigPages.h +++ b/src/laybasic/laybasic/layLayoutViewConfigPages.h @@ -38,6 +38,7 @@ namespace Ui { class LayoutViewConfigPage2a; class LayoutViewConfigPage2b; class LayoutViewConfigPage2c; + class LayoutViewConfigPage2d; class LayoutViewConfigPage3a; class LayoutViewConfigPage3b; class LayoutViewConfigPage3c; @@ -138,7 +139,23 @@ private: Ui::LayoutViewConfigPage2c *mp_ui; }; -class LayoutViewConfigPage3a +class LayoutViewConfigPage2d + : public lay::ConfigPage +{ +Q_OBJECT + +public: + LayoutViewConfigPage2d (QWidget *parent); + ~LayoutViewConfigPage2d (); + + virtual void setup (lay::Dispatcher *root); + virtual void commit (lay::Dispatcher *root); + +private: + Ui::LayoutViewConfigPage2d *mp_ui; +}; + +class LayoutViewConfigPage3a : public lay::ConfigPage { Q_OBJECT diff --git a/src/laybasic/laybasic/laybasic.pro b/src/laybasic/laybasic/laybasic.pro index 38963208b..449aa1f29 100644 --- a/src/laybasic/laybasic/laybasic.pro +++ b/src/laybasic/laybasic/laybasic.pro @@ -31,6 +31,7 @@ FORMS = \ LayoutViewConfigPage2a.ui \ LayoutViewConfigPage2b.ui \ LayoutViewConfigPage2c.ui \ + LayoutViewConfigPage2d.ui \ LayoutViewConfigPage3a.ui \ LayoutViewConfigPage3b.ui \ LayoutViewConfigPage3c.ui \ diff --git a/src/laybasic/laybasic/laybasicConfig.h b/src/laybasic/laybasic/laybasicConfig.h index 71a5a2019..dc772dea0 100644 --- a/src/laybasic/laybasic/laybasicConfig.h +++ b/src/laybasic/laybasic/laybasicConfig.h @@ -75,6 +75,9 @@ static const std::string cfg_sel_line_style ("sel-line-style"); static const std::string cfg_sel_transient_mode ("sel-transient-mode"); static const std::string cfg_sel_inside_pcells_mode ("sel-inside-pcells-mode"); +static const std::string cfg_tracking_cursor_color ("tracking-cursor-color"); +static const std::string cfg_tracking_cursor_enabled ("tracking-cursor-enabled"); + static const std::string cfg_markers_visible ("markers-visible"); static const std::string cfg_min_inst_label_size ("min-inst-label-size");