BIM: Use labels in DAE export

Signed-off-by: Gaël Écorchard <gael@km-robotics.cz>
This commit is contained in:
Gaël Écorchard
2024-09-28 21:36:34 +02:00
parent 27c786fef1
commit 281d112bea

View File

@@ -34,6 +34,7 @@ __url__ = "https://www.freecad.org"
import os
from typing import Optional
from xml.sax.saxutils import escape as sax_escape
import numpy as np
@@ -56,6 +57,17 @@ else:
DEBUG = True
def xml_escape(text: str, entities: dict[str, str] = None) -> str:
"""Escape text for XML.
This is a wrapper around xml.sax.saxutils.escape that replaces also
`"` with `&quot;` by default.
"""
if entities is None:
entities = {'"': "&quot;"}
return sax_escape(text, entities=entities)
def check_collada_import() -> bool:
"""Return True if the `collada` module is available.
@@ -207,12 +219,13 @@ def export(
author = FreeCAD.ActiveDocument.CreatedBy
except UnicodeEncodeError:
author = FreeCAD.ActiveDocument.CreatedBy.encode("utf8")
author = author.replace("<", "")
author = author.replace(">", "")
author = xml_escape(author)
col_contributor.author = author
ver = FreeCAD.Version()
appli = f"FreeCAD v{ver[0]}.{ver[1]} build {ver[2]}"
col_contributor.authoring_tool = appli
# Bug in collada from 0.4 to 0.9, contributors are not written to file.
# Set it anyway for future versions.
col_mesh.assetInfo.contributors.append(col_contributor)
col_mesh.assetInfo.unitname = "meter"
col_mesh.assetInfo.unitmeter = 1.0
@@ -269,7 +282,7 @@ def export(
geom = collada.geometry.Geometry(
collada=col_mesh,
id=f"geometry{obj_ind}",
name=obj.Name,
name=xml_escape(obj.Label),
sourcebyid=[vert_src, normal_src],
)
input_list = collada.source.InputList()