Skip to content

Usage for own diagram

bliznjan edited this page May 11, 2015 · 1 revision

##Using simulation for own diagram

1) Create class structure

Create simulator class for each non-abstract model class. For example, for DCPetriNet, which is subclass of DCDiagram, make DCPetriNetSimulator as subclass of DCDiagramSimulator. Another example, for DCPetriNetTransition, which is subclass of DCNamedElement, make DCPetriNetSimulator as subclass of DCElementSimulator. Also define subclass of DCSimulationGUI if you want to use simulation with DynaCASE itself and not only model.

2) Define all mandatory methods.

For all simulators define isSimulable, which tells whether there is any possibility to be directly simulated as active element and answer should be always true or always false.
For all simulators define isSteppable, which answers false if isSimulable is false, or answer whether it can be directly stepped right now.

For simulator whose content changes by simulation define loadState method, which should call super loadState and then replace current model content by content in variable startingModel.

For simulable simulators (those which can be actively stepped) define setDefaultStepping method. It should call super setDefaultStepping and then call desired combination of methods from stepping protocol (method category). Look into these categories in all simulators to learn what they do.

In subclass of DCDiagramSimulator define initializeClassMapping, which calls super initializeClassMapping and then adds to variable ClassMapping, which is Dictionary, model classes as keys with according simulator classes as values. Insert only non-abstract subclasses of DCElementSimulator.

In DCSimulationGUI subclass, define following:

  1. CLASS method initialize, which should just call super initialize.
  2. CLASS method simulableControllerClasses, which should return collection of controllers of elements, which can be directly stepped. For example transition controller in Petri nets.
  3. CLASS method controllerClass, which should return correct subclass of DCDiagramController, for example DCPetriNetController
  4. method simulatorClass, which should return correct subclass of DCDiagramSimulator, for example DCPetriNetSimulator

In DCSimulationGUI subclass, you can also define loadSimulation, which calls super loadSimulation and then executes own code when simulation is being prepared.
You can also define method buttonItems, which returns collection of blocks for creating buttons in simulation GUI. You need to get buttons from super buttonItems, add you buttons to it, and return this expanded collection.

Clone this wiki locally