Skip to content
Merged
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions openmc_plotter/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import pickle
from threading import Thread
import hashlib

from PySide2 import QtCore, QtGui
from PySide2.QtGui import QKeyEvent
Expand Down Expand Up @@ -37,6 +38,17 @@ def _openmcReload():
openmc.lib.init(["-c"])
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 Down Expand Up @@ -1065,6 +1077,21 @@ def restoreModelSettings(self):
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 "
Expand Down Expand Up @@ -1185,6 +1212,10 @@ 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()
Expand All @@ -1193,3 +1224,4 @@ def saveSettings(self):
def exportTallyData(self):
# show export tool dialog
self.showExportDialog()