Commit 944cdd7eb0da2cada6bc85691b804ee12c8a1801
1 parent
f4e362c5
Exists in
master
and in
68 other branches
FIX: Error edited mask with project salved
Showing
4 changed files
with
59 additions
and
19 deletions
Show diff stats
invesalius/control.py
| @@ -45,7 +45,7 @@ class Controller(): | @@ -45,7 +45,7 @@ class Controller(): | ||
| 45 | self.frame = frame | 45 | self.frame = frame |
| 46 | self.progress_dialog = None | 46 | self.progress_dialog = None |
| 47 | self.cancel_import = False | 47 | self.cancel_import = False |
| 48 | - | 48 | + |
| 49 | 49 | ||
| 50 | def __bind_events(self): | 50 | def __bind_events(self): |
| 51 | ps.Publisher().subscribe(self.OnImportMedicalImages, 'Import directory') | 51 | ps.Publisher().subscribe(self.OnImportMedicalImages, 'Import directory') |
| @@ -257,20 +257,30 @@ class Controller(): | @@ -257,20 +257,30 @@ class Controller(): | ||
| 257 | plistlib.writePlist(preset, preset_dir) | 257 | plistlib.writePlist(preset, preset_dir) |
| 258 | 258 | ||
| 259 | def OnSaveProject(self, pubsub_evt): | 259 | def OnSaveProject(self, pubsub_evt): |
| 260 | - filename = prj.Project().name | ||
| 261 | - filename = filename.replace(' ','') | ||
| 262 | - dir_ = tempfile.mkdtemp(filename) | 260 | + |
| 261 | + if not(pubsub_evt.data): | ||
| 262 | + filename = prj.Project().path | ||
| 263 | + else: | ||
| 264 | + filename = pubsub_evt.data | ||
| 265 | + dir_,filename = os.path.split(filename) | ||
| 266 | + | ||
| 267 | + if not (filename): | ||
| 268 | + filename = prj.Project().name | ||
| 269 | + else: | ||
| 270 | + filename = filename.replace(' ','_') | ||
| 271 | + prj.Project().name = filename | ||
| 272 | + prj.Project().path = filename | ||
| 263 | prj.Project().SavePlistProject(dir_, filename) | 273 | prj.Project().SavePlistProject(dir_, filename) |
| 264 | 274 | ||
| 265 | def OnOpenProject(self, pubsub_evt): | 275 | def OnOpenProject(self, pubsub_evt): |
| 266 | filename = os.path.abspath(pubsub_evt.data) | 276 | filename = os.path.abspath(pubsub_evt.data) |
| 267 | 277 | ||
| 268 | - print filename | ||
| 269 | 278 | ||
| 270 | proj = prj.Project() | 279 | proj = prj.Project() |
| 271 | proj.OpenPlistProject(filename) | 280 | proj.OpenPlistProject(filename) |
| 272 | proj.SetAcquisitionModality(proj.modality) | 281 | proj.SetAcquisitionModality(proj.modality) |
| 273 | - | 282 | + proj.save_as = False |
| 283 | + proj.path = filename | ||
| 274 | const.THRESHOLD_OUTVALUE = proj.threshold_range[0] | 284 | const.THRESHOLD_OUTVALUE = proj.threshold_range[0] |
| 275 | const.THRESHOLD_INVALUE = proj.threshold_range[1] | 285 | const.THRESHOLD_INVALUE = proj.threshold_range[1] |
| 276 | const.WINDOW_LEVEL['Default'] = (proj.window, proj.level) | 286 | const.WINDOW_LEVEL['Default'] = (proj.window, proj.level) |
invesalius/data/slice_.py
| @@ -559,8 +559,7 @@ class Slice(object): | @@ -559,8 +559,7 @@ class Slice(object): | ||
| 559 | # threshold pipeline | 559 | # threshold pipeline |
| 560 | current_mask.imagedata.DeepCopy(mask_thresh_imagedata) | 560 | current_mask.imagedata.DeepCopy(mask_thresh_imagedata) |
| 561 | else: | 561 | else: |
| 562 | - mask_thresh_imagedata = vtk.vtkImageData() | ||
| 563 | - mask_thresh_imagedata.DeepCopy(self.current_mask.imagedata) | 562 | + mask_thresh_imagedata = self.current_mask.imagedata |
| 564 | 563 | ||
| 565 | # map the input image through a lookup table | 564 | # map the input image through a lookup table |
| 566 | img_colours_mask = vtk.vtkImageMapToColors() | 565 | img_colours_mask = vtk.vtkImageMapToColors() |
invesalius/gui/frame.py
| @@ -29,6 +29,7 @@ import constants as const | @@ -29,6 +29,7 @@ import constants as const | ||
| 29 | import default_tasks as tasks | 29 | import default_tasks as tasks |
| 30 | import default_viewers as viewers | 30 | import default_viewers as viewers |
| 31 | import import_panel as imp | 31 | import import_panel as imp |
| 32 | +from project import Project | ||
| 32 | 33 | ||
| 33 | # Object toolbar | 34 | # Object toolbar |
| 34 | OBJ_TOOLS = [ID_ZOOM, ID_ZOOM_SELECT, ID_ROTATE, ID_MOVE, | 35 | OBJ_TOOLS = [ID_ZOOM, ID_ZOOM_SELECT, ID_ROTATE, ID_MOVE, |
| @@ -370,6 +371,9 @@ class ProjectToolBar(wx.ToolBar): | @@ -370,6 +371,9 @@ class ProjectToolBar(wx.ToolBar): | ||
| 370 | 371 | ||
| 371 | self.__init_items() | 372 | self.__init_items() |
| 372 | self.__bind_events() | 373 | self.__bind_events() |
| 374 | + | ||
| 375 | + #FIXME: | ||
| 376 | + self.save_as = True | ||
| 373 | 377 | ||
| 374 | def __init_items(self): | 378 | def __init_items(self): |
| 375 | 379 | ||
| @@ -438,8 +442,29 @@ class ProjectToolBar(wx.ToolBar): | @@ -438,8 +442,29 @@ class ProjectToolBar(wx.ToolBar): | ||
| 438 | self.Bind(wx.EVT_TOOL, self.OnToolSave, id=const.ID_FILE_SAVE) | 442 | self.Bind(wx.EVT_TOOL, self.OnToolSave, id=const.ID_FILE_SAVE) |
| 439 | 443 | ||
| 440 | def OnToolSave(self, evt): | 444 | def OnToolSave(self, evt): |
| 441 | - print "Saving ..." | ||
| 442 | - ps.Publisher().sendMessage('Save Project') | 445 | + filename = None |
| 446 | + project_name = (Project().name).replace(' ','_') | ||
| 447 | + | ||
| 448 | + if Project().save_as: | ||
| 449 | + dlg = wx.FileDialog(None, | ||
| 450 | + "Save InVesalius project as...", # title | ||
| 451 | + "", # last used directory | ||
| 452 | + project_name, # filename | ||
| 453 | + "InVesalius project (*.inv3)|*.inv3", | ||
| 454 | + wx.SAVE|wx.OVERWRITE_PROMPT) | ||
| 455 | + dlg.SetFilterIndex(0) # default is VTI | ||
| 456 | + | ||
| 457 | + if dlg.ShowModal() == wx.ID_OK: | ||
| 458 | + filename = dlg.GetPath() | ||
| 459 | + print "filename", filename | ||
| 460 | + extension = "inv3" | ||
| 461 | + if sys.platform != 'win32': | ||
| 462 | + if filename.split(".")[-1] != extension: | ||
| 463 | + filename = filename + "."+ extension | ||
| 464 | + | ||
| 465 | + Project().save_as = False | ||
| 466 | + | ||
| 467 | + ps.Publisher().sendMessage('Save Project',filename) | ||
| 443 | # ------------------------------------------------------------------ | 468 | # ------------------------------------------------------------------ |
| 444 | 469 | ||
| 445 | class ObjectToolBar(wx.ToolBar): | 470 | class ObjectToolBar(wx.ToolBar): |
invesalius/project.py
| @@ -107,7 +107,9 @@ class Project(object): | @@ -107,7 +107,9 @@ class Project(object): | ||
| 107 | 107 | ||
| 108 | self.invesalius_version = version.get_svn_revision() | 108 | self.invesalius_version = version.get_svn_revision() |
| 109 | print self.invesalius_version | 109 | print self.invesalius_version |
| 110 | - | 110 | + |
| 111 | + self.save_as = True | ||
| 112 | + self.path = "" | ||
| 111 | self.debug = 0 | 113 | self.debug = 0 |
| 112 | 114 | ||
| 113 | ####### MASK OPERATIONS | 115 | ####### MASK OPERATIONS |
| @@ -146,38 +148,42 @@ class Project(object): | @@ -146,38 +148,42 @@ class Project(object): | ||
| 146 | ps.Publisher.sendMessage('Set raycasting preset', preset) | 148 | ps.Publisher.sendMessage('Set raycasting preset', preset) |
| 147 | 149 | ||
| 148 | def SavePlistProject(self, dir_, filename): | 150 | def SavePlistProject(self, dir_, filename): |
| 149 | - filename = os.path.join(dir_, filename) | 151 | + |
| 152 | + dir_temp = tempfile.mkdtemp(filename) | ||
| 153 | + filename_tmp = os.path.join(dir_temp, filename) | ||
| 150 | 154 | ||
| 151 | project = {} | 155 | project = {} |
| 152 | 156 | ||
| 153 | for key in self.__dict__: | 157 | for key in self.__dict__: |
| 154 | if getattr(self.__dict__[key], 'SavePlist', None): | 158 | if getattr(self.__dict__[key], 'SavePlist', None): |
| 155 | - project[key] = {'#plist': self.__dict__[key].SavePlist(filename)} | 159 | + project[key] = {'#plist': self.__dict__[key].SavePlist(filename_tmp)} |
| 156 | else: | 160 | else: |
| 157 | project[key] = self.__dict__[key] | 161 | project[key] = self.__dict__[key] |
| 158 | 162 | ||
| 159 | masks = {} | 163 | masks = {} |
| 160 | for index in self.mask_dict: | 164 | for index in self.mask_dict: |
| 161 | masks[str(index)] = {'#mask':\ | 165 | masks[str(index)] = {'#mask':\ |
| 162 | - self.mask_dict[index].SavePlist(filename)} | 166 | + self.mask_dict[index].SavePlist(filename_tmp)} |
| 163 | print index | 167 | print index |
| 164 | 168 | ||
| 165 | surfaces = {} | 169 | surfaces = {} |
| 166 | for index in self.surface_dict: | 170 | for index in self.surface_dict: |
| 167 | surfaces[str(index)] = {'#surface':\ | 171 | surfaces[str(index)] = {'#surface':\ |
| 168 | - self.surface_dict[index].SavePlist(filename)} | 172 | + self.surface_dict[index].SavePlist(filename_tmp)} |
| 169 | print index | 173 | print index |
| 170 | 174 | ||
| 171 | project['surface_dict'] = surfaces | 175 | project['surface_dict'] = surfaces |
| 172 | project['mask_dict'] = masks | 176 | project['mask_dict'] = masks |
| 173 | - img_file = '%s_%s.vti' % (filename, 'imagedata') | 177 | + img_file = '%s_%s.vti' % (filename_tmp, 'imagedata') |
| 174 | iu.Export(self.imagedata, img_file, bin=True) | 178 | iu.Export(self.imagedata, img_file, bin=True) |
| 175 | project['imagedata'] = {'$vti':img_file} | 179 | project['imagedata'] = {'$vti':img_file} |
| 176 | print project | 180 | print project |
| 177 | - plistlib.writePlist(project, filename + '.plist') | 181 | + plistlib.writePlist(project, filename_tmp + '.plist') |
| 178 | 182 | ||
| 179 | - Compress(dir_, "teste.inv3")#os.path.join("~/Desktop/","teste.inv3")) | ||
| 180 | - shutil.rmtree(dir_) | 183 | + path = os.path.join(dir_,filename) |
| 184 | + print path | ||
| 185 | + Compress(dir_temp, path)#os.path.join("~/Desktop/","teste.inv3")) | ||
| 186 | + shutil.rmtree(dir_temp) | ||
| 181 | 187 | ||
| 182 | def OpenPlistProject(self, filename): | 188 | def OpenPlistProject(self, filename): |
| 183 | filelist = Extract(filename, tempfile.gettempdir()) | 189 | filelist = Extract(filename, tempfile.gettempdir()) |