Repository Public
1<!--2ORIX Cosmos3File: Documentation/modules/CosmosUI.md4Description: Reference of the interface module: what the solar-system workstation slice contains, how the scene is assembled, the extension points for the next domains, how it was verified, measured performance, and what is not implemented.5Author: Simon-Pierre Boucher6Contact: contact@spboucher.ai7-->8# CosmosUI — interface and application integration910First vertical slice: the **solar-system workstation**. The window structure (sidebar, Metal viewport, inspector,11timeline, toolbar, menus, preferences, methodology) is in place and driven by real ephemerides; later domains12(stars, galaxies, laboratory, observatory, missions, studio) plug into the extension points of section 4.1314```15swift build --scratch-path .build-ui --target CosmosUI16swift test --scratch-path .build-ui --filter CosmosUITests # 23 tests, 5 suites17Scripts/build.sh debug # app (xcodegen + xcodebuild)18Scripts/build.sh capture [dir] # 13 offscreen captures of the real window hierarchy19python3 Packages/CosmosUI/Tools/make_strings.py # regenerate the string catalogue (fails on a missing French text)20```2122## 1. Sources2324| File | Role |25|---|---|26| `SolarSystemData.swift` | Loads `core-ephemeris`, `missions` and the planetary data set; list of bodies (`BodyEntry`: kind, parent, radii, position method, coverage); `snapshot(at:lightTime:)` → positions, velocities, orientations; orbit paths; `ScaleSettings`, `LightTimeMode` |27| `SceneAssembly.swift` | `SceneAssembler`: snapshot → `SceneDescription` (scene frame re-centred on the camera target, bodies, light, orbit lines, markers, labels) and the screen-space list used for picking and accessibility |28| `SceneResources.swift` | `OrbitStore` (orbit-line cache refreshed on a background task), `TextureCatalog` (registration of installed surface maps), `SurfaceMapState` |29| `CameraController.swift` | Free / orbit / follow / synchronous modes on the renderer's `OrbitRig`, `FollowRig`, `FreeFlyRig`; go-to flights; view history; `ViewState` |30| `TimeController.swift` | Transport over `CosmosClock`: rate ladder, exact steps, date parsing, read-outs, validity messages, recorded instants |31| `Inspector.swift` | `InspectorBuilder` → `InspectorSnapshot` (sections of `DatumRow`, provenance cards) |32| `Search.swift` | `SearchEngine`, `SearchProvider`, solar-system / coordinates / `CatalogProvider` providers, ranking, `Naming` |33| `Formatting.swift` | `QuantityFormatter`: unit systems, significant digits, locale separators, locale-independent copy text |34| `Localization.swift` | `Localizer`, `L(key, english, args…)`, `InterfaceLanguage` |35| `PackLocation.swift` | `PackLocating`, `DirectoryPackLocator`, `InstalledPack` (manifest summary) |36| `Session.swift` | `Preferences`, `CommandID` + `ShortcutBinding`, `SessionState`, `SessionStore` |37| `AppModel.swift` | Main-actor state: per-frame assembly, 10 Hz read-outs, selection, navigation, session; the extension protocols |38| `Capture.swift` | `--screenshot` mode and the real-data benchmark scene |39| `Views/…` | `CosmosRootView`, toolbar, sidebar, inspector, timeline, viewport and input, search, welcome, methodology, preferences, `CosmosCommands` |40| `Resources/Localizable.xcstrings` | String catalogue, English and French (398 keys), generated by `Tools/make_strings.py` |4142The application target (`App/`) only declares the scenes (main window, detached inspector and timeline, methodology,43settings), the menu bar (`CosmosCommands`) and the verification launch modes.4445## 2. How a frame is built4647Every frame, on the main actor (`AppModel.frame`):48491. `SolarSystemData.snapshot(at:)` — one ephemeris state per body, relative to the solar-system barycentre, ICRF,50 Double. Planets and the Sun come from DE440s; the Moon relative to the Earth; moons, dwarf planets, asteroids51 and comets from the osculating elements relative to their centre; the centres of Mars…Pluto through the52 ephemeris module's `PlanetCenterFromSatellites`; spacecraft from the missions pack **inside their coverage53 only**. A body whose source does not cover the instant is marked unavailable and is not drawn. Outside the54 DE440s span everything that depends on the kernel is hidden and the interface says so.552. Orientation: IAU rotation model of `pck00011.tpc` (`icrfToBody` transposed); the Earth uses56 `CosmosCoordinates.EarthOrientation` (IAU 2006 / 2000B, UT1 from the time system).573. Optional light-time: `ApparentPosition.state(… correction: .lightTime)` of the ephemeris module for every body58 as seen from the Earth; orientations are evaluated at the emission time.594. Display positions: identical to the ephemeris in physical scale; in pedagogical scale moons are displaced60 (`ScaleSettings.moonDisplacement`).615. The **scene origin is the display position of the camera target**: every position is `display − origin` in62 Double before the renderer narrows it. The camera pose comes from the rigs, relative to that origin.636. `SceneAssembler.build`: bodies (kernel radii, oblateness, textures when installed, atmosphere and rings from64 CosmosPlanetary), the Sun as emissive body and inverse-square light, orbit lines from the cache, markers,65 labels. Exposure = (distance of the target from the Sun in au)², so every planet is legible; line colours are66 divided by the exposure so that annotations look the same everywhere.6768Orbit lines (`SolarSystemData.orbitPaths`): kernel bodies — the ephemeris trajectory relative to the parent over69one osculating period centred on the instant, 720 samples, open polyline, status `computed`, recomputed off the70main actor when the instant has moved by more than a quarter of the window (at most ten refreshes per second);71Keplerian bodies — the osculating ellipse of the installed elements, closed, status `estimated` (the renderer72draws it dashed); spacecraft — the sampled trajectory, one polyline per segment so that gaps stay gaps, relative73to the Earth for objects that never leave its neighbourhood (0.02 au). For Mars…Pluto the line is the trajectory74of the system barycentre.7576Markers: a body whose displayed disc is under 3 pt gets a hollow ring of fixed screen size (a diamond for77spacecraft), drawn without depth test; a resolved body is a filled disc. The legend states the difference.78Labels have priorities selection 100 > Sun 90 > planets 80 > dwarf planets 60 > moons 50 > spacecraft 45 > small79bodies 40 and fade with the apparent separation from the parent body (12 → 34 pt). Close to a body, the orbits,80markers and labels of unrelated small bodies fade out.8182Scale modes: *physical* (true sizes and distances); *pedagogical* (planets, moons and small bodies × N, default83300, Sun × min(N, 40) with its true total flux, every body lit as at 1 au, moons displaced by84(N − 1)(R planet + R moon)), with the permanent badge "Enlarged ×N — not to scale".8586## 3. Packs at runtime8788`DirectoryPackLocator.standard()` searches, per pack, `COSMOS_PACKS_DIR`, then89`~/Library/Application Support/ORIX Cosmos/Packs`, then `Contents/Resources/Packs` of the bundle. `project.yml`90copies `core-ephemeris`, `missions` and `textures-starter` into the bundle as folders (about 70 MB of data; `textures-hd`91and `sky-imagery` are not embedded). Without `core-ephemeris` the model enters `Phase.missingCore`: a localised92panel lists the folders searched, nothing is drawn, the timeline, methodology and preferences still work.93`PackLocating` is the seam for `CosmosDataPacks.PackStore`.9495## 4. Extension points for the next slices9697| Need | Mechanism |98|---|---|99| Sidebar entries of a new domain | `SidebarSectionProvider.sidebarSections()` appended to `AppModel.sidebarProviders` (a domain appears only when its provider is registered) |100| Scene content (star fields, deep sky, grids, laboratory bodies) | `SceneLayer.contribute(to:context:)` in `AppModel.sceneLayers`; the context gives the instant, the barycentric origin to subtract in Double, the camera pose, the viewport and the scale mode |101| Inspector sections | `InspectorSectionProvider.sections(for:at:formatter:)` in `AppModel.inspectorProviders` |102| Search | any `SearchProvider`; `CatalogSearchProvider(catalog)` wraps a `CatalogProvider` — rebuild `AppModel.searchEngine` with it |103| Timeline events | `TimelineEventProvider.events(in:)` in `AppModel.timelineProviders` (ticks on the scrubber); recorded instants and the events of the selected mission are already there |104| Packs | another `PackLocating` passed to `AppModel(packs:)` |105| A new command with a shortcut | a case of `CommandID` (title, default binding) and one line in `CosmosCommands` |106| A new string | `L("key", "English")` in the code, the French text in `Tools/make_strings.py`, then run the script |107108Selecting an object that the solar-system layer does not know (`AppModel.perform` with an unknown `ObjectID`) only109sets the selection: the owning domain must supply the go-to behaviour.110111## 5. Verification112113Unit and integration tests (`Packages/CosmosUI/Tests`, Swift Testing, run against `Resources/Packs`): 23 tests.114Among them: positions of the Earth, Moon, Mars and Titan in the snapshot equal to the ephemeris; the sub-solar115point of the Earth at 2025-03-20 12:00 UTC within 0.06° of the Astronomical Almanac low-precision solar formulas116(longitude −EoT = +1.87°, latitude +0.05°), both from the snapshot and from the assembled scene; coverage117enforcement (1970 for Voyager 1, 2200 for everything); light-time against `apparentState`; scale factors, badge118and moon displacement; markers, label priorities, rings; orbit lines against the ephemeris; search ranking and119coordinate parsing; formatting and "unknown"; rate ladder, exact steps, typed dates, validity warnings; camera120flights (monotonic, interruptible, Reduce Motion), modes, synchronous rotation, history, zoom range 3 m – 10¹⁷ m;121picking; inspector content and provenance; session round trip; preferences and shortcut reassignment; missing122core pack; pack priority order; orbit-cache refresh policy; every string present in both languages.123124Captures: `"ORIX Cosmos" --screenshot out.png --state … ` creates the real root view in an off-screen window of an125accessory application (never ordered in, never activated), draws the SwiftUI hierarchy with `cacheDisplay`, and126composites it over an offscreen render (`renderImage`) of the frame the viewport would draw, at the viewport's127size. A JSON side-car holds the accessibility summary, the inspector text and scene counts. Red night mode in a128capture is the same operation as the live tint (multiply by pure red) applied to the composite. Inspected on1292026-11-24 (in `build/captures/`): welcome (fr), overview (fr), Earth, Earth at the 2025 March equinox in130synchronous mode with apparent positions, Saturn with rings, enlarged Jupiter, New Horizons on 2015-07-14 in night131mode, year 2200 (fr, outside coverage), quick-search palette (fr, light appearance), methodology, preferences132(fr), missing core pack (fr).133134Menus: `open -g -j "ORIX Cosmos.app" --args --dump-menus out.json` starts the real SwiftUI application hidden,135writes the menu bar (titles, key equivalents, check marks) and quits; checked in English and in French.136137**Not verified by a person or by an automated test:** the live window on a display; mouse, trackpad and keyboard138navigation (events cannot be injected without driving the session); the live red tint (a Core Animation139compositing filter); the detached inspector and timeline windows; the shortcut recorder; full screen; VoiceOver.140141## 6. Measured performance142143`"ORIX Cosmos" --benchmark 15 out.json --scene solar-system|solar-system-overview`, Release build, 2026-11-24,144MacBook Pro Mac17,6 (Apple M5 Max, 18 cores, 48 GB), macOS 27.0, built-in display 120 Hz with EDR, drawable1453 456 × 2 234 px, MSAA 4×, render scale 1.00 (dynamic resolution off), 15 s after a 1.5 s warm-up, window ordered146behind the others, one-minute load average 12–13 (other builds running). Full records: `Benchmarks/ui/*.json`.147148| | Earth close-up (`solar-system`) | Whole system (`solar-system-overview`) |149|---|---|---|150| Content | 63 bodies assembled, Earth from 3.2 radii with albedo, clouds, night lights, specular mask, normal map, atmosphere; time 1 h/s; camera turning | 63 bodies, every orbit line, marker and label from 12 au; time 1 day/s; camera turning |151| Frame rate | 120.0 fps (display-limited), interval p99 9.45 ms | 120.0 fps, interval p99 9.07 ms |152| GPU time per frame | median 5.40 ms, p95 5.92, p99 6.15 | median 2.68 ms, p95 2.84, p99 2.88 |153| Renderer CPU per frame | median 0.28 ms, p99 0.44 | median 0.82 ms, p99 1.88 |154| **Scene assembly on the main actor** | median **0.20 ms**, p95 0.26, p99 0.32, max 0.49 | median **0.18 ms**, p95 0.22, p99 0.25, max 0.29 |155| Work | 25 draw calls, 25 289 triangles | 82 draw calls, 93 299 triangles |156| Orbit-cache refreshes (background) | 1 | 3 |157| Memory | textures 92 MB, footprint 1 078 MB | textures 17 MB, footprint 1 009 MB |158159In a Debug build the assembly takes about 1.0–1.2 ms per frame. The inspector, the time read-outs and the160accessibility summary are rebuilt ten times per second by a separate task and assigned only when they changed.161162## 7. Partial and not implemented163164- **Stars and sky background**: none; the sky is black. CosmosCatalog is not integrated (`CatalogSearchProvider`165 exists, no provider is registered).166- **Astronomical events** (eclipses, conjunctions): not wired; the timeline shows recorded instants and the events167 of the selected mission only.168- **CosmosDataPacks**: not used; packs are found by direct directory lookup behind `PackLocating`. No pack manager.169- **Laboratory, cosmology, observatory, missions tour, studio**: no navigation entry (left out until they exist).170- **Light-time observer**: the Earth only. Stellar aberration is not applied in the 3D view.171- **Resolution scale**: the renderer exposes dynamic resolution only; the preference is on/off plus a minimum scale,172 not a fixed scale. MSAA, the frame-rate cap and texture quality apply when the viewport is created.173- **Increase Contrast**: nothing specific beyond the system colours and materials.174- **Localisation gaps**: mission event labels, credits, licence texts and notes of the data sets stay in the175 language of the source (English). Window titles follow the language at launch.176- **Pedagogical scale**: moons end up close to their enlarged planet (the true surface gap is small compared with177 the enlarged sizes); spacecraft keep their true positions and can be inside an enlarged body (their marker stays178 visible).179- **Estimated status of Mars…Pluto**: their centre uses the satellite-based estimate; a satellite kernel pack would180 make them `computed`.181- **Uncertainties**: shown for the physical values that carry one; none for positions.182- **UI tests**: no XCUITest was written.183- **Window restoration**: the session (camera, time, selection, panels, modes, favourites) is saved every two184 seconds and at quit, and restored at launch; window frames are left to macOS.185186## 8. Requests to other modules187188- **CosmosRender**: a fixed render-scale setting; a screen-space marker primitive and exposure-independent189 polylines (the interface builds rings as polylines and divides colours by the exposure); a picking query.190- **CosmosEphemeris**: expose names and kinds of the bodies of `kepler_elements.json` (the interface re-reads the191 file); a `BodyFixedRotationProvider` conformance for `PlanetaryConstants`; a satellite-kernel pack.192- **CosmosPlanetary**: albedo of ring segments where published (rings without one are neutral grey); localised193 names are held by the interface.194- **CosmosDataPacks**: a `PackLocating` adapter over `PackStore`.195- **CosmosAstrodynamics**: a `TimelineEventProvider`.196