mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
Fix bug where the derived placements interface didn't take into account rotations
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
import bpy
|
||||
import blenderbim.tool as tool
|
||||
import ifcopenshell.util.placement
|
||||
from mathutils import Vector
|
||||
|
||||
|
||||
def refresh():
|
||||
@@ -31,12 +32,52 @@ class DerivedPlacementsData:
|
||||
|
||||
@classmethod
|
||||
def load(cls):
|
||||
cls.load_z_values()
|
||||
cls.load_collection()
|
||||
cls.data = {
|
||||
"is_storey": cls.is_storey(),
|
||||
"storey_height": cls.get_storey_height(),
|
||||
"storey_height": cls.storey_height(),
|
||||
"min_global_z": cls.min_global_z(),
|
||||
"max_global_z": cls.max_global_z(),
|
||||
"has_collection": cls.has_collection(),
|
||||
"min_decomposed_z": cls.min_decomposed_z(),
|
||||
"max_decomposed_z": cls.max_decomposed_z(),
|
||||
}
|
||||
cls.is_loaded = True
|
||||
|
||||
@classmethod
|
||||
def load_z_values(cls):
|
||||
cls.z_values = [
|
||||
(bpy.context.active_object.matrix_world @ Vector(co))[2] for co in bpy.context.active_object.bound_box
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def load_collection(cls):
|
||||
cls.collection = bpy.data.objects.get(bpy.context.active_object.users_collection[0].name)
|
||||
cls.collection_z = 0
|
||||
if cls.collection:
|
||||
cls.collection_z = cls.collection.matrix_world.translation.z
|
||||
|
||||
@classmethod
|
||||
def has_collection(cls):
|
||||
return bool(cls.collection)
|
||||
|
||||
@classmethod
|
||||
def min_global_z(cls):
|
||||
return "{0:.3f}".format(round(min(cls.z_values), 3))
|
||||
|
||||
@classmethod
|
||||
def max_global_z(cls):
|
||||
return "{0:.3f}".format(round(max(cls.z_values), 3))
|
||||
|
||||
@classmethod
|
||||
def min_decomposed_z(cls):
|
||||
return "{0:.3f}".format(round(min(cls.z_values) - cls.collection_z, 3))
|
||||
|
||||
@classmethod
|
||||
def max_decomposed_z(cls):
|
||||
return "{0:.3f}".format(round(max(cls.z_values) - cls.collection_z, 3))
|
||||
|
||||
@classmethod
|
||||
def is_storey(cls):
|
||||
element = tool.Ifc.get_entity(bpy.context.active_object)
|
||||
@@ -44,7 +85,7 @@ class DerivedPlacementsData:
|
||||
return element.is_a("IfcBuildingStorey")
|
||||
|
||||
@classmethod
|
||||
def get_storey_height(cls):
|
||||
def storey_height(cls):
|
||||
if not cls.is_storey():
|
||||
return
|
||||
element = tool.Ifc.get_entity(bpy.context.active_object)
|
||||
|
||||
@@ -157,24 +157,20 @@ class BIM_PT_derived_placements(Panel):
|
||||
if not DerivedPlacementsData.is_loaded:
|
||||
DerivedPlacementsData.load()
|
||||
|
||||
z = context.active_object.matrix_world.translation.z
|
||||
z_values = [co[2] for co in context.active_object.bound_box]
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text="Min Global Z")
|
||||
row.label(text="{0:.3f}".format(min(z_values) + z))
|
||||
row.label(text=DerivedPlacementsData.data["min_global_z"])
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text="Max Global Z")
|
||||
row.label(text="{0:.3f}".format(max(z_values) + z))
|
||||
row.label(text=DerivedPlacementsData.data["max_global_z"])
|
||||
|
||||
collection = bpy.data.objects.get(context.active_object.users_collection[0].name)
|
||||
if collection:
|
||||
collection_z = collection.matrix_world.translation.z
|
||||
if DerivedPlacementsData.data["has_collection"]:
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text="Min Local Z")
|
||||
row.label(text="{0:.3f}".format(min(z_values) + z - collection_z))
|
||||
row.label(text="Min Decomposed Z")
|
||||
row.label(text=DerivedPlacementsData.data["min_decomposed_z"])
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text="Max Local Z")
|
||||
row.label(text="{0:.3f}".format(max(z_values) + z - collection_z))
|
||||
row.label(text="Max Decomposed Z")
|
||||
row.label(text=DerivedPlacementsData.data["max_decomposed_z"])
|
||||
|
||||
if DerivedPlacementsData.data["is_storey"]:
|
||||
row = self.layout.row(align=True)
|
||||
|
||||
Reference in New Issue
Block a user