function enableAsPerWEcType(handles)
% enableAsPerWEcType
%   enableAsPerWEcType(handles), internal function for dis/enabling components on
%   main GUI

%   Project: IMPACT
%   Title of Code: enableAsPerWEcType
%   Relevant additional documentation:
%   Developer: Carlos Gonzalez
%   External Dependencies: NA
%
%   Disclaimer
%   CAUTION: It is strongly recommended that changes to this code
%   should be avoided without first consulting with authors.

if handles.iWecType==1 || handles.iWecType==2
    disable(handles.edit_sparImpedance);
    disable(handles.edit_floaterFexc);
    disable(handles.edit_sparFexc);
    disable(handles.edit_floaterImpedanceX);
    disable(handles.edit_sparImpedanceX);
    disable(handles.edit_floaterFexcX);
    disable(handles.edit_sparFexcX);
    disable(handles.pushbutton_EKFX);
    disable(handles.edit_ptoContX);
    disable(handles.edit_displacementLimitX);
    disable(handles.edit_gainPLDX);
    popupMenuList = {'Floater Impedance'};
    stListbox1 = {'u1';'PTO Force Demand'};
    stController = {'C1'};
elseif handles.iWecType==3 
    enable(handles.edit_sparImpedance);
    enable(handles.edit_floaterFexc);
    enable(handles.edit_sparFexc);
    disable(handles.pushbutton_EKFX);
    disable(handles.edit_floaterImpedanceX);
    disable(handles.edit_sparImpedanceX);
    disable(handles.edit_floaterFexcX);
    disable(handles.edit_sparFexcX);
    disable(handles.edit_ptoContX);
    disable(handles.edit_displacementLimitX);
    disable(handles.edit_gainPLDX);
    popupMenuList = {'Floater Impedance';'Spar Impedance'; 'Floater Excitation';'Spar Excitation'};
    stListbox1 = {'u1';'PTO Force Demand'};
    stController = {'C1'};
else
    enable(handles.edit_sparImpedance);
    enable(handles.edit_floaterFexc);
    enable(handles.edit_sparFexc);
    enable(handles.edit_floaterImpedanceX);
    enable(handles.edit_sparImpedanceX);
    enable(handles.edit_floaterFexcX);
    enable(handles.edit_sparFexcX);
    enable(handles.pushbutton_EKFX);
    enable(handles.edit_ptoContX);
    enable(handles.edit_displacementLimitX);
    enable(handles.edit_gainPLDX);
    popupMenuList = {'Floater Impedance';'Spar Impedance'; 'Floater Excitation';'Spar Excitation';...
        'Floater Impedance X';'Spar Impedance X'; 'Floater Excitation X';'Spar Excitation X'};
    stListbox1 = {'u1';'PTO Force Demand';'u2'};
    stController = {'C1';'C2'};

end
iValue = get(handles.popupmenu_designView,'Value');
set(handles.popupmenu_designView,'String',stController);
set(handles.popupmenu_designView,'Value',min(iValue,numel(stController)));


iValue1 = get(handles.listbox1,'Value');
zValues1 = get(handles.listbox1,'String');
stOption1 = zValues1{min(iValue1,numel(stListbox1))};

iValue2 = get(handles.listbox2,'Value');
zValues2 = get(handles.listbox2,'String');
stOption2 = zValues2{iValue2};

set(handles.listbox1,'String',stListbox1);
set(handles.listbox1,'Value',min(iValue1,numel(stListbox1)));


if strcmpi(stOption1,'u1') && strcmpi(stOption2,'Relative velocity')
    set(handles.radiobutton_CL,'Enable','on');
else
    set(handles.radiobutton_CL,'Enable','off');
    set(handles.radiobutton_OL,'Value',1);
    set(handles.radiobutton_CL,'Value',0);
end

iValue = get(handles.listbox2,'Value');
if ~strcmpi(stOption1,'u1') && handles.iWecType==3
    stOutput = {'Relative velocity';'Floater velocity'; 'Spar velocity'};
elseif ~strcmpi(stOption1,'u1') && handles.iWecType==4
    stOutput = {'Relative velocity';'Floater velocity'; 'Spar velocity';...
        'Relative velocity X';'Floater velocity X'; 'Spar velocity X'};
else
    stOutput = {'Relative velocity'};
end
set(handles.listbox2,'String',stOutput);
set(handles.listbox2,'Value',min(iValue,numel(stOutput)));

set(handles.popupmenu_fitTfs,'String',popupMenuList);
if handles.iWecType==1 || handles.iWecType==2
    set(handles.popupmenu_fitTfs,'Value',1);
end
guidata(handles.controller_design,handles);


function enable(hndl)
set(hndl,'Enable','on');
    

function disable(hndl)
set(hndl,'Enable','off');