def setRobotPosition(self, robotID, x, y, angle): if self.robots.has_key(robotID): rob = self.robots.get(robotID) if x != None: if self.fieldIsSwitched: rob.x = -x else: rob.x = x if y != None: if self.fieldIsSwitched: rob.y = -y else: rob.y = y if angle != None: if self.fieldIsSwitched: rob.angel = -angle + self.degToRadians(180) else: rob.angel = -angle transform = QTransform() transform.rotateRadians(rob.angel) rotPixMap = QPixmap( rob.rob_label.originalPixmap).transformed(transform) rob.rob_label.setPixmap(rotPixMap) rob.rob_label.setScaledContents(True) addScale = (abs(math.sin(rob.angel * 2))) * (math.sqrt(2) - 1) newsize = self.rob_pool.size + (self.rob_pool.size * addScale) rob.rob_label.setFixedSize(newsize, newsize) #print(addScale, newsize, rob.rob_label.width()) rob.rob_label.setScaledContents(True) rob.rob_label.move(self.screenMidX - int(rob.rob_label.width() / 2) + self._meter_to_UI(rob.x), \ self.screenMidY - int(rob.rob_label.height() / 2) - self._meter_to_UI(rob.y)) rob.ang_label.move( rob.rob_label.x() + int(rob.rob_label.width() / 2) - rob.ang_label.width() / 2,\ rob.rob_label.y() + int(rob.rob_label.height() / 2) - rob.ang_label.height() / 2) rob.arrow_label.move(rob.rob_label.x() + int(rob.rob_label.width() / 2) - rob.arrow_label.width() / 2,\ rob.rob_label.y() + int(rob.rob_label.height() / 2) - rob.arrow_label.height() / 2) rob.arrow_label.setRoboAngle(self.radToDeg(rob.angel)) rob.ang_label.setAngles(self.radToDeg(-rob.angel), None)
def draw_flipper_state(self): length = 100 self._widget.flipper_front_current.setText(str(self.flipper_state)) #self.flipper_state += self.flipper_diff; if(self.flipper_state > self.flipper_front_max_state): self.flipper_diff *= -1 # self.flipper_state = self.flipper_front_max_state if(self.flipper_state < self.flipper_front_min_state): self.flipper_diff *= -1 # self.flipper_state = self.flipper_front_min_state self.flipper_scene.clear() self.draw_flipper_max() self.draw_flipper_min() #red chassi self.flipper_scene.addRect(65, 60, 145, 25, QPen(), QBrush(QColor(255,0,0))) #right wheel self.flipper_scene.addEllipse(150, 50, 50, 50, QPen(), QBrush(QColor(0,0,0))) #left wheel self.flipper_scene.addEllipse(50, 50, 50, 50, QPen(), QBrush(QColor(0,0,0))) #flipper wheel transform = QTransform() transform.translate(155,70) transform.rotateRadians(-self.flipper_state) transform.translate(-25,-25) #flipper wheel connection flipper_wheel = QtGui.QGraphicsEllipseItem(120,5, 50, 50) flipper_wheel.setTransform(transform) flipper_wheel.setBrush( QBrush(QColor(0,0,0))) self.flipper_scene.addItem(flipper_wheel) #self.flipper_scene.addEllipse(250, 50, 50, 50, QPen(), QBrush(QColor(0,0,0))) transform = QTransform() transform.translate(160,75) transform.rotateRadians(-self.flipper_state) transform.translate(-10,-10) flipper_link = QtGui.QGraphicsRectItem(0,0, 135, 20) flipper_link.setBrush( QBrush(QColor(163,163,163))) flipper_link.setTransform(transform) self.flipper_scene.addItem(flipper_link) #front connection self.flipper_scene.addEllipse(155, 70, 10, 10, QPen(), QBrush(QColor(0,0,0))) transform = QTransform() transform.translate(160,75) transform.rotateRadians(-self.flipper_state) transform.translate(-10,-10) #flipper wheel connection flipper_wheel_connection = QtGui.QGraphicsEllipseItem(120,5, 10, 10) flipper_wheel_connection.setTransform(transform) flipper_wheel_connection.setBrush( QBrush(QColor(0,0,0))) self.flipper_scene.addItem(flipper_wheel_connection)