2021-08-17 08:55:29 +10:00
|
|
|
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
|
|
|
|
# Copyright (C) 2020, 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/>.
|
|
|
|
|
|
2021-01-04 13:07:29 +11:00
|
|
|
import bpy
|
2021-08-19 22:26:00 +02:00
|
|
|
import blenderbim.bim.module.root.prop as root_prop
|
2021-01-04 13:07:29 +11:00
|
|
|
from bpy.types import Panel
|
2021-03-25 10:48:31 +11:00
|
|
|
from ifcopenshell.api.root.data import Data
|
2021-01-05 21:15:52 +11:00
|
|
|
from blenderbim.bim.ifc import IfcStore
|
2021-01-04 13:07:29 +11:00
|
|
|
|
2021-01-12 15:12:53 +11:00
|
|
|
|
2021-01-04 13:07:29 +11:00
|
|
|
class BIM_PT_class(Panel):
|
|
|
|
|
bl_label = "IFC Class"
|
|
|
|
|
bl_idname = "BIM_PT_class"
|
|
|
|
|
bl_space_type = "PROPERTIES"
|
|
|
|
|
bl_region_type = "WINDOW"
|
|
|
|
|
bl_context = "object"
|
|
|
|
|
|
2021-01-05 21:15:52 +11:00
|
|
|
@classmethod
|
|
|
|
|
def poll(cls, context):
|
2021-09-27 12:51:43 +02:00
|
|
|
if not context.active_object:
|
|
|
|
|
return False
|
2021-01-05 21:15:52 +11:00
|
|
|
return IfcStore.get_file()
|
|
|
|
|
|
2021-01-04 13:07:29 +11:00
|
|
|
def draw(self, context):
|
|
|
|
|
props = context.active_object.BIMObjectProperties
|
|
|
|
|
if props.ifc_definition_id:
|
|
|
|
|
if props.ifc_definition_id not in Data.products:
|
2021-03-09 12:50:50 +11:00
|
|
|
try:
|
2021-03-25 10:48:31 +11:00
|
|
|
Data.load(IfcStore.get_file(), props.ifc_definition_id)
|
2021-03-09 12:50:50 +11:00
|
|
|
except:
|
|
|
|
|
row = self.layout.row(align=True)
|
|
|
|
|
row.label(text="IFC Element Not Found")
|
|
|
|
|
row.operator("bim.unlink_object", icon="UNLINKED", text="")
|
2021-06-15 13:05:24 +10:00
|
|
|
return
|
2021-01-04 13:07:29 +11:00
|
|
|
if props.is_reassigning_class:
|
|
|
|
|
row = self.layout.row(align=True)
|
|
|
|
|
row.operator("bim.reassign_class", icon="CHECKMARK")
|
2021-08-05 21:14:18 +10:00
|
|
|
row.operator("bim.disable_reassign_class", icon="CANCEL", text="")
|
2021-08-19 22:26:00 +02:00
|
|
|
self.draw_class_dropdowns(
|
2021-09-09 21:27:23 +10:00
|
|
|
context, root_prop.getIfcPredefinedTypes(context.scene.BIMRootProperties, context)
|
|
|
|
|
)
|
2021-01-04 13:07:29 +11:00
|
|
|
else:
|
|
|
|
|
data = Data.products[props.ifc_definition_id]
|
|
|
|
|
name = data["type"]
|
|
|
|
|
if data["PredefinedType"] and data["PredefinedType"] == "USERDEFINED":
|
2021-08-07 10:28:13 +10:00
|
|
|
if data["ObjectType"]:
|
|
|
|
|
name += "[{}]".format(data["ObjectType"])
|
|
|
|
|
elif data["ElementType"]:
|
|
|
|
|
name += "[{}]".format(data["ElementType"])
|
2021-01-04 13:07:29 +11:00
|
|
|
elif data["PredefinedType"]:
|
|
|
|
|
name += "[{}]".format(data["PredefinedType"])
|
|
|
|
|
row = self.layout.row(align=True)
|
|
|
|
|
row.label(text=name)
|
2021-07-19 19:19:12 +10:00
|
|
|
row.operator("bim.select_ifc_class", text="", icon="RESTRICT_SELECT_OFF").ifc_class = data["type"]
|
2021-04-18 20:24:08 +10:00
|
|
|
row.operator("bim.copy_class", icon="DUPLICATE", text="")
|
2021-03-09 12:50:50 +11:00
|
|
|
row.operator("bim.unlink_object", icon="UNLINKED", text="")
|
2021-04-22 14:00:18 +10:00
|
|
|
if IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcRoot"):
|
|
|
|
|
row.operator("bim.enable_reassign_class", icon="GREASEPENCIL", text="")
|
2021-03-13 09:58:12 +11:00
|
|
|
if context.selected_objects:
|
|
|
|
|
row.operator("bim.unassign_class", icon="X", text="")
|
|
|
|
|
else:
|
|
|
|
|
row.operator("bim.unassign_class", icon="X", text="").obj = context.active_object.name
|
2021-01-04 13:07:29 +11:00
|
|
|
else:
|
2021-08-19 22:26:00 +02:00
|
|
|
ifc_predefined_types = root_prop.getIfcPredefinedTypes(context.scene.BIMRootProperties, context)
|
|
|
|
|
self.draw_class_dropdowns(context, ifc_predefined_types)
|
2021-01-04 13:07:29 +11:00
|
|
|
row = self.layout.row(align=True)
|
|
|
|
|
op = row.operator("bim.assign_class")
|
2021-07-29 23:08:17 +02:00
|
|
|
op.ifc_class = context.scene.BIMRootProperties.ifc_class
|
2021-08-19 22:26:00 +02:00
|
|
|
op.predefined_type = context.scene.BIMRootProperties.ifc_predefined_type if ifc_predefined_types else ""
|
2021-07-29 23:08:17 +02:00
|
|
|
op.userdefined_type = context.scene.BIMRootProperties.ifc_userdefined_type
|
2021-01-04 13:07:29 +11:00
|
|
|
|
2021-08-19 22:26:00 +02:00
|
|
|
def draw_class_dropdowns(self, context, ifc_predefined_types):
|
2021-07-29 23:08:17 +02:00
|
|
|
props = context.scene.BIMRootProperties
|
2021-01-04 13:07:29 +11:00
|
|
|
row = self.layout.row()
|
|
|
|
|
row.prop(props, "ifc_product")
|
|
|
|
|
row = self.layout.row()
|
|
|
|
|
row.prop(props, "ifc_class")
|
2021-08-19 22:26:00 +02:00
|
|
|
if ifc_predefined_types:
|
2021-01-04 13:07:29 +11:00
|
|
|
row = self.layout.row()
|
|
|
|
|
row.prop(props, "ifc_predefined_type")
|
2021-08-19 22:26:00 +02:00
|
|
|
if ifc_predefined_types == "USERDEFINED":
|
2021-01-04 13:07:29 +11:00
|
|
|
row = self.layout.row()
|
|
|
|
|
row.prop(props, "ifc_userdefined_type")
|
2021-03-10 21:10:00 +11:00
|
|
|
row = self.layout.row()
|
2021-07-29 23:08:17 +02:00
|
|
|
row.prop(context.scene.BIMProperties, "contexts")
|