function [type, num, sid, isSfun] = getPathAndNumber(blkH, slObj, sfObj)
%

%   Copyright 2011-2023 The MathWorks, Inc.

    if blkH.isStateflow
        if nargin<3
            sfObj = blkH.sfObjID;
        end
        if nargin<2
            slObj = blkH.slBlkH;
        end
    elseif blkH.isSlBlock
        if nargin<2
            slObj = blkH.slBlkH;
        end
    end

    isSfun = false;
    if blkH.isStateflow
        num = blkH.sfObjID;
        type = blkH.typeDesc;
        bd = sfroot;
        SfIsa = sldvshareprivate('util_sfisa');
        if strcmp(blkH.typeDesc, 'Script')
            % ML blocks
            slsid = Simulink.ID.getSID(slObj);
            if strcmp(slsid, 'SimulinkRoot')
                % External ML
                % XXX This gives incorrect colors
                sid = '';
            else
                name = sf('get', sfObj, '.name');
                if ~isempty(name)
                   str = regexp(name, '\.m', 'split');
                   if length(str) == 2 && isempty(str{2})
                       % We will get here in case of Matlab Function blocks
                      sidBlk = regexp(slsid, '::', 'split');
                      sid = sidBlk{1};
                      return;
                   end
                end
                sid = Sldv.DataUtils.getSidForSfObj(sfObj, slObj);
                if isempty(sid)
                    %The handle returned by idToHandle is empty
                    sidChart = sf('get', sfObj, '.ssIdNumber');
                    sidBlk = regexp(slsid, '::', 'split');
                    sid =  strcat(sidBlk{1}, ':', num2str(sidChart));
                end
            end
        elseif blkH.isTruthTableGen
            mappingInfo = sf('get', sfObj, '.autogen.mapping');
            if isfield(mappingInfo, 'index')
                % Stateflow
                sfId = sf('ParentOf', sfObj);
                sidOfSfid = Simulink.ID.getSID(bd.find('Id', sfId));
                
                slBlkSID = Simulink.ID.getSID(slObj);
                blkParent = Simulink.ID.getParent(slBlkSID);
                
                splitSidOfSfid = regexp(sidOfSfid, ':', 'split');
                % In case of non-library TT, sidOfSfid = sid
                % In case of library TT, sidOfSfid depends on the currently
                % selected TT, as sfObj is shared across all the instances 
                % of the truth table. 
                sid = [blkParent ':' splitSidOfSfid{end}];
            else
                % Truth table using MAL
                if sf('get', sfObj, '.isa') ~= SfIsa.chart
                    sfObj = idToHandle(sfroot,sfObj);
                    sid = Simulink.ID.getSID(sfObj);
                else
                    slsid = Simulink.ID.getSID(slObj);
                    sidBlk = regexp(slsid, '::', 'split');
                    sid =  sidBlk{1};
                end
            end
        else
            sid = Sldv.DataUtils.getSidForSfObj(sfObj, slObj);
        end
    elseif blkH.isSlBlock
        num = -1;
        type = '-';
        % For sldv blocks we store the sid of the parent handle.
        newBlkH = sldvprivate('get_sldv_block', slObj);        
        sid = Simulink.ID.getSID(newBlkH);
        if  strcmp(get_param(newBlkH,'type'),'block') ...
                && strcmp(get_param(newBlkH,'BlockType'),'S-Function') ...
                && ( newBlkH ~= slObj ... % sldv blocks
                ||  slprivate('is_stateflow_based_block',get_param(slObj,'Parent'))) % Stateflow
            % Bitwise Operator or other S-function based blocks should not
            % reach here.
            isSfun = true;
            sid = Simulink.ID.getParent(sid);            
        end
    else
        % External MATLAB files from MLSys block
        num = -1;
        type = blkH.typeDesc; % 'Script'
        sid = '';
    end
end
