Skip to content

Commit f78be4a

Browse files
Merge pull request #8 from McSCert/DisableConversion
Close #7 Disable conversion to Simulink Function pre-R2014b
2 parents 88bf28b + 3f1f47e commit f78be4a

11 files changed

+135
-89
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ doc/tex/SimulinkModule_UserGuide.log
44
doc/tex/SimulinkModule_UserGuide.out
55
doc/tex/SimulinkModule_UserGuide.synctex.gz
66
doc/tex/SimulinkModule_UserGuide.toc
7+
*.asv

doc/SimulinkModule_UserGuide.pdf

40 KB
Binary file not shown.

doc/figs/ContextMenu1.png

574 Bytes
Loading

doc/figs/ContextMenu2.png

9.81 KB
Loading

doc/figs/ContextMenu3.png

28.9 KB
Loading

doc/tex/SimulinkModule_UserGuide.tex

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
\ifstrequal{#1}{6}{Print Interface}{}%
4444
\ifstrequal{#1}{7}{Print Dependencies}{}%
4545
\ifstrequal{#1}{8}{Delete Interface}{}%
46+
\ifstrequal{#1}{9}{Convert Subsystem}{}%
4647
}
4748

4849
\newcommand{\func}[1]{%
@@ -181,18 +182,25 @@ \subsection{Getting Started}
181182
\end{itemize}
182183

183184
\noindent
184-
Options available when one or more \simfunc blocks are selected are (Figure~\ref{FIG:simfunc_selected}):
185+
Options available when one or more \simfunc blocks are selected (Figure~\ref{FIG:simfunc_selected}):
185186
\begin{itemize}
186187
\item \emph{\menu{3}} %-- R2017b+
187188
\item \emph{\menu{2}} %-- R2014b+
188189
\end{itemize}
189190

191+
\noindent
192+
Options available when a \subsystem block is selected (Figure~\ref{FIG:subsystem_selected}):
193+
\begin{itemize}
194+
\item \emph{\menu{9}} %-- R2014b+
195+
\end{itemize}
196+
197+
190198
\begin{figure}[!htb]
191199
\centering
192200
\begin{subfigure}[b]{\textwidth}
193201
\centering
194202
\includegraphics[width=0.65\textwidth]{../figs/ContextMenu1}
195-
\caption{Menu options when no functions are selected.}
203+
\caption{Menu options when no \simfunc{s} are selected.}
196204
\label{FIG:none_selected}
197205
\end{subfigure}
198206

@@ -201,9 +209,19 @@ \subsection{Getting Started}
201209
\begin{subfigure}[b]{\textwidth}
202210
\centering
203211
\includegraphics[width=\textwidth]{../figs/ContextMenu2}
204-
\caption{Menu options when one or more functions are selected.}
212+
\caption{Menu options when one or more \simfunc{s} are selected.}
205213
\label{FIG:simfunc_selected}
206214
\end{subfigure}
215+
216+
\vspace{1em}%
217+
218+
\begin{subfigure}[b]{\textwidth}
219+
\centering
220+
\includegraphics[width=.85\textwidth]{../figs/ContextMenu3}
221+
\caption{Menu options when a \subsystem is selected.}
222+
\label{FIG:subsystem_selected}
223+
\end{subfigure}
224+
207225
\caption{Simulink Context Menu with context-dependant tool options visible.}
208226
\label{FIG:contextMenu}
209227
\end{figure}
@@ -291,7 +309,13 @@ \subsubsection{\menu{2}}
291309
\label{fig:demo1}
292310
\end{figure}
293311

294-
\newpage
312+
%-------------------------
313+
\subsubsection{\menu{9}}
314+
%-------------------------
315+
\emph{Note: This option is not available in versions prior to R2014a.}
316+
317+
Right-clicking on a \subsystem and then selecting \cmd{\menu{9}}, and one of the two option from the Context Menu will convert a \subsystem block into a \simfunc. This will prompt the user for a function name, and perform several functions to reconfigure the \subsystem. This includes converting any \inport/\outport blocks to \argin/\argout blocks, adding a \trigger block, and setting various parameters.
318+
295319
%-------------------------
296320
\subsubsection{\menu{4}}
297321
%-------------------------
@@ -435,13 +459,6 @@ \subsubsection{\menu{5} and \menu{6}}
435459
\label{FIG:simulinkinterface}
436460
\end{figure}
437461

438-
\paragraph{Warnings}
439-
\begin{enumerate}
440-
\item This feature is only available for versions R2017b and newer. The Context Menu will have this option disabled for earlier versions. This is because the \emph{function visibility} parameter (\ie scoping) was not introduced for \simfunc{s} until R2017b.
441-
442-
\item If a \simfunc is moved and one or more \simfunccaller{s} with the same prototype exist within its previous scope, a warning will appear in the Command Window. It is recommended that the user ensure all \simfunccaller{s} still correctly call the \simfunc. Automatic updating of \simfunccaller blocks is planned for a future version of this tool.
443-
\end{enumerate}
444-
445462
%-------------------------
446463
\subsubsection{\menu{8}}
447464
%-------------------------
@@ -479,7 +496,13 @@ \subsubsection{\menu{7}}
479496
%---------------------------------------
480497

481498
\subsection{Errors and Warnings}
482-
Any errors or warnings during tool use will be visible in the \matlab Command Window.
499+
Any errors or warnings during tool use will be visible in the \matlab Command Window or as pop-up windows.
500+
501+
\begin{enumerate}
502+
503+
504+
\item If a \simfunc is moved and one or more \simfunccaller{s} with the same prototype exist within its previous scope, a warning will appear in the Command Window. It is recommended that the user ensure all \simfunccaller{s} still correctly call the \simfunc. Automatic updating of \simfunccaller blocks is planned for a future version of this tool.
505+
\end{enumerate}
483506

484507
\subsection{Limitations}
485508
A \Simulink model can depend on or interact with other files and elements via the use of Callbacks\footnote{\url{https://www.mathworks.com/help/simulink/ug/model-callbacks.html}} and S-Functions\footnote{\url{https://www.mathworks.com/help/simulink/sfg/what-is-an-s-function.html}}. Identifying these is not currently supported by the tool.

doc/tex/macros.tex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030

3131
\newcommand{\inport}{\block{Inport}\@\xspace}
3232
\newcommand{\outport}{\block{Outport}\@\xspace}
33+
34+
\newcommand{\argin}{\block{ArgIn}\@\xspace}
35+
\newcommand{\argout}{\block{ArgOut}\@\xspace}
36+
3337
\newcommand{\constant}{\block{Constant}\@\xspace}
3438
\newcommand{\ground}{\block{Ground}\@\xspace}
3539
\newcommand{\subsystem}{\block{Subsystem}\@\xspace}
@@ -42,6 +46,8 @@
4246

4347
\newcommand{\docblock}{\block{DocBlock}\@\xspace}
4448

49+
\newcommand{\trigger}{\block{Trigger}\@\xspace}
50+
4551
\newcommand{\simfunc}{\block{Simulink Function}\@\xspace}
4652
\newcommand{\simfunccaller}{\block{Function Caller}\@\xspace}
4753

src/isGoodSimFcnName.m

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
function goodName = isGoodSimFcnName(subsystem, simulinkFcnName)
2-
% isGoodSimFcnName Checks to see if a Simulink Function name is the
3-
% same as any other Simulink Functions in scope at
4-
% the current subsystem level
5-
% Inputs:
6-
% subsystem Path of a subsystem where a Simulink Function
7-
% will be added
8-
% simulinkFcnName Name of the Simulink Function to be added
2+
% ISGOODSIMFCNNAME Check if a Simulink Function name is the same as any other
3+
% Simulink Functions in scope at the current subsystem level.
94
%
10-
% Outputs:
11-
% goodName Name can be used(1) or not(0)
5+
% Inputs:
6+
% subsystem Path of a subsystem where a Simulink Function will be added.
7+
% simulinkFcnName Name of the Simulink Function to be added.
128
%
13-
% Example:
14-
% isGoodSimFcnName('SubSystem_Name', 'SimFcnName')
9+
% Outputs:
10+
% goodName Whether the name can be used(1) or not(0).
11+
%
12+
% Example:
13+
% isGoodSimFcnName('SubSystem_Name', 'SimFcnName')
1514
%
1615
% ans = 1
1716

src/reqSimFcnName.m

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
function simulinkFcnName = reqSimFcnName()
2-
% getSimFcnName Prompts the user for an input Simulink Function name
3-
% until a name is entered which is not the same as
4-
% another Simulink Function in scope
2+
% REQSIMFCNNAME Prompt the user to input a Simulink Function name until a
3+
% name is entered which is not the same as another Simulink Function in scope.
54
%
6-
% Inputs:
7-
% N/A
5+
% Inputs:
6+
% N/A
87
%
9-
% Outputs:
10-
% simulinkFcnName Char array which represents a Simulink Function name
8+
% Outputs:
9+
% simulinkFcnName Char array representing a Simulink Function name.
1110
%
12-
% Example:
13-
% simulinkFcnName = getSimFcnName()
11+
% Example:
12+
% simulinkFcnName = getSimFcnName()
1413
%
1514
% ans = 'Function_Name'
1615

@@ -24,13 +23,13 @@
2423
% Loop until the input name is acceptable
2524
while 1
2625
inputName = inputdlg(prompt, dlgtitle, dims, definput);
27-
% Checks to see if the name shadows other names in scope
26+
% Check to see if the name shadows other names in scope
2827
if isGoodSimFcnName(gcs, inputName{1})
2928
break
3029
else
3130
waitfor(msgbox([inputName{1}, ...
32-
' is already used as a Simulink Function in scope.', ...
33-
newline, newline, 'Please enter a new name.'], dlgtitle));
31+
' is already used as a Simulink Function in scope.', ...
32+
char(10), 'Please enter a new name.'], dlgtitle));
3433
end
3534
end
3635
simulinkFcnName = inputName{1};

src/sl_customization.m

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ function sl_customization(cm)
88
schemaFcns = {};
99
selection = find_system(gcs, 'Type', 'block', 'Selected', 'on');
1010
selectedFcns = isSimulinkFcn(selection);
11+
12+
% Check if the Simulink version supports Simulink Functions
13+
v = ver('Simulink');
14+
if str2double(v.Version) > 8.3 % Greater than 2014a
15+
verOK = true;
16+
else
17+
verOK = false;
18+
end
1119

1220
if isempty(gcbs)
1321
schemaFcns{end+1} = @FcnCreatorSchema;
1422
schemaFcns{end+1} = @GuidelineSchema;
1523
schemaFcns{end+1} = @InterfaceSchema;
16-
elseif isSubsystem(gcbs) && ~isSimulinkFcn(gcbs) && ~isempty(gcbs)
24+
elseif verOK && isSubsystem(gcbs) && ~isSimulinkFcn(gcbs) && ~isempty(gcbs)
1725
schemaFcns{end+1} = @ConvToSimFcnSchema;
1826
elseif any(selectedFcns) && ~isempty(gcbs)
1927
schemaFcns{end+1} = @ChangeFcnScopeSchema;
@@ -123,9 +131,9 @@ function FcnCreatorCallback(callbackInfo)
123131
scopes = getFcnScope(fcns);
124132

125133
% Show conversion operations depending on scope
126-
anyGlobal = any(contains(scopes, char(Scope.Global)));
127-
anyScoped = any(contains(scopes, char(Scope.Scoped)));
128-
anyLocal = any(contains(scopes, char(Scope.Local)));
134+
anyGlobal = any(contains2(scopes, char(Scope.Global)));
135+
anyScoped = any(contains2(scopes, char(Scope.Scoped)));
136+
anyLocal = any(contains2(scopes, char(Scope.Local)));
129137
if anyScoped || anyLocal
130138
schema.childrenFcns{end+1} = @GlobalFcnSchema;
131139
end

0 commit comments

Comments
 (0)