% --- Executes on button press in rect_rem.
function rect_rem_Callback(hObject, eventdata, handles)
global shape invisible count incount
number=0;
[disc,page]=size(shape);
[nx,ny]=ginput(1);
x=round(nx);
y=round(ny);

for i=1:page
    temp=shape(i).elem;
    tempid=shape(i).id;
    if tempid==0
        continue        
    end
    [mtemp,ntemp]=size(temp);
    for j=1:mtemp
        if (temp(j,1)==x)&&(temp(j,2)==y)
            x1=min(temp(:,1));
            x2=max(temp(:,1));
            y1=min(temp(:,2));
            y2=max(temp(:,2));
            w=x2-x1;
            h=y2-y1;
            handle=findobj(gca,'type','rectangle','Position',[x1,y1,w,h]);
            delete (handle)
            number=i;
            break
        end
    end
    if number>0
        break
    end
end

if number>0
    connect=shape(number).seq;
    shape(number)=[];  
    count=count-1;
    [disc,page]=size(invisible);
    for i=1:page
        if invisible(i).shape==connect
            invisible(i)=[];
            incount=incount-1;
        end
    end
else
    msgbox('No rectangle at selected point');
end

