config.py 4.46 KB
Newer Older
1
2
import configparser
from datetime import datetime
Karol Actun's avatar
Karol Actun committed
3
from ast import literal_eval as make_tuple
Karol Actun's avatar
Karol Actun committed
4
5
import importlib

6
7
8
9
10
11
12
13

class ConfigData:

    def __init__(self):
        config = configparser.ConfigParser(allow_no_value=True)
        config.read("config.ini")
        self.seed_value = config.getint("Simulator", "seedvalue")
        self.max_round = config.getint("Simulator", "max_round")
Ahmad Reza's avatar
Ahmad Reza committed
14
        self.particle_random_order = config.getboolean("Simulator", "particle_random_order")
15
16
17
        self.window_size_x = config.getint("Simulator", "window_size_x")
        self.window_size_y = config.getint("Simulator", "window_size_y")

Karol Actun's avatar
Karol Actun committed
18
19
20
21
        self.visualization = config.getint("Visualization", "visualization")
        try:
            self.gui = config.get("Visualization", "gui")
        except configparser.NoOptionError as noe:
Karol Actun's avatar
Karol Actun committed
22
            print("no gui option given. setting to default \"gui.py\"")
Karol Actun's avatar
Karol Actun committed
23
24
            self.gui = "gui.py"

Karol Actun's avatar
Karol Actun committed
25
        try:
Karol Actun's avatar
Karol Actun committed
26
            self.grid_class = config.get("Visualization", "grid_class")
Karol Actun's avatar
Karol Actun committed
27
28
29
30
        except configparser.NoOptionError as noe:
            raise RuntimeError("Fatal Error: no grid class defined in config.ini!")

        try:
Karol Actun's avatar
Karol Actun committed
31
            self.grid_size = config.getint("Visualization", "grid_size")
Karol Actun's avatar
Karol Actun committed
32
33
34
        except configparser.NoOptionError as noe:
            raise RuntimeError("Fatal Error: no grid size defined in config.ini!")

Karol Actun's avatar
Karol Actun committed
35
36
        test = getattr(importlib.import_module("grids.%s" % self.grid_class), self.grid_class)
        self.grid = test(self.grid_size)
Karol Actun's avatar
Karol Actun committed
37
38
39

        self.particle_model_file = config.get("Visualization", "particle_model_file")
        self.tile_model_file = config.get("Visualization", "tile_model_file")
40
        self.location_model_file = config.get("Visualization", "location_model_file")
Karol Actun's avatar
Karol Actun committed
41
42
43

        self.particle_color = make_tuple(config.get("Visualization", "particle_color"))
        self.tile_color = make_tuple(config.get("Visualization", "tile_color"))
44
        self.location_color = make_tuple(config.get("Visualization", "location_color"))
Karol Actun's avatar
Karol Actun committed
45
        self.grid_color = make_tuple(config.get("Visualization", "grid_color"))
Karol Actun's avatar
Karol Actun committed
46
47
48
49
50
51
        self.cursor_color = make_tuple(config.get("Visualization", "cursor_color"))
        self.background_color = make_tuple(config.get("Visualization", "background_color"))
        self.center_color = make_tuple(config.get("Visualization", "center_color"))
        self.line_color = make_tuple(config.get("Visualization", "line_color"))
        self.line_scaling = make_tuple(config.get("Visualization", "line_scaling"))
        self.show_lines = config.getboolean("Visualization", "show_lines")
52
53
54
        self.coordinates_color = make_tuple(config.get("Visualization", "coordinates_color"))
        self.coordinates_scaling = make_tuple(config.get("Visualization", "coordinates_scaling"))
        self.show_coordinates = config.getboolean("Visualization", "show_coordinates")
Karol Actun's avatar
Karol Actun committed
55
56
57
58
59
60
61
62
63
64
65
        self.show_center = config.getboolean("Visualization", "show_center")
        self.focus_color = make_tuple(config.get("Visualization", "focus_color"))
        self.show_focus = config.getboolean("Visualization", "show_focus")

        self.look_at = make_tuple(config.get("Visualization", "look_at"))
        self.phi = config.getint("Visualization", "phi")
        self.theta = config.getint("Visualization", "theta")
        self.radius = config.getint("Visualization", "radius")
        self.fov = config.getint("Visualization", "fov")
        self.cursor_offset = config.getint("Visualization", "cursor_offset")
        self.render_distance = config.getint("Visualization", "render_distance")
Karol Actun's avatar
Karol Actun committed
66

67
68
69
70
71
72
73
74
        self.size_x = config.getfloat("World", "size_x")
        self.size_y = config.getfloat("World", "size_y")
        self.border = config.getboolean("World", "border")
        self.max_particles = config.getint("World", "max_particles")

        self.memory_limitation = config.getboolean("Matter", "memory_limitation")
        self.particle_mm_size = config.getint("Matter", "particle_mm_size")
        self.tile_mm_size = config.getint("Matter", "tile_mm_size")
75
        self.location_mm_size = config.getint("Matter", "location_mm_size")
76

77
78
79
80
81
82
83
84
85
        try:
            self.scenario = config.get("File", "scenario")
        except configparser.NoOptionError as noe:
            self.scenario = "init_scenario.py"

        try:
            self.solution = config.get("File", "solution")
        except configparser.NoOptionError as noe:
            self.solution = "solution.py"
86

Karol Actun's avatar
Karol Actun committed
87

88
89
        self.local_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')[:-1]
        self.multiple_sim = 0