clear all;
close all;
clc;

% schuss_start beschreibt die Eingabemasken des Programms, uebergibt die
% Eingabewerte an schuss1 bzw schuss2

%Falls wahl == 1 wird Userinterface geoeffnet
%Falls wahl == 2 wird einfache Eingabemaske angezeigt
auswahl = {'Abschuss mit Anfangsbedingungen', 'Abschuss mit Zielerfassung'};
aufforderung = {'Bitte waehlen Sie die Art der Flugbahn - Berechnung:'};

[wahl] = listdlg('ListString',auswahl,'PromptString',aufforderung,'SelectionMode','single','ListSize',[400 100]);

if (wahl == 1 | wahl == 2)

scrsz = get(0,'ScreenSize');
h = figure('Position',[50 100 scrsz(3)-100 scrsz(4)-150],'KeyPressFcn',@rueck);

hl = uipanel('Title','Vergleichende Darstellung der Flugbahnen','Fontsize',12,...
  'BackgroundColor',[.9 .9 .9],...
  'Units','Normalized',...
  'Position',[0 0 .5 1]);

hp = uipanel('Title','Startbedingungen','FontSize',12,...
  'BackgroundColor',[.9 .9 .9],...
  'Units','Normalized',...
  'Position',[.5 0 .5 1]);

% Positionierung bzw. Art der Eingabefelder
z0_e = uicontrol('Style','Edit','String','0','Parent',hp,...
  'Units','Normalized',...
  'Position',[.6 .9 .3 .05]);
if wahl == 1
    v0_e = uicontrol('Style','Slider','Parent',hp,...
      'Min',0,'Max',10000,'SliderStep',[0.001 0.01],...
      'Units','Normalized',...
      'Value',1000,...
      'Callback','v0anzeige',...
      'Position',[.6 .83 .3 .05]);
    v02 = uicontrol('Style','Edit','String','1000',...
      'Parent',hp,'Units','Normalized',... 
      'KeyPressFcn','rueck',...
      'Position',[.45 .83 .1 .05]);
elseif wahl == 2
    x0_e = uicontrol('Style','Slider','Parent',hp,...
      'Min',0,'Max',10000,'SliderStep',[0.001 0.01],...
      'Units','Normalized',...
      'Value',5000,...
      'Callback','v0anzeige',...
      'Position',[.6 .83 .3 .05]);
    x02 = uicontrol('Style','Edit','String','3000',...
      'Parent',hp,'Units','Normalized',... 
      'KeyPressFcn','rueck',...
      'Position',[.45 .83 .1 .05]);
end
phi_e = uicontrol('Style','Edit','String','45','Parent',hp,...
  'Units','Normalized',...
  'Position',[.6 .76 .3 .05]);           
m_e = uicontrol('Style','Edit','String','30','Parent',hp,...
  'Units','Normalized',...
  'Position',[.6 .69 .3 .05]);
rho_e= uicontrol('Style','Edit','String','1.293','Parent',hp,...
  'Units','Normalized',...
  'Position',[.6 .62 .3 .05]);      
quer_e = uicontrol('Style','Edit','String','0.1','Parent',hp,...
  'Units','Normalized',...
  'Position',[.6 .55 .3 .05]); 
temp_e = uicontrol('Style','Edit','String','20',...
  'Parent',hp,'Units','Normalized',...
  'Position',[.6 .48 .3 .05]); 
vw_e = uicontrol('Style','Edit','String','0',...
  'Parent',hp,'Units','Normalized',...
  'Position',[.6 .41 .3 .05]);
eta_e = uicontrol('Style','Edit','String','0','Parent',hp,...
  'Units','Normalized',...
  'Position',[.6 .34 .3 .05]);
cl_e = uicontrol('Style','Edit','String','0.2','Parent',hp,...
  'Units','Normalized',...
  'Position',[.6 .27 .3 .05]);
if wahl == 2
    error_e = uicontrol('Style','Edit','String','5','Parent',hp,...
      'Units','Normalized',...
      'Position',[.6 .20 .3 .05]);
end

checkb = uicontrol('Style','checkbox','String','  3D Animation/Auswertung',...
  'Parent',hp,'Units','Normalized',...
  'BackgroundColor',[.9 .9 .9],...
  'Position',[.6 .13 .35 .05]); 
aus = uicontrol('Style','Pushbutton','String','Programm beenden',...
    'Parent',hp,'Units','Normalized',...
  'Callback','close all',...
  'Position',[.55 .04 .3 .05]); 

%Ruft Funktion schuss1 auf und uebergibt ihr Eingabewerte         
if wahl == 1 
    an = uicontrol('Style','Pushbutton','String','Simulation starten','Parent',hp,...
      'Units','Normalized',...
      'Callback','schuss1(z0_e, v0_e, phi_e, m_e, rho_e, quer_e, temp_e, vw_e, eta_e, cl_e, checkb)',...
      'Position',[.15 .04 .3 .05]);
elseif wahl == 2
    an = uicontrol('Style','Pushbutton','String','Simulation starten','Parent',hp,...
      'Units','Normalized',...
      'Callback','schuss2(z0_e, x0_e, phi_e, m_e, rho_e, quer_e, temp_e, vw_e, eta_e, cl_e, error_e, checkb)',...
      'Position',[.15 .04 .3 .05]);  
end

% Positionierung des Textes
annotation1 = annotation(...
  h,'textbox',...
  'Position',[.5 .9 .1 .05],...
  'LineStyle','none',...
  'FitHeightToText','off',...
  'String',{'Starthoehe (m) (Max=10000)'});
if wahl == 1
    annotation2 = annotation(...
      h,'textbox',...
      'Position',[.5 .83 .1 .05],...
      'LineStyle','none',...
      'FitHeightToText','off',...
      'String',{'Startgeschw. (km/h) (Max=10000)'});
elseif wahl == 2
    annotation2 = annotation(...
      h,'textbox',...
      'Position',[.5 .83 .1 .05],...
      'LineStyle','none',...
      'FitHeightToText','off',...
      'String',{'Distanz (m) (Max=10000)'});
end
annotation3 = annotation(...
  h,'textbox',...
  'Position',[.5 .76 .1 .05],...
  'LineStyle','none',...
  'FitHeightToText','off',...
  'String',{'Startwinkel (grad) (Max=90)'});
annotation4 = annotation(...
  h,'textbox',...
  'Position',[.5 .69 .1 .05],...
  'LineStyle','none',...
  'FitHeightToText','off',...
  'String',{'Masse (kg) (Max=3000, Min=5)'});
annotation5 = annotation(...
  h,'textbox',...
  'Position',[.5 .62 .1 .05],...
  'LineStyle','none',...
  'FitHeightToText','off',...
  'String',{'Luftdichte (kg/dm^3) (Max=2)'});
annotation6 = annotation(...
  h,'textbox',...
  'Position',[.5 .55 .1 .05],...
  'LineStyle','none',...
  'FitHeightToText','off',...
  'String',{'Querschnittsflaeche (m^2) (Max=1)'});
annotation7 = annotation(...
  h,'textbox',...
  'Position',[.5 .48 .1 .05],...
  'LineStyle','none',...
  'FitHeightToText','off',...
  'String',{'Bodentemperatur (grad C) (Max=60)'});
annotation8 = annotation(...
  h,'textbox',...
  'Position',[.5 .41 .1 .05],...
  'LineStyle','none',...
  'FitHeightToText','off',...
  'String',{'Windgeschwindigkeit (km/h) (Max=38)'});
annotation9 = annotation(...
  h,'textbox',...
  'Position',[.5 .34 .1 .05],...
  'LineStyle','none',...
  'FitHeightToText','off',...
  'String',{'Windrichtung (grad) (1-360)'});
annotation10 = annotation(...
  h,'textbox',...
  'Position',[.5 .27 .1 .05],...
  'LineStyle','none',...
  'FitHeightToText','off',...
  'String',{'Widerstandskoeff cl (Max=0.3)'});
if wahl == 2
annotation10 = annotation(...
  h,'textbox',...
  'Position',[.5 .20 .1 .05],...
  'LineStyle','none',...
  'FitHeightToText','off',...
  'String',{'Tolerierbarer Fehler (Max=Distanz/5)'});
end

else  
    msgbox('Simulation abgebrochen','Warnung');
end
