-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathscgui.m
1255 lines (1082 loc) · 32.7 KB
/
scgui.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function out = scgui(varargin)
%SCGUI Create graphical user interface for the SC Toolbox.
% SCGUI creates the graphical user interface (GUI) for the
% Schwarz-Christoffel Toolbox in a new figure window.
%
% For complete details on the interface, see the user's guide.
% Copyright 1998-2002 by Toby Driscoll.
% $Id: scgui.m 298 2009-09-15 14:36:37Z driscoll $
% If called from the GUI, reroute to switchyard function cback
%%if nargin > 1
%% out = cback(guidata(gcbo),varargin{:});
%% return
%%end
% Create figure
fig = figure('name','Schwarz-Christoffel Mapping','numbertitle','off',...
'tag','scgui','menubar','none','vis','off');
set(fig,'defaultuicontrolinterrupt','on')
% Determine/set figure size
minsize = [95 36];
unit = get(0,'units');
set(0,'units','char')
ss = get(0,'screensize');
set(0,'units',unit)
optsize = 0.65*ss(3:4);
truesize = max(optsize,minsize);
set(fig,'unit','char','pos',[0 ss(4)-truesize(2)-8 truesize])
% can't figure out why this doesn't work right.
%% movegui(fig,'northeast')
% Custom resize function
% I have to disable this because at least in my window manager (KDE), the
% resizing is soooooooo slow as to be painful. But you can try it on
% your machine.
%%set(fig,'resizefcn',@resize,'deletefcn',@selfdelete)
set(fig,'resize','off')
% Create axes
ax(1) = axes('units','char','tag','PhysicalAxes');
ax(2) = axes('units','char','tag','CanonicalAxes');
set(ax,'next','add','box','on','plotboxaspectratio',[1 1 1])
% Create widgets and set sizes appropriately (subfunctions)
make_widgets(fig);
resize_widgets(fig)
drawnow
set(fig,'closerequestfcn',@scquit)
set(fig,'vis','on')
function draw(obj,varargin)
data = guidata(obj);
p = polyedit;
if ~isempty(p)
deletepoly(obj,'confirmed')
deletemap(obj)
addpoly(obj,p)
end
function domodify(obj,varargin)
data = guidata(obj);
p = data.polygon;
if isempty(p)
errordlg('You must first draw or import a polygon,','SC Error')
return
end
n = length(p);
p1 = polyedit(p);
% Was anything really changed?
changed = 0;
w = vertex(p);
w1 = vertex(p1);
if length(w1) ~= length(w)
changed = 1;
elseif norm(w(~isinf(w))-w1(~isinf(w1))) > 1000*eps
changed = 1;
end
if changed
deletepoly(obj,'confirmed')
addpoly(obj,p1)
% Ask about continuation.
set(findobj(data.SCfig,'tag','MeshLines'),'erase','norm','vis','off')
if data.iscurrent & length(w1)==length(w)
a = questdlg('Do you want to use continuation from the current parameter solution?','Map continuation','Yes','No','No');
else
a = 'No';
end
if strcmp(a,'No')
deletemap(obj)
else
deletemap(obj,'continue')
end
end
function edit(obj,varargin)
data = guidata(obj);
w = vertex(data.polygon);
if isempty(w), return, end
if any(isinf(w))
errordlg('Cannot edit vertices of unbounded polygons.','SC Error')
return
end
n = length(w);
% Call edit window
[flag,w] = scgedit('Edit vertices','Vertices:',w);
% If edit was accepted, try to convert it to a polygon.
if flag > 0
try
p = polygon(w);
catch
errordlg('Invalid polygon specified.','SC Error')
return
end
else
return
end
% We now assume the polygon was changed.
deletepoly(obj,'confirmed')
if length(w)~=n
% No way to be a continuation
deletemap(obj)
else
deletemap(obj,'continue')
end
addpoly(obj,polygon(w))
function solve(obj,varargin)
data = guidata(obj);
p = data.polygon;
if isempty(p)
errordlg('You must first draw or import a polygon.','SC Error')
return
end
mapnum = get(data.DomainPopup,'value');
maptype = data.mapclass{mapnum};
oldmap = data.map;
trace = 1;
%trace = get(data.TraceBox,'value');
tol = str2num(get(data.TolEdit,'string'));
if trace == 1
trace = 'on';
else
trace = 'off';
end
opt = sctool.scmapopt('Trace',trace,'Tol',tol);
if ~isempty(oldmap)
% Continuation
mapcmd = sprintf('map = %s(oldmap,p,opt);',maptype);
else
mapcmd = sprintf('map = %s(p,opt);',maptype);
end
try
eval(mapcmd)
catch
errordlg('Solution process failed!','SC Error')
return
end
deletemap(obj)
% Store new map
if ~isempty(map)
addmap(obj,map)
% Get the polygon back out of the map, because indexing and trivial
% vertices may change.
p = polygon(map);
deletepoly(obj,'confirmed')
addpoly(obj,p)
end
plotcanonical(obj)
setview(obj)
function plotcanonical(obj,varargin)
data = guidata(obj);
fig = data.SCfig;
if ~data.iscurrent, return, end
% Draw the canonical domain
axes(data.CanonicalAxes)
delete(findobj(gca,'tag','PolygonPlot'))
z = parameters(data.map);
z = z.prevertex;
switch class(data.map)
case { 'diskmap','extermap','crdiskmap' }
h = plot(exp(1i*linspace(0,2*pi,100)),'linewid',1);
axis normal
axis equal
axis square
axis([-1.1 1.1 -1.1 1.1])
case 'hplmap'
xmin = min(z(~isinf(z)));
xmax = max(z(~isinf(z)));
xlim = [1.1*xmin-.1*xmax,1.1*xmax-.1*xmin];
h = plot(xlim,[0,0],'linewid',1);
axis normal
axis equal
axis square
axis([xlim,-.1,1])
case 'stripmap'
minx = min(real(z(~isinf(z))));
maxx = max(real(z(~isinf(z))));
d = (maxx-minx)/2;
m = (maxx+minx)/2;
h(1) = plot([m-1.2*d,m+1.2*d],[0,0],'linewid',1);
h(2) = plot([m-1.2*d,m+1.2*d],[1,1],'linewid',1);
axis normal
axis equal
axis([m-1.2*d,m+1.2*d,-.1,1.1])
case { 'rectmap','crrectmap' }
axis auto
h = plot(polygon(z));
axis equal
end
guidata(fig,data)
set(h,'tag','PolygonPlot')
h = plot(real(z),imag(z),'ko','markersize',5,'markerfacecolor','k');
set(h,'tag','PolygonPlot')
function recenter(obj,varargin)
data = guidata(obj);
fig = data.SCfig;
% Only applies to current disk maps
isdisk = any(strcmp(class(data.map),{'diskmap','crdiskmap'}));
if ~data.iscurrent
errordlg('You must first solve for the map parameters.','SC Error')
return
elseif ~isdisk
errordlg('The conformal center is defined only for disk maps.','SC Error')
return
end
ax(1) = data.PhysicalAxes;
ax(2) = data.CanonicalAxes;
% Show physical domain & turn off point mapping
set(findobj(ax(1)),'vis','on')
set(findobj(ax(2)),'vis','off')
set(ax,'buttondown','')
% Get point and do calculation
axes(ax(1))
title('Click at conformal center')
[xc,yc] = ginput(1);
title('')
data.map = center(data.map,xc+i*yc);
guidata(obj,data)
deletemap(obj)
addmap(obj,data.map)
plotcanonical(obj)
setview(obj)
function scdisplay(obj,varargin)
data = guidata(obj);
if ~data.iscurrent
errordlg('You must first solve for the map parameters.','SC Error')
else
str = char(data.map);
pos = [0 0 100 size(str,1)];
f = figure('unit','char','vis','off','integerhandle','off',...
'name','Map parameters','numbertitle','off','pos',pos);
u = uicontrol('style','text','unit','char',...
'pos',pos,'fontname','FixedWidth','horiz','left',...
'background','white','string',str);
set(f,'vis','on')
end
function meshplot(obj,varargin)
data = guidata(obj);
if ~data.iscurrent
errordlg('You must first solve for the map parameters.','SC Error')
return
end
ax(1) = data.PhysicalAxes;
ax(2) = data.CanonicalAxes;
% Parse mesh line widgets
xrhan = data.XREdit;
ythan = data.YTEdit;
xrstring = get(xrhan,'string');
ytstring = get(ythan,'string');
if strcmp(xrstring,'defaults') | strcmp(xrstring,'default')
xr = 10;
else
xr = str2num(xrstring);
end
if strcmp(ytstring,'defaults') | strcmp(ytstring,'default')
yt = 10;
else
yt = str2num(ytstring);
end
% Bring up physical domain and clear old mesh lines
%% set(findobj(ax(1)),'vis','on')
%% set(findobj(ax(2)),'vis','off')
ml = findobj(ax,'tag','MeshLines');
%%set(ml,'erase','normal')
delete(ml)
delete(findobj(ax(1),'tag','PolygonPlot'))
drawnow
% Exterior map: Allow axis autoscale
if strcmp(class(data.map),'extermap')
set(ax(1),'xlimmode','auto','ylimmode','auto')
end
% Do the plot
[h,xr,yt] = plot(data.map,xr,yt);
%%set(h,'erasemode','none','tag','MeshLines')
set(h,'tag','MeshLines')
% Plotting routines plot their own copy of the polygon,
% without returning handles. This locates and (re)tags these lines.
hp = findobj(ax(1),'tag','PolygonSide');
set(hp,'tag','PolygonPlot','uicontext',data.PolygonContextMenu)
% Update mesh line widgets
if isempty(xr)
xrstring = '';
else
xrstring = ['[',sprintf('%.3g ',xr),']'];
end
isdisk = strcmp(class(data.map),'diskmap');
isdisk = isdisk | strcmp(class(data.map),'extermap');
if isempty(yt)
ytstring = '';
elseif isdisk
ytstring = ['pi*[',sprintf('%.3g ',yt/pi),']'];
else
ytstring = ['[',sprintf('%.3g ',yt),']'];
end
set(xrhan,'string',xrstring)
set(ythan,'string',ytstring)
% May want to fix up the canonical domain
axes(ax(2))
z = prevertex(data.map);
switch class(data.map)
case {'diskmap','extermap','crdiskmap'}
case 'hplmap'
zf = z(~isinf(z));
xlim = [min(zf);max(zf)];
xlim = [1.1 -.1; -.1 1.1] * xlim;
ylim = [0;max(zf)];
ylim = [0 0; -.1 1.1]*ylim;
axis([xlim',-0.05*ylim(2),ylim(2)])
case 'stripmap'
%% zf = z(~isinf(z));
%% xlim = [min(zf);max(zf)];
%% xlim = [1.1 -.1; -.1 1.1] * xlim;
%% axis([xlim',-.1,1.1])
case 'rectmap'
case 'crrectmap'
end
% Want to do this so that the buttondown of the mesh lines is set up.
setview(obj)
function images = mappts(pts)
domain = get(gca,'tag');
data = guidata(gcbo);
source = pts; % (given)
images = [];
if data.iscurrent
title('Mapping...')
drawnow
if ~isempty(source)
% Forward/inverse map, depending on plane in view
if strcmp(domain,'PhysicalAxes')
images = evalinv(data.map,source);
elseif strcmp(domain,'CanonicalAxes')
images = eval(data.map,source);
end
else
images = [];
end
title('')
drawnow
end
function addpt(varargin)
% Take no action unless it's a standard left-click. But DON'T just return,
% because that short-circuits context menu clicks.
if strcmp(get(gcf,'selectiontype'),'normal')
data = guidata(gcbo);
pt = get(gca,'currentpoint');
% Map it
img = mappts(pt(1,1)+i*pt(1,2));
ax(1) = data.PhysicalAxes;
ax(2) = data.CanonicalAxes;
domain = find(gca==ax);
% Ensure the existence of the line objects.
if isempty(data.PhysicalPoints) | ~ishandle(data.PhysicalPoints)
data.PhysicalPoints = make_pointsobject(data,'Physical');
end
if isempty(data.CanonicalPoints) | ~ishandle(data.CanonicalPoints)
data.CanonicalPoints = make_pointsobject(data,'Canonical');
end
h = [data.PhysicalPoints data.CanonicalPoints];
% Update objects to show points
axes(ax(domain))
%%set(h,'erasemode','none')
xs = [get(h(domain),'xdata') pt(1,1)];
ys = [get(h(domain),'ydata') pt(1,2)];
set(h(domain),'xdata',xs,'ydata',ys)
xi = [get(h(3-domain),'xdata') real(img)];
yi = [get(h(3-domain),'ydata') imag(img)];
set(h(3-domain),'xdata',xi,'ydata',yi)
if domain==1
data.phypoints = xs + 1i*ys;
data.canpoints = xi + 1i*yi;
else
data.phypoints = xi + 1i*yi;
data.canpoints = xs + 1i*ys;
end
%%set(h,'erasemode','normal')
guidata(gcbf,data)
end
function editpts(varargin)
domain = get(gca,'tag');
if isempty(domain), return, end
data = guidata(gcbo);
pphan = data.PhysicalPoints;
cphan = data.CanonicalPoints;
wp = get(pphan,'xdata')+i*get(pphan,'ydata');
zp = get(cphan,'xdata')+i*get(cphan,'ydata');
wp = wp(~isnan(wp));
zp = zp(~isnan(zp));
% Interpretation of box depends on current view domain
if strcmp(domain,'PhysicalAxes')
[flag,wp] = scgedit('Edit points','Physical',wp);
if flag > 0
zp = mappts(wp);
end
elseif strcmp(domain,'CanonicalAxes')
[flag,zp] = scgedit('Edit points','Canonical',zp);
if flag > 0
wp = mappts(zp);
end
end
if flag > 0
% Update point objects
set(pphan,'xdata',real(wp(:))','ydata',imag(wp(:))')
set(cphan,'xdata',real(zp(:))','ydata',imag(zp(:))')
data.phypoints = wp(:);
data.canpoints = zp(:);
guidata(gcbf,data)
end
function importexport(obj,varargin)
data = guidata(obj);
fig = data.SCfig;
% Find import/export window, or create if necessary
fig2 = findobj(0,'tag','sc_importexport');
if isempty(fig2)
fig2 = make_importexportfig;
else
figure(fig2)
end % (create window)
data = guidata(fig2);
data.parentfig = fig;
guidata(fig2,data)
% Reveal window and wait for action
set(fig2,'vis','on')
uiwait(fig2)
set(fig2,'vis','off') % turn it off
function scimport(obj,varargin)
% Data from the I/E dialog.
IEdata = guidata(obj);
% Data from the SC figure
SCfig = IEdata.parentfig;
SCdata = guidata(SCfig);
name = get(IEdata.PolygonEdit,'string');
if ~isempty(name)
try
p = evalin('base',name);
deletepoly(SCfig,'confirmed')
deletemap(SCfig)
addpoly(SCfig,p)
catch
errordlg(lasterr,'SC Error')
end
end
name = get(IEdata.MapEdit,'string');
if ~isempty(name)
try
map = evalin('base',name);
% This overrides an imported polygon.
p = polygon(map);
deletepoly(SCfig,'confirmed')
deletemap(SCfig)
addpoly(SCfig,p)
addmap(SCfig,map)
catch
errordlg(lasterr,'SC Error')
uiresume(gcbf)
end
end
plotcanonical(SCfig)
setdomain(SCfig)
setview(SCfig)
uiresume(gcbf)
function scexport(varargin)
% Data from the I/E dialog.
IEdata = guidata(gcbf);
% Data from the SC figure
SCfig = IEdata.parentfig;
SCdata = guidata(SCfig);
name = get(IEdata.PolygonEdit,'string');
if ~isempty(name) & ~isempty(SCdata.polygon)
assignin('base',name,SCdata.polygon);
end
name = get(IEdata.MapEdit,'string');
if ~isempty(name) & SCdata.iscurrent
assignin('base',name,SCdata.map);
end
uiresume(gcbf)
function setview(obj,varargin)
data = guidata(obj);
ax(1) = data.PhysicalAxes;
ax(2) = data.CanonicalAxes;
viewdom = get(data.ViewPopup,'value');
% Set axes positions
window = data.axeswindow;
if viewdom==1 | viewdom==2
set(ax,'pos',window)
else
% They must occupy the window together
dx = .46*window(3);
dy = window(4);
set(ax(1),'pos',[window(1) window(2) dx dy])
set(ax(2),'pos',[window(1)+window(3)-dx window(2) dx dy])
end
% Set visibility, map-on-click functions
vis = [viewdom~=2 viewdom~=1];
set(findobj(ax(vis)),'visible','on')
set(findobj(ax(~vis)),'visible','off')
% All children get the buttondown set to map points. This is because lines
% can "hide" the axes in a zone around the line (so no mapping close to the
% boundary). Even though the 'hittest' property seems to fix this,
% if that is turned off then we don't get nice context menus. The addpt
% function will sort out left clicks from right.
if ~isempty(data) & data.iscurrent
set(findobj(ax(vis)),'buttondown',@addpt)
else
set(findobj(ax(vis)),'buttondown','')
end
set(findobj(ax(~vis)),'buttondown','')
if sum(vis)==1
axes(ax(vis))
end
function setdomain(obj,varargin)
data = guidata(obj);
fig = data.SCfig;
mapnum = get(data.DomainPopup,'value');
%type = {'disk','half-plane','strip','rectangle','exterior'};
curmapnum = strmatch(class(data.map),data.mapclass);
if ~isempty(curmapnum) & mapnum~=curmapnum
% Map type has been changed, so kill old map
deletemap(obj)
end
% Mesh line options should be r/theta or x/y
set(data.XREdit,'string','defaults');
set(data.YTEdit,'string','defaults');
xrtext = data.XRText;
yttext = data.YTText;
if mapnum==1 | mapnum==5
set(xrtext,'string','r =')
set(yttext,'string','theta =')
else
set(xrtext,'string','x =')
set(yttext,'string','y =')
end
%%% Clear all current mesh lines
%%delete(findobj(fig,'tag','MeshLines'))
function scquit(varargin)
if strcmp(questdlg('Really quit?','Quit SC mapping'),'Yes')
selfdelete
end
function selfdelete(varargin)
delete([findobj(0,'tag','sc_importexport') gcbf])
function resize(varargin)
resize_widgets(gcbf)
function savedata(varargin)
obj = gcbo;
data = guidata(obj);
p = data.polygon; map = data.map;
if isempty(p) && isempty(map)
return
end
if ~isfield(data,'savename') || isempty(data.savename)
filter = '*.mat';
else
filter = data.savename;
end
[filen,pathn] = uiputfile(filter,'Save SC data');
if isstr(filen)
data.savename = [pathn filen];
guidata(obj,data);
save([pathn filen],'p','map');
end
function loaddata(varargin)
obj = gcbo;
data = guidata(obj);
if ~isfield(data,'savename') || isempty(data.savename)
filter = '*.mat';
else
filter = data.savename;
end
[filen,pathn] = uigetfile(filter,'Load SC data');
if isstr(filen)
S = load([pathn filen]);
if ~isfield(S,'p') || ~isfield(S,'map')
error('File %s does not contain needed GUI data',[pathn filen])
else
data.savename = [pathn filen];
guidata(obj,data);
deletepoly(obj,'confirmed')
deletemap(obj)
addpoly(obj,S.p)
if ~isempty(S.map), addmap(obj,S.map), end
end
end
function printablecopy(varargin)
fig = gcbf;
data = guidata(fig);
ax(1) = data.PhysicalAxes;
ax(2) = data.CanonicalAxes;
viewdom = get(data.ViewPopup,'value');
if viewdom==1 || viewdom==2 % only one view
idx = viewdom;
else
idx = [1 2];
end
newfig = figure;
for l = 1:length(idx)
subplot(1,length(idx),l);
tmp = gca;
axun = get(tmp,'unit'); axpos = get(tmp,'pos');
newax = copyobj( ax(idx(l)), newfig );
delete(tmp)
set(newax,'unit',axun,'pos',axpos);
% Wipe out GUI-specific markers.
set(newax,'buttondown','','tag','')
set(allchild(newax),'uicontextmenu',[],'buttondown','','tag','')
end
function addpoly(obj,p,varargin)
% Add a polygon. Make sure that it is displayed and tagged properly, and
% enable appropriate further actions.
data = guidata(obj);
data.polygon = p;
guidata(obj,data)
if isempty(p), return, end
if nargin<3 | ~all(ishandle(varargin{1}))
axes(data.PhysicalAxes)
axis auto
h = plot(p);
else
h = varargin{1};
end
set(h, 'tag','PolygonPlot', 'uicontext',data.PolygonContextMenu);
set(data.PolygonEnabled,'enable','on')
function deletepoly(obj,varargin)
% Remove the polygon from display and the data structure.
if nargin < 2 | ~isequal( varargin{1},'confirmed')
answer = questdlg('Really delete the current polygon?','Confirm delete',...
'Yes','No','No');
if strcmp(answer,'No'), return, end
end
data = guidata(obj);
data.polygon = [];
guidata(obj,data)
delete(findobj(data.SCfig,'tag','PolygonPlot'))
% Without a polygon, some controls are disabled.
set(data.PolygonEnabled,'enable','off')
function menudeletepoly(obj,varargin)
deletepoly(obj)
deletemap(obj)
function addmap(obj,map)
% Add a map. Make sure that supporting objects exist and
% enable appropriate further actions.
data = guidata(obj);
data.map = map;
data.iscurrent = 1;
guidata(obj,data)
% Correct the class popup to reflect reality.
set(data.DomainPopup,'value',strmatch(class(map),data.mapclass))
plotcanonical(obj)
% Enable relevant controls.
set(data.MapEnabled,'enable','on')
function deletemap(obj,varargin)
% The current map has been deleted (or never existed). Take care of the data
% structures and widgets.
data = guidata(obj);
% We may not erase the memory of the map if we want to do continuation.
if nargin < 2 | ~isequal(varargin{1},'continue')
data.map = [];
end
data.iscurrent = 0;
guidata(obj,data)
set(data.MapEnabled,'enable','off')
% No mesh lines or canonical domain.
ml = findobj(data.SCfig,'tag','MeshLines');
%%set(ml,'erasemode','normal')
delete(ml)
delete(findobj(data.CanonicalAxes,'tag','PolygonPlot'))
% There can be no points to display...
deletepoints(obj,'confirmed')
% ...nor can more be mapped.
set(findobj([data.PhysicalAxes,data.CanonicalAxes]),'buttondown','')
function deletepoints(obj,varargin)
% Remove plotted points from display and data structure.
if nargin < 2 | ~isequal( varargin{1},'confirmed')
answer = questdlg('Really delete the plotted points?','Confirm delete',...
'Yes','No','No');
if strcmp(answer,'No'), return, end
end
data = guidata(obj);
data.phypoints = [];
data.canpoints = [];
h = [data.PhysicalPoints,data.CanonicalPoints];
set(h(ishandle(h)),'xdata',[],'ydata',[])
guidata(obj,data)
function hp = make_pointsobject(data,type)
hp = line('parent',getfield(data,[type 'Axes']),...
'linestyle','none','marker','o','markersize',5,...
'color',[1 0 0],'markerfacecolor',[1 0 0],...
'tag',[type 'Points'],'uicontextmenu',data.PointContextMenu,...
'xdata',[],'ydata',[]);
function [flag,x1,x2] = scgedit(name,xlab1,x1,xlab2,x2)
% Pops up a figure window to edit some data.
nvar = 1;
if nargin==5
nvar = 2;
end
fig2 = figure('vis','off','NumberTitle','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],...