camelCase

This commit is contained in:
Daniel Carta
2024-07-03 17:44:46 -06:00
parent b8829b31f1
commit ae8894a751
3 changed files with 236 additions and 233 deletions
Vendored
BIN
View File
Binary file not shown.
+53 -38
View File
@@ -6,34 +6,34 @@ from PySide6.QtGui import QPixmap, QMouseEvent, QPainter, QPen, QColor, QPainter
from PySide6.QtCore import Qt, QPoint, QRect from PySide6.QtCore import Qt, QPoint, QRect
class ButtonEditor(QMainWindow): class ButtonEditor(QMainWindow):
def __init__(self, path_planner): def __init__(self, pathPlanner):
super().__init__() super().__init__()
self.setWindowTitle("Button Editor") self.setWindowTitle("Button Editor")
self.path_planner = path_planner self.pathPlanner = pathPlanner
self.image_label = QLabel(self) self.imageLabel = QLabel(self)
script_dir = os.path.dirname(os.path.abspath(__file__)) scriptDir = os.path.dirname(os.path.abspath(__file__))
image_path = os.path.join(script_dir, "images", "Field.png") imagePath = os.path.join(scriptDir, "images", "Field.png")
self.pixmap = QPixmap(image_path) self.pixmap = QPixmap(imagePath)
if self.pixmap.isNull(): if self.pixmap.isNull():
self.image_label.setText(f"Image not found at: {image_path}") self.imageLabel.setText(f"Image not found at: {imagePath}")
else: else:
self.image_label.setPixmap(self.pixmap) self.imageLabel.setPixmap(self.pixmap)
self.path_planner_button = QPushButton("Main Window") self.pathPlannerButton = QPushButton("Main Window")
self.path_planner_button.clicked.connect(self.show_path_planner) self.pathPlannerButton.clicked.connect(self.showPathPlanner)
self.button_editor_button = QPushButton("Button Editor") self.buttonEditorButton = QPushButton("Button Editor")
self.button_editor_button.clicked.connect(self.show_button_editor) self.buttonEditorButton.clicked.connect(self.showButtonEditor)
button_layout = QHBoxLayout() buttonLayout = QHBoxLayout()
button_layout.addWidget(self.path_planner_button) buttonLayout.addWidget(self.pathPlannerButton)
button_layout.addWidget(self.button_editor_button) buttonLayout.addWidget(self.buttonEditorButton)
layout = QVBoxLayout() layout = QVBoxLayout()
layout.addLayout(button_layout) layout.addLayout(buttonLayout)
layout.addWidget(self.image_label) layout.addWidget(self.imageLabel)
container = QWidget() container = QWidget()
container.setLayout(layout) container.setLayout(layout)
@@ -41,30 +41,45 @@ class ButtonEditor(QMainWindow):
self.resize(self.pixmap.width(), self.pixmap.height() + 60) self.resize(self.pixmap.width(), self.pixmap.height() + 60)
def show_button_editor(self): # Variables
self.matchLength = 15
self.TPS = 50
self.matchTicks = self.matchLength * self.TPS
self.displayTickResolution = 4
self.displayTicks = round(self.matchTicks / self.displayTickResolution)
self.keyFrames = []
def addKeyFrames(self):
currentFrame = 0
for i in range(0, self.displayTicks):
self.keyFrames.append(currentFrame)
def showButtonEditor(self):
self.show() self.show()
self.path_planner.hide() self.pathPlanner.hide()
def show_path_planner(self): def showPathPlanner(self):
self.hide() self.hide()
self.path_planner.show() self.pathPlanner.show()
def update_scene(self): def updateScene(self):
self.pixmap = QPixmap(os.path.join(os.path.dirname(os.path.abspath(__file__)), "images", "Field.png")) self.pixmap = QPixmap(os.path.join(os.path.dirname(os.path.abspath(__file__)), "images", "Field.png"))
painter = QPainter(self.pixmap) painter = QPainter(self.pixmap)
grey_pen = QPen(QColor(127, 127, 127)) greyPen = QPen(QColor(127, 127, 127))
grey_pen.setWidth(2) greyPen.setWidth(2)
painter.setPen(grey_pen) painter.setPen(greyPen)
# Draw the Bezier curve segments # Draw the Bezier curve segments
if self.path_planner.coordinates.size > 0: if self.pathPlanner.coordinates.size > 0:
for i in range(len(self.path_planner.coordinates) - 1): for i in range(len(self.pathPlanner.coordinates) - 1):
start = QPoint(self.path_planner.coordinates[i][0], self.path_planner.coordinates[i][1]) start = QPoint(self.pathPlanner.coordinates[i][0], self.pathPlanner.coordinates[i][1])
end = QPoint(self.path_planner.coordinates[i + 1][0], self.path_planner.coordinates[i + 1][1]) end = QPoint(self.pathPlanner.coordinates[i + 1][0], self.pathPlanner.coordinates[i + 1][1])
if i < len(self.path_planner.control_points): if i < len(self.pathPlanner.controlPoints):
control_pair = self.path_planner.control_points[i] controlPair = self.pathPlanner.controlPoints[i]
pen = QPen(Qt.yellow) pen = QPen(Qt.yellow)
pen.setWidth(2) pen.setWidth(2)
@@ -72,7 +87,7 @@ class ButtonEditor(QMainWindow):
path = QPainterPath() path = QPainterPath()
path.moveTo(start) path.moveTo(start)
path.cubicTo(control_pair[0], control_pair[1], end) path.cubicTo(controlPair[0], controlPair[1], end)
painter.drawPath(path) painter.drawPath(path)
# Draw the nodes # Draw the nodes
@@ -84,11 +99,11 @@ class ButtonEditor(QMainWindow):
painter.setPen(Qt.NoPen) painter.setPen(Qt.NoPen)
painter.setBrush(Qt.white) painter.setBrush(Qt.white)
for i, (x, y) in enumerate(self.path_planner.coordinates): for i, (x, y) in enumerate(self.pathPlanner.coordinates):
node_rect = QRect(x - self.path_planner.node_size // 6, y - self.path_planner.node_size // 6, nodeRect = QRect(x - self.pathPlanner.nodeSize // 6, y - self.pathPlanner.nodeSize // 6,
self.path_planner.node_size // 3, self.path_planner.node_size // 3) self.pathPlanner.nodeSize // 3, self.pathPlanner.nodeSize // 3)
painter.drawEllipse(node_rect) painter.drawEllipse(nodeRect)
painter.drawText(node_rect, Qt.AlignCenter, str(i + 1)) painter.drawText(nodeRect, Qt.AlignCenter, str(i + 1))
painter.end() painter.end()
self.image_label.setPixmap(self.pixmap) self.imageLabel.setPixmap(self.pixmap)
+183 -195
View File
@@ -14,35 +14,35 @@ class PathPlanner(QMainWindow):
self.setWindowTitle("Auto Planner") self.setWindowTitle("Auto Planner")
self.coordinates = np.empty((0, 2), dtype=int) self.coordinates = np.empty((0, 2), dtype=int)
self.control_points = [] self.controlPoints = []
self.rotation_handles = [] self.rotationHandles = []
self.node_angles = [] self.nodeAngles = []
self.image_label = QLabel(self) self.imageLabel = QLabel(self)
script_dir = os.path.dirname(os.path.abspath(__file__)) scriptDir = os.path.dirname(os.path.abspath(__file__))
image_path = os.path.join(script_dir, "images", "Field.png") imagePath = os.path.join(scriptDir, "images", "Field.png")
self.pixmap = QPixmap(image_path) self.pixmap = QPixmap(imagePath)
if self.pixmap.isNull(): if self.pixmap.isNull():
self.image_label.setText(f"Image not found at: {image_path}") self.imageLabel.setText(f"Image not found at: {imagePath}")
else: else:
self.image_label.setPixmap(self.pixmap) self.imageLabel.setPixmap(self.pixmap)
self.main_window_button = QPushButton("Main Window") self.mainWindowButton = QPushButton("Main Window")
self.main_window_button.clicked.connect(self.show_main_window) self.mainWindowButton.clicked.connect(self.showMainWindow)
self.button_editor_button = QPushButton("Button Editor") self.buttonEditorButton = QPushButton("Button Editor")
self.button_editor_button.clicked.connect(self.show_button_editor) self.buttonEditorButton.clicked.connect(self.showButtonEditor)
button_layout = QHBoxLayout() buttonLayout = QHBoxLayout()
button_layout.addWidget(self.main_window_button) buttonLayout.addWidget(self.mainWindowButton)
button_layout.addWidget(self.button_editor_button) buttonLayout.addWidget(self.buttonEditorButton)
layout = QVBoxLayout() layout = QVBoxLayout()
layout.addLayout(button_layout) layout.addLayout(buttonLayout)
layout.addWidget(self.image_label) layout.addWidget(self.imageLabel)
self.button_editor = ButtonEditor(self) self.buttonEditor = ButtonEditor(self)
container = QWidget() container = QWidget()
container.setLayout(layout) container.setLayout(layout)
@@ -52,185 +52,178 @@ class PathPlanner(QMainWindow):
self.setMouseTracking(True) self.setMouseTracking(True)
self.last_click_pos = QPoint() self.lastClickPos = QPoint()
self.coordinates = np.empty((0, 2), dtype=int) self.coordinates = np.empty((0, 2), dtype=int)
self.last_click_time = 0 self.lastClickTime = 0
self.node_size = 35 self.nodeSize = 35
self.handle_size = 15 self.handleSize = 15
self.rotation_handle_distance = 35 self.rotationHandleDistance = 35
self.control_points = [] self.controlPoints = []
self.rotation_handles = [] self.rotationHandles = []
self.node_angles = [] self.nodeAngles = []
self.dragging_control_point = False self.draggingControlPoint = False
self.dragging_node = False self.draggingNode = False
self.dragging_rotation_handle = False self.draggingRotationHandle = False
self.dragging_control_point_index = (-1, -1) self.draggingControlPointIndex = (-1, -1)
self.dragging_node_index = -1 self.draggingNodeIndex = -1
self.dragging_rotation_handle_index = -1 self.draggingRotationHandleIndex = -1
#Tells when either the left or right mouse button is pressed
def mousePressEvent(self, event: QMouseEvent): def mousePressEvent(self, event: QMouseEvent):
pos = self.image_label.mapFrom(self, event.position().toPoint()) pos = self.imageLabel.mapFrom(self, event.position().toPoint())
x, y = pos.x(), pos.y() x, y = pos.x(), pos.y()
if 0 <= x < self.pixmap.width() and 0 <= y < self.pixmap.height(): if 0 <= x < self.pixmap.width() and 0 <= y < self.pixmap.height():
if event.button() == Qt.RightButton: if event.button() == Qt.RightButton:
self.coordinates = np.vstack((self.coordinates, [x, y])) self.coordinates = np.vstack((self.coordinates, [x, y]))
if len(self.coordinates) >= 2: if len(self.coordinates) >= 2:
self.calculate_control_points() self.calculateControlPoints()
self.calculate_rotation_handle_pos() self.calculateRotationHandlePos()
self.draw_scene() self.drawScene()
self.button_editor.update_scene() self.buttonEditor.updateScene()
elif event.button() == Qt.LeftButton: elif event.button() == Qt.LeftButton:
current_time = event.timestamp() currentTime = event.timestamp()
if (current_time - self.last_click_time < 300 and if (currentTime - self.lastClickTime < 300 and
(pos - self.last_click_pos).manhattanLength() < 5): (pos - self.lastClickPos).manhattanLength() < 5):
node_index = self.is_point_in_node(x, y) nodeIndex = self.isPointInNode(x, y)
if node_index != -1: if nodeIndex != -1:
self.delete_node(node_index) self.deleteNode(nodeIndex)
else: else:
control_point_index = self.is_point_in_control_point(x, y) controlPointIndex = self.isPointInControlPoint(x, y)
if control_point_index != (-1, -1): if controlPointIndex != (-1, -1):
self.smoothPoints(control_point_index[0], control_point_index[1]) self.smoothPoints(controlPointIndex[0], controlPointIndex[1])
self.draw_scene() self.drawScene()
self.button_editor.update_scene() self.buttonEditor.updateScene()
else: else:
control_point_index = self.is_point_in_control_point(x, y) controlPointIndex = self.isPointInControlPoint(x, y)
if control_point_index != (-1, -1): if controlPointIndex != (-1, -1):
self.dragging_control_point = True self.draggingControlPoint = True
self.dragging_control_point_index = control_point_index self.draggingControlPointIndex = controlPointIndex
else: else:
node_index = self.is_point_in_node(x, y) nodeIndex = self.isPointInNode(x, y)
if node_index != -1: if nodeIndex != -1:
self.dragging_node = True self.draggingNode = True
self.dragging_node_index = node_index self.draggingNodeIndex = nodeIndex
else: else:
rotation_handle_index = self.is_point_in_rotation_handle(x, y) rotationHandleIndex = self.isPointInRotationHandle(x, y)
if rotation_handle_index != -1: if rotationHandleIndex != -1:
self.dragging_rotation_handle = True self.draggingRotationHandle = True
self.dragging_rotation_handle_index = rotation_handle_index self.draggingRotationHandleIndex = rotationHandleIndex
self.last_click_time = current_time self.lastClickTime = currentTime
self.last_click_pos = pos self.lastClickPos = pos
#Deletes node def deleteNode(self, index):
def delete_node(self, index):
self.coordinates = np.delete(self.coordinates, index, axis=0) self.coordinates = np.delete(self.coordinates, index, axis=0)
if index < len(self.control_points): if index < len(self.controlPoints):
del self.control_points[index] del self.controlPoints[index]
if index > 0 and index < len(self.control_points): if index > 0 and index < len(self.controlPoints):
del self.control_points[index - 1] del self.controlPoints[index - 1]
if index < len(self.rotation_handles): if index < len(self.rotationHandles):
del self.rotation_handles[index] del self.rotationHandles[index]
self.draw_scene() self.drawScene()
self.button_editor.update_scene() self.buttonEditor.updateScene()
def mouseMoveEvent(self, event: QMouseEvent): def mouseMoveEvent(self, event: QMouseEvent):
if self.dragging_control_point: if self.draggingControlPoint:
pos = self.image_label.mapFrom(self, event.position().toPoint()) pos = self.imageLabel.mapFrom(self, event.position().toPoint())
x, y = pos.x(), pos.y() x, y = pos.x(), pos.y()
curve_index, point_index = self.dragging_control_point_index curveIndex, pointIndex = self.draggingControlPointIndex
self.control_points[curve_index][point_index] = QPoint(x, y) self.controlPoints[curveIndex][pointIndex] = QPoint(x, y)
self.draw_scene() self.drawScene()
self.button_editor.update_scene() self.buttonEditor.updateScene()
elif self.dragging_node: elif self.draggingNode:
pos = self.image_label.mapFrom(self, event.position().toPoint()) pos = self.imageLabel.mapFrom(self, event.position().toPoint())
x, y = pos.x(), pos.y() x, y = pos.x(), pos.y()
self.coordinates[self.dragging_node_index] = [x, y] self.coordinates[self.draggingNodeIndex] = [x, y]
self.calculate_control_points() self.calculateControlPoints()
self.calculate_rotation_handle_pos() self.calculateRotationHandlePos()
self.draw_scene() self.drawScene()
self.button_editor.update_scene() self.buttonEditor.updateScene()
elif self.dragging_rotation_handle: elif self.draggingRotationHandle:
pos = self.image_label.mapFrom(self, event.position().toPoint()) pos = self.imageLabel.mapFrom(self, event.position().toPoint())
x, y = pos.x(), pos.y() x, y = pos.x(), pos.y()
node_x, node_y = self.coordinates[self.dragging_rotation_handle_index] nodeX, nodeY = self.coordinates[self.draggingRotationHandleIndex]
dx = x - node_x dx = x - nodeX
dy = y - node_y dy = y - nodeY
angle = np.arctan2(dy, dx) angle = np.arctan2(dy, dx)
self.node_angles[self.dragging_rotation_handle_index] = angle self.nodeAngles[self.draggingRotationHandleIndex] = angle
rotation_handle_x = int(node_x + self.rotation_handle_distance * np.cos(angle)) rotationHandleX = int(nodeX + self.rotationHandleDistance * np.cos(angle))
rotation_handle_y = int(node_y + self.rotation_handle_distance * np.sin(angle)) rotationHandleY = int(nodeY + self.rotationHandleDistance * np.sin(angle))
self.rotation_handles[self.dragging_rotation_handle_index] = QPoint(rotation_handle_x, rotation_handle_y) self.rotationHandles[self.draggingRotationHandleIndex] = QPoint(rotationHandleX, rotationHandleY)
self.draw_scene() self.drawScene()
self.button_editor.update_scene() self.buttonEditor.updateScene()
#Resets dragging when mouse is released
def mouseReleaseEvent(self, event: QMouseEvent): def mouseReleaseEvent(self, event: QMouseEvent):
if event.button() == Qt.LeftButton: if event.button() == Qt.LeftButton:
self.dragging_control_point = False self.draggingControlPoint = False
self.dragging_control_point_index = (-1, -1) self.draggingControlPointIndex = (-1, -1)
self.dragging_node = False self.draggingNode = False
self.dragging_node_index = -1 self.draggingNodeIndex = -1
self.dragging_rotation_handle = False self.draggingRotationHandle = False
self.dragging_rotation_handle_index = -1 self.draggingRotationHandleIndex = -1
self.button_editor.update_scene() self.buttonEditor.updateScene()
#These 3 are for distinguishing what the user is clicking def isPointInRotationHandle(self, x, y):
def is_point_in_rotation_handle(self, x, y): for i, handle in enumerate(self.rotationHandles):
for i, handle in enumerate(self.rotation_handles): if (abs(x - handle.x()) <= self.handleSize // 2 and
if (abs(x - handle.x()) <= self.handle_size // 2 and abs(y - handle.y()) <= self.handleSize // 2):
abs(y - handle.y()) <= self.handle_size // 2):
return i return i
return -1 return -1
def is_point_in_control_point(self, x, y): def isPointInControlPoint(self, x, y):
for i, control_pair in enumerate(self.control_points): for i, controlPair in enumerate(self.controlPoints):
for j, control_point in enumerate(control_pair): for j, controlPoint in enumerate(controlPair):
if (abs(x - control_point.x()) <= self.handle_size // 2 and if (abs(x - controlPoint.x()) <= self.handleSize // 2 and
abs(y - control_point.y()) <= self.handle_size // 2): abs(y - controlPoint.y()) <= self.handleSize // 2):
return (i, j) return (i, j)
return (-1, -1) return (-1, -1)
def is_point_in_node(self, x, y): def isPointInNode(self, x, y):
for i, (node_x, node_y) in enumerate(self.coordinates): for i, (nodeX, nodeY) in enumerate(self.coordinates):
if (abs(x - node_x) <= self.node_size // 2 and if (abs(x - nodeX) <= self.nodeSize // 2 and
abs(y - node_y) <= self.node_size // 2): abs(y - nodeY) <= self.nodeSize // 2):
return i return i
return -1 return -1
#Calculating the handle positions def calculateControlPoints(self):
def calculate_control_points(self):
if len(self.coordinates) >= 2: if len(self.coordinates) >= 2:
x1, y1 = self.coordinates[-2] x1, y1 = self.coordinates[-2]
x2, y2 = self.coordinates[-1] x2, y2 = self.coordinates[-1]
mid_x, mid_y = (x1 + x2) // 2, (y1 + y2) // 2 midX, midY = (x1 + x2) // 2, (y1 + y2) // 2
self.control_points.append([ self.controlPoints.append([
QPoint(mid_x - (x2 - x1) // 4, mid_y - (y2 - y1) // 4), QPoint(midX - (x2 - x1) // 4, midY - (y2 - y1) // 4),
QPoint(mid_x + (x2 - x1) // 4, mid_y + (y2 - y1) // 4) QPoint(midX + (x2 - x1) // 4, midY + (y2 - y1) // 4)
]) ])
def calculate_rotation_handle_pos(self): def calculateRotationHandlePos(self):
for i, (x, y) in enumerate(self.coordinates): for i, (x, y) in enumerate(self.coordinates):
if i >= len(self.node_angles): if i >= len(self.nodeAngles):
self.node_angles.append(np.pi) # Default angle for new nodes self.nodeAngles.append(np.pi) # Default angle for new nodes
angle = self.node_angles[i] angle = self.nodeAngles[i]
rotation_handle_x = int(x + self.rotation_handle_distance * np.cos(angle)) rotationHandleX = int(x + self.rotationHandleDistance * np.cos(angle))
rotation_handle_y = int(y + self.rotation_handle_distance * np.sin(angle)) rotationHandleY = int(y + self.rotationHandleDistance * np.sin(angle))
if i >= len(self.rotation_handles): if i >= len(self.rotationHandles):
self.rotation_handles.append(QPoint(rotation_handle_x, rotation_handle_y)) self.rotationHandles.append(QPoint(rotationHandleX, rotationHandleY))
else: else:
self.rotation_handles[i] = QPoint(rotation_handle_x, rotation_handle_y) self.rotationHandles[i] = QPoint(rotationHandleX, rotationHandleY)
#Updates buttonEditor def updateScene(self):
def update_scene(self): self.buttonEditor.updateScene(self.coordinates, self.controlPoints)
self.button_editor.update_scene(self.coordinates, self.control_points)
#Draws the scene, big important function def drawScene(self):
def draw_scene(self):
self.pixmap = QPixmap(os.path.join(os.path.dirname(os.path.abspath(__file__)), "images", "Field.png")) self.pixmap = QPixmap(os.path.join(os.path.dirname(os.path.abspath(__file__)), "images", "Field.png"))
painter = QPainter(self.pixmap) painter = QPainter(self.pixmap)
grey_pen = QPen(QColor(127, 127, 127)) greyPen = QPen(QColor(127, 127, 127))
grey_pen.setWidth(2) greyPen.setWidth(2)
painter.setPen(grey_pen) painter.setPen(greyPen)
for i, control_pair in enumerate(self.control_points): for i, controlPair in enumerate(self.controlPoints):
if i < len(self.coordinates) - 1: if i < len(self.coordinates) - 1:
start = QPoint(self.coordinates[i][0], self.coordinates[i][1]) start = QPoint(self.coordinates[i][0], self.coordinates[i][1])
end = QPoint(self.coordinates[i + 1][0], self.coordinates[i + 1][1]) end = QPoint(self.coordinates[i + 1][0], self.coordinates[i + 1][1])
@@ -241,29 +234,29 @@ class PathPlanner(QMainWindow):
path = QPainterPath() path = QPainterPath()
path.moveTo(start) path.moveTo(start)
path.cubicTo(control_pair[0], control_pair[1], end) path.cubicTo(controlPair[0], controlPair[1], end)
painter.drawPath(path) painter.drawPath(path)
painter.setBrush(Qt.NoBrush) painter.setBrush(Qt.NoBrush)
for control_point in control_pair: for controlPoint in controlPair:
painter.setPen(QPen(QColor(127, 127, 127), 1, Qt.DashLine)) painter.setPen(QPen(QColor(127, 127, 127), 1, Qt.DashLine))
painter.drawLine(start, control_point) painter.drawLine(start, controlPoint)
painter.drawLine(end, control_point) painter.drawLine(end, controlPoint)
painter.setPen(Qt.NoPen) painter.setPen(Qt.NoPen)
painter.setBrush(QColor(0, 255, 255)) painter.setBrush(QColor(0, 255, 255))
for control_point in control_pair: for controlPoint in controlPair:
painter.drawEllipse( painter.drawEllipse(
control_point.x() - self.handle_size // 2, controlPoint.x() - self.handleSize // 2,
control_point.y() - self.handle_size // 2, controlPoint.y() - self.handleSize // 2,
self.handle_size, self.handleSize,
self.handle_size self.handleSize
) )
painter.setBrush(Qt.NoBrush) painter.setBrush(Qt.NoBrush)
for i, (x, y) in enumerate(self.coordinates): for i, (x, y) in enumerate(self.coordinates):
if i < len(self.rotation_handles): if i < len(self.rotationHandles):
angle = self.node_angles[i] angle = self.nodeAngles[i]
painter.save() painter.save()
painter.translate(x, y) painter.translate(x, y)
@@ -273,8 +266,8 @@ class PathPlanner(QMainWindow):
pen.setWidth(2) pen.setWidth(2)
painter.setPen(pen) painter.setPen(pen)
painter.setBrush(Qt.NoBrush) painter.setBrush(Qt.NoBrush)
painter.drawRect(-self.node_size // 2, -self.node_size // 2, painter.drawRect(-self.nodeSize // 2, -self.nodeSize // 2,
self.node_size, self.node_size) self.nodeSize, self.nodeSize)
painter.restore() painter.restore()
@@ -282,70 +275,65 @@ class PathPlanner(QMainWindow):
font = painter.font() font = painter.font()
font.setPointSize(25) font.setPointSize(25)
painter.setFont(font) painter.setFont(font)
painter.drawText(QRect(x - self.node_size // 2, y - self.node_size // 2, painter.drawText(QRect(x - self.nodeSize // 2, y - self.nodeSize // 2,
self.node_size, self.node_size), self.nodeSize, self.nodeSize),
Qt.AlignCenter, str(i + 1)) Qt.AlignCenter, str(i + 1))
for i, handle in enumerate(self.rotation_handles): for i, handle in enumerate(self.rotationHandles):
painter.setBrush(QColor(255, 0, 255)) painter.setBrush(QColor(255, 0, 255))
painter.drawEllipse( painter.drawEllipse(
handle, handle,
self.handle_size // 2, self.handleSize // 2,
self.handle_size // 2 self.handleSize // 2
) )
painter.setBrush(Qt.NoBrush) painter.setBrush(Qt.NoBrush)
self.image_label.setPixmap(self.pixmap) self.imageLabel.setPixmap(self.pixmap)
self.button_editor.update_scene() self.buttonEditor.updateScene()
#S M O O T H def smoothPoints(self, curveIndex: int, pointIndex: int):
def smoothPoints(self, curve_index: int, point_index: int): if curveIndex + 1 < len(self.controlPoints):
if curve_index + 1 < len(self.control_points): prevControlPair = self.controlPoints[curveIndex]
prev_control_pair = self.control_points[curve_index] nextControlPair = self.controlPoints[curveIndex + 1]
next_control_pair = self.control_points[curve_index + 1] node = QPoint(self.coordinates[curveIndex + 1][0], self.coordinates[curveIndex + 1][1])
node = QPoint(self.coordinates[curve_index + 1][0], self.coordinates[curve_index + 1][1])
#Calculate the new position for the second control point newControl2 = QPoint(
new_control2 = QPoint( 2 * node.x() - nextControlPair[0].x(),
2 * node.x() - next_control_pair[0].x(), 2 * node.y() - nextControlPair[0].y()
2 * node.y() - next_control_pair[0].y()
) )
self.control_points[curve_index][1] = new_control2 self.controlPoints[curveIndex][1] = newControl2
#Calculate the new position for the first control point newControl1 = QPoint(
new_control1 = QPoint( 2 * node.x() - prevControlPair[1].x(),
2 * node.x() - prev_control_pair[1].x(), 2 * node.y() - prevControlPair[1].y()
2 * node.y() - prev_control_pair[1].y()
) )
self.control_points[curve_index + 1][0] = new_control1 self.controlPoints[curveIndex + 1][0] = newControl1
#Clears all def clearPoints(self):
def clear_points(self):
self.coordinates = np.empty((0, 2), dtype=int) self.coordinates = np.empty((0, 2), dtype=int)
self.control_points.clear() self.controlPoints.clear()
self.rotation_handles.clear() self.rotationHandles.clear()
self.node_angles.clear() self.nodeAngles.clear()
self.draw_scene() self.drawScene()
self.button_editor.update_scene() self.buttonEditor.updateScene()
#Warning for clearing def showClearWarning(self):
def show_clear_warning(self):
reply = QMessageBox.question(self, "Clear Auto", reply = QMessageBox.question(self, "Clear Auto",
"Are you sure you want to clear this auto?", "Are you sure you want to clear this auto?",
QMessageBox.Yes | QMessageBox.No, QMessageBox.No) QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes: if reply == QMessageBox.Yes:
self.clear_points() self.clearPoints()
def show_main_window(self): def showMainWindow(self):
self.show() self.show()
self.button_editor.hide() self.buttonEditor.hide()
def show_button_editor(self): def showButtonEditor(self):
self.hide() self.hide()
self.button_editor.show() self.buttonEditor.show()
if __name__ == "__main__": if __name__ == "__main__":
app = QApplication(sys.argv) app = QApplication(sys.argv)
window = PathPlanner() window = PathPlanner()
window.show() window.show()
sys.exit(app.exec()) sys.exit(app.exec())