diff --git a/src/__pycache__/configDialog.cpython-312.pyc b/src/__pycache__/configDialog.cpython-312.pyc index d01d209..4130735 100644 Binary files a/src/__pycache__/configDialog.cpython-312.pyc and b/src/__pycache__/configDialog.cpython-312.pyc differ diff --git a/src/__pycache__/graph.cpython-312.pyc b/src/__pycache__/graph.cpython-312.pyc index 65f0f04..fc81c94 100644 Binary files a/src/__pycache__/graph.cpython-312.pyc and b/src/__pycache__/graph.cpython-312.pyc differ diff --git a/src/__pycache__/renderer.cpython-312.pyc b/src/__pycache__/renderer.cpython-312.pyc index 3a6b49c..1d9066b 100644 Binary files a/src/__pycache__/renderer.cpython-312.pyc and b/src/__pycache__/renderer.cpython-312.pyc differ diff --git a/src/__pycache__/sim.cpython-312.pyc b/src/__pycache__/sim.cpython-312.pyc index ac4f2e9..b10fbd8 100644 Binary files a/src/__pycache__/sim.cpython-312.pyc and b/src/__pycache__/sim.cpython-312.pyc differ diff --git a/src/__pycache__/window.cpython-312.pyc b/src/__pycache__/window.cpython-312.pyc index 8da0f7d..997e303 100644 Binary files a/src/__pycache__/window.cpython-312.pyc and b/src/__pycache__/window.cpython-312.pyc differ diff --git a/src/configDialog.py b/src/configDialog.py index bddac56..471ab15 100644 --- a/src/configDialog.py +++ b/src/configDialog.py @@ -22,7 +22,7 @@ def initForms(self): self.acceLabel = widgets.QLabel() self.acceLabel.setText("Aceleração") self.acceIn = widgets.QLineEdit() - self.acceIn.setText(obj.acce.__str__()) + self.acceIn.setText(sum(obj.acce).__str__()) self.time0Label = widgets.QLabel() self.time0Label.setText("Tempo Inicial") @@ -101,6 +101,7 @@ def updateStuff(self): self.parent.AGraph.setPlot(t, a) self.parent.VGraph.setPlot(t, v) self.parent.gScene.sim = obj + self.parent.nodeDialog.sim = obj self.parent.reset() self.parent.timer.start() self.close() diff --git a/src/graph.py b/src/graph.py index 413a500..18c47b0 100644 --- a/src/graph.py +++ b/src/graph.py @@ -127,7 +127,7 @@ def update(self): if(ymax == 0): ymod = 0.13 elif(min(self.y)) < 0 and (max(self.y) > 0): - ymod = (ymax) + abs(min(self.y)) + ymod = max(self.y) + abs(min(self.y)) elif(abs(max(self.y)) == abs(min(self.y))): ymod = ymax else: diff --git a/src/nodeDialog.py b/src/nodeDialog.py new file mode 100644 index 0000000..e2db363 --- /dev/null +++ b/src/nodeDialog.py @@ -0,0 +1,67 @@ +import PyQt6.QtWidgets as widgets +import PyQt6.QtGui as gui +from data import Data +import graph + +class NodeDialog(widgets.QDialog): + def __init__(self, parent, simu): + super().__init__() + self._main = widgets.QWidget(self) + self.mainLayout = widgets.QFormLayout(self._main) + self.sim = simu + self.parent = parent + self.setWindowTitle("Noder 3000") + self.initForms() + + def initForms(self): + self.acceLabel = widgets.QLabel() + self.acceLabel.setText("Aceleração") + self.acceIn = widgets.QLineEdit() + self.acceIn.setText("0") + + self.timeFLabel = widgets.QLabel() + self.timeFLabel.setText("Intervalo") + self.timeFIn = widgets.QLineEdit() + self.timeFIn.setText(self.sim.TimeF.__str__()) + + self.submitBtn = widgets.QPushButton() + self.submitBtn.setText("Atualizar") + + + self.mainLayout.addWidget(self.acceLabel) + self.mainLayout.addWidget(self.acceIn) + + self.mainLayout.addWidget(self.timeFLabel) + self.mainLayout.addWidget(self.timeFIn) + + self.mainLayout.addWidget(self.submitBtn) + + self.submitBtn.clicked.connect(self.updateStuff) + + self.setFixedSize(165, 150) + + def updateStuff(self): + self.parent.timer.stop() + + self.sim.addNode(int(self.timeFIn.text()), int(self.acceIn.text())) + + t = [] + s = [] + a = [] + v = [] + + for dat in self.sim.dataArr: + t.append(dat.time) + s.append(dat.pos) + a.append(dat.acce) + v.append(dat.vel) + + self.parent.SGraph.setPlot(t, s) + self.parent.AGraph.setPlot(t, a) + self.parent.VGraph.setPlot(t, v) + self.parent.gScene.sim = self.sim + self.parent.reset() + self.parent.timer.start() + self.close() + + \ No newline at end of file diff --git a/src/renderer.py b/src/renderer.py index 468575a..1d10246 100644 --- a/src/renderer.py +++ b/src/renderer.py @@ -28,17 +28,21 @@ def __init__(self, parent, view, sim): def run(self): self.text.setPos((self.view.width()/2) - ((self.text.boundingRect().width()*5)/2), ((self.height()/2)) - ((self.text.boundingRect().height()) * 5)/2) - index = int(self.elapsedTime - self.sim.Time0) if int(self.elapsedTime - self.sim.Time0) < self.sim.TimeF else self.sim.TimeF - 1 + index = int(self.elapsedTime - self.sim.Time0) if int(self.elapsedTime - self.sim.Time0) < self.sim.TimeF else self.sim.TimeF + if index < 0: + index = 0 self.text.setPlainText("T={}, a={}, S={}, V={}".format(self.elapsedTime if self.elapsedTime > 0 else 0, - self.sim.acce, + self.sim.dataArr[index].acce, round(self.sim.dataArr[index].pos, 2), - self.vel)) + self.sim.dataArr[index].vel)) + if self.isRunning and self.elapsedTime < self.sim.TimeF: print("renderer: {}".format(str(self.elapsedTime))) if self.elapsedTime > self.sim.Time0: - self.vel += self.sim.acce - pos = (self.runner.x() + (self.vel)) - self.runner.setX(pos) + acce = self.sim.dataArr[index].acce + self.vel += acce + #pos = (self.runner.x() + (self.vel)) + self.runner.setX(self.sim.dataArr[index+1].pos) self.elapsedTime+= 1 self.runner.setY((self.height()/2) - 100/2) diff --git a/src/sim.py b/src/sim.py index 6bec136..3070d7b 100644 --- a/src/sim.py +++ b/src/sim.py @@ -8,7 +8,7 @@ class Simulation(): startVel = 0 currVel = 0 - acce = 0 + acce = [] startPos = 0 pos = 0 @@ -19,9 +19,14 @@ class Simulation(): def __init__(self, vel, pos, acce, time0, timeF): self.startVel = vel self.startPos = pos - self.acce = acce + self.vel = vel + self.pos = pos + self.acce = [] + self.acce = [acce] self.Time0 = time0 self.TimeF = timeF + print("TimeF= {}".format(self.TimeF)) + self.currTime = 0 self.dataArr = [] self.reset() self.run() @@ -39,13 +44,13 @@ def setPos(self, pos): #run simulation def run(self): - #self.dataArr.append(data.Data(self.startPos, self.currTime + self.Time0, self.startVel, self.acce)) + self.dataArr.append(data.Data(self.startPos, self.currTime + self.Time0, self.startVel, self.acce[0])) while self.currTime + self.Time0 < (self.TimeF): self.currTime+=1 - vel = self.startVel + self.acce*self.currTime - pos = self.startPos + self.startVel * self.currTime + (self.acce*pow(self.currTime, 2)) * 0.5 + self.vel = self.startVel + self.acce[0]*self.currTime + self.pos = self.startPos + self.startVel * self.currTime + (self.acce[0]*pow(self.currTime, 2)) * 0.5 #Amém - self.dataArr.append(data.Data(pos, self.currTime + self.Time0, vel, self.acce)) + self.dataArr.append(data.Data(self.pos, self.currTime + self.Time0, self.vel, self.acce[0])) print(self.dataArr[0].vel) #reset the simulation @@ -54,6 +59,15 @@ def reset(self): self.pos = self.startPos self.currTime = 0 - + def addNode(self, deltaT, acce): + self.acce.append(acce) + print("TimeF= {}".format(self.TimeF)) + print("deltaT= {}".format(deltaT)) + while self.currTime < (deltaT + self.TimeF): + self.currTime+=1 + self.vel += acce + self.pos += self.vel + self.dataArr.append(data.Data(self.pos, self.currTime, self.vel, acce)) + self.TimeF += deltaT obj = Simulation(0, 0, 1, 0, 50) \ No newline at end of file diff --git a/src/window.py b/src/window.py index aa68bca..129df11 100644 --- a/src/window.py +++ b/src/window.py @@ -6,6 +6,7 @@ from graph import g import sim from configDialog import ConfigDialog +from nodeDialog import NodeDialog import numpy as np @@ -101,10 +102,16 @@ def _setupConfigWidget(self): alterarBtn = QPushButton(self.ConfigWidget) alterarBtn.setText("Alterar Params") - self.configDialog = ConfigDialog(self) - configLayout.addWidget(alterarBtn) + nodeBtn = QPushButton(self.ConfigWidget) + nodeBtn.setText("Adicionar Nó") + + self.configDialog = ConfigDialog(self) + self.nodeDialog = NodeDialog(self, sim.obj) + configLayout.addWidget(alterarBtn) + configLayout.addWidget(nodeBtn) alterarBtn.clicked.connect(self.invokeCfgDialog) + nodeBtn.clicked.connect(self.invokeNodeDialog) #setup QGraphics def _setupQGraphics(self): @@ -168,6 +175,9 @@ def update(self): def invokeCfgDialog(self): self.configDialog.show() + def invokeNodeDialog(self): + self.nodeDialog.show() + qapp = QtWidgets.QApplication(sys.argv)