omf-python icon indicating copy to clipboard operation
omf-python copied to clipboard

Can't use `reader.get_project(uids)` multiple times

Open WesleyTheGeolien opened this issue 2 years ago • 0 comments

Calling get_project with uids mutates the project_elments in fileio.get_project on v1.0.1 this line is the culprit as copy is a shallow copy and not a deepcopy project_json = self._project_json.copy() proposed solution would be to:

import copy
copy.deepcopy(self.project_json)

MRE:

import omf

pts = omf.PointSetElement(
            name=f'Points',
            geometry=omf.PointSetGeometry(
                vertices=np.array([0,0,0])
            ),
        )

pts1 = omf.PointSetElement(
            name=f'Points',
            geometry=omf.PointSetGeometry(
                vertices=np.array([1,1,1])
            ),
        )

proj = omf.Project()
proj.elements = [pts, pts1]

omf.OMFWriter(proj, "test.omf")

reader = omf.OMFReader("test.omf")
print(reader._project_json[reader._uid]['elements'])

first_element_uid = str(reader.get_project_overview().elements[0].uid)
print(first_element_uid)
reader.get_project([first_element_uid])
print(reader._project_json[reader._uid]['elements'])

Happy to put in a PR just not sure how it works seeing it is on v1.0.1 is v1.0.2 (bug fix) on the road map or only v2.X in dev?

WesleyTheGeolien avatar Apr 12 '23 12:04 WesleyTheGeolien