Skip to content

Commit d2f4f0d

Browse files
committed
experimental patch of non parametric mep segments
1 parent 1c17ccc commit d2f4f0d

7 files changed

Lines changed: 84 additions & 0 deletions

File tree

src/blenderbim/blenderbim/bim/module/misc/ui.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def draw(self, context):
5050
row.operator("bim.draw_system_arrows")
5151
row = layout.row()
5252
row.operator("bim.clean_wireframes")
53+
row = layout.row()
54+
row.operator("bim.patch_non_parametric_mep_segment")
5355

5456
row = layout.row(align=True)
5557
row.operator("bim.enable_editing_sketch_extrusion_profile", text="Start Sketching")

src/blenderbim/blenderbim/bim/module/model/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
profile.ExtendProfile,
8787
profile.RecalculateProfile,
8888
profile.Rotate90,
89+
profile.PatchNonParametricMepSegment,
8990
roof.GenerateHippedRoof,
9091
slab.DisableEditingExtrusionProfile,
9192
slab.DisableEditingSketchExtrusionProfile,

src/blenderbim/blenderbim/bim/module/model/profile.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import blenderbim.tool as tool
2929
import blenderbim.core.type
3030
import blenderbim.core.geometry
31+
import blenderbim.core.material
3132
from math import pi, degrees, inf
3233
from mathutils import Vector, Matrix, Quaternion
3334
from blenderbim.bim.module.geometry.helper import Helper
@@ -857,6 +858,25 @@ def _execute(self, context):
857858
return {"FINISHED"}
858859

859860

861+
class PatchNonParametricMepSegment(bpy.types.Operator, tool.Ifc.Operator):
862+
bl_idname = "bim.patch_non_parametric_mep_segment"
863+
bl_label = "Set MEP segment Material Profile"
864+
bl_options = {"REGISTER", "UNDO"}
865+
866+
@classmethod
867+
def poll(cls, context):
868+
return context.active_object
869+
870+
def _execute(self, context):
871+
styles = tool.Geometry.get_styles(context.active_object)
872+
blenderbim.core.material.patch_non_parametric_mep_segment(
873+
tool.Ifc, tool.Material, tool.Profile, obj=context.active_object
874+
)
875+
bpy.ops.bim.enable_editing_extrusion_axis()
876+
bpy.ops.bim.edit_extrusion_axis()
877+
styles = tool.Geometry.get_styles(context.active_object)
878+
879+
860880
class EnableEditingExtrusionAxis(bpy.types.Operator, tool.Ifc.Operator):
861881
bl_idname = "bim.enable_editing_extrusion_axis"
862882
bl_label = "Enable Editing Extrusion Axis"

src/blenderbim/blenderbim/core/material.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,19 @@ def unassign_material(ifc, material_tool, objects):
119119
ifc.run("material.unassign_material", product=element_type)
120120
elif material:
121121
ifc.run("material.unassign_material", product=element)
122+
123+
124+
def patch_non_parametric_mep_segment(ifc, material_tool, profile_tool, obj):
125+
element = ifc.get_entity(obj)
126+
if not element:
127+
return
128+
if not material_tool.is_a_flow_segment(element):
129+
return
130+
has_material_profile = material_tool.has_material_profile(element)
131+
if has_material_profile:
132+
return
133+
representation_profile = profile_tool.get_profile(element)
134+
if not representation_profile:
135+
return
136+
material_profile = material_tool.replace_material_with_material_profile(element=element)
137+
ifc.run("material.assign_profile", material_profile=material_profile, profile=representation_profile)

src/blenderbim/blenderbim/core/tool.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,14 @@ def get_material_attributes(cls): pass
447447
def get_material(cls, element, should_inherit): pass
448448
def get_name(cls, obj): pass
449449
def get_type(cls, element): pass
450+
def has_material_profile(cls, element): pass
450451
def import_material_definitions(cls, material_type): pass
452+
def is_a_flow_segment(cls, element): pass
451453
def is_a_material_set(cls, material): pass
452454
def is_editing_materials(cls): pass
453455
def is_material_used_in_sets(cls, material): pass
454456
def load_material_attributes(cls, material): pass
457+
def replace_material_with_material_profile(cls, element): pass
455458

456459

457460
@interface
@@ -551,6 +554,8 @@ def set_default_modeling_dimensions(cls): pass
551554
@interface
552555
class Profile:
553556
def draw_image_for_ifc_profile(cls, draw, profile, size): pass
557+
def is_editing_profile(cls): pass
558+
def get_profile(cls, element): pass
554559

555560

556561
@interface

src/blenderbim/blenderbim/tool/material.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,30 @@ def add_material_to_set(cls, material_set, material):
193193
material=material,
194194
profile=profile,
195195
)
196+
197+
@classmethod
198+
def has_material_profile(cls, element):
199+
material = cls.get_material(element, should_inherit=False)
200+
inherited_material = cls.get_material(element, should_inherit=True)
201+
if material and "Profile" in material.is_a():
202+
return True
203+
if inherited_material and "Profile" in inherited_material.is_a():
204+
return True
205+
return False
206+
207+
@classmethod
208+
def is_a_flow_segment(cls, element):
209+
return element.is_a("IfcFlowSegment")
210+
211+
@classmethod
212+
def replace_material_with_material_profile(cls, element):
213+
old_material = cls.get_material(element, should_inherit=False)
214+
old_inherited_material = cls.get_material(element, should_inherit=True)
215+
blenderbim.core.material.unassign_material(tool.Ifc, tool.Material, objects=[tool.Ifc.get_object(element)])
216+
tool.Ifc.run("material.assign_material", product=element, type="IfcMaterialProfileSet")
217+
assinged_material = cls.get_material(element)
218+
material = old_material if old_material and old_material.is_a("IfcMaterial") else None
219+
if not material and old_inherited_material:
220+
material = old_inherited_material if old_inherited_material.is_a("IfcMaterial") else None
221+
material_profile = tool.Ifc.run("material.add_profile", profile_set=assinged_material, material=material)
222+
return material_profile

src/blenderbim/blenderbim/tool/profile.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,16 @@ def draw_image_for_ifc_profile(cls, draw, profile, size):
5757
@classmethod
5858
def is_editing_profile(cls):
5959
return ProfileDecorator.installed
60+
61+
@classmethod
62+
def get_profile(cls, element):
63+
representations = element.Representation
64+
for representation in representations.Representations:
65+
if not representation.is_a("IfcShapeRepresentation"):
66+
continue
67+
for representation_item in representation.Items:
68+
if representation_item.is_a("IfcExtrudedAreaSolid"):
69+
profile = representation_item.SweptArea
70+
if profile:
71+
return profile
72+
return None

0 commit comments

Comments
 (0)