📄 daqpropedit - what can do one comma.txt
字号:
function daqpropedit(varargin)
%DAQPROPEDIT Property Editor.
%
% DAQPROPEDIT allows editing of properties for the currently
% selected object through the use of a GUI.
% DAQPROPEDIT(OBJ) will set the currently selected object to OBJ on the GUI.
%
% See also PROPINFO, DAQHELP.
% LPD
% Copyright 1998-2003 The MathWorks, Inc.
% $Revision: 1.7.2.5 $ $Date: 2003/12/22 00:48:05 $
switch nargin,
%%%%%%%%%%%%%%%%%%
%%% Initialize %%%
%%%%%%%%%%%%%%%%%%
case 0,
objList=daqfind;
if ~isempty(objList),
objList=objList(1);
else
objList=[];
end
[hFig,data]=LInitFig(objList);
case 1,
if isa(varargin{1}, 'daqdevice') || isa(varargin{1}, 'daqchild')
if ~isvalid(varargin{1}),
error('daq:daqpropedit:argcheck', 'Input must be a valid data acquisition object.')
end
else
error('daq:daqpropedit:argcheck', 'Input must be a valid data acquisition object.');
end
if length(varargin{1})>1,
error('daq:daqpropedit:argcheck', 'Only one object is allowed as a first input argument.')
end
[hFig,data]=LInitFig(varargin{1});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Peform an action from the GUI %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 2,
Action=varargin{1};
hFig=varargin{2};
if ~ischar(Action) && ~ishandle(hFig),
error('daq:daqpropedit:argcheck', 'Too many input arguments to DAQPROPEDIT');
end
set(hFig,'pointer','watch');
data=get(hFig,'UserData');
switch Action,
case 'Close',
data=LClose(data,hFig);
case 'Delete',
data=LDelete(data,hFig);
case 'Help',
LHelp(hFig);
case 'HelpDAQ',
LHelpDAQ
case 'ObjectBrowser',
data=LObjButtonDown(data,hFig);
case 'PropertyChange',
data=LPropertyChange(data);
case 'Resize',
LResize(data,hFig);
case 'SetProperty',
data=LSetProperty(data);
case 'SetValue',
data=LSetValue(data);
% Need to first set the listbox string since LSubPropertyChange looks
% at the string in the listbox if it is one line.
data=LCreateListboxString(data);
data=LSubPropertyChange(data);
case 'Update'
data=LUpdate(data,data.CurrentObj);
end % switch Action
%%%%%%%%%%%%%
%%% Error %%%
%%%%%%%%%%%%%
otherwise,
error('daq:daqpropedit:argcheck', 'Too many input arguments to DAQPROPEDIT');
end % switch nargin
if ~isempty(hFig)&&ishandle(hFig),
set(hFig,'UserData',data,'Pointer','arrow');
end
%%%%%%%%%%%%%%%%%%
%%%%% LClose %%%%%
%%%%%%%%%%%%%%%%%%
function data=LClose(data,hFig)
% Take care of close being called from command line
if isempty(hFig),
hFig=gcf;
data=get(hFig,'UserData');
end
set(hFig,'Visible','off');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LCollapseTree %%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
function data=LCollapseTree(data,value)
% Collapse the Tree
data.ExpandAll=logical(0);
set(data.hMenu(6),'Checked','off');
data.IsExpanded(value)=logical(0);
data=LGetMapping(data);
data=LCreateObjectString(data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LConvertEvalCString %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function str=LConvertEvalCString(origStr)
% This function wraps a string returned from evalc so
% that the string may be placed in a listbox
origStr=strrep(origStr,'''','''''');
lastLoc=max(find(origStr~=abs(sprintf('\n'))));
origStr=[ ...
'char(''' ...
strrep(origStr(1:lastLoc),sprintf('\n'),''',''') ...
''')'
];
origStr=eval(origStr);
str=fliplr(deblank(fliplr(deblank(origStr))));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LConvertToString %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function str=LConvertToString(val)
switch class(val),
case 'char',
str=val;
case 'double',
if numel(val)==1,
str=num2str(val);
else
str=mat2str(val);
end
otherwise,
str=class(val);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LCreateInfo %%%%%
%%%%%%%%%%%%%%%%%%%%%%%
function data=LCreateInfo(data)
% This function:
% 1) Determine new object info.
% 2) Get Indices old objects
% 3) Remove stale info
% 4) Insert new info
% 5) Restore expand setting
hObj=daqfind;
numObj=length(hObj);
level=ones(numObj,1);
isExpanded=zeros(numObj,1);
if numObj==0,
oldData.ObjectList={};
oldData.IsExpanded=[];
else
oldData.ObjectList=data.ObjectList;
oldData.IsExpanded=data.IsExpanded;
end
data.ObjectList={};
data.Level=[];
data.HasChildren=[];
data.IsExpanded=[];
data.NameString={};
ct=1;
for lp=1:length(hObj),
if strncmp(get(hObj(lp),'Type'),'A',1),
children=hObj(lp).Channel;
else
children=hObj(lp).Line;
end
numChildren=length(children);
data.ObjectList{ct,1}=hObj(lp);
data.Level(ct,1)=1;
data.IsExpanded(ct,1)=logical(0);
data.HasChildren(ct,1)=numChildren>0;
data.NameString(ct,1)=LGetNameString(hObj(lp));
if ~isempty(children),
data.ObjectList(ct+1:ct+numChildren,1)=num2cell(children,2);
data.Level(ct+1:ct+numChildren,1)=2;
data.IsExpanded(ct+1:ct+numChildren,1)=logical(1);
data.HasChildren(ct+1:ct+numChildren,1)=logical(0);
data.NameString(ct+1:ct+numChildren,1)=LGetNameString(children);
end
ct=ct+numChildren+1;
end
expLoc=[];
if ~isempty(oldData.IsExpanded),
expLoc=find(oldData.IsExpanded==logical(1));
expObj=oldData.ObjectList(expLoc);
badLoc=[];
for lp=1:length(expObj),
if ( isempty(expObj{lp}) | ~isvalid(expObj{lp}) )
badLoc=[badLoc;lp];
end
end
if ~isempty(badLoc),
expObj(badLoc)=[];
end
if ~isempty(data.Level),
mainObjLoc=find(data.Level==1);
mainObj=data.ObjectList(mainObjLoc);
end
if ~isempty(mainObj),
for lp=1:length(expObj),
for inlp=1:length(mainObj),
if isequal(mainObj{inlp},expObj{lp}),
data.IsExpanded(mainObjLoc(inlp))=logical(1);
break
end
end
end
end
end
data=LGetMapping(data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LCreateListboxString %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function data=LCreateListboxString(data)
%Create the property value listbox string
if ~isempty(data.CurrentObj),
dispStruct=get(data.CurrentObj);
listString=LConvertEvalCString(evalc('disp(dispStruct)'));
colonLoc=findstr(listString(1,:),':');
padding=max(0,28-colonLoc(1));
listString=char(strcat({blanks(padding)},listString));
data.PropList=fieldnames(dispStruct);
val=find(strcmp(data.PropList,data.CurrentProp));
else
listString=' ';
val=1;
data.PropList={''};
end
topDispValue=get(data.hUI(1),'ListboxTop');
if topDispValue>val,
topDispValue=1;
end
set(data.hUI(1), ...
'String' ,listString , ...
'Value' ,val , ...
'ListboxTop',topDispValue ...
);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LCreateObjectString %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function data=LCreateObjectString(data)
% Create the ObjectString
if ~isempty(data.ObjectList),
fontAngle='normal';
levelInfo=data.Level(data.Mapping)-1;
numVal=length(levelInfo);
space=' ';
%%% Create the String %%%
childFlag=data.HasChildren(data.Mapping,1);
% Does it have children and is it expanded or collapsed
%43='+',45='-'
expandCollapse=char(32+childFlag.* ...
(((data.ExpandAll|data.IsExpanded(data.Mapping))*2)+11));
expandCollapse=num2cell(expandCollapse,2);
listString=data.NameString(data.Mapping);
for lpL =1:numVal,
listString{lpL,1}=[
space(ones(1,levelInfo(lpL)*2)) ...
expandCollapse{lpL,1} ...
space ...
listString{lpL,1}
];
end % for lpL
else
fontAngle='italic';
listString='No Data Acquisition Objects';
data.Mapping=[];
end % if ~isempty
% List was changed
topDispValue=get(data.hList,{'Value','ListboxTop'});
handleLoc=[];
for lp=1:length(data.ObjectList(data.Mapping)),
if isequal(data.ObjectList{data.Mapping(lp)},data.CurrentObj),
handleLoc=lp;
break
end
end
if isempty(handleLoc),
topDispValue={1 1};
else
topDispValue{1}=handleLoc;
topDispValue{2}=min(topDispValue{2},handleLoc);
end
set(data.hList, ...
'FontAngle' ,fontAngle , ...
'String' ,cellstr(listString), ...
{'Value','ListboxTop'},topDispValue ...
);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%
%%%%% LDelete %%%%%
%%%%%%%%%%%%%%%%%%%
function data=LDelete(data,hFig)
% Take care of delete being called from command line
if isempty(hFig),
hFig=gcf;
data=get(hFig,'UserData');
end
delete(hFig)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
%%%%% LDeQuotify %%%%%
%%%%%%%%%%%%%%%%%%%%%%
function Value=LDeQuotify(Value)
% Everything coming into here is a string array of 1 row
if ~isempty(Value),
if Value(1)=='''',Value(1)=[];end
end
if ~isempty(Value),
if Value(end)=='''',Value(end)=[];end
end
Value=LQuotingNoOverlap(Value,'''''','''');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
%%%%% LExpandAll %%%%%
%%%%%%%%%%%%%%%%%%%%%%
function data=LExpandAll(data)
hMenu=data.hMenu(6);
if strcmp(get(hMenu,'Checked'),'on'),
set(hMenu,'Checked','off');
data.ExpandAll=logical(0);
else
set(hMenu,'Checked','on');
data.ExpandAll=logical(1);
end
data=LGetMapping(data);
data=LCreateObjectString(data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LExpandTree %%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
function data=LExpandTree(data,value)
% Expand the Tree
data.IsExpanded(value)=1;
data=LGetMapping(data);
data=LCreateObjectString(data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LGetCurrentProp %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
function data=LGetCurrentProp(data)
if ~isempty(data.CurrentObj),
data.PropList=fieldnames(get(data.CurrentObj));
val=find(strcmp(data.PropList,data.CurrentProp));
if isempty(val),
data.CurrentProp=data.PropList{1};
end
set(data.hUI(2),'Enable','on');
else
data.CurrentProp='';
set(data.hUI(2),'Enable','off');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
%%%%% LGetFigPos %%%%%
%%%%%%%%%%%%%%%%%%%%%%
function [horiz,vert]=LGetFigPos(height,width)
% Get Initial Figure Position
temp=get(0,'Units');
set(0,'Units','pixels');
screenSize=get(0,'ScreenSize');
set(0,'Units',temp);
horiz=(screenSize(3)-width)/2;
vert=screenSize(4)/2-height-45;
if horiz < 0,
horiz=10;
end
if vert<0,
vert=screenSize(4)-height-30;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%
%%%%% LGetMapping %%%%%
%%%%%%%%%%%%%%%%%%%%%%%
function data=LGetMapping(data)
%%% Set up The String data %%%
numObj=length(data.ObjectList);
data.Mapping=(1:numObj)';
% Now to set up the hierarchy
loc=1;
val=[];
while loc<=numObj,
val=[val;loc];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -