Skip to content

Commit 5ff1155

Browse files
committed
Small improvements:
- Remove old invalid comment - Improve MVR writing example - Change export XML declaration - Add missing Source XML export to MappingDefinition - Remove unused export attributes from Data()
1 parent ba8b0bf commit 5ff1155

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ mvr_writer = pymvr.GeneralSceneDescriptionWriter()
6969
# 3. Serialize the scene object into the writer's XML root
7070
mvr_read.scene.to_xml(parent=mvr_writer.xml_root)
7171

72-
# 4. Add necesarry files like GDTF fixtures, trusses, 3D objects and so on
72+
# 4. Serialize the user_data object into the writer's XML root
73+
mvr_read.user_data.to_xml(parent=mvr_writer.xml_root)
74+
75+
# 5. Add necesarry files like GDTF fixtures, trusses, 3D objects and so on
7376
# Skipped in this example
7477

75-
# 5. Write the MVR file
78+
# 6. Write the MVR file
7679
output_path = Path("exported_mvr_file.mvr")
7780
mvr_writer.write_mvr(output_path)
7881
```

pymvr/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
8080
class GeneralSceneDescriptionWriter:
8181
"""Creates MVR zip archive with packed GeneralSceneDescription xml and other files"""
8282

83-
# Currently, MVR creation is manual, outside of the library.
84-
# The to_xml() often takes a parent and then creates a ElementTree.SubElement.
85-
# For complete, automatic conversion of an mvr object to xml, we need to adjust all the to_xml methods
86-
8783
def __init__(self):
8884
self.version_major: str = "1"
8985
self.version_minor: str = "6"
@@ -103,7 +99,7 @@ def write_mvr(self, path: Optional[str] = None):
10399
if sys.version_info >= (3, 9):
104100
ElementTree.indent(self.xml_root, space=" ", level=0)
105101
xmlstr = ElementTree.tostring(
106-
self.xml_root, encoding="unicode", xml_declaration=True
102+
self.xml_root, encoding="UTF-8", xml_declaration=True
107103
)
108104
with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as z:
109105
z.writestr("GeneralSceneDescription.xml", xmlstr)
@@ -648,7 +644,6 @@ def __str__(self):
648644
return f"{self.provider} {self.ver}"
649645

650646
def to_xml(self):
651-
attributes = {"name": self.name, "uuid": self.uuid}
652647
return ElementTree.Element(
653648
type(self).__name__, provider=self.provider, ver=self.ver
654649
)
@@ -742,9 +737,10 @@ def to_xml(self):
742737
)
743738
ElementTree.SubElement(element, "SizeX").text = str(self.size_x)
744739
ElementTree.SubElement(element, "SizeY").text = str(self.size_y)
740+
if self.source:
741+
element.append(self.source.to_xml())
745742
if self.scale_handling:
746743
self.scale_handling.to_xml(element)
747-
# TODO source
748744
return element
749745

750746

0 commit comments

Comments
 (0)