Simulink添加超链接出现失效的解决方式

给模块添加文字并且添加超链接,再次打开模型出现失效了。

原因是使用HTML方式添加出现失效,给修改成调用函数方式。

如果想给字体添加超链接,或者是字体颜色不能使用Simulink自带的属性,得使用HTML属性,这样会有导致连接失效风险。

可见下列代码添加模型的超链接。

toppaths = gcbp;
bplengths = getLength(toppaths);
blockpath = getBlock(toppaths,bplengths);
cellarray = convertToCell(toppaths);
systems = extractBefore(blockpath,'/');

% systems = inputdlg({'请输入顶层模型的名称:'},'Model Name.',[1 35],{'Top Model'});
% if isempty(systems)
%     systems = gcs;
% else
%     systems=systems{1};
% end
[models,blockpaths]=find_mdlrefs(systems,'AllLevels',0);
inports = find_system(systems,'BlockType','Inport');
pointsX = 1000;
pointsY = 500;
for jj=1:length(inports)
    posit = get_param(inports(jj),'Position');
    if pointsX >= posit{:}(1)
        pointsX = posit{:}(1);
        if pointsY >= posit{:}(2)
            pointsY = posit{:}(2);
        end
    end
end
pointsX=pointsX-500;
pointsX1 = pointsX;
pointsY1 = pointsY;
maxlengts = 0;
for ii=1:length(blockpaths)
    strs = extractAfter(blockpaths(ii),'/');
    bp = ['Simulink.BlockPath([parpath'',{''' blockpaths{ii} '''}])'];

    a = Simulink.Annotation(gcs,strs{:});
    a.UseDisplayTextAsClickCallback='off';
    a.Interpreter = 'rich';
    a.ClickFcn = ['toppaths = gcbp;' newline 'cellarray = convertToCell(toppaths);'...
        newline 'if length(cellarray)>1'...
        newline '  parpath = cellarray(1:end-1);'...
        newline 'else'...
        newline '  parpath = {};'...
        newline 'end'...
        newline 'hilite_system(' bp ',''find'');'];
% 使用调用函数方式可以防止连接失效。
    a.Name = strs{:};
%     a.Text = ['<a href="matlab:hilite_system(' bp ',''find'')' '">' strs{:} '</a>.'];
    numLe = length(strs{:});
    if maxlengts < numLe
        maxlengts=numLe;
    end
    a.MarkupType = 'markup';
    a.FontSize = 28;
    a.Position = [pointsX pointsY pointsX+numLe*9 pointsY + 14];
    pointsY = pointsY + 48;
    clear a
end
pointsY = pointsY + 48;
a= Simulink.Annotation(systems,'RemoveHighlighting');
a.UseDisplayTextAsClickCallback='off';
a.Interpreter = 'rich';

a.ClickFcn = ['SLStudio.Utils.RemoveHighlighting(get_param(''' systems ''',''handle''))'];
a.Name = 'RemoveHighlighting';
% a.Text = ['<a href="matlab:SLStudio.Utils.RemoveHighlighting(get_param(''' systems ''',''handle''))' '">RemoveHighlighting</a>.'];
numLe = length('RemoveHighlighting');
if maxlengts < numLe
    maxlengts=numLe;
end
a.MarkupType = 'markup';
a.FontSize = 28;
a.Position = [pointsX pointsY pointsX+numLe*10 pointsY + 14];

are = add_block('built-in/Area',[systems '/All modules are connected'],'Position',[pointsX1-90,pointsY1-50,pointsX+330+maxlengts,pointsY+50]);
set_param(are,'FontSize','28');

% view(a2)


% % deleteannotation
% h = find_system('Application_SWA_sim','FindAll','on','Type','annotation');
% for pp=1:length(h)
% a = get_param(h(pp),'Object');
% delete(a)
% end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值