Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve sesam xml writer #96

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/ada/api/spatial/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
_step_types = Union[StepSteadyState, StepEigen, StepImplicitStatic, StepExplicit]

if TYPE_CHECKING:
import xml.etree.ElementTree as ET

import ifcopenshell
import ifcopenshell.validate

Expand Down Expand Up @@ -256,10 +258,10 @@ def to_ifc(
print("IFC file creation complete")
return self.ifc_store.f

def to_genie_xml(self, destination_xml):
def to_genie_xml(self, destination_xml, writer_postprocessor: Callable[[ET.Element, Part], None] = None):
from ada.cadit.gxml.write.write_xml import write_xml

write_xml(self, destination_xml)
write_xml(self, destination_xml, writer_postprocessor=writer_postprocessor)

def push(self, comment, bimserver_url, username, password, project, merge=False, sync=False):
"""Push current assembly to BimServer with a comment tag that defines the revision name"""
Expand Down
3 changes: 2 additions & 1 deletion src/ada/cadit/gxml/write/write_beams.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ def add_segments(beam: Beam):
straight_segment = ET.SubElement(segments, "straight_segment", props)

d = ["x", "y", "z"]
origin = beam.parent.placement.get_absolute_placement().origin

geom = ET.SubElement(straight_segment, "geometry")
wire = ET.SubElement(geom, "wire")
guide = ET.SubElement(wire, "guide")
for i, pos in enumerate([beam.n1, beam.n2], start=1):
props = {d[i]: str(k) for i, k in enumerate(pos.p)}
props = {d[i]: str(k) for i, k in enumerate(origin + pos.p)}
props.update(dict(end=str(i)))
ET.SubElement(guide, "position", props)

Expand Down
19 changes: 10 additions & 9 deletions src/ada/cadit/gxml/write/write_masses.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ def add_masses(root: ET.Element, part: Part):
bc_con = ET.SubElement(sup_point, "mass")
ET.SubElement(bc_con, "mass_scalar", dict(mass=str(mass.mass)))
else:
for mass in part.masses:
print(mass)
bc_stru = ET.SubElement(root, "structure")
sup_point = ET.SubElement(bc_stru, "point_mass", {"name": mass.name})
sup_point.append(add_local_system(X, Y, Z))
geom = ET.SubElement(sup_point, "geometry")
ET.SubElement(geom, "position", {"x": str(mass.p[0]), "y": str(mass.p[1]), "z": str(mass.p[2])})
bc_con = ET.SubElement(sup_point, "mass")
ET.SubElement(bc_con, "mass_scalar", dict(mass=str(mass.mass)))
for p in part.get_all_subparts(True):
for mass in p.masses:
print(mass)
bc_stru = ET.SubElement(root, "structure")
sup_point = ET.SubElement(bc_stru, "point_mass", {"name": mass.name})
sup_point.append(add_local_system(X, Y, Z))
geom = ET.SubElement(sup_point, "geometry")
ET.SubElement(geom, "position", {"x": str(mass.p[0]), "y": str(mass.p[1]), "z": str(mass.p[2])})
bc_con = ET.SubElement(sup_point, "mass")
ET.SubElement(bc_con, "mass_scalar", dict(mass=str(mass.mass)))
12 changes: 8 additions & 4 deletions src/ada/cadit/gxml/write/write_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import pathlib
import xml.etree.ElementTree as ET
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Callable

from .write_bcs import add_boundary_conditions
from .write_beams import add_beams
Expand All @@ -18,7 +18,7 @@
_XML_TEMPLATE = pathlib.Path(__file__).parent / "resources/xml_blank.xml"


def write_xml(part: Part, xml_file, embed_sat=False):
def write_xml(part: Part, xml_file, embed_sat=False, writer_postprocessor: Callable[[ET.Element, Part], None] = None):
if not isinstance(xml_file, pathlib.Path):
xml_file = pathlib.Path(xml_file)

Expand All @@ -27,8 +27,9 @@ def write_xml(part: Part, xml_file, embed_sat=False):

part.consolidate_sections()
part.consolidate_materials()
part.move_all_nodes_here_from_subparts()
part.move_all_masses_here_from_subparts()

# part.move_all_nodes_here_from_subparts()
# part.move_all_masses_here_from_subparts()

# Find the <properties> element
structure_domain = root.find("./model/structure_domain")
Expand All @@ -49,6 +50,9 @@ def write_xml(part: Part, xml_file, embed_sat=False):
add_boundary_conditions(structures_elem, part)
add_masses(structures_elem, part)

if writer_postprocessor:
writer_postprocessor(root, part)

# Write the modified XML back to the file
os.makedirs(xml_file.parent, exist_ok=True)
tree.write(str(xml_file))
Loading