Muscat.Helpers.Factory module

CheckIntegrity(GUI: bool = False) str[source]
class Factory[source]

Bases: object

Base class to build custom factories str -> object instance To use this factory you must create a class like this

def RegisterClass(name, classType, constructor=None, withError = True):

return ImplicitGeometryFactory.RegisterClass(name,classType, constructor=constructor, withError = withError )

def Create(name,ops=None):

return ImplicitGeometryFactory.Create(name,ops)

class ImplicitGeometryFactory(Factory):

_Catalog = {} _SetCatalog = set()

def __init__(self):

super().__init__()

And use the functions to register and create objects

RegisterClass(“Offset”,ImplicitGeometryOffset,CreateImplicitGeometryOffset)

or (with a special constructor)

RegisterClass(“Offset”,ImplicitGeometryOffset)

And to create a class

res = Create(name,ops)

classmethod AllEntries() Set[source]

Return the internal set containing all the entries in the form : (key, class, constructor) := Tuple[str,Type,Callable[[Dict],Any]]

classmethod Create(name: str, ops: Dict | None = None, propertiesAssign: bool = True) Any[source]

Create a instance of a class associated to the key name

Parameters:
  • name (str) – the key

  • ops (Optional[Dict], optional) – options in the form of a dict to pass to the constructor, by default None

  • propertiesAssign (bool, optional) – if the class constructor is None and propertiesAssign is True then use ParserHelpers.ReadProperties to push the data into the object, by default True

Returns:

an instance of a the type associated to the key name

Return type:

Any

classmethod GetAvailableFor(name: str) List[Tuple[Type, Callable[[Dict], Any]]][source]

Return the list of all the entries associated to the key name

Parameters:

name (str) – the key

Returns:

the list of (class, constructors)

Return type:

List[Tuple[Type,Callable[[Dict],Any]]]

classmethod GetClass(name: str) Type[source]

Return the class associated to name

Parameters:

name (str) – the key

Returns:

the type

Return type:

Type

classmethod GetConstructor(name: str) Callable[[Dict], Any][source]

Return the constructor associated to name

Parameters:

name (str) – the key

Returns:

the constructor

Return type:

Callable[[Dict],Any]

classmethod PrintAvailable(fullDetails: bool = False) None[source]

print all the available entries in the factory

Parameters:

fullDetails (bool, optional) – True to print the docstring of every class, by default False

classmethod RegisterClass(name: str, classType: Type, constructor: Callable[[Dict], Any] | None = None, withError: bool = True) None[source]

Register a class and a constructor using the string name

Parameters:
  • name (str) – key to retrieve the instances of classType

  • classType (Type) – A type of a class

  • constructor (callable[[Dict],Any], optional) – the constructor , by default None

  • withError (bool, optional) – if false then the user can override a existent class/constructor , by default True

classmethod keys() Iterable[str][source]

Recover the keys (str) for all the object in the factor

Returns:

key entries

Return type:

Iterable[str]