covering - more detailed poll messages

This commit is contained in:
Andrej730
2024-08-01 14:03:29 +05:00
parent c8466e0606
commit 5ac84e2be7
2 changed files with 47 additions and 33 deletions
@@ -32,9 +32,7 @@ class AddInstanceFlooringCoveringFromCursor(bpy.types.Operator, tool.Ifc.Operato
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
relating_type_id = int(bpy.context.scene.BIMModelProperties.relating_type_id) return tool.Covering.covering_poll_relating_type_check(cls, context, "FLOORING")
relating_type = ifcopenshell.util.element.get_predefined_type(tool.Ifc.get().by_id(relating_type_id))
return relating_type == "FLOORING"
def _execute(self, context): def _execute(self, context):
try: try:
@@ -51,9 +49,7 @@ class AddInstanceCeilingCoveringFromCursor(bpy.types.Operator, tool.Ifc.Operator
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
relating_type_id = int(bpy.context.scene.BIMModelProperties.relating_type_id) return tool.Covering.covering_poll_relating_type_check(cls, context, "CEILING")
relating_type = ifcopenshell.util.element.get_predefined_type(tool.Ifc.get().by_id(relating_type_id))
return relating_type == "CEILING"
def _execute(self, context): def _execute(self, context):
try: try:
@@ -70,8 +66,10 @@ class RegenSelectedCoveringObject(bpy.types.Operator, tool.Ifc.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
element = tool.Ifc.get_entity(bpy.context.active_object) if (obj := context.active_object) and (element := tool.Ifc.get_entity(obj)) and element.is_a("IfcCovering"):
return element and element.is_a("IfcCovering") return True
cls.poll_message_set("IfcCovering must be selected.")
return False
def _execute(self, context): def _execute(self, context):
try: try:
@@ -90,11 +88,7 @@ class AddInstanceFlooringCoveringsFromWalls(bpy.types.Operator, tool.Ifc.Operato
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
element = tool.Ifc.get_entity(bpy.context.active_object) return tool.Covering.covering_poll_wall_selected(cls, context, "FLOORING")
relating_type_id = int(bpy.context.scene.BIMModelProperties.relating_type_id)
relating_type = ifcopenshell.util.element.get_predefined_type(tool.Ifc.get().by_id(relating_type_id))
if element and element.is_a("IfcWall") and tool.Model.get_usage_type(element) == "LAYER2":
return context.selected_objects and relating_type == "FLOORING"
def _execute(self, context): def _execute(self, context):
# This only works based on a 2D plan only considering the standard # This only works based on a 2D plan only considering the standard
@@ -118,11 +112,7 @@ class AddInstanceCeilingCoveringsFromWalls(bpy.types.Operator, tool.Ifc.Operator
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
element = tool.Ifc.get_entity(bpy.context.active_object) return tool.Covering.covering_poll_wall_selected(cls, context, "CEILING")
relating_type_id = int(bpy.context.scene.BIMModelProperties.relating_type_id)
relating_type = ifcopenshell.util.element.get_predefined_type(tool.Ifc.get().by_id(relating_type_id))
if element and element.is_a("IfcWall") and tool.Model.get_usage_type(element) == "LAYER2":
return context.selected_objects and relating_type == "CEILING"
def _execute(self, context): def _execute(self, context):
# This only works based on a 2D plan only considering the standard # This only works based on a 2D plan only considering the standard
+39 -15
View File
@@ -20,6 +20,7 @@ import bpy
import bmesh import bmesh
import shapely import shapely
import ifcopenshell import ifcopenshell
import ifcopenshell.util.element
import blenderbim.core.tool import blenderbim.core.tool
import blenderbim.core.root import blenderbim.core.root
import blenderbim.core.spatial import blenderbim.core.spatial
@@ -37,19 +38,42 @@ class Covering(blenderbim.core.tool.Covering):
props = bpy.context.scene.BIMCoveringProperties props = bpy.context.scene.BIMCoveringProperties
return props.ceiling_height return props.ceiling_height
# def toggle_spaces_visibility_wired_and_textured(cls, spaces):
# first_obj = tool.Ifc.get_object(spaces[0])
# if bpy.data.objects[first_obj.name].display_type == "TEXTURED":
# for space in spaces:
# obj = tool.Ifc.get_object(space)
# bpy.data.objects[obj.name].show_wire = True
# bpy.data.objects[obj.name].display_type = "WIRE"
# return
#
# elif bpy.data.objects[first_obj.name].display_type == "WIRE":
# for space in spaces:
# obj = tool.Ifc.get_object(space)
# bpy.data.objects[obj.name].show_wire = False
# bpy.data.objects[obj.name].display_type = "TEXTURED"
# return
# def toggle_spaces_visibility_wired_and_textured(cls, spaces): @classmethod
# first_obj = tool.Ifc.get_object(spaces[0]) def covering_poll_wall_selected(
# if bpy.data.objects[first_obj.name].display_type == "TEXTURED": cls, operator: type[bpy.types.Operator], context: bpy.types.Context, covering_type: str
# for space in spaces: ) -> bool:
# obj = tool.Ifc.get_object(space) if not context.selected_objects or not context.active_object:
# bpy.data.objects[obj.name].show_wire = True operator.poll_message_set("No objects selected.")
# bpy.data.objects[obj.name].display_type = "WIRE" return False
# return element = tool.Ifc.get_entity(context.active_object)
# if not element or not element.is_a("IfcWall") or not tool.Model.get_usage_type(element) == "LAYER2":
# elif bpy.data.objects[first_obj.name].display_type == "WIRE": operator.poll_message_set("LAYER2 based IfcWall must be selected.")
# for space in spaces: return False
# obj = tool.Ifc.get_object(space) return cls.covering_poll_relating_type_check(operator, context, covering_type)
# bpy.data.objects[obj.name].show_wire = False
# bpy.data.objects[obj.name].display_type = "TEXTURED" @classmethod
# return def covering_poll_relating_type_check(
cls, operator: type[bpy.types.Operator], context: bpy.types.Context, covering_type: str
) -> bool:
relating_type_id = int(context.scene.BIMModelProperties.relating_type_id)
relating_type = ifcopenshell.util.element.get_predefined_type(tool.Ifc.get().by_id(relating_type_id))
if relating_type != covering_type:
operator.poll_message_set(f"Select IfcCoveringType with predefined type '{covering_type}'.")
return False
return True