diff --git a/src/ant/antPlugin.cc b/src/ant/antPlugin.cc index e5b18884e..37ba19546 100644 --- a/src/ant/antPlugin.cc +++ b/src/ant/antPlugin.cc @@ -35,16 +35,24 @@ namespace ant { +static PluginDeclaration *sp_instance = 0; + PluginDeclaration::PluginDeclaration () : m_current_template (0), m_current_template_updated (true), m_templates_updated (true) { - // .. nothing yet .. + sp_instance = this; } PluginDeclaration::~PluginDeclaration () { - // .. nothing yet .. + sp_instance = 0; +} + +PluginDeclaration * +PluginDeclaration::instance () +{ + return sp_instance; } void @@ -124,7 +132,7 @@ PluginDeclaration::configure (const std::string &name, const std::string &value) m_templates = ant::Template::from_string (value); m_templates_updated = true; - + } else if (name == cfg_current_ruler_template) { int n = 0; @@ -161,9 +169,15 @@ PluginDeclaration::config_finalize () } void -PluginDeclaration::initialize (lay::PluginRoot *) +PluginDeclaration::initialized (lay::PluginRoot *) { - // .. nothing yet .. + ant::Template pos_template (tl::to_string (QObject::tr ("Cross")), "", "", "$U,$V", ant::Object::STY_cross_both, ant::Object::OL_diag, true, lay::AC_Global, "_cross"); + pos_template.set_mode (ant::Template::RulerSingleClick); + register_annotation_template (pos_template); + + ant::Template auto_template (tl::to_string (QObject::tr ("Measure")), "$X", "$Y", "$D", ant::Object::STY_ruler, ant::Object::OL_diag, true, lay::AC_Global, "_measure"); + auto_template.set_mode (ant::Template::RulerAutoMetric); + register_annotation_template (auto_template); } void @@ -244,6 +258,24 @@ PluginDeclaration::update_menu () } +void +PluginDeclaration::register_annotation_template (const ant::Template &t) +{ + if (t.category ().empty ()) { + return; + } + + for (std::vector::iterator i = m_templates.begin (); i != m_templates.end (); ++i) { + if (i->category () == t.category ()) { + return; + } + } + + m_templates.push_back (t); + lay::PluginRoot::instance ()->config_set (cfg_ruler_templates, ant::TemplatesConverter ().to_string (m_templates)); + lay::PluginRoot::instance ()->config_end (); +} + static tl::RegisteredClass config_decl (new ant::PluginDeclaration (), 3000, "ant::Plugin"); } diff --git a/src/ant/antPlugin.h b/src/ant/antPlugin.h index 44d132c1e..d3aaa01c6 100644 --- a/src/ant/antPlugin.h +++ b/src/ant/antPlugin.h @@ -46,10 +46,14 @@ public: virtual bool configure (const std::string &name, const std::string &value); virtual std::vector > config_pages (QWidget *parent) const; virtual void config_finalize (); - virtual void initialize (lay::PluginRoot *); + virtual void initialized (lay::PluginRoot *); virtual void uninitialize (lay::PluginRoot *); virtual bool menu_activated (const std::string &symbol) const; + void register_annotation_template (const ant::Template &t); + + static PluginDeclaration *instance (); + private: void update_current_template (); void update_menu (); diff --git a/src/ant/antService.cc b/src/ant/antService.cc index 884f18fda..f8129d8c4 100644 --- a/src/ant/antService.cc +++ b/src/ant/antService.cc @@ -2128,33 +2128,6 @@ Service::menu_activated (const std::string &symbol) } } -void -Service::register_annotation_template (const ant::Template &t) -{ - std::string value = lay::PluginRoot::instance ()->config_get (cfg_ruler_templates); - - std::vector templates = ant::Template::from_string (value); - - // Remove a template with the same category if such a template already exists - if (! t.category ().empty ()) { - for (size_t i = 0; i < templates.size (); ) { - if (templates[i].category () == t.category ()) { - templates.erase (templates.begin () + i); - } else { - ++i; - } - } - } - - // and add the new one - templates.push_back (t); - - value = ant::Template::to_string (templates); - - lay::PluginRoot::instance ()->config_set (cfg_ruler_templates, value); - lay::PluginRoot::instance ()->config_end (); -} - // ------------------------------------------------------------- } // namespace ant diff --git a/src/ant/antService.h b/src/ant/antService.h index 8cdca70c2..9b343582e 100644 --- a/src/ant/antService.h +++ b/src/ant/antService.h @@ -438,11 +438,6 @@ public: */ tl::Event annotation_selection_changed_event; - /** - * @brief Registers an annotation template globally - */ - static void register_annotation_template (const ant::Template &t); - private: // Ruler display and snapping configuration QColor m_color; diff --git a/src/ant/antTemplate.cc b/src/ant/antTemplate.cc index 3f2a7559d..9b0aa8eb5 100644 --- a/src/ant/antTemplate.cc +++ b/src/ant/antTemplate.cc @@ -46,8 +46,10 @@ Template::Template () Template::Template (const std::string &title, const std::string &fmt_x, const std::string &fmt_y, const std::string &fmt, - style_type style, outline_type outline, bool snap, lay::angle_constraint_type angle_constraint) + style_type style, outline_type outline, bool snap, lay::angle_constraint_type angle_constraint, + const std::string &cat) : m_title (title), + m_category (cat), m_fmt_x (fmt_x), m_fmt_y (fmt_y), m_fmt (fmt), m_style (style), m_outline (outline), m_snap (snap), m_angle_constraint (angle_constraint), diff --git a/src/ant/antTemplate.h b/src/ant/antTemplate.h index 42100c5fb..e5a8fee91 100644 --- a/src/ant/antTemplate.h +++ b/src/ant/antTemplate.h @@ -77,7 +77,7 @@ public: * * Creates a template with the given format strings and styles */ - Template (const std::string &title, const std::string &fmt_x, const std::string &fmt_y, const std::string &fmt, style_type style, outline_type outline, bool snap, lay::angle_constraint_type angle_constraints); + Template (const std::string &title, const std::string &fmt_x, const std::string &fmt_y, const std::string &fmt, style_type style, outline_type outline, bool snap, lay::angle_constraint_type angle_constraints, const std::string &cat); /** * @brief Copy constructor diff --git a/src/ant/gsiDeclAnt.cc b/src/ant/gsiDeclAnt.cc index aada84c10..83f565922 100644 --- a/src/ant/gsiDeclAnt.cc +++ b/src/ant/gsiDeclAnt.cc @@ -20,12 +20,11 @@ */ - - #include "gsiDecl.h" #include "gsiSignals.h" #include "antObject.h" #include "antService.h" +#include "antPlugin.h" #include "layLayoutView.h" namespace gsi @@ -416,7 +415,9 @@ static void register_annotation_template (const ant::Object &a, const std::strin t.set_mode (ant::Template::ruler_mode_type (mode)); - ant::Service::register_annotation_template (t); + if (ant::PluginDeclaration::instance ()) { + ant::PluginDeclaration::instance ()->register_annotation_template (t); + } } // NOTE: ant::Object is available as "BasicAnnotation" to allow binding for other methods. diff --git a/src/laybasic/laySnap.cc b/src/laybasic/laySnap.cc index 018366829..6dfda348c 100644 --- a/src/laybasic/laySnap.cc +++ b/src/laybasic/laySnap.cc @@ -108,8 +108,7 @@ snap (const db::DPoint &p1, const db::DPoint &p2, db::DCoord grid) if (grid <= 1e-10) { return std::make_pair (p1, p2); } else { - std::pair v = snap (db::DPoint (p1.x () / grid, p1.y () / grid), + std::pair v = snap (db::DPoint (p1.x () / grid, p1.y () / grid), db::DPoint (p2.x () / grid, p2.y () / grid)); return std::make_pair (v.first * grid, v.second * grid); }