Building storeys now show a derived storey height so you don't need to do math

This commit is contained in:
Dion Moult
2021-10-15 13:23:08 +11:00
parent 07bfe296dd
commit 0abe9f0559
4 changed files with 71 additions and 1 deletions
@@ -286,7 +286,6 @@ class IfcImporter:
if self.non_body_contexts: if self.non_body_contexts:
self.settings_2d.set_context_ids(self.non_body_contexts) self.settings_2d.set_context_ids(self.non_body_contexts)
def process_element_filter(self): def process_element_filter(self):
if self.ifc_import_settings.has_filter: if self.ifc_import_settings.has_filter:
self.elements = set(self.ifc_import_settings.elements) self.elements = set(self.ifc_import_settings.elements)
@@ -0,0 +1,61 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import blenderbim.tool as tool
import ifcopenshell.util.placement
def refresh():
DerivedPlacementsData.is_loaded = False
class DerivedPlacementsData:
data = {}
is_loaded = False
@classmethod
def load(cls):
cls.data = {
"is_storey": cls.is_storey(),
"storey_height": cls.get_storey_height(),
}
cls.is_loaded = True
@classmethod
def is_storey(cls):
element = tool.Ifc.get_entity(bpy.context.active_object)
if element:
return element.is_a("IfcBuildingStorey")
@classmethod
def get_storey_height(cls):
if not cls.is_storey():
return
element = tool.Ifc.get_entity(bpy.context.active_object)
storeys = [
(s, ifcopenshell.util.placement.get_local_placement(s.ObjectPlacement)[2][3])
for s in tool.Ifc.get().by_type("IfcBuildingStorey")
]
storeys = sorted(storeys, key=lambda s: s[1])
for i, storey in enumerate(storeys):
if storey[0] != element:
continue
if i >= len(storeys):
return "N/A"
return "{0:.3f}".format(round(storeys[i + 1][1] - storey[1], 3))
@@ -20,6 +20,7 @@ import bpy
from bpy.types import Panel from bpy.types import Panel
from ifcopenshell.api.geometry.data import Data from ifcopenshell.api.geometry.data import Data
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.module.geometry.data import DerivedPlacementsData
class BIM_PT_representations(Panel): class BIM_PT_representations(Panel):
@@ -153,6 +154,9 @@ class BIM_PT_derived_placements(Panel):
bl_parent_id = "OBJECT_PT_transform" bl_parent_id = "OBJECT_PT_transform"
def draw(self, context): def draw(self, context):
if not DerivedPlacementsData.is_loaded:
DerivedPlacementsData.load()
z = context.active_object.matrix_world.translation.z z = context.active_object.matrix_world.translation.z
z_values = [co[2] for co in context.active_object.bound_box] z_values = [co[2] for co in context.active_object.bound_box]
row = self.layout.row(align=True) row = self.layout.row(align=True)
@@ -172,6 +176,11 @@ class BIM_PT_derived_placements(Panel):
row.label(text="Max Local Z") row.label(text="Max Local Z")
row.label(text="{0:.3f}".format(max(z_values) + z - collection_z)) row.label(text="{0:.3f}".format(max(z_values) + z - collection_z))
if DerivedPlacementsData.data["is_storey"]:
row = self.layout.row(align=True)
row.label(text="Storey Height")
row.label(text=DerivedPlacementsData.data["storey_height"])
class BIM_PT_workarounds(Panel): class BIM_PT_workarounds(Panel):
bl_label = "IFC Vendor Workarounds" bl_label = "IFC Vendor Workarounds"
@@ -53,6 +53,7 @@ classes = (
ui.BIM_UL_links, ui.BIM_UL_links,
) )
def menu_func_export(self, context): def menu_func_export(self, context):
self.layout.operator(operator.ExportIFC.bl_idname, text="Industry Foundation Classes (.ifc/.ifczip/.ifcjson)") self.layout.operator(operator.ExportIFC.bl_idname, text="Industry Foundation Classes (.ifc/.ifczip/.ifcjson)")