function name = getUniqueSignalName(this,port)
% GETUNIQUESIGNALNAME - Gets the unique signal name port a port.  This
% method will search through model to find all the signals of the same name
% and then will search to get a unique block parent.  If there is no signal
% name return the truncated block path.

%  Author(s): John Glass
%  Revised:
% Copyright 1986-2004 The MathWorks, Inc.
% $Revision: 1.1.6.2 $ $Date: 2004/12/26 21:58:25 $

%% Get name of the port
name = get_param(port,'Name');
  
%% If it is empty use a truncated block name
if ~isempty(name)
    %% Get the block name
    block = regexprep(get_param(port,'Parent'),'\n',' ');
    blockname = regexprep(get_param(block,'Name'),'\n',' ');

    %% Find the shortest representation of the name for the block
    block_diagram = this.getModelHandleFromBlock(block);
    ports = find_system(block_diagram.Name,...
        'findall','on',...
        'FollowLinks','on',...
        'LookUnderMasks','all',...
        'type','port',...
        'Name',name);
    %% Get the block parents
    blocks = get_param(ports,'Parent');
    %% Remove the new line and carriage returns in the model/block name
    blocks = regexprep(blocks,'\n',' ');
    %% Make into a cell array if needed
    if ischar(blocks)
        blocks = {blocks};
    end        
    %% Get the index into the blocks list
    blk_ind = find(strcmp(block,blocks));
    %% Tack the signal name to the block name
    for ct = 1:length(blocks)
        blocks{ct} = [blocks{ct},'/',name];
    end
    unblks = uniqname(this,blocks,true);
    name = unblks{blk_ind};   
else
    name = this.getUniqueBlockName(get_param(port,'Parent'));
end
