| dbimdraw(CurrentBlock,DrawFlag,BusName,Names,Sizes,ShowBusFlag)
|
function dbimdraw(CurrentBlock,DrawFlag,BusName,Names,Sizes,ShowBusFlag)
%DBCBDRAW Update mask icon mask drawing string in SIMULINK DataBus blocks.
%
%Use this to setup complex drawing string for blocks in the DataBus blockset.
%Icon in the SIMULINK DataBus blockset.
%Valid block types are:
% 'Insert Signal(s)'
% 'Select Signal(s)'
% 'Combine Buses'
% William York, 12/95.
% Copyright (c) 1995 by The MathWorks, Inc.
% $Revision: 1.1 $ $Date: 1997/02/11 20:50:42 $
% disp(['Entering ' mfilename])
BlockType=get_param(CurrentBlock,'Mask Type');
if (findstr('Insert Signal',BlockType))
% Find the number of signals in the input string
[AllNames, Remainder]=strtok(Names, '|');
while ~isempty(Remainder)
[Name, Remainder]=strtok(Remainder, '|');
AllNames=str2mat(AllNames,Name);
end
[NumNames,MaxNameWidth]=size(AllNames);
% Check if sizes is a vector or scaler
if (strcmp(AllNames,'<none>'))
RealSizes=1;
else
for (Ind=1:NumNames)
indices=parsebus(BusName,deblank(AllNames(Ind,:)));
RealSizes(Ind)=length(indices);
end
end
if (length(Sizes) == 1)
if (Sizes)
% if sizes is length 1 and it's not zero, set it equal to RealSizes
Sizes=RealSizes;
else
% if sizes is length 1 and it's zero, leave it alone
end
end
if (length(RealSizes) < 1 )
% if real sizes is empty, set it to 1
RealSizes=1;
end
sys=get_param(CurrentBlock,'Parent');
cb=get_param(CurrentBlock,'Name');
BusSize = bussize(BusName);
setnin([sys '/' cb],BusSize,RealSizes,ShowBusFlag);
if (~DrawFlag)
drawstring=strrep(strrep(BlockType,'(Gui)',''),'(Text)','');
drawstring=strrep(drawstring,' ','\n');
else
if (ShowBusFlag)
DisplayString=sprintf(['%-' num2str(MaxNameWidth+2) 's'], ...
deblank(BusName));
else
DisplayString=[];
end
% Check if sizes is a vector or scaler
if (isempty(Sizes))
error('Empty Sizes vector passed to dbimdraw');
end
if (Sizes)
if (length(Sizes) ~= NumNames)
% This was called from the mask
% get the sizes which correspond to the given names
for (Ind=1:NumNames)
Sizes(Ind)=length(parsebus(BusName,deblank(AllNames(Ind,:))));
end
end
end
if (all(Sizes))
for (Ind=1:NumNames)
if (isempty(DisplayString))
DisplayString= ...
sprintf(['%-' num2str(MaxNameWidth) 's[%d]'], ...
deblank(AllNames(Ind,:)), Sizes(Ind));
else
DisplayString=[DisplayString, ...
sprintf(['\\n\\n%-' num2str(MaxNameWidth) 's[%d]'], ...
deblank(AllNames(Ind,:)), Sizes(Ind))];
end
end
else
for (Ind=1:NumNames)
if (isempty(DisplayString))
DisplayString=sprintf(['%-' num2str(MaxNameWidth+2) 's'], ...
deblank(AllNames(Ind,:)));
else
DisplayString=[DisplayString sprintf(['\\n\\n%-' ...
num2str(MaxNameWidth+2) 's'], deblank(AllNames(Ind,:)))];
end
end
end
drawstring=DisplayString;
end
elseif (findstr('Select Signal',BlockType))
% Find the number of signals in the input string
[AllNames, Remainder] = strtok(Names, '|');
while ~isempty(Remainder)
[Name, Remainder] = strtok(Remainder, '|');
AllNames=str2mat(AllNames,Name);
end
[NumNames,MaxNameWidth]=size(AllNames);
% Check if sizes is a vector or scaler
if (strcmp(AllNames,'<none>'))
RealSizes=1;
else
for (Ind=1:NumNames)
indices=parsebus(BusName,deblank(AllNames(Ind,:)));
RealSizes(Ind)=length(indices);
end
end
if (length(Sizes) == 1)
if (Sizes)
% if sizes is length 1 and it's not zero, set it equal to RealSizes
Sizes=RealSizes;
else
% if sizes is length 1 and it's zero, leave it alone
end
end
if (length(RealSizes) <= 1 )
% if real sizes is length 1 and greater than 1, or if real sizes is empty,
% set it to 1 mux sizes cannot be set to a "single vector". i.e. size of
% 4 will produce 4 outputs
RealSizes=1;
end
sys=get_param(CurrentBlock,'Parent');
cb=get_param(CurrentBlock,'Name');
% if this is the "muxed" version, don't redraw the outputs
if (findstr('Muxed',BlockType))
% do nothing
else
setnout([sys '/' cb],RealSizes);
end
if (~DrawFlag)
drawstring=strrep(strrep(strrep(BlockType,'(Gui)',''),'(Text)',''),' ','\n');
else
if (all(Sizes))
DisplayString=sprintf(['%' num2str(MaxNameWidth+2) 's[%d]'], ...
deblank(AllNames(1,:)), Sizes(1));
for (Ind=2:NumNames)
DisplayString=[DisplayString, ...
sprintf(['\\n\\n%' num2str(MaxNameWidth+2) 's[%d]'], ...
deblank(AllNames(Ind,:)), Sizes(Ind))];
end
else
DisplayString=sprintf(['%' num2str(MaxNameWidth+2) 's'], ...
deblank(AllNames(1,:)));
for (Ind=2:NumNames)
DisplayString=[DisplayString sprintf(['\\n\\n%' ...
num2str(MaxNameWidth+2) 's'],deblank(AllNames(Ind,:)))];
end
end
drawstring=DisplayString;
end
elseif (findstr('Combine Buses',BlockType))
% BusName - contains the output bus name
% Names - contains the input bus names
% Sizes - contains the sizes flag, currently this is not used
[AllNames, Remainder] = strtok(Names, '|');
while ~isempty(Remainder)
[Name, Remainder] = strtok(Remainder, '|');
AllNames=str2mat(AllNames,Name);
end
[NumNames,MaxNameWidth]=size(AllNames);
sys=get_param(CurrentBlock,'Parent');
cb=get_param(CurrentBlock,'Name');
setnin([sys '/' cb],NumNames);
if (~DrawFlag)
drawstring=strrep(strrep(BlockType,'(Gui)',''),'(Text)','');
drawstring=strrep(drawstring,' ','\n');
else
DisplayString= ...
sprintf(['%-' num2str(MaxNameWidth+3) 's'], deblank(AllNames(1,:)));
if (rem(NumNames,2))
% Odd number of names
for (Ind=2:((NumNames+1)/2-1))
DisplayString=[DisplayString ...
sprintf(['\\n\\n%-' num2str(MaxNameWidth+3) 's'], ...
deblank(AllNames(Ind,:)))];
end
DisplayString=[DisplayString, ...
sprintf(['\\n\\n%s - %s'], ...
deblank(AllNames((NumNames+1)/2,:)),deblank(BusName))];
for (Ind=((NumNames+1)/2)+1:NumNames)
DisplayString=[DisplayString ...
sprintf(['\\n\\n%-' num2str(MaxNameWidth+3) 's'], ...
deblank(AllNames(Ind,:)))];
end
else
% Even number of names
for (Ind=2:(NumNames/2))
DisplayString=[DisplayString ...
sprintf(['\\n\\n%-' num2str(MaxNameWidth+3) 's'], ...
deblank(AllNames(Ind,:)))];
end
DisplayString=[DisplayString ...
sprintf(['\\n\\n%' num2str(MaxNameWidth+3) 's'],deblank(BusName))];
for (Ind=(NumNames/2)+1:NumNames)
DisplayString=[DisplayString ...
sprintf(['\\n\\n%-' num2str(MaxNameWidth+3) 's'], ...
deblank(AllNames(Ind,:)))];
end
end
drawstring=DisplayString;
end
end
set_param(CurrentBlock,'Mask Display',drawstring);
% disp(['Leaving ' mfilename])
% EOF dbcbdraw.m
|
|