mirror of https://github.com/KLayout/klayout.git
WIP: rulers
- some refactoring - auto-registration of cross and measure rulers
This commit is contained in:
parent
86e2b8cad1
commit
78cdec4d68
|
|
@ -35,16 +35,24 @@
|
||||||
namespace ant
|
namespace ant
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static PluginDeclaration *sp_instance = 0;
|
||||||
|
|
||||||
PluginDeclaration::PluginDeclaration ()
|
PluginDeclaration::PluginDeclaration ()
|
||||||
: m_current_template (0),
|
: m_current_template (0),
|
||||||
m_current_template_updated (true), m_templates_updated (true)
|
m_current_template_updated (true), m_templates_updated (true)
|
||||||
{
|
{
|
||||||
// .. nothing yet ..
|
sp_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginDeclaration::~PluginDeclaration ()
|
PluginDeclaration::~PluginDeclaration ()
|
||||||
{
|
{
|
||||||
// .. nothing yet ..
|
sp_instance = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginDeclaration *
|
||||||
|
PluginDeclaration::instance ()
|
||||||
|
{
|
||||||
|
return sp_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -124,7 +132,7 @@ PluginDeclaration::configure (const std::string &name, const std::string &value)
|
||||||
|
|
||||||
m_templates = ant::Template::from_string (value);
|
m_templates = ant::Template::from_string (value);
|
||||||
m_templates_updated = true;
|
m_templates_updated = true;
|
||||||
|
|
||||||
} else if (name == cfg_current_ruler_template) {
|
} else if (name == cfg_current_ruler_template) {
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
@ -161,9 +169,15 @@ PluginDeclaration::config_finalize ()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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
|
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<ant::Template>::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<lay::PluginDeclaration> config_decl (new ant::PluginDeclaration (), 3000, "ant::Plugin");
|
static tl::RegisteredClass<lay::PluginDeclaration> config_decl (new ant::PluginDeclaration (), 3000, "ant::Plugin");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,14 @@ public:
|
||||||
virtual bool configure (const std::string &name, const std::string &value);
|
virtual bool configure (const std::string &name, const std::string &value);
|
||||||
virtual std::vector<std::pair <std::string, lay::ConfigPage *> > config_pages (QWidget *parent) const;
|
virtual std::vector<std::pair <std::string, lay::ConfigPage *> > config_pages (QWidget *parent) const;
|
||||||
virtual void config_finalize ();
|
virtual void config_finalize ();
|
||||||
virtual void initialize (lay::PluginRoot *);
|
virtual void initialized (lay::PluginRoot *);
|
||||||
virtual void uninitialize (lay::PluginRoot *);
|
virtual void uninitialize (lay::PluginRoot *);
|
||||||
virtual bool menu_activated (const std::string &symbol) const;
|
virtual bool menu_activated (const std::string &symbol) const;
|
||||||
|
|
||||||
|
void register_annotation_template (const ant::Template &t);
|
||||||
|
|
||||||
|
static PluginDeclaration *instance ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void update_current_template ();
|
void update_current_template ();
|
||||||
void update_menu ();
|
void update_menu ();
|
||||||
|
|
|
||||||
|
|
@ -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<ant::Template> 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
|
} // namespace ant
|
||||||
|
|
|
||||||
|
|
@ -438,11 +438,6 @@ public:
|
||||||
*/
|
*/
|
||||||
tl::Event annotation_selection_changed_event;
|
tl::Event annotation_selection_changed_event;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Registers an annotation template globally
|
|
||||||
*/
|
|
||||||
static void register_annotation_template (const ant::Template &t);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Ruler display and snapping configuration
|
// Ruler display and snapping configuration
|
||||||
QColor m_color;
|
QColor m_color;
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,10 @@ Template::Template ()
|
||||||
|
|
||||||
Template::Template (const std::string &title,
|
Template::Template (const std::string &title,
|
||||||
const std::string &fmt_x, const std::string &fmt_y, const std::string &fmt,
|
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_title (title),
|
||||||
|
m_category (cat),
|
||||||
m_fmt_x (fmt_x), m_fmt_y (fmt_y), m_fmt (fmt),
|
m_fmt_x (fmt_x), m_fmt_y (fmt_y), m_fmt (fmt),
|
||||||
m_style (style), m_outline (outline),
|
m_style (style), m_outline (outline),
|
||||||
m_snap (snap), m_angle_constraint (angle_constraint),
|
m_snap (snap), m_angle_constraint (angle_constraint),
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ public:
|
||||||
*
|
*
|
||||||
* Creates a template with the given format strings and styles
|
* 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
|
* @brief Copy constructor
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,11 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "gsiDecl.h"
|
#include "gsiDecl.h"
|
||||||
#include "gsiSignals.h"
|
#include "gsiSignals.h"
|
||||||
#include "antObject.h"
|
#include "antObject.h"
|
||||||
#include "antService.h"
|
#include "antService.h"
|
||||||
|
#include "antPlugin.h"
|
||||||
#include "layLayoutView.h"
|
#include "layLayoutView.h"
|
||||||
|
|
||||||
namespace gsi
|
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));
|
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.
|
// NOTE: ant::Object is available as "BasicAnnotation" to allow binding for other methods.
|
||||||
|
|
|
||||||
|
|
@ -108,8 +108,7 @@ snap (const db::DPoint &p1, const db::DPoint &p2, db::DCoord grid)
|
||||||
if (grid <= 1e-10) {
|
if (grid <= 1e-10) {
|
||||||
return std::make_pair (p1, p2);
|
return std::make_pair (p1, p2);
|
||||||
} else {
|
} else {
|
||||||
std::pair<db::DPoint, db
|
std::pair<db::DPoint, db::DPoint> v = snap (db::DPoint (p1.x () / grid, p1.y () / grid),
|
||||||
::DPoint> v = snap (db::DPoint (p1.x () / grid, p1.y () / grid),
|
|
||||||
db::DPoint (p2.x () / grid, p2.y () / grid));
|
db::DPoint (p2.x () / grid, p2.y () / grid));
|
||||||
return std::make_pair (v.first * grid, v.second * grid);
|
return std::make_pair (v.first * grid, v.second * grid);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue