-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
optickaCore.m
838 lines (771 loc) · 26.7 KB
/
optickaCore.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
% ========================================================================
classdef optickaCore < handle
%> @class optickaCore
%> @brief optickaCore base class inherited by other opticka classes.
%>
%> @section intro Introduction
%>
%> optickaCore is itself derived from handle. It provides methods to find
%> attributes with specific parameters (used in autogenerating UI panels),
%> clone the object, parse arguments safely on construction and add default
%> properties such as paths, dateStamp, uuid and name/comment management.
%>
%> Copyright ©2014-2024 Ian Max Andolina — released: LGPL3, see LICENCE.md
% ========================================================================
%--------------------PUBLIC PROPERTIES----------%
properties
%> object name
name char = ''
%> comment
comment string = ""
end
%--------------------ABSTRACT PROPERTIES----------%
properties (Abstract = true)
%> verbose logging, subclasses must assign this. This is normally logical true/false
verbose
end
%--------------------HIDDEN PROPERTIES------------%
properties (SetAccess = protected, Hidden = true)
%> are we cloning this from another object
cloning logical = false
end
%--------------------VISIBLE PROPERTIES-----------%
properties (SetAccess = protected, GetAccess = public)
%> clock() dateStamp set on construction
dateStamp = []
%> universal ID
uuid char
%> storage of various paths
paths struct
end
%--------------------DEPENDENT PROPERTIES----------%
properties (Dependent = true)
%> The fullName is the object name combined with its uuid and class name
fullName char
end
%--------------------TRANSIENT PROPERTIES----------%
properties (Access = protected, Transient = true)
%> Matlab version number, this is transient so it is not saved
mversion double = 0
%> sans font
sansFont = 'Ubuntu'
%> monoFont
monoFont = 'Ubunto Mono'
end
%--------------------PROTECTED PROPERTIES----------%
properties (Access = protected)
%> class name
className char = ''
%> save prefix generated from clock time
savePrefix = ''
%> cached full name
fullName_ = ''
end
%--------------------PRIVATE PROPERTIES----------%
properties (Access = private)
%> allowed properties passed to object upon construction
allowedPropertiesCore = {'name','comment','cloning'}
end
%=======================================================================
methods %------------------PUBLIC METHODS
%=======================================================================
% ===================================================================
function me = optickaCore(varargin)
%> @fn optickaCore
%> @brief Class constructor
%>
%> The class constructor for optickaCore.
%>
%> @param args are passed as name-value pairs or a structure of properties
%> which is parsed.
%>
%> @return instance of class.
% ===================================================================
args = me.addDefaults(varargin);
me.parseArgs(args, me.allowedPropertiesCore);
me.dateStamp = datetime('now');
me.className = class(me);
me.uuid = num2str(dec2hex(floor((now - floor(now))*1e10))); %me.uuid = char(java.util.UUID.randomUUID)%128bit uuid
me.fullName; %cache fullName
me.mversion = str2double(regexp(version,'(?<ver>^\d\.\d[\d]?)','match','once'));
setPaths(me);
getFonts(me);
end
% ===================================================================
function name = get.fullName(me)
%> @fn get.fullName
%> @brief concatenate the name with a uuid at get.
%> @param
%> @return name the concatenated name
% ===================================================================
if isempty(me.name)
me.fullName_ = sprintf('%s#%s', me.className, me.uuid);
else
me.fullName_ = sprintf('%s<%s#%s>', me.name, me.className, me.uuid);
end
name = me.fullName_;
end
% ===================================================================
function [path, sessionID, dateID] = getALF(me, subject, sessionPrefix, lab, create)
%> @fn initialiseSaveFile(me)
%> @brief Initialise Save prefix
%>
%> @return path - the path to use
%> @return dateid - YYYY-MM-DD-HH-MM-SS
% ===================================================================
if ~exist('subject','var') || isempty(subject); subject = 'unknown'; end
if ~exist('sessionPrefix','var') || isempty(sessionPrefix); sessionPrefix = ''; end
if ~exist('lab','var') || isempty(lab); lab = []; end
if ~exist('create','var') || isempty(create); create = false; end
dateID = fix(clock); %#ok<*CLOCK> compatible with octave
dateID = num2str(dateID(1:6));
dateID = regexprep(dateID,' +','-');
d = char(datetime("today"));
if isempty(lab)
path = [me.paths.savedData filesep subject filesep d];
else
path = [me.paths.savedData filesep lab filesep 'subjects' filesep subject filesep d];
end
if ~exist(path,'dir')
sessionID = [sessionPrefix '001'];
path = [path filesep sessionID filesep];
s = mkdir(path);
if s == 0; error('Cannot make Save File directory!!!'); end
fprintf('---> Path: %s created...\n',path);
return
else
isMatch = false;
n = 0;
d = dir(path);
pattern = sessionPrefix + digitsPattern(3);
for jj = 1:length(d)
e = extract(d(jj).name, pattern);
if ~isempty(e)
isMatch = true;
nn = str2double(e{1}(end-2:end));
if nn > n; n = nn; end
end
end
if isMatch
if create
sessionID = [sessionPrefix sprintf('%0.3d',n+1)];
path = [path filesep sessionID filesep];
s = mkdir(path);
if s == 0; error('Cannot make Save File directory!!!'); end
fprintf('---> Path: %s created...\n',path);
return
else
sessionID = [sessionPrefix sprintf('%0.3d',n)];
path = [path filesep sessionID filesep];
fprintf('---> Path: %s found...\n',path);
return
end
else
sessionID = [sessionPrefix '001'];
path = [path filesep sessionID filesep];
s = mkdir(path);
if s == 0; error('Cannot make Save File directory!!!'); end
fprintf('---> Path: %s created...\n',path);
end
end
me.paths.ALFPath = path;
end
% ===================================================================
function [list, typelist] = findAttributes(me, attrName, attrValue)
% [list, typelist] = findAttributes(me, attrName, attrValue)
%> @fn [list, typelist] = findAttributes (me, attrName, attrValue)
%> @brief find properties of object with specific attributes, for
%> example all properties whose GetAcccess attribute is public.
%>
%> @param attrName attribute name, i.e. GetAccess, Transient
%> @param attrValue value of that attribute, i.e. public, true
%>
%> @return list of properties that match that attribute
%> @return typelist the type of the property
% ===================================================================
if ischar(me) % Determine if first input is object or class name
mc = meta.class.fromName(me);
elseif isobject(me)
mc = metaclass(me);
end
% Initial size and preallocate
ii = 0; nProps = length(mc.PropertyList);
nameArray = cell(1, nProps);
typeArray = cell(1, nProps);
% For each property, check the value of the queried attribute
for c = 1:nProps
% Get a meta.property object from the meta.class object
mp = mc.PropertyList(c);
% Determine if the specified attribute is valid on this object
if isempty (findprop(mp,attrName))
error('Not a valid attribute name');
end
thisValue = mp.(attrName);
% If the attribute is set or has the specified value,
% save its name in cell array
if ischar(attrValue)
if strcmpi(attrValue, thisValue)
ii = ii + 1;
nameArray(ii) = {mp.Name};
typeArray{ii} = getType(me, mp);
end
elseif islogical(attrValue)
if thisValue == attrValue
ii = ii + 1;
nameArray(ii) = {mp.Name};
typeArray{ii} = getType(me, mp);
end
elseif isempty(attrValue)
if isempty(thisValue)
ii = ii + 1;
nameArray(ii) = {mp.Name};
typeArray{ii} = getType(me, mp);
end
end
end
% Return used portion of array
list = nameArray(1:ii)';
typelist = typeArray(1:ii)';
end
% ===================================================================
function list = findAttributesandType(me, attrName, attrValue, type)
%> @fn list = findAttributesandType(me, attrName, attrValue, type)
%> @brief find properties of object with specific attributes, for
%> example all properties whose GetAcccess attribute is public and
%> type is logical.
%>
%> @param attrName attribute name, i.e. GetAccess, Transient
%> @param attrValue value of that attribute, i.e. public, true
%> @param type logical, notlogical, string or number
%>
%> @return list of properties that match that attribute
% ===================================================================
if ischar(me) % Determine if first input is object or class name
mc = meta.class.fromName(me);
elseif isobject(me)
mc = metaclass(me);
end
% Initial size and preallocate
ii = 0;
nProps = length(mc.PropertyList);
cl_array = cell(1, nProps);
% For each property, check the value of the queried attribute
for c = 1:nProps
% Get a meta.property object from the meta.class object
mp = mc.PropertyList(c);
% Determine if the specified attribute is valid on this object
if isempty (findprop(mp,attrName))
error('Not a valid attribute name')
end
thisValue = mp.(attrName);
% If the attribute is set or has the specified value,
% save its name in cell array
if exist('attrValue','var') && ~isempty(thisValue)
if all(islogical(attrValue)) || all((ischar(thisValue) && strcmp(attrValue,thisValue)))
val = me.(mp.Name);
if exist('val','var')
if islogical(val) && strcmpi(type,'logical')
ii = ii + 1;
cl_array(ii) = {mp.Name};
elseif ~islogical(val) && strcmpi(type,'notlogical')
ii = ii + 1;
cl_array(ii) = {mp.Name};
elseif ischar(val) && strcmpi(type,'string')
ii = ii + 1;
cl_array(ii) = {mp.Name};
elseif isnumeric(val) && strcmpi(type,'number')
ii = ii + 1;
cl_array(ii) = {mp.Name};
elseif strcmpi(type,'any')
ii = ii + 1;
cl_array(ii) = {mp.Name};
end
end
end
end
end
% Return used portion of array
list = cl_array(1:ii);
end
% TODO
function value = findPropertyDefault(me,propName)
value = [];
if ischar(me) % Determine if first input is object or class name
mc = meta.class.fromName(me);
elseif isobject(me)
mc = metaclass(me);
end
nlist = {mc.PropertyList.Name};
nidx = find(matches(nlist, propName));
if ~isempty(nidx)
value = mc.PropertyList(nidx).DefaultValue;
end
end
% ===================================================================
function obj_out = clone(me)
%> @fn obj_out = clone(me)
%> @brief Use this syntax to make a deep copy of the object, i.e.
%> OBJ_OUT has the same field values, but will not behave as a
%> handle-copy of me anymore.
%>
%> @return obj_out cloned object
% ===================================================================
if isempty(me); obj_out = me; return; end
meta = metaclass(me);
obj_out = feval(class(me),'cloning',true);
for i = 1:length(meta.Properties)
prop = meta.Properties{i};
if strcmpi(prop.SetAccess,'Public') ...
&& ~(prop.Dependent || prop.Constant) ...
&& isprop(obj_out, prop.Name) ...
&& ~(isempty(me.(prop.Name)) ...
&& isempty(obj_out.(prop.Name)))
if isobject(me.(prop.Name)) && isa(me.(prop.Name),'optickaCore')
obj_out.(prop.Name) = me.(prop.Name).clone;
else
try
if ~matches(prop.Name,'font')
obj_out.(prop.Name) = me.(prop.Name);
end
catch ERR %#ok<CTCH>
warning('optickaCore:clone', 'Property not specified: "%s"',prop.Name)
end
end
end
end
% Check lower levels ...
props_child = {meta.PropertyList.Name};
checkSuperclasses(meta)
% This function is called recursively ...
function checkSuperclasses(List)
for ii=1:length(List.SuperclassList(:))
if ~isempty(List.SuperclassList(ii).SuperclassList)
checkSuperclasses(List.SuperclassList(ii))
end
for jj=1:length(List.SuperclassList(ii).PropertyList(:))
prop_super = List.SuperclassList(ii).PropertyList(jj).Name;
if ~strcmp(prop_super, props_child)
obj_out.(prop_super) = me.(prop_super);
end
end
end
end
end
% ===================================================================
function editProperties(me, properties)
%> @fn editProperties
%> @brief method to modify a set of properties
%>
%> @param properties - cell or struct of properties to modify
% ===================================================================
me.addArgs(properties);
end
% ===================================================================
function setProp(me, property, value)
%> @fn setProp(me, property, value)
%> @brief method to fast change a particular value. This is
%> useful for use in anonymous functions, like in the state machine.
%>
%> @param property — the property to change
%> @param value — the value to change it to
% ===================================================================
if isprop(me,property)
me.(property) = value;
end
end
% ===================================================================
function [rM, aM] = initialiseGlobals(me, doReset, doOpen)
%> @fn [rM, aM] = initialiseGlobals(me)
%> @brief in general we try NOT to use globals but for reward and audio, due to
%> e.g. eyelink we can't avoid it. This initialises and returns the globals
%> rM (rewardManager) and aM (audioManager). Run this to get the
%> reward/audio manager objects in any child class...
%>
%> @param doReset - try to reset the object? [false]
%> @param doOpen - try to open the objects if they are not yet
%> open? [false]
% ===================================================================
global rM aM
if ~exist('doReset','var'); doReset = false; end
if ~exist('doOpen','var'); doOpen = false; end
%------initialise the rewardManager global object
if ~isa(rM,'arduinoManager'); rM = arduinoManager(); end
if rM.isOpen && doReset
try rM.close; rM.reset; end
end
if doOpen && ~rM.isOpen; open(rM); end
%------initialise an audioManager for beeps,playing sounds etc.
if ~isa(aM,'audioManager'); aM = audioManager(); end
if doReset
try
aM.silentMode = false;
reset(aM);
catch
warning('Could not reset audio manager!');
aM.silentMode = true;
end
end
if doOpen && ~aM.isOpen && ~aM.silentMode && (isempty(aM.device) || aM.device > -1)
open(aM);
aM.beep(2000,0.1,0.1);
end
end
end
%=======================================================================
methods ( Hidden = true ) %-------HIDDEN METHODS-----%
%=======================================================================
% ===================================================================
function ID = initialiseSaveFile(me)
%> @fn initialiseSaveFile
%> @brief just get date fragment
%>
% ===================================================================
[~,~,ID] = getALF(me);
end
% ===================================================================
function checkPaths(me)
%> @fn checkPaths
%> @brief checks the paths are valid
%>
% ===================================================================
oldhome = me.paths.home;
newhome = getenv('HOME');
if ~matches(newhome,oldhome)
fn = fieldnames(me.paths);
for ii = 1:length(fieldnames(me.paths))
if contains(me.paths.(fn{ii}),oldhome)
me.paths.(fn{ii}) = regexprep(me.paths.(fn{ii}),oldhome,newhome);
end
end
me.paths.oldhome = oldhome;
end
samePath = false;
if isprop(me,'dir')
%if our object wraps a plxReader, try to use its paths
if isprop(me,'p') && isa(me.p,'plxReader')
checkPaths(me.p);
me.dir = me.p.dir; %inherit the path
end
if isprop(me,'matdir') %normally they are the same
if ~isempty(me.dir) && strcmpi(me.dir, me.matdir)
samePath = true;
end
end
if ~exist(me.dir,'dir')
if isprop(me,'file')
fn = me.file;
else
fn = '';
end
fprintf('Please find new directory for: %s\n',fn);
p = uigetdir('',['Please find new directory for: ' fn]);
if p ~= 0
me.dir = p;
else
warning('Can''t find valid source directory');
end
end
end
if isprop(me,'matdir')
if samePath; me.matdir = me.dir; return; end
if ~exist(me.matdir,'dir')
if exist(me.dir,'dir')
me.matdir = me.file;
else
if isprop(me,'matfile')
fn = me.matfile;
else
fn = '';
end
fprintf('Please find new directory for: %s\n',fn);
p = uigetdir('',['Please find new directory for: ' fn]);
if p ~= 0
me.matdir = p;
else
warning('Can''t find valid source directory');
end
end
end
end
if isa(me,'plxReader')
if isprop(me,'eA') && isa(me.eA,'eyelinkAnalysis')
me.eA.dir = me.dir;
end
end
end
end
%=======================================================================
methods ( Static = true ) %-------STATIC METHODS-----%
%=======================================================================
% ===================================================================
function args = makeArgs(args)
%> @fn makeArgs
%> @brief Converts cell args to structure array
%>
%>
%> @param args input data
%> @return args as a structure
% ===================================================================
if isstruct(args); return; end
while iscell(args) && length(args) == 1
args = args{1};
end
if iscell(args)
if mod(length(args),2) == 1 % odd
args = args(1:end-1); %remove last arg
end
odd = logical(mod(1:length(args),2));
even = logical(abs(odd-1));
args = cell2struct(args(even),args(odd),2);
elseif isstruct(args)
return
else
error('---> makeArgs: You need to pass name:value pairs / structure of name:value fields!');
end
end
% ===================================================================
function args = addDefaults(args, defs)
%> @fn addDefaults
%> @brief add default options to arg input
%>
%>
%> @param args input structure from varargin
%> @param defs extra default settings
%> @return args structure
% ===================================================================
if ~exist('args','var'); args = struct; end
if ~exist('defs','var'); defs = struct; end
if iscell(args); args = optickaCore.makeArgs(args); end
if iscell(defs); defs = optickaCore.makeArgs(defs); end
fnameDef = fieldnames(defs); %find our argument names
fnameArg = fieldnames(args); %find our argument names
for i=1:length(fnameDef)
id=cell2mat(cellfun(@(c) strcmp(c,fnameDef{i}),fnameArg,'UniformOutput',false));
if ~any(id)
args.(fnameDef{i}) = defs.(fnameDef{i});
end
end
end
% ===================================================================
function result = hasKey(in, key)
%> @fn hasKey
%> @brief check if a struct / object has a propery / field
%>
%> @param value name
% ===================================================================
result = false;
if isfield(in, key) || isprop(in, key)
result = true;
end
end
% ===================================================================
function [pressed, name, keys, shift] = getKeys(device)
%> @fn getKeys
%> @brief PTB Get key presses, stops key bouncing
% ===================================================================
persistent oldKeys
persistent shiftKey
if ~exist('device','var'); device = []; end
if isempty(oldKeys); oldKeys = zeros(1,256); end
if isempty(shiftKey); shiftKey = KbName('LeftShift'); end
pressed = false; name = []; keys = []; shift = false;
[press, ~, keyCode] = KbCheck(device);
shift = logical(keyCode(shiftKey));
if press
keys = keyCode & ~oldKeys;
if any(keys)
name = KbName(keys);
pressed = true;
end
end
oldKeys = keyCode;
end
end %--------END STATIC METHODS
%=======================================================================
methods ( Access = protected ) %-------PROTECTED METHODS-----%
%=======================================================================
% ===================================================================
function parseArgs(me, args, allowedProperties)
%> @fn parseArgs
%> @brief Sets properties from a structure or normal arguments pairs,
%> ignores invalid or non-allowed properties
%>
%> @param args input structure
%> @param allowedProperties properties possible to set on construction
% ===================================================================
if ischar(allowedProperties)
%we used | for regexp but better use cell array
allowedProperties = strsplit(allowedProperties,'|');
end
args = optickaCore.makeArgs(args);
if isstruct(args)
fnames = fieldnames(args); %find our argument names
for i=1:length(fnames)
if matches(fnames{i},allowedProperties) %only set if allowed property
try
me.(fnames{i})=args.(fnames{i}); %we set up the properies from the arguments as a structure
catch
me.salutation(fnames{i},'Propery invalid!',true);
end
end
end
end
end
% ===================================================================
function addArgs(me, args)
%> @brief Sets properties from a structure or normal arguments pairs,
%> ignores invalid or non-allowed properties
%>
%> @param args input structure
% ===================================================================
args = optickaCore.makeArgs(args);
if isstruct(args)
fnames = intersect(findAttributes(me,'SetAccess','public'),fieldnames(args));
for i=1:length(fnames)
try
if isstruct(me.(fnames{i})) && isstruct(args.(fnames{i}))
fn = fieldnames(args.(fnames{i}));
for j = 1:length(fn)
me.(fnames{i}).(fn{j}) = args.(fnames{i}).(fn{j});
end
else
me.(fnames{i})=args.(fnames{i}); %we set up the properies from the arguments as a structure
end
me.salutation(fnames{i},'SET property')
catch
me.salutation(fnames{i},'Property INVALID!',true);
end
end
end
end
% ===================================================================
function setPaths(me)
%> @brief set paths for object
%>
%> @param
% ===================================================================
me.paths(1).whatami = me.className;
me.paths.root = fileparts(which(mfilename));
me.paths.whereami = me.paths.root;
if ~isfield(me.paths, 'stateInfoFile')
me.paths.stateInfoFile = '';
end
if ismac || isunix
me.paths.home = getenv('HOME');
else
me.paths.home = 'C:';
end
me.paths.parent = [me.paths.home filesep 'OptickaFiles'];
if ~isfolder(me.paths.parent)
status = mkdir(me.paths.parent);
if status == 0; warning('Could not create OptickaFiles folder'); end
end
me.paths.savedData = [me.paths.parent filesep 'SavedData'];
if ~isfolder(me.paths.savedData)
status = mkdir(me.paths.savedData);
if status == 0; warning('Could not create SavedData folder'); end
end
me.paths.protocols = [me.paths.parent filesep 'Protocols'];
if ~isfolder(me.paths.protocols)
status = mkdir(me.paths.protocols);
if status == 0; warning('Could not create Protocols folder'); end
end
me.paths.calibration = [me.paths.parent filesep 'Calibration'];
if ~isfolder(me.paths.calibration)
status = mkdir(me.paths.calibration);
if status == 0; warning('Could not create Calibration folder'); end
end
if isdeployed
me.paths.deploypath = ctfroot;
end
end
% ===================================================================
function getFonts(me)
%> @fn getFonts(me)
%> @brief Checks OS and assigns a sans and mono font
lf = listfonts;
if ismac
me.sansFont = 'Avenir Next';
me.monoFont = 'Menlo';
elseif ispc
me.sansFont = 'Calibri';
me.monoFont = 'Consolas';
else %linux
me.sansFont = 'Ubuntu';
me.monoFont = 'Ubuntu Mono';
end
if matches('Graublau Sans', lf)
me.sansFont = 'Graublau Sans';
elseif matches('Source Sans 3', lf)
me.sansFont = 'Source Sans 3';
elseif matches('Source Sans Pro', lf)
me.sansFont = 'Source Sans Pro';
end
if matches('Fira Code', lf)
me.monoFont = 'Fira Code';
elseif matches('Cascadia Code', lf)
me.monoFont = 'Cascadia Code';
elseif matches('JetBrains Mono', lf)
me.monoFont = 'JetBrains Mono';
end
end
% ===================================================================
function out=toStructure(me)
%> @fn out=toStructure(me)
%> @brief Converts properties to a structure
%>
%>
%> @param me this instance object
%> @param tmp is whether to use the temporary or permanent properties
%> @return out the structure
% ===================================================================
fn = fieldnames(me);
for j=1:length(fn)
out.(fn{j}) = me.(fn{j});
end
end
% ===================================================================
function out = getType(me, in)
%> @brief Give a metaproperty return the likely property class
%>
%>
%> @param me this instance object
%> @param in metaproperty
%> @return out class name
% ===================================================================
out = 'undefined';
thisClass = '';
if in.HasDefault
thisClass = class(in.DefaultValue);
if strcmpi(thisClass,'double') && length(in.DefaultValue) > 1
thisClass = '{[double vector],[]}';
end
elseif ~isempty(in.Validation) && ~isempty(in.Validation.Class)
thisClass = in.Validation.Class.Name;
end
if ~isempty(thisClass); out = thisClass; end
end
% ===================================================================
function logOutput(me, in, message, override)
%> @brief Prints messages dependent on verbosity
%>
%> Prints messages dependent on verbosity
%> @param me this instance object
%> @param in the calling function or main info
%> @param message additional message that needs printing to command window
%> @param override force logging if true even if verbose is false
% ===================================================================
if ~exist('override','var');override = false;end
if me.verbose==true || override == true
if ~exist('message','var') || isempty(message)
fprintf(['---> ' me.fullName_ ': ' in '\n']);
else
fprintf(['---> ' me.fullName_ ': ' message ' | ' in '\n']);
end
end
end
function salutation(me, varargin)
logOutput(me, varargin{:});
end
end
end