Skip to content

Commit df7599c

Browse files
authored
Ability to show outlines by cell or material independent of "Color by" (#167)
1 parent c7c274c commit df7599c

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

openmc_plotter/docks.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,10 @@ def _createOptionsBox(self):
221221
self.main_window.editPlotVisibility)
222222

223223
# Outlines
224-
self.outlinesBox = QCheckBox(self)
225-
self.outlinesBox.stateChanged.connect(self.main_window.toggleOutlines)
224+
self.outlinesCellBox = QCheckBox(self)
225+
self.outlinesCellBox.stateChanged.connect(self.main_window.toggleOutlinesCell)
226+
self.outlinesMatBox = QCheckBox(self)
227+
self.outlinesMatBox.stateChanged.connect(self.main_window.toggleOutlinesMat)
226228

227229
# Basis
228230
self.basisBox = QComboBox(self)
@@ -247,7 +249,8 @@ def _createOptionsBox(self):
247249
self.opLayout.addRow('Universe Level:', self.universeLevelBox)
248250
self.opLayout.addRow('Plot alpha:', self.domainAlphaBox)
249251
self.opLayout.addRow('Visible:', self.visibilityBox)
250-
self.opLayout.addRow('Outlines:', self.outlinesBox)
252+
self.opLayout.addRow('Cell Outlines:', self.outlinesCellBox)
253+
self.opLayout.addRow('Material Outlines:', self.outlinesMatBox)
251254
self.opLayout.addRow(self.colorOptionsButton)
252255
self.opLayout.setLabelAlignment(QtCore.Qt.AlignLeft)
253256
self.opLayout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
@@ -331,7 +334,8 @@ def updatePlotVisibility(self):
331334
self.visibilityBox.setChecked(self.model.activeView.domainVisible)
332335

333336
def updateOutlines(self):
334-
self.outlinesBox.setChecked(self.model.activeView.outlines)
337+
self.outlinesCellBox.setChecked(self.model.activeView.outlinesCell)
338+
self.outlinesMatBox.setChecked(self.model.activeView.outlinesMat)
335339

336340
def updateBasis(self):
337341
self.basisBox.setCurrentText(self.model.activeView.basis)

openmc_plotter/main_window.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def createMenuBar(self):
375375
self.outlineAct.setToolTip('Display Cell/Material Boundaries')
376376
self.outlineAct.setStatusTip('Toggle display of domain '
377377
'outlines when enabled')
378-
outline_connector = partial(self.toggleOutlines, apply=True)
378+
outline_connector = partial(self.toggleOutlinesCell, apply=True)
379379
self.outlineAct.toggled.connect(outline_connector)
380380
self.editMenu.addAction(self.outlineAct)
381381

@@ -444,7 +444,7 @@ def updateEditMenu(self):
444444

445445
self.maskingAction.setChecked(self.model.currentView.masking)
446446
self.highlightingAct.setChecked(self.model.currentView.highlighting)
447-
self.outlineAct.setChecked(self.model.currentView.outlines)
447+
self.outlineAct.setChecked(self.model.currentView.outlinesCell)
448448
self.overlapAct.setChecked(self.model.currentView.color_overlaps)
449449

450450
num_previous_views = len(self.model.previousViews)
@@ -549,6 +549,11 @@ def loadViewFile(self, filename):
549549

550550
if saved['version'] == self.model.version:
551551
self.model.activeView = saved['current']
552+
# Handle backward compatibility for outline attributes
553+
if not hasattr(self.model.activeView, 'outlinesCell'):
554+
self.model.activeView.outlinesCell = False
555+
if not hasattr(self.model.activeView, 'outlinesMat'):
556+
self.model.activeView.outlinesMat = False
552557
self.dock.updateDock()
553558
self.colorDialog.updateDialogValues()
554559
self.applyChanges()
@@ -877,8 +882,15 @@ def editPlotAlpha(self, value):
877882
def editPlotVisibility(self, value):
878883
self.model.activeView.domainVisible = bool(value)
879884

880-
def toggleOutlines(self, value, apply=False):
881-
self.model.activeView.outlines = bool(value)
885+
def toggleOutlinesCell(self, value, apply=False):
886+
self.model.activeView.outlinesCell = bool(value)
887+
self.dock.updateOutlines()
888+
889+
if apply:
890+
self.applyChanges()
891+
892+
def toggleOutlinesMat(self, value, apply=False):
893+
self.model.activeView.outlinesMat = bool(value)
882894
self.dock.updateOutlines()
883895

884896
if apply:

openmc_plotter/plotgui.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -705,17 +705,28 @@ def plotSourceSites(self):
705705
def add_outlines(self):
706706
cv = self.model.currentView
707707
# draw outlines as isocontours
708-
if cv.outlines:
708+
if cv.outlinesCell or cv.outlinesMat:
709709
# set data extents for automatic reporting of pointer location
710710
data_bounds = self.current_view_data_bounds()
711-
levels = np.unique(self.model.ids)
712-
self.contours = self.ax.contour(self.model.ids,
713-
origin='upper',
714-
colors='k',
715-
linestyles='solid',
716-
levels=levels,
717-
extent=data_bounds,
718-
algorithm='serial')
711+
if cv.outlinesCell:
712+
levels = np.unique(self.model.cell_ids)
713+
self.ax.contour(self.model.cell_ids,
714+
origin='upper',
715+
colors='k',
716+
linestyles='solid',
717+
levels=levels,
718+
extent=data_bounds,
719+
algorithm='serial')
720+
if cv.outlinesMat:
721+
levels = np.unique(self.model.mat_ids)
722+
self.ax.contour(self.model.mat_ids,
723+
origin='upper',
724+
colors='k',
725+
linestyles='solid',
726+
levels=levels,
727+
extent=data_bounds,
728+
algorithm='serial')
729+
719730

720731
@staticmethod
721732
def parseContoursLine(line):

openmc_plotter/plotmodel.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,10 @@ class PlotViewIndependent:
919919
Alpha value of the geometry plot
920920
plotVisibile : bool
921921
Controls visibility of geometry
922-
outlines: bool
923-
Controls visibility of geometry outlines
922+
outlinesCell : bool
923+
Controls visibility of cell outlines
924+
outlinesMat : bool
925+
Controls visibility of material outlines
924926
tallyDataColormap : str
925927
Name of the colormap used for tally data
926928
tallyDataVisible : bool
@@ -962,7 +964,8 @@ def __init__(self):
962964
self.overlap_color = (255, 0, 0)
963965
self.domainAlpha = 1.0
964966
self.domainVisible = True
965-
self.outlines = False
967+
self.outlinesCell = False
968+
self.outlinesMat = False
966969
self.colormaps = {'temperature': 'Oranges', 'density': 'Greys'}
967970
# set defaults for color dialog
968971
self.data_minmax = {prop: (0.0, 0.0) for prop in _MODEL_PROPERTIES}
@@ -988,6 +991,15 @@ def __init__(self):
988991
self.tallyContours = False
989992
self.tallyContourLevels = ""
990993

994+
def __setstate__(self, state):
995+
"""Handle backward compatibility when unpickling old views"""
996+
self.__dict__.update(state)
997+
# Add missing attributes from older versions
998+
if not hasattr(self, 'outlinesCell'):
999+
self.outlinesCell = False
1000+
if not hasattr(self, 'outlinesMat'):
1001+
self.outlinesMat = False
1002+
9911003
def getDataLimits(self):
9921004
return self.data_minmax
9931005

0 commit comments

Comments
 (0)