WIP port covetool. See #1222.

This commit is contained in:
Dion Moult
2021-01-24 08:19:26 +11:00
parent 65f381a377
commit b68f490dbc
@@ -1,6 +1,9 @@
import bpy import bpy
import json import json
import ifcopenshell
import ifcopenshell.util.element
from math import degrees, atan2 from math import degrees, atan2
from blenderbim.bim.ifc import IfcStore
from .api import Api from .api import Api
@@ -70,6 +73,7 @@ class RunAnalysis(bpy.types.Operator):
bl_label = "Run Analysis" bl_label = "Run Analysis"
def execute(self, context): def execute(self, context):
self.file = IfcStore.get_file()
self.inputs = { self.inputs = {
"floors": [], "floors": [],
"walls": [], "walls": [],
@@ -94,16 +98,13 @@ class RunAnalysis(bpy.types.Operator):
return {"FINISHED"} return {"FINISHED"}
def get_rotation_angle(self): def get_rotation_angle(self):
if ( if not self.file.by_type("IfcMapConversion"):
not bpy.context.scene.BIMProperties.has_georeferencing
or not bpy.context.scene.MapConversion.x_axis_abscissa
or not bpy.context.scene.MapConversion.x_axis_ordinate
):
return 0 return 0
map_conversion = self.file.by_type("IfcMapConversion")[0]
rotation = -1 * degrees( rotation = -1 * degrees(
atan2( atan2(
float(bpy.context.scene.MapConversion.x_axis_ordinate), float(map_conversion.XAxisOrdinate or 0),
float(bpy.context.scene.MapConversion.x_axis_abscissa), float(map_conversion.XAxisAbscissa or 1),
) )
) )
if rotation < 0: if rotation < 0:
@@ -164,34 +165,36 @@ class RunAnalysis(bpy.types.Operator):
def get_covetool_category(self, obj): def get_covetool_category(self, obj):
if not hasattr(obj, "data") or not isinstance(obj.data, bpy.types.Mesh): if not hasattr(obj, "data") or not isinstance(obj.data, bpy.types.Mesh):
return return
if "IfcSlab" in obj.name: if not obj.BIMObjectProperties.ifc_definition_id:
return
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
ifc_class = element.is_a()
if "IfcSlab" in ifc_class:
return "floors" return "floors"
elif "IfcRoof" in obj.name: elif "IfcRoof" in ifc_class:
return "roofs" return "roofs"
elif "IfcWall" in obj.name: elif "IfcWall" in ifc_class:
if self.is_wall_internal(obj): if self.is_wall_internal(element):
return "interior_walls" return "interior_walls"
return "walls" return "walls"
elif "IfcWindow" in obj.name: elif "IfcWindow" in ifc_class:
if self.is_window_skylight(obj): if self.is_window_skylight(element):
return "skylights" return "skylights"
return "windows" return "windows"
elif "IfcShadingDevice" in obj.name: elif "IfcShadingDevice" in ifc_class:
return "shading_devices" return "shading_devices"
def is_wall_internal(self, obj): def is_wall_internal(self, element):
pset_wallcommon = obj.BIMObjectProperties.psets.get("Pset_WallCommon") psets = ifcopenshell.util.element.get_psets(element)
if pset_wallcommon: pset = psets.get("Pset_WallCommon")
is_external = pset_wallcommon.properties.get("IsExternal") if pset:
if is_external: is_external = pset.get("IsExternal", None)
if is_external.string_value == "True": if is_external is not None:
return False return is_external
else: predefined_type = element.get_info().get("PredefinedType")
return True if predefined_type and predefined_type in ["MOVABLE", "PARTITIONING", "PLUMBINGWALL"]:
predefined_type = obj.BIMObjectProperties.attributes.get("PredefinedType")
if predefined_type and predefined_type.string_value in ["MOVABLE", "PARTITIONING", "PLUMBINGWALL"]:
return True return True
def is_window_skylight(self, obj): def is_window_skylight(self, element):
predefined_type = obj.BIMObjectProperties.attributes.get("PredefinedType") predefined_type = element.get_info().get("PredefinedType")
return predefined_type and predefined_type.string_value == "SKYLIGHT" return predefined_type and predefined_type.string_value == "SKYLIGHT"