Skip to content

Commit

Permalink
fix bug in beamtapered export to ifc
Browse files Browse the repository at this point in the history
  • Loading branch information
Krande committed Dec 16, 2024
1 parent 1bdcdaa commit 27c79ec
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 26 deletions.
12 changes: 12 additions & 0 deletions src/ada/api/beams/geom_beams.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def straight_tapered_beam_to_geom(beam: BeamTapered, is_solid=True) -> Geometry:
return ibeam_taper_to_geom(beam)
else:
return ibeam_taper_to_face_geom(beam)
elif beam.section.type == beam.section.TYPES.TPROFILE:
if is_solid:
return tbeam_taper_to_geom(beam)
else:
return ibeam_taper_to_face_geom(beam)
elif beam.section.type == beam.section.TYPES.BOX:
if is_solid:
return boxbeam_taper_to_geom(beam)
Expand Down Expand Up @@ -138,6 +143,13 @@ def ibeam_taper_to_geom(beam: BeamTapered) -> Geometry:
geom = geo_so.ExtrudedAreaSolidTapered(profile1, place, beam.length, Direction(0, 0, 1), profile2)
return Geometry(beam.guid, geom, beam.color)

def tbeam_taper_to_geom(beam: BeamTapered) -> Geometry:
profile1 = section_to_arbitrary_profile_def_with_voids(beam.section)
profile2 = section_to_arbitrary_profile_def_with_voids(beam.taper)

place = Axis2Placement3D(location=beam.n1.p, axis=beam.xvec, ref_direction=beam.yvec)
geom = geo_so.ExtrudedAreaSolidTapered(profile1, place, beam.length, Direction(0, 0, 1), profile2)
return Geometry(beam.guid, geom, beam.color)

def ibeam_taper_to_face_geom(beam: BeamTapered) -> Geometry:
profile1 = section_to_arbitrary_profile_def_with_voids(beam.section, solid=False)
Expand Down
20 changes: 20 additions & 0 deletions src/ada/cadit/ifc/write/geom/solids.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,23 @@ def extruded_area_solid(

extrude_direction = direction(eas.extruded_direction, f)
return f.create_entity("IfcExtrudedAreaSolid", profile, axis3d, extrude_direction, eas.depth)


def extruded_area_solid_tapered(
eas: geo_so.ExtrudedAreaSolidTapered, f: ifcopenshell.file
) -> ifcopenshell.entity_instance:
"""Converts an ExtrudedAreaSolidTapered to an IFC representation"""

axis3d = ifc_placement_from_axis3d(eas.position, f)
profile = arbitrary_profile_def(eas.swept_area, f)
end_profile = arbitrary_profile_def(eas.end_swept_area, f)
extrude_direction = direction(eas.extruded_direction, f)

return f.create_entity(
"IfcExtrudedAreaSolidTapered",
SweptArea=profile,
Position=axis3d,
ExtrudedDirection=extrude_direction,
Depth=eas.depth,
EndSweptArea=end_profile,
)
17 changes: 4 additions & 13 deletions src/ada/cadit/ifc/write/write_beams.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
ifc_dir,
)
from ada.cadit.ifc.write.geom.points import cpt
from ada.cadit.ifc.write.geom.solids import extruded_area_solid
from ada.cadit.ifc.write.geom.solids import extruded_area_solid, extruded_area_solid_tapered
from ada.cadit.ifc.write.write_curves import write_curve_poly
from ada.config import Config
from ada.core.constants import O
from ada.core.guid import create_guid
from ada.core.utils import to_real

Expand Down Expand Up @@ -121,7 +120,6 @@ def add_material_assignment(self, beam: Beam, ifc_beam):

def extrude_straight_tapered_beam(beam: BeamTapered, f: ifile, profile):
"""Extrude a straight beam with a tapered profile"""
extrude_dir = ifc_dir(f, (0.0, 0.0, 1.0))
parent = f.by_guid(beam.parent.guid)
a = beam.parent.get_assembly()

Expand All @@ -135,8 +133,6 @@ def extrude_straight_tapered_beam(beam: BeamTapered, f: ifile, profile):
e1 = beam.e1
vec = beam.xvec_e

profile2 = a.ifc_store.get_profile_def(beam.taper)

# Transform coordinates to local coords
p1 = tuple([float(x) + float(e1[i]) for i, x in enumerate(beam.n1.p.copy())])
p2 = p1 + np.array([0, 0, 1]) * beam.length
Expand All @@ -146,22 +142,17 @@ def extrude_straight_tapered_beam(beam: BeamTapered, f: ifile, profile):

ifc_polyline = f.create_entity("IfcPolyLine", [p1_ifc, p2_ifc])

global_origin = f.createIfcCartesianPoint(O)
ifc_axis2plac3d = f.create_entity("IfcAxis2Placement3D", global_origin, None, None)

extrude_area_solid = f.create_entity(
"IfcExtrudedAreaSolidTapered", profile, ifc_axis2plac3d, extrude_dir, beam.length, profile2
)
solid = extruded_area_solid_tapered(beam.solid_geom().geometry, f)

# Add colour
if beam.color is not None:
add_colour(f, extrude_area_solid, str(beam.color), beam.color)
add_colour(f, solid, str(beam.color), beam.color)

body_context = a.ifc_store.get_context("Body")
axis_context = a.ifc_store.get_context("Axis")
ax23d = f.create_entity("IfcAxis2Placement3D", p1_ifc, ifc_dir(f, vec), ifc_dir(f, yvec))
loc_plac = f.create_entity("IfcLocalPlacement", global_placement, ax23d)
body = f.create_entity("IfcShapeRepresentation", body_context, "Body", "SweptSolid", [extrude_area_solid])
body = f.create_entity("IfcShapeRepresentation", body_context, "Body", "SweptSolid", [solid])
axis = f.create_entity("IfcShapeRepresentation", axis_context, "Axis", "Curve3D", [ifc_polyline])

return body, axis, loc_plac
Expand Down
26 changes: 13 additions & 13 deletions src/ada/sections/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,30 +292,30 @@ def tg_section(in_str: str, s: float, units: Units):
if res is None:
continue
h = [_rdoff(float(x) * s) for x in res.group(2).split("/")]
wt = [_rdoff(float(x) * s) for x in res.group(3).split("/")]
tw = [_rdoff(float(x) * s) for x in res.group(4).split("/")]
tf = [_rdoff(float(x) * s) for x in res.group(5).split("/")]
width = [_rdoff(float(x) * s) for x in res.group(3).split("/")]
thick_web = [_rdoff(float(x) * s) for x in res.group(4).split("/")]
thick_flange = [_rdoff(float(x) * s) for x in res.group(5).split("/")]
sec = Section(
in_str,
h=h[0],
sec_type=SectionCat.BASETYPES.TPROFILE,
w_btn=tw[0],
w_top=wt[0],
t_fbtn=tf[0],
t_ftop=tf[0],
t_w=tw[0],
w_btn=thick_web[0],
w_top=width[0],
t_fbtn=thick_flange[0],
t_ftop=thick_flange[0],
t_w=thick_web[0],
metadata=dict(cad_str=in_str),
units=units,
)
tap = Section(
in_str + "_e",
h=h[-1],
sec_type=SectionCat.BASETYPES.TPROFILE,
w_btn=wt[-1],
w_top=tw[-1],
t_fbtn=tf[-1],
t_ftop=tf[-1],
t_w=tw[-1],
w_btn=thick_web[-1],
w_top=width[-1],
t_fbtn=thick_flange[-1],
t_ftop=thick_flange[-1],
t_w=thick_web[-1],
metadata=dict(cad_str=in_str),
units=units,
)
Expand Down

0 comments on commit 27c79ec

Please sign in to comment.