Skip to content

Commit

Permalink
add graph nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgumCorrupto committed Apr 14, 2024
1 parent 3cf5bf6 commit a65def8
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 17 deletions.
Binary file modified src/__pycache__/configDialog.cpython-312.pyc
Binary file not shown.
Binary file modified src/__pycache__/graph.cpython-312.pyc
Binary file not shown.
Binary file modified src/__pycache__/renderer.cpython-312.pyc
Binary file not shown.
Binary file modified src/__pycache__/sim.cpython-312.pyc
Binary file not shown.
Binary file modified src/__pycache__/window.cpython-312.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion src/configDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
67 changes: 67 additions & 0 deletions src/nodeDialog.py
Original file line number Diff line number Diff line change
@@ -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()


16 changes: 10 additions & 6 deletions src/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
28 changes: 21 additions & 7 deletions src/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Simulation():

startVel = 0
currVel = 0
acce = 0
acce = []

startPos = 0
pos = 0
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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)
14 changes: 12 additions & 2 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from graph import g
import sim
from configDialog import ConfigDialog
from nodeDialog import NodeDialog

import numpy as np

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -168,6 +175,9 @@ def update(self):

def invokeCfgDialog(self):
self.configDialog.show()
def invokeNodeDialog(self):
self.nodeDialog.show()



qapp = QtWidgets.QApplication(sys.argv)
Expand Down

0 comments on commit a65def8

Please sign in to comment.