www.gusucode.com > sldoguis工具箱matlab源码程序 > sldoguis/+sldodialogs/+sensitivityanalysis/@ModelGoalSection/ModelGoalSection.m
classdef ModelGoalSection < sldodialogs.absView % % Copyright 2014-2015 The MathWorks, Inc. methods(Access = public) function obj = ModelGoalSection(data) %MODELGOALSECTION Construct ModelGoalSection object % % obj = ModelGoalSection(data) % %Call parent constructor obj = obj@sldodialogs.absView(data); %Construct the Section widgets build(obj); %Initialize the section initialize(obj); end end methods(Access = private) function build(this) %BUILD Construct the section widgets % % New Requirement button file = fullfile(sldodialogs.getIconResourcePath('sldodialogs'), 'Requirement_Add_24.png'); btnNewReq = toolpack.component.TSDropDownButton(... getString(message('sldo:dialogs:lblModelGoal_NewRequirement')), ... toolpack.component.Icon(file)); btnNewReq.Orientation = toolpack.component.ButtonOrientation.VERTICAL; btnNewReq.Name = 'btnNewReq'; btnNewReq.Description = getString(message('sldo:dialogs:lblModelGoal_NewRequirement_Description')); btnNewReq.Popup = createNewRequirementMenu(this); % Select Model Goals (Experiments/Requirements) button file = fullfile(sldodialogs.getIconResourcePath('sldodialogs'),'Requirement_24.png'); btnSelect = toolpack.component.TSButton(... getString(message('sldo:dialogs:lblModelGoalSelect')), ... toolpack.component.Icon(file)); btnSelect.Orientation = toolpack.component.ButtonOrientation.VERTICAL; btnSelect.Name = 'btnSelect'; btnSelect.Description = getString(message('sldo:dialogs:lblModelGoalSelect_Description')); %Store widgets for easy access this.Widgets = [... btnNewReq, ... btnSelect ... ]; %Layout the options widgets on a panel pnlOpt = toolpack.component.TSPanel(... 'f:p, 2dlu, f:p', ... %2 columns 'f:p'); %1 row pnlOpt.Name = 'pnlOptions'; pnlOpt.add(btnNewReq, 'rc(1,1)'); pnlOpt.add(btnSelect, 'rc(1,3)'); %Create tool-strip sections and add panels this.TPComponent = toolpack.desktop.ToolSection('secModelGoals', ... getString(message('sldo:dialogs:lblModelGoals'))); add(this.TPComponent, pnlOpt); end function mnu = createNewRequirementMenu(this) %CREATENEWREQUIREMENTMENU Create new requirement drop down items % %Menus for requirements if sldodialogs.data.isSCDInstalled items = struct(... 'Name', '', ... 'Title', getString(message('sldo:dialogs:lblMenuNewRequirement_Time')), ... 'Description', '', ... 'Tip', '', ... 'Icon', [], ... 'Help', [], ... 'Header', true); else items = struct(... 'Name', '', ... 'Title', getString(message('sldo:dialogs:lblMenuNewRequirement')), ... 'Description', '', ... 'Tip', '', ... 'Icon', [], ... 'Help', [], ... 'Header', true); end %Add Experiment item items = [items ; struct(... 'Name', 'mnuNewExperiment', ... 'Title', getString(message('sldo:dialogs:lblSignalMatching')), ... 'Description', getString(message('sldo:dialogs:lblExperiment_Description')), ... 'Tip', '', ... 'Icon', toolpack.component.Icon(fullfile(sldodialogs.getIconResourcePath('sldodialogs'),'SelectExperiments_24px.png')), ... 'Help', [], ... 'Header', false) ]; allReq = this.getRequirementList('time'); for ct=1:size(allReq,1) items = [items; struct(... 'Name', allReq{ct,1}, ... 'Title', allReq{ct,2}, ... 'Description', allReq{ct,4}, ... 'Tip', '', ... 'Icon', toolpack.component.Icon(allReq{ct,3}), ... 'Help', [], ... 'Header', false)]; end if sldodialogs.data.isSCDInstalled items = [items; struct(... 'Name', '', ... 'Title', getString(message('sldo:dialogs:lblMenuNewRequirement_Frequency')), ... 'Description', '', ... 'Tip', '', ... 'Icon', [], ... 'Help', [], ... 'Header', true)]; allReq = this.getRequirementList('frequency'); for ct=1:size(allReq,1) items = [items; struct(... 'Name', allReq{ct,1}, ... 'Title', allReq{ct,2}, ... 'Description', allReq{ct,4}, ... 'Tip', '', ... 'Icon', toolpack.component.Icon(allReq{ct,3}), ... 'Help', [], ... 'Header', false)]; end end %Create a menu from the items mnu = toolpack.component.TSDropDownPopup(items); mnu.Name = 'mnuNewGoal'; end function cbNewExperiment(this, btn) %CBNEWEXPERIMENT Manage btnNewExperiment events % %Add a blank experiment to the workspace, and mark the %experiment as selected for estimation/evaluation newExp = sldodialogs.parameterestimation.ExperimentSection.createExperiment(getModelName(this.Data)); wksp = getWorkspace(this.Data, 'local'); name = matlab.lang.makeUniqueStrings('SignalMatching', who(wksp)); assignin(wksp, name, newExp); this.Data.LocalExperiments(end).SelectedForEstimation = true; %Create an editor dialog for the new experiment, and add it to %the dialog manager dm = getToolData(getDesignOptimizationData(this.Data), 'DialogManager'); tc = sldodialogs.ExperimentEditorTC(name, wksp, dm); gc = createView(tc); %Configure experiment editor for sensitivity analysis setShowParameters(gc,false); %Disable/hide parameters section of experiment editor labels = struct(... 'Title', getString(message('sldo:dialogs:lblSignalMatching_Edit')), ... 'InputsEmpty', getString(message('sldo:dialogs:lblSignalMatching_NoInputs')),... 'InputsInstruction', getString(message('sldo:dialogs:lblSignalMatching_InputsInstruction')),... 'OutputsEmpty', getString(message('sldo:dialogs:lblSignalMatching_NoOutputs')),... 'OutputsInstruction', getString(message('sldo:dialogs:lblSignalMatching_OutputsInstruction')),... 'StatesEmpty', getString(message('sldo:dialogs:lblSignalMatching_NoStates')),... 'StatesInstruction', getString(message('sldo:dialogs:lblSignalMatching_StatesInstruction')),... 'ParametersEmpty', getString(message('sldo:dialogs:lblSignalMatching_NoParameters')),... 'ParametersInstruction', getString(message('sldo:dialogs:lblSignalMatching_ParametersInstruction')),... 'DeleteSignal', getString(message('sldo:dialogs:lblSignalMatching_DeleteSignal'))); setLabels(gc,labels) setHelpData(gc,fullfile(docroot,'toolbox','sldo','sldo.map'),'sensitivity_edit_experiment') %Open the dialog addDialog(dm, gc); show(gc, btn, true); %Hilight new variable grp = sldodialogs.ToolManager.getInstance(getModelName(this.Data), ... getToolType(this.Data)); hiliteVariable(grp, wksp, name); end function cbMenuNewRequirement(this, hSrc, hBtn) %CBMENUNEWREQUIREMENT Manage New Requirement menu events % item = hSrc.Items(hSrc.SelectedIndex); selectedItem = item.Name; %Handle experiments/signal matching requirements separately if strcmp(selectedItem,'mnuNewExperiment') cbNewExperiment(this,hBtn) return end %Parse out requirement class and source idx = regexp(selectedItem,'\$'); clsReq = selectedItem(1:idx-1); clsSrc = selectedItem(idx+1:end); if strcmp(clsReq,'sdo.requirements.Custom') %Special case for custom clsSrc = 'all'; end %Create source selector for source class type wksp = getWorkspace(this.Data, 'local'); switch clsSrc case 'Simulink.SimulationData.Signal' %Time domain requirement, create source component to %select signals. srcTC = sldodialogs.SelectSignalDialogTC(getModelName(this.Data),wksp); HelpData = struct(... 'MapFile', [docroot '/toolbox/sldo/sldo.map'], ... 'TopicID', 'sa_selecting_signals_to_bound'); case 'linearize.IOPoint' %Frequency domain requirement, create source component %to select Linearization IOs srcTC = sldodialogs.SelectLinIODialogTC(getModelName(this.Data),wksp); HelpData = struct(... 'MapFile', [docroot '/toolbox/sldo/sldo.map'], ... 'TopicID', 'io_creator'); case 'all' %Requirement can be both time and/or frequency domain, %create generic source editor if sldodialogs.data.isSCDInstalled srcTC = sldodialogs.SelectSourceDialogTC(getModelName(this.Data),wksp); HelpData.MapFile = [docroot '/toolbox/sldo/sldo.map']; HelpData.TopicID = {... 'sa_selecting_signals_to_bound', ... 'io_creator'}; else srcTC = sldodialogs.SelectSignalDialogTC(getModelName(this.Data),wksp); HelpData = struct(... 'MapFile', [docroot '/toolbox/sldo/sldo.map'], ... 'TopicID', 'sa_selecting_signals_to_bound'); end end %Create dialog for requirement/source combo goalName = sldodialogs.responseoptimization.RequirementSection.createReqVariableName(clsReq,wksp); % Create the requirement and assign in workspace hGoal = eval(clsReq); wksp = getWorkspace(this.Data, 'local'); name = matlab.lang.makeUniqueStrings(goalName, who(wksp)); assignin(wksp, name, hGoal); % Configure the requirement, keeping track of sources, % requirements, and whether it is to be evaluated data = struct(... 'Requirement', goalName, ... 'hReq', hGoal, ... 'Source', {{}} ); data.Selected = true; addConfiguredRequirement(this.Data, data) % Highlight variable in data browser grp = sldodialogs.ToolManager.getInstance(getModelName(this.Data), ... getToolType(this.Data)); hiliteVariable(grp, wksp, goalName) % Add the dialog for the requirement, using dialog manager dm = getToolData(getDesignOptimizationData(this.Data), 'DialogManager'); gc = createView(sldodialogs.responseoptimization.CreateRequirementDialogTC(... goalName, ... wksp, ... hGoal, ... srcTC)); [lblReq, lblSrc] = sldodialogs.responseoptimization.RequirementSection.getCreateReqLabels(clsReq,clsSrc); gc.ReqSectionLabel = lblReq; gc.SrcSectionLabel = lblSrc; setHelpData(getSourceGC(gc),HelpData.MapFile,HelpData.TopicID); %Install listener for when Source selector widget changes %as we'll need to update requirement-source connection %information addlistener(srcTC,'ComponentChanged',@(hSrc,hData) cbSrcChanged(this,hSrc,goalName)); % Show requirement editor dialog, and add requirement editor % to dialog manager show(gc, hBtn, true); addDialog(dm, gc); end function cbDeleteNewRequirementDialog(this,dlg) %CBDELETENEWREQUIREMENTDIALOG Manage New Requirement Dialog deletion events % if isvalid(this) idx = this.dlgNewRequirement == dlg; this.dlgNewRequirement(idx) = []; end end function cbSrcChanged(this,hSrc,Req) %CBSRCCHANGED % ssig = getSelectedSources(hSrc); if isvalid(this.Data) data = this.Data.LocalRequirements; idx = strcmp({data.Requirement},Req); if any(idx) data(idx).Source = ssig; this.Data.LocalRequirements = data; end end end function initialize(this) %INITIALIZE Configure the section widgets % %Install listener for New Requirement events btnNewReq = getWidget(this,'btnNewReq'); addlistener(btnNewReq.Popup, 'ListItemSelected', ... @(hSrc,hData) cbMenuNewRequirement(this, hSrc, btnNewReq)); %Install listener for Edit Goal events, populating menu btnSelect = getWidget(this,'btnSelect'); addlistener(btnSelect,'ActionPerformed', @(hSrc,hData) cbSelect(this)); end function cbSelect(this) %CBSELECT Manage events for Selecting goals % dm = getToolData(getDesignOptimizationData(this.Data),'DialogManager'); ct = 1; hDlg = []; while isempty(hDlg) && ct <= numel(dm.Dialogs) if isa(dm.Dialogs{ct},'sldodialogs.sensitivityanalysis.SelectGoalsDialogGC') %Should only ever be one 'sldodialogs.sensitivityanalysis.SelectGoalsDialogGC' hDlg = dm.Dialogs{ct}; else ct = ct+1; end end if isempty(hDlg) tc = sldodialogs.sensitivityanalysis.SelectGoalsDialogTC(this.Data); hDlg = createView(tc); dm = getToolData(getDesignOptimizationData(this.Data),'DialogManager'); addDialog(dm,hDlg); end update(getPeer(hDlg)); show(hDlg,getWidget(this,'btnSelect'),true); end end methods(Static = true, Access = private) function supportedReq = getRequirementList(dType) %GETREQUIREMENTLIST List of supported design requirements % % Static method to return list of design requirements % supported by the SDO GUI % switch dType case 'frequency' sType = 'linearize.IOPoint'; allReq = sldodialogs.responseoptimization.RequirementSection.getFrequencyDomainReq; case 'time' sType = 'Simulink.SimulationData.Signal'; allReq = sldodialogs.responseoptimization.RequirementSection.getTimeDomainReq; otherwise error(message('sldo:general:errUnexpected',sprintf('Unsupported requirement domain type - %s',dType))); end supportedReq = cell(numel(allReq),4); for ct = 1:size(supportedReq,1) dispData = sldodialogs.responseoptimization.RequirementSection.getRequirementOverviewDescription(allReq{ct},dType); supportedReq(ct,2:end) = {... getString(message(dispData{1})), ... dispData{2}, ... getString(message(dispData{3}))}; if strcmp(allReq{ct},'sdo.requirements.SignalTracking') %Customise tracking requirement description for sensitivity %analysis supportedReq{ct,4} = getString(message('sldo:dialogs:lblSignalTrackingDescriptionSA')); end end supportedReq(:,1) = strcat(allReq(:),'$',sType); end end end