ESBO-ETC/esbo_etc/classes/target/TargetFactory.py

51 lines
1.5 KiB
Python
Raw 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 .ATarget import ATarget
2020-09-10 15:03:57 +02:00
from ...classes import target as tg
from ...lib.logger import logger
class TargetFactory(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) -> ATarget:
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 : ATarget
The created target object
2020-09-10 15:03:57 +02:00
"""
2020-09-12 11:51:49 +02:00
2020-09-10 15:03:57 +02:00
if parent is None:
2020-09-12 11:51:49 +02:00
opts = self.collectOptions(options)
2020-09-10 15:03:57 +02:00
opts["wl_bins"] = self._common_conf.wl_bins.val
2020-09-12 11:51:49 +02:00
if hasattr(tg, options.type):
class_ = getattr(tg, options.type)
return class_(**opts)
2020-09-10 15:03:57 +02:00
else:
logger.error("Unknown target type: '" + options.type + "'")
else:
logger.error("No parent object allowed for target.")