-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEspresso.m
201 lines (174 loc) · 6.75 KB
/
Espresso.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
function Espresso(varargin)
%ESPRESSO Start Espresso
%
% ESPRESSO() starts an Espresso session or activates the main window if a
% session is already running.
% Copyright 2017-2024 Alexandre Schimel, Yoann Ladroit, NIWA
% Licensed under MIT. Details on https://github.com/alexschimel/Espresso/
% Debug
global DEBUG;
DEBUG = 0;
% input parser
p = inputParser;
addOptional(p,'Filenames',{},@(x) ischar(x)|iscell(x));
parse(p,varargin{:});
% Set java window style and remove Javaframe warning
if ispc
javax.swing.UIManager.setLookAndFeel('com.sun.java.swing.plaf.windows.WindowsLookAndFeel');
end
warning('off','MATLAB:ui:javacomponent:FunctionToBeRemoved');
warning('off','MATLAB:ui:javaframe:PropertyToBeRemoved');
warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');
warning('off','MATLAB:polyshape:repairedBySimplify');
warning('off','MATLAB:polyshape:boundaryLessThan2Points');
warning('off','MATLAB:polyshape:boundary3Points');
warning('off','MATLAB:chckxy:IgnoreNaN');
% In Matlab, if a session is already running, activate the window and exit
if ~isdeployed()
wc_win = findobj(groot,'tag','Espresso');
if ~isempty(wc_win)
fprintf('Espresso already running. Activating window...\n');
figure(wc_win);
fprintf('Done. Espresso is ready for use.\n\n')
return;
end
end
% If on MATLAB, add relevant folders to path
if ~isdeployed
appRootFolder = whereisroot();
update_path(appRootFolder);
end
% Create Espresso user folder if needed
espressoUserFolder = espresso_user_folder();
if ~isfolder(espressoUserFolder)
mkdir(espressoUserFolder);
end
% Init config file if needed
espressoConfigFile = espresso_config_file();
if ~isfile(espressoConfigFile)
init_config_file();
end
% Init export folder if needed
espressoExportFolder = espresso_export_folder();
if ~isfolder(espressoExportFolder)
mkdir(espressoExportFolder);
end
% Setup log file
startTime = now;
logfile = generate_Espresso_diary_filename;
if ~isfolder(fileparts(logfile))
mkdir(fileparts(logfile));
end
if isfile(logfile)
delete(logfile);
end
diary(logfile);
EspressoUserdata.logfile = logfile; % save to app in order to close diary at the end
% Getting software info for start-up message
[espressoVer, coffeeVer, aknowledgments] = espresso_version();
licenseFile = espresso_license_file();
licenseLines = readlines(licenseFile);
espressoLicense = licenseLines(find(contains(licenseLines,"license",'IgnoreCase',true),1));
espressoCopyright = licenseLines(find(contains(licenseLines,"copyright",'IgnoreCase',true),1));
if isdeployed
licenseLocation = 'About section';
else
[~,licenseFilename] = fileparts(licenseFile);
licenseLocation = sprintf('%s file',licenseFilename);
end
% Start-up message
introText = {};
introText{end+1,1} = sprintf('ESPRESSO v%s (powered by CoFFee v%s)\n',espressoVer,coffeeVer);
introText{end+1,1} = sprintf('%s\n',espressoCopyright);
introText{end+1,1} = sprintf('Licensed under the %s. See %s for details.\n',espressoLicense,licenseLocation);
introText{end+1,1} = sprintf('If you use this software, please acknowledge:\n');
introText{end+1,1} = sprintf('%s.\n',aknowledgments);
introLimsText = {char([61.*ones(1,max(cellfun(@length,introText))-1),10])};
introText = [introLimsText;introText;introLimsText];
cellfun(@fprintf,introText);
% Session start messages
fprintf('New session start at %s. Please wait...\n',datestr(startTime));
fprintf('Espresso user folder: %s.\n',espressoUserFolder);
fprintf('Espresso config file: %s.\n',espressoConfigFile);
fprintf('Log file for this session: %s.\n',logfile);
% If on MATLAB, need to find and add CoFFee to the path
if ~isdeployed
% check coffee folder
coffeeFolder = get_config_field('coffeeFolder');
if ~is_coffee_folder(coffeeFolder)
% throw an alert to find manually a suitable coffee folder
fprintf('USER INPUT NEEDED. Select suitable CoFFee folder.\n');
coffeeFolder = uigetdir(appRootFolder,'Select suitable CoFFee folder');
% second check
if ~is_coffee_folder(coffeeFolder)
error('Not a CoFFee folder.');
end
end
fprintf('CoFFee folder: %s.\n',coffeeFolder);
% check coffee version is the one we need
fprintf('Checking CoFFee version... ');
isVersionOK = is_coffee_version(coffeeFolder,coffeeVer);
fprintf('CoFFee v%s found.\n',get_coffee_version(coffeeFolder));
if ~isVersionOK
warning(['This version of Espresso (%s) was built with a version'...
' of CoFFee (%s) that is different from that (%s) of the toolbox'...
' you have specified (%s). Proceeding, but you may experience'...
' issues. If you intend to simply use Espresso, consider'...
' checking out the correct CoFFee version. If you intend to'...
' develop Espresso, you should fix the version discrepancy.'],...
espressoVer,coffeeVer,get_coffee_version(coffeeFolder),coffeeFolder);
end
% add coffee to path
addpath(genpath(coffeeFolder));
% save that path in config file
set_config_field('coffeeFolder',coffeeFolder);
end
% check for possibility of GPU computation
[~,info] = CFF_is_parallel_computing_available();
fprintf('%s\n',info);
% create main_figure
fprintf('Creating main figure...\n');
if ~isdeployed()
figureVisibilityAtStart = 'on';
else
figureVisibilityAtStart = 'off';
end
main_figure = figure('Units','pixels',...
'Color','White',...
'Name',sprintf('Espresso v%s',espressoVer),...
'Tag','Espresso',...
'NumberTitle','off',...
'Resize','on',...
'MenuBar','none',...
'Toolbar','none',...
'visible',figureVisibilityAtStart,...
'WindowStyle','normal',...
'UserData',EspressoUserdata,...
'CloseRequestFcn',@closefcn_clean_espresso,...
'ResizeFcn',@resize_espresso);
% Install mouse pointer manager in figure
iptPointerManager(main_figure);
% Add Espresso icon
set_icon_espresso(main_figure);
% Default font size for Controls and Panels
set(0,'DefaultUicontrolFontSize',10);
set(0,'DefaultUipanelFontSize',12);
set(0,'DefaultAxesLooseInset',[0,0,0,0]);
% initialize and attach to the main figure the disp_config object, which
% will hold all information about what is currently on screen
disp_config = display_config_cl();
setappdata(main_figure,'disp_config',disp_config);
% initialize and attach to the main figure all other future data
setappdata(main_figure,'fData',{});
setappdata(main_figure,'grids',[]);
setappdata(main_figure,'ext_figs',[]);
setappdata(main_figure,'features',[]);
% Create the contents of main figure
initialize_display(main_figure);
% Initialize disp_config listeners and button controls
fprintf('Initializing listeners and controls...\n');
init_listeners(main_figure);
initialize_interactions_v2(main_figure);
% Final message
fprintf('Done. Espresso is ready for use.\n\n')
end