function SFLibInstanceHighlighting(blockH)

%Utility function to perform highlighting on the given instance of an SF Library.

%This function performs highlighting for all elements in the chart except
%Simulink-in-Stateflow. Highlighting for Simulink-in-Stateflow
%is performed in cvi.Informer.SFLibInstanceHighlighting_SLinSF (see
%explanation below for reasons for the same)
 
%Explanation of how highlighting works for SF Library Instances:
%Transitions/states in SF library instances point directly to the library items. 
%If multiple library instances are open, and the highlighting is
%changed on one of them, all instances will be updated to the same,
%since in effect you are changing the highlighting on the library directly. 
 
%To overcome this, highlighting on an instance is refreshed everytime it is opened. 
 
%In coverage we have separate cvids per sf library instance incl. all the instance
%children. This utility will be called every time an instance is opened, and
%highlighting for all chart elements in the instance will be refreshed using 
%coverage information in the instance specific cvids.
 
%Simulink-in-Stateflow is implemented differently. All blocks in the SL-in-SF 
%subsystem have their own instances. So it is possible to highlight multiple
%instances of library charts containing Simulink-in-Stateflow simultaneously
%(note we can only highlight the SL-in-SF piece simultaneously). Therefore we
%have the option of performing highlighting for SL-in-SF in all the instances 
%early on (in cvmodelview itself), as opposed to needing to perform it everytime
%the chart instance is opened. For speed, this is what is implemented. 
%Additionally, as of 14a, highlighting of Simulink blocks involves a set_param, 
%and set_param calls are not allowed in slsf blk_open  method (which is what is called when a chart is opened), 
%so the option of highlighting Sl-in-SF when a chart is opened is not possible as of 14a.

[toHighlight, informerObj, sfInstanceStruct] = cvi.Informer.SFLibInstanceHighlightingChecks(blockH);

if ~toHighlight
    return;
end

root = Stateflow.Root;

cvIds = sfInstanceStruct.cvIds;
sfIds = cv('get',cvIds,'.handle');

% Find sf style objects
sfFullCovStyle = sf('find','all','style.name','Full coverage');
sfMissingCovStyle = sf('find','all','style.name','Missing coverage');

%Highlighting color
%Only highlight full/missing coverage. We do not need to worry about grey (filtering color). 
%That is taken care of later

badgeHandler = [];
modelH = get_param(bdroot(blockH), 'handle');
if informerObj.badgeHandlers.isKey(modelH) 
     badgeHandler = informerObj.badgeHandlers(modelH);
end

for idx = 1:length(sfIds)       
    
    if (cv('get', cvIds(idx), '.origin') == 2)
        
        udi = root.idToHandle(sfIds(idx));
        
        if(isa(udi, 'Stateflow.Chart') || isa(udi, 'Stateflow.State') || isa(udi, 'Stateflow.Transition') || isa(udi, 'Stateflow.SLFunction'))
            %make sure this is a Stateflow object that can receive highlighting before using sf('SetAltStyle'

            
            if ~isempty(badgeHandler)
                badgeHandler.addStyleAndBadge(cvIds(idx), [], sfIds(idx), udi, sfInstanceStruct.informerStrings{idx});
            else
                %map informer data
                informerObj.infrmObj.mapData(udi,['<big>' sfInstanceStruct.informerStrings{idx} '</big>']);
            end

            if sfInstanceStruct.isFullCoverage(idx) == 1
                % Apply the full coverage style for stateflow
                sf('SetAltStyle', sfFullCovStyle(1), sfIds(idx));
            elseif sfInstanceStruct.isFullCoverage(idx) == 0
                % Apply the partial coverage style for stateflow
                sf('SetAltStyle', sfMissingCovStyle(1), sfIds(idx));
            elseif sfInstanceStruct.isFullCoverage(idx) == 2
                % Apply the partial coverage style for stateflow
                sf('SetAltStyle', sfJusitifedCovStyle(1), sfIds(idx));
            end

        end
    end
end      


end %end:SFLibHighlighting
        
