Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LODレベルを選択できるオプションを追加 #635

Merged
merged 32 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1ffdbcd
lod option
satoshi7190 Aug 21, 2024
b357792
Merge branch 'main' into feature/lod-option
satoshi7190 Aug 22, 2024
9d719bc
Merge branch 'main' into feature/lod-option
satoshi7190 Aug 22, 2024
9caed2a
DataSinkProviderTest
satoshi7190 Aug 22, 2024
a98779a
Selection UI poc
satoshi7190 Aug 22, 2024
29b55ce
Change of type
satoshi7190 Aug 26, 2024
e43f931
Reflected in ui
satoshi7190 Aug 27, 2024
e9b5eb2
Replacement of naming
satoshi7190 Aug 29, 2024
9051f2d
Fixes to TransformerRegistry
satoshi7190 Aug 30, 2024
e0fb5e1
Merge branch 'main' into feature/lod-option
satoshi7190 Aug 30, 2024
c8b4e06
Add command argument.
satoshi7190 Aug 30, 2024
a4e6dc0
Additional error handling
satoshi7190 Sep 2, 2024
3079c22
Merge branch 'main' into feature/lod-option
satoshi7190 Sep 2, 2024
59589cf
Remove unnecessary imports
satoshi7190 Sep 2, 2024
1e80a45
Type modification
satoshi7190 Sep 2, 2024
0907cc1
Modification of lod options
satoshi7190 Sep 2, 2024
72ff456
Error handling fixes
satoshi7190 Sep 2, 2024
a7d9f36
Modification of naming
satoshi7190 Sep 4, 2024
dc6e722
Modification of naming
satoshi7190 Sep 4, 2024
b7006e7
Fix variable declarations
satoshi7190 Sep 4, 2024
dd99cee
Adjustments to the UI
satoshi7190 Sep 4, 2024
d7070ca
Delete requirements
satoshi7190 Sep 5, 2024
d4a4b85
Adjustment of ui
satoshi7190 Sep 5, 2024
498bcff
Added error handling of invalid commands
satoshi7190 Sep 5, 2024
cbfd15c
Comments, correction of variable names
satoshi7190 Sep 9, 2024
4c8c0e2
Implementation of early returns
satoshi7190 Sep 9, 2024
456d5c9
Modification of naming
satoshi7190 Sep 9, 2024
8fc3108
Fixing LodSelection
satoshi7190 Sep 9, 2024
3891dc9
Functionalisation of common options
satoshi7190 Sep 10, 2024
87a21ff
Remove unnecessary borrow in file_path.push() call
satoshi7190 Sep 10, 2024
ae55b39
Refactor redundant pattern matching to use is_err()
satoshi7190 Sep 10, 2024
05bc85d
Merge branch 'main' into feature/lod-option
satoshi7190 Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
source::{citygml::CityGmlSourceProvider, DataSourceProvider},
transformer::{
self, MappingRules, MultiThreadTransformer, NusamaiTransformBuilder, TransformBuilder,
TransformerOption, TransformerRegistry,
TransformerRegistry,
},
};
use nusamai_plateau::models::TopLevelCityObject;
Expand Down Expand Up @@ -135,7 +135,7 @@
filetype: String,
epsg: u16,
rules_path: String,
transformer_options: Vec<TransformerOption>,
transformer_registry: TransformerRegistry,

Check warning on line 138 in app/src-tauri/src/main.rs

View check run for this annotation

Codecov / codecov/patch

app/src-tauri/src/main.rs#L138

Added line #L138 was not covered by tests
sink_parameters: Parameters,
tasks_state: tauri::State<ConversionTasksState>,
window: tauri::Window,
Expand Down Expand Up @@ -191,7 +191,7 @@
sink_provider.create(&sink_params)
};

let mut requirements = sink.make_requirements(transformer_options);
let mut requirements = sink.make_requirements(transformer_registry);

Check warning on line 194 in app/src-tauri/src/main.rs

View check run for this annotation

Codecov / codecov/patch

app/src-tauri/src/main.rs#L194

Added line #L194 was not covered by tests
requirements.set_output_epsg(epsg);

let source = {
Expand Down
69 changes: 69 additions & 0 deletions app/src/lib/components/SinkOptions.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<script lang="ts">
import {
isIntegerParameter,
isStringParameter,
isBooleanParameter,
createRangeArray
} from '$lib/sinkparams';

export let sinkOptionKeys;
export let sinkParameters;
</script>

{#if sinkOptionKeys.length > 0}
<div class="flex flex-col gap-2">
{#each sinkOptionKeys as key}
{#if isIntegerParameter(sinkParameters.items[key].parameter)}
<div class="flex gap-2 w-80">
<label for={key} class="w-3/4 pointer-events-none"
>{sinkParameters.items[key].label}</label
>
<select
bind:value={sinkParameters.items[key].parameter.Integer.value}
id={key}
class="w-1/4 border-2 border-gray-300 px-2 rounded-md cursor-pointer"
>
{#if sinkParameters.items[key].parameter.Integer.min !== undefined && sinkParameters.items[key].parameter.Integer.max !== undefined}
{#each createRangeArray(sinkParameters.items[key].parameter.Integer.min, sinkParameters.items[key].parameter.Integer.max) as value}
<option {value} class="text-center">{value}</option>
{/each}
{/if}
</select>
</div>
{:else if isStringParameter(sinkParameters.items[key].parameter)}
<!-- TODO String input -->
<!-- <div class="flex gap-2 w-80">
<label for={key} class="w-3/4">{sinkParameters.items[key].label}</label>
<input
type="text"
id={key}
bind:value={sinkParameters.items[key].parameter.String.value}
class="w-1/4"
/>
</div> -->
satoshi7190 marked this conversation as resolved.
Show resolved Hide resolved
{:else if isBooleanParameter(sinkParameters.items[key].parameter)}
<div class="flex gap-2 w-80 items-center">
<label for={key} class="w-3/4 pointer-events-none"
>{sinkParameters.items[key].label}</label
>
<div class="relative inline-block w-10 h-6 rounded-full cursor-pointer ml-auto">
<input
bind:checked={sinkParameters.items[key].parameter.Boolean.value}
id={key}
type="checkbox"
class="absolute w-10 h-6 transition-colors duration-300 rounded-full appearance-none cursor-pointer peer bg-gray-200 checked:bg-accent1 peer-checked:before:bg-accent1"
/>
<label
for={key}
class="before:content[''] absolute top-2/4 -left-1 h-6 w-6 -translate-y-2/4 cursor-pointer rounded-full border border-blue-gray-100 bg-white shadow-md transition-all duration-300 peer-checked:translate-x-full"
>
<div
class="inline-block p-5 rounded-full top-2/4 left-2/4 -translate-x-2/4 -translate-y-2/4"
></div>
</label>
</div>
</div>
{/if}
{/each}
</div>
{/if}
46 changes: 46 additions & 0 deletions app/src/lib/components/TransformerOptions.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script lang="ts">
import { isBooleanConfig, isSelectionConfig } from '$lib/transformer';

export let transformerRegistry;
</script>

{#if transformerRegistry && transformerRegistry.configs.length > 0}
{#each transformerRegistry.configs as config}
{#if isBooleanConfig(config.parameter)}
<div class="flex gap-2 w-80 items-center">
<label for={config.key} class="w-3/4 pointer-events-none">
{config.label}
</label>
<div class="relative inline-block w-10 h-6 rounded-full cursor-pointer ml-auto">
<input
bind:checked={config.parameter.Boolean}
id={config.key}
type="checkbox"
class="absolute w-10 h-6 transition-colors duration-300 rounded-full appearance-none cursor-pointer peer bg-gray-200 checked:bg-accent1 peer-checked:before:bg-accent1"
/>
<label
for={config.key}
class="before:content[''] absolute top-2/4 -left-1 h-6 w-6 -translate-y-2/4 cursor-pointer rounded-full border border-blue-gray-100 bg-white shadow-md transition-all duration-300 peer-checked:translate-x-full"
>
<div
class="inline-block p-5 rounded-full top-2/4 left-2/4 -translate-x-2/4 -translate-y-2/4"
></div>
</label>
</div>
</div>
{:else if isSelectionConfig(config.parameter)}
<div class="flex gap-2 w-80">
<label for={config.key} class="w-2/4 pointer-events-none">{config.label}</label>
<select
id={config.key}
class="w-2/4 border-2 border-gray-300 px-2 rounded-md cursor-pointer"
bind:value={config.parameter.Selection.selected_value}
>
{#each config.parameter.Selection.options as option, index (index)}
<option value={option.value}>{option.label}</option>
{/each}
</select>
</div>
{/if}
{/each}
{/if}
24 changes: 14 additions & 10 deletions app/src/lib/sinkparams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ export interface BooleanParameter {
};
}

type Parameter = IntegerParameter | StringParameter | BooleanParameter;
export interface SelectionParameter {
Selection: {
value: { [key: string]: string }[];
};
}

type Parameter = IntegerParameter | StringParameter | BooleanParameter | SelectionParameter;

interface ParamsOptionItem {
parameter: Parameter;
Expand All @@ -33,22 +39,20 @@ export interface SinkParameters {
}

// Check the parameter type
export function isIntegerParameter(
parameter: Parameter
): parameter is { Integer: { value: number; min: number; max: number } } {
export function isIntegerParameter(parameter: Parameter): parameter is IntegerParameter {
return (parameter as { Integer?: unknown }).Integer !== undefined;
}
export function isStringParameter(
parameter: Parameter
): parameter is { String: { value: string } } {
export function isStringParameter(parameter: Parameter): parameter is StringParameter {
return (parameter as { String?: unknown }).String !== undefined;
}
export function isBooleanParameter(
parameter: Parameter
): parameter is { Boolean: { value: boolean } } {
export function isBooleanParameter(parameter: Parameter): parameter is BooleanParameter {
return (parameter as { Boolean?: unknown }).Boolean !== undefined;
}

export function isSelectionParameter(parameter: Parameter): parameter is SelectionParameter {
return (parameter as { Selection?: unknown }).Selection !== undefined;
}

export function createRangeArray(min: number, max: number): number[] {
if (min > max) throw new Error('min should be less than or equal to max');
return Array.from({ length: max - min + 1 }, (_, i) => min + i);
Expand Down
58 changes: 58 additions & 0 deletions app/src/lib/transformer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
export interface SelectionOptions<T extends string> {
label: string;
value: T;
}

export interface SelectionConfig<T extends string> {
options: SelectionOptions<T>[];
selected_value: T;
}

export interface Selection<T extends string> {
Selection: SelectionConfig<T>;
}

export interface TransformerConfig<T> {
key: string;
label: string;
parameter: T;
}

export interface BooleanConfig {
Boolean: boolean;
}

type TransformerParameterType = boolean | SelectionConfig<string>;

export type TransformerRegistry = {
configs: Array<TransformerConfig<TransformerParameterType>>;
};

export type TransformerOptions = {
label: string;
parameter_type: 'Boolean' | 'Selection';
parameter_value: string;
}[];

// Type guard function to determine if the type is a BooleanConfig type.
export function isBooleanConfig(param: unknown): param is BooleanConfig {
return (
typeof param === 'object' &&
param !== null &&
'Boolean' in param &&
typeof param.Boolean === 'boolean'
);
}

// Type guard function to determine if the type is a Selection type.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isSelectionConfig<T extends string>(param: any): param is Selection<T> {
return (
typeof param === 'object' &&
'Selection' in param &&
typeof param.Selection === 'object' &&
Array.isArray(param.Selection.options) &&
'selected_value' in param.Selection &&
typeof param.Selection.selected_value === 'string'
);
}
13 changes: 4 additions & 9 deletions app/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { invoke } from '@tauri-apps/api/tauri';
import { attachConsole } from 'tauri-plugin-log-api';
import type { SinkParameters } from '$lib/sinkparams';
import type { TransformerRegistry } from '$lib/transformer';

import Icon from '@iconify/svelte';
import InputSelector from './InputSelector.svelte';
Expand All @@ -22,28 +23,22 @@
let isConvertButtonDisabled = true;

$: isConvertButtonDisabled = !inputPaths.length || !outputPath || isRunning;
let transformerRegistry: { key: string; label: string; is_enabled: boolean }[];
let transformerRegistry: TransformerRegistry;

async function convertAndSave() {
isRunning = true;

const transformerOptions = transformerRegistry.map((transformerConfig) => {
return {
key: transformerConfig.key,
is_enabled: transformerConfig.is_enabled
};
});

try {
await invoke('run_conversion', {
inputPaths,
outputPath,
filetype,
epsg,
rulesPath,
transformerOptions,
transformerRegistry,
sinkParameters
});

isRunning = false;
await message(`変換が完了しました。\n'${outputPath}' に出力しました。`, { type: 'info' });
} catch (error: any) {
Expand Down
5 changes: 3 additions & 2 deletions app/src/routes/InputSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import Icon from '@iconify/svelte';
import { abbreviatePath } from '$lib/utils';

let isFolderMode = true;
// let isFolderMode = true;
let isFolderMode = import.meta.env.VITE_TEST_INPUT_PATH ? false : true;
let inputFolders: string[] = [];
export let inputPaths: string[] = [];

// Clear the inputs when the mode changes
$: if (isFolderMode || !isFolderMode) {
inputFolders = [];
inputPaths = [];
inputPaths = import.meta.env.VITE_TEST_INPUT_PATH ? [import.meta.env.VITE_TEST_INPUT_PATH] : [];
satoshi7190 marked this conversation as resolved.
Show resolved Hide resolved
}

async function openFolderDialog() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/routes/OutputSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// When filetype changes, reset outputPath
$: {
filetype;
outputPath = '';
outputPath = import.meta.env.VITE_TEST_OUTPUT_PATH ?? '';
}

function clearSelected() {
Expand Down
Loading