Skip to content

Commit

Permalink
Allow user to change default resolution from command line (#140)
Browse files Browse the repository at this point in the history
* Allow user to change default resolution from command line

* Apply default_res to restored view
  • Loading branch information
paulromano authored Jun 5, 2024
1 parent 52f82d2 commit f58d349
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
5 changes: 4 additions & 1 deletion openmc_plotter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def main():
help='Ignore plot_settings.pkl file if present.')
ap.add_argument('-s', '--threads', type=int, default=None,
help='If present, number of threads used to generate plots.')
ap.add_argument('-r', '--resolution', type=int, default=None,
help='Default number of pixels in each direction')
ap.add_argument('model_path', nargs='?', default=os.curdir,
help='Location of model XML file or a directory containing '
'XML files (default is current dir)')
Expand Down Expand Up @@ -68,7 +70,8 @@ def run_app(user_args):

font_metric = QtGui.QFontMetrics(app.font())
screen_size = app.primaryScreen().size()
mainWindow = MainWindow(font_metric, screen_size, user_args.model_path, user_args.threads)
mainWindow = MainWindow(font_metric, screen_size, user_args.model_path,
user_args.threads, user_args.resolution)
# connect splashscreen to main window, close when main window opens
mainWindow.loadGui(use_settings_pkl=user_args.ignore_settings)

Expand Down
7 changes: 5 additions & 2 deletions openmc_plotter/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ class MainWindow(QMainWindow):
def __init__(self,
font=QtGui.QFontMetrics(QtGui.QFont()),
screen_size=QtCore.QSize(),
model_path='.', threads=None):
model_path='.',
threads=None,
resolution=None):
super().__init__()

self.screen = screen_size
self.font_metric = font
self.setWindowTitle('OpenMC Plot Explorer')
self.model_path = Path(model_path)
self.threads = threads
self.default_res = resolution

def loadGui(self, use_settings_pkl=True):

Expand Down Expand Up @@ -471,7 +474,7 @@ def loadModel(self, reload=False, use_settings_pkl=True):
if reload:
self.resetModels()
else:
self.model = PlotModel(use_settings_pkl, self.model_path)
self.model = PlotModel(use_settings_pkl, self.model_path, self.default_res)

# update plot and model settings
self.updateRelativeBases()
Expand Down
38 changes: 28 additions & 10 deletions openmc_plotter/plotmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class PlotModel:
If True, use plot_settings.pkl file to reload settings
model_path : pathlib.Path
Path to model XML file or directory
default_res : int
Default resolution as the number of pixels in each direction
Attributes
----------
Expand Down Expand Up @@ -147,7 +149,7 @@ class PlotModel:
have unapplied changes
"""

def __init__(self, use_settings_pkl, model_path):
def __init__(self, use_settings_pkl, model_path, default_res):
""" Initialize PlotModel class attributes """

# Retrieve OpenMC Cells/Materials
Expand All @@ -174,7 +176,7 @@ def __init__(self, use_settings_pkl, model_path):
self.previousViews = []
self.subsequentViews = []

self.defaultView = self.getDefaultView()
self.defaultView = self.getDefaultView(default_res)

if model_path.is_file():
settings_pkl = model_path.with_name('plot_settings.pkl')
Expand Down Expand Up @@ -228,7 +230,8 @@ def __init__(self, use_settings_pkl, model_path):
self.statepoint = None

self.currentView = PlotView(restore_view=view,
restore_domains=restore_domains)
restore_domains=restore_domains,
default_res=default_res)

else:
self.currentView = copy.deepcopy(self.defaultView)
Expand Down Expand Up @@ -256,14 +259,19 @@ def statepoint(self, statepoint):
if self._statepoint and not self._statepoint.is_open:
self._statepoint.open()

def getDefaultView(self):
def getDefaultView(self, default_res):
""" Generates default PlotView instance for OpenMC geometry
Centers plot view origin in every dimension if possible. Defaults
to xy basis, with height and width to accomodate full size of
geometry. Defaults to (0, 0, 0) origin with width and heigth of
25 if geometry bounding box cannot be generated.
Parameters
----------
default_res : int
Default resolution as the number of pixels in each direction
Returns
-------
default : PlotView instance
Expand All @@ -286,7 +294,8 @@ def getDefaultView(self):
else:
zcenter = 0.00

default = PlotView([xcenter, ycenter, zcenter], width, height)
default = PlotView([xcenter, ycenter, zcenter], width, height,
default_res=default_res)
return default

def resetColors(self):
Expand Down Expand Up @@ -760,6 +769,8 @@ class ViewParam(openmc.lib.plot._PlotBase):
Width of plot view in model units
height : float
Height of plot view in model units
default_res : int
Default resolution as the number of pixels in each direction
Attributes
----------
Expand All @@ -781,7 +792,7 @@ class ViewParam(openmc.lib.plot._PlotBase):
The universe level for the plot (default: -1 -> all universes shown)
"""

def __init__(self, origin=(0, 0, 0), width=10, height=10):
def __init__(self, origin=(0, 0, 0), width=10, height=10, default_res=1000):
"""Initialize ViewParam attributes"""
super().__init__()

Expand All @@ -790,8 +801,8 @@ def __init__(self, origin=(0, 0, 0), width=10, height=10):
self.origin = origin
self.width = width
self.height = height
self.h_res = 1000
self.v_res = 1000
self.h_res = default_res
self.v_res = default_res
self.basis = 'xy'
self.color_overlaps = False

Expand Down Expand Up @@ -976,15 +987,22 @@ class PlotView:
'h_res', 'v_res', 'basis', 'llc', 'urc', 'color_overlaps')

def __init__(self, origin=(0, 0, 0), width=10, height=10, restore_view=None,
restore_domains=False):
restore_domains=False, default_res=None):
"""Initialize PlotView attributes"""

if restore_view is not None:
self.view_ind = copy.copy(restore_view.view_ind)
self.view_params = copy.copy(restore_view.view_params)
if default_res is not None:
p = self.view_params
p.h_res = default_res
p.v_res = int(default_res * p.height / p.width)
else:
self.view_ind = PlotViewIndependent()
self.view_params = ViewParam(origin=origin, width=width, height=height)
if default_res is not None:
self.view_params = ViewParam(origin, width, height, default_res)
else:
self.view_params = ViewParam(origin, width, height)

# Get model domain info
if restore_domains and restore_view is not None:
Expand Down

0 comments on commit f58d349

Please sign in to comment.