EnEff-BIM / EnEffBIM-Framework

translating from BIM to BEPS
MIT License
8 stars 0 forks source link

Include type Conversion in getter Methods #62

Closed PRemmen closed 9 years ago

PRemmen commented 9 years ago

We should include the type conversion directly into the getter methods, so the user does not need to take care of that

PRemmen commented 9 years ago

@math-boy is the reason why you save unmapped components into a list, because there might be Many To One mapping?

math-boy commented 9 years ago

Yeah, we have a mapping rule named many2one. So I use a container to save all the unmapped components.

From: Peter Remmen [mailto:notifications@github.com] Sent: Monday, September 07, 2015 11:42 AM To: EnEff-BIM/EnEffBIM-Framework Cc: Cao, Jun Subject: Re: [EnEffBIM-Framework] Include type Conversion in getter Methods (#62)

@math-boyhttps://github.com/math-boy is the reason why you save unmapped components into a list, because there might be Many To One mapping?

— Reply to this email directly or view it on GitHubhttps://github.com/EnEff-BIM/EnEffBIM-Framework/issues/62#issuecomment-138252383.

TobiasMaile commented 9 years ago

@PRemmen @math-boy can you both post a small code snippet, so I can better understand how we are currently dealing with this issue. Then we can discuss this on Wednesday.

Thanks.

Tobias

PRemmen commented 9 years ago

In the Python Wrapper we have a function in the SimSystem() Class:

    def typeConversion(self):
        if self._dataType == None:
            self._dataType = self.getDataType()
        return getattr(self, self._dataType)()

dataType is a string we recieve from SimModel (e.g. "toBoilerHotWater") I guess this is a string @math-boy added to each used component. With this string we call the corresponding Function in SimSystem() CLass on Python Side for Type Conversion:

def toBoilerHotWater(self):
        return lib.sim_system_to_boiler_hotwater(self.obj)

The advantage is that we can use this function to directly convert classes to the correct SimInstance, so the user does not have to take care of this.

    @property
    def unmappedComponent(self):
        if self._unmappedComponent == None:
            self._unmappedComponent = []
            for id in  range(lib.component_get_unmapped_component_number(self.obj)):
                self._unmappedComponent.append(lib.component_get_unmapped_component(self.obj, id).**typeConversion()**)
        return self._unmappedComponent

This will return e.g. a SimBoilerHotWater

The disadvantage is, that the string "toBoilerHotWater" is propbably not in SimModel or SimXML, or is there a corresponding type conversion in SimModel?

math-boy commented 9 years ago

@PRemmen Yes, in SimXML, we store the root type and sub type of each element. Later we can use this info to generate the corresponding conversion string for Python.