Commit d2c38737 authored by jayd1860's avatar jayd1860
Browse files

v1.75.2

-- Sync with shared libraries (submodules).

* DataTree, v1.11.0
-- Change NirsClass.ProbeEqual() to consider measurement lists in different orders but same set of SD pairs to be equal. SO SDgui doesn't think edits were made when they weren't.
-- Add NirsClass.GetChannelsMeanDistance() method same as in SnirfClass

* Utils, v1.4.2
-- Make another tweak in MenuBox - character size doesn't quite equal character units so we compensate by multiplying by scaling factor for button width and height.

* Utils, v1.4.1
-- Fix some size and position issues with radiobutton style MenuBox. Another attempt to simplify size and position calculations.
parent a44aeede
Loading
Loading
Loading
Loading
+64 −11
Original line number Diff line number Diff line
@@ -349,10 +349,23 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
            fields{2} = propnames(obj2.SD);
            
            fieldsToExclude = { ...
                'MeasList'; ...
                'MeasListAct'; ...
                'SrcMap'; ...
                };
            
            
            % Check MeasList explicitely
            if (isfield(obj.SD,'MeasList') && ~isfield(obj2.SD,'MeasList')) || ~isfield(obj.SD,'MeasList') && isfield(obj2.SD,'MeasList')
                return;
            end
            [~, k1] = sortrows(obj.SD.MeasList);
            [~, k2] = sortrows(obj2.SD.MeasList);
            if ~all(obj.SD.MeasList(k1,:) == obj2.SD.MeasList(k2,:))
                return;
            end            

            
            for kk = 1:length(fields)
                for jj = 1:length(fields{kk})
                    field = fields{kk}{jj};
@@ -363,7 +376,7 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
                    end                    
                    
                    % Now compare field
                    if ~isfield(obj.SD,field) || ~isfield(obj2.SD,field)
                    if (isfield(obj.SD,field) && ~isfield(obj2.SD,field)) || ~isfield(obj.SD,field) && isfield(obj2.SD,field) 
                        return;
                    end
                    if eval( sprintf('~strcmp(class(obj.SD.%s), class(obj2.SD.%s))', field, field) )
@@ -1070,7 +1083,11 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
        
        
        % ----------------------------------------------------------------------------------
        function SetProbeSpatialUnit(obj, spatialUnitNew, scaling)
        function SetProbeSpatialUnit(obj, spatialUnitNew, scaling, ndims)
            if ~exist('ndims','var')
                ndims = '2d';
            end
            
            % Set scaling based on current units and desired units if they do not match AND
            % scaling was not explcitly specified (i.e., passed in as an argument). 
            if ~exist('scaling','var') || isempty(scaling)
@@ -1100,6 +1117,8 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
            
            
            obj.SD.SpatialUnit = spatialUnitNew;
            
            if isempty(ndims) || strcmpi(ndims, '2D')
                obj.SD.SrcPos = obj.SD.SrcPos * scaling;
                obj.SD.DetPos = obj.SD.DetPos * scaling;
                obj.SD.DummyPos = obj.SD.DummyPos * scaling;
@@ -1108,8 +1127,14 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
                    obj.SD.SpringList(lst,3) = obj.SD.SpringList(lst,3) * scaling;
                end
                obj.SD.Landmarks.pos = obj.SD.Landmarks.pos * scaling;
            end
            
            if isempty(ndims) || strcmpi(ndims, '3D')
                obj.SD.SrcPos3D = obj.SD.SrcPos3D * scaling;
                obj.SD.DetPos3D = obj.SD.DetPos3D * scaling;
                obj.SD.DummyPos3D = obj.SD.DummyPos3D * scaling;
                obj.SD.Landmarks3D.pos = obj.SD.Landmarks3D.pos * scaling;
            obj.SD.Landmarks2D.pos = obj.SD.Landmarks2D.pos * scaling;
            end
        end
        
        
@@ -1261,6 +1286,7 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
        end        
        
        
        
        % ----------------------------------------------------------------------------------
        function CopyStruct(obj, s)            
            fields = propnames(obj);
@@ -1295,6 +1321,7 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
        end
        
        
        
        % ----------------------------------------------------------------------------------
        function ConvertSnirfData(obj, snirf)
            obj.d = snirf.data(1).dataTimeSeries;
@@ -1302,6 +1329,7 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
        end
        
        
        
        % ----------------------------------------------------------------------------------
        function ConvertSnirfStim(obj, snirf)
            obj.s = zeros(length(obj.t), length(snirf.stim));
@@ -1325,6 +1353,7 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
        end
        
        
        
        % ----------------------------------------------------------------------------------
        function ConvertSnirfAux(obj, snirf)
            obj.aux = zeros(length(obj.t), length(snirf.aux));
@@ -1334,6 +1363,7 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
        end
        
        
        
        % ----------------------------------------------------------------------------------
        function ConvertSnirf(obj, snirf)
            obj.ConvertSnirfProbe(snirf);
@@ -1345,6 +1375,27 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass

        
        
        % -----------------------------------------------------------------------
        function [md2d, md3d] = GetChannelsMeanDistance(obj)
            md2d = [];
            md3d = [];            
            ml = obj.SD.MeasList;
            if isempty(ml)
                return
            end
            k = find(ml(:,4)==1);
            ml = ml(k,:);
            d1 = zeros(size(ml,1),1);
            for ii = 1:length(d1)
                d1(ii) = dist3(obj.SD.SrcPos(ml(ii,1),:), obj.SD.DetPos(ml(ii,2),:)); 
                d2(ii) = dist3(obj.SD.SrcPos3D(ml(ii,1),:), obj.SD.DetPos3D(ml(ii,2),:)); 
            end
            md2d = mean(d1);
            md3d = mean(d2);
        end
        
        
        
        % ----------------------------------------------------------------------------------        
        function ErrorCheck(obj)
            if isempty(obj)
@@ -1391,6 +1442,7 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
        end
        
        
        
        % ----------------------------------------------------------------
        function [str, fields] = Properties2String(obj)
            str = '';
@@ -1405,6 +1457,7 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
        end
        
        
        
        % -------------------------------------------------------
        function changes = StimChangesMade(obj)                        
            % Load stims from file
+1 −1
Original line number Diff line number Diff line
1.10.0
 No newline at end of file
1.11.0
 No newline at end of file
+85 −79
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ function [answer, hf] = MenuBox(msg, bttns, relativePos, textLineWidth, options)
%   q = MenuBox('Please select option',{'option1','option2','option3'},[],[],'dontAskAgain:radiobutton');
%   q = MenuBox('Please select option',{'option1','option2','option3'},'upperright',80,'askEveryTime:radiobutton');
%
answer = [];
hf = [];

global bttnIds
global selection
@@ -31,9 +33,6 @@ global selectionStyle
bttnIds = 0;
selection = 0;

DEBUG=0;
DEBUG2=0;

% Parse args
if iscell(msg)
    msg = [msg{:}];
@@ -61,14 +60,6 @@ else
    selectionStyle = 'pushbutton';
end

bttnstrlenmax = 0;
for ii = 1:length(bttns)
    if length(bttns{ii})>bttnstrlenmax
        bttnstrlenmax = length(bttns{ii});
    end
end
bttnstrlenmin = 7;

% Syntax for special call of MenuBox to ONLY get back the selection of
% "ask/don't ask" checkbox strings, then exit function
checkboxes  = getCheckboxes(options);
@@ -77,39 +68,73 @@ if isempty(msg)
    return;
end

length(find(msg == sprintf('\n'))); %#ok<*SPRINTFN>

nchar        = length(msg);
nNewLines    = length(find(msg == sprintf('\n'))); %#ok<*SPRINTFN>
ncheckboxes = length(checkboxes);
nbttns       = length(bttns)+ncheckboxes;
if bttnstrlenmax<bttnstrlenmin
    Wbttn = 2.1*bttnstrlenmin;
else
    Wbttn = 2.1*bttnstrlenmax;


% Initial X size and position of text
Wtext = 70;

Hk = 1.2;
Htext = ceil(length(msg) / Wtext)*Hk;
HtextGap0 = 2;
HtextGap = 2;

% Initial X sizes and positions of buttons
Wbttn = 65;
WbttnMin = 20;
XbttnOffset = 5;


% Calculate standard width of buttons
WbttnMaxActual = length(bttns{1});
for ii = 1:length(bttns)
    if length(bttns{ii}) > WbttnMaxActual
        WbttnMaxActual = length(bttns{ii});
    end
end
if WbttnMaxActual < Wbttn
    Wbttn = WbttnMaxActual;
end
if WbttnMaxActual < WbttnMin
    Wbttn = WbttnMin;
end
Hbttn = 2.7;

if Wbttn < textLineWidth
    Wtext = textLineWidth;                       % In char units
    kW = Wtext;
else
    Wtext = 1.1 * Wbttn;
    kW = Wbttn;
% Initial Y size and position of buttons
Hbttn = 1;
HbttnGap = 3;

% Calculate standard height of buttons
for ii = 1:length(bttns)    
    temp = ceil(length(bttns{ii}) / Wbttn);
    if temp > Hbttn
        Hbttn = temp;
    end
end
Htext = round(nchar / Wtext)+4 + nNewLines;


% Position/dimensions in the X direction
a    = (.1 * kW);
Wfig = kW + 2*a;                % GUI width
% Character size doesn't quite equal character units so we compensate by multiplying by 
% scaling factor in the x and y directions
Wbttn = Wbttn*1.3;
Hbttn = Hbttn*2;


% Position/dimensions in the Y direction
vertgap = 1.2;
Hfig    = (Htext+vertgap+1) + nbttns*(Hbttn+vertgap) + vertgap*1.5;
% Figure size and position 
if strcmpi(selectionStyle, 'radiobutton')
    Hc = 10;
else
    Hc = 5;
end
XtextOffset = Wtext/8;
Wfig = Wtext + 2*XtextOffset;
HfigBottom = nbttns * (Hbttn + HbttnGap) + Hc;
HfigTop = HtextGap0 + Htext + HtextGap;
Hfig = HfigTop + HfigBottom;

% Get position of parent GUI in character units
hf = figure('numbertitle', 'off', 'menubar','none', 'toolbar','none', 'name',title);
%set(hf, 'visible','off');
set(hf, 'units','characters');

hParent = get(groot,'CurrentFigure');
if isempty(hParent)
    hParent = hf;
@@ -117,69 +142,50 @@ end
set(hParent, 'units','characters');
posParent = get(hParent, 'position');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate GUI objects position/dimensions in the Y and Y
% directions, in characters units
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(hf, 'visible','off');
set(hf, 'units','characters');

% Determine optimal position of MenuBox relative to parent GUI
if hf == hParent
    pX = posParent(1);
    pY = posParent(2);
else
    [pX, pY] = positionRelative(hf, posParent, relativePos);
posBox = [pX, pY, Wfig, Hfig];

if DEBUG
    fprintf('posBox = [%0.1f, %0.1f, %0.1f, %0.1f]\n', posBox(1), posBox(2), posBox(3), posBox(4));
end


% Set GUI position/size
posBox = [pX, pY, Wfig, Hfig];
set(hf, 'position', posBox);
if strcmpi(selectionStyle, 'radiobutton')
    DispSaveCancelBttns(hf);
end
p = get(hf, 'position');

kW = 8;
% Display message
if DEBUG2
    fprintf('message position:   [%0.1f, %0.1f, %0.1f, %0.1f]\n', p(3)/4, p(4)-(Htext+vertgap),(kW-2)*(p(3)/kW), Htext);
    ht = uicontrol('parent',hf, 'style','text', 'units','characters', 'string',msg, ...
        'position',[[p(3)/kW, p(4)-(Htext+vertgap), (kW-2)*(p(3)/kW), Htext]], 'horizontalalignment','center', ...
        'backgroundcolor',[.2,.2,.2], 'foregroundcolor',[.9,.9,.9]);
else
    ht = uicontrol('parent',hf, 'style','text', 'units','characters', 'string',msg, ...
        'position',[p(3)/kW, p(4)-(Htext+vertgap), (kW-2)*(p(3)/kW), Htext], 'horizontalalignment','left');
end

% Draw button options
hb = zeros(nbttns,1);
p  = zeros(nbttns,4);
TextPos = get(ht, 'position');
YbttnStart = Htext + 2*HtextGap;

%fprintf('[ %0.1f, %0.1f, %0.1f, %0.1f ]\n', [XtextOffset, HfigBottom+HtextGap, Wtext, Htext]);
fprintf('Hfig = %0.1f, HtextGap0 = \n', p(4)-(HtextGap0+Htext));
ht = uicontrol('parent',hf, 'style','text', 'units','characters', 'string',msg, ...
    'position',[XtextOffset, p(4)-(HtextGap0+Htext), Wtext, Htext], 'horizontalalignment','left');
for k = 1:nbttns
    Ypfk = TextPos(2) - k*(Hbttn+vertgap);
    p(k,:) = [a, Ypfk, Wbttn, Hbttn];
    
    if DEBUG2
        fprintf('%d) %s:   p1 = [%0.1f, %0.1f, %0.1f, %0.1f]\n', k, bttns{k}, p(k,1), p(k,2), p(k,3), p(k,4));
    end
    
    Ypfk = Hfig - (YbttnStart + k*(Hbttn+HbttnGap));
    p = [XbttnOffset, Ypfk, Wbttn, Hbttn];    
    if k > (nbttns-ncheckboxes)
        val = GetCheckboxValue(k, nbttns, ncheckboxes, options);
        hb(k) = uicontrol('parent',hf, 'style','checkbox', 'string',checkboxes{k-(nbttns-ncheckboxes)}, 'units','characters', ...
            'position',[p(k,1), p(k,2), 2*length(checkboxes{k-(nbttns-ncheckboxes)}), p(k,4)], 'value',val, ...
            'position',[p(1), p(2), 2*length(checkboxes{k-(nbttns-ncheckboxes)}), p(4)], 'value',val, ...
            'tag',sprintf('%d', k-(nbttns-ncheckboxes)), 'callback',{@checkboxDontAskOptions_Callback, hf});
        
        checkboxDontAskOptions_Callback(hb(k), [], hf);
    else
        hb(k) = uicontrol('parent',hf, 'style',selectionStyle, 'string',bttns{k}, 'units','characters', 'position',p(k,:), ...
        if strcmpi(selectionStyle, 'radiobutton')
            hb = uicontrol('parent',hf, 'style',selectionStyle, 'string','', 'units','characters', 'position',[p(1), p(2), 4, p(4)], ...
                'tag',sprintf('%d', k), 'callback',@pushbuttonGroup_Callback);
            
            uicontrol('parent',hf, 'style','text', 'string',bttns{k}, 'units','characters', 'position',[p(1)+4, p(2), p(3), p(4)], ...
                'horizontalalignment','left', 'fontsize',8);
        else
            uicontrol('parent',hf, 'style',selectionStyle, 'string',bttns{k}, 'units','characters', 'position',[p(1), p(2), p(3), p(4)+Hbttn/2], ...
                'tag',sprintf('%d', k), 'callback',@pushbuttonGroup_Callback);
        end
    end
end

% Need to make sure position data is saved in pixel units at end of function
% to as these are the units used to reposition GUI later if needed
setGuiFonts(hf);
p = guiOutsideScreenBorders(hf);

+1 −1
Original line number Diff line number Diff line
1.4.0
 No newline at end of file
1.4.2
 No newline at end of file
+7 −0
Original line number Diff line number Diff line
@@ -22,6 +22,13 @@ set(hObject, 'units','normalized');
Ps = get(0,'MonitorPositions');
p = get(hObject,'position');

% Don't do anything if within screen borders in all directions
if ((p(1)+p(3)) < 1) && (p(1) > 0)
    if ((p(2)+p(4)) < 1) && (p(2) > 0)
        return
    end
end

% To work correctly for mutiple sceens, Ps must be sorted in ascending order
Ps = sort(Ps,'ascend');

Loading