function buttonDown(src, evnt)
% buttonDown
%   button down callback

%   Project: IMPACT
%   Title of Code: buttonDown
%   Relevant additional documentation:
%   Developer: Carlos Gonzalez
%   External Dependencies: NA
%
%   Disclaimer
%   CAUTION: It is strongly recommended that changes to this code
%   should be avoided without first consulting with authors.

% check if it is withine axes range
hAx = gca;
pt = get(hAx, 'CurrentPoint');
ptX = pt(1,1);
ptY = pt(1,2);
xLim = get(hAx, 'XLim');
yLim = get(hAx, 'YLim');
if (ptX < xLim(1))||(ptX > xLim(2))||(ptY < yLim(1))||(ptY > yLim(2))
    return;
end

handles = guidata(src);
C = handles.C;
str = handles.Tb.selected;
switch str
    case 'arrow'
        changeText(handles.Tb.Arrow.hInfo, [ptX, ptY], handles);
    case 'pole'
        C2 = zpk([], [-ptX], 1);
        C = series(C, C2);
    case 'zero'
        C2 = zpk([-ptX], [], 1);
        C = series(C, C2);
    case 'comPole'
        C2 = zpk([], [-ptX+1e-4i, -ptX-1e-4i], 1);
        C = series(C, C2);
    case 'comZero'
        C2 = zpk([-ptX+1e-4i, -ptX-1e-4i], [], 1);
        C = series(C, C2);
    case 'eraser'
        C = removeZP(C, [ptX, ptY], handles);
    case 'zoomIn'
        ZoomIn = handles.Tb.ZoomIn;
        ZoomIn.downPoint = [ptX, ptY];
        ZoomIn.status = 'on'; % zoom in pressed
        for m = 1:4
            set(ZoomIn.hLine, 'parent', gca);
        end
        handles.Tb.ZoomIn = ZoomIn;
    case 'zoomOut'
        ZoomOut = handles.Tb.ZoomOut;
        ZoomOut.downPoint = [ptX, ptY];
        handles.Tb.ZoomOut = ZoomOut;
    case 'hand'        
        setptr(handles.hFig, 'closedhand');
        handles.Tb.Hand.status = 'on';
        Hand = handles.Tb.Hand;
        Hand.prevPoint = [ptX, ptY];
        Hand = handZPK(Hand, handles);
        handles.Tb.Hand = Hand;
end
handles.C = C;
handles.sys = parallel(series(C, handles.G),series(handles.C2,handles.G2)); % change this CG !!!
guidata(handles.hFig, handles);
switch str
    case 'arrow'
    case {'pole', 'zero', 'comPole', 'comZero', 'eraser'}
        updatePlot(handles);
    case 'zoomIn'
    case 'zoomOut'
    case 'hand' 
end

