⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guiprint.m

📁 改进等高线拟合代码
💻 M
字号:
function guiprint(action)

% GUIPRINT is the print module of the GUI

% All the software included in this package is presented as is.
% It may be distributed freely. The author can, however, not be
% held responsible for any problems whatever.
% 
% Designed by Johan Baeten.
% Last updated: 22-03-2000
% Johan.baeten@mech.kuleuven.ac.be


global FITHANDLES
global PRINTHANDLES
global UICTRHANDLES
global MAINFIG

setting('menubarenableoff');
set(FITHANDLES(1,:),'enable','off');
v_state = get(FITHANDLES(1,1),'visible');


if strcmp(action,'start'),
  [existFlag,fignr]=figflag('GUI Print Window',1);

  if existFlag,
    if strcmp(v_state,'on'),
      set(PRINTHANDLES(3),'value',[1]);
    else
      set(PRINTHANDLES(3),'value',[0]);
    end
    set(fignr,'visible','on');
  else  
    % create print window now %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%
    position=get(0,'DefaultFigurePosition');
    position(3:4)=[440 180];
    fignr=figure( ...
         'Name','GUI Print Window', ...
         'NumberTitle','off', ...
         'Visible','off', ...
         'MenuBar','none', ...
 	 	   'Position',position, ...
   		'Color',[0.8 0.8 0.8], ...
			'Resize','off');

   uicontrol(fignr,'style','frame',...
                   'backgroundcolor',[0.8 0.8 0.8],...
                   'position',[5 55 430 120]);

   uicontrol(fignr,'string','Options:',...
                   'horizontalalignment','left',...
                   'backgroundcolor',[0.8 0.8 0.8],...
                   'style','text',...
                   'position',[10 152 120 20]);

   PRINTHANDLES(1)= uicontrol(fignr,'style','checkbox',...
                   'horizontalalignment','left',...
                   'string',' - not used - ',...
                   'position',[10 65 140 25],...
                   'value',[0]);
   PRINTHANDLES(2)= uicontrol(fignr,'string',' - not used - ',...
                   'position',[10 95 140 25],...
                   'style','checkbox',...
                   'horizontalalignment','left',...
                   'value',[0]);
   PRINTHANDLES(3)= uicontrol(fignr,'string','Add List of Points',...
                   'position',[10 125 140 25],...
                   'horizontalalignment','left',...
                   'style','checkbox',...
                   'value',[0]);
   if strcmp(v_state,'on'),
     set(PRINTHANDLES(3),'value',[1]);
   end
   uicontrol(fignr,'string','Page Layout:',...
                   'backgroundcolor',[0.8 0.8 0.8],...
                   'style','text',...
                   'horizontalalignment','right',...
                   'position',[170 125 120 25]);
   uicontrol(fignr,'string','Printer:',...
                   'backgroundcolor',[0.8 0.8 0.8],...
                    'style','text',...
                   'horizontalalignment','right',...
                    'position',[170 65 120 25]);

   PRINTHANDLES(4)= uicontrol(fignr,'style','popupmenu', ...
       'position',[300 125 120 25],...
       'HorizontalAlignment','left',...
       'string',['Portrait   ';...
                 'Landscape  ';
                 'Portr-Tall ';]);

   PRINTHANDLES(5)= uicontrol(fignr,'style','popupmenu', ...
       'position',[300 65 120 25],...
       'HorizontalAlignment','left',...
       'string',['LaserHP          ';...
                 '..''my printer''.. ';...
                 'Print to File ...' ]);


   uicontrol(fignr,'string','Print',...
                   'style','pushbutton',...
                   'position',[100 10 70 30],...
                   'callback','guiprint(''continu'');');
   uicontrol(fignr,'string','Cancel',...
                   'style','pushbutton',...
                   'position',[250 10 70 30],...
                   'callback','guiprint(''cancel'');');
   set(fignr,'visible','on');
   end
   %%%%%%%%%%%%%%%%%%%%%%%%%%%

elseif strcmp(action,'continu'),

  set(gcf,'visible','off');
  if get(PRINTHANDLES(5),'value')==3,
    seterror(' Give Filename to print to.')    
    [filename, pathname]= uiputfile('*.ps','Print to file');
    if filename == 0  ,
      guiprint('cancel');
      seterror(' ... Print to File Canceled');
      return;
    end
    filename = lower(filename);
    pathname = lower(pathname);
    lf = length(filename);
    ok = 0;
    if lf>3,
      if strcmp(filename(lf-2:lf),'.ps'),
         if lf < 11,
            ok = 1;
         else
            guiprint('cancel');
            seterror(' ... Print to File Canceled: File to long.');
            return;
         end
      end
    end 
    if ~ok,  
      for i =1:lf 
         if filename(i) == '.',
            guiprint('cancel');
            seterror(' ... Print to File Canceled: Incorrect filename.');
            return;
         end
      end
      if lf<9,
         filename = [filename,'.ps'];
      else
         guiprint('cancel');  
         seterror(' ... Print to File Canceled: Filename to long.');
         return;
      end
    end
  end

  figure(MAINFIG);
  seterror(' Wait while converting image to print ... ');

  set(FITHANDLES,'visible','off');
  set(UICTRHANDLES(1),'visible','off');
  mainaxes = gca;
  set(gcf,'paperunits','centimeters','papertype','a4letter');
 
  if get(PRINTHANDLES(3),'value')==1,
    nrofpoints = get(FITHANDLES(1,12),'value'); 
    if nrofpoints > 0,
       for i = 1:nrofpoints,
          xc(i) = get(FITHANDLES(3,i),'value');
          yc(i) = get(FITHANDLES(4,i),'value');
       end
    end
    
    lbh = 18;
    lbw = 25;
    mapos = get(mainaxes,'position');

    ha = axes('units','normalized',...
              'position',[mapos(3)+0.1 mapos(2) (0.9-mapos(3)) mapos(4)-mapos(2)]);    
    set(ha,'box','on','xgrid','off','ygrid','off');
    set(ha,'xlim',[0 200],'ylim',[0 270],...
           'xtick',[],'ytick',[],...
           'xticklabels',[''],'yticklabels',['']);
 
    text(10,232,'#');text(45,232,'x value');text(115,232,'y value');
    for i  = 1:nrofpoints,
      text(10, 225-i*lbh,num2str(i));
      text(45, 225-i*lbh,num2str(xc(i)));
      text(115, 225-i*lbh,num2str(yc(i)));
    end
    title('List of Points');
  end


  if get(PRINTHANDLES(4),'value')==1,
    set(gcf,'paperorientation','portrait',...
            'paperposition',[1 7 19 685*19/900]);
  elseif get(PRINTHANDLES(4),'value')==2,
    orient landscape;
    set(gcf,'paperposition',[3 1 25 685*25/900]);
  else
    set(gcf,'paperorientation','portrait');
    ps=get(gcf,'papersize');
    pp = [1 1 ps-2];
    set(gcf,'paperposition',pp);
  end
 

  if get(PRINTHANDLES(5),'value')==1,
    seterror([' Printing to Laserjet 6L.']);
    print -dps 'prt.ps'
    !lp -dlaserhp prt.ps;
    delete prt.ps;
  elseif get(PRINTHANDLES(5),'value')==2,
    %%% Build in your own printer %%%
  else
    seterror([' Printing to ''' filename '''.']);
    tf = [pathname filename];
    eval(['print -dps ' tf]);
  end

  seterror(' Printed out. Resetting ... ');

  if get(PRINTHANDLES(3),'value')==1,
    delete(ha);
  end
  set(FITHANDLES,'visible',v_state);
  set(UICTRHANDLES(1),'visible','on');
  setting('menubarenableon');
  set(FITHANDLES(1,:),'enable','on');
  
  seterror(' Printed out. Resetting ... done.');
  %%% Delete next 'if' when you have build in your own printer %%%
  if get(PRINTHANDLES(5),'value')==2,  
	  seterror([' Not printing -- Build in your own printer ...']);
  end  


elseif strcmp(action,'cancel')
  setting('menubarenableon');
  set(FITHANDLES(1,:),'enable','on');
  [existFlag,fignr]=figflag('GUI Print Window',1);
  if existFlag,
    set(fignr,'visible','off');
  end
  seterror(' Printing Cancelled.');  
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -