Skip to content
Snippets Groups Projects
Commit 8e0399a5 authored by Eric Wait's avatar Eric Wait
Browse files

Fixed History

parent d83119ef
No related branches found
No related tags found
No related merge requests found
% History.m - % History.m -
% This will keep track of any state changes. Call this function once the % This will keep track of any state changes. Call this function once the
% new state is established. After the changes take place. % new state is established. After the changes take place.
% Possible actions are: % Possible actions are:
...@@ -19,90 +19,63 @@ ...@@ -19,90 +19,63 @@
% %
% This file is part of LEVer - the tool for stem cell lineaging. See % This file is part of LEVer - the tool for stem cell lineaging. See
% https://pantherfile.uwm.edu/cohena/www/LEVer.html for details % https://pantherfile.uwm.edu/cohena/www/LEVer.html for details
% %
% LEVer is free software: you can redistribute it and/or modify % LEVer is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by % it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or % the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version. % (at your option) any later version.
% %
% LEVer is distributed in the hope that it will be useful, % LEVer is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of % but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details. % GNU General Public License for more details.
% %
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with LEVer in file "gnu gpl v3.txt". If not, see % along with LEVer in file "gnu gpl v3.txt". If not, see
% <http://www.gnu.org/licenses/>. % <http://www.gnu.org/licenses/>.
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function History(action) function History(action)
global CellFamilies CellTracks HashedCells CONSTANTS Figures CellHulls CellFeatures Costs GraphEdits CachedCostMatrix ConnectedDist CellPhenotypes SegmentationEdits global CellFamilies CellTracks HashedCells CONSTANTS Figures CellHulls Costs GraphEdits CachedCostMatrix ConnectedDist CellPhenotypes SegmentationEdits
% global test
persistent hist; %stack persistent hist; %stack
persistent current; %points to the last state saved on the stack persistent current; %points to the last state saved on the stack
persistent bottom; %points to the oldest or bottom most valid history persistent bottom; %points to the oldest or bottom most valid history
persistent top; %points to the youngest or top most valid history persistent top; %points to the youngest or top most valid history
persistent empty; %flag will be "empty" if only the original opened state is on the stack persistent saved; %flag will be "empty" if only the original opened state is on the stack
persistent full; %flag
persistent exceededLimit; %flag to denote if CONSTANTS.historySize has ever been reached
if (isempty(hist)) if (isempty(hist))
current = 1; current = 0;
bottom = 0; bottom = 0;
top = 0; top = 0;
empty = 1; saved = 0;
full = 0;
exceededLimit = 0;
end end
switch action switch action
case 'Push' case 'Saved'
if (empty) saved = current;
empty = 0; setMenus();
bottom = 1; case 'Push'
elseif (full) current = Increment(current);
%drop oldest history
exceededLimit = 1; if (current==bottom)
if (bottom < CONSTANTS.historySize) if (bottom==saved)
bottom = bottom + 1; saved = 0;
else
bottom = 1;
end end
end bottom = Increment(bottom);
current = current + 1;
if (current > CONSTANTS.historySize)
current = 1;
end end
top = current; top = current;
SetHistElement(current); SetHistElement(current);
if (current==bottom)
full = 1;
empty = 0;
end
setMenus(); setMenus();
case 'Pop' case 'Undo'
if (~empty) if (current~=bottom)
if (current == 0) current = Decrement(current);
current = CONSTANTS.historySize;
end
if (current==bottom && ~full)
empty = 1;
end
full = 0;
current = current - 1;
if(current==0)
current = CONSTANTS.historySize;
end
GetHistElement(current); GetHistElement(current);
...@@ -111,121 +84,65 @@ switch action ...@@ -111,121 +84,65 @@ switch action
UI.DrawCells(); UI.DrawCells();
UI.UpdateSegmentationEditsMenu(); UI.UpdateSegmentationEditsMenu();
UI.UpdatePhenotypeMenu(); UI.UpdatePhenotypeMenu();
setMenus();
Error.LogAction('Undo'); Error.LogAction('Undo');
end end
setMenus();
case 'Redo' case 'Redo'
if (top>current || (bottom>=top && top~=current)) if (top~=current)
%redo possible %redo possible
current = current + 1; current = Increment(current);
if (current > CONSTANTS.historySize)
current = 1;
end
GetHistElement(current); GetHistElement(current);
empty = 0;
if(current==bottom)
full = 1;
end
%Update displays %Update displays
UI.DrawTree(Figures.tree.familyID); UI.DrawTree(Figures.tree.familyID);
UI.DrawCells(); UI.DrawCells();
UI.UpdateSegmentationEditsMenu(); UI.UpdateSegmentationEditsMenu();
UI.UpdatePhenotypeMenu(); UI.UpdatePhenotypeMenu();
setMenus();
Error.LogAction('Redo'); Error.LogAction('Redo');
end end
setMenus();
case 'Top' case 'Top'
GetHistElement(current); GetHistElement(current);
UI.UpdateSegmentationEditsMenu(); UI.UpdateSegmentationEditsMenu();
UI.UpdatePhenotypeMenu(); UI.UpdatePhenotypeMenu();
case 'Init' case 'Init'
current = 1; current = 1;
bottom = 1; bottom = 1;
top = 1; top = 1;
empty = 0; saved = 1;
full = 0;
exceededLimit = 0;
SetHistElement(current); SetHistElement(current);
set(Figures.cells.menuHandles.redoMenu,'Enable','off'); setMenus();
set(Figures.tree.menuHandles.redoMenu,'Enable','off');
set(Figures.cells.menuHandles.undoMenu,'Enable','off');
set(Figures.tree.menuHandles.undoMenu,'Enable','off');
set(Figures.cells.menuHandles.saveMenu,'Enable','off');
set(Figures.tree.menuHandles.saveMenu,'Enable','off');
end end
function setMenus() function setMenus()
if(top>bottom) if (current==bottom)
%not "rolled over" set(Figures.cells.menuHandles.undoMenu,'Enable','off');
if(current<top) set(Figures.tree.menuHandles.undoMenu,'Enable','off');
%redo possible
set(Figures.cells.menuHandles.redoMenu,'Enable','on');
set(Figures.tree.menuHandles.redoMenu,'Enable','on');
else
set(Figures.cells.menuHandles.redoMenu,'Enable','off');
set(Figures.tree.menuHandles.redoMenu,'Enable','off');
end
if(current>bottom)
%undo possible
set(Figures.cells.menuHandles.undoMenu,'Enable','on');
set(Figures.tree.menuHandles.undoMenu,'Enable','on');
else
set(Figures.cells.menuHandles.undoMenu,'Enable','off');
set(Figures.tree.menuHandles.undoMenu,'Enable','off');
end
elseif(top==bottom && ~empty)
if(current~=top)
%redo and undo possible
set(Figures.cells.menuHandles.redoMenu,'Enable','on');
set(Figures.tree.menuHandles.redoMenu,'Enable','on');
set(Figures.cells.menuHandles.undoMenu,'Enable','on');
set(Figures.tree.menuHandles.undoMenu,'Enable','on');
else
set(Figures.cells.menuHandles.redoMenu,'Enable','off');
set(Figures.tree.menuHandles.redoMenu,'Enable','off');
if(~full)
set(Figures.cells.menuHandles.undoMenu,'Enable','off');
set(Figures.tree.menuHandles.undoMenu,'Enable','off');
else
set(Figures.cells.menuHandles.undoMenu,'Enable','on');
set(Figures.tree.menuHandles.undoMenu,'Enable','on');
end
end
else else
%"rolled over" set(Figures.cells.menuHandles.undoMenu,'Enable','on');
if(current>=bottom || current<top) set(Figures.tree.menuHandles.undoMenu,'Enable','on');
%redo possible
set(Figures.cells.menuHandles.redoMenu,'Enable','on');
set(Figures.tree.menuHandles.redoMenu,'Enable','on');
else
set(Figures.cells.menuHandles.redoMenu,'Enable','off');
set(Figures.tree.menuHandles.redoMenu,'Enable','off');
end
if(current>bottom || current<=top)
%undo possible
set(Figures.cells.menuHandles.undoMenu,'Enable','on');
set(Figures.tree.menuHandles.undoMenu,'Enable','on');
else
set(Figures.cells.menuHandles.undoMenu,'Enable','off');
set(Figures.tree.menuHandles.undoMenu,'Enable','off');
end
end end
%check to see if we are at the original state from the .mat file if (current==top)
if(exceededLimit) set(Figures.cells.menuHandles.redoMenu,'Enable','off');
set(Figures.cells.menuHandles.saveMenu,'Enable','on'); set(Figures.tree.menuHandles.redoMenu,'Enable','off');
set(Figures.tree.menuHandles.saveMenu,'Enable','on');
else else
if(empty) set(Figures.cells.menuHandles.redoMenu,'Enable','on');
set(Figures.tree.menuHandles.redoMenu,'Enable','on');
end
if (isfield(Figures.cells,'menuHandles') && isfield(Figures.cells.menuHandles,'saveMenu'))
if (saved==current)
set(Figures.cells.menuHandles.saveMenu,'Enable','off'); set(Figures.cells.menuHandles.saveMenu,'Enable','off');
set(Figures.tree.menuHandles.saveMenu,'Enable','off'); set(Figures.tree.menuHandles.saveMenu,'Enable','off');
set(Figures.cells.handle,'Name',[CONSTANTS.datasetName ' Image Data']);
set(Figures.tree.handle,'Name',[CONSTANTS.datasetName ' Image Data']);
else else
set(Figures.cells.menuHandles.saveMenu,'Enable','on'); set(Figures.cells.menuHandles.saveMenu,'Enable','on');
set(Figures.tree.menuHandles.saveMenu,'Enable','on'); set(Figures.tree.menuHandles.saveMenu,'Enable','on');
set(Figures.cells.handle,'Name',[CONSTANTS.datasetName ' Image Data *']);
set(Figures.tree.handle,'Name',[CONSTANTS.datasetName ' Image Data *']);
end end
end end
end %setMenu end %setMenu
...@@ -235,7 +152,6 @@ end ...@@ -235,7 +152,6 @@ end
hist(index).CellTracks = CellTracks; hist(index).CellTracks = CellTracks;
hist(index).HashedCells = HashedCells; hist(index).HashedCells = HashedCells;
hist(index).CellHulls = CellHulls; hist(index).CellHulls = CellHulls;
hist(index).CellFeatures = CellFeatures;
hist(index).Costs = Costs; hist(index).Costs = Costs;
hist(index).GraphEdits = GraphEdits; hist(index).GraphEdits = GraphEdits;
hist(index).CachedCostMatrix = CachedCostMatrix; hist(index).CachedCostMatrix = CachedCostMatrix;
...@@ -250,7 +166,6 @@ end ...@@ -250,7 +166,6 @@ end
CellTracks = hist(index).CellTracks; CellTracks = hist(index).CellTracks;
HashedCells = hist(index).HashedCells; HashedCells = hist(index).HashedCells;
CellHulls = hist(index).CellHulls; CellHulls = hist(index).CellHulls;
CellFeatures = hist(index).CellFeatures;
Costs = hist(index).Costs; Costs = hist(index).Costs;
GraphEdits = hist(index).GraphEdits; GraphEdits = hist(index).GraphEdits;
CachedCostMatrix = hist(index).CachedCostMatrix; CachedCostMatrix = hist(index).CachedCostMatrix;
...@@ -259,4 +174,20 @@ end ...@@ -259,4 +174,20 @@ end
CellPhenotypes = hist(index).CellPhenotypes; CellPhenotypes = hist(index).CellPhenotypes;
SegmentationEdits = hist(index).SegmentationEdits; SegmentationEdits = hist(index).SegmentationEdits;
end end
function index = Increment(index)
index = index+1;
if (index > CONSTANTS.historySize)
index = 1;
end
end
function index = Decrement(index)
index = index-1;
if (index == 0 )
index = CONSTANTS.historySize;
end
end
%test = [test; [current,bottom,top,saved]];
end end
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
% This initial action creates a has of several core data structures to % This initial action creates a has of several core data structures to
% allow verification that a run of edits starts from the correct data. % allow verification that a run of edits starts from the correct data.
function [coreHash bInitialSeg] = OriginAction(bInitialSeg) function [historyAction coreHash bInitialSeg] = OriginAction(bInitialSeg)
historyAction = '';
coreHash = Dev.GetCoreHashList(); coreHash = Dev.GetCoreHashList();
end end
\ No newline at end of file
...@@ -5,5 +5,5 @@ ...@@ -5,5 +5,5 @@
% was performed. % was performed.
function historyAction = Undo() function historyAction = Undo()
historyAction = 'Pop'; historyAction = 'Undo';
end end
...@@ -49,14 +49,6 @@ else ...@@ -49,14 +49,6 @@ else
end end
end end
%no longer "dirty"
if(isfield(Figures,'tree') && isfield(Figures.tree,'menuHandles') && isfield(Figures.tree.menuHandles,'saveMenu'))
set(Figures.tree.menuHandles.saveMenu,'Enable','off');
set(Figures.cells.menuHandles.saveMenu,'Enable','off');
end
Error.LogAction('Saved');
%let the user know that the drawing is done %let the user know that the drawing is done
if(isfield(Figures,'tree') && isfield(Figures.tree,'handle')) if(isfield(Figures,'tree') && isfield(Figures.tree,'handle'))
set(Figures.tree.handle,'Pointer','arrow'); set(Figures.tree.handle,'Pointer','arrow');
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
function SaveDataAs() function SaveDataAs()
global CONSTANTS Figures global CONSTANTS
if (exist('LEVerSettings.mat','file')~=0) if (exist('LEVerSettings.mat','file')~=0)
load('LEVerSettings.mat'); load('LEVerSettings.mat');
...@@ -49,12 +49,7 @@ else ...@@ -49,12 +49,7 @@ else
return return
end end
save('LEVerSettings.mat','settings'); save('LEVerSettings.mat','settings');
%no longer "dirty"
set(Figures.tree.menuHandles.saveMenu,'Enable','off');
set(Figures.cells.menuHandles.saveMenu,'Enable','off');
Error.LogAction(['Saved As: ' settings.matFile]); Error.LogAction(['Saved As: ' settings.matFile]);
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment