Plugin development : markers in custom plugin (C++, Qt)

Hi, following our effort to integrate klayout within qucs, we are developing a new plugin (entire framework is C++ and we link directly KLayout libraries).
Now, in this plugin (child of edt::Service) we create a lay::Marker to follow some "drag" activity by the mouse.
Here there is something we don't comprehend: at the beginning (blank layout) everything works fine.
After loading a gds in the current layoutView, we switch again the view mode to the new plugin but the marker is not shown anymore.
All events are handled correctly to the plugin and we enforce the layoutView->show_markers(true).

Apparently, loading a gds into the view changes some behaviour of the view itself but we cannot figure out what.

Any hint? Thanks!
Alessio

Comments

  • Hi Alessio,

    do you have some code you can share?

    Right now, markers do not survive a change of the files inside the view. Markers are not intended as persisting objects, but rather short-lived annotations - such as error markers.

    Maybe you can register your plugin to listen to events on the view and regenerate the markers after such a change, or you use a QTimer to regularly check if the marker is still alive. But I have not tried one of these options myself.

    I guess it's possible to change the KLayout code to have markers survive a file operation. But that's worth a ticket on GitHub.

    Regards,

    Matthias

  • Hi Matthias,

    Thanks for the prompt follow up.

    The issue is that, even if we create a new marker (after the layout has been loaded), it's not visible.

    Here follows the relevant code:
    1. at beginning (empty layout) and
    2. after layout load we switch to our plugin which is created from its factory with top (0) priority

    if (my_mode_id >=0)
            m_layoutView->switch_mode(my_mode_id);
    
     lay::Plugin* active = m_layoutView->active_plugin();
     m_layoutView->show_markers(true);
    

    Then here the handler of mouse event (overriding edt::Service)

    bool    myCustomPlugin::mouse_move_event(const db::DPoint &p, unsigned int buttons, bool )
    {
      // Check if left button is kept down
      if ((buttons & lay::LeftButton))
      {
        if (!m_dragging)
        {
          m_dragging   = true;
          m_drag_start = m_last_snapped;
        }
        m_drag_box = db::DBox(m_drag_start, m_last_snapped);
      }
    
      update_cursor_markers();
    
      emit  signal_mouse_position(m_last_snapped);
    
      return false;
    }
    

    Procedure to update mouse cursor and (hopefully) marker:

    /**
     * @brief myCustomPlugin::update_cursor_markers
     */
    void  myCustomPlugin::update_cursor_markers()
    {
      clear_mouse_cursors();
    
      add_mouse_cursor(m_last_snapped, false);
    
      update_marker();
    
    }
    

    Procedure to update the marker

        /**
         * @brief myCustomPlugin::update_marker
         */
        void  myCustomPlugin::update_marker()
        {
          if (!m_dragging) return;
    
          if (m_marker==nullptr)
            create_marker();
    
          if (m_marker!=nullptr)
          {
            m_marker->set(m_drag_box,db::DCplxTrans());
            m_marker->visible(true);
          }
          mp_view->show_markers(true);
        }
    

    This is called each time mouse is pressed

    /**
     * @brief myCustomPlugin::create_marker
     */
    void        myCustomPlugin::create_marker()
    {
    
      if (m_marker!=nullptr) return;
      if (mp_view==nullptr) return;
    
      m_marker = new lay::Marker(mp_view, mp_view->active_cellview_index());
    
      unsigned int fillColor  = 0x00cc00;
      unsigned int frameColor = 0x00cc00;
      int dither    = 0;          // solid
      int lineStyle = 3;
      int width     = 1;
    
      m_marker->set_color (brighter_color(fillColor));
      m_marker->set_frame_color(brighter_color(frameColor));
      m_marker->set_dither_pattern(dither);         
      m_marker->set_line_style(lineStyle);
      m_marker->set_line_width(width);           
      m_marker->set_vertex_size(1);
      m_marker->set_halo(1);
    }
    

    This is called each time mouse is release (delete the marker)

        /**
         * @brief myCustomPlugin::delete_marker
         */
        void        myCustomPlugin::delete_marker()
        {
    
          if (m_marker==nullptr) return;
          delete m_marker;
          v = nullptr;
    
        }
    

    At mouse release we cancel the marker

    bool        myCustomPlugin::mouse_release_event(const db::DPoint &p, unsigned int buttons, bool /*prio*/)
    {
        if (!m_dragging)
          return false;
    
        m_dragging = false;
    
        db::DBox box(m_drag_start, p);
    
        delete_marker();
    
        update_cursor_markers();
    
        return true;
    }
    

    So, as you can see, the code is (or should be) pretty straightforward. This means that we are doing something wrong but we really cannot figure out what.

    Thank you very much!

    Alessio

Sign In or Register to comment.