def __init__(self, config: Configurator, program_stage: CurrentProgramStage):

        # call super()
        self.ip = config.get("landscapelab", "ip")
        self.port = config.get("landscapelab", "port")
        super().__init__(config)

        self.extent_tracker = ExtentTracker.get_instance()
        self.program_stage = program_stage

        # set the callback functions for the received messages from the LL
        self.keyword_callbacks = {
            SEND_REC_CREATE_OBJECT_MSG["keyword"]: self.create_local_brick,
            SEND_REC_UPDATE_OBJECT_MSG["keyword"]: self.update_local_brick,
            SEND_REC_REMOVE_OBJECT_MSG["keyword"]: self.remove_local_brick,
            REC_GAMESTATE_INFO_MSG["keyword"]: self.game_mode_change,
            REC_UPDATE_SCORE_MSG["keyword"]: self.update_local_score,
            REC_PLAYER_POSITION_MSG["keyword"]: self.update_player_position
        }

        self.provided_tokens = []
        for color in config.get("brick_colors"):
            for shape in BrickShape:
                if shape.value > 0:
                    self.provided_tokens.append({"color": color, "shape": shape.name})
Exemplo n.º 2
0
    def __init__(self,
                 config: Configurator,
                 position: Vector,
                 size: Vector,
                 color: List = None,
                 border_color: List = None,
                 border_weight: float = None):

        super().__init__()

        # overwrite none values with defaults
        if color is None:
            color = config.get("ui_settings", "nav_block_background_color")
        if border_color is None:
            border_color = config.get("ui_settings", "nav_block_border_color")
        if border_weight is None:
            border_weight = config.get("ui_settings",
                                       "nav_block_border_weight")

        # set block position/size
        self.position = position  # only modify with set_position
        self.size = size  # only modify with set_size
        self.area = Extent.from_vectors(position, position + size,
                                        False)  # only modify with set_area
        self.is_ellipse = False

        # set block color
        self.color = (color[0], color[1], color[2])
        self.show_background_color = True

        self.border_thickness: float = border_weight
        self.border_color = (border_color[0], border_color[1], border_color[2])
        self.show_border = True
Exemplo n.º 3
0
    def __init__(self, config: Configurator, name: str, extent: Extent,
                 zoom_limits: Tuple[int, int], resolution: Tuple[int, int]):

        self.name = name
        self.config = config
        self.extent_tracker = ExtentTracker.get_instance()
        self.min_zoom, self.max_zoom = zoom_limits

        # set resolution
        self.resolution_x, self.resolution_y = resolution

        # initialize two black images
        self.map_image = [
            ImageHandler.ensure_alpha_channel(
                np.ones((self.resolution_y, self.resolution_x, 3), np.uint8) *
                255),
            ImageHandler.ensure_alpha_channel(
                np.ones(
                    (self.resolution_y, self.resolution_x, 3), np.uint8) * 255)
        ]
        self.current_image = 0

        # crs is initialized with a local configuration but overwritten once a connection with the LL is established
        self.crs = config.get("map_settings", "coordinate_reference_system")
        extent.fit_to_ratio(self.resolution_y / self.resolution_x)
        self.current_extent: Extent = extent

        # set extent modifiers
        pan_up_modifier = np.array([0, 1, 0, 1])
        pan_down_modifier = np.array([0, -1, 0, -1])
        pan_left_modifier = np.array([-1, 0, -1, 0])
        pan_right_modifier = np.array([1, 0, 1, 0])
        self.zoom_in_modifier = np.array([1, 1, -1, -1])
        self.zoom_out_modifier = np.array([-1, -1, 1, 1])

        # get navigation settings
        pan_distance = config.get('map_settings', 'pan_distance')
        zoom_strength = config.get('map_settings', 'zoom_strength')

        # these functions can be used to interact with the map
        # by calling these functions one can pan and zoom on the map
        # the functions will automatically request a new rendered map extent from the QGIS plugin
        # they need accept an unused brick parameter to make it possible to call these functions via UICallback
        self.pan_up = partial(self.modify_extent, pan_up_modifier,
                              pan_distance)
        self.pan_down = partial(self.modify_extent, pan_down_modifier,
                                pan_distance)
        self.pan_left = partial(self.modify_extent, pan_left_modifier,
                                pan_distance)
        self.pan_right = partial(self.modify_extent, pan_right_modifier,
                                 pan_distance)
        self.zoom_in = partial(self.modify_extent, self.zoom_in_modifier,
                               zoom_strength)
        self.zoom_out = partial(self.modify_extent, self.zoom_out_modifier,
                                zoom_strength)
Exemplo n.º 4
0
    def __init__(self,
                 config: Configurator,
                 position: Vector,
                 size: Vector,
                 name: str = '',
                 icon_name: str = None,
                 color: List = None,
                 active_color: List = None,
                 border_color: List = None,
                 border_weight: float = None):

        # overwrite none values with defaults
        if color is None:
            color = config.get("ui_settings", "button_background_color")
        if active_color is None:
            active_color = config.get("ui_settings",
                                      "button_active_background_color")
        if border_color is None:
            border_color = config.get("ui_settings", "button_border_color")
        if border_weight is None:
            border_weight = config.get("ui_settings", "button_border_weight")

        # call super init
        super().__init__(config,
                         position,
                         size,
                         color=color,
                         border_color=border_color,
                         border_weight=border_weight)

        # set visuals
        self.icon = None
        if icon_name is not None:
            img_handler = ImageHandler(config)
            self.icon = img_handler.load_image(icon_name, self.size.as_point())

        self.color_pressed = (active_color[0], active_color[1],
                              active_color[2])
        self.icon_pressed = None

        self.name: str = name
        self.show_name: bool = False

        self.show_border = True

        self.is_ellipse = True

        # set button callback functions
        self.callbacks: Dict[UIActionType, UICallback] = {}
        self.set_callback(UIActionType.PRESS, UICallback())
        self.set_callback(UIActionType.RELEASE, UICallback())
        # self.set_callback(UIActionType.HOLD, self.callback_do_nothing)

        self.pressed = False
        self.pressed_once = False
Exemplo n.º 5
0
    def __init__(self, config: Configurator, callbacks: dict):

        # initialize connection string and ssl configuration
        self.ip = config.get("qgis", "ip")
        self.port = config.get("qgis", "port")
        self.ssl_pem_file = config.get("server", "ssl_pem_file")

        # call super
        super().__init__(config)

        self.callbacks = callbacks
    def find_button_mapping(action_sets: List[NamedCallbacks], config: Configurator) -> MappedCallbacks:
        ret: MappedCallbacks = {}

        # iterates over all NamedCallbacks (remember NamedCallbacks is a List itself)
        for action_dict in action_sets:
            # iterates over each action in the current list
            for action_name, callback in action_dict.items():
                try:
                    # try to find button mapping in config file
                    mapped_key = config.get("button_map", action_name.name)
                    ret[ord(mapped_key)] = (action_name, callback)
                except ConfigError:
                    logger.warning("Could not find button mapping for UI action {}.".format(action_name.name))

        return ret
Exemplo n.º 7
0
    def load_image(self,
                   name: str,
                   size: Optional[Tuple[int, int]] = None,
                   relative_center: Optional[Tuple[float, float]] = None,
                   center: Optional[Tuple[int, int]] = None):

        image_dict = self.config.get("resources", name)

        # check that image has path
        if 'path' not in image_dict:
            err_msg = 'image has no path specified'
            logger.error(err_msg)
            raise ConfigError(err_msg)

        image_path = Configurator.reconstruct_path(self.resource_path,
                                                   image_dict['path'])
        logger.debug("loading image {}".format(image_path))
        img = cv2.imread(image_path, -1)

        # resize if size is not None or size specified in config
        # also ensure size exists in image_dict
        if size:
            img = cv2.resize(img, size)
            image_dict["size"] = [0, 0]
            image_dict["size"][0], image_dict["size"][1] = size
        elif 'size' in image_dict:
            img = cv2.resize(img,
                             (image_dict['size'][0], image_dict['size'][1]))
        else:
            image_dict["size"] = [0, 0]
            image_dict["size"][0] = img.shape[1]
            image_dict["size"][1] = img.shape[0]

        # overwrite center if defined in params
        if relative_center:
            rel_x, rel_y = relative_center
            image_dict['center'] = [
                int(rel_x * image_dict['size'][0]),
                int(rel_y * image_dict['size'][1])
            ]
        if center:
            image_dict['center'] = center

        img = ImageHandler.ensure_alpha_channel(img)

        # add image to dictionary and return
        image_dict['image'] = img
        return image_dict
Exemplo n.º 8
0
    def __init__(self, config: Configurator, position: Vector, size: Vector, horizontal: bool, flipped: bool,
                 score: Score, bar_color: List[Tuple[int, int, int]] = None, background_color: List = None,
                 border_color: List = None, border_weight: float = None):

        super().__init__(config, position, size, color=background_color, border_color=border_color,
                         border_weight=border_weight)

        self.config = config

        default_bar_color = config.get("ui_settings", "progress_bar_color")
        if bar_color is None:
            self.bar_color = [(color[2], color[1], color[0]) for color in default_bar_color]
        else:
            self.bar_color = bar_color

        self.horizontal: bool = horizontal
        self.flipped: bool = flipped
        self.wrap_around = False

        self.score: Score = score
Exemplo n.º 9
0
    def __init__(self, config: Configurator, name, ll_communicator):

        self.config = config
        self.landscape_lab = ll_communicator

        # get desired screen resolution
        resolution_x = int(config.get("beamer_resolution", "width"))
        resolution_y = int(config.get("beamer_resolution", "height"))

        # get zoom limits
        zoom_limits = config.get("map_settings", "map_zoom_limits")

        super().__init__(config, name, self.get_start_extent(), zoom_limits,
                         (resolution_x, resolution_y))

        # set new extent
        config.set("map_settings", "extent_width",
                   [self.current_extent.x_min, self.current_extent.x_max])
        config.set("map_settings", "extent_height",
                   [self.current_extent.y_min, self.current_extent.y_max])
    def __init__(self,
                 map_handler: MainMap,
                 ui_root: UIElement,
                 callback_manager: CallbackManager,
                 tracker: Tracker,
                 config: Configurator,
                 board: Board,
                 program_stage: CurrentProgramStage,
                 video_output_name=None):

        self.config = config
        self.callback_manager = callback_manager
        self.extent_tracker = ExtentTracker.get_instance()
        self.board = board
        self.program_stage = program_stage

        self.active_channel = TableOutputChannel.CHANNEL_BOARD_DETECTION
        self.active_window = TableOutputStream.WINDOW_NAME_DEBUG

        # create a store of the last images of each channel
        self.channel_images = {}
        for channel in TableOutputChannel:
            self.channel_images[channel.name] = np.empty((1, 1))

        # create debug window
        cv2.namedWindow(TableOutputStream.WINDOW_NAME_DEBUG, cv2.WINDOW_NORMAL)
        cv2.resizeWindow(TableOutputStream.WINDOW_NAME_DEBUG, config.get("screen_resolution", "width"),
                         config.get("screen_resolution", "height"))

        # create beamer window
        beamer_id = self.config.get("beamer_resolution", "screen_id")
        if beamer_id >= 0:
            pos_x = config.get("beamer_resolution", "pos_x")
            pos_y = config.get("beamer_resolution", "pos_y")

            logger.info("beamer coords: {} {}".format(pos_x, pos_y))

            cv2.namedWindow(TableOutputStream.WINDOW_NAME_BEAMER, cv2.WND_PROP_FULLSCREEN)
            cv2.moveWindow(TableOutputStream.WINDOW_NAME_BEAMER, pos_x, pos_y)
            cv2.setWindowProperty(TableOutputStream.WINDOW_NAME_BEAMER, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
        else:
            cv2.namedWindow(TableOutputStream.WINDOW_NAME_BEAMER, cv2.WINDOW_AUTOSIZE)

        cv2.setMouseCallback(TableOutputStream.WINDOW_NAME_BEAMER, self.beamer_mouse_callback)

        if video_output_name:
            # Define the codec and create VideoWriter object. The output is stored in .avi file.
            # Define the fps to be equal to 10. Also frame size is passed.
            self.video_handler = cv2.VideoWriter(video_output_name, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'),
                                                 10, (config.get('video_resolution', 'width'),
                                                      config.get('video_resolution', 'height')))
        else:
            self.video_handler = None

        self.last_frame = None

        # set ui_root and map handler, create empty variable for tracker
        self.ui_root = ui_root
        self.map_handler = map_handler
        self.tracker: Tracker = tracker

        # create image handler to load images
        self.image_handler = ImageHandler(config)

        # load qr code images
        qr_size = self.config.get("qr_code", "size")
        # TODO calc optimal size on draw instead of scaling down to fixed size
        self.qr_bottom_left = self.image_handler.load_image("qr_bottom_left", (qr_size, qr_size))
        self.qr_bottom_right = self.image_handler.load_image("qr_bottom_right", (qr_size, qr_size))
        self.qr_top_left = self.image_handler.load_image("qr_top_left", (qr_size, qr_size))
        self.qr_top_right = self.image_handler.load_image("qr_top_right", (qr_size, qr_size))

        # load brick overlay images
        self.brick_outdated = self.image_handler.load_image("outdated_brick")
        self.brick_unknown = self.image_handler.load_image("unknown_brick")
        self.brick_internal = self.image_handler.load_image("internal_brick")

        # load and initialize icon lists
        self.brick_icons = {}
        self.virtual_icons = {}
        self.brick_icons["windmill_icon"] = self.image_handler.load_image("windmill_brick")
        self.brick_icons["pv_icon"] = self.image_handler.load_image("pv_brick")
        self.virtual_icons["windmill_icon"] = self.image_handler.load_image("windmill_icon")
        self.virtual_icons["pv_icon"] = self.image_handler.load_image("pv_icon")
Exemplo n.º 11
0
    def __init__(self, config: Configurator):

        self.config = config
        self.resource_path = Configurator.reconstruct_path(
            os.getcwd(), self.config.get("resources", "relative_path"))