function varargout = PointBCDialogue(varargin)
% PointBCDialogue is a dialogue to define boundary conditions on specific
% points in the mesh. The user enters the coordinates of the point, the
% local x and local y boundary conditions, and the angle (CCW
% positive) between the local x direction and the global x direction in the mesh.
% The position chosen does not have to correspond exactly to a nodal point
% position; the results will be transfered to the nearest nodal point.
% This dialogue should be used AFTER defining surface boundary conditions,
% as surface BCs will overwrite point BCs. 


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


% Choose default settings
handles.xc='n'; % traction tangential
handles.yc='n'; % traction normal

% Choose default command line output for BCDialogue
handles.pos = [0 0];
handles.code = 1;
handles.lxval = 0;
handles.lyval = 0;
handles.ang  = 0;


set(handles.figure1,'Name','Apply Point Boundary Condition');
set(handles.figure1,'Color',[.996 .496 .313]);

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = PointBCDialogue_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.pos;
% varargout{2} = handles.code;
% varargout{3} = handles.lxval;
% varargout{4} = handles.lyval;
% varargout{5} = handles.ang;

% outputstruct=struct('pos',handles.pos,'code',handles.code,...
%     'tang',handles.lxval,'norm',handles.lyval,'ang',handles.ang);
% varargout{1} = outputstruct;
varargout{1}=[handles.pos,handles.code,handles.lxval,handles.lyval,handles.ang];
delete(handles.figure1);

function xcorval_Callback(hObject, eventdata, handles)
% hObject    handle to xcorval (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 xcorval as text
%        str2double(get(hObject,'String')) returns contents of xcorval as a double
handles.pos(1)=str2num(get(hObject,'String'));
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function xcorval_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xcorval (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 ycorval_Callback(hObject, eventdata, handles)
% hObject    handle to ycorval (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 ycorval as text
%        str2double(get(hObject,'String')) returns contents of ycorval as a double
handles.pos(2)=str2num(get(hObject,'String'));
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function ycorval_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ycorval (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 on selection change in xlocbctype.
function xlocbctype_Callback(hObject, eventdata, handles)
% hObject    handle to xlocbctype (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns xlocbctype contents as cell array
%        contents{get(hObject,'Value')} returns selected item from xlocbctype
val = get(hObject,'Value');

% (code==1)   %normal: traction; tangential: traction
% (code==2)   %normal: displacement; tangential: traction
% (code==3)   %normal: traction; tangential: displacement
% (code==4)   %normal: displacement; tangential: displacement
switch val
    case 1 % natural
        handles.xc='n';
        switch handles.yc
            case 'e'
                handles.code=2;
            case 'n'
                handles.code=1;
        end
        set(handles.xlocbcunits,'String','Force');
        
    case 2 % essential
        handles.xc='e';
        switch handles.yc
            case 'e'
                handles.code=4;
            case 'n'
                handles.code=3;
        end
        set(handles.xlocbcunits,'String','Length');
        
end
guidata(hObject,handles);

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

% Hint: popupmenu 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 xlocbcval_Callback(hObject, eventdata, handles)
% hObject    handle to xlocbcval (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 xlocbcval as text
%        str2double(get(hObject,'String')) returns contents of xlocbcval as a double
handles.lxval=str2num(get(hObject,'String'));
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function xlocbcval_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xlocbcval (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 on selection change in ylocbctype.
function ylocbctype_Callback(hObject, eventdata, handles)
% hObject    handle to ylocbctype (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns ylocbctype contents as cell array
%        contents{get(hObject,'Value')} returns selected item from ylocbctype
val = get(hObject,'Value');

switch val       
    case 1 % natural
        handles.yc='n';
        switch handles.xc
            case 'e'
                handles.code=3;
            case 'n'
                handles.code=1;
        end
        set(handles.ylocbcunits,'String','Force');
        
    case 2 % essential
        handles.yc='e';
        switch handles.xc
            case 'e'
                handles.code=4;
            case 'n'
                handles.code=2;
        end
        set(handles.ylocbcunits,'String','Length');

end
guidata(hObject,handles);


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

% Hint: popupmenu 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 ylocbcval_Callback(hObject, eventdata, handles)
% hObject    handle to ylocbcval (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 ylocbcval as text
%        str2double(get(hObject,'String')) returns contents of ylocbcval as a double
handles.lyval=str2num(get(hObject,'String'));
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function ylocbcval_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ylocbcval (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 xyntangle_Callback(hObject, eventdata, handles)
% hObject    handle to xyntangle (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 xyntangle as text
%        str2double(get(hObject,'String')) returns contents of xyntangle as a double
handles.ang=str2num(get(hObject,'String'));
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function xyntangle_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xyntangle (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 on button press in donebutton.
function donebutton_Callback(hObject, eventdata, handles)
% hObject    handle to donebutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

uiresume(handles.figure1);
