www.gusucode.com > sldv工具箱matlab源码程序 > sldv/sldv/private/configcomp_attach.m

    function configcomp_attach(modelH,subsystemH)

% Copyright 2006-2015 The MathWorks, Inc.

narginchk(1,2);

if nargin<2
    subsystemH = [];
end

mdlObj = bdroot(modelH);
if strcmp(get_param(mdlObj, 'BlockDiagramType'), 'library')
     warning(message('Sldv:configcomp_attach:InvalidMDLObj'));
    return;
end

%
% Get Active Configurations sets associated with this model. We then check
% if any of the active configuration sets contains an slavtcc object before
% attaching to a model.
%
[slavtcc,configSet,configSetRefVarName] = configcomp_get(modelH);

% Attach the slavtcc to the current configuration set.
if strcmp(get_param(modelH, 'SimulationStatus'), 'stopped')
    if ~isa(slavtcc,'Sldv.ConfigComp'),
        slavtexist = license('test','Simulink_Design_Verifier') && exist('slavteng','file')==3;
        if slavtexist==0
            warning(message('Sldv:configcomp_attach:NoSLDV'));
            return;
        else
            if ~isempty(configSetRefVarName)                
                if isempty(subsystemH)
                    toBeAnalyzedComponent = sprintf('model ''%s''',get_param(modelH,'Name'));
                else
                    toBeAnalyzedComponent = sprintf('subsystem ''%s''',getfullname(subsystemH));
                end
                str = getString(message('Sldv:configcomp_attach:ModelReferencesA',get_param(modelH,'Name'),configSetRefVarName,toBeAnalyzedComponent,configSetRefVarName));
                answer = questdlg(str, getString(message('Sldv:configcomp_attach:ModelReferencesConfigurationSet')),'Yes','No','No');
                if strcmp(answer,'No')
                    % if not open dialog, release the data dictionary
                    % connection
                    csdd = configset.util.ConfigSetDialogSourceManager.getInstance;
                    csdd.clean;
                    return;                    
                end
            end            
            slavtcc = Sldv.ConfigComp(subsystemH);  
            
            %% BACKGROUND
            % In R2014b we introduced new flag DetectActiveLogic for Quick Dead Logic.
            % If DetectDeadLogic and DetectActiveLogic is both checked then we
            % perform Regular version of dead logic. If only DetectDeadLogic is on then
            % Quick version of dead logic detection runs. 

            %% PROBLEM:
            % From 2014b Quick Dead Logic detection is made default technique 
            % to detect dead logic. But making Quick Dead Logic default 
            % affects compatibility for older models before 2014b which expect 
            % regular dead logic to run by default. 
            
            %% SOLUTION
            % 1. Keep the default value of option DetectActiveLogic 'on' for
            %    compatibility issue. 
            % 2. If model does not have SLDV config set attached 
            %    then the flip the value of 'DetectActiveLogic' to 'off' 
            %    before attaching new config set to it. 
            % 3. When we get default option using Sldv.Options(), again flip
            %    the value of 'DetectActiveLogic' to 'off', to ensure new
            %    options created will have DetectActiveLogic 'off' in default.
            
            slavtcc.DVDetectActiveLogic = 'off';
            
            attachComponent(configSet, slavtcc);           
        end
    end
end