Skip to content

Commit 381de65

Browse files
committed
fix motorized valve
1 parent 2b93cf6 commit 381de65

File tree

2 files changed

+50
-47
lines changed

2 files changed

+50
-47
lines changed

src/bim2fem/ifcplus/api/distribution_element.py

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,6 @@ def create_motorized_valve(
710710
add_shape_representation_to_ports: bool = False,
711711
) -> ifcopenshell.entity_instance:
712712

713-
# Create Element
714713
if element is None:
715714
element = ifcopenshell.api.root.create_entity(
716715
file=ifc4_file,
@@ -719,7 +718,6 @@ def create_motorized_valve(
719718
predefined_type="MOTORIZED",
720719
)
721720

722-
# Assign spatial container
723721
if isinstance(spatial_element, ifcopenshell.entity_instance):
724722
ifcopenshell.api.spatial.assign_container(
725723
file=ifc4_file,
@@ -731,64 +729,74 @@ def create_motorized_valve(
731729
place_object_relative_to_parent=True,
732730
)
733731

734-
# Assign System
735732
if isinstance(distribution_system, ifcopenshell.entity_instance):
736733
ifcopenshell.api.system.assign_system(
737734
file=ifc4_file,
738735
products=[element],
739736
system=distribution_system,
740737
)
741738

742-
# Create Constituted Solid Geometry
743-
operands = [
744-
bim2fem.ifcplus.api.geometry.add_block( # Block
745-
ifc4_file=ifc4_file,
746-
length=2 * outer_diameter,
747-
width=2 / 5 * outer_diameter,
748-
height=2 / 5 * outer_diameter,
749-
repositioned_origin=(0.0, 0.0, outer_diameter),
750-
repositioned_z_axis=(0.0, 0.0, 1.0),
751-
repositioned_x_axis=(1.0, 0.0, 0.0),
752-
),
753-
bim2fem.ifcplus.api.geometry.add_cylindrical_extruded_area_solid( # Cylinder
754-
ifc4_file=ifc4_file,
755-
radius=outer_diameter / 2.0,
756-
extrusion_depth=2 / 5 * outer_diameter,
757-
repositioned_origin=(1.5 * outer_diameter, 0.0, outer_diameter / 2.0),
758-
repositioned_z_axis=(0.0, 1.0, 0.0),
759-
repositioned_x_axis=(1.0, 0.0, 1.0),
760-
),
761-
bim2fem.ifcplus.api.geometry.add_cylindrical_extruded_area_solid( # Cylinder
762-
ifc4_file=ifc4_file,
763-
radius=outer_diameter / 2.0 - thickness,
764-
extrusion_depth=2 / 5 * outer_diameter,
765-
repositioned_origin=(1.5 * outer_diameter, 0.0, outer_diameter / 2.0),
766-
repositioned_z_axis=(0.0, 1.0, 0.0),
767-
repositioned_x_axis=(1.0, 0.0, 1.0),
768-
),
769-
]
739+
block = bim2fem.ifcplus.api.geometry.add_block(
740+
ifc4_file=ifc4_file,
741+
length=2 * outer_diameter,
742+
width=2 / 5 * outer_diameter,
743+
height=2 / 5 * outer_diameter,
744+
repositioned_origin=(0.0, 0.0, outer_diameter),
745+
repositioned_z_axis=(0.0, 0.0, 1.0),
746+
repositioned_x_axis=(1.0, 0.0, 0.0),
747+
)
770748

771-
# Add and Assign Representation
772-
representation_item = bim2fem.ifcplus.api.geometry.add_csg_solid(
773-
operands=operands,
774-
boolean_operators=["UNION", "DIFFERENCE"],
749+
cylinder_1 = bim2fem.ifcplus.api.geometry.add_cylindrical_extruded_area_solid(
750+
ifc4_file=ifc4_file,
751+
radius=outer_diameter / 2.0,
752+
extrusion_depth=2 / 5 * outer_diameter,
753+
repositioned_origin=(1.5 * outer_diameter, 0.0, outer_diameter / 2.0),
754+
repositioned_z_axis=(0.0, 1.0, 0.0),
755+
repositioned_x_axis=(1.0, 0.0, 1.0),
756+
)
757+
758+
cylinder_2 = bim2fem.ifcplus.api.geometry.add_cylindrical_extruded_area_solid(
759+
ifc4_file=ifc4_file,
760+
radius=outer_diameter / 2.0 - thickness,
761+
extrusion_depth=2 / 5 * outer_diameter,
762+
repositioned_origin=(1.5 * outer_diameter, 0.0, outer_diameter / 2.0),
763+
repositioned_z_axis=(0.0, 1.0, 0.0),
764+
repositioned_x_axis=(1.0, 0.0, 1.0),
775765
)
766+
767+
boolean_result_1 = ifcopenshell.api.geometry.add_boolean(
768+
file=ifc4_file,
769+
first_item=block,
770+
second_items=[cylinder_1],
771+
operator="UNION",
772+
)[-1]
773+
774+
boolean_result_2 = ifcopenshell.api.geometry.add_boolean(
775+
file=ifc4_file,
776+
first_item=boolean_result_1,
777+
second_items=[cylinder_2],
778+
operator="DIFFERENCE",
779+
)[-1]
780+
781+
csg_solid = bim2fem.ifcplus.api.geometry.add_csg_solid(
782+
boolean_result_or_primitive=boolean_result_2,
783+
)
784+
785+
representation_type = ifcopenshell.util.representation.guess_type(items=[csg_solid])
786+
776787
shape_model = bim2fem.ifcplus.api.geometry.add_shape_model(
777788
ifc4_file=ifc4_file,
778789
shape_model_class="IfcShapeRepresentation",
779790
representation_identifier="Body",
780-
representation_type="CSG",
781-
context_type="Model",
782-
target_view="MODEL_VIEW",
783-
items=[representation_item],
791+
representation_type=cast(str, representation_type),
792+
items=[csg_solid],
784793
)
785794
ifcopenshell.api.geometry.assign_representation(
786795
file=ifc4_file,
787796
product=element,
788797
representation=shape_model,
789798
)
790799

791-
# Edit Element Placement
792800
bim2fem.ifcplus.api.placement.edit_object_placement(
793801
product=element,
794802
repositioned_origin=(0.0, 0.0, 0.0),
@@ -797,7 +805,6 @@ def create_motorized_valve(
797805
place_object_relative_to_parent=place_object_relative_to_parent,
798806
)
799807

800-
# Add and Assign Type
801808
element_type = bim2fem.ifcplus.api.element_type.add_element_type(
802809
ifc4_file=ifc4_file,
803810
ifc_class=ifcopenshell.util.type.get_applicable_types(ifc_class=element.is_a())[
@@ -812,7 +819,6 @@ def create_motorized_valve(
812819
relating_type=element_type,
813820
)
814821

815-
# Port 1
816822
port1_origin_in_object_coordinates = (
817823
1.5 * outer_diameter,
818824
0.0,
@@ -838,7 +844,6 @@ def create_motorized_valve(
838844
place_object_relative_to_parent=True,
839845
)
840846

841-
# Port 2
842847
port2_origin_in_object_coordinates = (
843848
1.5 * outer_diameter,
844849
2 / 5 * outer_diameter,

tests/ifcplus/api/test_distribution_element.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ def test_add_one_make_up_air_unit(
5454
assert bbox_dict["min"] == (0.0, 0.0, 0.0)
5555
assert bbox_dict["max"] == (4.0, 1.5, 1.5)
5656

57-
output_path = str(
58-
OUTPUT_DIR_FOR_DISTRIBUTION_ELEMENT / "one_make_up_air_unit.ifc"
59-
)
57+
output_path = str(OUTPUT_DIR_FOR_DISTRIBUTION_ELEMENT / "make_up_air_unit.ifc")
6058
bim2fem.ifcplus.api.project.write_to_ifc_spf(
6159
ifc4_file=ifc_file_with_ventilation_distribution_system,
6260
file_path=output_path,
@@ -112,7 +110,7 @@ def test_add_air_filtration_containment_housing(
112110

113111
output_path = str(
114112
OUTPUT_DIR_FOR_DISTRIBUTION_ELEMENT
115-
/ "one_air_filtration_containment_housing.ifc"
113+
/ "air_filtration_containment_housing.ifc"
116114
)
117115
bim2fem.ifcplus.api.project.write_to_ifc_spf(
118116
ifc4_file=ifc_file_with_ventilation_distribution_system,

0 commit comments

Comments
 (0)