2323from blenderbim .bim .module .system .data import SystemData , ObjectSystemData , PortData
2424
2525
26+ FLOW_DIRECTION_TO_ICON = {
27+ "SOURCE" : "FORWARD" ,
28+ "SINK" : "BACK" ,
29+ "SOURCEANDSINK" : "ARROW_LEFTRIGHT" ,
30+ "NOTDEFINED" : "RESTRICT_INSTANCED_ON" ,
31+ }
32+
33+
2634class BIM_PT_systems (Panel ):
2735 bl_label = "Systems"
2836 bl_idname = "BIM_PT_systems"
@@ -156,11 +164,43 @@ def draw(self, context):
156164 self .props = context .scene .BIMSystemProperties
157165
158166 row = self .layout .row (align = True )
159- row .label (text = f"{ PortData .data ['total_ports' ]} Ports Found" , icon = "PLUGIN" )
167+ total_ports = PortData .data ["total_ports" ]
168+ row .label (text = f"{ total_ports } Ports Found" , icon = "PLUGIN" )
160169 row .operator ("bim.show_ports" , icon = "HIDE_OFF" , text = "" )
161170 row .operator ("bim.hide_ports" , icon = "HIDE_ON" , text = "" )
162171 row .operator ("bim.add_port" , icon = "ADD" , text = "" )
163172
173+ if total_ports == 0 :
174+ return
175+
176+ row = self .layout .row (align = True )
177+ row .label (text = "Ports located on object and connected objects:" )
178+ row = self .layout .row (align = True )
179+ cols = [row .column (align = True ) for i in range (6 )]
180+
181+ for i , port_data in enumerate (PortData .data ["located_ports_data" ]):
182+ port , port_obj , connected_obj = port_data
183+ flow_direction_icon = FLOW_DIRECTION_TO_ICON [port .FlowDirection or "NOTDEFINED" ]
184+ if port_obj :
185+ cols [0 ].label (text = "" , icon = flow_direction_icon )
186+ cols [1 ].operator ("bim.select_entity" , text = "" , icon = "RESTRICT_SELECT_OFF" ).ifc_id = port .id ()
187+ cols [2 ].label (text = port_obj .name )
188+ else :
189+ cols [0 ].label (text = "" , icon = flow_direction_icon )
190+ cols [1 ].label (text = "" , icon = "HIDE_ON" )
191+ cols [2 ].label (text = "Port is hidden" )
192+
193+ if connected_obj :
194+ cols [3 ].operator ("bim.disconnect_port" , text = "" , icon = "UNLINKED" ).element_id = port .id ()
195+ cols [4 ].operator (
196+ "bim.select_entity" , text = "" , icon = "RESTRICT_SELECT_OFF"
197+ ).ifc_id = connected_obj .BIMObjectProperties .ifc_definition_id
198+ cols [5 ].label (text = f"{ connected_obj .name } " )
199+ else :
200+ cols [3 ].label (text = "" , icon = "UNLINKED" )
201+ cols [4 ].label (text = "" , icon = "BLANK1" )
202+ cols [5 ].label (text = "Port is disconnected" )
203+
164204
165205class BIM_PT_port (Panel ):
166206 bl_label = "Port"
@@ -184,36 +224,56 @@ def poll(cls, context):
184224 def draw (self , context ):
185225 self .props = context .scene .BIMSystemProperties
186226
187- element = tool .Ifc .get_entity (context .active_object )
188- port_class = element .is_a ()
189227 layout = self .layout
190228 row = layout .row (align = True )
191- row .label (text = port_class )
229+ row .label (text = "IfcDistributionPort" )
192230 row .operator ("bim.connect_port" , icon = "PLUGIN" , text = "" )
193231 row .operator ("bim.disconnect_port" , icon = "UNLINKED" , text = "" )
194232 row .operator ("bim.remove_port" , icon = "X" , text = "" )
195233
196- if port_class == "IfcDistributionPort" :
197- current_flow_direction = str (element .FlowDirection )
198- row = layout .row (align = True )
199- row .label (text = "Flow Direction:" )
200- row .label (text = current_flow_direction )
201-
202- # TODO: replace with enum property?
203- flow_directions = (
204- ("SOURCE" , "FORWARD" ),
205- ("SINK" , "BACK" ),
206- ("SOURCEANDSINK" , "ARROW_LEFTRIGHT" ),
207- ("NOTDEFINED" , "RESTRICT_INSTANCED_ON" ),
208- )
234+ if not PortData .is_loaded :
235+ PortData .load ()
209236
210- row = layout .row (align = True )
211- row .label (text = "Change Flow Direction:" )
212- for flow_direction , icon in flow_directions :
213- row = layout .row ()
214- row .operator ("bim.set_flow_direction" , icon = icon , text = flow_direction ).direction = flow_direction
215- if flow_direction == current_flow_direction :
216- row .enabled = False
237+ if not PortData .data ["is_port" ]:
238+ return
239+
240+ element = tool .Ifc .get_entity (context .active_object )
241+ current_flow_direction = str (element .FlowDirection )
242+ row = layout .row (align = True )
243+ row .label (text = "Flow Direction:" )
244+ row .label (text = current_flow_direction )
245+
246+ # port located on
247+ row = layout .row (align = True )
248+ relating_object = PortData .data ["port_relating_object" ]
249+ row .label (text = "Port located on:" )
250+ row .label (text = relating_object .name )
251+ row .operator (
252+ "bim.select_entity" , text = "" , icon = "RESTRICT_SELECT_OFF"
253+ ).ifc_id = relating_object .BIMObjectProperties .ifc_definition_id
254+
255+ # object connected to the port
256+ row = layout .row (align = True )
257+ connected_object = PortData .data ["port_connected_object" ]
258+ if connected_object :
259+ row .label (text = "Port connected to:" )
260+ row .label (text = connected_object .name )
261+ row .operator (
262+ "bim.select_entity" , text = "" , icon = "RESTRICT_SELECT_OFF"
263+ ).ifc_id = connected_object .BIMObjectProperties .ifc_definition_id
264+ else :
265+ row .label (text = "Port is not connected to any element" )
266+
267+ # TODO: replace with enum property?
268+ row = layout .row (align = True )
269+ row .label (text = "Change Flow Direction:" )
270+ for flow_direction in FLOW_DIRECTION_TO_ICON .keys ():
271+ row = layout .row ()
272+ row .operator (
273+ "bim.set_flow_direction" , icon = FLOW_DIRECTION_TO_ICON [flow_direction ], text = flow_direction
274+ ).direction = flow_direction
275+ if flow_direction == current_flow_direction :
276+ row .enabled = False
217277
218278
219279class BIM_UL_systems (UIList ):
0 commit comments