# SCCD2DEVS
This project focuses on the conversion of SCCD XML files into a format compatible with pypDEVS, a Python implementation of the Parallel DEVS (pypDEVS) formalism. The SCCD XML format is commonly used for describing the configuration and behavior of complex systems, while pypDEVS provides a framework for modeling and simulating discrete-event systems.

In this thesis project, we explore the process of transforming SCCD XML files into pypDEVS models, enabling seamless integration of SCCD-based system descriptions into the pDEVS simulation environment. By leveraging the capabilities of both SCCD and pypDEVS, we aim to facilitate the analysis and simulation of intricate systems, contributing to the advancement of modeling and simulation techniques in various domains.

A small documentation for the project can be found here, providing insights into the conversion methodology, implementation details, and examples of utilizing the converted models within the pypDEVS framework. Through this work, we endeavor to bridge the gap between SCCD-based system specifications and the pypDEVS simulation paradigm, fostering greater flexibility and efficiency in system analysis and design processes.

## Compiler
To compile a conforming SCCD XML file, the provided Python compiler can be used. The compiler can compile conforming SCCD models to two languages: Python and Javascript. Four platforms are supported, TODO: fill in provided platforms.

The compiler can be used from the command line as follows:
```
$python -m sccd.compiler.sccdc --help
usage: python -m sccd.compiler.sccdc [-h] [-o OUTPUT] [-v VERBOSE]
                                     [-p PLATFORM] [-l LANGUAGE]
                                     input

positional arguments:
  input                 The path to the XML file to be compiled.

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        The path to the generated code. Defaults to the same
                        name as the input file but with matching extension.
  -v VERBOSE, --verbose VERBOSE
                        2 = all output; 1 = only warnings and errors; 0 = only
                        errors; -1 = no output. Defaults to 2.
  -p PLATFORM, --platform PLATFORM
                        Let the compiled code run on top of threads, gameloop
                        , eventloop or pypDEVS. The default is eventloop. PypDEVS is only supported for python
  -l LANGUAGE, --language LANGUAGE
                        Target language, either "javascript" or "python".
                        Defaults to the latter.
```

## Runtime Platforms

### PypDEVS
The ```PypDEVS``` platform works only in the Python language. The platform works both with and without combination of a UI system that allows for scheduling events. Default implementations are provided for the Tkinter UI library on Python.

## Examples
All of the examples need two files: A ```runner.py``` and a ```target.py```. The target is generated by the compiler and the runner needs to be made seperatelly.

### BouncingBalls
To compile the ```BouncingBalls```example, run the following command

```
python3 sccds.py -o "./examples/BouncingBalls/PyDEVS/target.py" -p "pypDEVS" "./examples/BouncingBalls/sccd.xml"
```

This will generate a target for the runner which can be composed as follows:

```
from pypdevs.simulator import Simulator
import target as target

from tkinter import *
from sccd.runtime.libs.ui_v2 import UI

class OutputListener:
	def __init__(self, ui):
		self.ui = ui

	def add(self, event):
		if event.port == "ui":
			method = getattr(self.ui, event.name)
			method(*event.parameters)

if __name__ == '__main__':
	model = target.Controller(name="controller")
	refs = {"ui": model.ui, "field_ui": model.atomic1.field_ui}

	tkroot = Tk()
	tkroot.withdraw()
	sim = Simulator(model)
	sim.setRealTime(True)
	sim.setRealTimeInputFile(None)
	sim.setRealTimePorts(refs)
	sim.setVerbose(None)
	sim.setRealTimePlatformTk(tkroot)


	#controller = target.Controller(TkEventLoop(tkroot))
	ui = UI(tkroot, "controller")
	#controller.addMyOwnOutputListener(OutputListener(ui))
	#controller.start()
	sim.simulate()
	tkroot.mainloop()
```

To finally run the sccd in pypDEVS, run the following command:
```
python3 runner.py
```

### Timer

## TODO


## TO ASK
1) De tests van bouncingballs --> server was down/traag gisteren
2) Destroy all verwijdert alles maar simulatie stopt niet --> setTerminationCondition(condition)?
3) FixedTimerThread werkt niet in DEVS, gevalvan threading ipv Eventloop
4) if earliest_event_time == INFINITY:
		if self.finished_callback: self.finished_callback() # TODO: This is not necessarily correct (keep_running necessary?)
        	return
Dit gebeurd in sccd soms maar als dit gebeurd in DEVS dan betekend dit dat er een event kan zijn 
6) Hans example --> Bouncing Elevator Balls
