From a82781e6b157a254228d4130930405021c46d56b Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 7 Feb 2024 23:31:13 +0000 Subject: [PATCH] cq_toplevel: don't assume as_assy=True; some consumers need a single object --- cq_toplevel.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cq_toplevel.py b/cq_toplevel.py index 2ed58e0..edca2e4 100755 --- a/cq_toplevel.py +++ b/cq_toplevel.py @@ -67,7 +67,7 @@ def export_png_image(obj, file_: str, orientation: str): exporter.Write() -def _model(): +def _model(as_assy: bool=False): logger.info("computing model ...") render_phone = os.environ.get("CASE_RENDER_PHONE", "") not in ("", "0") render_phone_only = os.environ.get("CASE_RENDER_PHONE_ONLY", "") not in ("", "0") @@ -78,15 +78,15 @@ def _model(): return case.orient_for_printing(phone) battery = ldtek_battery.LdtekBattery() - return case.case(phone, battery=battery, render_phone=render_phone) + return case.case(phone, battery=battery, render_phone=render_phone, as_assy=as_assy) -_computedModel = None -def model(): +_computedModels = {} +def model(as_assy: bool=False): """ memoized wrapper around `_model` """ - global _computedModel - if _computedModel is None: - _computedModel = _model() - return _computedModel + global _computedModels + if as_assy not in _computedModels: + _computedModels[as_assy] = _model(as_assy=as_assy) + return _computedModels[as_assy] def main(): logging.basicConfig() @@ -121,7 +121,7 @@ def main(): orientation = "back" if "front" in args.export_png: orientation = "front" - model_ = model() + model_ = model(as_assy=True) logger.info("exporting png to %s", args.export_png) export_png_image(model_, args.export_png, orientation)