black format src/pyodide

This commit is contained in:
Andrej730
2025-11-17 12:41:27 +05:00
parent bec46562f5
commit db5ec77730
4 changed files with 39 additions and 55 deletions
-1
View File
@@ -12,7 +12,6 @@ extend-exclude = '''
|src/ifcconvert/cityjson/* |src/ifcconvert/cityjson/*
|src/svgfill |src/svgfill
|src/exterior-shell-extractor |src/exterior-shell-extractor
|src/pyodide
''' '''
[tool.pyright] [tool.pyright]
+23 -44
View File
@@ -27,7 +27,9 @@ class Context:
def open(self, file_content): def open(self, file_content):
self.model = ifcopenshell.file.from_string(file_content) self.model = ifcopenshell.file.from_string(file_content)
body = [ctx for ctx in self.model.by_type('IfcGeometricRepresentationContext') if ctx.ContextIdentifier == 'Body'] body = [
ctx for ctx in self.model.by_type("IfcGeometricRepresentationContext") if ctx.ContextIdentifier == "Body"
]
if body: if body:
self.body = body[0] self.body = body[0]
else: else:
@@ -40,7 +42,9 @@ class Context:
target_view="MODEL_VIEW", target_view="MODEL_VIEW",
parent=context, parent=context,
) )
axis = [ctx for ctx in self.model.by_type('IfcGeometricRepresentationContext') if ctx.ContextIdentifier == 'Axis'] axis = [
ctx for ctx in self.model.by_type("IfcGeometricRepresentationContext") if ctx.ContextIdentifier == "Axis"
]
if body: if body:
self.axis = axis[0] self.axis = axis[0]
else: else:
@@ -53,15 +57,13 @@ class Context:
target_view="GRAPH_VIEW", target_view="GRAPH_VIEW",
parent=context, parent=context,
) )
self.storey = self.model.by_type('IfcBuildingStorey')[0] self.storey = self.model.by_type("IfcBuildingStorey")[0]
def _create_empty_model(self): def _create_empty_model(self):
# Create a blank model # Create a blank model
self.model = ifcopenshell.file() self.model = ifcopenshell.file()
# All projects must have one IFC Project element # All projects must have one IFC Project element
project = ifcopenshell.api.run( project = ifcopenshell.api.run("root.create_entity", self.model, ifc_class="IfcProject", name="My Project")
"root.create_entity", self.model, ifc_class="IfcProject", name="My Project"
)
# Geometry is optional in IFC, but because we want to use geometry in this example, let's define units # Geometry is optional in IFC, but because we want to use geometry in this example, let's define units
# Assigning without arguments defaults to metric units # Assigning without arguments defaults to metric units
ifcopenshell.api.run("unit.assign_unit", self.model) ifcopenshell.api.run("unit.assign_unit", self.model)
@@ -85,12 +87,8 @@ class Context:
parent=context, parent=context,
) )
# Create a site, building, and storey. Many hierarchies are possible. # Create a site, building, and storey. Many hierarchies are possible.
site = ifcopenshell.api.run( site = ifcopenshell.api.run("root.create_entity", self.model, ifc_class="IfcSite", name="My Site")
"root.create_entity", self.model, ifc_class="IfcSite", name="My Site" building = ifcopenshell.api.run("root.create_entity", self.model, ifc_class="IfcBuilding", name="Building A")
)
building = ifcopenshell.api.run(
"root.create_entity", self.model, ifc_class="IfcBuilding", name="Building A"
)
self.storey = ifcopenshell.api.run( self.storey = ifcopenshell.api.run(
"root.create_entity", "root.create_entity",
self.model, self.model,
@@ -118,9 +116,7 @@ class Context:
products=[self.storey], products=[self.storey],
) )
def create_2pt_wall( def create_2pt_wall(self, p1, p2, elevation, height, thickness, container, wall_type=None):
self, p1, p2, elevation, height, thickness, container, wall_type=None
):
p1 = np.array([p1[0], p1[1]]) p1 = np.array([p1[0], p1[1]])
p2 = np.array([p2[0], p2[1]]) p2 = np.array([p2[0], p2[1]])
@@ -188,26 +184,22 @@ class Context:
def create_fill(self, ty, pt, wall): def create_fill(self, ty, pt, wall):
if isinstance(wall, str): if isinstance(wall, str):
wall = self.model[wall] wall = self.model[wall]
if not wall.is_a('IfcWall'): if not wall.is_a("IfcWall"):
raise ValueError("Only 'wall' hosts are supported") raise ValueError("Only 'wall' hosts are supported")
if ty == 'door': if ty == "door":
props = propertygroups.BIMDoorProperties() props = propertygroups.BIMDoorProperties()
elif ty == 'window': elif ty == "window":
props = propertygroups.BIMWindowProperties() props = propertygroups.BIMWindowProperties()
else: else:
raise ValueError("Only 'door' or 'window' fills are supported") raise ValueError("Only 'door' or 'window' fills are supported")
si_conversion = ifcopenshell.util.unit.calculate_unit_scale(self.model) si_conversion = ifcopenshell.util.unit.calculate_unit_scale(self.model)
body = ifcopenshell.util.representation.get_context( body = ifcopenshell.util.representation.get_context(self.model, "Model", "Body", "MODEL_VIEW")
self.model, "Model", "Body", "MODEL_VIEW"
)
representation_data = props.to_dict(si_conversion=si_conversion) representation_data = props.to_dict(si_conversion=si_conversion)
representation_data["context"] = body representation_data["context"] = body
door_representation = ifcopenshell.api.run( door_representation = ifcopenshell.api.run(
f"geometry.add_{ty}_representation", self.model, **representation_data f"geometry.add_{ty}_representation", self.model, **representation_data
) )
door = ifcopenshell.api.run( door = ifcopenshell.api.run("root.create_entity", self.model, ifc_class=f"ifc{ty}")
"root.create_entity", self.model, ifc_class=f"ifc{ty}"
)
door.OverallWidth = props.overall_width / si_conversion door.OverallWidth = props.overall_width / si_conversion
door.OverallHeight = props.overall_height / si_conversion door.OverallHeight = props.overall_height / si_conversion
ifcopenshell.api.run( ifcopenshell.api.run(
@@ -223,11 +215,7 @@ class Context:
products=[door], products=[door],
) )
r = [ r = [r for r in wall.Representation.Representations if r.RepresentationIdentifier == "Axis"]
r
for r in wall.Representation.Representations
if r.RepresentationIdentifier == "Axis"
]
if not r: if not r:
raise ValueError("Axis representation is needed") raise ValueError("Axis representation is needed")
r = r[0] r = r[0]
@@ -260,9 +248,7 @@ class Context:
position_3d = None position_3d = None
if self.model.schema == "IFC2X3": if self.model.schema == "IFC2X3":
position_3d = self.model.createIfcAxis2Placement2D( position_3d = self.model.createIfcAxis2Placement2D(self.model.createIfcCartesianPoint([0.0, 0.0, 0.0]))
self.model.createIfcCartesianPoint([0.0, 0.0, 0.0])
)
position_2d = self.model.createIfcAxis2Placement2D( position_2d = self.model.createIfcAxis2Placement2D(
self.model.createIfcCartesianPoint([door.OverallWidth / 2.0, 0.0]) self.model.createIfcCartesianPoint([door.OverallWidth / 2.0, 0.0])
) )
@@ -294,10 +280,7 @@ class Context:
ifcopenshell.api.feature.add_feature(self.model, feature=opening, element=wall) ifcopenshell.api.feature.add_feature(self.model, feature=opening, element=wall)
ifcopenshell.api.feature.add_filling(self.model, opening=opening, element=door) ifcopenshell.api.feature.add_filling(self.model, opening=opening, element=door)
z_offsets = { z_offsets = {"door": 0, "window": 1}
'door': 0,
'window': 1
}
opening.ObjectPlacement = self.model.createIfcLocalPlacement( opening.ObjectPlacement = self.model.createIfcLocalPlacement(
wall.ObjectPlacement, wall.ObjectPlacement,
self.model.createIfcAxis2Placement3D( self.model.createIfcAxis2Placement3D(
@@ -307,9 +290,7 @@ class Context:
door.ObjectPlacement = self.model.createIfcLocalPlacement( door.ObjectPlacement = self.model.createIfcLocalPlacement(
opening.ObjectPlacement, opening.ObjectPlacement,
self.model.createIfcAxis2Placement3D( self.model.createIfcAxis2Placement3D(self.model.createIfcCartesianPoint((0.0, 0.0, 0.0))),
self.model.createIfcCartesianPoint((0.0, 0.0, 0.0))
),
) )
return door return door
@@ -317,9 +298,7 @@ class Context:
def to_obj_file(self, fn): def to_obj_file(self, fn):
st = ifcopenshell.geom.settings(USE_WORLD_COORDS=True, WELD_VERTICES=False) st = ifcopenshell.geom.settings(USE_WORLD_COORDS=True, WELD_VERTICES=False)
it = ifcopenshell.geom.iterator(st, self.model, exclude=("IfcOpeningElement",)) it = ifcopenshell.geom.iterator(st, self.model, exclude=("IfcOpeningElement",))
sr = ifcopenshell.geom.serializers.obj( sr = ifcopenshell.geom.serializers.obj(fn, fn + ".mtl", st, ifcopenshell.geom.serializer_settings())
fn, fn + ".mtl", st, ifcopenshell.geom.serializer_settings()
)
if it.initialize(): if it.initialize():
for el in ifcopenshell.geom.consume_iterator(it): for el in ifcopenshell.geom.consume_iterator(it):
sr.write(el) sr.write(el)
@@ -330,7 +309,7 @@ if __name__ == "__main__":
m = Context() m = Context()
w1 = m.create_2pt_wall((0.0, 0.0), (4.0, 0.0), 0.0, 3.0, 0.1, m.storey) w1 = m.create_2pt_wall((0.0, 0.0), (4.0, 0.0), 0.0, 3.0, 0.1, m.storey)
w2 = m.create_2pt_wall((1.0, 3.0), (1.0, 0.0), 0.0, 3.0, 0.1, m.storey) w2 = m.create_2pt_wall((1.0, 3.0), (1.0, 0.0), 0.0, 3.0, 0.1, m.storey)
m.create_fill('door', [2, 0.0], w1) m.create_fill("door", [2, 0.0], w1)
m.create_fill('window', [1, 1.5], w2) m.create_fill("window", [1, 1.5], w2)
m.model.write("out.ifc") m.model.write("out.ifc")
m.to_obj_file("out.obj") m.to_obj_file("out.obj")
+7 -4
View File
@@ -3,6 +3,7 @@ from dataclasses import dataclass, field
# From: src\bonsai\bonsai\bim\module\model\prop.py # From: src\bonsai\bonsai\bim\module\model\prop.py
# Adapted to use dataclasses instead of bpy props # Adapted to use dataclasses instead of bpy props
@dataclass @dataclass
class BIMWindowProperties: class BIMWindowProperties:
non_si_units_props = ("is_editing", "window_type") non_si_units_props = ("is_editing", "window_type")
@@ -19,6 +20,7 @@ class BIMWindowProperties:
) )
# number of panels and default mullion/transom values # number of panels and default mullion/transom values
# fmt: off
window_types_panels = { window_types_panels = {
"SINGLE_PANEL": (1, ((0, 0 ), (0, 0 ))), "SINGLE_PANEL": (1, ((0, 0 ), (0, 0 ))),
"DOUBLE_PANEL_HORIZONTAL": (2, ((0, 0 ), (0.45, 0 ))), "DOUBLE_PANEL_HORIZONTAL": (2, ((0, 0 ), (0.45, 0 ))),
@@ -30,6 +32,7 @@ class BIMWindowProperties:
"TRIPLE_PANEL_HORIZONTAL": (3, ((0, 0 ), (0.3, 0.6))), "TRIPLE_PANEL_HORIZONTAL": (3, ((0, 0 ), (0.3, 0.6))),
"TRIPLE_PANEL_VERTICAL": (3, ((0.2, 0.4), (0, 0 ))), "TRIPLE_PANEL_VERTICAL": (3, ((0.2, 0.4), (0, 0 ))),
} }
# fmt: on
is_editing: bool = False is_editing: bool = False
window_type: str = "SINGLE_PANEL" window_type: str = "SINGLE_PANEL"
@@ -50,10 +53,10 @@ class BIMWindowProperties:
second_transom_offset: float = 0.6 second_transom_offset: float = 0.6
# panel properties # panel properties
frame_depth: list = field(default_factory = lambda: [0.035] * 3) frame_depth: list = field(default_factory=lambda: [0.035] * 3)
frame_thickness: list = field(default_factory = lambda: [0.035] * 3) frame_thickness: list = field(default_factory=lambda: [0.035] * 3)
def to_dict(self, si_conversion=1.): def to_dict(self, si_conversion=1.0):
di = { di = {
"partition_type": self.window_type, "partition_type": self.window_type,
"overall_height": self.overall_height / si_conversion, "overall_height": self.overall_height / si_conversion,
@@ -124,7 +127,7 @@ class BIMDoorProperties:
frame_thickness: float = 0.035 frame_thickness: float = 0.035
frame_depth: float = 0.035 frame_depth: float = 0.035
def to_dict(self, si_conversion=1.): def to_dict(self, si_conversion=1.0):
return { return {
"operation_type": self.door_type, "operation_type": self.door_type,
"overall_height": self.overall_height / si_conversion, "overall_height": self.overall_height / si_conversion,
+9 -6
View File
@@ -1,26 +1,29 @@
async def test_pset(): async def test_pset():
import ifcopenshell.api.pset import ifcopenshell.api.pset
import ifcopenshell.api.material import ifcopenshell.api.material
errors = [] errors = []
try: try:
model = ifcopenshell.file() model = ifcopenshell.file()
steel_material = ifcopenshell.api.material.add_material(model, name="S355 Steel") steel_material = ifcopenshell.api.material.add_material(model, name="S355 Steel")
steel_pset = ifcopenshell.api.pset.add_pset(model, steel_pset = ifcopenshell.api.pset.add_pset(model, product=steel_material, name="Pset_MaterialSteel")
product=steel_material,
name="Pset_MaterialSteel")
ifcopenshell.api.pset.edit_pset(model, ifcopenshell.api.pset.edit_pset(
model,
pset=steel_pset, pset=steel_pset,
properties={ properties={
"YieldStress": 355*(10**6), # Pa (355 MPa) "YieldStress": 355 * (10**6), # Pa (355 MPa)
}) },
)
except Exception as e: except Exception as e:
errors.append(f"API Error: {e}") errors.append(f"API Error: {e}")
return errors return errors
async def test_doc(): async def test_doc():
import ifcopenshell.util.doc import ifcopenshell.util.doc
errors = [] errors = []
try: try:
ifcopenshell.util.doc.get_entity_doc("IFC4", "IfcWall", recursive=True) ifcopenshell.util.doc.get_entity_doc("IFC4", "IfcWall", recursive=True)