-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimulation.py
93 lines (70 loc) · 2.84 KB
/
Simulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
from PyQt5 import QtCore, QtWidgets
from computation.torque import TorqueFile, IncompleteFile
from computation.geometry import Geom
from qt_error_handling import python_exception_dialog
class NoSimulationParamsFile:
pass
class Simulation(QtCore.QObject):
sigUpdateProgress = QtCore.pyqtSignal()
sigLoaded = QtCore.pyqtSignal()
sigUpdateLabel = QtCore.pyqtSignal(str)
def __init__(self, parent, geo_file, params=None):
super(Simulation, self).__init__(parent)
self._geom = None
self.geo_file_name = geo_file
self.loaded = False
self._label = None
self.__sig_emitDataChanged = None
ThreadLoader(self, self).start()
# progress update timer
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.sigUpdateProgress.emit)
self.timer.start(4000)
self.sigLoaded.connect(lambda: [self.timer.stop(), self.sigUpdateProgress.emit()])
torque_file = os.path.join(os.path.dirname(geo_file), 'TORQUE.csv')
if os.path.isfile(torque_file):
self._torque = TorqueFile(torque_file, params=params)
try:
self._torque.read()
except IncompleteFile:
QtWidgets.QMessageBox.information(None, "Warning",
"Incomplete torque file. Only available data will be considered.",
QtWidgets.QMessageBox.Ok)
except Exception as err:
python_exception_dialog(err, parent)
else:
self._torque = None
def connect_signals_to_item(self, item):
self.__sig_emitDataChanged = item.emitDataChanged
self.sigUpdateProgress.connect(self.__sig_emitDataChanged)
def disconnect_signals_from_item(self):
if self.__sig_emitDataChanged is not None:
self.sigUpdateProgress.disconnect(self.__sig_emitDataChanged)
def torque(self):
return self._torque
def geom(self):
return self._geom
def load(self):
self._geom = Geom(self.geo_file_name)
self._geom.load()
self.loaded = True
self.sigLoaded.emit()
self._geom.geo.cache()
def progress(self):
if self._geom is not None and self._geom.geo is not None:
return self._geom.geo.progress, self._geom.geo.progress_total
else:
return None, None
def set_label(self, label):
self._label = label
self.sigUpdateLabel.emit(label)
def label(self):
return self._label
# creates the simulation Geom object (including loading the file) in a seperate thread
class ThreadLoader(QtCore.QThread):
def __init__(self, parent, load_obj):
QtCore.QThread.__init__(self, parent)
self.load_obj = load_obj
def run(self):
self.load_obj.load()