Skip to content

Allow custom classes to utilise the GeometryMaker.parse_json method #66

@lukethehuman

Description

@lukethehuman

It is possible to instantiate a GeometryMaker directly from a JSON file, by parsing which class the JSON file describes. Hypnos contains a mapping between classname strings and classes, telling the GeometryMaker which class to use.

This only works for built-in Component and Assembly classes, as user-controlled custom classes have no such mapping. To tell a GeometryMaker instance about custom classes, the following must be done:

json_file = "path/to/file.json"

my_custom_class = MyCustomClass(json_file)

maker = GeometryMaker()
maker.constructed_geometry = [my_custom_class]

To bring the custom class workflow more in line with the built-in class workflow, it would be better to be able to tell the GeometryMaker about custom classes during initialisation, and then read-in the JSON file in the same way, like so:

json_file = "path/to/file.json"

maker = GeometryMaker(custom_class=MyCustomClass)
maker.parse_json(json_file)

Some consideration will be required as to the best way to implement this feature in a general enough way to support any number and combination of custom objects. We may also want to consider whether and how to check that custom objects are legitimate, perhaps by checking that they are instances of the built-in base classes.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions