1616# You should have received a copy of the GNU General Public License
1717# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
1818
19+ import blenderbim .tool as tool
1920import blenderbim .bim .module .type .prop as type_prop
2021from bpy .types import Panel
2122from blenderbim .bim .ifc import IfcStore
22- from ifcopenshell . api . type .data import Data
23+ from blenderbim . bim . module . type .data import TypeData
2324
2425
2526class BIM_PT_type (Panel ):
@@ -33,23 +34,20 @@ class BIM_PT_type(Panel):
3334 def poll (cls , context ):
3435 if not context .active_object :
3536 return False
36- props = context .active_object .BIMObjectProperties
37- if not props .ifc_definition_id :
38- return False
39- if not IfcStore .get_element (props .ifc_definition_id ):
40- return False
41- if props .ifc_definition_id not in Data .products and props .ifc_definition_id not in Data .types :
42- Data .load (IfcStore .get_file (), props .ifc_definition_id )
43- if props .ifc_definition_id not in Data .products and props .ifc_definition_id not in Data .types :
44- return False
45- if not Data .products .get (props .ifc_definition_id , None ) and not Data .types .get (props .ifc_definition_id , None ):
37+ element = tool .Ifc .get_entity (context .active_object )
38+ if not element :
4639 return False
40+ if not element .is_a ("IfcProduct" ) and not element .is_a ("IfcTypeProduct" ):
41+ return True
4742 return True
4843
4944 def draw (self , context ):
45+ if not TypeData .is_loaded :
46+ TypeData .load ()
47+
5048 oprops = context .active_object .BIMObjectProperties
5149
52- if oprops . ifc_definition_id in Data . products :
50+ if TypeData . data [ "is_product" ] :
5351 self .draw_product_ui (context )
5452 else :
5553 self .draw_type_ui (context )
@@ -58,7 +56,7 @@ def draw_type_ui(self, context):
5856 props = context .active_object .BIMTypeProperties
5957 oprops = context .active_object .BIMObjectProperties
6058 row = self .layout .row (align = True )
61- row .label (text = f"{ len ( Data . types [ oprops . ifc_definition_id ]) } Typed Objects" )
59+ row .label (text = f"{ TypeData . data [ 'total_instances' ] } Typed Objects" )
6260 row .operator ("bim.select_type_objects" , icon = "RESTRICT_SELECT_OFF" , text = "" )
6361
6462 def draw_product_ui (self , context ):
@@ -69,26 +67,23 @@ def draw_product_ui(self, context):
6967 row = self .layout .row (align = True )
7068
7169 row .prop (props , "relating_type_class" , text = "" )
72- if type_prop .get_object_relating_type (None , context ):
70+ if type_prop .get_relating_type (None , context ):
7371 row .prop (props , "relating_type" , text = "" )
7472 row .operator ("bim.assign_type" , icon = "CHECKMARK" , text = "" )
7573 else :
7674 row .label (text = "No Types Found" )
7775 row .operator ("bim.disable_editing_type" , icon = "CANCEL" , text = "" )
7876 else :
7977 row = self .layout .row (align = True )
80- name = "{}/{}" .format (
81- Data .products [oprops .ifc_definition_id ]["type" ], Data .products [oprops .ifc_definition_id ]["Name" ]
82- )
83- if name == "None/None" :
84- row .label (text = "This object has no type" )
85- row .operator ("bim.enable_editing_type" , icon = "GREASEPENCIL" , text = "" )
86- else :
87- row .label (text = name )
78+ if TypeData .data ["type_name" ]:
79+ row .label (text = TypeData .data ["type_name" ])
8880 row .operator ("bim.select_type" , icon = "TRACKER" , text = "" )
8981 row .operator ("bim.select_similar_type" , icon = "RESTRICT_SELECT_OFF" , text = "" )
9082 row .operator ("bim.enable_editing_type" , icon = "GREASEPENCIL" , text = "" )
9183 row .operator ("bim.unassign_type" , icon = "X" , text = "" )
84+ else :
85+ row .label (text = "This object has no type" )
86+ row .operator ("bim.enable_editing_type" , icon = "GREASEPENCIL" , text = "" )
9287
9388
9489def add_object_button (self , context ):
0 commit comments