Cameo Simulation Toolkit UserGuide
Cameo Simulation Toolkit UserGuide
TOOLKIT
version 1.0
user guide
No Magic, Inc.
2011
All material contained herein is considered proprietary information owned by No Magic, Inc. and is not to be
shared, copied, or reproduced by any means. All information copyright 2010-2011 by No Magic, Inc. All Rights
Reserved.
CONTENTS
CAMEO SIMULATION TOOLKIT 5
1. Getting Started 5
1.1 Introduction to Cameo Simulation Toolkit 5
1.2 Key Features 5
1.3 Installation 6
2. Model Execution 6
2.1 Simulation by Executing Elements 7
2.1.1 Behaviors 10
2.1.2 Class 14
2.1.3 Diagram 17
2.1.4 Instance Specification 17
2.2 Simulation by Executing the Execution Configuration 18
3. Execution Configuration 20
3.1 ExecutionConfig Stereotype 20
3.2 Execution Log 20
3.3 User Interface Prototyping 21
3.4 UI Modeling Diagram Execution 22
3.5 ActiveImage and ImageSwitcher 25
4. Animation 26
4.1 Active and Visited Elements 26
4.2 Customizing Animation Colors 27
5. Simulation Debugging 28
5.1 Understanding Simulation Sessions 28
5.2 Simulation Debuger 29
5.3 Simulation Console 30
5.3.1 Console Pane 30
5.3.2 Simulation Information 31
5.3.3 Simulation Log File 32
5.4 Runtime Values Monitoring 32
5.4.1 Variables Pane 32
5.4.2 Runtime Object created from InstanceSpecification 33
5.4.3 Exporting Runtime Objects to InstanceSpecification 34
5.5 Breakpoints 36
5.5.1 Adding Breakpoints 37
5.5.2 Removing Breakpoints 38
6. Validation and Verification 40
7. State Machine Simulation 42
7.1 Supported Elements 42
7.2 Adapting Models for State Machine Simulation 43
7.2.1 Defining Trigger on Transition 43
7.2.2 Using Guard on Transition 44
7.2.3 Behaviors on Entry, Exit, and Do Activity of State 45
7.3 Running State Machine Execution 45
7.4 Sample Projects 46
7.4.1 test_regions.mdzip 46
7.4.2 test_timers.mdzip 46
7.4.3 test_guard.mdzip 47
8. Activity Simulation 47
8.1 About Activity Execution Engine 47
8.2 Creating Model for Activity Execution 48
8.3 Executing Activity 71
1. Getting Started
Cameo Simulation Toolkit is a MagicDraw plugin which provides a unique set of tools supporting the standard-
ized construction, verification, and execution of computationally complete models based on a foundational sub-
set of UML.
No Magic is the first in the industry to provide customers with an easy-to-use, standard-based executable UML
solution that integrates the semantics of different UML behaviors.
With Cameo Simulation Toolkit, you can execute a model and validate the functionality or performance of a
system in the context of a realistic mock-up of the intended user interface. The solution allows you to predict
how the system responds to user interaction or predefined test data and execution scenarios.
Cameo Simulation Toolkit contains the Simulation Framework plugin that provides the basic GUI to manage the
runtime of any kind of executable models and integrations with any simulation engines. The main functional-
ities of Cameo Simulation Toolkit are as follows:
(i) Simulation Window:
• Toolbars and Debugger Pane: to control the execution/simulation
• Simulation Console: to execute log outputs and command line for active engine
• Sessions Pane: to select the interested session of execution
• Variables Pane: to monitor the runtime values of each execution session
• Math Console: to communicate with Mathematical engine
• Breakpoints pane
• Triggers option
(ii) Pluggable execution engines
(iii) Execution animation
(iv) Model debugger
(v) Pluggable events and data sources
(vi) Pluggable mockup panels
(vii) Model-driven execution configurations
(viii) Pluggable expression evaluators and action languages
(ii) State Machine execution engine: W3C SCXML (State Charts XML) standard, an open-
source Apache implementation.
(iii) Activities execution engine: OMG fUML (foundational subset of Executable UML) standard.
(iv) Parametrics execution engine: allows Cameo Simulation Toolkit to execute SysML Para-
metric diagrams. SysML Plugin for MagicDraw is required for the engine to work properly.
1.3 Installation
To install Cameo Simulation Toolkit, either (i) use Resource/Plugin Manager in MagicDraw to download and
install the plugin, or (ii) follow the manual installation instructions if you have already downloaded the plugin.
1. Click Help > Resource/Plugin Manager on the MagicDraw main menu. The Resource/Plugin
Manager will appear and prompt you to check for available updates and new resources. Click
Check for Updates > Check.
NOTE Specify HTTP Proxy Settings for connection to start MagicDraw updates and resources.
2. Under the Plugins (commercial) group, select the Cameo Simulation Toolkit check box and
click Download/Install.
3. Restart the MagicDraw application.
(ii) To install Cameo Simulation Toolkit following the manual installation instructions on all platforms:
2. Model Execution
Cameo Simulation Toolkit allows you to execute the elements in a MagicDraw project. The elements that can
be executed must be supported by the execution engines in Cameo Simulation Toolkit. Any number of execu-
tion engines can be implemented, as separate plugins, and registered to Simulation Framework as the engines
for some particular types of model.
You can create a simulation by either (2.1) executing the elements that are supported by the execution engines,
or (2.2) creating the execution configuration, set the element to be executed as the execution target of the exe-
cution configuration, and then execute the model from the execution configuration.
1. Right-click an element either (i) on the diagram (Figure 1) or (ii) in the containment browser
(Figure 2), and then select Simulation > Execute.
2. The Simulation Window will open. The Simulation session will automatically be started and
displayed in the Sessions Pane (Figure 3). The session corresponds to the selected element in
the active diagram.
3. Click the Run Execution button on the toolbar (Figure 3) to execute the model.
NOTE Cameo Simulation Toolkit will use different execution engines to exe-
cute different kinds of elements:
• Behaviors
• Class
• Diagram
• Instance Specification
2.1.1 Behaviors
You can select a behavior, either (2.1.1.1) Activity or (2.1.1.2) State Machine, and execute it.
2.1.1.1 Activity
If you select to execute a behavior, which is an Activity (Figure 4), Cameo Simulation Toolkit will execute it on
the Activity diagram whose context is the selected Activity (Figure 5). A new session (Activity) will open in the
Sessions Pane. If you click the session, the runtime object of the selected Activity will open in the Variables
Pane.
2.1.1.2 StateMachine
If you select to execute a behavior, which is a State Machine (Figure 6), then it will be executed on the State
Machine diagram whose context is the selected State Machine (Figure 7).
You can also select to execute from an Activity or a State Machine diagram directly either by:
(i) opening the diagram and click the Execute button on the Simulation Window toolbar, or
(ii) right-clicking the diagram and select Simulation > Execute.
The Behavior, which is the context of the diagram, will then be executed.
2.1.2 Class
You can select to execute a Class element that is not a Behavior. A simulation session will be created to exe-
cute the selected class. The runtime value whose type is the selected Class, will be created to store the simu-
lated values. If the selected Class has a defined classifier behavior, either Activity or State Machine (Figure 8),
then it will be executed once you have clicked the Run Execution button. For example, if you select to execute
the Calculator class (Figure 1), the simulation will be performed on the Calculator state machine (Figure 7).
Figure 8 -- Show the Calculator Class, having a State Machine as its Classifier Behavior
If the class does not have a defined classifier behavior (Figure 9), the parametric will be executed instead (only
if the selected class is a SysML Block containing Constraint Property(ies)).
2.1.3 Diagram
To execute a diagram:
• Right-click a diagram and select Simulation > Execute (Figure 11). The element, which is the
context of the diagram, will be executed the same way a behavior or a class is executed.
You can also simulate an InstanceSpecification. The runtime object and the runtime values will be created from
the selected InstanceSpecification and its slot values. These runtime object and runtime values will be used for
the execution. You can see more information about runtime object and runtime values in Section 5.4.2.
To execute an InstanceSpecification:
• Right-click an InstanceSpecification and select Simulation > Execute. The classifier of the
selected InstanceSpecification will be executed the same way a behavior or a class is
executed. However, the slot values of the selected InstanceSpecification will be used to create
the runtime values at the beginning of the execution (Figure 12).
• Right-click an Execution Configuration and select Simulation > Execution (Figure 13).
• Select the execution configuration in the drop-down list (all of the execution configurations in
the open project will be listed in the drop-down list) on the Simulation Control toolbar and click
the Run ‘<name of execution configuration>’ Config button (Figure 14).
3. Execution Configuration
Cameo Simulation Toolkit provides a model-based execution configuration through the «ExecutionConfig» ste-
reotype. The «ExecutionConfig» configuration properties consist of:
• executionTarget – the element from which the execution should be started.
• silent – if the value is true, no animation (nor idle time) will be used.
• ui – the user interface mockup configuration to be started with the execution.
• log – the element in which the execution trace will be recorded.
• resultInstance - the InstanceSpecification which the execution results will be saved as its slot
values. If resultInstance is not specified, then the execution results will not be saved event if the
executionTarget is an InstanceSpecification.
NOTE You can use Execution configurations as the target elements in other execution configurations in
the next release of Cameo Simulation Toolkit.
A model-based execution log/trace has many advantages and some of them are as follows:
• it can be used as a source for various customized reports and analyses using the MagicDraw
validation mechanism (as both are model-based).
• it allows you to import execution data into any other UML compliant tool.
You can record multiple simulation sessions or test results in the same «ExecutionLog» element. The session
starting time can be seen as the name of the attribute. Currently, you can record the following runtime data (see
Figure 17):
• Signal Instance (when recordSignals = true) under the “Signal Instances” node – timestamp
(i.e. the relative occurrence time in milliseconds: ‘0’ when start execution), signal type and
target (Figure 17).
• Sequence of Activation and Sequence of Deactivation (when recordActivation = true) under
the “Activation sequence” node – timestamp and type of element being activated/deactivated.
• Behavior Call and Operation Call (when recordCalls = true) under the “Behavior Calls” and
“Operation Calls” nodes, respectively – timestamp, type, target and value(s).
• Runtime Value (when the recordedValues attribute has at least one Property selected) under
the “Value Changes” node – timestamp, select Property and value(s) of the selected Property.
• Constraint Failure (when recordedConstraintFailures = true) under the “Constraint Failures”
node – timestamp, element, target and value(s).
Whenever an execution engine creates a runtime object of a referenced classifier, a mockup UI will be instanti-
ated and displayed. A MockupPanel interface allows a mockup to listen to all of the execution events, monitor
structural feature values, and trigger signals.
Once represented, the UI component will reflect the value of the represented Property in the
Variables Pane during execution, and vice versa.
• Labels: drag a Property to a UI Label to bind the Property to such UI Label (the
«RuntimeValue» stereotype will be automatically applied; its “element” tag will then be set to
the Property; and its “Text” tag will also be set to the name of such Property). In this case, we
say that “the UI Label represents the Property”. Once represented, the UI Label will display the
value of the represented Property in the Variables Pane during execution.
• Buttons: a UI Button can be used to 1) send Signal(s), 2) call Operation(s) or 3) call
Behavior(s):
• Sending Signal(s): drag a Signal to a UI Button to associate the Signal with the UI
Button (the «SignalInstance» stereotype will be automatically applied; its “element”
(“signal”) tag will then be set to the Signal; and its “Text” tag will also be set to the
name of such Signal). During execution, if this UI Button is pressed, it will send the
associated Signal.
• Call Operation(s): drag an Operation to a UI Button to associate the Operation with
the UI Button (the «OperationCall» stereotype will be automatically applied; its
“element” tag will then be set to the Operation; and its “Text” tag will also be set to
the name of such Operation). During execution, if this UI Button is pressed, it will
call the associated Operation.
• Call Behavior(s): drag an Behavior (e.g., Activity) to a UI Button to associate the
Behavior with the UI Button (the «BehaviorCall» stereotype will be automatically
applied; its “element” tag will then be set to the Behavior; and its “Text” tag will also
be set to the name of such Behavior). During execution, if this UI Button is pressed,
it will call the associated Behavior.
Figure 19 demonstrates an example of using MagicDraw’s User Interface Modeling Diagram with Cameo Sim-
ulation Toolkit.
See the Calculator.mdzip sample for more details. Just drag any GUI elements to a diagram, click Execute,
and see them come alive!
NOTE • The current version of Cameo Simulation Toolkit supports frames, panels, group boxes, labels,
buttons, checkboxes, text fields, and sliders only.
• Do not drag and drop model element of existing UI Frame (from Containment Tree) on a
diagram to create one more ComponentView/Frame symbol on such diagram. Cameo
Simulation Toolkit still does not support 2 UI symbols of the same model element yet.
• Other samples worth trying include: test_nested_UI_panels.mdzip, test_UI.mdzip,
StopWatch_advanced.mdzip, and SimpleUI_labelUpdate.mdzip.
Figure 20 demonstrates an example of how to use ImageSwitcher and ActiveImage (see FlashingLight.mdzip
sample):
Once the FlashLight ExecutionConfig is executed, the mockup UI will be displayed (Figure 21). You can then
click on the Power button (circle one) to start execution, i.e. making the light bulb blink (see Flash-
ingLight.mdzip sample).
4. Animation
Active elements in a diagram will be annotated during execution using the same annotation mechanism used in
the active validation:
• Active and visited elements will be annotated with red and green respectively.
• Runtime values will be visible in the tooltip text of active elements.
NOTE • If an execution trace remains visible in a diagram, click the diagram to clear it.
• If a model is executed in silent mode by selecting an execution configuration whose silent tag
value is set to ‘true’, the animations will be disabled (See Section 3. Execution Configuration
for more information).
5. Simulation Debugging
You can create multiple simulation sessions during a single execution, for example, an Activity execution. If the
executed Activity contains callBehaviorActions, a new simulation session will be created to execute each call-
BehaviorAction. All of the simulation sessions will be shown in the Sessions Pane during execution. The Ses-
sions Pane will display the simulation sessions by their context elements in the tree node (Figure 24).
Step into To execute and run animation in the current active ele-
ment of a selected simulation session in the Sessions
Pane.
Step over To execute the current active element of a selected simu-
lation session and run animation in the background.
You can also pause the execution of a model at pre-defined breakpoints (see Section 5.5), examine and edit
variables in Variables Pane (Section 5.4.1), or execute element-by-element using Step into / Step over button.
The Debugger Pane includes a player-like control panel for a step-by-step execution (see Table 2 above),
threads/behaviors with an expandable stack trace (Understanding Simulation Sessions), Variables Pane/run-
time structure (Runtime Values Monitoring), Breakpoints pane (Breakpoints), and input/output console for cus-
tom commands or expressions evaluation (Console).
Cameo Simulation Toolkit provide Simulation Console for displaying simulation information during model exe-
cution. The displayed information could contain hyperlink to the model element in the MagicDraw project. The
model element will be selected in containment browser when you click on the hyperlink.
Show Runtime Informa- To the runtime information of the Cameo Simulation Tool-
tion kit. The runtime information compose of the registered
execution engines, available scripting engines and the
active simulation sessions (Figure 26).
There are 6-levels of information which can be displayed in the Simulation Console (ascending sorted by prior-
ity):
• TRACE: Trace information.
• DEBUG: Debuging information.
• INFO: Normal information.
• WARN: Warning information.
• ERR: Error information.
• FATAL: Fatal information.
By default, only the information with priority equal to INFO and higher (WARN, ERR, FATAL) will be displayed in
Simulation Console. You can customize the information displayed in Simulation Console by editing the simula-
tion.properties file in the data directory in MagicDraw installation directory.
You can use text editor to edit this file. Go to log4j.category.SIM_CONSOLE and change from first parameter
the lowest priority level that can be shown in the Simulation Console (INFO is the default value).
log4j.category.SIM_CONSOLE=INFO,SimConsoleApp,SimXMLApp
For example, you could change the first parameter of log4j.category.SIM_CONSOLE to TRACE for allow Sim-
ulation Console to display all level of simulation information.
log4j.category.SIM_CONSOLE=TRACE,SimConsoleApp,SimXMLApp
You can see more information on customizing display in Simulation Console from the comment in the simula-
tion.properties file.
During execution, the simulated information will be displayed in the Simulation Console. However, the Simula-
tion Console is limited to display only 60,000 characters for the sake of performance. If the simulation informa-
tion exceed the maximum capacity, only the latest 60,000 characters will then be displayed. Nevertheless, your
old simulation information will be automatically archived in the simulation.log file in user home directory
(<User home directory>/.magicdraw/<version>). The simulation.log file is an XML file (or a text file - to cus-
tomize it, see the comment in the simulation.properties file) that record all simulation information that had
ever displayed in the Simulation Console during model execution.
You can select a session in the Sessions Pane (Figure 27) to display the runtime objects and values that cor-
respond to the context element of a selected session in the Variables Pane.
When a model is being executed, (5.4.1.1) a context, (5.4.1.2) runtime objects, and (5.4.1.3) runtime values will
be created to store the simulated values of the model.
5.4.1.1 Context
A simulation session is always associated with its context of execution. The context of a simulation session is a
Class or one of its subtypes. When a context element is executed, a runtime object (of the context’s type) will
be created to store the runtime values. In Figure 27, the context of the selected simulation session is the “Cal-
culator” class.
A runtime object is the simulated value of a Class. In other words, it is a runtime instance of a Class, and hence
of the context as well. In Figure 27, the runtime object of the simulation session context is the “Calcula-
tor@155d21b” instance. Since the runtime instance is the “Calculator” Class type’s , it could contain structural
features (which corresponds to the Class attributes), for example, “display” and “operand1”.
A runtime value refers to the value of the structural features mentioned in section 5.4.1.2 above, for example,
“200” and “120”. However, if the type of a structural feature is a classifier, its runtime value can also refer to
another runtime object of a structural feature type.
The Variables Pane (Figure 27) displays the structure of an executing model and the runtime values during the
execution of the model. This pane contains two columns: (i) Name and (ii) Value:
The Name column represents the context and its structural features. If the context is a State Machine session’s,
the current state of the context will be displayed in square brackets. If a structural feature is typed by a Class,
which is the context of another State Machine session, the current state of such context will also be displayed in
square brackets, after the structural feature.
The Value column represents the runtime values of those structural features in a Name column. A runtime
value can be the input or output of an execution. You can directly edit the runtime values in the Value column if
they are of the following types: Boolean, Integer, Real, and String.
At starting point of model execution, the runtime object will be created for storing the runtime values. If the ele-
ment which is selected for execution is InstanceSpecification or the ExecutionConfig whose executionTarget is
InstanceSpecification. The runtime values will be created from the slot values. They will be assigned to the run-
time object’s structural features which equivalent to the slot’s defining feature.
If the slot of an InstanceSpecification is empty, and the slot’s defining feature has defined default value, then the
runtime value will be created from the default value and will be assigned to the runtime object’s structural fea-
ture instead. Figure 28 -- show the runtime object that is created for executing pipe InstanceSpecification. The
InstanceSpecification contains only one slot value of lenght. Then, the runtime value which is created for the
length structural feature of the runtime object, will be equal to this slot value (1.0). For the runtime values of
radius and thickness, they will be equal to the default values of radius and thickness property of Pipe class
(0.05 and 0.002 respectively).
You can export a runtime object, which is shown in the Variables Pane, to a model as an InstanceSpecification.
You can export it to either (i) a newly-created InstanceSpecification or (ii) an existing InstanceSpecification. The
values of a runtime object will be set to the slots of an InstanceSpecification.
1. Either (i) click a row that has a runtime object to be exported in the Name column and click the
Export to New Instance icon on the Variables Pane toolbar or (ii) right-click it and select
Export to New Instance (Figure 26).
2. The Select Owner dialog will open. Select the owner of the created InstanceSpecfication and
click OK (Figure 30).
1. Either (i) click a row that has a runtime object to be exported in the Name column and click the
Export to Instance icon on the Variables Pane toolbar or (ii) right-click it and select Export to
Instance (Figure 31).
2. The Select Instance dialog will open. Select an InstanceSpecification that will be used to save
the runtime object (you can select only the InstanceSpecification that has the same classifier as
the runtime object) and click OK (Figure 32).
5.5 Breakpoints
Cameo Simulation Toolkit allows you to add or remove breakpoints to or from model elements. The model exe-
cution will be paused when these model elements are activated during the execution. You can open the Break-
points pane to see and manage all of the existing breakpoints in an active project. The Breakpoints pane lists
all breakpoints with their properties shown in separate columns (Figure 33).
Column Function
Enabled To display the enabled/disabled states of a breakpoint. If the value is true then
the breakpoint is enabled. Otherwise, the breakpoint is disabled. The execu-
tion of a model will be suspended at that particular breakpoint only when the
breakpoint is enabled (true).
Element To represent a model element to which each breakpoint is applied. The execu-
tion of a model will be suspended when the symbol of the element is activated
or deactivated (depending on the value in the Suspend column).
Condition To represent a breakpoint condition, a boolean expression, that will be evalu-
ated when the execution of a model reaches the element to which a breakpoint
is applied. The execution will be suspended at that particular element/break-
point when the result of the boolean expression is true. If the conditional is not
defined, the execution will always be suspended when it reaches that particu-
lar breakpoint.
Suspend There are three kinds of execution suspensions: (i) On Entry, (ii) On Exit, and
(iii) Both.
(i) On Entry: the execution of a model will be suspended when a breakpoint’s
element is activated.
(ii) On Exit: the execution of a model will be suspended when a breakpoint’s
element is deactivated.
(iii) Both: the execution of a model will be suspended on both activation and
deactivation of a breakpoint’s element.
You can add a Breakpoint to a model element using the context menu.
• Right-click a model element in either the containment browser or the symbol of the model
element in a diagram, and then select Simulation > Add Breakpoint(s) (Figure 34).
You can also remove a Breakpoint can be removed using the context menu.
To remove a Breakpoint:
• Right-click a model element that has a breakpoint(s) and select Simulation > Remove
Breakpoint(s) (Figure 35).
You can also use the Remove Breakpoint(s) or Remove All Breakpoints toolbar button or the context menu
of the Breakpoints pane to remove all of the existing breakpoints (Figure 36).
To validate a model:
1. Click Options > Environment on the MagicDraw main menu to open the Environment
Options dialog (Figure 37).
2. Select the Simulation node on the left-hand side pane and select the Check Model Before
Execution check box.
3. Click OK.
4. Execute your model. A dialog will open, asking whether you want to load the required profiles
that contain the validation rules to validate your model (if your project does not contain the
required validation rules) (Figure 38).
5. Click either (i) Yes to load the validation rules and validate the model before the execution or (ii)
No to execute the model without validating it.
The W3C SCXML standard provides a generic state machine-based execution environment based on Harel
statecharts. SCXML is capable to describe complex state machines, including sub-states, concurrency, history,
time events, and many more. Most of the things that can be represented as a UML state chart such as business
process flows, view navigation bits, interaction or dialog management, and many more, can leverage the
SCXML engine.
With the state machine execution build, you can simulate an executable model both as a demonstration tool
and to validate and verify the system behavior at key milestone reviews. In addition, Cameo Simulation Toolkit
supports the UML state machine export to standard SCXML files for further analysis or transformations
(through the state machine context menu).
Exportable to
Element Type Executable (Yes/No) SCXML (Yes/No)
state Yes Yes
composite state Yes Yes
orthogonal state Yes Yes
submachine state Yes Yes
initial state Yes Yes
final state Yes Yes
onEntry Yes Yes
onExit Yes Yes
onTransition Yes Yes
doActivity Yes Yes
time event Yes Yes
deep history Yes Yes
shallow history Yes Yes
transition-to-self Yes Yes
choice Yes Yes
NOTE All of the elements in a State Machine diagram (to be executed) must have names.
A runtime object will change its state when it receives a trigger. Therefore, a transition should have a defined
trigger. A trigger can be either a signal or time event.
You can specify the guard conditions on transitions using any action language. Open test_guard.mdzip to see
an example of how to specify guards on transitions.
You can use the properties of a context classifier (the classifier that is the context of a State Machine diagram)
in guard expressions as variable names. The real values of the variables will be resolved at runtime. In
test_guard.mdzip, the values come from the slots of the instance of the context classifier (see the instance
diagram in the sample project).
States can have defined behaviors at Entry, Exit, or Do Activity. Cameo Simulation Toolkit will create a new sim-
ulation session to execute those defined behaviors. A defined behavior can be an Activity, State Machine, or
OpaqueBehavior. The execution engine that corresponds to a defined behavior will be used to execute a
model. If the defined behavior is OpaqueBehavior, the ScriptEngine will be used to execute the code in the
body of OpaqueBehavior.
Figure 41 -- The Execution of Behavior on Entry of State (See Sample Project - StopWatch.mdzip)
During a state machine execution, the state of a runtime object will be changed by a trigger. The trigger can be
either a signal or time event. If it is a signal event trigger, the signal can be sent to a runtime object to trigger it
from one state to another. To send the trigger signal, you have to select the runtime object, which is the target
recipent for the signal, in the Variables Pane. All signals that can be received by a selected runtime object will
be listed in the Triggers drop-down menu on the Simulation Window toolbar (Figure 42).
A signal can be sent to a runtime object through a Mock-up User Interface. See more information about Mock-
up in Section 3.4 UI Modeling Diagram Execution.
7.4.1 test_regions.mdzip
7.4.2 test_timers.mdzip
7.4.3 test_guard.mdzip
7.4.1 test_regions.mdzip
This sample demonstrates the use of an orthogonal state with parallel regions, and entry or exit activities.
• An Entry activity will be executed right after a state has been activated before any other states
in the inner regions.
• All of the initial states in all regions will be activated at the same time. It demonstrates multiple
active states at the same time.
• The events list in Simulation Console contains the triggers of all outgoing transitions of all active
states.
• If one of the parent's state outgoing transitions is triggered, an exit activity will be executed
before the state is deactivated.
7.4.2 test_timers.mdzip
• The transitions with specified time events will be automatically triggered after a specified
amount of time (in seconds or milliseconds).
• Only relative time (delays) are supported.
7.4.3 test_guard.mdzip
This sample demonstrates the ability to specify and resolve guard conditions on the transitions.
• The properties of a context classifier can be used in the expressions as variable names.
• The real values of the variables will be resolved at runtime.
• If this is the case, they come from the slots of the instance of the context classifier (see the
Instance diagram).
8. Activity Simulation
Various UML activity diagram concepts are supported, including object and control flows, behavior and opera-
tion calls, sending and accepting signals and time events, pins, parameters, decisions, structured activity
nodes, and many more.*
NOTE • Activities that will be executed must be owned in a Package or Class only. As a workaround,
the CallBehavior actions, owned by the call behaviors in a package, will be used for the entry/
do/exit behaviors in states.
• The guards on an ObjectFlow are not boolean expressions in fUML. They contain a value that
should match with the runtime value that flows on the ObjectFlow during execution. You can
change this mode to a regular UML (boolean expression) by changing the Environment
Options-Simulation-Use fUML Decision Semantics value. The value is false (UML mode) by
default.
1. Create a new UML project by clicking File > New Project... on the main menu. The New Proj-
ect dialog will open (Figure 43).
2. Select UML Project from the General-Purpose Modeling group and specify the project’s
name, for example, “SimpleActivityExecution”.
3. Specify the location where you want to save your project file, and then click OK.
4. Right-click the Data model in the containment browser and select New Element > Class. A
new class element, which is the context of the activity, will be created in the containment
browser. Name the created class, for example, “SumPrinter”.
5. Add two properties: (i) x and (ii) y of type Integer.
(i) Right-click the SumPrinter class and select New Element > Property. Type ‘x’ to
name the property (Figure 44). Right click x and select Specificaton to open its
Specification dialog. Select Integer as the property type (Figure 45).
Once the properties x and y have been created, define the behavior of the created class by specifying the clas-
sifier behavior of the SumPrinter class with a UML Activity element.
(ii) To create an activity to print the summation value of the two properties:
1. Right click the SumPrinter class in the containment browser and select New Diagram > Activ-
ity Diagram to create a new Activity under it.
2. Name the diagram “PrintSum”.
Now that the activity has been created, assign it as the classifier behavior of SumPrinter.
(iii) To assign the activity as the classifier behavior of the created class:
1. Right-click the SumPrinter class in the containment browser and select Specification to open
its Specification dialog (Figure 47).
2. Select All from the Properties drop-down menu to make sure that all of the properties are
listed in the dialog.
3. Click Classifier Behavior and select the PrintSum activity.
(iv) To create an opaque behavior to print the summation value of the two input parameters of type Integer:
1. Right-click the Data model in the containment browser and select New Element > Opaque
Behavior. A new opaque behavior will be created under the Data model.
2. Name it “PrintSumOfIntegers” (Figure 49).
(i) Right-click the PrintSumOfIntegers opaque behavior and select New Element >
Parameter. Name the created parameter ‘a’ and select Integer as the type of parame-
ter a (Figure 50).
Figure 51 -- PrintSumOfIntegers Opaque Behavior Containing Parameters a and b in the Containment Browser
(v) To write a script to print the summation of the given integer values:
• Open the specification dialog of the PrintSumOfIntegers opaque behavior and write a script in
the Body field (you can use any scripting language that is supported by MagicDraw’s macro
engine, for example, BeanShell, Groovy, JavaScript, Jython, or Jruby). In this example,
JavaScript will be used to print the summation of the given integer values that are referred to by
the parameters a and b; therefore, the script will be: “print(a+b)” (Figure 52).
NOTE If you want use a script language other than JavaScript, specify it in the Language attribute.
The next steps will be to complete the PrintSum activity diagram of the SumPrinter class and add ReadStruc-
turalFeatureAction so that the values of properties x and y, which are owned by the SumPrinter class, can be
read. The values of a and b will later be passed on to the PrintSumOfIntegers opaque behavior as the values
of input parameters a and b respectively.
1. Drag the PrintSumOfIntegers opaque behavior from containment browser to the PrintSum
activity diagram. A new action of PrintSumOfIntegers will be created.
2. Name the action “print” (Figure 53).
Figure 53 -- Creating a Print Action by Dragging the PrintSumOfIntegers Opaque Behavior to Activity Diagram
3. Add Initial and Activity Final nodes to the activity diagram and connect them to the print action
using a control flow (Figure 54).
4. Click Action and select the Any Action... diagram toolbar button on the PrintSum activity dia-
gram.
6. Click the PrintSum activity diagram to create the action and name it “readX” (Figure 57).
8. Click the Structural Feature ... button to open the Select Property dialog to select the struc-
tural feature (Figure 59).
9. Select property x of the SumPrinter class and click OK. The Select Property dialog will close.
10. Select Pins on the left-hand side pane of the Specification dialog. You need to create two
pins for ReadStructuralFeatureAction: (i) the input pin to specify the runtime object of type
SumPrinter whose runtime values that correspond to the properties x and y will be used for
execution, and (ii) the output pin of the type Integer to specify the value read from the structural
feature.
(i) Click the Object button and select Input Pin from the context menu (Figure 60). A
new input pin will be added to the action. Name this pin “self” and select SumPrinter.
as its type, and then click the Back button (Figure 61).
(ii) Click the Result button and select Output Pin from the context menu (Figure 62).
Name this pin “a” and select Integer as its type, and then click the Close button (Fig-
ure 63).
11. Click the readX action on the activity diagram and select Display Pins on the smart manipula-
tor (Figure 64). The Select Pin dialog will open (Figure 65).
12. Select all pins and click OK. The Select Pins dialog will close.
13. Connect pin a of the readX action to pin a of the print action (Figure 66).
Figure 66 -- Activity Diagram Showing the Flow between readX and print Actions
(vii) To create a ReadSelfAction to read a runtime object that will be supplied to the input pins of readX and
readY actions:
1. Right-click Any Action on the diagram toolbar of the Activity diagram. The Select Action
Metaclass dialog will open (Figure 68).
4. Right-click the readSelf action to open its Specification dialog (Figure 70).
5. Select Pins on the left-hand side pane of the dialog and add a new output pin named “self” of
type SumPrinter to the Result row.
6. Go to the PrintSum activity diagram and show the output pin of the readSelf action using the
smart manipulator button.
7. Create a Fork Horizontal and connect it to the pins of the actions on the diagrams using an
object flow (Figure 71).
The final step will be to create an InstanceSpecification whose classifier is the SumPrinter and assign the
values to the slots that corespond to properties x and y. These values will be used during the simulation.
(viii) To create an InstanceSpecification whose classifier is the SumPrinter and assign the values to the slots
that corespond to the properties x and y:
1. Right-click the Data model and select New Element > InstanceSpecification.
2. Name the created InstanceSpecification “instance” (Figure 72).
5. Edit the classifier by selecting the SumPrinter class and click OK.
6. Click Slots on the left-hand side pane of the Specification dialog and select x:Integer (Fig-
ure 74).
7. Click the Create Value button to create a new value of the slot (Figure 74). The Value box will
open (Figure 75).
Figure 76 -- The created InstanceSpecification with Slot Values in the Containment Browser
The following example will show you how to add breakpoints to pin a and b of the print action. Once the model
execution has reached these pins, the simulation will be suspended.
1. Right-click an element and select Simulation > Add Breakpoint(s) (Figure 77). The break-
points will be shown in the Breakpoints pane of the Simulation Window (Figure 78).
You can open the Simulation Window by clicking Window > Simulation on the main menu (Fig-
ure 79).
2. Right-click instance in the containment browser and select Simulation > Execution (Fig-
ure 80) to execute the model from instance, which is the InstanceSpecification of the Sum-
Printer classifier.
3. A new simulation session will be created and displayed in the Sessions Pane of the Simula-
tion Window (Figure 81). The symbol of elements that have breakpoints attached will be high-
lighted in yellow (default) (Figure 82).
4. Click the Run Execution button on the Simulation Window toolbar. Cameo Simulation Toolkit
will animate the execution on the PrintSum activity diagram. The execution will be suspended
when pin a or b of the print action is activated. You can hover your mouse pointer over the
active element to see its runtime value.
5. Click the Resume Execution button on the Simulation Window toolbar to continue the execu-
tion (Figure 80).
6. The execution will be suspended again when pin b is activated. Click Resume Execution to
continue the execution. In the Simulation Console of the Simulation Window, you can see
the printed value of 10, which is the summation between 2 and 8.
Figure 84 -- Simulation Console of Simulation Window Showing the Printed Result of Summation
NOTE If you do not want to display the animation (silent execution), you can create Execution Config-
uration to customize the execution by selecting instance as the executionTarget and set silent
to true. See Section 2.2 for more information.
9. Parametrics Simulation
The Parametric Engine will use the Mathematical Engine to solve the mathematical and logical expressions
that are defined as the constraints of Constraint Blocks. The default Mathematical Engine, which comes with
Cameo Simulation Toolkit, is Math Console.
The Parametric engine in the current version of Cameo Simulation Toolkit can solve expressions in a one-way
direction only. The variables that are defined on the left-hand side of an expression will be considered as the
output parameters, whereas the variables on the right-hand side as the input parameters. The values of the
input constraint parameters must be specified in order to evaluate the values of the output constraint parame-
ters.
When you start the parametric execution on a SysML block, the Parametric Engine will execute the constraint
and nested constraint properties of the block. The order of the execution of the constraint properties will depend
on the expressions. If an input constraint parameter of the constraint property is connected to an output con-
straint parameter of another constraint property, the constraint property that requires the input values will be
executed after the one that provides the values to the output constraint parameters
In the SysML Parametric Diagram of the test_parametrics.mdzip sample (Figure 85), which is located in the
<md.install.dir>/samples/simulation/Parametrics/ directory, you can see that the order of the execution of con-
straint properties will be: s1, s2 and s3 respectively.
9.2.2 Typing Value Properties by Boolean, Integer, Real, Complex, or Their Subtypes
SysML provides the QUDV library to create different value types. You can use these value types to type the
value properties that are defined in a SysML model, which can be used for the parametric execution. However,
they must be inherited from the basic SysML value types which are Boolean, Integer, Real, and Complex. You
can see the example in the CylinderPipe.mdzip sample.
SysML provides a binding connector to connect elements whose values are bound together. The Parametric
engine uses the binding connector to distinguish between the connector that represents a physical connection
and the one that bounds the values. Therefore, you can use a binding connector to connect a value property to
a constraint parameter, and a constraint parameter to another constraint parameter. You cannot used it to con-
nect a value property to another value property if neither of them is connected to a constraint parameter,
because it cannot specify the flow of the parametric execution direction. To do this, you need to first create a
constraint block to assign the operation, and then insert a binding connector.
Figure 88 -- Using a Constraint Property Instead of Directly Binding Value Properties using Binding Connector
An InstanceSpecification of the SysML block is required to start the parametric execution on a SysML model.
The initial values, which will be used for simulation, must be specified as the slot values of the InstanceSpecifi-
cation. You also need to specify the values of the value properties that are connected to the input constraint
parameters, otherwise, the default values will be used. The default value of the value properties whose type is
Number or its subtypes, is zero. The default value of the value properties, which are boolean, is false.
You can also use the InstanceSpecification of a SysML block to store the values resulting from the parametric
execution if the execution configuration is used, by defining the resultInstance of the «ExecutionConfig» stereo-
type in the InstanceSpecification (Figure 90).
NOTE You need to create InstanceValues for the slots which correspond to the part properties, refer-
ence properties, or shared properties (InstanceValue), even though they contain empty slot val-
ues of the value properties. Otherwise, you cannot save the result values to the
InstanceSpecification. You need to create the slots before saving the result values.
According to the multiplicity of property elements, a runtime object cannot contain multiple runtime values that
correspond to a property. If the property is bound to constraint parameters, which are the input of an expres-
sion, then a list of values will be passed on to the mathematical engine to solve the expression. The mathemat-
ical and logical expressions, which are defined in the constraint blocks, must support the use of multiple values.
Since a matrix column will be constructed from a list of input values in the Built-in Math Solver, the mathemati-
cal expression must be written in a form that supports matrix variables.
If you refer to the Multiply constraint block in the test_parametrics sample, you will see that the mathematical
expression of the constraint block is: z = x * y. If four values are passed on to the mathematical engine for each
x or y parameter, then two column matrices (4x1 matrices) will be constructed and used to solve the expres-
sion. However, the column matrices cannot solve the expression because the matrix dimensions do not agree
(the number of column of x must be equal to the number of row of y). To solve this, you need to rewrite the
expression. You need to change the column matrices to diagonal matrices before the multiplication operation
starts by changing the expression to: z = diag(diag(x) * diag(y)).
Figure 91 -- Constraint Blocks Expressions Used with Multiple Values in CylinderPipe.mdzip Sample
If you have an InstanceSpecification of the SysML block that contains multiple slot values and if the slot values
are the InstanceValues whose InstanceSpecifications also contain multiple slot values and so on, up to the slot
values, which correspond to the value properties that are connected to the constraint parameters. You need to
pass all of these values on to the mathematical engine.
If this is the case, the Parametric engine will first collect all of the values that correspond to the value properties
that are connected to the constraint parameters, and then create a list of values and pass it on to the Mathe-
matical engine. The order of the values will depend on the order of the slot values. To ensure that the values
order will remain the same, you need to specify the IsOrder attribute of the Property elements, which has a
non-singular multiplicity, to true. In the SysML Parametric diagram of the CylinderPipe.mdzip sample (Fig-
ure 87), and the InstanceSpecification of the SysML block “RawMaterialSupplier” in Figure 92, the list of the
values for the mathematical engine to solve the expression are as follows:
• length = {1.0, 2.25, 12}
• radius = {0.1, 0.25, 0.25}
• tickness = {0.002, 0.002, 0.005}
1. Start the Parametric Simulation Engine (you can select Block A, InstanceSpecification a:A, or
the Execution Configuration class symbol (on the Execution Configurations Block Definition Dia-
gram). Either:
(i) right-click the element symbol and select Simulation > Execute in context menu
or
(ii) select the element symbol and click the Execute button in the Simulation Window
toolbar. (If you click the Execute button without selecting any element and the active diagram is
a SysML Parametric diagram, then the classifier, which is the context of the active SysML Para-
metric diagram, will be used as the element to be executed.)
NOTE In the case that the element to be executed is a Classifier, the InstanceSpecification must be
specified. The slot values defined in that particular InstanceSpecification will be used as inputs
for the simulation, and placeholders as outputs. If there is only one matching InstanceSpecifica-
tion found in the project, then it will automatically be used for the simulation. Otherwise, the
Select Element dialog will open for you to select an InstanceSpecification (Figure 93).
2. Once the Parametric Simulation Engine has been started, the runtime structure of the executed
classifier will be shown in the Variables Pane (Figure 94). You can modify the values in the
value column of the Variables Pane.
3. Click the Run button to start the simulation. The Parametric Simulation Engine will simu-
late your Parametric model (with animation on your diagram), and input the calculation result
into the corresponding slot of the selected InstanceSpecification automatically (Figure 95).
Figure 96 -- Slot Value before and after Simulation with Parametric Simulation Engine
com.nomagic.magicdraw.simulation.parametrics.ParametricsEngine.executeObject(Obje
ct object);
An argument object is the runtime object of a classifier to be executed. You can obtain this particular runtime
object by using some UML actions such as ReadSelfAction, ReadStructuralFeatureValueAction, and Val-
ueSpecificationAction, or by using the Cameo Simulation Toolkit Open API. Figure 97 shows the Parametric
activity diagram in the CylinderPipe.mdzip sample. The action:ExecuteParametric is used to run the parametic
execution. The runtime object, which will be executed, is obtained from the value specification action rawMate-
rialSupplier.
NOTE All of the sample projects of the Parametric Simulation Engine include the Execution Configura-
tions package that contains two ExecutionConfig elements for normal and silent execution. You
can select this ExecutionConfig class to start the Parametric Simulation Engine.
1. Open StopWatch.mdzip.
2. Right-click the stopwatch_config ExectionConfig (in the Config Simulation Configuration Dia-
gram) and then select Simulation > Execute in the context menu.
3. In the Simulation Window, press the Run Execution button to start the execution.
4. The Stopwatch mockup panel will then open. Also, the StopWatch is started with the “ready”
state.
5. Either (i) click the start button in the mockup panel, or (ii) select the context (StopWatch
[ready]) in the Variables Pane, and then select the start signal in the Triggers: combo box in
the Simulation Window to initiate the timer. The following buttons / signals can be used in dif-
ferent states:
• The stop button / signal will stop the timer if the current state is either running or
paused.
• The reset button / signal will reset the timer to 0 if the current state is stopped.
• The split button / signal will stop displaying the elapsed time, but the timer still runs
in background, if the current state is running.
• The unsplit button will redisplay the elapsed time if the current state is paused.
NOTE You need to close all of the current project control windows before switching to another project,
or close the project or MagicDraw to ensure that the tool is fully functioned.
If you do not want to trigger events manually, you can model the events instead. Activity diagrams allow you to
model the SendSignalActions sequence and send Signals to any target Objects. Cameo Simulation Toolkit
allows you to execute this particular activity and sends the signals to other active Engines. Therefore, whenever
you start a State Machine Simulation, the transitions will be automatically triggered.
1. Open StopWatch.mdzip.
2. Right-click the Stopwatch Testcase ExectionConfig (in the testcase Simulation Configuration
Diagram) and then select Simulation > Execute in the context menu.
3. In the Simulation Window, press the Run Execution button to start the execution.
4. The Testcase scenario Activity diagram will then be executed. Once the context created by
the Create Object createObject is passed to the startObjectBehavior element, the Stopwatch
mockup panel will then open, and a state machine execution will start.
5. You will see how the Activity diagram is executed; each SendSignalAction will be highlighted in
red, the transition will be triggered, and the StopWatch system will start, pause, or stop accord-
ing to the signals sent by each SendSignalAction.
The current Cameo Simulation Toolkit version comes with a Built-in Math Solver.
1. Click Options > Environment on the main menu to open the Environment Options dialog.
2. Select Simulation in the left-hand side pane and select a mathematical engine from the Math-
ematical Engine field (Figure 98).
You can start or stop the mathematical engine by clicking the Start Math Engine or Stop Math Engine button
(Figure 99).
Cameo Simulation Tookit allows you to exchange values between slots and the Mathematical engine through
the diagram context menu on slot (Figure 100).
1. Right-click the slot to which you will export a value and select Import Value from Engine. The
Value Exchange dialog will be open (Figure 101).
2. Specify the variable name whose value you want to import and click OK.
1. Right-click the slot whose value you want to export and select Export Value to Engine. The
Value Exchange dialog will open.
2. Specify the variable name to which you will export the value and click OK.
During model execution, the runtime values which are shown in the Variable Pane could be exported to the
Mathematical engine using context menu on the selected row as shown in Figure 102. Therefore, you can ana-
lyze these exported runtime values with Mathematica engine’s functions, e.g. plot.
Figure 102 -- Show the context menu for exporting the runtime value to Mathematical engine.
1. Right-click the row that contains runtime value to be exported and select Export value to Math
Engine. The Value Exchanger will open.
2. Specify the variable name to which you will export the value and click OK.
You can type generic mathematical equations directly in the Math Console, for example:
x = 10;
y = 20;
z = x+y
NOTE The calculation results for the expressions that end with a semicolon (;) will be set to the corre-
sponding variable in the Built-in Math Solver environment. It will not be displayed in the Math
Console.
The calculation result (false) will be assigned to the variable c, but it will not be displayed in the Math Console.
If an expression does not contain any assignment operator, the calculation result will be set to the variable
'ans', for example:
x = 10;
20 + x
You can calculate multiple expressions at the same time by typing a semicolon (;) at the end of each expres-
sion, for example:
x = 10; y = 20; z = x+y; a = z / x
11.3.2 Variables
The variables (operands) that can be used in Built-in Math Solver must conform to the following naming con-
ventions:
• The characters in a variable name must be a-z, A-Z, or 0-9.
• The first character must not be a number.
• Variable name must not be Constants (“E” or “PI”)
• Variable names must not be Functions (“sqrt”, “sin”, “cos”).
• Variable names must not be Operators (“+”, “-”, “*”, “/”).
11.3.3 Values
Valid values that can be used in an expression are: (11.3.3.1) Real Number, (11.3.3.2) Complex Number,
(11.3.3.3) Boolean, and (11.3.3.4) Matrix.
d = 1.25 + 0.25i
NOTE The 'i' character in an expression can be parsed as the imaginary unit or character of a variable
name. If 'i' is placed after a number and the next character is neither an alphabet nor number, it
will be parsed as an imaginary unit (otherwise parsed as a variable). For example:
• ca = 1i ‘i’ is parsed as an imaginary unit.
• cb = i ‘i’ is parsed as a variable.
• cx = 3.25i ‘i’ is parsed as an imaginary unit.
• cy = 4i4 ‘i’ is parsed as the first character of a variable name 'i4'
11.3.3.3 Boolean
a = true
b = false
11.3.3.4 Matrix
U = [1.0, 2.0, 3.0; 4.0, 5.0, 6.0; 7.0, 8.0, 9.0]
A = [true; false; false; true]
NOTE • You can add a matrix to the built-in math solver by the following syntax (a
semi-colon is used as row separator and comma or space is used as a
comma separator). From the expression in 11.3.3.4 above:
U = [1.0, 2.0, 3.0; 4.0, 5.0, 6.0; 7.0, 8.0, 9.0]
true
A = false
false
true
• You can refer to a matrix element by specifying the row index and column
index in round brackets after a matrix name, for example (from U above):
U(1, 1) is 1.0
U(2, 3) is 6.0
• You can also refer to a matrix element by specifying only one index in round
brackets after a matrix name. If this is the case, the matrix will be considered
as a column-major order matrix. The elements on the given column-major
order index will be returned. For example (from U above):
U(2) is 4.0
U(6) is 8.0
11.3.4 Constants
Constant Value
E The real value that is closer than any other to e, the base of the natural logarithms.
PI The real value that is closer than any other to pi, the ratio of the circumference of a
circle to its diameter.
11.3.5 Operators
b) Assignment Operators
11.3.6 Functions
random random() To return a real value with a positive sign, greater than or
equal to 0.0 but less than 1.0.
real real(c) To return the real value of the real part of a given complex
number.
This function operates element-wise on matrices.
rint rint(x) To return the value that is closest in value to an argument
and is equal to a mathematical integer.
This function operates element-wise on matrices.
round round(x) To return the closest value to an argument and is equal to a
mathematical integer.
This function operates element-wise on matrices.
sec sec(x) To return the secant of a given value.
sec(c) This function operates element-wise on matrices.
secd secd(x) To return the secant of a given value, expressed in degree.
secd(c) This function operates element-wise on matrices.
sech sech(x) To return the hyperbolic secant of a given value.
sech(c) This function operates element-wise on matrices.
Built-in Math Solver provides the API for the user to create the user-defined functions. These functions can be
used in mathematical or logical expressions of constraint elements. To create the user-defined function, you
have to create a new MagicDraw plugin. Then, create a Java class that implements the UserDefinedFunction
interface. Finally, register the created class to the built-in math solver.
You can see the MagicDraw OpenAPI UserGuide.pdf in the <md.install.dir>/manual directory for the infor-
mation about how to create a new MagicDraw plugin.
Cameo Simulation Toolkit provides the Java interface, which is UserDefinedFunction interface, for creating the
user-defined functions in built-in math solver. It has 3 methods that must be implemented in the Java class.
String getName()
This method returns name of the user-defined function. It will be used for calling to the user-
defined function in mathematical expression.
This method will be called by built-in math solver for validating the input parameters before
perform function operation. The ‘parameters’ are the input parameters which are passed to the
user-defined function. If all of them are valid, this method returns true. Otherwise, false is
returned.
This method will be called by built-in math solver for perform the user-defined function operation.
The ‘parameters’ are the input parameters which are passed to the user-defined function. The
implemented code for calculation the result value from the given input parameters should be
placed in this method.
For example, the user-defined fucntion for polynomial value evaluation from the given polynomial coefficient
and the value that polynomial will be evaluated.
So, we create a new Java class which is named with “PolyvalFunctionDescriptor”. It must implements the
UserDefinedFunction interface.
11.3.7.2 Register user-defined funtion to Built-in Math Solver using SimpleMathEngine class
The SimpleMathEngine class represents the built-in math solver. The Java class which implements the
UserDefinedFunction interface must be registered to this class when the created plugin is initialized.
package com.nomagic.magicdraw.simulation.udfsample;
import com.nomagic.magicdraw.plugins.Plugin;
import com.nomagic.magicdraw.simulation.expsolver.mathengine.SimpleMathEngine;
@Override
public boolean close() {
SimpleMathEngine.unregisterUserDefinedFunction(PolyvalFunctionDescrip-
tor.name);
return true;
}
@Override
public boolean isSupported() {
return true;
}
}
11.4.1 Setting up system for calling MATLAB® from Cameo Simulation Toolkit
3. Add path of MATLAB® bin and bin/win32 (or bin/win64 for Microsoft Windows 64-bit) folder to
the Path environment variable.
• Double-click System in Control Panel to open the System Properties dialog.
Select Advanced tab.
Figure 105 -- Environment Variables Dialog for Setting System Path Variable.
• Select Path in System vairables group and click Edit button to open the Edit System
Variable dialog.
• Insert path to MATLAB® bin and bin/win32 folder (or bin/win64 for Microsoft
Windows 64-bit) at the begin of Variable value, e.g. “C:\Program
Files\MATLAB\R2010b\bin;C:\Program Files\MATLAB\R2010b\bin\win32;”.
You can switch the mathematical solver to MATLAB® by setting the Mathematical Enigne field in the environ-
ment option to MATLAB® (Figure 107).
• Select Options > Environment in main menu bar. The Environment Options dialog will open.
• Select Simulation in the left pane.
• In Mathematic Engine, select MATLAB® from drop-down list.
• Click OK.
Any value specification in a model (like guards, constraints, decisions, default values, opaqueBehaviors) can
have the opaque expressions defined using an action language. The languages that are supported include:
• Javascript
• Beanshell
• Groovy
• Jython
• JRuby
• OCL
• Java binaries
• Math (see 11. Mathematical Engine)
• Other additional downloadable JSR-223 script engines (see https://scripting.dev.java.net/)