Skip to content

Commit 58e531c

Browse files
committed
Simplify ID logic and labels
1 parent c9c0358 commit 58e531c

1 file changed

Lines changed: 18 additions & 23 deletions

File tree

openmc_plotter/plotgui.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import io
22
from functools import partial
3-
import openmc
43

54
from PySide6 import QtCore, QtGui
65
from PySide6.QtWidgets import (QWidget, QPushButton, QHBoxLayout, QVBoxLayout,
@@ -311,15 +310,7 @@ def getIDinfo(self, event):
311310
and 0 <= xPos and xPos < self.model.currentView.h_res:
312311
cell_id = int(self.model.cell_ids[yPos, xPos])
313312
mat_id = int(self.model.mat_ids[yPos, xPos])
314-
if self.model.currentView.colorby == 'cell':
315-
id = cell_id
316-
else:
317-
id = mat_id
318-
if id == _OVERLAP:
319-
if cell_id < _OVERLAP:
320-
id = cell_id
321-
elif mat_id < _OVERLAP:
322-
id = mat_id
313+
id = self._domainId(cell_id, mat_id)
323314
instance = self.model.instances[yPos, xPos]
324315
temp = "{:g}".format(self.model.property_data[yPos, xPos, 0])
325316
density = "{:g}".format(self.model.property_data[yPos, xPos, 1])
@@ -347,6 +338,20 @@ def getIDinfo(self, event):
347338

348339
return id, instance, properties, domain, domain_kind
349340

341+
def _domainId(self, cell_id, mat_id):
342+
if self.model.currentView.colorby != 'cell':
343+
return mat_id
344+
if cell_id == _OVERLAP and mat_id < _OVERLAP:
345+
return mat_id
346+
return cell_id
347+
348+
def _cellLabel(self, cell_id):
349+
try:
350+
name = self.model.activeView.cells[cell_id].name
351+
except KeyError:
352+
name = None
353+
return f"{cell_id} ({name})" if name else str(cell_id)
354+
350355
def _overlapInfo(self, id):
351356
if id == _OVERLAP:
352357
return "OVERLAP"
@@ -356,19 +361,9 @@ def _overlapInfo(self, id):
356361
return "OVERLAP (unknown region)"
357362

358363
universe, cell1, cell2 = self.model.overlap_map[overlap_idx]
359-
try:
360-
name1 = self.model.activeView.cells[cell1].name or str(cell1)
361-
except KeyError:
362-
name1 = str(cell1)
363-
try:
364-
name2 = self.model.activeView.cells[cell2].name or str(cell2)
365-
except KeyError:
366-
name2 = str(cell2)
367-
368-
return (
369-
f"OVERLAP: Universe {universe}, "
370-
f"Cells {name1} and {name2}"
371-
)
364+
label1 = self._cellLabel(cell1)
365+
label2 = self._cellLabel(cell2)
366+
return f"OVERLAP: Universe {universe}, Cells {label1} and {label2}"
372367

373368
def mouseDoubleClickEvent(self, event):
374369
xCenter, yCenter = self.getPlotCoords(event.pos())

0 commit comments

Comments
 (0)