Skip to content

Commit

Permalink
Merge pull request #25 from shred86/dev
Browse files Browse the repository at this point in the history
Version 1.40.04
  • Loading branch information
shred86 authored Jun 29, 2024
2 parents 9b52a6e + 5ba60ab commit 97afd19
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 25 deletions.
26 changes: 20 additions & 6 deletions src/O4_Config_Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,16 @@ def write_to_config(self, config_file = None):
f = open(config_file, "w")
for var in list_tile_vars:
tile_zones = []
lat = self.lat
lon = self.lon
if lat < 0:
lat = lat + 1
if lon < 0:
lon = lon + 1
for zone in globals()["zone_list"]:
_zone_list = [int(coord) for coord in zone[0]]
_zone_list = set(_zone_list)
if self.lat in _zone_list and self.lon+1 in _zone_list:
if lat in _zone_list and lon in _zone_list:
tile_zones.append(zone)
_LOGGER.debug("Zones in tile found: %s", tile_zones)
if var == "zone_list":
Expand Down Expand Up @@ -355,7 +361,7 @@ def tile_cfg_status(self, *args) -> None:
if self.parent.tile_cfg_exists.get():
self.tile_cfg_msg.set(
f"Tile configuration loaded for " \
f"{self.parent.lat.get()}{self.parent.lon.get()}"
f"{self.parent.lat.get()} {self.parent.lon.get()}"
)
state = "normal"
for _, value in self.tile_entry_.items():
Expand Down Expand Up @@ -955,6 +961,10 @@ def reset_tile_cfg(self) -> None:
return 0
# Find all the zones for the active tile
tile_zones = []
if lat < 0:
lat = lat + 1
if lon < 0:
lon = lon + 1
for zone in globals()["zone_list"]:
_zone_list = [int(coord) for coord in zone[0]]
_zone_list = set(_zone_list)
Expand Down Expand Up @@ -1029,7 +1039,7 @@ def load_backup_tile_cfg(self) -> None:
pass
# Apply changes to update global variables
self.apply_changes("tile")
UI.vprint(0, f"Backup configuration loaded for tile at {lat}{lon}")
UI.vprint(0, f"Backup configuration loaded for tile at {lat} {lon}")
f.close()

def load_tile_cfg(self) -> None:
Expand Down Expand Up @@ -1081,7 +1091,7 @@ def load_tile_cfg(self) -> None:
self.parent.tile_cfg_exists.set(True)
# Apply changes to update global variables
self.apply_changes("tile")
UI.vprint(0, f"Configuration loaded for tile at {lat}{lon}")
UI.vprint(0, f"Configuration loaded for tile at {lat} {lon}")
f.close()

def write_tile_cfg(self) -> None:
Expand Down Expand Up @@ -1115,10 +1125,14 @@ def write_tile_cfg(self) -> None:
self.apply_changes("tile")
# Get zones only for the tile
tile_zones = []
if lat < 0:
lat = lat + 1
if lon < 0:
lon = lon + 1
for zone in globals()["zone_list"]:
_zone_list = [int(coord) for coord in zone[0]]
_zone_list = set(_zone_list)
if lat in _zone_list and lon+1 in _zone_list:
if lat in _zone_list and lon in _zone_list:
tile_zones.append(zone)
_LOGGER.debug("Zones saved for tile at %s %s: %s", lat, lon, tile_zones)
for var in list_tile_vars:
Expand All @@ -1128,7 +1142,7 @@ def write_tile_cfg(self) -> None:
f.write(var + "=" + self.v_[var].get() + "\n")
self.load_tile_cfg()
self.tile_cfg_status()
UI.vprint(1, f"Configuration saved for tile at {lat}{lon}")
UI.vprint(1, f"Configuration saved for tile at {lat} {lon}")
return

def reset_global_cfg(self) -> None:
Expand Down
15 changes: 15 additions & 0 deletions src/O4_DEM_Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,25 @@ def ensure_elevation(source, lat, lon, verbose=True):
"P36",
"Q36",
"R36",
# New Zealand
"SL58",
"SI59",
"SJ59",
"SK59",
"SL59",
"SI60",
"SJ60",
"SK60",
"SL60",
):
resol = 1
else:
resol = 3

# Wellington Intl has missing elevation data in 1" resolution
if (lat, lon) == (-42, 174):
resol = 3

url = (
"http://viewfinderpanoramas.org/dem"
+ str(resol)
Expand Down
6 changes: 6 additions & 0 deletions src/O4_DSF_Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ def extract_elevation_and_bathymetry_data(lat, lon):
"Earth nav data",
FNAMES.long_latlon(lat, lon) + ".dsf",
)
if not os.path.exists(global_scenery_dsf):
global_scenery_dsf = os.path.join(
OVL.custom_overlay_src_alternate,
"Earth nav data",
FNAMES.long_latlon(lat, lon) + ".dsf",
)
if not os.path.exists(global_scenery_dsf):
UI.exit_message_and_bottom_line(
" ERROR: file ",
Expand Down
61 changes: 44 additions & 17 deletions src/O4_GUI_Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def load_tile_cfg(self, lat: int, lon: int) -> None:
self.default_website.set(CFG.default_website)
self.default_zl.set(CFG.default_zl)
self.tile_cfg_exists.set(True)
UI.vprint(1, f"Configuration loaded for tile at {lat}{lon}")
UI.vprint(1, f"Configuration loaded for tile at {lat} {lon}")
f.close()
else:
for var in list_global_tile_vars:
Expand Down Expand Up @@ -558,7 +558,21 @@ def get_lat_lon(self, check=True):
return (48, -6)
return (lat, lon)

def tile_from_interface(self):
def tile_from_interface(self) -> CFG.Tile | bool:
"""
Create a Tile object for building a tile from the main window.
:return: Tile object or False
;rtype: Tile object or False
"""
# Check for unsaved changes
if (
self.config_window is not None
and self.config_window.winfo_exists()
):
response = self.config_window.check_unsaved_changes()
if response == "cancel":
return False
try:
(lat, lon) = self.get_lat_lon()
return CFG.Tile(lat, lon, str(self.custom_build_dir.get()))
Expand All @@ -568,7 +582,10 @@ def tile_from_interface(self):
def build_poly_file(self):
try:
tile = self.tile_from_interface()
tile.make_dirs()
if tile:
tile.make_dirs()
else:
return
except Exception as e:
UI.vprint(1, "Process aborted.\n")
_LOGGER.exception(e)
Expand All @@ -581,7 +598,10 @@ def build_poly_file(self):
def build_mesh(self, event):
try:
tile = self.tile_from_interface()
tile.make_dirs()
if tile:
tile.make_dirs()
else:
return
except Exception as e:
UI.vprint(1, "Process aborted.\n")
_LOGGER.exception("Exception on build_mesh")
Expand All @@ -594,7 +614,10 @@ def build_mesh(self, event):
def sort_mesh(self, event):
try:
tile = self.tile_from_interface()
tile.make_dirs()
if tile:
tile.make_dirs()
else:
return
except Exception as e:
UI.vprint(1, "Process aborted.\n")
_LOGGER.exception("Exception on sort_mesh")
Expand All @@ -607,7 +630,10 @@ def sort_mesh(self, event):
def community_mesh(self, event):
try:
tile = self.tile_from_interface()
tile.make_dirs()
if tile:
tile.make_dirs()
else:
return
except Exception as e:
UI.vprint(1, "Process aborted.\n")
_LOGGER.exception("Exception on community_mesh")
Expand All @@ -621,7 +647,10 @@ def build_masks(self, event):
for_imagery = "Shift" in str(event) or "shift" in str(event)
try:
tile = self.tile_from_interface()
tile.make_dirs()
if tile:
tile.make_dirs()
else:
return
except Exception as e:
UI.vprint(1, "Process aborted.\n")
_LOGGER.exception(e)
Expand All @@ -632,17 +661,12 @@ def build_masks(self, event):
self.working_thread.start()

def build_tile(self):
# Check for unsaved changes
if (
self.config_window is not None
and self.config_window.winfo_exists()
):
response = self.config_window.check_unsaved_changes()
if response == "cancel":
return
try:
tile = self.tile_from_interface()
tile.make_dirs()
if tile:
tile.make_dirs()
else:
return
except Exception as e:
UI.vprint(1, "Process aborted.\n")
_LOGGER.exception(e)
Expand All @@ -663,7 +687,10 @@ def build_all(self):
return
try:
tile = self.tile_from_interface()
tile.make_dirs()
if tile:
tile.make_dirs()
else:
return
except Exception as e:
UI.vprint(1, "Process aborted.\n")
_LOGGER.exception(e)
Expand Down
2 changes: 1 addition & 1 deletion src/O4_Overlay_Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def build_overlay(lat, lon):
dest_dir = os.path.join(
FNAMES.Overlay_dir, "Earth nav data", FNAMES.round_latlon(lat, lon)
)
UI.vprint(1, "-> Coping the final overlay DSF in " + dest_dir)
UI.vprint(1, "-> Copying the final overlay DSF in " + dest_dir)
if not os.path.exists(dest_dir):
try:
os.makedirs(dest_dir)
Expand Down
2 changes: 1 addition & 1 deletion src/O4_Version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version='1.40.03'
version='1.40.04'

0 comments on commit 97afd19

Please sign in to comment.