ladybug-tools / honeybee-core

:honeybee: honeybee core library
https://www.ladybug.tools/honeybee-core/docs/
GNU Affero General Public License v3.0
14 stars 14 forks source link

Discussion: Model Scale/Rotate/Reflect Propogate to Extensions? #541

Closed ed-p-may closed 1 year ago

ed-p-may commented 1 year ago

I am running into a new question and I wonder about your thoughts?

Scenario:

A user builds a Rhino / Honeybee Model in IP units and writes out the model to HBJSON. Outside Rhino the user reads the file in, and then calls convert_to_units() or scale to change the model units to SI. At that point, if any extensions (such as Honeybee-PH) include any dimensional values, these do not get changed. So the user might end up with a Model in meters, but extension elements still in inches (or whatever they were built in).

So: I wonder how you would feel about adding a scale() function to model.properties, which then only calls out to any property extensions whenever Model's scale / rotate / reflect functions get called? So maybe roughly something like:

model:

def scale(self, factor, origin=None):
    ... # existing code...
    self.properties.scale()

model.properties:

def scale(self, factor, origin=None)
    for extension_prefix in self._extension_attributes:
        ext = getattr(self, extension_prefix)
        try:
            ext.scale()
        except AttributeError:
            pass

The goal being just to ping any extensions and say "hey: we're scaling" (or rotating, or reflecting, ...) and then if the extension wants to do anything with that, fine, or if not: fine. But at least to let them know somehow? So kind of similar to the way that properties' to_dict and from_dict call out to extensions during their operation?

Alternatively, perhaps there is a way to let extensions subscribe to a messaging protocol to get informed about these types of changes?

ed-p-may commented 1 year ago

Whoops - never mind, realizing now that this is already implemented! Don't know how I missed that at first....