@@ -1068,13 +1068,10 @@ def restoreModelSettings(self):
10681068 model = pickle .load (file )
10691069
10701070 # check if loaded cell/mat ids hash match the pkl file:
1071- current_mat_hash = hashlib .md5 (
1072- pickle .dumps (self .model .mat_ids )).hexdigest ()
1073- current_cell_hash = hashlib .md5 (
1074- pickle .dumps (self .model .cell_ids )).hexdigest ()
1075-
1076- if (current_mat_hash != model .mat_ids_hash ) or \
1077- (current_cell_hash != model .cell_ids_hash ):
1071+ current_mat_xml_hash = self .hash_file ('materials.xml' )
1072+ current_geom_xml_hash = self .hash_file ('geometry.xml' )
1073+ if (current_mat_xml_hash != model .mat_xml_hash ) or \
1074+ (current_geom_xml_hash != model .geom_xml_hash ):
10781075 # hashes do not match so ignore plot_settings.pkl file
10791076 pkl_settings_warn = "WARNING: Model has changed since " + \
10801077 "storing plot settings. Ignoring " + \
@@ -1202,11 +1199,9 @@ def saveSettings(self):
12021199 if len (self .model .subsequentViews ) > 10 :
12031200 self .model .subsequentViews = self .model .subsequentViews [- 10 :]
12041201
1205- # get hashes for cell/mat ids at close
1206- self .model .cell_ids_hash = hashlib .md5 (
1207- pickle .dumps (self .model .cell_ids )).hexdigest ()
1208- self .model .mat_ids_hash = hashlib .md5 (
1209- pickle .dumps (self .model .mat_ids )).hexdigest ()
1202+ # get hashes for geometry.xml and material.xml at close
1203+ self .model .mat_xml_hash = self .hash_file ('materials.xml' )
1204+ self .model .geom_xml_hash = self .hash_file ('geometry.xml' )
12101205
12111206 with open ('plot_settings.pkl' , 'wb' ) as file :
12121207 if self .model .statepoint :
@@ -1216,3 +1211,15 @@ def saveSettings(self):
12161211 def exportTallyData (self ):
12171212 # show export tool dialog
12181213 self .showExportDialog ()
1214+
1215+ @staticmethod
1216+ def hash_file (filename ):
1217+ # return the md5 hash of a file
1218+ h = hashlib .md5 ()
1219+ with open (filename ,'rb' ) as file :
1220+ chunk = 0
1221+ while chunk != b'' :
1222+ # read 1024 bytes at a time
1223+ chunk = file .read (1024 )
1224+ h .update (chunk )
1225+ return h .hexdigest ()
0 commit comments