Skip to content

Commit

Permalink
Merge pull request #8 from McSCert/DisableConversion
Browse files Browse the repository at this point in the history
Close #7 Disable conversion to Simulink Function pre-R2014b
  • Loading branch information
monikajaskolka committed Sep 17, 2020
2 parents 88bf28b + 3f1f47e commit f78be4a
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 89 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ doc/tex/SimulinkModule_UserGuide.log
doc/tex/SimulinkModule_UserGuide.out
doc/tex/SimulinkModule_UserGuide.synctex.gz
doc/tex/SimulinkModule_UserGuide.toc
*.asv
Binary file modified doc/SimulinkModule_UserGuide.pdf
Binary file not shown.
Binary file modified doc/figs/ContextMenu1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/figs/ContextMenu2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/figs/ContextMenu3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 35 additions & 12 deletions doc/tex/SimulinkModule_UserGuide.tex
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
\ifstrequal{#1}{6}{Print Interface}{}%
\ifstrequal{#1}{7}{Print Dependencies}{}%
\ifstrequal{#1}{8}{Delete Interface}{}%
\ifstrequal{#1}{9}{Convert Subsystem}{}%
}

\newcommand{\func}[1]{%
Expand Down Expand Up @@ -181,18 +182,25 @@ \subsection{Getting Started}
\end{itemize}

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

\noindent
Options available when a \subsystem block is selected (Figure~\ref{FIG:subsystem_selected}):
\begin{itemize}
\item \emph{\menu{9}} %-- R2014b+
\end{itemize}


\begin{figure}[!htb]
\centering
\begin{subfigure}[b]{\textwidth}
\centering
\includegraphics[width=0.65\textwidth]{../figs/ContextMenu1}
\caption{Menu options when no functions are selected.}
\caption{Menu options when no \simfunc{s} are selected.}
\label{FIG:none_selected}
\end{subfigure}

Expand All @@ -201,9 +209,19 @@ \subsection{Getting Started}
\begin{subfigure}[b]{\textwidth}
\centering
\includegraphics[width=\textwidth]{../figs/ContextMenu2}
\caption{Menu options when one or more functions are selected.}
\caption{Menu options when one or more \simfunc{s} are selected.}
\label{FIG:simfunc_selected}
\end{subfigure}

\vspace{1em}%

\begin{subfigure}[b]{\textwidth}
\centering
\includegraphics[width=.85\textwidth]{../figs/ContextMenu3}
\caption{Menu options when a \subsystem is selected.}
\label{FIG:subsystem_selected}
\end{subfigure}

\caption{Simulink Context Menu with context-dependant tool options visible.}
\label{FIG:contextMenu}
\end{figure}
Expand Down Expand Up @@ -291,7 +309,13 @@ \subsubsection{\menu{2}}
\label{fig:demo1}
\end{figure}

\newpage
%-------------------------
\subsubsection{\menu{9}}
%-------------------------
\emph{Note: This option is not available in versions prior to R2014a.}

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.

%-------------------------
\subsubsection{\menu{4}}
%-------------------------
Expand Down Expand Up @@ -435,13 +459,6 @@ \subsubsection{\menu{5} and \menu{6}}
\label{FIG:simulinkinterface}
\end{figure}

\paragraph{Warnings}
\begin{enumerate}
\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.

\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.
\end{enumerate}

%-------------------------
\subsubsection{\menu{8}}
%-------------------------
Expand Down Expand Up @@ -479,7 +496,13 @@ \subsubsection{\menu{7}}
%---------------------------------------

\subsection{Errors and Warnings}
Any errors or warnings during tool use will be visible in the \matlab Command Window.
Any errors or warnings during tool use will be visible in the \matlab Command Window or as pop-up windows.

\begin{enumerate}


\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.
\end{enumerate}

\subsection{Limitations}
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.
Expand Down
6 changes: 6 additions & 0 deletions doc/tex/macros.tex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

\newcommand{\inport}{\block{Inport}\@\xspace}
\newcommand{\outport}{\block{Outport}\@\xspace}

\newcommand{\argin}{\block{ArgIn}\@\xspace}
\newcommand{\argout}{\block{ArgOut}\@\xspace}

\newcommand{\constant}{\block{Constant}\@\xspace}
\newcommand{\ground}{\block{Ground}\@\xspace}
\newcommand{\subsystem}{\block{Subsystem}\@\xspace}
Expand All @@ -42,6 +46,8 @@

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

\newcommand{\trigger}{\block{Trigger}\@\xspace}

\newcommand{\simfunc}{\block{Simulink Function}\@\xspace}
\newcommand{\simfunccaller}{\block{Function Caller}\@\xspace}

Expand Down
21 changes: 10 additions & 11 deletions src/isGoodSimFcnName.m
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
function goodName = isGoodSimFcnName(subsystem, simulinkFcnName)
% isGoodSimFcnName Checks to see if a Simulink Function name is the
% same as any other Simulink Functions in scope at
% the current subsystem level
% Inputs:
% subsystem Path of a subsystem where a Simulink Function
% will be added
% simulinkFcnName Name of the Simulink Function to be added
% ISGOODSIMFCNNAME Check if a Simulink Function name is the same as any other
% Simulink Functions in scope at the current subsystem level.
%
% Outputs:
% goodName Name can be used(1) or not(0)
% Inputs:
% subsystem Path of a subsystem where a Simulink Function will be added.
% simulinkFcnName Name of the Simulink Function to be added.
%
% Example:
% isGoodSimFcnName('SubSystem_Name', 'SimFcnName')
% Outputs:
% goodName Whether the name can be used(1) or not(0).
%
% Example:
% isGoodSimFcnName('SubSystem_Name', 'SimFcnName')
%
% ans = 1

Expand Down
23 changes: 11 additions & 12 deletions src/reqSimFcnName.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
function simulinkFcnName = reqSimFcnName()
% getSimFcnName Prompts the user for an input Simulink Function name
% until a name is entered which is not the same as
% another Simulink Function in scope
% REQSIMFCNNAME Prompt the user to input a Simulink Function name until a
% name is entered which is not the same as another Simulink Function in scope.
%
% Inputs:
% N/A
% Inputs:
% N/A
%
% Outputs:
% simulinkFcnName Char array which represents a Simulink Function name
% Outputs:
% simulinkFcnName Char array representing a Simulink Function name.
%
% Example:
% simulinkFcnName = getSimFcnName()
% Example:
% simulinkFcnName = getSimFcnName()
%
% ans = 'Function_Name'

Expand All @@ -24,13 +23,13 @@
% Loop until the input name is acceptable
while 1
inputName = inputdlg(prompt, dlgtitle, dims, definput);
% Checks to see if the name shadows other names in scope
% Check to see if the name shadows other names in scope
if isGoodSimFcnName(gcs, inputName{1})
break
else
waitfor(msgbox([inputName{1}, ...
' is already used as a Simulink Function in scope.', ...
newline, newline, 'Please enter a new name.'], dlgtitle));
' is already used as a Simulink Function in scope.', ...
char(10), 'Please enter a new name.'], dlgtitle));
end
end
simulinkFcnName = inputName{1};
Expand Down
16 changes: 12 additions & 4 deletions src/sl_customization.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ function sl_customization(cm)
schemaFcns = {};
selection = find_system(gcs, 'Type', 'block', 'Selected', 'on');
selectedFcns = isSimulinkFcn(selection);

% Check if the Simulink version supports Simulink Functions
v = ver('Simulink');
if str2double(v.Version) > 8.3 % Greater than 2014a
verOK = true;
else
verOK = false;
end

if isempty(gcbs)
schemaFcns{end+1} = @FcnCreatorSchema;
schemaFcns{end+1} = @GuidelineSchema;
schemaFcns{end+1} = @InterfaceSchema;
elseif isSubsystem(gcbs) && ~isSimulinkFcn(gcbs) && ~isempty(gcbs)
elseif verOK && isSubsystem(gcbs) && ~isSimulinkFcn(gcbs) && ~isempty(gcbs)
schemaFcns{end+1} = @ConvToSimFcnSchema;
elseif any(selectedFcns) && ~isempty(gcbs)
schemaFcns{end+1} = @ChangeFcnScopeSchema;
Expand Down Expand Up @@ -123,9 +131,9 @@ function FcnCreatorCallback(callbackInfo)
scopes = getFcnScope(fcns);

% Show conversion operations depending on scope
anyGlobal = any(contains(scopes, char(Scope.Global)));
anyScoped = any(contains(scopes, char(Scope.Scoped)));
anyLocal = any(contains(scopes, char(Scope.Local)));
anyGlobal = any(contains2(scopes, char(Scope.Global)));
anyScoped = any(contains2(scopes, char(Scope.Scoped)));
anyLocal = any(contains2(scopes, char(Scope.Local)));
if anyScoped || anyLocal
schema.childrenFcns{end+1} = @GlobalFcnSchema;
end
Expand Down
Loading

0 comments on commit f78be4a

Please sign in to comment.