Skip to content

Commit

Permalink
Fix layer selection for custom tile ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephbirkner committed Nov 5, 2024
1 parent e833a4a commit ec15c72
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 39 deletions.
11 changes: 7 additions & 4 deletions erdblick_app/app/jump.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class JumpTargetService {
try {
tileId = BigInt(bigintStr);
} catch {
valid = false;
return null;
}

if (quoted1 || unquoted1) {
Expand All @@ -170,10 +170,10 @@ export class JumpTargetService {
}
}
} else {
valid = false;
return null;
}

if (tileId === -1n || !valid) {
if (tileId === -1n) {
return null;
}

Expand Down Expand Up @@ -216,6 +216,9 @@ export class JumpTargetService {

valid &&= this.validateMapgetTileId(matches[0].toString());
}
else {
valid = false;
}

return {
icon: "pi-database",
Expand Down Expand Up @@ -253,7 +256,7 @@ export class JumpTargetService {
}
}
},
validate: (value: string) => {
validate: (_: string) => {
return valid;
}
}
Expand Down
1 change: 0 additions & 1 deletion erdblick_app/app/search.panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ export class SearchPanelComponent implements AfterViewInit {
for (let i = 0; i < this.searchItems.length; i++) {
// TODO: Introduce a static ID for the action, so we can reference it directly.
if (this.searchItems[i].name === "Inspect Tile Layer Source Data") {
console.assert(this.searchItems[i].validate(value))
this.parametersService.setSearchHistoryState([i, value]);
break;
}
Expand Down
75 changes: 41 additions & 34 deletions erdblick_app/app/sourcedataselection.dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ import {coreLib} from "./wasm";
})
export class SourceDataLayerSelectionDialogComponent {
selectedTileId: SourceDataDropdownOption | undefined;
tileIds: SourceDataDropdownOption[] = [];
selectedSourceDataLayer: SourceDataDropdownOption | undefined;
sourceDataLayers: SourceDataDropdownOption[] = [];
sourceDataLayersMap: Map<string, SourceDataDropdownOption[]> = new Map<string, SourceDataDropdownOption[]>();
selectedMapId: SourceDataDropdownOption | undefined;
mapIdsMap: Map<bigint, SourceDataDropdownOption[]> = new Map<bigint, SourceDataDropdownOption[]>();
selectedSourceDataLayer: SourceDataDropdownOption | undefined;

tileIds: SourceDataDropdownOption[] = [];
mapIds: SourceDataDropdownOption[] = [];
sourceDataLayers: SourceDataDropdownOption[] = [];

mapIdsPerTileId: Map<bigint, SourceDataDropdownOption[]> = new Map<bigint, SourceDataDropdownOption[]>();
sourceDataLayersPerMapId: Map<string, SourceDataDropdownOption[]> = new Map<string, SourceDataDropdownOption[]>();

errorString: string = "";
loading: boolean = true;
customTileId: string = "";
Expand All @@ -86,42 +89,46 @@ export class SourceDataLayerSelectionDialogComponent {
this.load();
});
this.menuService.customTileAndMapId.subscribe(([tileId, mapId]: [string, string]) => {
this.load(tileId.length > 0, tileId, mapId);
this.load(tileId, mapId);
this.menuService.tileSourceDataDialogVisible = true;
});
}

load(withCustomTileId: boolean = false, customTileId: string = "", customMapId: string = "") {
this.showCustomTileIdInput = withCustomTileId;
load(customTileId: string = "", customMapId: string = "") {
this.showCustomTileIdInput = customTileId.length > 0;
this.customTileId = customTileId;
this.customMapId = customMapId;
this.mapIds = [];
this.sourceDataLayers = [];
this.loading = false;
this.menuService.tileOutiline.next(null);
if (withCustomTileId && customTileId) {
const tileId = BigInt(customTileId);
this.triggerModelChange({id: tileId, name: customTileId});

// Special case: There is a custom tile ID.
if (customTileId) {
this.onCustomTileIdChange(customTileId);
return;
}

// Abort if no Tile IDs were provided by the menu service.
if (!this.tileIds.length) {
this.selectedTileId = undefined;
this.errorString = "No tile IDs available for the clicked position!";
return;
}

// Fill map IDs per tile ID.
for (let i = 0; i < this.tileIds.length; i++) {
const id = this.tileIds[i].id as bigint;
const maps = [...this.findMapsForTileId(id)];
this.tileIds[i]["disabled"] = !maps.length;
this.mapIdsMap.set(id, maps);
this.mapIdsPerTileId.set(id, maps);
}
this.selectedTileId = this.tileIds.find(element => !element.disabled);
if (this.selectedTileId === undefined) {
return;

// Pre-select the tile ID.
let tileIdSelection = this.tileIds.find(element => !element.disabled);
if (tileIdSelection) {
this.setCurrentTileId(tileIdSelection);
}
this.triggerModelChange(this.selectedTileId);
}

*findMapsForTileId(tileId: bigint): Generator<SourceDataDropdownOption> {
Expand All @@ -147,28 +154,28 @@ export class SourceDataLayerSelectionDialogComponent {

const tileId = BigInt(tileIdString);
const maps = [...this.findMapsForTileId(tileId)];
this.mapIdsMap.set(tileId, maps);
this.triggerModelChange({id: tileId, name: tileIdString});
this.mapIdsPerTileId.set(tileId, maps);
this.setCurrentTileId({id: tileId, name: tileIdString});
}

private triggerModelChange(tileId: SourceDataDropdownOption) {
private setCurrentTileId(tileId: SourceDataDropdownOption) {
this.selectedTileId = tileId;
this.onTileIdChange(tileId);
if (this.customMapId.length) {
const mapId = { id: this.customMapId, name: this.customMapId };
if (!this.mapIds.includes(mapId)) {
this.mapIds.push(mapId);

if (this.customMapId) {
let mapSelection = this.mapIds.find(entry => entry.id == this.customMapId);
if (mapSelection) {
this.selectedMapId = mapSelection;
}
this.selectedMapId = mapId;
this.findLayersForMapId(mapId.id);
this.onMapIdChange(this.selectedMapId);
if (this.sourceDataLayers.length) {
this.selectedSourceDataLayer = this.sourceDataLayers[0];
this.onLayerIdChange(this.selectedSourceDataLayer);
else {
this.mapIds.unshift({ id: this.customMapId, name: this.customMapId });
}
return;
}

if (this.mapIds.length) {
this.selectedMapId = this.mapIds[0];
if (!this.selectedMapId) {
this.selectedMapId = this.mapIds[0];
}
this.onMapIdChange(this.selectedMapId);
if (this.sourceDataLayers.length) {
this.selectedSourceDataLayer = this.sourceDataLayers[0];
Expand All @@ -182,14 +189,14 @@ export class SourceDataLayerSelectionDialogComponent {
this.selectedSourceDataLayer = undefined;
this.sourceDataLayers = [];
this.outlineTheTileBox(BigInt(tileId.id), Color.HOTPINK);
const mapIds = this.mapIdsMap.get(tileId.id as bigint);
const mapIds = this.mapIdsPerTileId.get(tileId.id as bigint);
if (mapIds !== undefined) {
this.mapIds = mapIds.sort((a, b) => a.name.localeCompare(b.name));
for (let i = 0; i < this.mapIds.length; i++) {
const id = this.mapIds[i].id as string;
const layers = this.findLayersForMapId(id);
this.mapIds[i]["disabled"] = !layers.length;
this.sourceDataLayersMap.set(id, layers);
this.sourceDataLayersPerMapId.set(id, layers);
}
}
}
Expand Down Expand Up @@ -229,7 +236,7 @@ export class SourceDataLayerSelectionDialogComponent {

onMapIdChange(mapId: SourceDataDropdownOption) {
this.selectedSourceDataLayer = undefined;
const sourceDataLayers = this.sourceDataLayersMap.get(mapId.id as string);
const sourceDataLayers = this.sourceDataLayersPerMapId.get(mapId.id as string);
if (sourceDataLayers !== undefined) {
this.sourceDataLayers = sourceDataLayers;
}
Expand Down

0 comments on commit ec15c72

Please sign in to comment.