Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e42ecd9
rough draft of only restoring view settings, not model settings - thi…
kkiesling Jun 9, 2022
a253599
remove commented lines and functions that are no longer needed
kkiesling Jun 9, 2022
0c6d89f
remove unnecessary import
kkiesling Jun 13, 2022
7ce9e4b
remove missed print statement
kkiesling Jun 22, 2022
5ee873b
more streamlined to use composition over inheritance
kkiesling Jun 22, 2022
1b187f7
trying to asses view equality and populating ids
kkiesling Jun 22, 2022
748baf8
trying to separate just the view parameters from the rest of view ind…
kkiesling Jun 23, 2022
b130f62
separate out only the _PlotBase parameters and check those
kkiesling Jun 23, 2022
95ef00e
only store necessary info for reload in pickle file
kkiesling Jun 24, 2022
4d371be
cleaned up docstrings
kkiesling Jun 29, 2022
e9e92a0
make view params attribute on plotview to simplify
kkiesling Jul 6, 2022
3e996c9
remove debugging print statements
kkiesling Jul 6, 2022
eb34f8b
need to copy view params from previous view
kkiesling Jul 7, 2022
ac39180
updated docstrings for new classes
kkiesling Jul 7, 2022
0ff3ed4
Apply suggestions from code review
kkiesling Jul 8, 2022
ed014f5
issue warning and ignore plot settings if load fails
kkiesling Jul 8, 2022
81b41bb
typo
kkiesling Jul 8, 2022
8051d2f
remove mistaken imports
kkiesling Jul 8, 2022
3ab3f4b
ids_map and prop_map don't need to be private
kkiesling Jul 8, 2022
7e3ecd3
wording changes
kkiesling Jul 11, 2022
ca2eab5
need to add view_params to list of attributes
kkiesling Jul 11, 2022
6ad6cde
increment plotmodel version
kkiesling Jul 11, 2022
08a9a38
simplify try/except statement
kkiesling Jul 11, 2022
635fbf9
use_settings_pkl in docstring
kkiesling Jul 11, 2022
9990c72
store full currentView so that view_ind and view_params are both saved
kkiesling Jul 11, 2022
6a5f909
list of attribures as class attribute
kkiesling Jul 11, 2022
05743d8
restore domain properties if file hashes are unchanged as well
kkiesling Jul 11, 2022
56e12dd
prop_map and properties attributes were redundant
kkiesling Jul 11, 2022
90bf435
adopt_plotbase must be in PlotView to be able to set params
kkiesling Jul 11, 2022
8825405
make cell_ids, instances, and mat_ids properties
kkiesling Jul 11, 2022
ebe5460
make initial view the currentview and always create a default view
kkiesling Jul 13, 2022
9ae7a76
compare active and current views before updating current view to chec…
kkiesling Jul 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove commented lines and functions that are no longer needed
  • Loading branch information
kkiesling committed Jul 7, 2022
commit a2535996b225366941b1618db6db006cd3a5dea3
69 changes: 1 addition & 68 deletions openmc_plotter/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ def _openmcReload(threads=None):
openmc.lib.init(args)
openmc.lib.settings.verbosity = 1

def hash_file(filename):
# return the md5 hash of a file
h = hashlib.md5()
with open(filename,'rb') as file:
chunk = 0
while chunk != b'':
# read 32768 bytes at a time
chunk = file.read(32768)
h.update(chunk)
return h.hexdigest()

class MainWindow(QMainWindow):
def __init__(self,
font=QtGui.QFontMetrics(QtGui.QFont()),
Expand All @@ -62,7 +51,7 @@ def __init__(self,
self.font_metric = font
self.setWindowTitle('OpenMC Plot Explorer')

def loadGui(self, use_settings_pkl=True, use_saved_view=True):
def loadGui(self, use_settings_pkl=True):

self.pixmap = None
self.zoom = 100
Expand Down Expand Up @@ -465,11 +454,7 @@ def loadModel(self, reload=False, use_settings_pkl=True):
if reload:
self.resetModels()
else:
#if use_settings_pkl:
# self.restoreModelSettings()
self.model = PlotModel(use_settings_pkl)
# create new plot model


# update plot and model settings
self.updateRelativeBases()
Expand Down Expand Up @@ -1078,51 +1063,6 @@ def restoreWindowSettings(self):

self.colorDialog.setVisible(is_visible)

def restoreModelSettings(self):
if os.path.isfile("plot_settings.pkl"):

with open('plot_settings.pkl', 'rb') as file:
model = pickle.load(file)

# # check if loaded cell/mat ids hash match the pkl file:
# current_mat_xml_hash = hash_file('materials.xml')
# current_geom_xml_hash = hash_file('geometry.xml')
# if (current_mat_xml_hash != model.mat_xml_hash) or \
# (current_geom_xml_hash != model.geom_xml_hash):
# # hashes do not match so ignore plot_settings.pkl file
# msg_box = QMessageBox()
# msg = "WARNING: Model has changed since storing plot " +\
# "settings. Ignoring previous plot settings."
# msg_box.setText(msg)
# msg_box.setIcon(QMessageBox.Warning)
# msg_box.setStandardButtons(QMessageBox.Ok)
# msg_box.exec_()
# return

# do not replace model if the version is out of date
if model.version != self.model.version:
print("WARNING: previous plot settings are for a different "
"version of the GUI. They will be ignored.")
wrn_msg = "Existing version: {}, Current GUI version: {}"
print(wrn_msg.format(model.version, self.model.version))
return

try:
self.model.statepoint = model.statepoint
except OSError:
msg_box = QMessageBox()
msg = "Could not open statepoint file: \n\n {} \n"
msg_box.setText(msg.format(self.model.statepoint.filename))
msg_box.setIcon(QMessageBox.Warning)
msg_box.setStandardButtons(QMessageBox.Ok)
msg_box.exec_()
self.model.statepoint = None

self.model.currentView = PlotView(restore_view=model.currentView)
self.model.activeView = copy.deepcopy(model.currentView)
self.model.previousViews = model.previousViews
self.model.subsequentViews = model.subsequentViews

def resetModels(self):
self.cellsModel = DomainTableModel(self.model.activeView.cells)
self.materialsModel = DomainTableModel(self.model.activeView.materials)
Expand Down Expand Up @@ -1219,18 +1159,11 @@ def saveSettings(self):
if len(self.model.subsequentViews) > 10:
self.model.subsequentViews = self.model.subsequentViews[-10:]

# get hashes for geometry.xml and material.xml at close
self.model.mat_xml_hash = hash_file('materials.xml')
self.model.geom_xml_hash = hash_file('geometry.xml')

with open('plot_settings.pkl', 'wb') as file:
if self.model.statepoint:
self.model.statepoint.close()
pickle.dump(self.model, file)

#with open('view_settings.pkl', 'wb') as file:
# pickle.dump(self.model.currentView, file)

def exportTallyData(self):
# show export tool dialog
self.showExportDialog()
Expand Down
9 changes: 7 additions & 2 deletions openmc_plotter/plotmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ def _do_op(array, tally_value, ax=0):


class PlotViewIndependent(openmc.lib.plot._PlotBase):
""" View settings for OpenMC plot, independent of the model.
"""View settings for OpenMC plot, independent of the model.

Parameters
----------
Expand All @@ -694,6 +694,8 @@ class PlotViewIndependent(openmc.lib.plot._PlotBase):
Width of plot view in model units
height : float
Height of plot view in model units
restore_view : PlotView or PlotViewIndependent or None
view object with specified parameters to restore

Attributes
----------
Expand Down Expand Up @@ -770,6 +772,8 @@ def __init__(self, origin=(0, 0, 0), width=10, height=10, restore_view=None):
super().__init__()

if restore_view is not None:
# set parameters based on supplied view

# View Parameters
self.level = restore_view.level
Comment thread
paulromano marked this conversation as resolved.
Outdated
self.origin = restore_view.origin
Expand Down Expand Up @@ -818,6 +822,7 @@ def __init__(self, origin=(0, 0, 0), width=10, height=10, restore_view=None):

else:
# set defaults

# View Parameters
self.level = -1
self.origin = origin
Expand Down Expand Up @@ -922,7 +927,7 @@ def adopt_plotbase(self, view):
self.basis = view.basis

class PlotView(PlotViewIndependent):
""" View settings for OpenMC plot.
"""Setup the view of the model.

Attributes
----------
Expand Down