From 3a612f9b04e97e5868a033ac499777b29cda58c7 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 28 Jul 2025 23:11:21 +0200 Subject: [PATCH] WIP: integration of new features --- src/db/db/gsiDeclDbEdgePairs.cc | 81 ++++++++++++++++++++++++++++++--- src/db/db/gsiDeclDbEdges.cc | 81 ++++++++++++++++++++++++++++++--- src/db/db/gsiDeclDbTexts.cc | 75 ++++++++++++++++++++++++++++-- 3 files changed, 218 insertions(+), 19 deletions(-) diff --git a/src/db/db/gsiDeclDbEdgePairs.cc b/src/db/db/gsiDeclDbEdgePairs.cc index 903aba802..88ef5d297 100644 --- a/src/db/db/gsiDeclDbEdgePairs.cc +++ b/src/db/db/gsiDeclDbEdgePairs.cc @@ -33,6 +33,7 @@ #include "dbPropertiesFilter.h" #include "gsiDeclDbContainerHelpers.h" +#include "gsiDeclDbMeasureHelpers.h" namespace gsi { @@ -89,6 +90,11 @@ 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) +{ + return new gsi::expression_filter (expression, inverse, dbu); +} + Class decl_EdgePairFilterBase ("db", "EdgePairFilterBase", gsi::EdgePairFilterBase::method_decls (true) + gsi::constructor ("property_glob", &make_pg, gsi::arg ("name"), gsi::arg ("pattern"), gsi::arg ("inverse", false), gsi::arg ("case_sensitive", true), @@ -129,6 +135,25 @@ Class decl_EdgePairFilterBase ("db", "EdgePairFilterBas "Apply this filter with \\EdgePairs#filtered. See \\property_glob for an example.\n" "\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), + "@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" + "\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. " + "The expression may use the following variables and functions:\n" + "\n" + "@ul\n" + "@li @b shape @/b: The current shape (i.e. 'EdgePair' without DBU specified or 'DEdgePair' otherwise) @/li\n" + "@li @b value() @/b: The value of the property with the given name (the first one if there are multiple properties with the same name) @/li\n" + "@li @b values() @/b: All values of the properties with the given name (returns a list) @/li\n" + "@li @b @/b: A shortcut for 'value()' ( is used as a symbol) @/li\n" + "@/ul\n" + "\n" + "This feature has been introduced in version 0.30.3." ), "@hide" ); @@ -184,7 +209,9 @@ Class decl_EdgePairFilterImpl (decl_EdgePairFilterBase, // --------------------------------------------------------------------------------- // EdgePairProcessor binding -Class > decl_EdgePairProcessor ("db", "EdgePairOperator", +Class decl_EdgePairProcessorBase ("db", "EdgePairProcessorBase", "@hide"); + +Class > decl_EdgePairProcessor (decl_EdgePairProcessorBase, "db", "EdgePairOperator", shape_processor_impl::method_decls (false), "@brief A generic edge-pair operator\n" "\n" @@ -227,7 +254,45 @@ Class > decl_EdgePairProcessor ( "This class has been introduced in version 0.29.\n" ); -Class > decl_EdgePairToPolygonProcessor ("db", "EdgePairToPolygonOperator", +static +property_computation_processor * +new_pcp (const db::EdgePairs *container, const std::map &expressions, bool copy_properties, double dbu) +{ + return new property_computation_processor (container, expressions, copy_properties, dbu); +} + +Class > decl_EdgePairPropertiesExpressions (decl_EdgePairProcessorBase, "db", "EdgePairPropertiesExpressions", + property_computation_processor::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), + "@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" + ), + "@brief An operator attaching computed properties to the edge pairs\n" + "\n" + "This operator will execute a number of expressions and attach the results as new properties. " + "The expression inputs can be taken either from the edge pairs themselves or from existing properties.\n" + "\n" + "A number of expressions can be supplied with a name. The expressions will be evaluated and the result " + "is attached to the output edge pairs as user properties with the given names.\n" + "The expression may use the following variables and functions:\n" + "\n" + "@ul\n" + "@li @b shape @/b: The current shape (i.e. 'EdgePair' without DBU specified or 'DEdgePair' otherwise) @/li\n" + "@li @b value() @/b: The value of the property with the given name (the first one if there are multiple properties with the same name) @/li\n" + "@li @b values() @/b: All values of the properties with the given name (returns a list) @/li\n" + "@li @b @/b: A shortcut for 'value()' ( is used as a symbol) @/li\n" + "@/ul\n" + "\n" + "This class has been introduced in version 0.30.3.\n" +); + +Class decl_EdgePairToPolygonProcessorBase ("db", "EdgePairToPolygonProcessorBase", "@hide"); + +Class > decl_EdgePairToPolygonProcessor (decl_EdgePairToPolygonProcessorBase, "db", "EdgePairToPolygonOperator", shape_processor_impl::method_decls (false), "@brief A generic edge-pair-to-polygon operator\n" "\n" @@ -251,7 +316,9 @@ Class > decl_EdgePairTo "This class has been introduced in version 0.29.\n" ); -Class > decl_EdgePairToEdgeProcessor ("db", "EdgePairToEdgeOperator", +Class decl_EdgePairToEdgeProcessorBase ("db", "EdgePairProcessorBase", "@hide"); + +Class > decl_EdgePairToEdgeProcessor (decl_EdgePairToEdgeProcessorBase, "db", "EdgePairToEdgeOperator", shape_processor_impl::method_decls (false), "@brief A generic edge-pair-to-edge operator\n" "\n" @@ -491,24 +558,24 @@ static std::vector split_filter (const db::EdgePairs *r, const Ed return as_2edge_pairs_vector (r->split_filter (*f)); } -static db::EdgePairs processed_epep (const db::EdgePairs *r, const shape_processor_impl *f) +static db::EdgePairs processed_epep (const db::EdgePairs *r, const db::EdgePairProcessorBase *f) { return r->processed (*f); } -static void process_epep (db::EdgePairs *r, const shape_processor_impl *f) +static void process_epep (db::EdgePairs *r, const db::EdgePairProcessorBase *f) { r->process (*f); } -static db::Edges processed_epe (const db::EdgePairs *r, const shape_processor_impl *f) +static db::Edges processed_epe (const db::EdgePairs *r, const db::EdgePairToEdgeProcessorBase *f) { db::Edges out; r->processed (out, *f); return out; } -static db::Region processed_epp (const db::EdgePairs *r, const shape_processor_impl *f) +static db::Region processed_epp (const db::EdgePairs *r, const db::EdgePairToPolygonProcessorBase *f) { db::Region out; r->processed (out, *f); diff --git a/src/db/db/gsiDeclDbEdges.cc b/src/db/db/gsiDeclDbEdges.cc index 0383d14ac..036391851 100644 --- a/src/db/db/gsiDeclDbEdges.cc +++ b/src/db/db/gsiDeclDbEdges.cc @@ -34,6 +34,7 @@ #include "dbPropertiesFilter.h" #include "gsiDeclDbContainerHelpers.h" +#include "gsiDeclDbMeasureHelpers.h" namespace gsi { @@ -90,6 +91,11 @@ 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) +{ + return new gsi::expression_filter (expression, inverse, dbu); +} + Class decl_EdgeFilterBase ("db", "EdgeFilterBase", gsi::EdgeFilterBase::method_decls (true) + gsi::constructor ("property_glob", &make_pg, gsi::arg ("name"), gsi::arg ("pattern"), gsi::arg ("inverse", false), gsi::arg ("case_sensitive", true), @@ -130,6 +136,25 @@ Class decl_EdgeFilterBase ("db", "EdgeFilterBase", "Apply this filter with \\Edges#filtered. See \\property_glob for an example.\n" "\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), + "@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" + "\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. " + "The expression may use the following variables and functions:\n" + "\n" + "@ul\n" + "@li @b shape @/b: The current shape (i.e. 'Edge' without DBU specified or 'DEdge' otherwise) @/li\n" + "@li @b value() @/b: The value of the property with the given name (the first one if there are multiple properties with the same name) @/li\n" + "@li @b values() @/b: All values of the properties with the given name (returns a list) @/li\n" + "@li @b @/b: A shortcut for 'value()' ( is used as a symbol) @/li\n" + "@/ul\n" + "\n" + "This feature has been introduced in version 0.30.3." ), "@hide" ); @@ -187,7 +212,9 @@ Class decl_EdgeFilterImpl (decl_EdgeFilterBase, "db", "Edge // --------------------------------------------------------------------------------- // EdgeProcessor binding -Class > decl_EdgeProcessorBase ("db", "EdgeOperator", +Class decl_EdgeProcessorBase ("db", "EdgeProcessorBase", "@hide"); + +Class > decl_EdgeOperator (decl_EdgeProcessorBase, "db", "EdgeOperator", shape_processor_impl::method_decls (true), "@brief A generic edge-to-polygon operator\n" "\n" @@ -232,7 +259,45 @@ Class > decl_EdgeProcessorBase ("db" "This class has been introduced in version 0.29.\n" ); -Class > decl_EdgeToPolygonProcessor ("db", "EdgeToPolygonOperator", +static +property_computation_processor * +new_pcp (const db::Edges *container, const std::map &expressions, bool copy_properties, double dbu) +{ + return new property_computation_processor (container, expressions, copy_properties, dbu); +} + +Class > decl_EdgePropertiesExpressions (decl_EdgeProcessorBase, "db", "EdgePropertiesExpressions", + property_computation_processor::method_decls (true) + + gsi::constructor ("new", &new_pcp, gsi::arg ("edges"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), + "@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" + ), + "@brief An operator attaching computed properties to the edges\n" + "\n" + "This operator will execute a number of expressions and attach the results as new properties. " + "The expression inputs can be taken either from the edges themselves or from existing properties.\n" + "\n" + "A number of expressions can be supplied with a name. The expressions will be evaluated and the result " + "is attached to the output edges as user properties with the given names.\n" + "The expression may use the following variables and functions:\n" + "\n" + "@ul\n" + "@li @b shape @/b: The current shape (i.e. 'Edge' without DBU specified or 'DEdge' otherwise) @/li\n" + "@li @b value() @/b: The value of the property with the given name (the first one if there are multiple properties with the same name) @/li\n" + "@li @b values() @/b: All values of the properties with the given name (returns a list) @/li\n" + "@li @b @/b: A shortcut for 'value()' ( is used as a symbol) @/li\n" + "@/ul\n" + "\n" + "This class has been introduced in version 0.30.3.\n" +); + +Class decl_EdgeToPolygonProcessorBase ("db", "EdgeToPolygonProcessorBase", "@hide"); + +Class > decl_EdgeToPolygonProcessor (decl_EdgeToPolygonProcessorBase, "db", "EdgeToPolygonOperator", shape_processor_impl::method_decls (true), "@brief A generic edge-to-polygon operator\n" "\n" @@ -256,7 +321,9 @@ Class > decl_EdgeToPolygonP "This class has been introduced in version 0.29.\n" ); -Class > decl_EdgeToEdgePairProcessor ("db", "EdgeToEdgePairOperator", +Class decl_EdgeToEdgePairProcessorBase ("db", "EdgeToEdgePairProcessorBase", "@hide"); + +Class > decl_EdgeToEdgePairProcessor (decl_EdgeToEdgePairProcessorBase, "db", "EdgeToEdgePairOperator", shape_processor_impl::method_decls (true), "@brief A generic edge-to-edge-pair operator\n" "\n" @@ -516,22 +583,22 @@ static std::vector split_filter (const db::Edges *r, const gsi::EdgeF return as_2edges_vector (r->split_filter (*f)); } -static db::Edges processed_ee (const db::Edges *r, const shape_processor_impl *f) +static db::Edges processed_ee (const db::Edges *r, const db::EdgeProcessorBase *f) { return r->processed (*f); } -static void process_ee (db::Edges *r, const shape_processor_impl *f) +static void process_ee (db::Edges *r, const db::EdgeProcessorBase *f) { r->process (*f); } -static db::EdgePairs processed_eep (const db::Edges *r, const shape_processor_impl *f) +static db::EdgePairs processed_eep (const db::Edges *r, const db::EdgeToEdgePairProcessorBase *f) { return r->processed (*f); } -static db::Region processed_ep (const db::Edges *r, const shape_processor_impl *f) +static db::Region processed_ep (const db::Edges *r, const db::EdgeToPolygonProcessorBase *f) { db::Region out; r->processed (out, *f); diff --git a/src/db/db/gsiDeclDbTexts.cc b/src/db/db/gsiDeclDbTexts.cc index 17a9563c9..96fd60a95 100644 --- a/src/db/db/gsiDeclDbTexts.cc +++ b/src/db/db/gsiDeclDbTexts.cc @@ -30,6 +30,7 @@ #include "dbPropertiesFilter.h" #include "gsiDeclDbContainerHelpers.h" +#include "gsiDeclDbMeasureHelpers.h" namespace gsi { @@ -86,6 +87,11 @@ 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) +{ + return new gsi::expression_filter (expression, inverse, dbu); +} + Class decl_TextFilterBase ("db", "TextFilterBase", gsi::TextFilterBase::method_decls (false) + gsi::constructor ("property_glob", &make_pg, gsi::arg ("name"), gsi::arg ("pattern"), gsi::arg ("inverse", false), gsi::arg ("case_sensitive", true), @@ -126,6 +132,25 @@ Class decl_TextFilterBase ("db", "TextFilterBase", "Apply this filter with \\Texts#filtered. See \\property_glob for an example.\n" "\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), + "@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" + "\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. " + "The expression may use the following variables and functions:\n" + "\n" + "@ul\n" + "@li @b shape @/b: The current shape (i.e. 'Text' without DBU specified or 'DText' otherwise) @/li\n" + "@li @b value() @/b: The value of the property with the given name (the first one if there are multiple properties with the same name) @/li\n" + "@li @b values() @/b: All values of the properties with the given name (returns a list) @/li\n" + "@li @b @/b: A shortcut for 'value()' ( is used as a symbol) @/li\n" + "@/ul\n" + "\n" + "This feature has been introduced in version 0.30.3." ), "@hide" ); @@ -182,7 +207,9 @@ Class decl_TextFilterImpl (decl_TextFilterBase, "db", "Text // --------------------------------------------------------------------------------- // TextProcessor binding -Class > decl_TextProcessor ("db", "TextOperator", +Class decl_TextProcessorBase ("db", "TextProcessorBase", "@hide"); + +Class > decl_TextProcessor (decl_TextProcessorBase, "db", "TextOperator", shape_processor_impl::method_decls (false), "@brief A generic text operator\n" "\n" @@ -227,7 +254,45 @@ Class > decl_TextProcessor ("db", "T "This class has been introduced in version 0.29.\n" ); -Class > decl_TextToPolygonProcessor ("db", "TextToPolygonOperator", +static +property_computation_processor * +new_pcp (const db::Texts *container, const std::map &expressions, bool copy_properties, double dbu) +{ + return new property_computation_processor (container, expressions, copy_properties, dbu); +} + +Class > decl_TextPropertiesExpressions (decl_TextProcessorBase, "db", "TextPropertiesExpressions", + property_computation_processor::method_decls (true) + + gsi::constructor ("new", &new_pcp, gsi::arg ("texts"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), + "@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" + ), + "@brief An operator attaching computed properties to the texts\n" + "\n" + "This operator will execute a number of expressions and attach the results as new properties. " + "The expression inputs can be taken either from the texts themselves or from existing properties.\n" + "\n" + "A number of expressions can be supplied with a name. The expressions will be evaluated and the result " + "is attached to the output texts as user properties with the given names.\n" + "The expression may use the following variables and functions:\n" + "\n" + "@ul\n" + "@li @b shape @/b: The current shape (i.e. 'Text' without DBU specified or 'DText' otherwise) @/li\n" + "@li @b value() @/b: The value of the property with the given name (the first one if there are multiple properties with the same name) @/li\n" + "@li @b values() @/b: All values of the properties with the given name (returns a list) @/li\n" + "@li @b @/b: A shortcut for 'value()' ( is used as a symbol) @/li\n" + "@/ul\n" + "\n" + "This class has been introduced in version 0.30.3.\n" +); + +Class decl_TextToPolygonProcessorBase ("db", "TextToPolygonProcessorBase", "@hide"); + +Class > decl_TextToPolygonProcessor (decl_TextToPolygonProcessorBase, "db", "TextToPolygonOperator", shape_processor_impl::method_decls (false), "@brief A generic text-to-polygon operator\n" "\n" @@ -407,17 +472,17 @@ static std::vector split_filter (const db::Texts *r, const TextFilter return as_2texts_vector (r->split_filter (*f)); } -static db::Texts processed_tt (const db::Texts *r, const shape_processor_impl *f) +static db::Texts processed_tt (const db::Texts *r, const db::TextProcessorBase *f) { return r->processed (*f); } -static void process_tt (db::Texts *r, const shape_processor_impl *f) +static void process_tt (db::Texts *r, const db::TextProcessorBase *f) { r->process (*f); } -static db::Region processed_tp (const db::Texts *r, const shape_processor_impl *f) +static db::Region processed_tp (const db::Texts *r, const db::TextToPolygonProcessorBase *f) { db::Region out; r->processed (out, *f);