def build_tile(tile):
    if UI.is_working: return 0
    UI.is_working = 1
    UI.red_flag = False
    UI.logprint("Step 3 for tile lat=", tile.lat, ", lon=", tile.lon,
                ": starting.")
    UI.vprint(
        0, "\nStep 3 : Building DSF/Imagery for tile " +
        FNAMES.short_latlon(tile.lat, tile.lon) + " : \n--------\n")

    if not os.path.isfile(FNAMES.mesh_file(tile.build_dir, tile.lat,
                                           tile.lon)):
        UI.lvprint(
            0, "ERROR: A mesh file must first be constructed for the tile!")
        UI.exit_message_and_bottom_line('')
        return 0

    timer = time.time()

    tile.write_to_config()

    if not IMG.initialize_local_combined_providers_dict(tile):
        UI.exit_message_and_bottom_line('')
        return 0

    try:
        if not os.path.exists(
                os.path.join(tile.build_dir, 'Earth nav data',
                             FNAMES.round_latlon(tile.lat, tile.lon))):
            os.makedirs(
                os.path.join(tile.build_dir, 'Earth nav data',
                             FNAMES.round_latlon(tile.lat, tile.lon)))
        if not os.path.isdir(os.path.join(tile.build_dir, 'textures')):
            os.makedirs(os.path.join(tile.build_dir, 'textures'))
        if UI.cleaning_level > 1 and not tile.grouped:
            for f in os.listdir(os.path.join(tile.build_dir, 'textures')):
                if f[-4:] != '.png': continue
                try:
                    os.remove(os.path.join(tile.build_dir, 'textures', f))
                except:
                    pass
        if not tile.grouped:
            try:
                shutil.rmtree(os.path.join(tile.build_dir, 'terrain'))
            except:
                pass
        if not os.path.isdir(os.path.join(tile.build_dir, 'terrain')):
            os.makedirs(os.path.join(tile.build_dir, 'terrain'))
    except Exception as e:
        UI.lvprint(0, "ERROR: Cannot create tile subdirectories.")
        UI.vprint(3, e)
        UI.exit_message_and_bottom_line('')
        return 0

    download_queue = queue.Queue()
    convert_queue = queue.Queue()
    build_dsf_thread = threading.Thread(target=DSF.build_dsf,
                                        args=[tile, download_queue])
    download_thread = threading.Thread(
        target=download_textures, args=[tile, download_queue, convert_queue])
    build_dsf_thread.start()
    if not skip_downloads:
        download_thread.start()
        if not skip_converts and not O4_ESP_Globals.build_for_ESP:
            UI.vprint(1, "-> Opening convert queue and", max_convert_slots,
                      "conversion workers.")
            dico_conv_progress = {'done': 0, 'bar': 3}
            convert_workers = parallel_launch(IMG.convert_texture,
                                              convert_queue,
                                              max_convert_slots,
                                              progress=dico_conv_progress)
    build_dsf_thread.join()
    if not skip_downloads:
        download_queue.put('quit')
        download_thread.join()
        if not skip_converts and not O4_ESP_Globals.build_for_ESP:
            for _ in range(max_convert_slots):
                convert_queue.put('quit')
            parallel_join(convert_workers)
            if UI.red_flag:
                UI.vprint(1, "DDS conversion process interrupted.")
            elif dico_conv_progress['done'] >= 1:
                UI.vprint(1, " *DDS conversion of textures completed.")
    UI.vprint(1, " *Activating DSF file.")
    dsf_file_name = os.path.join(
        tile.build_dir, 'Earth nav data',
        FNAMES.long_latlon(tile.lat, tile.lon) + '.dsf')
    try:
        os.rename(dsf_file_name + '.tmp', dsf_file_name)
    except:
        UI.vprint(0, "ERROR : could not rename DSF file, tile is not actived.")
    if UI.red_flag:
        UI.exit_message_and_bottom_line()
        return 0
    if UI.cleaning_level > 1:
        try:
            os.remove(FNAMES.alt_file(tile))
        except:
            pass
        try:
            os.remove(FNAMES.input_node_file(tile))
        except:
            pass
        try:
            os.remove(FNAMES.input_poly_file(tile))
        except:
            pass
    if UI.cleaning_level > 2:
        try:
            os.remove(FNAMES.mesh_file(tile.build_dir, tile.lat, tile.lon))
        except:
            pass
        try:
            os.remove(FNAMES.apt_file(tile))
        except:
            pass
    if UI.cleaning_level > 1 and not tile.grouped:
        remove_unwanted_textures(tile)
    if O4_ESP_Globals.build_for_ESP:
        O4_ESP_Utils.run_ESP_resample(O4_ESP_Globals.ESP_build_dir)

    UI.timings_and_bottom_line(timer)
    UI.logprint("Step 3 for tile lat=", tile.lat, ", lon=", tile.lon,
                ": normal exit.")
    return 1
예제 #2
0
def build_tile(tile):
    UI.red_flag = False
    UI.logprint("Step 3 for tile lat=", tile.lat, ", lon=", tile.lon,
                ": starting.")
    UI.vprint(
        0, "\nStep 3 : Building DSF/Imagery for tile " +
        FNAMES.short_latlon(tile.lat, tile.lon) + " : \n--------\n")

    if not os.path.isfile(FNAMES.mesh_file(tile.build_dir, tile.lat,
                                           tile.lon)):
        UI.lvprint(
            0, "ERROR: A mesh file must first be constructed for the tile!")
        UI.exit_message_and_bottom_line('')
        return 0

    timer = time.time()

    tile.write_to_config()
    #tile.ensure_elevation_data()

    IMG.initialize_local_combined_providers_dict(tile)

    try:
        if not os.path.exists(
                os.path.join(tile.build_dir, 'Earth nav data',
                             FNAMES.round_latlon(tile.lat, tile.lon))):
            os.makedirs(
                os.path.join(tile.build_dir, 'Earth nav data',
                             FNAMES.round_latlon(tile.lat, tile.lon)))
        if not os.path.isdir(os.path.join(tile.build_dir, 'textures')):
            os.makedirs(os.path.join(tile.build_dir, 'textures'))
        try:
            shutil.rmtree(os.path.join(tile.build_dir, 'terrain'))
        except:
            pass
        if not os.path.isdir(os.path.join(tile.build_dir, 'terrain')):
            os.makedirs(os.path.join(tile.build_dir, 'terrain'))
    except Exception as e:
        UI.lvprint(0, "ERROR: Cannot create tile subdirectories.")
        UI.vprint(3, e)
        UI.exit_message_and_bottom_line('')
        return 0

    download_queue = queue.Queue()
    convert_queue = queue.Queue()
    build_dsf_thread = threading.Thread(target=DSF.build_dsf,
                                        args=[tile, download_queue])
    download_thread = threading.Thread(
        target=download_textures, args=[tile, download_queue, convert_queue])
    build_dsf_thread.start()
    if not skip_downloads:
        download_thread.start()
        if not skip_converts:
            UI.vprint(1, "-> Opening convert queue and", max_convert_slots,
                      "conversion workers.")
            dico_conv_progress = {'done': 0, 'bar': 3}
            convert_workers = parallel_launch(IMG.convert_texture,
                                              convert_queue,
                                              max_convert_slots,
                                              progress=dico_conv_progress)
    build_dsf_thread.join()
    if not skip_downloads:
        download_queue.put('quit')
        download_thread.join()
        if not skip_converts:
            for _ in range(max_convert_slots):
                convert_queue.put('quit')
            parallel_join(convert_workers)
            if UI.red_flag:
                UI.vprint(1, "DDS conversion process interrupted.")
            elif dico_conv_progress['done'] >= 1:
                UI.vprint(1, " *DDS conversion of textures completed.")
    if UI.red_flag:
        UI.exit_message_and_bottom_line()
        return 0
    UI.timings_and_bottom_line(timer)
    UI.logprint("Step 3 for tile lat=", tile.lat, ", lon=", tile.lon,
                ": normal exit.")
    return 1