import
This commit is contained in:
parent
e0132fa617
commit
d72d720f22
@ -5,8 +5,17 @@ class CarController:
|
|||||||
def __init__(self,parentMap):
|
def __init__(self,parentMap):
|
||||||
self.map=parentMap
|
self.map=parentMap
|
||||||
self.cars=[]
|
self.cars=[]
|
||||||
|
self.path = None
|
||||||
|
|
||||||
def fromPath(self,path):
|
def setPath(self,path):
|
||||||
|
self.path = path
|
||||||
|
|
||||||
|
def fromPath(self,path=None):
|
||||||
|
if(path == None):
|
||||||
|
if(self.path == None):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
path = self.path
|
||||||
for vehicle in sumolib.xml.parse(path,"vehicle"):
|
for vehicle in sumolib.xml.parse(path,"vehicle"):
|
||||||
route=vehicle.route[0].edges.split()
|
route=vehicle.route[0].edges.split()
|
||||||
self.cars.append(Car(vehicle.id,route,self.map,self))
|
self.cars.append(Car(vehicle.id,route,self.map,self))
|
||||||
|
17
Map.py
17
Map.py
@ -10,10 +10,22 @@ class Map:
|
|||||||
def __init__(self,path=None):
|
def __init__(self,path=None):
|
||||||
if path!=None:
|
if path!=None:
|
||||||
self.fromPath(path)
|
self.fromPath(path)
|
||||||
|
self.net = None
|
||||||
|
|
||||||
def fromPath(self,path):
|
def fromPath(self,path):
|
||||||
self.net = sumolib.net.readNet(path,withInternal=True,withConnections=True)
|
self.net = sumolib.net.readNet(path,withInternal=True,withConnections=True)
|
||||||
|
|
||||||
|
def isLoaded(self):
|
||||||
|
return not (self.net == None)
|
||||||
|
|
||||||
|
def safeCall(func):
|
||||||
|
def inner(*args, **kwargs):
|
||||||
|
if not args[0].isLoaded():
|
||||||
|
return
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
return inner
|
||||||
|
|
||||||
|
@safeCall
|
||||||
def draw(self, painter):
|
def draw(self, painter):
|
||||||
for edge in self.net.getEdges():
|
for edge in self.net.getEdges():
|
||||||
color=Qt.white
|
color=Qt.white
|
||||||
@ -25,18 +37,23 @@ class Map:
|
|||||||
poly = QPolygonF.fromList(pts)
|
poly = QPolygonF.fromList(pts)
|
||||||
painter.drawPolyline(poly)
|
painter.drawPolyline(poly)
|
||||||
|
|
||||||
|
@safeCall
|
||||||
def getEdge(self,edgeID):
|
def getEdge(self,edgeID):
|
||||||
return self.net.getEdge(edgeID)
|
return self.net.getEdge(edgeID)
|
||||||
|
|
||||||
|
@safeCall
|
||||||
def getNode(self,nodeID):
|
def getNode(self,nodeID):
|
||||||
return self.net.getNode(nodeID)
|
return self.net.getNode(nodeID)
|
||||||
|
|
||||||
|
@safeCall
|
||||||
def getLane(self,laneID):
|
def getLane(self,laneID):
|
||||||
return self.net.getLane(laneID)
|
return self.net.getLane(laneID)
|
||||||
|
|
||||||
|
@safeCall
|
||||||
def getBounds(self):
|
def getBounds(self):
|
||||||
return self.net.getBBoxXY()
|
return self.net.getBBoxXY()
|
||||||
|
|
||||||
|
@safeCall
|
||||||
def convertPos(self,pos):
|
def convertPos(self,pos):
|
||||||
bounds=self.net.getBoundary()
|
bounds=self.net.getBoundary()
|
||||||
bounds[0]-=200
|
bounds[0]-=200
|
||||||
|
23
main.py
23
main.py
@ -8,7 +8,7 @@ else:
|
|||||||
|
|
||||||
from PySide6.QtCore import Qt, QTimer
|
from PySide6.QtCore import Qt, QTimer
|
||||||
from PySide6.QtWidgets import QApplication, QMainWindow
|
from PySide6.QtWidgets import QApplication, QMainWindow
|
||||||
from PySide6.QtGui import QSurfaceFormat
|
from PySide6.QtGui import QSurfaceFormat, QAction
|
||||||
from window import Ui_MainWindow
|
from window import Ui_MainWindow
|
||||||
|
|
||||||
from mainLoop import mainLoop
|
from mainLoop import mainLoop
|
||||||
@ -19,7 +19,23 @@ class MainWindow(QMainWindow):
|
|||||||
self.ui = Ui_MainWindow()
|
self.ui = Ui_MainWindow()
|
||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
|
|
||||||
self.mainLoop = mainLoop(self.ui.mainSurf)
|
self.setAttribute(Qt.WA_TranslucentBackground)
|
||||||
|
self.setAttribute(Qt.WA_NoSystemBackground, False)
|
||||||
|
|
||||||
|
self.mainLoop = mainLoop(self)
|
||||||
|
|
||||||
|
fileMenu = self.menuBar().addMenu("&File")
|
||||||
|
openMenu = fileMenu.addMenu("&Open")
|
||||||
|
|
||||||
|
openNet = QAction("&Open Network",self)
|
||||||
|
openNet.setStatusTip("Open Network file (.net.xml)")
|
||||||
|
openNet.triggered.connect(self.mainLoop.openNetwork)
|
||||||
|
openMenu.addAction(openNet)
|
||||||
|
|
||||||
|
openVeh = QAction("&Open Vehicles",self)
|
||||||
|
openVeh.setStatusTip("Open Vehicle description (.rou.xml)")
|
||||||
|
openVeh.triggered.connect(self.mainLoop.openVehicles)
|
||||||
|
openMenu.addAction(openVeh)
|
||||||
|
|
||||||
timer = QTimer(self)
|
timer = QTimer(self)
|
||||||
timer.timeout.connect(self.mainLoop.update)
|
timer.timeout.connect(self.mainLoop.update)
|
||||||
@ -34,9 +50,8 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
format = QSurfaceFormat()
|
format = QSurfaceFormat()
|
||||||
format.setDepthBufferSize(24)
|
format.setDepthBufferSize(24)
|
||||||
format.setStencilBufferSize(8)
|
|
||||||
format.setVersion(3, 2)
|
format.setVersion(3, 2)
|
||||||
format.setSamples(16)
|
format.setSamples(4)
|
||||||
format.setProfile(QSurfaceFormat.CoreProfile)
|
format.setProfile(QSurfaceFormat.CoreProfile)
|
||||||
QSurfaceFormat.setDefaultFormat(format)
|
QSurfaceFormat.setDefaultFormat(format)
|
||||||
|
|
||||||
|
27
mainLoop.py
27
mainLoop.py
@ -1,15 +1,16 @@
|
|||||||
from Map import Map
|
from Map import Map
|
||||||
from CarController import CarController
|
from CarController import CarController
|
||||||
|
|
||||||
|
from PySide6.QtWidgets import QFileDialog
|
||||||
|
|
||||||
class mainLoop():
|
class mainLoop():
|
||||||
def __init__(self, painter):
|
def __init__(self, parent):
|
||||||
self.painter = painter
|
self.parent = parent
|
||||||
|
self.painter = parent.ui.mainSurf
|
||||||
|
|
||||||
self.map = Map()
|
self.map = Map()
|
||||||
self.map.fromPath("test2.net.xml")
|
|
||||||
|
|
||||||
self.controller = CarController(self.map)
|
self.controller = CarController(self.map)
|
||||||
self.controller.fromPath("test5.rou.xml")
|
|
||||||
|
|
||||||
self.painter.addMap(self.map)
|
self.painter.addMap(self.map)
|
||||||
self.painter.addCarController(self.controller)
|
self.painter.addCarController(self.controller)
|
||||||
@ -17,3 +18,21 @@ class mainLoop():
|
|||||||
def update(self):
|
def update(self):
|
||||||
self.controller.update()
|
self.controller.update()
|
||||||
self.painter.update()
|
self.painter.update()
|
||||||
|
|
||||||
|
def openNetwork(self):
|
||||||
|
fileName = QFileDialog.getOpenFileName(self.parent,"Open Network", "./", "Network File (*.net.xml)")
|
||||||
|
if(fileName[0] == ''):
|
||||||
|
return
|
||||||
|
self.map.fromPath(fileName[0])
|
||||||
|
self.painter.generateTransform()
|
||||||
|
|
||||||
|
self.controller.fromPath()
|
||||||
|
|
||||||
|
def openVehicles(self):
|
||||||
|
fileName = QFileDialog.getOpenFileName(self.parent,"Open Vehicle trip description", "./", "Route File (*.rou.xml)")
|
||||||
|
if(fileName[0] == ''):
|
||||||
|
return
|
||||||
|
self.controller.setPath(fileName[0])
|
||||||
|
if(self.map.isLoaded()):
|
||||||
|
self.controller.fromPath()
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
from PySide6.QtOpenGLWidgets import QOpenGLWidget
|
from PySide6.QtOpenGLWidgets import QOpenGLWidget
|
||||||
from PySide6.QtCore import Qt
|
from PySide6.QtCore import Qt
|
||||||
from PySide6.QtGui import QPainter, QFont, QColor, QTransform
|
from PySide6.QtGui import QPainter, QFont, QColor, QTransform, QOpenGLContext, QOpenGLFunctions
|
||||||
|
from PySide6 import QtOpenGL
|
||||||
|
|
||||||
class mainPainter(QOpenGLWidget):
|
class mainPainter(QOpenGLWidget):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(mainPainter, self).__init__(parent)
|
super(mainPainter, self).__init__(parent)
|
||||||
|
|
||||||
self.map = None
|
self.map = None
|
||||||
self.carController = None
|
self.carController = None
|
||||||
self.transform = QTransform()
|
self.transform = QTransform()
|
||||||
@ -17,6 +19,8 @@ class mainPainter(QOpenGLWidget):
|
|||||||
|
|
||||||
def generateTransform(self):
|
def generateTransform(self):
|
||||||
bounds = self.map.getBounds()
|
bounds = self.map.getBounds()
|
||||||
|
if(bounds == None):
|
||||||
|
return
|
||||||
bounds[0] = list(map(lambda b: b-10,bounds[0]))
|
bounds[0] = list(map(lambda b: b-10,bounds[0]))
|
||||||
bounds[1] = list(map(lambda b: b+10, bounds[1]))
|
bounds[1] = list(map(lambda b: b+10, bounds[1]))
|
||||||
self.transform.reset()
|
self.transform.reset()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user