Clear Filters
Clear Filters

how can i fix the check in Model Advisor ? (very urgent)

3 views (last 30 days)

hello guys , I managed to integrate the verification with the model advisor, but I wonder how I can correct the error from the window of model Advisor ? pleaaase help me it's very urgennnttt !!!!! here's the script i made : function sl_customization(cm) %------ definir la règle -----

%----- where checks are added (location : by Product)--------

cm.addModelAdvisorCheckFcn(@defineModelAdvisorChecks);

 %----- where checks are added (location : by Task)--------

% cm.addModelAdvisorTaskAdvisorFcn(@defineTaskAdvisor);

% ----- where checks are added ( location : My group) ----- % cm.addModelAdvisorTaskFcn(@defineModelAdvisorTasks);

function defineModelAdvisorChecks % --- Get handle to model advisor object mdladvRoot = ModelAdvisor.Root; %------ publier la règle ---- rec = ModelAdvisor.Check('DetectiondesEspaces'); %----- rec : var utilisé pour définir la règle d'interface ----- rec.Title = 'Check_des_Spaces '; %---- The Title : le texte nommant la règle dans Model Advisor ---- rec.TitleTips = 'added check_spaces'; %------ The TitleTips : est le texte qui montre la boîte de dialogue de vérification ----- rec.setCallbackFcn(@SimpleCallback,'None','StyleOne'); %----- setCallbackFcn : définit le nom de la fonction, le contexte et le style de vérification------ rec.setCallbackFcn(@SampleCallback,'None','StyleOne');

% --- input parameters rec.setInputParametersLayoutGrid([1 1]); %---- définit le nombre de lignes et de colonnes disponibles pour les paramètres d'entrée---- inputParam1 = ModelAdvisor.InputParameter; % ---- créer une handle object pour définir l'entrée ---- inputParam1.Name = 'checkSpaces'; % --- Name: texte de l'entrée ----- inputParam1.Value=' ';% ----- Value: La valeur par défaut de l'entrée --- inputParam1.Type='String'; % ---- type de l'entrée ---- inputParam1.Description='sample tooltip'; % ---- Description: The tool tip pour l'entrée---- inputParam1.setRowSpan([1 1]); % ---- setRowSpan: La position horizontale de l'entrée dans [start row, end row] ------ inputParam1.setColSpan([1 1]); % ----- setColSpan: L'emplacement vertical de l'entrée dans [start col, end col] ---- rec.setInputParameters({inputParam1}); % ----- setInputParameters: ajoute les informations de paramètre d'entrée à rec handle --

% ----- set fix operation ----- myAction = ModelAdvisor.Action; % ModelAdvisor.Action: The action function is used fix errors---- %myAction.setCallbackFcn(@SimpleActionCallback); %--- setCallbackFcn: ----- Définit le nom de la fonction appelée lorsque le bouton Action est enfoncé----- myAction.setCallbackFcn(@SampleActionCallback); %--- setCallbackFcn: ----- Définit le nom de la fonction appelée lorsque le bouton Action est enfoncé----- myAction.Name = ' Fix spaces'; %----- Name:Le texte sur le bouton de rappel

myAction.Description = 'Click the button to update all spaces '; % ------ Descriptn: Le texte décrivant l'action ------

rec.setAction(myAction); % ----- setAction: Ajouter les informations d'action au rec ----- rec.ListViewVisible = true; %---- Afficher / masquer le bouton d'exploration des résultats ----- mdladvRoot.publish(rec,'Demo'); %---- ajouter les règles au model advisor group dans le fichier "Demo"-----

%--- SimpleCallback function that checks the Spaces(inport) ---- function result = SimpleCallback(system) mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system); result = {};

inport = find_system(bdroot,'BlockType','Inport'); espaces_Inp=''; for i=1:length(inport) x=get_param(inport{i},'Name'); for j=1: length(x) if strcmp(x(j),' ')==1 espaces_Inp=[espaces_Inp inport(i)]; end end end espaces_Inp=espaces_Inp'

DetectionEspaces; ft = ModelAdvisor.FormatTemplate ('ListTemplate'); ft.setInformation(['detect spaces ']);

if ~isempty(espaces_Inp) ft.setSubResultStatusText(['Check has failed.']); ft.setListObj(espaces_Inp); ft.setSubResultStatus('warn'); ft.setRecAction('Parameterise the spaces'); mdladvObj.setCheckResultStatus(false); mdladvObj.setActionEnable(true); else ft.setSubResultStatusText(['check had passed .No spaces detected.']); ft.setSubResultStatus('pass'); mdladvObj.setCheckResultStatus(true); end ft.setSubBar(0); result{end+1}=ft;

%--- SimpleCallback function that check spaces (outport)---- function result = SampleCallback(system) mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system); result = {};

outport = find_system(bdroot,'BlockType','Outport'); espaces_Out=''; for i=1:length(outport) x=get_param(outport{i},'Name'); for j=1: length(x) if strcmp(x(j),' ')==1 espaces_Out=[espaces_Out outport(i)]; end end end espaces_Out=espaces_Out'

DetectionEspaces; ft = ModelAdvisor.FormatTemplate ('ListTemplate'); ft.setInformation(['detect spaces ']);

if ~isempty(espaces_Out) ft.setSubResultStatusText(['Check has failed.']); ft.setListObj(espaces_Out); ft.setSubResultStatus('warn'); ft.setRecAction('Parameterise the spaces'); mdladvObj.setCheckResultStatus(false); mdladvObj.setActionEnable(true); else ft.setSubResultStatusText(['check had passed .No spaces detected.']); ft.setSubResultStatus('pass'); mdladvObj.setCheckResultStatus(true); end ft.setSubBar(0); result{end+1}=ft; % %

% % % --- SimpleCallback function that fixes failed check ----

function result = SampleActionCallback(taskobj) mdladvObj = taskobj.MAObj; result = {}; system = getfullname(mdladvObj.System);

% Get the string from the input parameter box. inputParams = mdladvObj.getInputParameters; textEntryEx = inputParams{1}.Value; %----- in ----- inport = find_system(system,'BlockType','Inport'); espaces_Inp=''; for i=1:length(inport) x=get_param(inport{i},'Name'); for j=1: length(x) if strcmp(x(j),' ')==1 espaces_Inp=[espaces_Inp inport(i)]; end end end espaces_Inp=espaces_Inp'

ft = ModelAdvisor.FormatTemplate('TableTemplate'); % Define table col titles ft.setColTitles({'Block','space_detected','No_space'}) for inx=1:size(espaces_Inp) spacedetected = get_param(espaces_Inp{inx},'Name'); ft.addRow({espaces_Inp{inx},spacedetected,textEntryEx}); set_param(espaces_Inp{inx},'Name',textEntryEx); end

ft.setSubBar(0); result = ft; mdladvObj.setActionEnable(false);

%------- out------ outport = find_system(bdroot,'BlockType','Outport'); espaces_Out=''; for i=1:length(outport) x=get_param(outport{i},'Name'); for j=1: length(x) if strcmp(x(j),' ')==1 espaces_Out=[espaces_Out outport(i)]; end end end espaces_Out=espaces_Out'

ft = ModelAdvisor.FormatTemplate('TableTemplate'); % Define table col titles ft.setColTitles({'Block','space_detected','No_space'}) for inx=1:size(espaces_Out) spacedetected = get_param(espaces_Out{inx},'Name'); ft.addRow({espaces_Out{inx},spacedetected,textEntryEx}); set_param(espaces_Out{inx},'Name',textEntryEx); end

ft.setSubBar(0); result = ft; mdladvObj.setActionEnable(false);

  1 Comment
Image Analyst
Image Analyst on 28 Mar 2018
Because your code was not formatted correctly it ended up in the spam bucket. I rescued it from there, but please read this http://www.mathworks.com/matlabcentral/answers/13205#answer_18099 so it doesn't end up there again where no one will see it.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!