klayout 源码分析系列续 plugin

本文详细介绍了插件系统的工作原理,以ant::Service为例,分为三个步骤:声明、注册和生成。首先,声明了一个继承自多个基类的Service类,包含鼠标事件处理函数。接着,通过tl::RegisteredClass模板将插件类注册到系统中。最后,在LayoutView类中遍历并创建所有注册的插件,根据选项决定是否创建特定插件。这个过程揭示了插件系统如何动态加载和管理组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

plugin 的使用分三步,下面以ant::Service举例。

第一步. 声明

class ANT_PUBLIC Service
  : public lay::ViewService,
    public lay::Editable,
    public lay::Plugin,
    public lay::Drawing,
    public db::Object
{
    Service (db::Manager *manager, lay::LayoutView *view);

    virtual bool mouse_move_event (const db::DPoint &p, unsigned int buttons, bool prio);

    virtual bool mouse_press_event (const db::DPoint &p, unsigned int buttons, bool prio);

    virtual bool mouse_click_event (const db::DPoint &p, unsigned int buttons, bool prio);

}

第二步. 注册

通过模板把plugin类注册到系统中

antPlugin.cc

static tl::RegisteredClass<lay::PluginDeclaration> config_decl (new ant::PluginDeclaration (), 3000, "ant::Plugin");

}

第三步.生成

void LayoutView::create_plugins (lay::PluginRoot *root, const lay::PluginDeclaration *except_this)
{
  for (std::vector<lay::Plugin *>::iterator p = mp_plugins.begin (); p != mp_plugins.end (); ++p) {
    delete *p;
  }
  mp_plugins.clear ();

  //  create the plugins
  for (tl::Registrar<lay::PluginDeclaration>::iterator cls = tl::Registrar<lay::PluginDeclaration>::begin (); cls != tl::Registrar<lay::PluginDeclaration>::end (); ++cls) {

    if (&*cls != except_this) {

      //  TODO: clean solution. The following is a HACK:
      if (cls.current_name () == "ant::Plugin" || cls.current_name () == "img::Plugin") {
        //  ant and img are created always
        create_plugin (root, &*cls);
      } else if ((m_options & LV_NoPlugins) == 0) {
        //  others: only create unless LV_NoPlugins is set
        create_plugin (root, &*cls);
      } else if ((m_options & LV_NoGrid) == 0 && cls.current_name () == "GridNetPlugin") {
        //  except grid net plugin which is created on request
        create_plugin (root, &*cls);
      }

    }

  }

  mode (default_mode ());
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天天进步2015

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值