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

📄 scgui.m

📁 computation of conformal maps to polygonally bounded regions
💻 M
📖 第 1 页 / 共 3 页
字号:

nvar = 1;
if nargin==5
  nvar = 2;
end

fig2 = figure('vis','off','number','off','menu','none','name',name);
pos = get(fig2,'pos');
height = 150-34*(nvar==1);
set(fig2,'pos',[pos(1),pos(2),400,height])
uicontrol(fig2,'style','frame','pos',[0,0,400,height]);
for j=1:nvar
  height = 64+34*(nvar-j);
  eval(sprintf('xlab=xlab%d;x=x%d(:);',j,j))
  uicontrol(fig2,'style','text','pos',[10,height,80,24],...
      'string',xlab,'hor','r');
  xstr = ['[ ',sprintf(' %.4g%+.4gi ',[real(x)';imag(x)']),']'];
  ui(j) = uicontrol(fig2,'style','edit','pos',[100,height,290,24],...
      'string',xstr,'tag','scgeditbox');
end
uicontrol(fig2,'style','push','pos',[40,20,60,24],...
    'string','Clear','call',...
    'set(findobj(gcf,''tag'',''scgeditbox''),''string'',''[ ]'')')
uicontrol(fig2,'style','push','pos',[170,20,60,24],...
    'string','Done','call','global SC_FLAG,SC_FLAG=1;')
uicontrol(fig2,'style','push','pos',[300,20,60,24],...
    'string','Cancel','call','global SC_FLAG,SC_FLAG=-1;')
set(fig2,'vis','on')
global SC_FLAG
SC_FLAG = 0;
while ~SC_FLAG
  drawnow
end
flag = SC_FLAG;
clear global SC_FLAG

if flag > 0
  for j=1:nvar
    x = eval(get(ui(j),'string'),'[]');
    eval(sprintf('x%d=x;',j))
  end
end

delete(fig2)

%=======================================================
function lapsolver(varargin)

data = guidata(gcbf);
if ~isa(data.polygon,'polygon')
  errordlg('You must first define a polygon.','No polygon');
else
  p = data.polygon;
  ls = openfig('lsprogress');
  h = guihandles(ls);
  set(h.BC,'background',[1 1 0])
  bdata = lapsolvegui(p);
  set(h.BC,'background',[0 1 0])
  set(h.SC,'background',[1 1 0])
  drawnow
  phi = lapsolve(p,bdata);
  set(h.SC,'background',[0 1 0])
  set(h.Eval,'background',[1 1 0])
  drawnow
  [tri,x,y] = triangulate(p);
  u = phi(x+i*y);
  set(h.Eval,'background',[0 1 0])
  drawnow
  
  figure;
  trisurf(tri,x,y,u);
  title('Solution of Laplace''s equation')
  close(ls)
end


%=======================================================
function make_widgets(fig)

% Create uicontrol frames
set(fig,'defaultuicontrolunits','char')
% We aren't going to set positions, because that is done in resize_widgets
uicontrol('style','frame','tag','SettingsFrame');
uicontrol('style','frame','tag','ActionsFrame');


% SETTINGS
% This checkbox really seems unnecessary now.
%%setting(1) = uicontrol('Parent',fig, ...
%%    'String','Monitor progress', ...
%%    'Style','checkbox', ...
%%    'Tag','TraceBox', ...
%%    'Value',1);
setting(1) = uicontrol('Parent',fig, ...
    'String','Tolerance desired', ...
    'FontWeight','bold', ...
    'Horizontal','center',...
    'tag','TolText',...
    'Style','text');
setting(2) = uicontrol('Parent',fig, ...
    'String','1e-5', ...
    'Background',.8*[1 1 1],...
    'Style','edit', ...
    'Tag','TolEdit');
setting(3) = uicontrol('Parent',fig, ...
    'String','Canonical domain', ...
    'HorizontalAlignment','left', ...
    'Min',1, ...
    'FontWeight','bold', ...
    'horiz','cen',...
    'Style','text', ...
    'tag','DomainText',...
    'Value',1);
mapname = {'disk','half-plane','strip','rectangle','disk exterior', ...
      'disk (CR)','rectified (CR)'};
setting(4) = uicontrol('Parent',fig, ...
    'Callback',@setdomain, ...
    'Max',7, ...
    'Min',1, ...
    'String',mapname, ...
    'Style','popupmenu', ...
    'Tag','DomainPopup', ...
    'Value',1);
setting(5) = uicontrol('Parent',fig, ...
    'String','View', ...
    'HorizontalAlignment','left', ...
    'Min',1, ...
    'FontWeight','bold', ...
    'Style','text', ...
    'horiz','cen',...
    'tag','ViewText',...
    'Value',1);
setting(6) = uicontrol('Parent',fig, ...
    'Callback',@setview, ...
    'Max',3, ...
    'Min',1, ...
    'String',{'Physical domain' 'Canonical domain' 'Both domains'}, ...
    'Style','popupmenu', ...
    'Tag','ViewPopup', ...
    'Value',1);
setting(7) = uicontrol('Parent',fig, ...
    'HorizontalAlignment','right', ...
    'String','theta =', ...
    'Style','text', ...
    'horiz','left',...
    'Tag','YTText');
setting(8) = uicontrol('Parent',fig, ...
    'String','defaults', ...
    'Background',.8*[1 1 1],...
    'Style','edit', ...
    'horiz','left',...
    'Tag','YTEdit');
setting(9) = uicontrol('Parent',fig, ...
    'HorizontalAlignment','right', ...
    'String','r =', ...
    'Style','text', ...
    'horiz','left',...
    'Tag','XRText');
setting(10) = uicontrol('Parent',fig, ...
    'String','defaults', ...
    'Style','edit', ...
    'horiz','left',...
    'Background',.8*[1 1 1],...
    'Tag','XREdit');
setting(11) = uicontrol('Parent',fig, ...
    'HorizontalAlignment','left', ...
    'FontWeight','bold', ...
    'String','Mesh lines', ...
    'Style','text',...
    'horiz','cen',...
    'tag','MeshText');
 
% ACTIONS
% When loading GUI icons, we will use the system's default BG color.
bg = get(0,'defaultuicontrolbackground');
names = {'pencil','pencileraser','solve','bullseye','plot','magglass',...
      'prompt','quit'};
for j=1:length(names)
  icons{j} = imread(['private/' names{j} '.png'],'back',bg);
end
action(1) = uicontrol('parent',fig,'style','push',...
    'cdata',icons{1},...
    'tooltip','Draw new polygon',...
    'unit','pix','pos',[0 0 42 42],...
    'Callback',@draw,...
    'tag','DrawButton');
% Determine how large the icons are in character units on this computer. 
set(action(1),'unit','char')
icon_size = get(action(1),'pos');
icon_size = icon_size(3:4);
action(2) = uicontrol('parent',fig,'style','push',...
    'cdata',icons{2},...
    'tooltip','Modify current polygon',...
    'Callback',@domodify,...
    'tag','ModifyButton');
action(3) = uicontrol('parent',fig,'style','push',...
    'cdata',icons{3},...
    'tooltip','Solve for parameters',...
    'Callback',@solve,...
    'tag','SolveButton');
action(4) = uicontrol('parent',fig,'style','push',...
    'cdata',icons{4},...
    'tooltip','Set conformal center',...
    'Callback',@recenter,...
    'tag','CenterButton');
action(5) = uicontrol('parent',fig,'style','push',...
    'cdata',icons{5},...
    'tooltip','Plot a mesh',...
    'Callback',@meshplot,...
    'tag','PlotButton');
action(6) = uicontrol('parent',fig,'style','push',...
    'cdata',icons{6},...
    'tooltip','Inspect map details',...
    'Callback',@scdisplay,...
    'tag','ShowButton');
action(7) = uicontrol('parent',fig,'style','push',...
    'cdata',icons{7},...
    'tooltip','Import/export to command line',...
    'Callback',@importexport,...
    'tag','ImportExportButton');
action(8) = uicontrol('parent',fig,'style','push',...
    'cdata',icons{8},...
    'tooltip','Quit SC GUI',...
    'Callback',@scquit,...
    'tag','QuitButton');

% CONTEXT MENUS
cm = uicontextmenu('tag','PolygonContextMenu');
uimenu(cm,'label','Modify...','call',@domodify)
uimenu(cm,'label','Inspect vertices...','call',@edit)
uimenu(cm,'label','Delete...','call',@menudeletepoly)
uimenu(cm,'label','Cancel action','separator','on')

cm = uicontextmenu('tag','PointContextMenu');
uimenu(cm,'label','Inspect...','call',@editpts)
uimenu(cm,'label','Delete...','call',@deletepoints)
uimenu(cm,'label','Cancel action','separator','on')

% FIGURE MENUS
filemenu = uimenu(fig,'label','File');
uimenu(filemenu,'label','Save map data...','call',@savedata,...
       'tag','FileSaveMenu');
uimenu(filemenu,'label','Load map data...','call',@loaddata,...
       'tag','FileLoadMenu');
uimenu(filemenu,'label','Import/export to workspace...',...
       'call',@importexport,'tag','FileImportExportMenu');
uimenu(filemenu,'label','Make a printable copy','call',@printablecopy);
uimenu(filemenu,'label','Quit SC mapping...','call',@scquit);
polymenu = uimenu(fig,'label','Polygon');
uimenu(polymenu,'label','New...','call',@draw,'tag','PolyNewMenu');
uimenu(polymenu,'label','Modify...','call',@domodify,'tag','PolyModifyMenu');
uimenu(polymenu,'label','Edit numerically...','call',@edit,...
       'tag','PolyEditMenu');
mapmenu = uimenu(fig,'label','Map');
uimenu(mapmenu,'label','Solve for parameters','call',@solve,...
       'tag','MapSolveMenu');
uimenu(mapmenu,'label','Reset conformal center...','call',@recenter,...
       'tag','MapCenterMenu');
uimenu(mapmenu,'label','Plot a mesh','call',@meshplot,...
       'tag','MapPlotMenu');
uimenu(mapmenu,'label','Inspect details','call',@scdisplay,...
       'tag','MapShowMenu');
toolsmenu = uimenu(fig,'label','Tools');
tutmenu = uimenu(toolsmenu,'label','Tutorials','separator','on');
uimenu(tutmenu,'label','Basic','call','scdtutor');
uimenu(tutmenu,'label','Infinite vertices','call','scdinf');
uimenu(tutmenu,'label','Elongated polygons','call','scdlong');
uimenu(tutmenu,'label','Faber polynomials','call','scdfaber');
uimenu(toolsmenu,'label','Laplace solver...','separator','on',...
       'call',@lapsolver,'tag','ToolsLaplaceMenu');

data = guihandles(fig);

% Store all needed data
data.polygon = [];
data.map = [];
data.iscurrent = 0;
data.mapclass = { 'diskmap','hplmap','stripmap','rectmap','extermap', ...
    'crdiskmap','crrectmap' };
data.phypoints = [];
data.canpoints = [];
data.PhysicalPoints = [];
data.CanonicalPoints = [];
data.iconsize = icon_size;
data.settings = setting;
data.actions = action;
data.SCfig = fig;

% Find objects whose validity depends on polygon or map existence.
polydep = {'ModifyButton','SolveButton','FileSaveMenu','PolyModifyMenu',...
           'PolyEditMenu','MapSolveMenu','ToolsLaplaceMenu'};
mapdep = {'CenterButton','PlotButton','ShowButton','MapCenterMenu',...
          'MapPlotMenu','MapShowMenu'};
for k = 1:length(polydep)
  PD(k) = findobj(fig,'tag',polydep{k});
end
for k = 1:length(mapdep)
  MD(k) = findobj(fig,'tag',mapdep{k});
end
data.PolygonEnabled = PD(:);
data.MapEnabled = MD(:);
set(PD,'enable','off'), set(MD,'enable','off')

guidata(fig,data)

%=======================================================
function resize_widgets(fig)
% This function is called whenever the figure is resized.

figpos = get(fig,'pos');
data = guidata(fig);

% Minimum sizes
figpos(3) = max(figpos(3),95);
figpos(4) = max(figpos(4),36);

set(fig,'pos',figpos)
%movegui(fig)
h = figpos(4) - data.iconsize(2) - 0.5;
set(data.SettingsFrame,'pos',[figpos(3)-23 0 23 h])
set(data.ActionsFrame,'pos',[0 h figpos(3) data.iconsize(2)+0.5]);

% Leave a cushion around the axes
h = 10 + data.iconsize(2);
data.axeswindow = [9 5 figpos(3)-41 figpos(4)-h];

% SETTINGS
h = figpos(4) - 28 - data.iconsize(2);
w = figpos(3) - 22;
set(data.TolText, 'pos',[w+1 h+23.5 20 1.25])
set(data.TolEdit, 'pos',[w+6.5 h+21.5 9 1.5])
%set(data.TraceBox, 'pos',[w+1 h+18.75 20 1.75])
set(data.DomainText, 'pos',[w+1 h+15.5 20 1.25])
set(data.DomainPopup, 'pos',[w+1 h+13.25 20 1.75])
set(data.ViewText, 'pos',[w+1 h+10 20 1.25])
set(data.ViewPopup, 'pos',[w+1 h+7.75 20 1.75])
set(data.MeshText, 'pos',[w+1 h+4.5 20 1.25])
set(data.XRText, 'pos',[w+1 h+2.75 7 1.25])
set(data.XREdit, 'pos',[w+1 h+1 20 1.5])
set(data.YTText, 'pos',[w+1 h-1.25 7 1.25])
set(data.YTEdit, 'pos',[w+1 h-3 20 1.5])

% ACTIONS
h = figpos(4) - data.iconsize(2) - 0.25;
dx = data.iconsize(1);
dy = data.iconsize(2);
set(data.DrawButton, 'pos',[1 h dx dy])
set(data.ModifyButton, 'pos',[1+dx h dx dy])
set(data.SolveButton, 'pos',[4+2*dx h dx dy])
set(data.CenterButton, 'pos',[4+3*dx h dx dy])
set(data.PlotButton, 'pos',[7+4*dx h dx dy])
set(data.ShowButton, 'pos',[7+5*dx h dx dy])
set(data.ImportExportButton, 'pos',[10+6*dx h dx dy])
set(data.QuitButton, 'pos',[13+7*dx h dx dy])

guidata(fig,data)
% This makes an extra "flash" at startup. But it might be necessary
setview(fig)

%============================================================
function fig = make_importexportfig()

fig = figure('vis','off','number','off','name','Import/Export',...
    'tag','sc_importexport','handlevisibility','callback',...
    'unit','char','menu','none','integerhandle','off','resize','off');

set(fig,'pos',[0,0,41,10])
movegui(fig,'center');

set(fig,'defaultuicontrolunits','char')

uicontrol(fig,'style','frame','pos',[0,0,41,10])

uicontrol('Parent',fig, ...
	'HorizontalAlignment','left', ...
	'Position',[4 6.75 18 1.5],...
	'String','Polygon variable: ', ...
	'Style','text');
uicontrol('Parent',fig, ...
	'Position',[21 6.75 10 1.5],...
	'String','', ...
	'Style','edit', ...
	'Tag','PolygonEdit');
uicontrol('Parent',fig, ...
	'HorizontalAlignment','left', ...
	'Position',[4 4.25 18 1.5],...
	'String','Map variable: ', ...
	'Style','text');
uicontrol('Parent',fig, ...
	'Position',[21 4.25 10 1.5],...
	'String','', ...
	'Style','edit', ...
	'Tag','MapEdit');

% These buttons cause the actions to be taken
%cb = ['fig=gcf; scfig = getuprop(fig,''scfig'');',...
%      'data = scgimprt(getuprop(scfig,''mapdata''));,',...
%      'setuprop(scfig,''mapdata'',data),',...
%      'scgui(scfig,''importupdate'');',...
%      'uiresume(fig)'];
uicontrol('Parent',fig, ...
	'Callback',@scimport, ...
	'Position',[3 1 9 1.75],...
	'String','Import');
%cb = ['scfig = getuprop(gcf,''scfig'');',...
%      'scgexprt(getuprop(scfig,''mapdata'')),',...
%      'uiresume(gcf)'];
uicontrol('Parent',fig, ...
	'Callback', @scexport, ...
	'Position',[16 1 9 1.75],...
	'String','Export');
uicontrol('Parent',fig, ...
	'Callback','uiresume(gcf)', ...
	'Position',[29 1 9 1.75],...
	'String','Cancel');

data = guihandles(fig);
guidata(fig,data)

⌨️ 快捷键说明

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