Fusion-Power-Plant-Framework / bluemira

Bluemira is an integrated inter-disciplinary design tool for future fusion reactors. It incorporates several modules, some of which rely on other codes, to carry out a range of typical conceptual fusion reactor design activities.
https://bluemira.readthedocs.io/
GNU Lesser General Public License v2.1
64 stars 16 forks source link

Implement a serialize/deserialize function for geometry objects #97

Open ivanmaione opened 3 years ago

ivanmaione commented 3 years ago

Is your feature request related to a problem? Please describe. In the present implementation of bluemira it is not possible to extract curve parameters (e.g. start and end points of a line, or poles of a bezier curve) without accessing directly the freecad object. I would like to have a method that interfaces with freecad and serialize/deserialize bluemira geometry objects.

Describe the solution you'd like Implement in _freecadapi.py and tools.py a set of methods that extract wire's curve parameters from the freecad object. These methods should return a dictionary with all the information necessary to restore the initial object.

Describe alternatives you've considered Instead of using a dictionary, it would also have been possible to create a set of bluemira primitive classes (e.g. Line, Circle, BSpline, Bezier, etc.) in which essential primitive information is stored. Serialize and Deserialize methods would have been then added to such classes. However, the time requested for such implementation could take more time.

Additional context

DanShort12 commented 3 years ago

Sounds good to me. I think that the dictionaries are a reasonable solution for representing the parameters for a CAD primitive. Will the serialisation/deserialisation also handle the rest of the BluemiraGeo properties so that the whole object can be treated as a dictionary (or json) or is the intention just to serialise/deserialise the _shape part?

ivanmaione commented 3 years ago

The methods have been proposed only for the _shape part but, using the same dictionary strategy, it should be almost easy to extend it to a BluemiraGeo instance (added in the additional context). For the moment I am only going to define the serialize/deserialize as class methods (e.g. BluemiraGeo.serialize()) that return/"eat" a simple dict. Not going to implement a json interface. That should be common to all the serializable object... out of the scope of this proposal. Is it fine for you, @DanShort12 ?

DanShort12 commented 3 years ago

Yep, fine for me to just handle the _shape part and to just use a dict for now. I think it's worth extending the implementation at some point to work for the full BluemiraGeo objects and to allow them to be read / written from / to json (that gives us an equivalent level of serialisation to what is available in BLUEPRINT), so I'll put in a couple of follow up issues.

CoronelBuendia commented 2 years ago

As discussed with @ivanmaione: we only treat Wire at present. Leaving this open