elrnv / vtkio

Visualization ToolKit (VTK) file parser and writer
Apache License 2.0
57 stars 13 forks source link

Improve version handling #12

Closed elrnv closed 1 year ago

elrnv commented 3 years ago

Currently the version in the Vtk type represents the version for both XML and Legacy formats, which have independent versioning.

The problem is that a legacy file loaded as Vtk will be written with an incorrect version in XML and vice versa, unless the user explicitly updates the version. This is bad for usability because it puts the burden of learning about vtk versions on the user and forces people to have to handle these cases explicitly.

In the majority of cases, versioning should be handled automatically, and overridden if needed.

The current proposal to resolve this is to refactor version to be an enum as follows:

enum Version {
    /// Automatically handle versioning on write for both Legacy and XML formats.
    Auto,
    /// Loaded Legacy format with this version. Writing in XML format is handled as with the `Auto` variant.
    Legacy { major: u32, minor: u32 },
    /// Loaded XML format with this version. Writing in Legacy is handled as with the `Auto` variant.
    XML { major: u32, minor: u32 },
}

The rules for writing should be such be that the minimum compatible version is used for both Legacy and XML format. The implementer should consult the VTK docs for this. The automatic behaviour should be clearly documented in the code and updated whenever a newer VTK feature is added.