From 9cd77e5cec3868ce1d18b945c6833547dc60e569 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 25 Dec 2021 18:03:30 +0100 Subject: [PATCH] WIP: expose a new method of PCellDeclaration called 'wants_lazy_evaluation' --- src/db/db/dbPCellDeclaration.h | 11 +++++++++ src/db/db/gsiDeclDbLibrary.cc | 26 ++++++++++++++++++++ src/edt/edt/edtPCellParametersPage.cc | 2 +- src/lay/lay/macro_templates/pcell.lym | 7 ++++++ src/lay/lay/macro_templates/pcell_python.lym | 6 +++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/db/db/dbPCellDeclaration.h b/src/db/db/dbPCellDeclaration.h index acd4d12c9..c354b12a7 100644 --- a/src/db/db/dbPCellDeclaration.h +++ b/src/db/db/dbPCellDeclaration.h @@ -429,6 +429,17 @@ public: return db::Trans (); } + /** + * @brief Returns a value indicating that the PCell wants lazy evaluation + * + * In lazy evaluation mode, the PCell is not immediately updated when a parameter is changed in the UI, but only when it is requested + * to be updated. + */ + virtual bool wants_lazy_evaluation () const + { + return false; + } + /** * @brief Gets the Layout object the PCell is registered inside or NULL if it is not registered */ diff --git a/src/db/db/gsiDeclDbLibrary.cc b/src/db/db/gsiDeclDbLibrary.cc index 0d6570bef..fc2ea5ed6 100644 --- a/src/db/db/gsiDeclDbLibrary.cc +++ b/src/db/db/gsiDeclDbLibrary.cc @@ -276,6 +276,7 @@ Class decl_PCellDeclaration_Native ("db", "PCellDeclaratio gsi::method ("can_create_from_shape", &db::PCellDeclaration::can_create_from_shape) + gsi::method ("parameters_from_shape", &db::PCellDeclaration::parameters_from_shape) + gsi::method ("transformation_from_shape", &db::PCellDeclaration::transformation_from_shape) + + gsi::method ("wants_lazy_evaluation", &db::PCellDeclaration::wants_lazy_evaluation) + gsi::method ("display_text", &db::PCellDeclaration::get_display_name) + gsi::method ("layout", &db::PCellDeclaration::layout, "@brief Gets the Layout object the PCell is registered in or nil if it is not registered yet.\n" @@ -407,6 +408,20 @@ public: } } + bool wants_lazy_evaluation_fb () const + { + return db::PCellDeclaration::wants_lazy_evaluation (); + } + + virtual bool wants_lazy_evaluation () const + { + if (cb_wants_lazy_evaluation.can_issue ()) { + return cb_wants_lazy_evaluation.issue (&db::PCellDeclaration::wants_lazy_evaluation); + } else { + return db::PCellDeclaration::wants_lazy_evaluation (); + } + } + std::string get_display_name_fb (const db::pcell_parameters_type ¶meters) const { return db::PCellDeclaration::get_display_name (parameters); @@ -427,6 +442,7 @@ public: gsi::Callback cb_can_create_from_shape; gsi::Callback cb_parameters_from_shape; gsi::Callback cb_transformation_from_shape; + gsi::Callback cb_wants_lazy_evaluation; gsi::Callback cb_coerce_parameters; gsi::Callback cb_get_display_name; }; @@ -507,6 +523,16 @@ Class decl_PCellDeclaration (decl_PCellDeclaration_Native, "it will use this method to derive the transformation for the PCell instance that will replace the shape. " "See also \\parameters_from_shape and \\can_create_from_shape." ) + + gsi::callback ("wants_lazy_evaluation", &PCellDeclarationImpl::wants_lazy_evaluation, &PCellDeclarationImpl::cb_wants_lazy_evaluation, + "@brief Gets a value indicating whether the PCell wants lazy evaluation\n" + "In lazy evaluation mode, the PCell UI will not immediately update the layout when a parameter is changed. " + "Instead, the user has to commit the changes in order to have the parameters updated. This is " + "useful for PCells that take a long time to compute.\n" + "\n" + "The default implementation will return 'false' indicating immediate updates.\n" + "\n" + "This method has been added in version 0.27.6.\n" + ) + gsi::callback ("display_text", &PCellDeclarationImpl::get_display_name, &PCellDeclarationImpl::cb_get_display_name, gsi::arg ("parameters"), "@brief Returns the display text for this PCell given a certain parameter set\n" "Reimplement this method to create a distinct display text for a PCell variant with \n" diff --git a/src/edt/edt/edtPCellParametersPage.cc b/src/edt/edt/edtPCellParametersPage.cc index 2fc7a4a12..84b624ebe 100644 --- a/src/edt/edt/edtPCellParametersPage.cc +++ b/src/edt/edt/edtPCellParametersPage.cc @@ -227,7 +227,7 @@ PCellParametersPage::init () bool PCellParametersPage::lazy_evaluation () { - return false; // @@@ + return mp_pcell_decl.get () && mp_pcell_decl->wants_lazy_evaluation (); } void diff --git a/src/lay/lay/macro_templates/pcell.lym b/src/lay/lay/macro_templates/pcell.lym index e3665c365..31ed9240f 100644 --- a/src/lay/lay/macro_templates/pcell.lym +++ b/src/lay/lay/macro_templates/pcell.lym @@ -71,6 +71,13 @@ module PCellLibModule # TODO: return a RBA::Trans object for the initial transformation of # the instance # end + # + # optional: + # def wants_lazy_evaluation + # TODO: return "true" here if the PCell takes a long time to compute. + # In lazy mode, the user has to acknowledge parameter changes before + # they are executed. + # end end diff --git a/src/lay/lay/macro_templates/pcell_python.lym b/src/lay/lay/macro_templates/pcell_python.lym index d3f0b9f17..2d7e3c334 100644 --- a/src/lay/lay/macro_templates/pcell_python.lym +++ b/src/lay/lay/macro_templates/pcell_python.lym @@ -54,6 +54,12 @@ class PCell(pya.PCellDeclarationHelper): # def transformation_from_shape_impl(self): # TODO: return a RBA::Trans object for the initial transformation of # the instance + # + # optional: + # def wants_lazy_evaluation(self): + # TODO: return "True" here if the PCell takes a long time to compute. + # In lazy mode, the user has to acknowledge parameter changes before + # they are executed. # TODO: add more PCell classes ..