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

% Last Modified by GUIDE v2.5 16-Jul-2003 15:28:42

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @laserGui_OpeningFcn, ...
                   'gui_OutputFcn',  @laserGui_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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 laserGui is made visible.
function laserGui_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 laserGui (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

if strcmp(get(hObject,'Visible'),'off')
    initialize_gui(hObject, handles);
end
% UIWAIT makes laserGui wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = laserGui_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;

% --------------------------------------------------------------------
function MenuFile_Callback(hObject, eventdata, handles)
% hObject    handle to MenuFile (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function MenuFileExit_Callback(hObject, eventdata, handles)
% hObject    handle to MenuFileExit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close;

% --------------------------------------------------------------------
function MenuFileOpen_Callback(hObject, eventdata, handles)
% hObject    handle to MenuFileOpen (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

[file, pathname] = uigetfile('*.txt');
if  isequal(file, 0)
    open(file);
end
set(handles.Caminho, 'string',strcat(pathname,file));
nomeficheiro = strcat(pathname,file);
tic;
leficheiro;
cor;
set(handles.MenuViewCor, 'Checked','ON');
set(handles.MenuViewCinzento, 'Checked','OFF');
time = toc;
set(handles.NVarrimentos, 'string',nlinhas);
set(handles.Resolucao, 'string',resolu);
set(handles.Tempo,'string',time);

set(handles.Caminho, 'Visible','ON');
set(handles.text2, 'Visible','ON');
set(handles.text3, 'Visible','ON');
set(handles.text6, 'Visible','ON');
set(handles.valorintervalo, 'Visible','ON');
set(handles.NVarrimentos, 'Visible','ON');
set(handles.Resolucao, 'Visible','ON');
set(handles.Tempo, 'Visible','ON');
set(handles.Intervalo, 'Visible','ON');

% --------------------------------------------------------------------
function MenuFilePrint_Callback(hObject, eventdata, handles)
% hObject    handle to MenuFilePrint (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
printdlg(handles.figure1);


% --------------------------------------------------------------------
function MenuFilePrintPreview_Callback(hObject, eventdata, handles)
% hObject    handle to MenuFilePrintPreview (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
printpreview(handles.figure1);

% --------------------------------------------------------------------

function MenuView_Callback(hObject, eventdata, handles)
% hObject    handle to MenuView (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function MenuViewRotate_Callback(hObject, eventdata, handles)
% hObject    handle to MenuViewRotate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% set(handles.MenuViewRotate, 'Value',1);
set(handles.MenuViewRotate, 'Checked','ON');
set(handles.MenuViewZoom, 'Checked','OFF');
view3d off;
view3d rot;

% --------------------------------------------------------------------
function MenuViewZoom_Callback(hObject, eventdata, handles)
% hObject    handle to MenuViewZoom (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.MenuViewRotate, 'Checked','OFF');
set(handles.MenuViewZoom, 'Checked','ON');
view3d off;
view3d zoom;

% --------------------------------------------------------------------
function MenuViewCor_Callback(hObject, eventdata, handles)
% hObject    handle to MenuViewCor (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data = getappdata(gcbf, 'Laser');
X = data.X;
Y = data.Y;
Z = data.Z;
nlinhas = data.nlinhas;
set(handles.MenuViewCor, 'Checked','ON');
set(handles.MenuViewCinzento, 'Checked','OFF');
cor;

% --------------------------------------------------------------------
function MenuViewCinzento_Callback(hObject, eventdata, handles)
% hObject    handle to MenuViewCinzento (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Funçao que inicia todos os valores do programa
data = getappdata(gcbf, 'Laser');
X = data.X;
Y = data.Y;
Z = data.Z;
nlinhas = data.nlinhas;
set(handles.MenuViewCor, 'Checked','OFF');
set(handles.MenuViewCinzento, 'Checked','ON');
cinzento;

% --------------------------------------------------------------------
function initialize_gui(fig_handle, handles)
clc;
data.X = [];
data.Y = [];
data.Z = [];
data.nlinhas = 0;

setappdata(fig_handle, 'Laser', data);

axis equal;
axis off;
imshow('background.jpg');
Title(' ');
set(handles.MenuViewCor, 'Checked','ON');
set(handles.MenuViewCinzento, 'Checked','OFF');