Skip to content

Commit

Permalink
refactor: ♻️ refactor lineManager into separate classes
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Aug 16, 2024
1 parent 2e41b8d commit 861e1df
Show file tree
Hide file tree
Showing 31 changed files with 806 additions and 1,025 deletions.
4 changes: 1 addition & 3 deletions src/keepTrackApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type { InputManager } from './singletons/input-manager';
import { PanTouchEvent, TapTouchEvent } from './singletons/input-manager/touch-input';
import type { OrbitManager } from './singletons/orbitManager';
import { Scene } from './singletons/scene';
import { StarManager } from './singletons/starManager';
import type { TimeManager } from './singletons/time-manager';
import type { UiManager } from './singletons/uiManager';
import { WebGLRenderer } from './singletons/webgl-renderer';
Expand Down Expand Up @@ -82,7 +81,7 @@ type KeepTrackApiEventArguments = {
[KeepTrackApiEvents.resize]: [];
[KeepTrackApiEvents.altCanvasResize]: [];
[KeepTrackApiEvents.endOfDraw]: [Milliseconds];
[KeepTrackApiEvents.onWatchlistUpdated]: [number[]];
[KeepTrackApiEvents.onWatchlistUpdated]: [{ id: number, inView: boolean }[]];
[KeepTrackApiEvents.staticOffsetChange]: [number];
[KeepTrackApiEvents.onLineAdded]: [LineManager];
[KeepTrackApiEvents.sensorDotSelected]: [DetailedSensor];
Expand Down Expand Up @@ -266,7 +265,6 @@ export class KeepTrackApi {
}

getSoundManager = () => keepTrackContainer.get<SoundManager>(Singletons.SoundManager);
getStarManager = () => keepTrackContainer.get<StarManager>(Singletons.StarManager);
getRenderer = () => keepTrackContainer.get<WebGLRenderer>(Singletons.WebGLRenderer);
getScene = () => keepTrackContainer.get<Scene>(Singletons.Scene);
getCatalogManager = () => keepTrackContainer.get<CatalogManager>(Singletons.CatalogManager);
Expand Down
11 changes: 0 additions & 11 deletions src/plugins/astronomy/astronomy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class Astronomy extends KeepTrackPlugin {
isIconDisabledOnLoad = true;
isIconDisabled = true;
bottomIconCallback = (): void => {
const catalogManagerInstance = keepTrackApi.getCatalogManager();
const orbitManagerInstance = keepTrackApi.getOrbitManager();
const drawManagerInstance = keepTrackApi.getRenderer();
const uiManagerInstance = keepTrackApi.getUiManager();
Expand All @@ -51,13 +50,6 @@ export class Astronomy extends KeepTrackPlugin {
return;
}

if (catalogManagerInstance.isStarManagerLoaded) {
/*
* TODO: This takes way too long trying to find the star's
* satellite id from its name. The ids should be predetermined.
*/
keepTrackApi.getStarManager().drawAllConstellations();
}
orbitManagerInstance.clearInViewOrbit();
keepTrackApi.getMainCamera().cameraType = CameraType.ASTRONOMY; // Activate Astronomy Camera Mode
// getEl('fov-text').innerHTML = ('FOV: ' + (settingsManager.fieldOfView * 100).toFixed(2) + ' deg');
Expand All @@ -72,9 +64,6 @@ export class Astronomy extends KeepTrackPlugin {
uiManagerInstance.hideSideMenus();
keepTrackApi.getMainCamera().cameraType = CameraType.DEFAULT; // Back to normal Camera Mode
LegendManager.change('default');
if (catalogManagerInstance.isStarManagerLoaded) {
keepTrackApi.getStarManager().clearConstellations();
}
// getEl('fov-text').innerHTML = ('');
getEl(this.bottomIconElementName).classList.remove('bmenu-item-selected');
}
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/debug/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { KeepTrackApiEvents } from '@app/interfaces';
import { keepTrackApi } from '@app/keepTrackApi';
import debugPng from '@public/img/icons/debug.png';

import { LineTypes, lineManagerInstance } from '@app/singletons/draw-manager/line-manager';
import { lineManagerInstance } from '@app/singletons/draw-manager/line-manager';
import { LineColors } from '@app/singletons/draw-manager/line-manager/line';
import eruda from 'eruda';
import { Milliseconds } from 'ootk';
import { KeepTrackPlugin, clickDragOptions } from '../KeepTrackPlugin';
Expand Down Expand Up @@ -126,9 +127,9 @@ export class DebugMenuPlugin extends KeepTrackPlugin {

if (sat) {
const offsetFromSat = keepTrackApi.getMainCamera().getCameraPosition(sat.position, keepTrackApi.getMainCamera().getCameraOrientation());
const position = [sat.position.x + offsetFromSat[0], sat.position.y + offsetFromSat[1], sat.position.z + offsetFromSat[2]];
const camPos = [sat.position.x + offsetFromSat[0], sat.position.y + offsetFromSat[1], sat.position.z + offsetFromSat[2]];

lineManagerInstance.create(LineTypes.REF_TO_SAT, [selectedSat, position[0], position[1], position[2]], 'o');
lineManagerInstance.createRef2Ref([camPos[0], camPos[1], camPos[2]], [sat.position.x, sat.position.y, sat.position.z], LineColors.PURPLE);
}
}
});
Expand All @@ -139,7 +140,7 @@ export class DebugMenuPlugin extends KeepTrackPlugin {
if (camera) {
const position = camera.getCameraPosition();

lineManagerInstance.create(LineTypes.CENTER_OF_EARTH_TO_REF, [position[0], position[1], position[2]], 'r');
lineManagerInstance.createRef2Ref(position, [0, 0, 0], LineColors.PURPLE);
}
});
},
Expand Down
5 changes: 0 additions & 5 deletions src/plugins/planetarium/planetarium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ export class Planetarium extends KeepTrackPlugin {
* getEl('fov-text').innerHTML = ('FOV: ' + (settingsManager.fieldOfView * 100).toFixed(2) + ' deg');
*/
LegendManager.change('planetarium');
const catalogManagerInstance = keepTrackApi.getCatalogManager();

if (catalogManagerInstance.isStarManagerLoaded) {
keepTrackApi.getStarManager().clearConstellations();
}

keepTrackApi.getPlugin(Astronomy)?.setBottomIconToUnselected();
} else {
Expand Down
12 changes: 2 additions & 10 deletions src/plugins/sensor-list/sensor-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { KeepTrackApiEvents } from '@app/interfaces';
import { getClass } from '@app/lib/get-class';
import { getEl } from '@app/lib/get-el';
import { CameraType } from '@app/singletons/camera';
import { LineTypes } from '@app/singletons/draw-manager/line-manager';
import { errorManagerInstance } from '@app/singletons/errorManager';
import { PersistenceManager, StorageKey } from '@app/singletons/persistence-manager';
import { LegendManager } from '@app/static/legend-manager';
Expand Down Expand Up @@ -187,18 +186,11 @@ export class SensorListPlugin extends KeepTrackPlugin {

const sat = selectSatManagerInstance.getSelectedSat();

if (sat.isMissile()) {
if (!sat.isSatellite()) {
return;
}

Object.keys(sensors).forEach((key) => {
const sensor = sensors[key];
const isInView = sensor.isSatInFov(sat as DetailedSatellite, keepTrackApi.getTimeManager().simulationTimeObj);

if (isInView) {
keepTrackApi.getLineManager().create(LineTypes.MULTI_SENSORS_TO_SAT, [sat.id, keepTrackApi.getCatalogManager().getSensorFromSensorName(sensor.name)], 'g');
}
});
keepTrackApi.getLineManager().createSensorsToSatFovOnly(sat as DetailedSatellite);
});
this.isSensorLinksAdded = true;
}
Expand Down
44 changes: 15 additions & 29 deletions src/plugins/sensor/sensor-info-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { KeepTrackApiEvents, ToastMsgType } from '@app/interfaces';
import { keepTrackApi } from '@app/keepTrackApi';
import { getEl, hideEl, showEl } from '@app/lib/get-el';
import { LineManager, LineTypes } from '@app/singletons/draw-manager/line-manager';
import { LineManager } from '@app/singletons/draw-manager/line-manager';
import { SensorToMoonLine } from '@app/singletons/draw-manager/line-manager/sensor-to-moon-line';
import { SensorToSunLine } from '@app/singletons/draw-manager/line-manager/sensor-to-sun-line';
import radioTowerPng from '@public/img/icons/radio-tower.png';
import { RfSensor, SpaceObjectType } from 'ootk';
import { KeepTrackPlugin, clickDragOptions } from '../KeepTrackPlugin';
Expand Down Expand Up @@ -142,8 +144,8 @@ export class SensorInfoPlugin extends KeepTrackPlugin {
}

private checkIfLinesVisible_(lineManager: LineManager) {
this.isSunLineVisible_ = lineManager.drawLineList.some((line) => {
if (line.type === LineTypes.SENSOR_TO_SUN) {
this.isSunLineVisible_ = lineManager.lines.some((line) => {
if (line instanceof SensorToSunLine) {
return true;
}

Expand All @@ -158,8 +160,8 @@ export class SensorInfoPlugin extends KeepTrackPlugin {
this.isSunLineVisible_ = false;
}

this.isMonnLineVisible_ = lineManager.drawLineList.some((line) => {
if (line.type === LineTypes.SENSOR_TO_MOON) {
this.isMonnLineVisible_ = lineManager.lines.some((line) => {
if (line instanceof SensorToMoonLine) {
return true;
}

Expand All @@ -180,9 +182,9 @@ export class SensorInfoPlugin extends KeepTrackPlugin {
if (this.isMonnLineVisible_) {
const lineManager = keepTrackApi.getLineManager();

for (const line of lineManager.drawLineList) {
if (line.type === LineTypes.SENSOR_TO_MOON) {
lineManager.drawLineList.splice(lineManager.drawLineList.indexOf(line), 1);
for (const line of lineManager.lines) {
if (line instanceof SensorToMoonLine) {
line.isGarbage = true;
getEl('sensor-moon-btn').textContent = 'Add Line to Moon \u25B6';
this.isMonnLineVisible_ = false;
keepTrackApi.getSoundManager().play(SoundNames.TOGGLE_OFF);
Expand All @@ -198,17 +200,9 @@ export class SensorInfoPlugin extends KeepTrackPlugin {
keepTrackApi.getUiManager().toast('Please Select Only One Sensor', ToastMsgType.caution);
}

// Draw Line to Sun from Sensor
const scene = keepTrackApi.getScene();
const now = keepTrackApi.getTimeManager().simulationTimeObj;

keepTrackApi
.getLineManager()
.create(
LineTypes.SENSOR_TO_MOON,
[sensors[0].eci(now).x, sensors[0].eci(now).y, sensors[0].eci(now).z, scene.moon.position[0], scene.moon.position[1], scene.moon.position[2]],
'w',
);
.createSensorToMoon(keepTrackApi.getSensorManager().currentSensors[0]);

// Change Button Text
getEl('sensor-moon-btn').textContent = 'Remove Line to Moon \u25B6';
Expand All @@ -223,9 +217,9 @@ export class SensorInfoPlugin extends KeepTrackPlugin {
if (this.isSunLineVisible_) {
const lineManager = keepTrackApi.getLineManager();

for (const line of lineManager.drawLineList) {
if (line.type === LineTypes.SENSOR_TO_SUN) {
lineManager.drawLineList.splice(lineManager.drawLineList.indexOf(line), 1);
for (const line of lineManager.lines) {
if (line instanceof SensorToSunLine) {
line.isGarbage = true;
getEl('sensor-sun-btn').textContent = 'Add Line to Sun \u25B6';
this.isSunLineVisible_ = false;
keepTrackApi.getSoundManager().play(SoundNames.TOGGLE_OFF);
Expand All @@ -241,17 +235,9 @@ export class SensorInfoPlugin extends KeepTrackPlugin {
keepTrackApi.getUiManager().toast('Please Select Only One Sensor', ToastMsgType.caution);
}

// Draw Line to Sun from Sensor
const scene = keepTrackApi.getScene();
const now = keepTrackApi.getTimeManager().simulationTimeObj;

keepTrackApi
.getLineManager()
.create(
LineTypes.SENSOR_TO_SUN,
[sensors[0].eci(now).x, sensors[0].eci(now).y, sensors[0].eci(now).z, scene.sun.position[0], scene.sun.position[1], scene.sun.position[2]],
'o',
);
.createSensorToSun(keepTrackApi.getSensorManager().currentSensors[0]);

// Change Button Text
getEl('sensor-sun-btn').textContent = 'Remove Line to Sun \u25B6';
Expand Down
20 changes: 11 additions & 9 deletions src/plugins/sensor/sensorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { errorManagerInstance } from '@app/singletons/errorManager';
import { KeepTrackApiEvents } from '@app/interfaces';
import { lat2pitch, lon2yaw } from '@app/lib/transforms';
import { waitForCruncher } from '@app/lib/waitForCruncher';
import { LineTypes, lineManagerInstance } from '@app/singletons/draw-manager/line-manager';
import { lineManagerInstance } from '@app/singletons/draw-manager/line-manager';
import { PersistenceManager, StorageKey } from '@app/singletons/persistence-manager';
import { LegendManager } from '@app/static/legend-manager';
import { SatMath } from '@app/static/sat-math';
Expand Down Expand Up @@ -146,18 +146,16 @@ export class SensorManager {
case 'BLEAFB':
case 'CLRSFS':
case 'THLSFB':
lineManagerInstance.create(LineTypes.SENSOR_SCAN_HORIZON, [sensorId, sensor.minAz, sensor.minAz + 120, sensor.minEl, sensor.maxRng], 'c');
lineManagerInstance.create(LineTypes.SENSOR_SCAN_HORIZON, [sensorId, sensor.minAz + 120, sensor.maxAz, sensor.minEl, sensor.maxRng], 'c');
lineManagerInstance.createSensorScanHorizon(keepTrackApi.getSensorManager().getSensorById(sensorId), 1, 2);
lineManagerInstance.createSensorScanHorizon(keepTrackApi.getSensorManager().getSensorById(sensorId), 2, 2);
break;
case 'RAFFYL':
// TODO: Find actual face directions
lineManagerInstance.create(LineTypes.SENSOR_SCAN_HORIZON, [sensorId, 300, 60, sensor.minEl, sensor.maxRng], 'c');
lineManagerInstance.create(LineTypes.SENSOR_SCAN_HORIZON, [sensorId, 60, 180, sensor.minEl, sensor.maxRng], 'c');
lineManagerInstance.create(LineTypes.SENSOR_SCAN_HORIZON, [sensorId, 180, 300, sensor.minEl, sensor.maxRng], 'c');
lineManagerInstance.createSensorScanHorizon(keepTrackApi.getSensorManager().getSensorById(sensorId), 1, 3);
lineManagerInstance.createSensorScanHorizon(keepTrackApi.getSensorManager().getSensorById(sensorId), 2, 3);
lineManagerInstance.createSensorScanHorizon(keepTrackApi.getSensorManager().getSensorById(sensorId), 3, 3);
break;
case 'COBRADANE':
// NOTE: This will be a bit more complicated later
lineManagerInstance.create(LineTypes.SENSOR_SCAN_HORIZON, [sensorId, sensor.minAz, sensor.maxAz, sensor.minEl, sensor.maxRng], 'c');
lineManagerInstance.createSensorScanHorizon(keepTrackApi.getSensorManager().getSensorById(sensorId), 1, 1);
break;
default:
errorManagerInstance.warn('Sensor not found');
Expand Down Expand Up @@ -562,6 +560,10 @@ export class SensorManager {
return this.currentSensors.concat(this.secondarySensors).concat(this.stfSensors);
}

getAllSensors(): DetailedSensor[] {
return Object.values(sensors);
}

public calculateSensorPos(now: Date, sensors?: DetailedSensor[]): { x: number; y: number; z: number; lat: number; lon: number; gmst: GreenwichMeanSiderealTime } {
sensors = this.verifySensors(sensors);
const sensor = sensors[0];
Expand Down
61 changes: 24 additions & 37 deletions src/plugins/watchlist/watchlist-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { dateFormat } from '@app/lib/dateFormat';
import { getEl } from '@app/lib/get-el';
import { shake } from '@app/lib/shake';
import { showLoading } from '@app/lib/showLoading';
import { LineTypes, lineManagerInstance } from '@app/singletons/draw-manager/line-manager';
import { SatMath } from '@app/static/sat-math';
import { lineManagerInstance } from '@app/singletons/draw-manager/line-manager';
import { LineColors } from '@app/singletons/draw-manager/line-manager/line';
import { SensorMath } from '@app/static/sensor-math';
import infoPng from '@public/img/icons/info.png';
import { DetailedSatellite, MILLISECONDS_PER_DAY, Sgp4 } from 'ootk';
import { DetailedSatellite, MILLISECONDS_PER_DAY } from 'ootk';
import { KeepTrackPlugin } from '../KeepTrackPlugin';
import { SelectSatManager } from '../select-sat-manager/select-sat-manager';
import { WatchlistPlugin } from './watchlist';
Expand Down Expand Up @@ -129,62 +129,49 @@ export class WatchlistOverlay extends KeepTrackPlugin {
return;
}
this.updateFovLines_();

for (const element of this.watchlistPlugin_.watchlistInViewList) {
if (element === true) {
return;
}
}
}

private updateFovLinesMulti_(sat: DetailedSatellite, i: number) {
keepTrackApi.getOrbitManager().removeInViewOrbit(this.watchlistPlugin_.watchlistList[i]);
for (const sensor of keepTrackApi.getSensorManager().currentSensors) {
const satrec = Sgp4.createSatrec(sat.tle1, sat.tle2); // perform and store sat init calcs
const rae = SatMath.getRae(keepTrackApi.getTimeManager().simulationTimeObj, satrec, sensor);
const isInFov = SatMath.checkIsInView(sensor, rae);
private updateFovLinesMulti_(sat: DetailedSatellite) {
const idx = this.watchlistPlugin_.watchlistList.findIndex((el) => el.id === sat.id);

if (!isInFov) {
continue;
}
lineManagerInstance.create(LineTypes.SELECTED_SENSOR_TO_SAT_IF_IN_FOV, [sat.id, keepTrackApi.getCatalogManager().getSensorFromSensorName(sensor.name)], 'g');
keepTrackApi.getOrbitManager().removeInViewOrbit(this.watchlistPlugin_.watchlistList[idx].id);
for (const sensor of keepTrackApi.getSensorManager().currentSensors) {
lineManagerInstance.createSensorToSatFovOnly(sensor, sat, LineColors.GREEN);
}
}

private updateFovLinesSingle_(sat: DetailedSatellite, i: number) {
private updateFovLinesSingle_(sat: DetailedSatellite) {
const inView = keepTrackApi.getDotsManager().inViewData[sat.id];
const uiManagerInstance = keepTrackApi.getUiManager();
const idx = this.watchlistPlugin_.watchlistList.findIndex((el) => el.id === sat.id);
const inViewListVal = this.watchlistPlugin_.watchlistList[idx].inView;

if (inView === 1 && this.watchlistPlugin_.watchlistInViewList[i] === false) {
if (inView === 1 && inViewListVal === false) {
// Is inview and wasn't previously
this.watchlistPlugin_.watchlistInViewList[i] = true;
this.watchlistPlugin_.watchlistList[idx].inView = true;
uiManagerInstance.toast(`Satellite ${sat.sccNum} is In Field of View!`, ToastMsgType.normal);
lineManagerInstance.create(
LineTypes.SELECTED_SENSOR_TO_SAT_IF_IN_FOV,
[sat.id, keepTrackApi.getCatalogManager().getSensorFromSensorName(keepTrackApi.getSensorManager().currentSensors[0].name)],
'g',
);
keepTrackApi.getOrbitManager().addInViewOrbit(this.watchlistPlugin_.watchlistList[i]);
lineManagerInstance.createSensorToSatFovOnly(keepTrackApi.getSensorManager().currentSensors[0], sat, LineColors.GREEN);
keepTrackApi.getOrbitManager().addInViewOrbit(this.watchlistPlugin_.watchlistList[idx].id);
}
if (inView === 0 && this.watchlistPlugin_.watchlistInViewList[i] === true) {
if (inView === 0 && inViewListVal === true) {
// Isn't inview and was previously
this.watchlistPlugin_.watchlistInViewList[i] = false;
this.watchlistPlugin_.watchlistList[idx].inView = false;
uiManagerInstance.toast(`Satellite ${sat.sccNum} left Field of View!`, ToastMsgType.standby);
keepTrackApi.getOrbitManager().removeInViewOrbit(this.watchlistPlugin_.watchlistList[i]);
keepTrackApi.getOrbitManager().removeInViewOrbit(this.watchlistPlugin_.watchlistList[idx].id);
}
}

private updateFovLines_() {
const catalogManagerInstance = keepTrackApi.getCatalogManager();
const sensorManagerInstance = keepTrackApi.getSensorManager();

for (let i = 0; i < this.watchlistPlugin_.watchlistList.length; i++) {
const sat = catalogManagerInstance.getSat(this.watchlistPlugin_.watchlistList[i]);
for (const obj of this.watchlistPlugin_.watchlistList) {
const sat = catalogManagerInstance.getSat(obj.id);

if (sensorManagerInstance.currentSensors.length > 1) {
this.updateFovLinesMulti_(sat, i);
this.updateFovLinesMulti_(sat);
} else {
this.updateFovLinesSingle_(sat, i);
this.updateFovLinesSingle_(sat);
}
}
}
Expand Down Expand Up @@ -213,8 +200,8 @@ export class WatchlistOverlay extends KeepTrackPlugin {

const satArray: DetailedSatellite[] = [];

for (const id of this.watchlistPlugin_.watchlistList) {
satArray.push(catalogManagerInstance.getSat(id, GetSatType.EXTRA_ONLY));
for (const obj of this.watchlistPlugin_.watchlistList) {
satArray.push(catalogManagerInstance.getSat(obj.id, GetSatType.EXTRA_ONLY));
}

this.nextPassArray = SensorMath.nextpassList(satArray, sensorManagerInstance.currentSensors, 1, this.OVERLAY_CALC_LENGTH_IN_DAYS);
Expand Down
Loading

0 comments on commit 861e1df

Please sign in to comment.