Skip to content

Commit

Permalink
Clean up interface for source site sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano committed Jun 19, 2024
1 parent affd307 commit 367996d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion openmc_plotter/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def createMenuBar(self):
self.openStatePointAction.setToolTip('Open statepoint file')
self.openStatePointAction.triggered.connect(self.openStatePoint)

self.sourceSitesAction = QAction('&Sample Source Sites...', self)
self.sourceSitesAction = QAction('&Sample source sites...', self)
self.sourceSitesAction.setToolTip('Add source sites to plot')
self.setStatusTip('Sample and add source sites to the plot')
self.sourceSitesAction.triggered.connect(self.plotSourceSites)
Expand Down
2 changes: 1 addition & 1 deletion openmc_plotter/plotgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def plotSourceSites(self):
self.ax.scatter([s[h_idx] for s in sites_to_plot],
[s[v_idx] for s in sites_to_plot],
marker='o',
color=self.model.sourceSitesColor)
color=rgb_normalize(self.model.sourceSitesColor))

def add_outlines(self):
cv = self.model.currentView
Expand Down
4 changes: 2 additions & 2 deletions openmc_plotter/plotmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class PlotModel:
in plot explorer
sourceSitesTolerance : float
Tolerance for source site plotting (default 0.1 cm)
sourceSitesColor : tuple of 3 floats
sourceSitesColor : tuple of 3 int
RGB color for source site plotting (default blue)
sourceSitesVisible : bool
Whether to plot source sites (default True)
Expand Down Expand Up @@ -189,7 +189,7 @@ def __init__(self, use_settings_pkl, model_path, default_res):
# Source site defaults
self.sourceSitesApplyTolerance = False
self.sourceSitesTolerance = 0.1 # cm
self.sourceSitesColor = (0, 0, 1)
self.sourceSitesColor = (0, 0, 255)
self.sourceSitesVisible = True
self.sourceSites = None

Expand Down
65 changes: 33 additions & 32 deletions openmc_plotter/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,64 +12,62 @@ class SourceSitesDialog(QtWidgets.QDialog):
def __init__(self, model, font_metric, parent=None):
super().__init__(parent)

self.setWindowTitle('Sample Source Sites')
self.model = model
self.font_metric = font_metric
self.parent = parent

self.layout = QtWidgets.QGridLayout()
self.layout = QtWidgets.QFormLayout()
self.setLayout(self.layout)

def show(self):
self.populate()
super().show()

def populate(self):
row = 0
self.layout.addWidget(QtWidgets.QLabel("Source Sites:"), row, 100)
self.nSitesBox = QtWidgets.QSpinBox()
self.nSitesBox = QtWidgets.QSpinBox(self)
self.nSitesBox.setMaximum(1_000_000)
self.nSitesBox.setMinimum(0)
self.nSitesBox.setValue(1000)
self.nSitesBox.setToolTip('Number of source sites to sample from the OpenMC source')
self.layout.addWidget(self.nSitesBox, row, 1)
self.sampleButton = QtWidgets.QPushButton("Sample New Sites")
self.sampleButton.setToolTip('Sample new source sites from the OpenMC source')
self.sampleButton.clicked.connect(self._sample_sites)
self.layout.addWidget(self.sampleButton, row, 2, 1, 2)

row += 1
self.sites_visible = QtWidgets.QCheckBox("Source Sites Visible")
self.sites_visible = QtWidgets.QCheckBox(self)
self.sites_visible.setChecked(self.model.sourceSitesVisible)
self.sites_visible.setToolTip('Toggle visibility of source sites on the slice plane')
self.sites_visible.stateChanged.connect(self._toggle_source_sites)
self.layout.addWidget(self.sites_visible, row, 0, 1, 2)
self.colorButton = QtWidgets.QPushButton("Select Color")

self.colorButton = QtWidgets.QPushButton(self)
self.colorButton.setToolTip('Select color for displaying source sites on the slice plane')
self.colorButton.setCursor(QtCore.Qt.PointingHandCursor)
self.colorButton.setFixedHeight(self.font_metric.height() * 1.5)
self.colorButton.clicked.connect(self._select_source_site_color)
self.layout.addWidget(self.colorButton, row, 2, 1, 2)
rgb = self.model.sourceSitesColor
self.colorButton.setStyleSheet(
f"border-radius: 8px; background-color: rgb{rgb}")

row += 1
self.toleranceToggle = QtWidgets.QCheckBox()
self.toleranceToggle.setChecked(self.model.sourceSitesApplyTolerance)
self.toleranceToggle.stateChanged.connect(self._toggle_tolerance)
self.layout.addWidget(self.toleranceToggle, row, 0)
tolerance_tip = 'Slice axis tolerance for displaying source sites on the slice plane'
self.toleranceBox = ScientificDoubleSpinBox()
self.toleranceBox.setToolTip(tolerance_tip)
self.toleranceBox.setToolTip('Slice axis tolerance for displaying source sites on the slice plane')
self.toleranceBox.setValue(self.model.sourceSitesTolerance)
self.toleranceBox.valueChanged.connect(self._set_source_site_tolerance)
self.toleranceBox.setEnabled(self.model.sourceSitesApplyTolerance)
label = QtWidgets.QLabel("Tolerance:")
label.setToolTip(tolerance_tip)
self.layout.addWidget(label, row, 1)
self.layout.addWidget(self.toleranceBox, row, 2)

row += 1
self.layout.addWidget(HorizontalLine(), row, 0, 1, 4)
self.toleranceToggle = QtWidgets.QCheckBox(self)
self.toleranceToggle.setChecked(self.model.sourceSitesApplyTolerance)
self.toleranceToggle.stateChanged.connect(self._toggle_tolerance)

self.sampleButton = QtWidgets.QPushButton("Sample New Sites")
self.sampleButton.setToolTip('Sample new source sites from the OpenMC source')
self.sampleButton.clicked.connect(self._sample_sites)

row += 1
self.closeButton = QtWidgets.QPushButton("Close")
self.closeButton.clicked.connect(self.close)
self.layout.addWidget(self.closeButton, row, 3)

self.layout.addRow("Source Sites:", self.nSitesBox)
self.layout.addRow("Visible:", self.sites_visible)
self.layout.addRow("Color:", self.colorButton)
self.layout.addRow('Tolerance:', self.toleranceBox)
self.layout.addRow('Apply tolerance:', self.toleranceToggle)
self.layout.addRow(HorizontalLine())
self.layout.addRow(self.sampleButton)
self.layout.addRow(self.closeButton)

def _sample_sites(self):
self.model.getExternalSourceSites(self.nSitesBox.value())
Expand All @@ -82,7 +80,9 @@ def _toggle_source_sites(self):
def _select_source_site_color(self):
color = QtWidgets.QColorDialog.getColor()
if color.isValid():
self.model.sourceSitesColor = color.getRgbF()
rgb = self.model.sourceSitesColor = color.getRgb()[:3]
self.colorButton.setStyleSheet(
f"border-radius: 8px; background-color: rgb{rgb}")
self.parent.applyChanges()

def _toggle_tolerance(self):
Expand All @@ -94,6 +94,7 @@ def _set_source_site_tolerance(self):
self.model.sourceSitesTolerance = self.toleranceBox.value()
self.parent.applyChanges()


class ExportDataDialog(QtWidgets.QDialog):
"""
A dialog to facilitate generation of VTK files for
Expand Down

0 comments on commit 367996d

Please sign in to comment.