Commit 944cdd7eb0da2cada6bc85691b804ee12c8a1801
1 parent
f4e362c5
Exists in
master
and in
6 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 | 45 | self.frame = frame |
46 | 46 | self.progress_dialog = None |
47 | 47 | self.cancel_import = False |
48 | - | |
48 | + | |
49 | 49 | |
50 | 50 | def __bind_events(self): |
51 | 51 | ps.Publisher().subscribe(self.OnImportMedicalImages, 'Import directory') |
... | ... | @@ -257,20 +257,30 @@ class Controller(): |
257 | 257 | plistlib.writePlist(preset, preset_dir) |
258 | 258 | |
259 | 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 | 273 | prj.Project().SavePlistProject(dir_, filename) |
264 | 274 | |
265 | 275 | def OnOpenProject(self, pubsub_evt): |
266 | 276 | filename = os.path.abspath(pubsub_evt.data) |
267 | 277 | |
268 | - print filename | |
269 | 278 | |
270 | 279 | proj = prj.Project() |
271 | 280 | proj.OpenPlistProject(filename) |
272 | 281 | proj.SetAcquisitionModality(proj.modality) |
273 | - | |
282 | + proj.save_as = False | |
283 | + proj.path = filename | |
274 | 284 | const.THRESHOLD_OUTVALUE = proj.threshold_range[0] |
275 | 285 | const.THRESHOLD_INVALUE = proj.threshold_range[1] |
276 | 286 | const.WINDOW_LEVEL['Default'] = (proj.window, proj.level) | ... | ... |
invesalius/data/slice_.py
... | ... | @@ -559,8 +559,7 @@ class Slice(object): |
559 | 559 | # threshold pipeline |
560 | 560 | current_mask.imagedata.DeepCopy(mask_thresh_imagedata) |
561 | 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 | 564 | # map the input image through a lookup table |
566 | 565 | img_colours_mask = vtk.vtkImageMapToColors() | ... | ... |
invesalius/gui/frame.py
... | ... | @@ -29,6 +29,7 @@ import constants as const |
29 | 29 | import default_tasks as tasks |
30 | 30 | import default_viewers as viewers |
31 | 31 | import import_panel as imp |
32 | +from project import Project | |
32 | 33 | |
33 | 34 | # Object toolbar |
34 | 35 | OBJ_TOOLS = [ID_ZOOM, ID_ZOOM_SELECT, ID_ROTATE, ID_MOVE, |
... | ... | @@ -370,6 +371,9 @@ class ProjectToolBar(wx.ToolBar): |
370 | 371 | |
371 | 372 | self.__init_items() |
372 | 373 | self.__bind_events() |
374 | + | |
375 | + #FIXME: | |
376 | + self.save_as = True | |
373 | 377 | |
374 | 378 | def __init_items(self): |
375 | 379 | |
... | ... | @@ -438,8 +442,29 @@ class ProjectToolBar(wx.ToolBar): |
438 | 442 | self.Bind(wx.EVT_TOOL, self.OnToolSave, id=const.ID_FILE_SAVE) |
439 | 443 | |
440 | 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 | 470 | class ObjectToolBar(wx.ToolBar): | ... | ... |
invesalius/project.py
... | ... | @@ -107,7 +107,9 @@ class Project(object): |
107 | 107 | |
108 | 108 | self.invesalius_version = version.get_svn_revision() |
109 | 109 | print self.invesalius_version |
110 | - | |
110 | + | |
111 | + self.save_as = True | |
112 | + self.path = "" | |
111 | 113 | self.debug = 0 |
112 | 114 | |
113 | 115 | ####### MASK OPERATIONS |
... | ... | @@ -146,38 +148,42 @@ class Project(object): |
146 | 148 | ps.Publisher.sendMessage('Set raycasting preset', preset) |
147 | 149 | |
148 | 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 | 155 | project = {} |
152 | 156 | |
153 | 157 | for key in self.__dict__: |
154 | 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 | 160 | else: |
157 | 161 | project[key] = self.__dict__[key] |
158 | 162 | |
159 | 163 | masks = {} |
160 | 164 | for index in self.mask_dict: |
161 | 165 | masks[str(index)] = {'#mask':\ |
162 | - self.mask_dict[index].SavePlist(filename)} | |
166 | + self.mask_dict[index].SavePlist(filename_tmp)} | |
163 | 167 | print index |
164 | 168 | |
165 | 169 | surfaces = {} |
166 | 170 | for index in self.surface_dict: |
167 | 171 | surfaces[str(index)] = {'#surface':\ |
168 | - self.surface_dict[index].SavePlist(filename)} | |
172 | + self.surface_dict[index].SavePlist(filename_tmp)} | |
169 | 173 | print index |
170 | 174 | |
171 | 175 | project['surface_dict'] = surfaces |
172 | 176 | project['mask_dict'] = masks |
173 | - img_file = '%s_%s.vti' % (filename, 'imagedata') | |
177 | + img_file = '%s_%s.vti' % (filename_tmp, 'imagedata') | |
174 | 178 | iu.Export(self.imagedata, img_file, bin=True) |
175 | 179 | project['imagedata'] = {'$vti':img_file} |
176 | 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 | 188 | def OpenPlistProject(self, filename): |
183 | 189 | filelist = Extract(filename, tempfile.gettempdir()) | ... | ... |