Commit 4d99bc518a7b7d89df3c40f65ef19fc469a2c087
Committed by
GitHub
1 parent
320c4ae3
Exists in
master
Give the user the option to compact or not when saving the file. When the file i…
…s not compacted the file is saved faster. Also, save the surface file only one time. * Option to save compressed or not * Improvements * Saving only one time the surface * Checking if surface file exists * Incremented the format version to 1.1 * Showing an info dialog about user opening a inv3 file created by a newer invesalius format
Showing
5 changed files
with
60 additions
and
16 deletions
Show diff stats
invesalius/constants.py
invesalius/control.py
... | ... | @@ -233,17 +233,19 @@ class Controller(): |
233 | 233 | session = ses.Session() |
234 | 234 | if saveas or session.temp_item: |
235 | 235 | proj = prj.Project() |
236 | - filepath = dialog.ShowSaveAsProjectDialog(proj.name) | |
236 | + filepath, compress = dialog.ShowSaveAsProjectDialog(proj.name) | |
237 | 237 | if filepath: |
238 | 238 | #session.RemoveTemp() |
239 | 239 | session.OpenProject(filepath) |
240 | 240 | else: |
241 | 241 | return |
242 | 242 | else: |
243 | + proj = prj.Project() | |
244 | + compress = proj.compress | |
243 | 245 | dirpath, filename = session.project_path |
244 | 246 | filepath = os.path.join(dirpath, filename) |
245 | 247 | |
246 | - self.SaveProject(filepath) | |
248 | + self.SaveProject(filepath, compress) | |
247 | 249 | |
248 | 250 | |
249 | 251 | def ShowDialogCloseProject(self): |
... | ... | @@ -335,7 +337,7 @@ class Controller(): |
335 | 337 | path = pubsub_evt.data |
336 | 338 | self.SaveProject(path) |
337 | 339 | |
338 | - def SaveProject(self, path=None): | |
340 | + def SaveProject(self, path=None, compress=False): | |
339 | 341 | Publisher.sendMessage('Begin busy cursor') |
340 | 342 | session = ses.Session() |
341 | 343 | if path: |
... | ... | @@ -348,7 +350,7 @@ class Controller(): |
348 | 350 | filename = filename.decode(const.FS_ENCODE) |
349 | 351 | |
350 | 352 | proj = prj.Project() |
351 | - prj.Project().SavePlistProject(dirpath, filename) | |
353 | + prj.Project().SavePlistProject(dirpath, filename, compress) | |
352 | 354 | |
353 | 355 | session.SaveProject() |
354 | 356 | Publisher.sendMessage('End busy cursor') | ... | ... |
invesalius/data/surface.py
... | ... | @@ -74,11 +74,19 @@ class Surface(): |
74 | 74 | else: |
75 | 75 | self.name = name |
76 | 76 | |
77 | + self.filename = None | |
78 | + | |
77 | 79 | def SavePlist(self, dir_temp, filelist): |
78 | - filename = u'surface_%d' % self.index | |
79 | - vtp_filename = filename + u'.vtp' | |
80 | - vtp_filepath = os.path.join(dir_temp, vtp_filename) | |
81 | - pu.Export(self.polydata, vtp_filepath, bin=True) | |
80 | + if self.filename and os.path.exists(self.filename): | |
81 | + filename = u'surface_%d' % self.index | |
82 | + vtp_filename = filename + u'.vtp' | |
83 | + vtp_filepath = self.filename | |
84 | + else: | |
85 | + filename = u'surface_%d' % self.index | |
86 | + vtp_filename = filename + u'.vtp' | |
87 | + vtp_filepath = tempfile.mktemp() | |
88 | + pu.Export(self.polydata, vtp_filepath, bin=True) | |
89 | + self.filename = vtp_filepath | |
82 | 90 | |
83 | 91 | filelist[vtp_filepath] = vtp_filename |
84 | 92 | ... | ... |
invesalius/gui/dialogs.py
... | ... | @@ -221,6 +221,13 @@ class ProgressDialog(object): |
221 | 221 | |
222 | 222 | |
223 | 223 | # --------- |
224 | + | |
225 | +INV_NON_COMPRESSED = 0 | |
226 | +INV_COMPRESSED = 1 | |
227 | + | |
228 | +WILDCARD_INV_SAVE = _("InVesalius project (*.inv3)|*.inv3") + "|" + \ | |
229 | + _("InVesalius project compressed (*.inv3)|*.inv3") | |
230 | + | |
224 | 231 | WILDCARD_OPEN = "InVesalius 3 project (*.inv3)|*.inv3|" \ |
225 | 232 | "All files (*.*)|*.*" |
226 | 233 | |
... | ... | @@ -425,7 +432,7 @@ def ShowSaveAsProjectDialog(default_filename=None): |
425 | 432 | _("Save project as..."), # title |
426 | 433 | "", # last used directory |
427 | 434 | default_filename, |
428 | - _("InVesalius project (*.inv3)|*.inv3"), | |
435 | + WILDCARD_INV_SAVE, | |
429 | 436 | wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) |
430 | 437 | #dlg.SetFilterIndex(0) # default is VTI |
431 | 438 | |
... | ... | @@ -446,8 +453,9 @@ def ShowSaveAsProjectDialog(default_filename=None): |
446 | 453 | if filename.split(".")[-1] != extension: |
447 | 454 | filename = filename + "." + extension |
448 | 455 | |
456 | + wildcard = dlg.GetFilterIndex() | |
449 | 457 | os.chdir(current_dir) |
450 | - return filename | |
458 | + return filename, wildcard == INV_COMPRESSED | |
451 | 459 | |
452 | 460 | |
453 | 461 | # Dialog for neuronavigation markers |
... | ... | @@ -727,6 +735,15 @@ def ImportEmptyDirectory(dirpath): |
727 | 735 | dlg.Destroy() |
728 | 736 | |
729 | 737 | |
738 | +def ImportOldFormatInvFile(): | |
739 | + msg = _("File was created in a newer InVesalius version. Some functionalities may not work correctly.") | |
740 | + dlg = wx.MessageDialog(None, msg, | |
741 | + "InVesalius 3", | |
742 | + wx.ICON_INFORMATION | wx.OK) | |
743 | + dlg.ShowModal() | |
744 | + dlg.Destroy() | |
745 | + | |
746 | + | |
730 | 747 | def ImportInvalidFiles(ftype="DICOM"): |
731 | 748 | if ftype == "Bitmap": |
732 | 749 | msg = _("There are no Bitmap, JPEG, PNG or TIFF files in the selected folder.") | ... | ... |
invesalius/project.py
... | ... | @@ -71,6 +71,8 @@ class Project(object): |
71 | 71 | # TODO: Future ++ |
72 | 72 | self.annotation_dict = {} |
73 | 73 | |
74 | + self.compress = False | |
75 | + | |
74 | 76 | # InVesalius related data |
75 | 77 | # So we can find bugs and reproduce user-related problems |
76 | 78 | self.invesalius_version = version.get_svn_revision() |
... | ... | @@ -202,17 +204,20 @@ class Project(object): |
202 | 204 | measures[str(m.index)] = item |
203 | 205 | return measures |
204 | 206 | |
205 | - def SavePlistProject(self, dir_, filename): | |
207 | + def SavePlistProject(self, dir_, filename, compress=False): | |
206 | 208 | dir_temp = tempfile.mkdtemp().decode(const.FS_ENCODE) |
207 | 209 | |
210 | + self.compress = compress | |
211 | + | |
208 | 212 | filename_tmp = os.path.join(dir_temp, u'matrix.dat') |
209 | 213 | filelist = {} |
210 | 214 | |
211 | 215 | project = { |
212 | 216 | # Format info |
213 | - "format_version": 1, | |
217 | + "format_version": const.INVESALIUS_ACTUAL_FORMAT_VERSION, | |
214 | 218 | "invesalius_version": const.INVESALIUS_VERSION, |
215 | 219 | "date": datetime.datetime.now().isoformat(), |
220 | + "compress": self.compress, | |
216 | 221 | |
217 | 222 | # case info |
218 | 223 | "name": self.name, # patient's name |
... | ... | @@ -267,7 +272,7 @@ class Project(object): |
267 | 272 | |
268 | 273 | # Compressing and generating the .inv3 file |
269 | 274 | path = os.path.join(dir_,filename) |
270 | - Compress(dir_temp, path, filelist) | |
275 | + Compress(dir_temp, path, filelist, compress) | |
271 | 276 | |
272 | 277 | # Removing the temp folder. |
273 | 278 | shutil.rmtree(dir_temp) |
... | ... | @@ -295,6 +300,11 @@ class Project(object): |
295 | 300 | main_plist = os.path.join(dirpath ,'main.plist') |
296 | 301 | project = plistlib.readPlist(main_plist) |
297 | 302 | |
303 | + format_version = project["format_version"] | |
304 | + if format_version > const.INVESALIUS_ACTUAL_FORMAT_VERSION: | |
305 | + from invesalius.gui.dialogs import ImportOldFormatInvFile | |
306 | + ImportOldFormatInvFile() | |
307 | + | |
298 | 308 | # case info |
299 | 309 | self.name = project["name"] |
300 | 310 | self.modality = project["modality"] |
... | ... | @@ -304,6 +314,8 @@ class Project(object): |
304 | 314 | self.threshold_range = project["scalar_range"] |
305 | 315 | self.spacing = project["spacing"] |
306 | 316 | |
317 | + self.compress = project.get("compress", True) | |
318 | + | |
307 | 319 | # Opening the matrix containing the slices |
308 | 320 | filepath = os.path.join(dirpath, project["matrix"]["filename"]) |
309 | 321 | self.matrix_filename = filepath |
... | ... | @@ -337,7 +349,7 @@ class Project(object): |
337 | 349 | measure.Load(measurements[index]) |
338 | 350 | self.measurement_dict[int(index)] = measure |
339 | 351 | |
340 | -def Compress(folder, filename, filelist): | |
352 | +def Compress(folder, filename, filelist, compress=False): | |
341 | 353 | tmpdir, tmpdir_ = os.path.split(folder) |
342 | 354 | current_dir = os.path.abspath(".") |
343 | 355 | temp_inv3 = tempfile.mktemp() |
... | ... | @@ -348,7 +360,10 @@ def Compress(folder, filename, filelist): |
348 | 360 | temp_inv3 = temp_inv3.decode(const.FS_ENCODE) |
349 | 361 | #os.chdir(tmpdir) |
350 | 362 | #file_list = glob.glob(os.path.join(tmpdir_,"*")) |
351 | - tar = tarfile.open(temp_inv3, "w:gz") | |
363 | + if compress: | |
364 | + tar = tarfile.open(temp_inv3, "w:gz") | |
365 | + else: | |
366 | + tar = tarfile.open(temp_inv3, "w") | |
352 | 367 | for name in filelist: |
353 | 368 | tar.add(name, arcname=os.path.join(tmpdir_, filelist[name])) |
354 | 369 | tar.close() |
... | ... | @@ -361,7 +376,7 @@ def Extract(filename, folder): |
361 | 376 | folder = win32api.GetShortPathName(folder) |
362 | 377 | folder = folder.decode(const.FS_ENCODE) |
363 | 378 | |
364 | - tar = tarfile.open(filename, "r:gz") | |
379 | + tar = tarfile.open(filename, "r") | |
365 | 380 | idir = os.path.split(tar.getnames()[0])[0].decode('utf8') |
366 | 381 | os.mkdir(os.path.join(folder, idir)) |
367 | 382 | filelist = [] | ... | ... |