Introducing variables to property filters, computation functions, generalizing net function for net measurement

This commit is contained in:
Matthias Koefferlein 2025-08-02 19:50:06 +02:00
parent e82ebf6733
commit d001f7fa04
10 changed files with 96 additions and 69 deletions

View File

@ -2055,7 +2055,7 @@ db::Region LayoutToNetlist::antenna_check (const db::Region &gate, double gate_a
}
db::Region
LayoutToNetlist::measure_net (const db::Region &primary, const std::map<std::string, const db::Region *> &secondary, const std::string &expression)
LayoutToNetlist::measure_net (const db::Region &primary, const std::map<std::string, const db::Region *> &secondary, const std::string &expression, const std::map<std::string, tl::Variant> &variables)
{
// TODO: that's basically too much .. we only need the clusters
if (! m_netlist_extracted) {
@ -2065,6 +2065,25 @@ LayoutToNetlist::measure_net (const db::Region &primary, const std::map<std::str
db::Layout &ly = dss ().layout (m_layout_index);
double dbu = ly.dbu ();
db::MeasureNetEval eval (this, dbu);
for (auto v = variables.begin (); v != variables.end (); ++v) {
eval.set_var (v->first, v->second);
}
eval.set_primary_layer (layer_of (primary));
for (auto s = secondary.begin (); s != secondary.end (); ++s) {
if (s->second) {
eval.set_secondary_layer (s->first, layer_of (*s->second));
}
}
eval.init ();
tl::Extractor ex (expression.c_str ());
tl::Expression compiled_expr;
eval.parse (compiled_expr, ex);
db::DeepLayer dl (&dss (), m_layout_index, ly.insert_layer ());
for (db::Layout::bottom_up_const_iterator cid = ly.begin_bottom_up (); cid != ly.end_bottom_up (); ++cid) {
@ -2074,21 +2093,6 @@ LayoutToNetlist::measure_net (const db::Region &primary, const std::map<std::str
continue;
}
db::MeasureNetEval eval (this, dbu);
eval.set_primary_layer (layer_of (primary));
for (auto s = secondary.begin (); s != secondary.end (); ++s) {
if (s->second) {
eval.set_secondary_layer (s->first, layer_of (*s->second));
}
}
eval.init ();
tl::Extractor ex (expression.c_str ());
tl::Expression compiled_expr;
eval.parse (compiled_expr, ex);
for (connected_clusters<db::NetShape>::all_iterator c = clusters.begin_all (); ! c.at_end (); ++c) {
if (! clusters.is_root (*c)) {

View File

@ -1146,9 +1146,9 @@ public:
* * "perimeter(name)": the perimeter of the secondary-layer shapes. 'name' is a symbol with the name given in the secondary-layer map
* * "put(name, value)": places the value as property 'name' on the output shapes
* * "skip(flag)": will skip the primary shapes of that net when called with a true value
* * "net_name": the name of the net
* * "net": the Net object of the current net
*/
db::Region measure_net (const db::Region &primary, const std::map<std::string, const db::Region *> &secondary, const std::string &expression);
db::Region measure_net (const db::Region &primary, const std::map<std::string, const db::Region *> &secondary, const std::string &expression, const std::map<std::string, tl::Variant> &variables);
/**
* @brief Saves the database to the given path

View File

@ -21,6 +21,7 @@
*/
#include "dbMeasureEval.h"
#include "gsiClassBase.h"
namespace db
{
@ -372,11 +373,11 @@ private:
MeasureNetEval *mp_eval;
};
class NetNameFunction
class NetFunction
: public tl::EvalFunction
{
public:
NetNameFunction (MeasureNetEval *eval)
NetFunction (MeasureNetEval *eval)
: mp_eval (eval)
{
// .. nothing yet ..
@ -385,9 +386,9 @@ public:
virtual void execute (const tl::ExpressionParserContext &context, tl::Variant &out, const std::vector<tl::Variant> &args, const std::map<std::string, tl::Variant> * /*kwargs*/) const
{
if (args.size () != 1) {
throw tl::EvalError (tl::to_string (tr ("'net_name' function does not take and argument")), context);
throw tl::EvalError (tl::to_string (tr ("'net' function does not take and argument")), context);
}
out = mp_eval->net_name_func ();
out = mp_eval->net_func ();
}
private:
@ -465,7 +466,7 @@ MeasureNetEval::init ()
define_function ("skip", new NetSkipFunction (this));
define_function ("area", new NetAreaFunction (this));
define_function ("perimeter", new NetPerimeterFunction (this));
define_function ("net_name", new NetNameFunction (this));
define_function ("net", new NetFunction (this));
}
void
@ -531,7 +532,7 @@ MeasureNetEval::skip_func (bool f) const
}
tl::Variant
MeasureNetEval::net_name_func () const
MeasureNetEval::net_func () const
{
const db::Netlist *nl = mp_l2n->netlist ();
if (! nl) {
@ -552,7 +553,7 @@ MeasureNetEval::net_name_func () const
auto n = m_nets_per_cell_and_cluster_id->find (std::make_pair (m_cell_index, m_cluster_id));
if (n != m_nets_per_cell_and_cluster_id->end ()) {
return tl::Variant (n->second->name ());
return tl::Variant::make_variant_ref (n.operator-> ());
} else {
return tl::Variant ();
}

View File

@ -137,7 +137,7 @@ private:
friend class NetPutFunction;
friend class NetAreaFunction;
friend class NetPerimeterFunction;
friend class NetNameFunction;
friend class NetFunction;
friend class NetSkipFunction;
struct AreaAndPerimeter
@ -162,7 +162,7 @@ private:
tl::Variant area_func (int layer_index) const;
tl::Variant perimeter_func (int layer_index) const;
void skip_func (bool f) const;
tl::Variant net_name_func () const;
tl::Variant net_func () const;
};
}

View File

@ -90,9 +90,9 @@ static gsi::EdgePairFilterBase *make_pg (const tl::Variant &name, const std::str
return new EdgePairPropertiesFilter (name, pattern, inverse);
}
static gsi::EdgePairFilterBase *make_pe (const std::string &expression, bool inverse, double dbu)
static gsi::EdgePairFilterBase *make_pe (const std::string &expression, bool inverse, double dbu, const std::map<std::string, tl::Variant> &variables)
{
return new gsi::expression_filter<gsi::EdgePairFilterBase, db::EdgePairs> (expression, inverse, dbu);
return new gsi::expression_filter<gsi::EdgePairFilterBase, db::EdgePairs> (expression, inverse, dbu, variables);
}
Class<gsi::EdgePairFilterBase> decl_EdgePairFilterBase ("db", "EdgePairFilterBase",
@ -136,11 +136,12 @@ Class<gsi::EdgePairFilterBase> decl_EdgePairFilterBase ("db", "EdgePairFilterBas
"\n"
"This feature has been introduced in version 0.30."
) +
gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0),
gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Creates an expression-based filter\n"
"@param expression The expression to evaluate.\n"
"@param inverse If true, inverts the selection - i.e. all edge pairs without a property with the given name and value range are selected.\n"
"@param dbu If given and greater than zero, the shapes delivered by the 'shape' function will be in micrometer units.\n"
"@param variables Arbitrary values that are available as variables inside the expressions.\n"
"\n"
"Creates a filter that will evaluate the given expression on every shape and select the shape "
"when the expression renders a boolean true value. "
@ -256,37 +257,39 @@ Class<shape_processor_impl<db::EdgePairProcessorBase> > decl_EdgePairProcessor (
static
property_computation_processor<db::EdgePairProcessorBase, db::EdgePairs> *
new_pcp (const db::EdgePairs *container, const std::map<tl::Variant, std::string> &expressions, bool copy_properties, double dbu)
new_pcp (const db::EdgePairs *container, const std::map<tl::Variant, std::string> &expressions, bool copy_properties, double dbu, const std::map <std::string, tl::Variant> &variables)
{
return new property_computation_processor<db::EdgePairProcessorBase, db::EdgePairs> (container, expressions, copy_properties, dbu);
return new property_computation_processor<db::EdgePairProcessorBase, db::EdgePairs> (container, expressions, copy_properties, dbu, variables);
}
static
property_computation_processor<db::EdgePairProcessorBase, db::EdgePairs> *
new_pcps (const db::EdgePairs *container, const std::string &expression, bool copy_properties, double dbu)
new_pcps (const db::EdgePairs *container, const std::string &expression, bool copy_properties, double dbu, const std::map <std::string, tl::Variant> &variables)
{
std::map<tl::Variant, std::string> expressions;
expressions.insert (std::make_pair (tl::Variant (), expression));
return new property_computation_processor<db::EdgePairProcessorBase, db::EdgePairs> (container, expressions, copy_properties, dbu);
return new property_computation_processor<db::EdgePairProcessorBase, db::EdgePairs> (container, expressions, copy_properties, dbu, variables);
}
Class<property_computation_processor<db::EdgePairProcessorBase, db::EdgePairs> > decl_EdgePairPropertiesExpressions (decl_EdgePairProcessorBase, "db", "EdgePairPropertiesExpressions",
property_computation_processor<db::EdgePairProcessorBase, db::EdgePairs>::method_decls (true) +
gsi::constructor ("new", &new_pcp, gsi::arg ("edge_pairs"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0),
gsi::constructor ("new", &new_pcp, gsi::arg ("edge_pairs"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Creates a new properties expressions operator\n"
"\n"
"@param edge_pairs The edge pair collection, the processor will be used on. Can be nil, but if given, allows some optimization.\n"
"@param expressions A map of property names and expressions used to generate the values of the properties (see class description for details).\n"
"@param copy_properties If true, new properties will be added to existing ones.\n"
"@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n"
"@param variables Arbitrary values that are available as variables inside the expressions.\n"
) +
gsi::constructor ("new", &new_pcps, gsi::arg ("edge_pairs"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0),
gsi::constructor ("new", &new_pcps, gsi::arg ("edge_pairs"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Creates a new properties expressions operator\n"
"\n"
"@param edge_pairs The edge pair collection, the processor will be used on. Can be nil, but if given, allows some optimization.\n"
"@param expression A single expression evaluated for each shape (see class description for details).\n"
"@param copy_properties If true, new properties will be added to existing ones.\n"
"@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n"
"@param variables Arbitrary values that are available as variables inside the expressions.\n"
),
"@brief An operator attaching computed properties to the edge pairs\n"
"\n"

View File

@ -91,9 +91,9 @@ static gsi::EdgeFilterBase *make_pg (const tl::Variant &name, const std::string
return new EdgePropertiesFilter (name, pattern, inverse);
}
static gsi::EdgeFilterBase *make_pe (const std::string &expression, bool inverse, double dbu)
static gsi::EdgeFilterBase *make_pe (const std::string &expression, bool inverse, double dbu, const std::map<std::string, tl::Variant> &variables)
{
return new gsi::expression_filter<gsi::EdgeFilterBase, db::Edges> (expression, inverse, dbu);
return new gsi::expression_filter<gsi::EdgeFilterBase, db::Edges> (expression, inverse, dbu, variables);
}
Class<gsi::EdgeFilterBase> decl_EdgeFilterBase ("db", "EdgeFilterBase",
@ -137,11 +137,12 @@ Class<gsi::EdgeFilterBase> decl_EdgeFilterBase ("db", "EdgeFilterBase",
"\n"
"This feature has been introduced in version 0.30."
) +
gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0),
gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Creates an expression-based filter\n"
"@param expression The expression to evaluate.\n"
"@param inverse If true, inverts the selection - i.e. all edges without a property with the given name and value range are selected.\n"
"@param dbu If given and greater than zero, the shapes delivered by the 'shape' function will be in micrometer units.\n"
"@param variables Arbitrary values that are available as variables inside the expressions.\n"
"\n"
"Creates a filter that will evaluate the given expression on every shape and select the shape "
"when the expression renders a boolean true value. "
@ -261,37 +262,39 @@ Class<shape_processor_impl<db::EdgeProcessorBase> > decl_EdgeOperator (decl_Edge
static
property_computation_processor<db::EdgeProcessorBase, db::Edges> *
new_pcp (const db::Edges *container, const std::map<tl::Variant, std::string> &expressions, bool copy_properties, double dbu)
new_pcp (const db::Edges *container, const std::map<tl::Variant, std::string> &expressions, bool copy_properties, double dbu, const std::map <std::string, tl::Variant> &variables)
{
return new property_computation_processor<db::EdgeProcessorBase, db::Edges> (container, expressions, copy_properties, dbu);
return new property_computation_processor<db::EdgeProcessorBase, db::Edges> (container, expressions, copy_properties, dbu, variables);
}
static
property_computation_processor<db::EdgeProcessorBase, db::Edges> *
new_pcps (const db::Edges *container, const std::string &expression, bool copy_properties, double dbu)
new_pcps (const db::Edges *container, const std::string &expression, bool copy_properties, double dbu, const std::map <std::string, tl::Variant> &variables)
{
std::map<tl::Variant, std::string> expressions;
expressions.insert (std::make_pair (tl::Variant (), expression));
return new property_computation_processor<db::EdgeProcessorBase, db::Edges> (container, expressions, copy_properties, dbu);
return new property_computation_processor<db::EdgeProcessorBase, db::Edges> (container, expressions, copy_properties, dbu, variables);
}
Class<property_computation_processor<db::EdgeProcessorBase, db::Edges> > decl_EdgePropertiesExpressions (decl_EdgeProcessorBase, "db", "EdgePropertiesExpressions",
property_computation_processor<db::EdgeProcessorBase, db::Edges>::method_decls (true) +
gsi::constructor ("new", &new_pcp, gsi::arg ("edges"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0),
gsi::constructor ("new", &new_pcp, gsi::arg ("edges"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Creates a new properties expressions operator\n"
"\n"
"@param edges The edge collection, the processor will be used on. Can be nil, but if given, allows some optimization.\n"
"@param expressions A map of property names and expressions used to generate the values of the properties (see class description for details).\n"
"@param copy_properties If true, new properties will be added to existing ones.\n"
"@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n"
"@param variables Arbitrary values that are available as variables inside the expressions.\n"
) +
gsi::constructor ("new", &new_pcps, gsi::arg ("edges"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0),
gsi::constructor ("new", &new_pcps, gsi::arg ("edges"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Creates a new properties expressions operator\n"
"\n"
"@param edges The edge collection, the processor will be used on. Can be nil, but if given, allows some optimization.\n"
"@param expression A single expression evaluated for each shape (see class description for details).\n"
"@param copy_properties If true, new properties will be added to existing ones.\n"
"@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n"
"@param variables Arbitrary values that are available as variables inside the expressions.\n"
),
"@brief An operator attaching computed properties to the edge pairs\n"
"\n"

View File

@ -216,9 +216,9 @@ static db::Region antenna_check (db::LayoutToNetlist *l2n, const db::Region &pol
return antenna_check3 (l2n, poly, 1, 0, metal, 1, 0, ratio, diodes, texts);
}
static db::Region measure_net (db::LayoutToNetlist *l2n, const db::Region &primary, const std::map<std::string, const db::Region *> &secondary, const std::string &expression)
static db::Region measure_net (db::LayoutToNetlist *l2n, const db::Region &primary, const std::map<std::string, const db::Region *> &secondary, const std::string &expression, const std::map<std::string, tl::Variant> &variables)
{
return l2n->measure_net (primary, secondary, expression);
return l2n->measure_net (primary, secondary, expression, variables);
}
static void join_net_names (db::LayoutToNetlist *l2n, const std::string &s)
@ -1215,10 +1215,12 @@ Class<db::LayoutToNetlist> decl_dbLayoutToNetlist ("db", "LayoutToNetlist",
"\n"
"This variant has been introduced in version 0.26.6.\n"
) +
gsi::method_ext ("measure_net", &measure_net, gsi::arg ("primary"), gsi::arg ("secondary"), gsi::arg ("expression"),
gsi::method_ext ("measure_net", &measure_net, gsi::arg ("primary"), gsi::arg ("secondary"), gsi::arg ("expression"), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Runs a generic net measurement function\n"
"\n"
"This method accepts some primary layer, a number of secondary layers with names and an expression.\n"
"It also accepts variables which become available as variables inside the expression. This allows passing "
"arbitrary values without having to encode them into the expression string.\n"
"\n"
"It will look at nets connecting to shapes on the primary layer and execute the expression for each\n"
"of those nets. After that it will copy the primary shapes of the net to the output with the properties\n"
@ -1236,7 +1238,7 @@ Class<db::LayoutToNetlist> decl_dbLayoutToNetlist ("db", "LayoutToNetlist",
"@li 'perimeter(name)': the perimeter of the secondary-layer shapes. 'name' is a symbol with the name given in the secondary-layer map @/li\n"
"@li 'put(name, value)': places the value as property 'name' on the output shapes @/li\n"
"@li 'skip(flag)': will skip the primary shapes of that net when called with a true value @/li\n"
"@li 'net_name': the name of the net @/li\n"
"@li 'net': the \\Net object of the current net @/li\n"
"@/ul\n"
) +
// test API

View File

@ -98,7 +98,7 @@ public:
typedef typename ProcessorBase::shape_type shape_type;
typedef typename ProcessorBase::result_type result_type;
property_computation_processor (const Container *container, const std::map<tl::Variant, std::string> &expressions, bool copy_properties, double dbu)
property_computation_processor (const Container *container, const std::map<tl::Variant, std::string> &expressions, bool copy_properties, double dbu, const std::map<std::string, tl::Variant> &variables)
: m_eval (dbu, true /*with_put*/), m_copy_properties (copy_properties), m_expression_strings (expressions)
{
if (container) {
@ -107,6 +107,10 @@ public:
m_eval.init ();
for (auto v = variables.begin (); v != variables.end (); ++v) {
m_eval.set_var (v->first, v->second);
}
// compile the expressions
for (auto e = m_expression_strings.begin (); e != m_expression_strings.end (); ++e) {
m_expressions.push_back (std::make_pair (e->first.is_nil () ? db::property_names_id_type (0) : db::property_names_id (e->first), tl::Expression ()));
@ -170,11 +174,15 @@ class expression_filter
public:
typedef typename FilterBase::shape_type shape_type;
expression_filter (const std::string &expression, bool inverse, double dbu)
expression_filter (const std::string &expression, bool inverse, double dbu, const std::map<std::string, tl::Variant> &variables)
: m_eval (dbu, false /*without put func*/), m_inverse (inverse), m_expression_string (expression)
{
m_eval.init ();
for (auto v = variables.begin (); v != variables.end (); ++v) {
m_eval.set_var (v->first, v->second);
}
// compile the expression
tl::Extractor ex (m_expression_string.c_str ());
m_eval.parse (m_expression, ex);

View File

@ -109,9 +109,9 @@ static gsi::PolygonFilterBase *make_pg (const tl::Variant &name, const std::stri
return new PolygonPropertiesFilter (name, pattern, inverse);
}
static gsi::PolygonFilterBase *make_pe (const std::string &expression, bool inverse, double dbu)
static gsi::PolygonFilterBase *make_pe (const std::string &expression, bool inverse, double dbu, const std::map<std::string, tl::Variant> &variables)
{
return new gsi::expression_filter<gsi::PolygonFilterBase, db::Region> (expression, inverse, dbu);
return new gsi::expression_filter<gsi::PolygonFilterBase, db::Region> (expression, inverse, dbu, variables);
}
Class<gsi::PolygonFilterBase> decl_PolygonFilterBase ("db", "PolygonFilterBase",
@ -155,11 +155,12 @@ Class<gsi::PolygonFilterBase> decl_PolygonFilterBase ("db", "PolygonFilterBase",
"\n"
"This feature has been introduced in version 0.30."
) +
gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0),
gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Creates an expression-based filter\n"
"@param expression The expression to evaluate.\n"
"@param inverse If true, inverts the selection - i.e. all polygons without a property with the given name and value range are selected.\n"
"@param dbu If given and greater than zero, the shapes delivered by the 'shape' function will be in micrometer units.\n"
"@param variables Arbitrary values that are available as variables inside the expressions.\n"
"\n"
"Creates a filter that will evaluate the given expression on every shape and select the shape "
"when the expression renders a boolean true value. "
@ -277,36 +278,38 @@ Class<shape_processor_impl<db::PolygonProcessorBase> > decl_PolygonOperator (dec
static
property_computation_processor<db::PolygonProcessorBase, db::Region> *
new_pcp (const db::Region *container, const std::map<tl::Variant, std::string> &expressions, bool copy_properties, double dbu)
new_pcp (const db::Region *container, const std::map<tl::Variant, std::string> &expressions, bool copy_properties, double dbu, const std::map <std::string, tl::Variant> &variables)
{
return new property_computation_processor<db::PolygonProcessorBase, db::Region> (container, expressions, copy_properties, dbu);
return new property_computation_processor<db::PolygonProcessorBase, db::Region> (container, expressions, copy_properties, dbu, variables);
}
property_computation_processor<db::PolygonProcessorBase, db::Region> *
new_pcps (const db::Region *container, const std::string &expression, bool copy_properties, double dbu)
new_pcps (const db::Region *container, const std::string &expression, bool copy_properties, double dbu, const std::map <std::string, tl::Variant> &variables)
{
std::map<tl::Variant, std::string> expressions;
expressions.insert (std::make_pair (tl::Variant (), expression));
return new property_computation_processor<db::PolygonProcessorBase, db::Region> (container, expressions, copy_properties, dbu);
return new property_computation_processor<db::PolygonProcessorBase, db::Region> (container, expressions, copy_properties, dbu, variables);
}
Class<property_computation_processor<db::PolygonProcessorBase, db::Region> > decl_PolygonPropertiesExpressions (decl_PolygonProcessorBase, "db", "PolygonPropertiesExpressions",
property_computation_processor<db::PolygonProcessorBase, db::Region>::method_decls (true) +
gsi::constructor ("new", &new_pcp, gsi::arg ("region"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0),
gsi::constructor ("new", &new_pcp, gsi::arg ("region"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Creates a new properties expressions operator\n"
"\n"
"@param region The region, the processor will be used on. Can be nil, but if given, allows some optimization.\n"
"@param expressions A map of property names and expressions used to generate the values of the properties (see class description for details).\n"
"@param copy_properties If true, new properties will be added to existing ones.\n"
"@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n"
"@param variables Arbitrary values that are available as variables inside the expressions.\n"
) +
gsi::constructor ("new", &new_pcps, gsi::arg ("region"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0),
gsi::constructor ("new", &new_pcps, gsi::arg ("region"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Creates a new properties expressions operator\n"
"\n"
"@param region The region, the processor will be used on. Can be nil, but if given, allows some optimization.\n"
"@param expression A single expression evaluated for each shape (see class description for details).\n"
"@param copy_properties If true, new properties will be added to existing ones.\n"
"@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n"
"@param variables Arbitrary values that are available as variables inside the expressions.\n"
),
"@brief An operator attaching computed properties to the edge pairs\n"
"\n"

View File

@ -87,9 +87,9 @@ static gsi::TextFilterBase *make_pg (const tl::Variant &name, const std::string
return new TextPropertiesFilter (name, pattern, inverse);
}
static gsi::TextFilterBase *make_pe (const std::string &expression, bool inverse, double dbu)
static gsi::TextFilterBase *make_pe (const std::string &expression, bool inverse, double dbu, const std::map<std::string, tl::Variant> &variables)
{
return new gsi::expression_filter<gsi::TextFilterBase, db::Texts> (expression, inverse, dbu);
return new gsi::expression_filter<gsi::TextFilterBase, db::Texts> (expression, inverse, dbu, variables);
}
Class<gsi::TextFilterBase> decl_TextFilterBase ("db", "TextFilterBase",
@ -133,11 +133,12 @@ Class<gsi::TextFilterBase> decl_TextFilterBase ("db", "TextFilterBase",
"\n"
"This feature has been introduced in version 0.30."
) +
gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0),
gsi::constructor ("expression_filter", &make_pe, gsi::arg ("expression"), gsi::arg ("inverse", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Creates an expression-based filter\n"
"@param expression The expression to evaluate.\n"
"@param inverse If true, inverts the selection - i.e. all texts without a property with the given name and value range are selected.\n"
"@param dbu If given and greater than zero, the shapes delivered by the 'shape' function will be in micrometer units.\n"
"@param variables Arbitrary values that are available as variables inside the expressions.\n"
"\n"
"Creates a filter that will evaluate the given expression on every shape and select the shape "
"when the expression renders a boolean true value. "
@ -256,36 +257,38 @@ Class<shape_processor_impl<db::TextProcessorBase> > decl_TextProcessor (decl_Tex
static
property_computation_processor<db::TextProcessorBase, db::Texts> *
new_pcp (const db::Texts *container, const std::map<tl::Variant, std::string> &expressions, bool copy_properties, double dbu)
new_pcp (const db::Texts *container, const std::map<tl::Variant, std::string> &expressions, bool copy_properties, double dbu, const std::map <std::string, tl::Variant> &variables)
{
return new property_computation_processor<db::TextProcessorBase, db::Texts> (container, expressions, copy_properties, dbu);
return new property_computation_processor<db::TextProcessorBase, db::Texts> (container, expressions, copy_properties, dbu, variables);
}
property_computation_processor<db::TextProcessorBase, db::Texts> *
new_pcps (const db::Texts *container, const std::string &expression, bool copy_properties, double dbu)
new_pcps (const db::Texts *container, const std::string &expression, bool copy_properties, double dbu, const std::map <std::string, tl::Variant> &variables)
{
std::map<tl::Variant, std::string> expressions;
expressions.insert (std::make_pair (tl::Variant (), expression));
return new property_computation_processor<db::TextProcessorBase, db::Texts> (container, expressions, copy_properties, dbu);
return new property_computation_processor<db::TextProcessorBase, db::Texts> (container, expressions, copy_properties, dbu, variables);
}
Class<property_computation_processor<db::TextProcessorBase, db::Texts> > decl_TextPropertiesExpressions (decl_TextProcessorBase, "db", "TextPropertiesExpressions",
property_computation_processor<db::TextProcessorBase, db::Texts>::method_decls (true) +
gsi::constructor ("new", &new_pcp, gsi::arg ("texts"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0),
gsi::constructor ("new", &new_pcp, gsi::arg ("texts"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Creates a new properties expressions operator\n"
"\n"
"@param texts The text collection, the processor will be used on. Can be nil, but if given, allows some optimization.\n"
"@param expressions A map of property names and expressions used to generate the values of the properties (see class description for details).\n"
"@param copy_properties If true, new properties will be added to existing ones.\n"
"@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n"
"@param variables Arbitrary values that are available as variables inside the expressions.\n"
) +
gsi::constructor ("new", &new_pcps, gsi::arg ("texts"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0),
gsi::constructor ("new", &new_pcps, gsi::arg ("texts"), gsi::arg ("expression"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), gsi::arg ("variables", std::map<std::string, tl::Variant> (), "{}"),
"@brief Creates a new properties expressions operator\n"
"\n"
"@param texts The text collection, the processor will be used on. Can be nil, but if given, allows some optimization.\n"
"@param expression A single expression evaluated for each shape (see class description for details).\n"
"@param copy_properties If true, new properties will be added to existing ones.\n"
"@param dbu If not zero, this value specifies the database unit to use. If given, the shapes returned by the 'shape' function will be micrometer-unit objects.\n"
"@param variables Arbitrary values that are available as variables inside the expressions.\n"
),
"@brief An operator attaching computed properties to the edge pairs\n"
"\n"