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 ());
}