From 06b0f0caf11f4658a5d44be901075ba51a941eb5 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 19 Feb 2022 19:03:24 +0100 Subject: [PATCH] toc --- README.md | 43 +++++++++++++++++++++-- mainPainter.md | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 mainPainter.md diff --git a/README.md b/README.md index 54b396c..6853a7c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,42 @@ -# Traffic -conf Peip \ No newline at end of file +* [DOCUMENTATION](DOC.md#documentation) + * [Reseau routier .net.xml de SUMO](DOC.md#reseau-routier-netxml-de-sumo) + * [Edge](DOC.md#edge) + * [Lane](DOC.md#lane) + * [Junction/Node](DOC.md#junctionnode) + * [Compilation](DOC.md#compilation) + * [Pour generer les classes de l'ui à partir des .ui de Qt Designer](DOC.md#pour-generer-les-classes-de-lui-à-partir-des-ui-de-qt-designer) + * [Pour faire un executable](DOC.md#pour-faire-un-executable) + +* [mainLoop.py](mainLoop.md#mainlooppy) + * [imports](mainLoop.md#imports) + * [classe mainLoop](mainLoop.md#classe-mainloop) + * [__init__](mainLoop.md#__init__) + * [start](mainLoop.md#start) + * [update](mainLoop.md#update) + * [openNetwork](mainLoop.md#opennetwork) + * [openVehicles](mainLoop.md#openvehicles) + * [quickLoad](mainLoop.md#quickload) + * [updateFps](mainLoop.md#updatefps) + +* [main.py](main.md#mainpy) + * [Imports](main.md#imports) + * [Classe MainWindow](main.md#classe-mainwindow) + * [__init__](main.md#__init__) + * [keyPressEvent](main.md#keypressevent) + * [updateFPS](main.md#updatefps) + * [updatePhysicsFps](main.md#updatephysicsfps) + * [openNetwork](main.md#opennetwork) + * [openVehicle](main.md#openvehicle) + * [main](main.md#main) + +* [mainPainter.py](mainPainter.md#mainpainterpy) + * [Imports](mainPainter.md#imports) + * [mainPainter](mainPainter.md#mainpainter) + * [__init__](mainPainter.md#__init__) + * [addMap](mainPainter.md#addmap) + * [addCarController](mainPainter.md#addcarcontroller) + * [generateTransform](mainPainter.md#generatetransform) + * [resizeGL](mainPainter.md#resizegl) + * [paintEvent](mainPainter.md#paintevent) + diff --git a/mainPainter.md b/mainPainter.md new file mode 100644 index 0000000..7be7782 --- /dev/null +++ b/mainPainter.md @@ -0,0 +1,92 @@ +# mainPainter.py +La classe qui gére l'affichage (de la partie principale, pas les ui d'infos) + +## Imports +Comme d'hab les imports de Qt + +```python +from PySide6.QtOpenGLWidgets import QOpenGLWidget +from PySide6.QtCore import Qt, QThread +from PySide6.QtGui import QPainter, QFont, QColor, QTransform, QOpenGLContext, QOpenGLFunctions +from PySide6 import QtOpenGL +``` + +## mainPainter +La classe principale, c'est un sous-classe de QOpenGLWidget + +```python +class mainPainter(QOpenGLWidget): +``` + +## \_\_init\_\_ +Notre initialisation, on récupère les deux classe de la carte et des voitures parce que c'est eux qui sont responsables de leurs affichage. +Le QTransform sert à calculer/stocker la transformation pour passer de coordonnées dans le monde réél-\>coords sur l'écran + +```python + def __init__(self, parent=None): + super(mainPainter, self).__init__(parent) + + self.map = None + self.carController = None + self.transform = QTransform() +``` + +## addMap +Juste un fonction pour passer la carte, on pourrait probablement le faire passer dans le constructeur plutôt + +```python + def addMap(self, netMap): + self.map = netMap +``` + +## addCarController +Comme [addMap](#addMap) + +```python + def addCarController(self, cc): + self.carController = cc +``` + +## generateTransform +La fonction qui genere la transformation monde-\>écran. +On récupere les limites du réseau, puis on translate/scale en fonction +Pour avoir un peu de marge on rajoute 10 de tout les côtés +Comme l'origine est en haut à gauche et les y decroissant on scale de -1 sur y pour remettre l'image à l'endroit + +```python + def generateTransform(self): + bounds = self.map.getBounds() + if(bounds is None): + return + bounds[0] = list(map(lambda b: b-10,bounds[0])) + bounds[1] = list(map(lambda b: b+10, bounds[1])) + self.transform.reset() + tr = QTransform() + tr.translate(-bounds[0][0],-bounds[0][1]) + scale=min(self.width()/(bounds[1][0]-bounds[0][0]),self.height()/(bounds[1][1]-bounds[0][1])) + sc = QTransform() + sc.scale(scale,-scale) + self.transform = tr * sc * QTransform(1, 0, 0, 1, 0, self.height()) +``` + +## resizeGL +Fonction appelé quand le widget est redimensionné (ça inclut la création), le cas échéant on recalcule la transformation avec la nouvelle taille + +```python + def resizeGL(self,w,h): + self.generateTransform() +``` + +## paintEvent +Fonction appelé à chaque appel sur update. +On crée notre QPainter, on active l'anti-aliasing (marche pas en openGL apparement), on clear l'écran, on applique la transformation et on demande à notre carte et nos voitures de se dessiner. + +```python + def paintEvent(self, e): + painter = QPainter(self) + painter.RenderHint(QPainter.Antialiasing) + painter.eraseRect(e.rect()); + painter.setTransform(self.transform) + self.map.draw(painter) + self.carController.draw(painter) +```