SPB Git

Repository Public BSD-3-Clause

PlannerScreen.swift 8.5 KB 179 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Maps9// File             : Apps/ORIXMaps/Sources/Explore/PlannerScreen.swift10// Module           : Explore11// Repository       : https://git.spboucher.ai/orix-maps12// Created          : 2026-11-2513// Last Modified    : 2026-11-2514//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author           : Simon-Pierre Boucher20// Position         : Professor of Finance21// Institution      : Université du Québec en Outaouais (UQO)22// Department       : Département des sciences administratives23// Organization     : SP Boucher24//25// Website          : https://spboucher.ai26// Git              : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General          : info@spboucher.ai33// Professional     : contact@spboucher.ai34// Direct           : simon@spboucher.ai35// Research         : research@spboucher.ai36// Development      : dev@spboucher.ai37// Support          : support@spboucher.ai38// Security/Admin   : admin@spboucher.ai39// Notifications    : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification   : Public66// Distribution     : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License          : Proprietary, all rights reserved (see license file)80// License File     : LICENSE81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import ORIXDesignSystem89import ORIXGeoCore90import ORIXMapPackage91import SwiftUI9293/// ORIX Offline Planner: before leaving, which maps does this trip need, and which are missing on this device?94struct PlannerScreen: View {95    @Environment(AppModel.self) private var app96    @State private var destination: PlaceSelection?9798    private var language: String { app.settings.interfaceLanguageCode }99100    /// The line to check: the planned route when there is one, otherwise the straight line from the position (or the map101    /// centre) to the chosen place.102    private var line: (points: [Coordinate], isRoute: Bool)? {103        if let route = app.directions.route { return (route.geometry, true) }104        guard let destination else { return nil }105        let start = app.location.lastFix?.coordinate ?? app.map.camera.center106        return ([start, destination.coordinate], false)107    }108109    var body: some View {110        List {111            Section {112                if app.directions.route != nil {113                    Label("Checking the route currently planned", systemImage: "arrow.triangle.turn.up.right.diamond")114                } else {115                    Picker("Destination", selection: $destination) {116                        Text("Choose a saved place").tag(PlaceSelection?.none)117                        ForEach(app.library.places) { p in118                            Text(p.name).tag(Optional(PlaceSelection(id: p.id, title: p.name, subtitle: p.address, coordinate: p.coordinate, origin: .saved(p.id.uuidString))))119                        }120                    }121                    if app.library.places.isEmpty { Text("Save the place you are going to, or plan a route, then come back here.").font(.footnote).foregroundStyle(.secondary) }122                }123            } footer: {124                Text("The planner compares the trip with the maps on this device and with the catalog. With no planned route it checks a straight line, which the real road may leave.")125            }126            if let line {127                let report = coverage(of: line.points)128                Section("Coverage") {129                    LabeledContent("Trip length") { Text(verbatim: app.settings.formatter.distance(Geodesy.length(of: line.points))) }130                    LabeledContent("Covered by installed maps") { Text(report.coveredShare, format: .percent.precision(.fractionLength(0))) }131                    if report.isComplete {132                        Label("Every part of this trip is inside an installed map.", systemImage: "checkmark.seal.fill").foregroundStyle(ORIX.Palette.success)133                    } else {134                        NoticeView("Part of this trip is outside the maps on this device: no streets, search or directions there without a connection.", kind: .warning)135                    }136                    if !line.isRoute { NoticeView("Straight-line check. Plan the route for an exact answer.") }137                }138                if !report.installed.isEmpty {139                    Section("Installed maps on the way") {140                        ForEach(report.installed) { r in Label(r.name(language: language), systemImage: "checkmark.circle.fill") }141                    }142                }143                if !report.available.isEmpty {144                    Section("Maps to download for this trip") {145                        ForEach(report.available) { r in146                            HStack {147                                VStack(alignment: .leading) {148                                    Text(r.name(preferring: [language]))149                                    Text(verbatim: app.settings.formatter.bytes(Int64(r.latest.downloadSize))).font(.footnote).foregroundStyle(.secondary)150                                }151                                Spacer()152                                if app.regionsModel.downloads[r.id] != nil { ProgressView() } else {153                                    Button("Download") { app.regionsModel.download(r) }.buttonStyle(.borderless)154                                }155                            }156                        }157                    }158                }159                if !report.isComplete, report.available.isEmpty {160                    Section { Text(app.regionsModel.catalog == nil ? "The catalog is not loaded: connect once to see which maps exist for the rest of the trip." : "No published map covers the rest of this trip yet.").foregroundStyle(.secondary) }161                }162            }163        }164        .accessibilityIdentifier("planner.list")165        .navigationTitle("Trip planner")166        .navigationBarTitleDisplayMode(.inline)167        .task { await app.regionsModel.refreshCatalog() }168    }169170    private func coverage(of points: [Coordinate]) -> TripCoverage {171        TripCoverage.compute(line: points, regions: app.regions, catalog: app.regionsModel.catalog?.document.regions ?? [],172                             installedIDs: Set(app.regionsModel.installed.map(\.id)))173    }174}175176extension PlaceSelection: Hashable {177    func hash(into hasher: inout Hasher) { hasher.combine(id) }178}179
Files main
Menu

Theme