function flexbtns
%
% Function: flexbtns
% 
% Usage: flexbtns
%
% Description:
%    Initializes the Flexibility Analysis Window
%    Handles and graphics elements.
%    Returns a vector to those elements.
%

% Version SWD970902
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This matlab source code was originally     %
% developed as part of "DIAMOND" at          %
% Los Alamos National Laboratory. It may     %
% be copied, modified, and distributed in    %
% any form, provided:                        %
%  a) This notice accompanies the files and  %
%     appears near the top of all source     %
%     code files.                            %
%  b) No payment or commercial services are  %
%     received in exchange for the code.     %
%                                            %
% Original copyright is reserved by the      %
% Regents of the University of California,   %
% in addition to Scott W. Doebling, Phillip  %
% J. Cornwell, Erik G. Straser, and Charles  %
% R. Farrar.                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global HANDLES

%====================================
% General buttons parameters
%====================================
top=.95;
left=.84;
btnwd=.15;
btnht=.08;
spacing=.01;

%====================================
% Set up the console frame
%=====================================
frmborder=0.01;
ypos=.05-frmborder;
frmpos=[left-frmborder ypos btnwd+2*frmborder .95+2*frmborder];
HANDLES.hflexb(1)=uicontrol(HANDLES.hfigdmnd, ...
        'Style','Frame', ...
        'Position',frmpos, ...
        'BackgroundColor',[.5 .5 .5]);

%
% Set up plot axes
%

HANDLES.hflexb(2) = axes('position',[.1 .22 .7 .7],'dataaspectratio',[1 1 1]);

%
% Set up legend axes
%

HANDLES.hflexb(15) = axes('position',[.1 .1 .7 .10]);

%
% Loading DOF Textbox
%
btnnum=2;
ypos=top-(btnnum-1)*(btnht+spacing)+2*spacing;
btnpos=[left ypos-btnht btnwd btnht/2];
HANDLES.hflexb(4)=uicontrol(HANDLES.hfigdmnd, ...
      'style','text', ...
      'position',btnpos, ...
      'string','Loaded DOF');

btnpos=[left ypos-btnht*3/2 btnwd btnht/2];
HANDLES.hflexb(5)=uicontrol(HANDLES.hfigdmnd, ...
   'style','edit', ...
   'position',btnpos, ...
   'string','1',...
   'callback',...
   ['iflex_t = str2num(get(HANDLES.hflexb(5),''string''));',...
      'if iflex_t < 1,',...
      '   DAMAGEID.iflexdof = 1;',...
      'elseif iflex_t > length(DAMAGEID.undammode{1}),',...
      '   DAMAGEID.iflexdof = length(DAMAGEID.undammode{1});',...
      'else,',...
      '   DAMAGEID.iflexdof = iflex_t;',...
      'end,',...
      'set(HANDLES.hflexb(5),''string'',num2str(DAMAGEID.iflexdof)),']);
%
%  Positive/Negative Loading
%

btnnum=3.0;
ypos=top-(btnnum-1)*(btnht+spacing)+2*spacing;
btnpos=[left ypos-btnht btnwd btnht/2];
HANDLES.hflexb(13)  = uicontrol(HANDLES.hfigdmnd, ...
      'style','text', ...
      'position',btnpos, ...
      'string','Loading Sign');

btnpos(2) = btnpos(2) - btnht/2;
HANDLES.hflexb(6)  = uicontrol(HANDLES.hfigdmnd, ...
   'style','popup', ...
   'position',btnpos, ...
   'Value',1,...
   'string','Positive|Negative',...
   'callback',...
   ['if get(HANDLES.hflexb(6),''value'') == 1,',...
      '	DAMAGEID.iflexsgn = 1;',...
      'else,',...
      '	DAMAGEID.iflexsgn = -1;',...
      'end,']);

%
%  Flexibility Loading Type
%

btnnum=4;
ypos=top-(btnnum-1)*(btnht+spacing)+2*spacing;
btnpos=[left ypos-btnht btnwd btnht/2];
HANDLES.hflexb(7)  = uicontrol(HANDLES.hfigdmnd, ...
      'style','text', ...
      'position',btnpos, ...
      'string','Loading Type');

btnpos(2) = btnpos(2) - btnht/2;
HANDLES.hflexb(8)  = uicontrol(HANDLES.hfigdmnd, ...
   'style','popup', ...
   'position',btnpos, ...
   'Value',1,...
   'string','Uniform|Multi-Point|Single Point',...
   'callback',...
   ['switch get(HANDLES.hflexb(8),''value'');',...
      'case 1, DAMAGEID.nflexload = ''Uniform'';',...
      '	 set(HANDLES.hflexb(4:5),''visible'',''off''),',...
      'case 2, DAMAGEID.nflexload = ''Multi Point'';',...
      '	 set(HANDLES.hflexb(4:5),''visible'',''off''),',...
      'case 3, DAMAGEID.nflexload = ''Single Point'';',...
      '   set(HANDLES.hflexb(4:5),''visible'',''on''),',...
      '   DAMAGEID.iflexdof = str2num(get(HANDLES.hflexb(5),''string''));',...
		'end']);


%
%  Plot Type
%

btnnum=5;
ypos=top-(btnnum-1)*(btnht+spacing)+2*spacing;
btnpos=[left ypos-btnht btnwd btnht/2];
HANDLES.hflexb(14)  = uicontrol(HANDLES.hfigdmnd, ...
      'style','text', ...
      'position',btnpos, ...
      'string','Plot Type');

btnpos(2) = btnpos(2) - btnht/2;
HANDLES.hflexb(9)  = uicontrol(HANDLES.hfigdmnd, ...
      'style','popup', ...
      'position',btnpos, ...
      'Value',1,...
      'string','Flex Change|Undamaged Flex|Damaged Flex',...
      'callback',...
      ['switch get(HANDLES.hflexb(9),''value'');',...
         'case 1, DAMAGEID.iflextype = ''Flexibility Change'';',...
         'case 2, DAMAGEID.iflextype = ''Undamaged Flexibility'';',...
         'case 3, DAMAGEID.iflextype = ''Damaged Flexibility'';',...
         'end,']);

%
% Plot Flexibility Shape
%

btnnum=7;
ypos=top-(btnnum-1)*(btnht+spacing)+2*spacing;
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.hflexb(10)=uicontrol(HANDLES.hfigdmnd, ...
   'style','pushbutton', ...
   'position',btnpos, ...
   'string','Plot Flex',...
   'callback',...
   ['clear undammode dammode undamfreq damfreq,',...
      'for j = 1:length(DAMAGEID.mode_anal),',...
      '   undammode(:,j) = DAMAGEID.undammode{DAMAGEID.mode_anal(j)}'';',...
      '   dammode(:,j) = DAMAGEID.dammode{DAMAGEID.mode_anal(j)}'';',...
      '   undamfreq(j) = DAMAGEID.undamFreq{DAMAGEID.mode_anal(j)}'';',...
      '   damfreq(j) = DAMAGEID.damFreq{DAMAGEID.mode_anal(j)}'';',...
      'end,',...
      'DAMAGEID.undamflex = undammode/diag(2*pi*undamfreq)^2 * undammode'';',...
      'DAMAGEID.damflex = dammode/diag(2*pi*damfreq)^2 * dammode'';',...
      'plotflex,']);

%
% Select the modes to use in the analysis
%
btnnum=9;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.hflexb(12)=uicontrol(HANDLES.hfigdmnd, ...
      'style','pushbutton', ...
      'position',btnpos, ...
      'string','Select Modes', ...
      'Callback', ...
      ['set(HANDLES.hmdsel(1),''visible'',''on''), figure(HANDLES.hmdsel(1)),']);

set(HANDLES.hflexb,'visible','off')

return

