ESBO-ETC/esbo_etc/classes/optical_component/OpticalComponentFactory.py

82 lines
3.1 KiB
Python
Raw Permalink Normal View History

from ..ARadiantFactory import ARadiantFactory
2020-09-10 15:03:57 +02:00
from ..Entry import Entry
from ..IRadiant import IRadiant
2020-09-10 15:31:07 +02:00
from .AOpticalComponent import AOpticalComponent
2020-09-10 15:03:57 +02:00
from ...classes import optical_component as oc
from ...lib.logger import logger
class OpticalComponentFactory(ARadiantFactory):
2020-09-10 15:03:57 +02:00
"""
A Factory creating objects of the type IRadiant
"""
def __init__(self, common_conf: Entry):
"""
Instantiate a new factory object
Parameters
----------
common_conf : Entry
The common configuration of the configuration file
"""
super().__init__(common_conf)
2020-09-10 15:31:07 +02:00
def create(self, options: Entry, parent: IRadiant = None) -> AOpticalComponent:
2020-09-10 15:03:57 +02:00
"""
Create a new object of the type IRadiant
Parameters
----------
options : Entry
The options to be used as parameters for the instantiation of the new object.
parent : IRadiant
The optional parent element of the object (necessary for subclasses of AOpticalComponent).
Returns
-------
2020-09-10 15:31:07 +02:00
obj : AOpticalComponent
The created optical component
2020-09-10 15:03:57 +02:00
"""
if parent is not None:
2020-09-12 11:51:49 +02:00
opts = self.collectOptions(options)
2020-09-10 15:03:57 +02:00
opts["parent"] = parent
2020-09-12 11:51:49 +02:00
if hasattr(oc, options.type):
class_ = getattr(oc, options.type)
2020-09-10 15:03:57 +02:00
return class_(**opts)
else:
logger.error("Unknown optical component type: '" + options.type + "'")
else:
2020-09-12 11:51:49 +02:00
logger.error("Parent object is required for optical component.")
2020-09-10 15:03:57 +02:00
2020-09-10 15:31:07 +02:00
def fromConfigBatch(self, conf: Entry, parent: IRadiant) -> AOpticalComponent:
2020-09-10 15:03:57 +02:00
"""
Initialize a decorated target from a configuration.
Parameters
----------
conf : Entry
The configuration defining the target and the decorators.
parent : IRadiant
The optional parent element of the object
Returns
-------
2020-09-10 15:31:07 +02:00
parent : AOpticalComponent
2020-09-10 15:03:57 +02:00
The decorated parent object.
"""
if hasattr(conf.astroscene, "optical_component"):
for entry in conf.astroscene.optical_component if type(conf.astroscene.optical_component) == list else\
[conf.astroscene.optical_component]:
parent = self.create(entry, parent)
if hasattr(conf, "common_optics") and hasattr(conf.common_optics, "optical_component"):
for entry in conf.common_optics.optical_component if type(conf.common_optics.optical_component) == \
list else [conf.common_optics.optical_component]:
if isinstance(entry, Entry):
parent = self.create(entry, parent)
if hasattr(conf, "instrument") and hasattr(conf.instrument, "optical_component"):
for entry in conf.instrument.optical_component if type(conf.instrument.optical_component) == list else\
[conf.instrument.optical_component]:
if isinstance(entry, Entry):
parent = self.create(entry, parent)
return parent