From 8d7919e0549952964a2c61585c79eed1c09e24f2 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 28 Jul 2025 22:38:44 +0200 Subject: [PATCH] WIP --- src/db/db/gsiDeclDbMeasureHelpers.cc | 67 +++++++++++++++++++++------- src/db/db/gsiDeclDbMeasureHelpers.h | 11 ++--- src/db/db/gsiDeclDbRegion.cc | 18 ++++---- 3 files changed, 66 insertions(+), 30 deletions(-) diff --git a/src/db/db/gsiDeclDbMeasureHelpers.cc b/src/db/db/gsiDeclDbMeasureHelpers.cc index 1d2133719..06998cc86 100644 --- a/src/db/db/gsiDeclDbMeasureHelpers.cc +++ b/src/db/db/gsiDeclDbMeasureHelpers.cc @@ -117,8 +117,8 @@ private: // -------------------------------------------------------------------- // MeasureEval implementation -MeasureEval::MeasureEval () - : m_shape_type (None), m_prop_id (0) +MeasureEval::MeasureEval (double dbu) + : m_shape_type (None), m_prop_id (0), m_dbu (dbu) { mp_shape.any = 0; } @@ -196,21 +196,54 @@ MeasureEval::resolve_name (const std::string &name, const tl::EvalFunction *&fun tl::Variant MeasureEval::shape_func () const { - switch (m_shape_type) - { - case None: - default: - return tl::Variant (); - case Polygon: - return tl::Variant (mp_shape.poly); - case PolygonRef: - return tl::Variant (mp_shape.poly_ref); - case Edge: - return tl::Variant (mp_shape.edge); - case EdgePair: - return tl::Variant (mp_shape.edge_pair); - case Text: - return tl::Variant (mp_shape.text); + if (m_dbu > 1e-10) { + + db::CplxTrans tr (m_dbu); + + switch (m_shape_type) + { + case None: + default: + return tl::Variant (); + case Polygon: + return tl::Variant (tr * *mp_shape.poly); + case PolygonRef: + { + db::Polygon poly; + mp_shape.poly_ref->instantiate (poly); + return tl::Variant (tr * poly); + } + case Edge: + return tl::Variant (tr * *mp_shape.edge); + case EdgePair: + return tl::Variant (tr * *mp_shape.edge_pair); + case Text: + return tl::Variant (tr * *mp_shape.text); + } + + } else { + + switch (m_shape_type) + { + case None: + default: + return tl::Variant (); + case Polygon: + return tl::Variant (*mp_shape.poly); + case PolygonRef: + { + db::Polygon poly; + mp_shape.poly_ref->instantiate (poly); + return tl::Variant (poly); + } + case Edge: + return tl::Variant (*mp_shape.edge); + case EdgePair: + return tl::Variant (*mp_shape.edge_pair); + case Text: + return tl::Variant (*mp_shape.text); + } + } } diff --git a/src/db/db/gsiDeclDbMeasureHelpers.h b/src/db/db/gsiDeclDbMeasureHelpers.h index b28e0b5b2..5fd8f4363 100644 --- a/src/db/db/gsiDeclDbMeasureHelpers.h +++ b/src/db/db/gsiDeclDbMeasureHelpers.h @@ -48,7 +48,7 @@ class DB_PUBLIC MeasureEval : public tl::Eval { public: - MeasureEval (); + MeasureEval (double dbu); void init (); @@ -92,6 +92,7 @@ private: mutable ShapeType m_shape_type; mutable ShapeRef mp_shape; mutable db::properties_id_type m_prop_id; + double m_dbu; tl::Variant shape_func () const; tl::Variant value_func (db::property_names_id_type name_id) const; @@ -162,8 +163,8 @@ public: typedef typename ProcessorBase::shape_type shape_type; typedef typename ProcessorBase::result_type result_type; - property_computation_processor (const Container *container, const std::map &expressions, bool copy_properties) - : m_eval (), m_copy_properties (copy_properties), m_expression_strings (expressions) + property_computation_processor (const Container *container, const std::map &expressions, bool copy_properties, double dbu) + : m_eval (dbu), m_copy_properties (copy_properties), m_expression_strings (expressions) { if (container) { this->set_result_is_merged (is_merged (container)); @@ -222,8 +223,8 @@ class expression_filter public: typedef typename FilterBase::shape_type shape_type; - expression_filter (const std::string &expression, bool inverse) - : m_eval (), m_inverse (inverse), m_expression_string (expression) + expression_filter (const std::string &expression, bool inverse, double dbu) + : m_eval (dbu), m_inverse (inverse), m_expression_string (expression) { m_eval.init (); diff --git a/src/db/db/gsiDeclDbRegion.cc b/src/db/db/gsiDeclDbRegion.cc index bc5b3adbf..3347b9c79 100644 --- a/src/db/db/gsiDeclDbRegion.cc +++ b/src/db/db/gsiDeclDbRegion.cc @@ -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) +static gsi::PolygonFilterBase *make_pe (const std::string &expression, bool inverse, double dbu) { - return new gsi::expression_filter (expression, inverse); + return new gsi::expression_filter (expression, inverse, dbu); } Class decl_PolygonFilterBase ("db", "PolygonFilterBase", @@ -155,17 +155,18 @@ Class 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::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 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" "\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 @/li\n" + "@li @b shape @/b: The current shape (i.e. 'Polygon' without DBU specified or 'DPolygon' 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" @@ -276,19 +277,20 @@ Class > decl_PolygonOperator (dec static property_computation_processor * -new_pcp (const db::Region *container, const std::map &expressions, bool copy_properties) +new_pcp (const db::Region *container, const std::map &expressions, bool copy_properties, double dbu) { - return new property_computation_processor (container, expressions, copy_properties); + return new property_computation_processor (container, expressions, copy_properties, dbu); } Class > decl_PolygonPropertiesExpressions (decl_PolygonProcessorBase, "db", "PolygonPropertiesExpressions", property_computation_processor::method_decls (true) + - gsi::constructor ("new", &new_pcp, gsi::arg ("region"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), + gsi::constructor ("new", &new_pcp, gsi::arg ("region"), gsi::arg ("expressions"), gsi::arg ("copy_properties", false), gsi::arg ("dbu", 0.0), "@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" ), "@brief An operator attaching computed properties to the polygons\n" "\n" @@ -300,7 +302,7 @@ Class > dec "The expression may use the following variables and functions:\n" "\n" "@ul\n" - "@li @b shape @/b: The current shape @/li\n" + "@li @b shape @/b: The current shape (i.e. 'Polygon' without DBU specified or 'DPolygon' 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"