def wheelEvent(self, event): event.ignore() numDegrees = event.angleDelta().y() / 8 if numDegrees > 0: self.setTransform(QTransform.fromScale(1.15, 1.15), True) #self.scale(1.15, 1.15) else: self.setTransform(QTransform.fromScale(0.85, 0.85), True)
def _mirror(self, item): """ Mirror any QItem to have correct orientation :param item: :return: """ item.setTransform(QTransform().scale(1, -1).translate( 0, -self.map_height))
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 mouseMoveEvent(self, event): if event.buttons() == Qt.MidButton: mouseMovePos = event.pos() view_diff = (mouseMovePos - self.mousePressPos) tf = self.transform_press scene_diff = view_diff new_tf = QTransform(tf.m11(), tf.m12(), tf.m21(), tf.m22(), tf.dx() + view_diff.x(), tf.dy() + view_diff.y()) self.setTransform(new_tf) else: super(GraphView, self).mouseMoveEvent(event)
def scale_map(self, graphicsView, scenario): rectF = graphicsView.geometry() if (float(rectF.width()) / self.mapSize.width() < float(rectF.height()) / self.mapSize.height()): scale = float(rectF.width()) / self.mapSize.width() elif scenario == 'pal_office' or scenario == 'sml': scale = 0.7 else: scale = float(rectF.height()) / self.mapSize.height() transform = QTransform(scale, 0, 0.0, scale, 0, 0) return transform
def wheelEvent(self, wheel_event): if wheel_event.modifiers() == Qt.NoModifier: delta = wheel_event.delta() delta = max(min(delta, 480), -480) mouse_before_scale_in_scene = self.mapToScene(wheel_event.pos()) scale_factor = 1 + (0.2 * (delta / 120.0)) scaling = QTransform(scale_factor, 0, 0, scale_factor, 0, 0) self.setTransform(self.transform() * scaling) mouse_after_scale_in_scene = self.mapToScene(wheel_event.pos()) center_in_scene = self.mapToScene(self.frameRect().center()) self.centerOn(center_in_scene + mouse_before_scale_in_scene - mouse_after_scale_in_scene) wheel_event.accept() else: QGraphicsView.wheelEvent(self, wheel_event)
def wheelEvent(self, wheel_event): if wheel_event.modifiers() == Qt.NoModifier: num_degrees = wheel_event.delta() / 8.0 num_steps = num_degrees / 15.0 mouse_before_scale_in_scene = self.mapToScene(wheel_event.pos()) scale_factor = 1.2 * num_steps if num_steps < 0: scale_factor = -1.0 / scale_factor scaling = QTransform(scale_factor, 0, 0, scale_factor, 0, 0) self.setTransform(self.transform() * scaling) mouse_after_scale_in_scene = self.mapToScene(wheel_event.pos()) center_in_scene = self.mapToScene(self.frameRect().center()) self.centerOn(center_in_scene + mouse_before_scale_in_scene - mouse_after_scale_in_scene) wheel_event.accept() else: QGraphicsView.wheelEvent(self, wheel_event)
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)
def _mirror(self, item): item.setTransform(QTransform.fromScale(-1, 1), True) item.setTransform(QTransform.fromTranslate(-self.w, 0), True)
def __init__(self, gameFrame, fieldImageLabel): self.frame = gameFrame self.field = fieldImageLabel rp = rospkg.RosPack() ip_filename = os.path.join(rp.get_path('bitbots_live_tool_rqt'), 'resource', 'ip_config.yaml') with open(ip_filename, "r") as file: config = yaml.load(file) self.fieldfilename = config.get("FIELD_IMAGE") self.field_scale_global = config.get("FIELD_SCALE") self.default_positions = config.get("DEFAULT_POSITIONS") file.close() print("Config: " + self.fieldfilename + ", " + str(self.field_scale_global)) rp = rospkg.RosPack() self.fieldfilename = os.path.join( BallPool.rp.get_path('bitbots_live_tool_rqt'), 'resource', self.fieldfilename) self.fieldPixmap = QPixmap(self.fieldfilename) self.field.setPixmap(self.fieldPixmap) field_width = self.fieldPixmap.width() field_height = self.fieldPixmap.height() self.field_aspect = float(field_width) / float(field_height) self.frame_aspect = float(self.frame.width()) / float( self.frame.height()) self.field_border = 40 # margin to frame self.transform = QTransform() self.fieldIsSwitched = False self.icon_timeout = 3 self.team_colors = {3: "cyan", 2: "magenta"} if self.field_aspect >= self.frame_aspect: # self.field_size_x = self.frame.width() - self.field_border * 2 self.field_size_y = self.field_size_x / self.field_aspect else: self.field_size_y = self.frame.height() - self.field_border * 2 self.field_size_x = self.field_size_y / self.field_aspect self.field.setScaledContents(True) self.field.setFixedSize(self.field_size_x, self.field_size_y) self.field_scale = float(self.field_size_x) / float(field_width) #print(self.field_scale) self.screenMidX = int(self.frame.width() / 2) self.screenMidY = int(self.frame.height() / 2) self.field.move(self.screenMidX - int(self.field.width() / 2), self.screenMidY - int(self.field.height() / 2)) self.colors = ["red", "green", "yellow", "blue"] self.robots = {} # dict where keys are robot IDs self.tabToRobot = {} # dict where keys are tab-nrs [0-3] self.ball_pool = BallPool(self.frame, size=42) self.rob_pool = RobotPool(self.frame, size=48) self.opp_pool = OpponentPool(self.frame, size=42) self.team_pool = TeammatePool(self.frame, size=42) self.cross_pool = CrossPool(self.frame, size=34) self.undef_pool = UndefinedPool(self.frame, size=42)