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