itaVA_setup.m 14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
function varargout = itaVA_setup(varargin)
% ITAVA_SETUP MATLAB code for itaVA_setup.fig
%      ITAVA_SETUP, by itself, creates a new ITAVA_SETUP or raises the existing
%      singleton*.
%
%      H = ITAVA_SETUP returns the handle to a new ITAVA_SETUP or the handle to
%      the existing singleton*.
%
%      ITAVA_SETUP('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ITAVA_SETUP.M with the given input arguments.
%
%      ITAVA_SETUP('Property','Value',...) creates a new ITAVA_SETUP or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before itaVA_setup_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to itaVA_setup_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help itaVA_setup

25
% Last Modified by GUIDE v2.5 08-Feb-2017 15:42:50
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

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @itaVA_setup_OpeningFcn, ...
                   'gui_OutputFcn',  @itaVA_setup_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before itaVA_setup is made visible.
function itaVA_setup_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to itaVA_setup (see VARARGIN)

% Choose default command line output for itaVA_setup
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

61
% VAMatlab
62 63 64
current_va_mex_dir = which( 'VAMatlab' );
if ~isempty( current_va_mex_dir )
    [ va_mex_path, ~, ~ ] = fileparts( current_va_mex_dir );
65 66 67 68
    [ va_path, ~, ~ ] = fileparts( va_mex_path );
    set( handles.va_search_dir, 'String', fullfile( va_path ) );
    
    set( handles.edit_vamatlab_full_path, 'String', current_va_mex_dir )
69 70 71 72 73 74
    try
        v = VAMatlab( 'getVersion' );
        set( handles.edit_vamatlab_version, 'String', v )
    catch
        set( handles.edit_vamatlab_version, 'String', 'Failed to execute VAMatlab, probably a depending library is missing.' )
    end
75 76 77 78 79 80 81
end

% VAServer
current_va_server_dir = which( 'VAServer.exe' );
if ~isempty( current_va_server_dir )
    set( handles.edit_vaserver_full_path, 'String', current_va_server_dir )
    [ ~, v ] = system( [ current_va_server_dir ' --version' ] );
82 83 84 85
    vs = strsplit( v, '\n' );
    for i = 1:numel( vs )
        vss = vs{ 1, i };
        if numel( vss ) > 6
86 87 88
            if strcmpi( vss( 3:10 ), 'VAServer' )
                server_version = vss( 15:end );
                set( handles.edit_vaserver_version, 'String', strcat( server_version ) )
89 90 91
            end
        end
    end
92 93
end

94
% NatNetML
95 96 97
current_natnet_dir = which( 'NatNetML.dll' );
if ~isempty( current_natnet_dir )
    ainfo = NET.addAssembly( current_natnet_dir );
98 99
    client = NatNetML.NatNetClientML( 0 );
    natnetversion_raw = client.NatNetVersion;
100 101 102 103
    vs = sprintf( 'NatNetML (OptiTrack) %d.%d', natnetversion_raw(1), natnetversion_raw(2) );
    set( handles.edit_natnet_version, 'String', vs )
end

104
uiwait( handles.figure1 );
105 106 107 108 109 110 111 112 113 114


% --- Outputs from this function are returned to the command line.
function varargout = itaVA_setup_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
115 116 117
if ~isempty( handles )
    varargout{1} = handles.output;
end
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


% --- Executes on button press in pushbutton_close.
function pushbutton_close_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_close (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close( gcf )


function edit_vamatlab_full_path_Callback(hObject, eventdata, handles)
% hObject    handle to edit_vamatlab_full_path (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_vamatlab_full_path as text
%        str2double(get(hObject,'String')) returns contents of edit_vamatlab_full_path as a double


% --- Executes during object creation, after setting all properties.
function edit_vamatlab_full_path_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_vamatlab_full_path (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function edit_vaserver_full_path_Callback(hObject, eventdata, handles)
% hObject    handle to edit_vaserver_full_path (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_vaserver_full_path as text
%        str2double(get(hObject,'String')) returns contents of edit_vaserver_full_path as a double


% --- Executes during object creation, after setting all properties.
function edit_vaserver_full_path_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_vaserver_full_path (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes during object creation, after setting all properties.
function va_search_dir_CreateFcn(hObject, eventdata, handles)
% hObject    handle to va_search_dir (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function checkbox_recursively_Callback(hObject, eventdata, handles)
function checkbox_permanently_Callback(hObject, eventdata, handles)

% --- Executes on button press in pushbutton_va_dir_browse.
function pushbutton_va_dir_browse_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_va_dir_browse (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

start_path = get( handles.va_search_dir, 'String' );
if exist( start_path, 'file' ) ~= 7
    start_path = pwd;
end

va_search_dir = uigetdir( start_path );

if ~isempty( va_search_dir )
    set( handles.va_search_dir, 'String', va_search_dir )
    find_VA( va_search_dir, handles )
end

function find_VA( va_search_dir, handles )

recursive_flag = get( handles.checkbox_recursively, 'Value' );
permanent_flag = get( handles.checkbox_permanently, 'Value' );

set( handles.edit_vamatlab_full_path, 'String', 'Scanning ... ' )
set( handles.edit_vaserver_full_path, 'String', 'Scanning ... ' )

% VAMatlab
[ vamatlab_found, vamatlab_dir ] = find_VA_Component( va_search_dir, [ 'VAMatlab.' mexext ], recursive_flag );
if vamatlab_found
    addpath( vamatlab_dir )
    if permanent_flag
        savepath
    end
    set( handles.edit_vamatlab_full_path, 'String', fullfile( vamatlab_dir, [ 'VAMatlab.' mexext ] ) )
    v = VAMatlab( 'getVersion' );
    set( handles.edit_vamatlab_version, 'String', v )
else
    set( handles.edit_vamatlab_full_path, 'String', 'not found' )
end

% VAServer
[ vaserver_found, vaserver_dir ] = find_VA_Component( va_search_dir, 'VAServer.exe', recursive_flag );
if vaserver_found
    addpath( vaserver_dir )
    if permanent_flag
        savepath
    end
    vaserver_path = fullfile( vaserver_dir, 'VAServer.exe' );
    set( handles.edit_vaserver_full_path, 'String', vaserver_path )
237
    [ ~, v ] = system( [ vaserver_path ' --version' ] );
238 239 240 241
    vs = strsplit( v, '\n' );
    for i = 1:numel( vs )
        vss = vs{ 1, i };
        if numel( vss ) > 6
242 243 244
            if strcmpi( vss( 3:10 ), 'VAServer' )
                server_version = vss( 15:end );
                set( handles.edit_vaserver_version, 'String', strcat( server_version ) )
245 246 247
            end
        end
    end
248 249 250 251 252 253 254 255
else
    set( handles.edit_vaserver_full_path, 'String', 'not found' )
end

function [ found, va_component_dir ] = find_VA_Component( va_search_dir, component, recursive )
found = false;
va_component_dir = '';

256 257 258
if isempty( va_search_dir )
    return % something went wrong
end
259 260 261 262 263 264 265 266
if ~va_search_dir
    return;
end

if exist( fullfile( va_search_dir, component ), 'file' )
    found = true;
    va_component_dir = fullfile( va_search_dir ); % Base path is one folder up
end
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
if ~found && recursive
    listing = dir( va_search_dir );    
    for idx = 1:length( listing )
        current_file_name = listing( idx ).name;
        if listing( idx ).isdir && current_file_name(1) ~= '.'
            [ found, va_component_dir ] = find_VA_Component( fullfile( va_search_dir, current_file_name ), component, recursive );
            if found
                break % Find first
            end
        end 
    end
end



function va_search_dir_Callback(hObject, eventdata, handles)
% hObject    handle to va_search_dir (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of va_search_dir as text
%        str2double(get(hObject,'String')) returns contents of va_search_dir as a double


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton_close.
function pushbutton_close_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton_close (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close( handles.gui )



function edit_vamatlab_version_Callback(hObject, eventdata, handles)
% hObject    handle to edit_vamatlab_version (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_vamatlab_version as text
%        str2double(get(hObject,'String')) returns contents of edit_vamatlab_version as a double


% --- Executes during object creation, after setting all properties.
function edit_vamatlab_version_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_vamatlab_version (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_vaserver_version_Callback(hObject, eventdata, handles)
% hObject    handle to edit_vaserver_version (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_vaserver_version as text
%        str2double(get(hObject,'String')) returns contents of edit_vaserver_version as a double


% --- Executes during object creation, after setting all properties.
function edit_vaserver_version_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_vaserver_version (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367



function edit_natnet_version_Callback(hObject, eventdata, handles)
% hObject    handle to edit_natnet_version (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_natnet_version as text
%        str2double(get(hObject,'String')) returns contents of edit_natnet_version as a double


% --- Executes during object creation, after setting all properties.
function edit_natnet_version_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_natnet_version (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end