www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mvgraph4d/prefsgui.m

    function gr=prefsgui(gr,varargin)
%PREFSGUI Preferences GUI for graph4d objects
%
%  PREFSGUI(GR) opens a GUI for altering general preferences in the graph4d
%  object.

%  Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc.


scrsz=get(0,'ScreenSize');
figh=xregdialog('position',[scrsz(3)/2-145 scrsz(4)/2-140 290 270],...
    'name','4D Graph Options',...
    'resize','off');

lyt=i_createlyt(figh,gr);

% ok and cancel buttons
okbtn=uicontrol('Style','pushbutton',...
    'Parent',figh,...
    'String','OK',...
    'Callback','set(gcbf, ''tag'', ''ok'', ''visible'', ''off'');');
cancbtn=uicontrol('Style','pushbutton',...
    'Parent',figh,...
    'String','Cancel',...
    'Callback','set(gcbf, ''tag'', ''cancel'', ''visible'', ''off'');');
applybtn=uicontrol('Style','pushbutton',...
    'Parent',figh,...
    'String','Apply',...
    'Callback',{@i_apply, gr});

main = xreggridbaglayout(figh, 'dimension', [2 4], ...
    'rowsizes', [-1 25], ...
    'colsizes', [-1 65 65 65], ...
    'border', [10 10 10 10], ...
    'gapx', 7, ...
    'gapy', 10, ...
    'mergeblock', {[1 1], [1 4]}, ...
    'elements', {lyt, [], [], okbtn, [], cancbtn, [], applybtn});
figh.LayoutManager = main;
set(main, 'packstatus', 'on');
figh.showDialog(okbtn);

tg = get(figh, 'Tag');
if strcmp(tg, 'ok')
    % Apply changes before deleting figure
    i_apply(applybtn, [], gr);
end

delete(figh);
return


function lyt=i_createlyt(figh,gr)

% Colors
frm1=mbcgui.container.layoutpanel(...
    'Parent', figh, ...
    'Title','Colors',...
    'BorderType', 'etchedin', ...
    'LayoutBorder',[10 0 10 5]);
ud.axcol=get(gr.axes,'Color');
ud.gen.axcol.edit=uicontrol('Style','edit',...
    'Parent',frm1,...
    'BackgroundColor',[1 1 1],...
    'Callback',{@i_editchcol, gr, 'gen.axcol.push'});
ud.gen.axcol.push=uicontrol('Style','toggle',...
    'Value',0,...
    'Callback',{@i_interactivechcol, gr, 'gen.axcol.edit'},...
    'Parent',frm1);
ud.gen.axcol.text=xregGui.labelcontrol('parent',frm1,...
    'controlsize', 75, ...
    'string','Axes color:', ...
    'control', ud.gen.axcol.edit);

if ischar(ud.axcol)
    set([ud.gen.axcol.edit],'String','none');
else   
    set(ud.gen.axcol.push,'BackgroundColor',ud.axcol);
    set(ud.gen.axcol.edit,'String',['[' num2str(ud.axcol(1)) ' ' num2str(ud.axcol(2)) ' ' num2str(ud.axcol(3)) ']']);
end

ud.lbcol=get(gr.axes,'XColor');
ud.gen.fgcol.edit=uicontrol('Style','edit',...
    'Parent',frm1,...
    'BackgroundColor',[1 1 1],...
    'String',['[' num2str(ud.lbcol(1)) ' ' num2str(ud.lbcol(2)) ' ' num2str(ud.lbcol(3)) ']'],...
    'Callback',{@i_editchcol, gr, 'gen.fgcol.push'});
ud.gen.fgcol.push=uicontrol('Style','toggle',...
    'Value',0,...
    'BackgroundColor',ud.lbcol,...
    'Callback',{@i_interactivechcol, gr, 'gen.fgcol.edit'},...
    'Parent',frm1);
ud.gen.fgcol.text=xregGui.labelcontrol('parent',frm1,...
    'controlsize', 75, ...
    'string','Axes'' markings color:', ...
    'control', ud.gen.fgcol.edit);

frm2=mbcgui.container.layoutpanel(...
    'Parent', figh, ...
    'Title','Grid',...
    'BorderType', 'etchedin', ...
    'LayoutBorder',[10 0 10 5]);
val=zeros(2,2);
st=get(gr.axes,'GridLineStyle');
val(find(strcmp(st,{'-',':','--','-.'})))=1;
if ~any(val)
    val(1)=1;
end
ud.hist.gridstyle=xregGui.rbgroup(frm2,'nx',2,'ny',2, ...
    'string',{'solid','dashed';'dotted','dash-dot'},...
    'value',val);

grs = get(gr.axes,{'XGrid','YGrid','ZGrid'});
val = strcmp(grs,'on');
% grid direction on/off
ud.hist.gridx.roll=uicontrol('Parent', frm2,...
    'Style', 'checkbox', ... 
    'String','X-direction',...
    'Value',val(1));
ud.hist.gridy.roll=uicontrol('Parent', frm2,...
    'Style', 'checkbox', ...
    'String','Y-direction',...
    'Value',val(2));
ud.hist.gridz.roll=uicontrol('Parent', frm2,...
    'Style', 'checkbox', ...
    'String','Z-direction',...
    'Value',val(3)); 

proj=get(gr.axes,'Projection');
val=strcmp(proj,{'orthographic','perspective'});
ud.axesproj.type=xregGui.rbgroup(figh,'nx',2,'ny',1,...
    'string',{'Orthographic','Perspective'},'value',val);
ud.axesproj.txt=xregGui.labelcontrol('parent',figh,...
    'controlsize', 180, ...
    'string','Axes projection:', ...
    'control', ud.axesproj.type, ...
    'BaselineOffsetMode', 'manual');

grd1 = xreggridbaglayout(frm1, 'packstatus', 'off', ...
    'dimension', [2 2], ...
    'rowsizes', [20 20], ...
    'colsizes', [190 30], ...
    'gapx', 5, ...
    'gapy', 3, ...
    'elements', {ud.gen.axcol.text, ud.gen.fgcol.text, ud.gen.axcol.push, ud.gen.fgcol.push});
set(frm1, 'LayoutComponent', {grd1});
grd2 = xreggridbaglayout(frm2, 'dimension', [3 2], ...
    'rowsizes', [20 20 20], ...
    'colsizes', [100 -1], ...
    'gapx', 10, ...
    'gapy', 3, ...
    'mergeblock', {[1 2], [2 2]}, ...
    'elements', {ud.hist.gridx.roll, ud.hist.gridy.roll, ud.hist.gridz.roll, ud.hist.gridstyle});
set(frm2, 'LayoutComponent', {grd2});

lyt = xreggridbaglayout(figh, 'dimension', [3 1], ...
    'rowsizes', [75, 100, 20], ...
    'gapy', 10, ...
    'elements', {frm1, frm2, ud.axesproj.txt});

ud.graph=gr;
set(figh,'UserData',ud);
return


function i_apply(src, evt, gr)
figh = ancestor(get(src, 'Parent'), 'figure');
ud=get(figh,'UserData');

% update object
vis = get(gr, 'Visible');
set(gr,'Visible','off');
axcol=get(ud.gen.axcol.edit,'String');
if strcmp(axcol,'none')
    set(gr.axes,'Color','none');
else
    set(gr.axes,'Color',get(ud.gen.axcol.push,'BackgroundColor'));
end
col=get(ud.gen.fgcol.push,'BackgroundColor');
set([gr.axes;gr.colorbar.axes],{'XColor','YColor','ZColor'},{col,col,col});
set([gr.xtext;gr.ytext;gr.ztext; gr.ctext; ...
        gr.colorbar.frame1; gr.colorbar.frame2; gr.colorbar.userange], ...
    'ForegroundColor',col);
set(get(gr.colorbar.axes,'Title'),'Color',col);

val(1)=get(ud.hist.gridx.roll,'Value');
val(2)=get(ud.hist.gridy.roll,'Value');
val(3)=get(ud.hist.gridz.roll,'Value');
grs=repmat({'off'},1,3);
grs(val~=0)={'on'};
set(gr.axes,{'XGrid','YGrid','ZGrid'},grs);
grids={'-',':','--','-.'};
val=get(ud.hist.gridstyle,'Selected');
set(gr.axes,'GridLineStyle',grids{val}); 

proj={'orthographic','perspective'};
proj=proj{get(ud.axesproj.type,'Selected')};
set(gr.axes,'Projection',proj);

set(gr,'Visible',vis);
return


function i_editchcol(src, evt, gr, field)
figh= ancestor(get(src, 'Parent'), 'figure');
ud=get(figh,'UserData');
changeobj=i_getfield(ud,field);

% grab string
str=get(src,'String');
if strcmp(str,'none')
    set(changeobj,'BackgroundColor',get(0,'DefaultUicontrolBackgroundColor'));
    set(src,'String','none');
else
    col=str2num(str);
    if length(col(:))~=3 || any(col>1 | col<0)  
        % revert
        col=get(changeobj(1),'BackgroundColor');
        set(src,'String',['[' num2str(col(1)) ' ' num2str(col(2)) ' ' num2str(col(3)) ']']);
    else
        set(changeobj,'BackgroundColor',col);
    end
end  


function i_interactivechcol(src, evt, gr, field)
figh= ancestor(get(src, 'Parent'), 'figure');
ud=get(figh,'UserData');
changeobj=i_getfield(ud,field);

col=get(src,'BackgroundColor');
col2=uisetcolor(col);
if ~all(col2==col)
    set(src,'BackgroundColor',col2,'Value',0);
    set(changeobj,'String',['[' num2str(col2(1),2) ' ' num2str(col2(2),2) ' ' num2str(col2(3),2) ']']);
else
    set(src,'Value',0);
end



%========================================================================
% i_getfield......replacement for external getfield
%========================================================================

function [out]=i_getfield(base,ext)
% parse ext for .'s
dots=strfind(ext,'.');
% set up subsrefs structs
if isempty(dots)
    s=struct('type','.','subs',ext);
else
    dots=[1 dots+1 length(ext)+2];
    for n=1:(length(dots)-1)
        sbs(n)={ext(dots(n):(dots(n+1)-2))};
    end
    s=struct('type',repmat({'.'},1,length(dots)-1),'subs',sbs);
end
out=subsref(base,s);
return