55import threading
66import os
77import pickle
8+ import hashlib
89
910from PySide2 .QtWidgets import QItemDelegate , QColorDialog , QLineEdit , QMessageBox
1011from PySide2 .QtCore import QAbstractTableModel , QModelIndex , Qt , QSize , QEvent
6061 'Std. Dev.' : 'std_dev' ,
6162 'Rel. Error' : 'rel_err' }
6263
64+ def hash_file (filename ):
65+ # return the md5 hash of a file
66+ h = hashlib .md5 ()
67+ with open (filename ,'rb' ) as file :
68+ chunk = 0
69+ while chunk != b'' :
70+ # read 32768 bytes at a time
71+ chunk = file .read (32768 )
72+ h .update (chunk )
73+ return h .hexdigest ()
6374class PlotModel ():
6475 """ Geometry and plot settings for OpenMC Plot Explorer model
6576
@@ -149,6 +160,8 @@ def __init__(self, use_settings_pkl):
149160 self .defaultView = self .getDefaultView ()
150161
151162 else :
163+ restore_domains = False
164+
152165 # check GUI version
153166 if data ['version' ] != self .version :
154167 print ("WARNING: previous plot settings are for a different "
@@ -159,6 +172,14 @@ def __init__(self, use_settings_pkl):
159172 else :
160173 view = data ['currentView' ]
161174
175+ # get materials.xml and geometry.xml hashes to
176+ # restore additional settings if possible
177+ mat_xml_hash = hash_file ('materials.xml' )
178+ geom_xml_hash = hash_file ('geometry.xml' )
179+ if mat_xml_hash == data ['mat_xml_hash' ] and \
180+ geom_xml_hash == data ['geom_xml_hash' ]:
181+ restore_domains = True
182+
162183 # restore statepoint file
163184 try :
164185 self .statepoint = data ['statepoint' ]
@@ -171,7 +192,8 @@ def __init__(self, use_settings_pkl):
171192 msg_box .exec_ ()
172193 self .statepoint = None
173194
174- self .defaultView = PlotView (restore_view = view )
195+ self .defaultView = PlotView (restore_view = view ,
196+ restore_domains = restore_domains )
175197
176198 else :
177199 self .defaultView = self .getDefaultView ()
@@ -929,6 +951,9 @@ class PlotView:
929951 Height of plot view in model units
930952 restore_view : PlotView or None
931953 view object with specified parameters to restore
954+ restore_domains : bool (optional)
955+ If True and restore_view is provided, then also restore domain
956+ properties. Default False.
932957
933958 Attributes
934959 ----------
@@ -948,7 +973,8 @@ class PlotView:
948973 plotbase_attrs = ('level' , 'origin' , 'width' , 'height' ,
949974 'h_res' , 'v_res' , 'basis' , 'color_overlaps' )
950975
951- def __init__ (self , origin = (0 , 0 , 0 ), width = 10 , height = 10 , restore_view = None ):
976+ def __init__ (self , origin = (0 , 0 , 0 ), width = 10 , height = 10 , restore_view = None ,
977+ restore_domains = False ):
952978 """Initialize PlotView attributes"""
953979
954980 if restore_view is not None :
@@ -959,9 +985,14 @@ def __init__(self, origin=(0, 0, 0), width=10, height=10, restore_view=None):
959985 self .view_params = ViewParam (origin = origin , width = width , height = height )
960986
961987 # Get model domain info
962- self .cells = self .getDomains ('cell' )
963- self .materials = self .getDomains ('material' )
964- self .selectedTally = None
988+ if restore_domains and restore_view is not None :
989+ self .cells = restore_view .cells
990+ self .materials = restore_view .materials
991+ self .selectedTally = restore_view .selectedTally
992+ else :
993+ self .cells = self .getDomains ('cell' )
994+ self .materials = self .getDomains ('material' )
995+ self .selectedTally = None
965996
966997 def __getattr__ (self , name ):
967998 if name in self .attrs :
0 commit comments