www.gusucode.com > private工具箱matlab源码程序 > private/get_custom_code_settings.m
function customCodeSettings = get_custom_code_settings(targetId,parentTargetId, notTypingCustomIR) % notTypingCustomIR flag is to see if we are typing custom code. % Because if we do then get_custom_code_settings goes through different % code path if nargin < 3 notTypingCustomIR = true; end % Assumption: parent model and child model have the same targetName relevantTargetId = targetId; targetName = sf('get', targetId, 'target.name'); machineId = sf('get', targetId, 'target.machine'); machineName = sf('get', machineId, 'machine.name'); isLib = sf('get', machineId,'machine.isLibrary'); isRTW = strcmp(targetName, 'rtw'); customCodeSettings.customSourceCode = ''; customCodeSettings.machineId = machineId; customCodeSettings.parseCC = false; % targets other than sfun and rtw: custom target or hdl target if ~isRTW && ~strcmp(targetName, 'sfun') if isLib && ~sf('get',targetId,'.useLocalCustomCodeSettings') relevantTargetId = parentTargetId; end customCodeSettings.relevantTargetId = relevantTargetId; customCodeSettings.customCode = sf('get',relevantTargetId,'target.customCode'); customCodeSettings.customSourceCode = ''; customCodeSettings.userIncludeDirs = sf('get',relevantTargetId,'target.userIncludeDirs'); customCodeSettings.userSources = sf('get',relevantTargetId,'target.userSources'); customCodeSettings.userLibraries = sf('get',relevantTargetId,'target.userLibraries'); customCodeSettings.reservedNames = sf('get',relevantTargetId,'target.reservedNames'); customCodeSettings.customInitializer = sf('get',relevantTargetId,'target.customInitializer'); customCodeSettings.customTerminator = sf('get',relevantTargetId,'target.customTerminator'); return; end cs = getActiveConfigSet(machineName); if isLib % Change the config set to the main model's config set if we need to pull from the main model if isRTW useMainModelSettings = strcmp(get_param(cs, 'RTWUseLocalCustomCode'), 'off'); else useMainModelSettings = strcmp(get_param(cs, 'SimUseLocalCustomCode'), 'off'); end if useMainModelSettings relevantTargetId = parentTargetId; machineId = sf('get', parentTargetId, 'target.machine'); cs = getActiveConfigSet(sf('get', machineId, 'machine.name')); customCodeSettings.machineId = machineId; end end customCodeSettings.relevantTargetId = relevantTargetId; % ISSUE: Note that the SimParseCustomCode flag is not visible on libraries. % Ideally, we should get rid of the custom code settings on libraries. If not, % then we should at least replicate this flag on the library configset as well. % Additionally, the RTW custom code panel should also have an identical flag. % Note that we are currently pulling the custom code from the appropriate configset. % If a library is set to pull from the local configset, then this probably means % that the user has no visual means to set the parse custom code flag. customCodeSettings.parseCC = strcmp(get_param(cs, 'SimParseCustomCode'), 'on'); useRTWCustomCodePanel = strcmp(get_param(cs, 'RTWUseSimCustomCode'), 'off'); % Return an empty customCodeSettings in following cases: % 1) if we are generating RTW code for non-lib charts and we are not trying % to TYPE custom code % 2) if we are generating RTW code for lib charts but the chart is set to use % main machine's custom code settings if isRTW && notTypingCustomIR && (~isLib || useMainModelSettings) customCodeSettings.customCode = ''; customCodeSettings.customSourceCode = ''; customCodeSettings.userIncludeDirs = ''; customCodeSettings.userSources = ''; customCodeSettings.userLibraries = ''; customCodeSettings.reservedNames = ''; customCodeSettings.customInitializer = ''; customCodeSettings.customTerminator = ''; elseif isRTW && useRTWCustomCodePanel customCodeSettings.customCode = get_param(cs, 'CustomHeaderCode'); customCodeSettings.customSourceCode = get_param(cs, 'CustomSourceCode'); customCodeSettings.userIncludeDirs = get_param(cs, 'CustomInclude'); customCodeSettings.userSources = get_param(cs, 'CustomSource'); customCodeSettings.userLibraries = get_param(cs, 'CustomLibrary'); customCodeSettings.reservedNames = get_param(cs, 'ReservedNames'); customCodeSettings.customInitializer = get_param(cs, 'CustomInitializer'); customCodeSettings.customTerminator = get_param(cs, 'CustomTerminator'); else % sfun target if (slfeature('LegacyCodeIntegration') == 1) [customCodeSettings, ~] = legacycode.util.lci_getSettings(machineName, false); customCodeSettings.relevantTargetId = relevantTargetId; customCodeSettings.machineId = machineId; customCodeSettings.parseCC = strcmp(get_param(cs, 'SimParseCustomCode'), 'on'); else customCodeSettings.customCode = get_param(cs, 'SimCustomHeaderCode'); customCodeSettings.customSourceCode = get_param(cs, 'SimCustomSourceCode'); customCodeSettings.userIncludeDirs = get_param(cs, 'SimUserIncludeDirs'); customCodeSettings.userSources = get_param(cs, 'SimUserSources'); customCodeSettings.userLibraries = get_param(cs, 'SimUserLibraries'); customCodeSettings.customCompilerFlags = get_param(cs, 'SimCustomCompilerFlags'); customCodeSettings.customLinkerFlags = get_param(cs, 'SimCustomLinkerFlags'); customCodeSettings.reservedNames = get_param(cs, 'SimReservedNames'); customCodeSettings.customInitializer = get_param(cs, 'SimCustomInitializer'); customCodeSettings.customTerminator = get_param(cs, 'SimCustomTerminator'); end end