Ejemplo n.º 1
0
 def parse(raw: bytes, colors, drawables, texts, sizes, image_config, *args, **kwargs) -> MapData:
     scale = float(image_config[CONF_SCALE])
     map_image_size = raw.find(bytes([127, 123]))
     map_image = raw[16:map_image_size + 1]
     map_info_raw = raw[map_image_size + 1:]
     map_info = json.loads(map_info_raw)
     width = map_info["width"]
     height = map_info["height"]
     x_min = map_info["x_min"]
     y_min = map_info["y_min"]
     resolution = map_info["resolution"]
     x_min_calc = x_min / resolution
     y_min_calc = y_min / resolution
     map_data = MapData(0, 1000)
     map_data.rooms = MapDataParserRoidmi.parse_rooms(map_info)
     image = MapDataParserRoidmi.parse_image(map_image, width, height, x_min_calc, y_min_calc, resolution,
                                             colors, image_config, map_data.rooms)
     map_data.image = image
     map_data.path = MapDataParserRoidmi.parse_path(map_info)
     map_data.vacuum_position = MapDataParserRoidmi.parse_vacuum_position(map_info)
     map_data.charger = MapDataParserRoidmi.parse_charger_position(map_info)
     map_data.no_go_areas, map_data.no_mopping_areas, map_data.walls = MapDataParserRoidmi.parse_areas(map_info)
     if not map_data.image.is_empty:
         MapDataParserRoidmi.draw_elements(colors, drawables, sizes, map_data, image_config)
         if len(map_data.rooms) > 0 and map_data.vacuum_position is not None:
             map_data.vacuum_room = MapDataParserRoidmi.get_current_vacuum_room(map_image, map_data, width)
             if map_data.vacuum_room is not None:
                 map_data.vacuum_room_name = map_data.rooms[map_data.vacuum_room].name
         ImageHandlerRoidmi.rotate(map_data.image)
         ImageHandlerRoidmi.draw_texts(map_data.image, texts)
     return map_data
Ejemplo n.º 2
0
 def parse_image(map_image: bytes, width: int, height: int, min_x: float, min_y: float, resolution: float,
                 colors: Dict, image_config: Dict, rooms: Dict[int, Room]) -> ImageData:
     image_top = 0
     image_left = 0
     room_numbers = list(rooms.keys())
     image, rooms_raw = ImageHandlerRoidmi.parse(map_image, width, height, colors, image_config, room_numbers)
     for number, room in rooms_raw.items():
         pf = lambda p: MapDataParserRoidmi.image_to_map(p, resolution, min_x, min_y)
         p1 = pf(Point(room[0] + image_left, room[1] + image_top))
         p2 = pf(Point(room[2] + image_left, room[3] + image_top))
         rooms[number].x0 = p1.x
         rooms[number].y0 = p1.y
         rooms[number].x1 = p2.x
         rooms[number].y1 = p2.y
     return ImageData(width * height, image_top, image_left, height, width, image_config, image,
                      lambda p: MapDataParserRoidmi.map_to_image(p, resolution, min_x, min_y))