|
8 | 8 | from .scientific_spin_box import ScientificDoubleSpinBox |
9 | 9 |
|
10 | 10 |
|
| 11 | +class SourceSitesDialog(QtWidgets.QDialog): |
| 12 | + def __init__(self, model, font_metric, parent=None): |
| 13 | + super().__init__(parent) |
| 14 | + |
| 15 | + self.setWindowTitle('Sample Source Sites') |
| 16 | + self.model = model |
| 17 | + self.font_metric = font_metric |
| 18 | + self.parent = parent |
| 19 | + |
| 20 | + self.layout = QtWidgets.QFormLayout() |
| 21 | + self.setLayout(self.layout) |
| 22 | + |
| 23 | + self.populate() |
| 24 | + |
| 25 | + def populate(self): |
| 26 | + self.nSitesBox = QtWidgets.QSpinBox(self) |
| 27 | + self.nSitesBox.setMaximum(1_000_000) |
| 28 | + self.nSitesBox.setMinimum(0) |
| 29 | + self.nSitesBox.setValue(1000) |
| 30 | + self.nSitesBox.setToolTip('Number of source sites to sample from the OpenMC source') |
| 31 | + |
| 32 | + self.sites_visible = QtWidgets.QCheckBox(self) |
| 33 | + self.sites_visible.setChecked(self.model.sourceSitesVisible) |
| 34 | + self.sites_visible.setToolTip('Toggle visibility of source sites on the slice plane') |
| 35 | + self.sites_visible.stateChanged.connect(self._toggle_source_sites) |
| 36 | + |
| 37 | + self.colorButton = QtWidgets.QPushButton(self) |
| 38 | + self.colorButton.setToolTip('Select color for displaying source sites on the slice plane') |
| 39 | + self.colorButton.setCursor(QtCore.Qt.PointingHandCursor) |
| 40 | + self.colorButton.setFixedHeight(self.font_metric.height() * 1.5) |
| 41 | + self.colorButton.clicked.connect(self._select_source_site_color) |
| 42 | + rgb = self.model.sourceSitesColor |
| 43 | + self.colorButton.setStyleSheet( |
| 44 | + f"border-radius: 8px; background-color: rgb{rgb}") |
| 45 | + |
| 46 | + self.toleranceBox = ScientificDoubleSpinBox() |
| 47 | + self.toleranceBox.setToolTip('Slice axis tolerance for displaying source sites on the slice plane') |
| 48 | + self.toleranceBox.setValue(self.model.sourceSitesTolerance) |
| 49 | + self.toleranceBox.valueChanged.connect(self._set_source_site_tolerance) |
| 50 | + self.toleranceBox.setEnabled(self.model.sourceSitesApplyTolerance) |
| 51 | + |
| 52 | + self.toleranceToggle = QtWidgets.QCheckBox(self) |
| 53 | + self.toleranceToggle.setChecked(self.model.sourceSitesApplyTolerance) |
| 54 | + self.toleranceToggle.stateChanged.connect(self._toggle_tolerance) |
| 55 | + |
| 56 | + self.sampleButton = QtWidgets.QPushButton("Sample New Sites") |
| 57 | + self.sampleButton.setToolTip('Sample new source sites from the OpenMC source') |
| 58 | + self.sampleButton.clicked.connect(self._sample_sites) |
| 59 | + |
| 60 | + self.closeButton = QtWidgets.QPushButton("Close") |
| 61 | + self.closeButton.clicked.connect(self.close) |
| 62 | + |
| 63 | + self.layout.addRow("Source Sites:", self.nSitesBox) |
| 64 | + self.layout.addRow("Visible:", self.sites_visible) |
| 65 | + self.layout.addRow("Color:", self.colorButton) |
| 66 | + self.layout.addRow('Tolerance:', self.toleranceBox) |
| 67 | + self.layout.addRow('Apply tolerance:', self.toleranceToggle) |
| 68 | + self.layout.addRow(HorizontalLine()) |
| 69 | + self.layout.addRow(self.sampleButton) |
| 70 | + self.layout.addRow(self.closeButton) |
| 71 | + |
| 72 | + def _sample_sites(self): |
| 73 | + self.model.getExternalSourceSites(self.nSitesBox.value()) |
| 74 | + self.parent.applyChanges() |
| 75 | + |
| 76 | + def _toggle_source_sites(self): |
| 77 | + self.model.sourceSitesVisible = self.sites_visible.isChecked() |
| 78 | + self.parent.applyChanges() |
| 79 | + |
| 80 | + def _select_source_site_color(self): |
| 81 | + color = QtWidgets.QColorDialog.getColor() |
| 82 | + if color.isValid(): |
| 83 | + rgb = self.model.sourceSitesColor = color.getRgb()[:3] |
| 84 | + self.colorButton.setStyleSheet( |
| 85 | + f"border-radius: 8px; background-color: rgb{rgb}") |
| 86 | + self.parent.applyChanges() |
| 87 | + |
| 88 | + def _toggle_tolerance(self): |
| 89 | + self.model.sourceSitesApplyTolerance = self.toleranceToggle.isChecked() |
| 90 | + self.toleranceBox.setEnabled(self.toleranceToggle.isChecked()) |
| 91 | + self.parent.applyChanges() |
| 92 | + |
| 93 | + def _set_source_site_tolerance(self): |
| 94 | + self.model.sourceSitesTolerance = self.toleranceBox.value() |
| 95 | + self.parent.applyChanges() |
| 96 | + |
| 97 | + |
11 | 98 | class ExportDataDialog(QtWidgets.QDialog): |
12 | 99 | """ |
13 | 100 | A dialog to facilitate generation of VTK files for |
|
0 commit comments