From 944cdd7eb0da2cada6bc85691b804ee12c8a1801 Mon Sep 17 00:00:00 2001 From: paulojamorim Date: Tue, 17 Nov 2009 15:18:44 +0000 Subject: [PATCH] FIX: Error edited mask with project salved --- invesalius/control.py | 22 ++++++++++++++++------ invesalius/data/slice_.py | 3 +-- invesalius/gui/frame.py | 29 +++++++++++++++++++++++++++-- invesalius/project.py | 24 +++++++++++++++--------- 4 files changed, 59 insertions(+), 19 deletions(-) diff --git a/invesalius/control.py b/invesalius/control.py index 2b3e1be..ce848db 100755 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -45,7 +45,7 @@ class Controller(): self.frame = frame self.progress_dialog = None self.cancel_import = False - + def __bind_events(self): ps.Publisher().subscribe(self.OnImportMedicalImages, 'Import directory') @@ -257,20 +257,30 @@ class Controller(): plistlib.writePlist(preset, preset_dir) def OnSaveProject(self, pubsub_evt): - filename = prj.Project().name - filename = filename.replace(' ','') - dir_ = tempfile.mkdtemp(filename) + + if not(pubsub_evt.data): + filename = prj.Project().path + else: + filename = pubsub_evt.data + dir_,filename = os.path.split(filename) + + if not (filename): + filename = prj.Project().name + else: + filename = filename.replace(' ','_') + prj.Project().name = filename + prj.Project().path = filename prj.Project().SavePlistProject(dir_, filename) def OnOpenProject(self, pubsub_evt): filename = os.path.abspath(pubsub_evt.data) - print filename proj = prj.Project() proj.OpenPlistProject(filename) proj.SetAcquisitionModality(proj.modality) - + proj.save_as = False + proj.path = filename const.THRESHOLD_OUTVALUE = proj.threshold_range[0] const.THRESHOLD_INVALUE = proj.threshold_range[1] const.WINDOW_LEVEL['Default'] = (proj.window, proj.level) diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index abf4bac..6c29ae8 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -559,8 +559,7 @@ class Slice(object): # threshold pipeline current_mask.imagedata.DeepCopy(mask_thresh_imagedata) else: - mask_thresh_imagedata = vtk.vtkImageData() - mask_thresh_imagedata.DeepCopy(self.current_mask.imagedata) + mask_thresh_imagedata = self.current_mask.imagedata # map the input image through a lookup table img_colours_mask = vtk.vtkImageMapToColors() diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index 3927073..44550d4 100755 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -29,6 +29,7 @@ import constants as const import default_tasks as tasks import default_viewers as viewers import import_panel as imp +from project import Project # Object toolbar OBJ_TOOLS = [ID_ZOOM, ID_ZOOM_SELECT, ID_ROTATE, ID_MOVE, @@ -370,6 +371,9 @@ class ProjectToolBar(wx.ToolBar): self.__init_items() self.__bind_events() + + #FIXME: + self.save_as = True def __init_items(self): @@ -438,8 +442,29 @@ class ProjectToolBar(wx.ToolBar): self.Bind(wx.EVT_TOOL, self.OnToolSave, id=const.ID_FILE_SAVE) def OnToolSave(self, evt): - print "Saving ..." - ps.Publisher().sendMessage('Save Project') + filename = None + project_name = (Project().name).replace(' ','_') + + if Project().save_as: + dlg = wx.FileDialog(None, + "Save InVesalius project as...", # title + "", # last used directory + project_name, # filename + "InVesalius project (*.inv3)|*.inv3", + wx.SAVE|wx.OVERWRITE_PROMPT) + dlg.SetFilterIndex(0) # default is VTI + + if dlg.ShowModal() == wx.ID_OK: + filename = dlg.GetPath() + print "filename", filename + extension = "inv3" + if sys.platform != 'win32': + if filename.split(".")[-1] != extension: + filename = filename + "."+ extension + + Project().save_as = False + + ps.Publisher().sendMessage('Save Project',filename) # ------------------------------------------------------------------ class ObjectToolBar(wx.ToolBar): diff --git a/invesalius/project.py b/invesalius/project.py index 0a89fb1..297bcce 100755 --- a/invesalius/project.py +++ b/invesalius/project.py @@ -107,7 +107,9 @@ class Project(object): self.invesalius_version = version.get_svn_revision() print self.invesalius_version - + + self.save_as = True + self.path = "" self.debug = 0 ####### MASK OPERATIONS @@ -146,38 +148,42 @@ class Project(object): ps.Publisher.sendMessage('Set raycasting preset', preset) def SavePlistProject(self, dir_, filename): - filename = os.path.join(dir_, filename) + + dir_temp = tempfile.mkdtemp(filename) + filename_tmp = os.path.join(dir_temp, filename) project = {} for key in self.__dict__: if getattr(self.__dict__[key], 'SavePlist', None): - project[key] = {'#plist': self.__dict__[key].SavePlist(filename)} + project[key] = {'#plist': self.__dict__[key].SavePlist(filename_tmp)} else: project[key] = self.__dict__[key] masks = {} for index in self.mask_dict: masks[str(index)] = {'#mask':\ - self.mask_dict[index].SavePlist(filename)} + self.mask_dict[index].SavePlist(filename_tmp)} print index surfaces = {} for index in self.surface_dict: surfaces[str(index)] = {'#surface':\ - self.surface_dict[index].SavePlist(filename)} + self.surface_dict[index].SavePlist(filename_tmp)} print index project['surface_dict'] = surfaces project['mask_dict'] = masks - img_file = '%s_%s.vti' % (filename, 'imagedata') + img_file = '%s_%s.vti' % (filename_tmp, 'imagedata') iu.Export(self.imagedata, img_file, bin=True) project['imagedata'] = {'$vti':img_file} print project - plistlib.writePlist(project, filename + '.plist') + plistlib.writePlist(project, filename_tmp + '.plist') - Compress(dir_, "teste.inv3")#os.path.join("~/Desktop/","teste.inv3")) - shutil.rmtree(dir_) + path = os.path.join(dir_,filename) + print path + Compress(dir_temp, path)#os.path.join("~/Desktop/","teste.inv3")) + shutil.rmtree(dir_temp) def OpenPlistProject(self, filename): filelist = Extract(filename, tempfile.gettempdir()) -- libgit2 0.21.2