function varargout = DesignCircumferential(varargin)
% RADIOUS_OF_BASE_PLATFORM MATLAB code for radious_of_base_platform.fig
%      RADIOUS_OF_BASE_PLATFORM, by itself, creates a new RADIOUS_OF_BASE_PLATFORM or raises the existing
%      singleton*.
%
%      H = RADIOUS_OF_BASE_PLATFORM returns the handle to a new RADIOUS_OF_BASE_PLATFORM or the handle to
%      the existing singleton*.
%
%      RADIOUS_OF_BASE_PLATFORM('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in RADIOUS_OF_BASE_PLATFORM.M with the given input arguments.
%
%      RADIOUS_OF_BASE_PLATFORM('Property','Value',...) creates a new RADIOUS_OF_BASE_PLATFORM or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before DesignCircumferential_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to DesignCircumferential_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 radious_of_base_platform

% Last Modified by GUIDE v2.5 06-May-2012 19:06:37

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @DesignCircumferential_OpeningFcn, ...
                   'gui_OutputFcn',  @DesignCircumferential_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 radious_of_base_platform is made visible.
function DesignCircumferential_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 radious_of_base_platform (see VARARGIN)

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


setappdata(0, 'Platform', 'Base');

Rb = 100;
circle([0,0],Rb,1000);
line('Xdata' , [ 0  Rb ] , 'YData', [ 0  0 ] ) ;

text(0, Rb/10 , 'Sabit Platform Yarıçapı' ) ;

ylabel('Y');xlabel('X');
% Update handles structure
guidata(hObject, handles);


% UIWAIT makes radious_of_base_platform wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = DesignCircumferential_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
varargout{1} = handles.output;

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

ylabel('Y');xlabel('X');

Rb =  str2double(  get( handles.edit_Rb , 'String')  );

if (isempty(Rb))
     set(handles.edit_Rb,'String','0');
end

if ( Rb <= 0 ) 
    errordlg('Radious must be greater than 0...Please correct the Radius' );
    return;
else 
    set(handles.uipanel_AngleSets, 'visible','on');
    set(handles.edit_Q1,'visible','on');
    set(handles.edit_Q2,'visible','on');
    set(handles.edit_Q3,'visible','on');
    set(handles.edit_Q4,'visible','on');
    set(handles.edit_Q5,'visible','on');
    set(handles.edit_Q6,'visible','on');
    set(handles.text_Q1,'visible','on');
    set(handles.text_Q2,'visible','on');
    set(handles.text_Q3,'visible','on');
    set(handles.text_Q4,'visible','on');
    set(handles.text_Q5,'visible','on');
    set(handles.text_Q6,'visible','on');
    set(handles.pb_OK2,'visible','on');

    set(handles.axes1, 'visible', 'on');
    circle([0,0],Rb,1000);  
end

Platform = getappdata(0, 'Platform');
if ( strcmp ( Platform , 'Moving') )
    setappdata(0, 'Rm' , Rb);
    
    Rm = getappdata(0, 'Rm');
    circle([0,0],Rm,1000);
    line('Xdata' , [ 0  Rm ] , 'YData', [ 0  0 ] ) ;
    text(0, Rm/10 , 'Hareketli Platform Yarıçapı' ) ;
else
    setappdata(0, 'Rb' , Rb);
    
    Rb = getappdata(0, 'Rb');
    circle([0,0],Rb,1000);
    line('Xdata' , [ 0  Rb ] , 'YData', [ 0  0 ] ) ;
    text(0, Rb/10 , 'Sabit Platform Yarıçapı' ) ;
end

ylabel('Y');xlabel('X');

guidata(hObject, handles);



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

cla;
ylabel('Y');xlabel('X');
Q1 = str2double ( get(handles.edit_Q1, 'String') );
Q2 = str2double ( get(handles.edit_Q2, 'String') );
Q3 = str2double ( get(handles.edit_Q3, 'String') );
Q4 = str2double ( get(handles.edit_Q4, 'String') );
Q5 = str2double ( get(handles.edit_Q5, 'String') );
Q6 = str2double ( get(handles.edit_Q6, 'String') );

Q = deg2rad( [ Q1 ; Q2 ; Q3 ; Q4  ; Q5 ; Q6 ] );

Platform = getappdata(0, 'Platform');
if ( strcmp ( Platform , 'Moving') )
    Rm = getappdata(0, 'Rm');
    ax = Rm * cos(Q);ax_text_pos = ax-(Rm/10 * ( cos(Q)./abs( cos(Q) ) ) ); 
    ay = Rm * sin(Q);ay_text_pos = ay-(Rm/12 * ( sin(Q)./abs( sin(Q) ) ) ); 
    az = Q * 0;
    a = [ ax ay az ];
    circle([0,0],Rm,1000);
    text(ax_text_pos ,ay_text_pos,['A1' ; 'A2' ; 'A3' ; 'A4' ; 'A5' ; 'A6' ]  );
    line('XData',[ ax ; ax(1)],'YData',[ ay ; ay(1)],'ZData',[ az ; 0 ] );
    
    setappdata( 0 , 'Moving_connection_points'  , a );

else
    Rb = getappdata(0, 'Rb');
    bx = Rb * cos(Q); bx_text_pos = bx-(Rb/10 * ( cos(Q)./abs( cos(Q) ) ) ); 
    by = Rb * sin(Q); by_text_pos = by-(Rb/12 * ( sin(Q)./abs( sin(Q) ) ) ); 
    bz = Q * 0;
    
    b = [ bx by bz ];
    circle([0,0],Rb,1000);
    text(bx_text_pos ,by_text_pos,['B1' ; 'B2' ; 'B3' ; 'B4' ; 'B5' ; 'B6' ]  );    
    line('XData',[ bx ; bx(1)],'YData',[ by ; by(1)],'ZData',[ bz ; 0 ] );    
    setappdata( 0 , 'Base_connection_points' , b );
end

set(handles.pb_Confirm, 'visible', 'on');
ylabel('Y');xlabel('X');

% saveas(gcf,'functionsaveas.fig');
% saveas(handles.axes1,'functionsaveas.eps','eps2c');
guidata(hObject, handles);



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

cla;
ylabel('Y');xlabel('X');

if ( strcmp( get( hObject, 'String' ) , 'Analysis this Platform') )
    close;
    DesignGSP;
    return;
end


Platform = getappdata(0, 'Platform');

if ( strcmp ( Platform , 'Base' )  ) 
    set(handles.pb_Confirm, 'String' , 'Onayla');
    set(handles.text_Rb, 'String' , 'Hareketli Platformdaki Çemberin Yarıçap Değeri (HPÇY)');
    set(handles.edit_Q1,'visible','off');
    set(handles.edit_Q2,'visible','off');
    set(handles.edit_Q3,'visible','off');
    set(handles.edit_Q4,'visible','off');
    set(handles.edit_Q5,'visible','off');
    set(handles.edit_Q6,'visible','off');
    set(handles.text_Q1,'visible','off');
    set(handles.text_Q2,'visible','off');
    set(handles.text_Q3,'visible','off');
    set(handles.text_Q4,'visible','off');
    set(handles.text_Q5,'visible','off');
    set(handles.text_Q6,'visible','off');
    set(handles.pb_OK2,'visible','off');
    set(handles.edit_Rb,'String','0');
    set(handles.axes1,'visible','off');
    setappdata(0, 'Platform', 'Moving');
    set(handles.uipanel_AngleSets, 'visible', 'off' );
    %%set(handles.axes1,'visible','off');
    cla;
    ylabel('Y');xlabel('X');
    set(handles.axes1,'visible','on');
    Rb = getappdata(0, 'Rb');
    circle([0,0],Rb,1000);
    line('Xdata' , [ 0  Rb ] , 'YData', [ 0  0 ] ) ;
    text(Rb/4, Rb/10 , 'Radius of Mobile' ) ;
    
    setappdata(0,'Base_radius', Rb );
    
    set(handles.pb_Confirm, 'visible', 'off');
    
else %%already moving platform 
    set(handles.edit_Q1,'visible','off');
    set(handles.edit_Q2,'visible','off');
    set(handles.edit_Q3,'visible','off');
    set(handles.edit_Q4,'visible','off');
    set(handles.edit_Q5,'visible','off');
    set(handles.edit_Q6,'visible','off');
    set(handles.text_Q1,'visible','off');
    set(handles.text_Q2,'visible','off');
    set(handles.text_Q3,'visible','off');
    set(handles.text_Q4,'visible','off');
    set(handles.text_Q5,'visible','off');
    set(handles.text_Q6,'visible','off');
    set(handles.pb_OK2,'visible','off');
    set(handles.edit_Rb,'String','0');
    cla;
    ylabel('Y');xlabel('X');
    set(handles.axes1, 'visible','off');
    Rm = getappdata(0, 'Rm');
    setappdata(0,'Moving_radius', Rm );
    
   close;
    DesignGSP;
    return;
    
%     set(handles.text_Rb,'visible','off');
%     set(handles.frame_Rb,'visible','off');
%     set(handles.edit_Rb,'visible','off');
%     
%     set(handles.pb_Confirm, 'String' , 'Analysis this Platform',...
%         'Position',[ 37.8 15.231 30.2 2.615 ]  );
    
end


    


function edit_Q1_Callback(hObject, eventdata, handles)
% hObject    handle to edit_Q1 (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_Q1 as text
%        str2double(get(hObject,'String')) returns contents of edit_Q1 as a double


% --- Executes during object creation, after setting all properties.
function edit_Q1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_Q1 (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_Q2_Callback(hObject, eventdata, handles)
% hObject    handle to edit_Q2 (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_Q2 as text
%        str2double(get(hObject,'String')) returns contents of edit_Q2 as a double


% --- Executes during object creation, after setting all properties.
function edit_Q2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_Q2 (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_Q3_Callback(hObject, eventdata, handles)
% hObject    handle to edit_Q3 (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_Q3 as text
%        str2double(get(hObject,'String')) returns contents of edit_Q3 as a double


% --- Executes during object creation, after setting all properties.
function edit_Q3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_Q3 (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_Q4_Callback(hObject, eventdata, handles)
% hObject    handle to edit_Q4 (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_Q4 as text
%        str2double(get(hObject,'String')) returns contents of edit_Q4 as a double


% --- Executes during object creation, after setting all properties.
function edit_Q4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_Q4 (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_Q5_Callback(hObject, eventdata, handles)
% hObject    handle to edit_Q5 (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_Q5 as text
%        str2double(get(hObject,'String')) returns contents of edit_Q5 as a double


% --- Executes during object creation, after setting all properties.
function edit_Q5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_Q5 (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_Q6_Callback(hObject, eventdata, handles)
% hObject    handle to edit_Q6 (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_Q6 as text
%        str2double(get(hObject,'String')) returns contents of edit_Q6 as a double


% --- Executes during object creation, after setting all properties.
function edit_Q6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_Q6 (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_Rb_Callback(hObject, eventdata, handles)
% hObject    handle to edit_Rb (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_Rb as text
%        str2double(get(hObject,'String')) returns contents of edit_Rb as a double


% --- Executes during object creation, after setting all properties.
function edit_Rb_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_Rb (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 when figure1 is resized.
function figure1_ResizeFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
