config.py 4.56 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
        self.particle_random_order_always = config.getboolean("Simulator", "particle_random_order_always")
16
17
18
        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
19
20
21
22
        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
23
            print("no gui option given. setting to default \"gui.py\"")
Karol Actun's avatar
Karol Actun committed
24
25
            self.gui = "gui.py"

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

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

Karol Actun's avatar
Karol Actun committed
36
37
        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
38
39
40

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

        self.particle_color = make_tuple(config.get("Visualization", "particle_color"))
        self.tile_color = make_tuple(config.get("Visualization", "tile_color"))
45
        self.location_color = make_tuple(config.get("Visualization", "location_color"))
Karol Actun's avatar
Karol Actun committed
46
        self.grid_color = make_tuple(config.get("Visualization", "grid_color"))
Karol Actun's avatar
Karol Actun committed
47
48
49
50
51
52
        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")
53
54
55
        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
56
57
58
59
60
61
62
63
64
65
66
        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
67

68
69
70
71
72
73
74
75
        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")
76
        self.location_mm_size = config.getint("Matter", "location_mm_size")
77

78
79
80
81
82
83
84
85
86
        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"
87

Karol Actun's avatar
Karol Actun committed
88

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