Skip to content

Commit

Permalink
Merge branch 'main' into feature/mvt-zoomlevel-gui
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshi7190 committed Jun 28, 2024
2 parents 31cf9fd + bd4f23e commit 7ec7adc
Show file tree
Hide file tree
Showing 33 changed files with 572 additions and 111 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ npx tauri build

### Test

- Test & Lint

```bash
cargo clippy --all-targets --all-features
cargo test --workspace --exclude app --all-features
```

#### Coverage

Codecov: [https://app.codecov.io/gh/MIERUNE/plateau-gis-converter](https://app.codecov.io/gh/MIERUNE/plateau-gis-converter)
Expand Down
14 changes: 7 additions & 7 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use nusamai::{
source::{citygml::CityGmlSourceProvider, DataSourceProvider},
transformer::{
self, MappingRules, MultiThreadTransformer, NusamaiTransformBuilder, TransformBuilder,
TransformerOption, TransformerRegistry,
},
};
use nusamai_plateau::models::TopLevelCityObject;
Expand Down Expand Up @@ -57,7 +58,8 @@ fn main() {
.invoke_handler(tauri::generate_handler![
run_conversion,
cancel_conversion,
get_parameter
get_parameter,
get_transform
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down Expand Up @@ -126,12 +128,14 @@ fn select_sink_provider(filetype: &str) -> Option<Box<dyn DataSinkProvider>> {
}

#[tauri::command(async)]
#[allow(clippy::too_many_arguments)]
fn run_conversion(
input_paths: Vec<String>,
output_path: String,
filetype: String,
epsg: u16,
rules_path: String,
transformer_options: Vec<TransformerOption>,
params_option: Parameters,
tasks_state: tauri::State<ConversionTasksState>,
window: tauri::Window,
Expand Down Expand Up @@ -169,7 +173,7 @@ fn run_conversion(

log::info!("Running pipeline with input: {:?}", input_paths);

let sink = {
let mut sink = {
let sink_provider = select_sink_provider(&filetype).ok_or_else(|| {
let msg = format!("Invalid sink type: {}", filetype);
log::error!("{}", msg);
Expand All @@ -190,7 +194,7 @@ fn run_conversion(
sink_provider.create(&sink_params)
};

let mut requirements = sink.make_requirements();
let mut requirements = sink.make_requirements(transformer_options);
requirements.set_output_epsg(epsg);

let source = {
Expand Down Expand Up @@ -296,6 +300,20 @@ fn cancel_conversion(tasks_state: tauri::State<ConversionTasksState>) {
tasks_state.canceller.lock().unwrap().cancel();
}

/// Get the transform options for a given sink type
#[tauri::command]
fn get_transform(filetype: String) -> Result<TransformerRegistry, Error> {
let sink_provider = select_sink_provider(&filetype).ok_or_else(|| {
let msg = format!("Invalid sink type: {}", filetype);
log::error!("{}", msg);
Error::InvalidSetting(msg)
})?;

let transformer_registry = sink_provider.available_transformer();

Ok(transformer_registry)
}

/// Get the configurable parameters of the sink
#[tauri::command]
fn get_parameter(filetype: String) -> Result<Parameters, Error> {
Expand All @@ -304,7 +322,6 @@ fn get_parameter(filetype: String) -> Result<Parameters, Error> {
log::error!("{}", msg);
Error::InvalidSetting(msg)
})?;

let sink_params = sink_provider.parameters();

Ok(sink_params)
Expand Down
18 changes: 14 additions & 4 deletions app/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="ts">
import { message } from '@tauri-apps/api/dialog';
import { invoke } from '@tauri-apps/api/tauri';
import { attachConsole } from 'tauri-plugin-log-api';
import { message } from '@tauri-apps/api/dialog';
import type { ParamsOption } from '$lib/parameters';
import Icon from '@iconify/svelte';
import InputSelector from './InputSelector.svelte';
import SettingSelector from './SettingSelector.svelte';
import OutputSelector from './OutputSelector.svelte';
import LoadingAnimation from './LoadingAnimation.svelte';
import OutputSelector from './OutputSelector.svelte';
import SettingSelector from './SettingSelector.svelte';
attachConsole(); // For Tauri log in the webview console
Expand All @@ -23,17 +23,26 @@
let isConvertButtonDisabled = true;
$: isConvertButtonDisabled = !inputPaths.length || !outputPath || isRunning || isValidationError;
let transformerRegistry: { key: string; label: string; is_enabled: boolean }[];
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,
paramsOption
});
isRunning = false;
Expand All @@ -57,7 +66,7 @@
{/if}

<div class="py-5 grid place-items-center h-screen">
<div class="max-w-2xl flex flex-col gap-12 pb-4">
<div class="max-w-2xl flex flex-col gap-12 pb-8">
<div class="flex items-center gap-1.5">
<h1 class="font-bold text-2xl">PLATEAU GIS Converter</h1>
<a href="/about" class="hover:text-accent1">
Expand All @@ -73,6 +82,7 @@
bind:rulesPath
bind:paramsOption
bind:isValidationError
bind:transformerRegistry
/>

<OutputSelector {filetype} bind:outputPath />
Expand Down
55 changes: 49 additions & 6 deletions app/src/routes/SettingSelector.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<script lang="ts">
import { dialog } from '@tauri-apps/api';
import Icon from '@iconify/svelte';
import { filetypeOptions } from '$lib/settings';
import { invoke } from '@tauri-apps/api/tauri';
import type { ParamsOption, IntegerParameter } from '$lib/parameters';
import { isIntegerParameter, isStringParameter, isBooleanParameter } from '$lib/parameters';
// TODO debug
import { info, warn, trace, error, attachConsole } from 'tauri-plugin-log-api';
import Icon from '@iconify/svelte';
import { dialog } from '@tauri-apps/api';
export let filetype: string;
export let epsg: number = 4979;
Expand All @@ -16,6 +13,7 @@
export let isValidationError: boolean;
let optionParameter: string[] = [];
export let transformerRegistry: { key: string; label: string; is_enabled: boolean }[];
$: epsgOptions = filetypeOptions[filetype]?.epsg || [];
$: disableEpsgOptions = epsgOptions.length < 2;
Expand Down Expand Up @@ -61,7 +59,6 @@
// Validate the input value
function validateInput(event: any) {
if (isIntegerParameter(paramsOption.items[event.target.id].parameter)) {
warn(event.target.value);
const input = event.target.value;
const param = paramsOption.items[event.target.id].parameter as IntegerParameter;
if (input) {
Expand All @@ -81,6 +78,21 @@
// TODO String validate
}
}
async function getTransformerRegistry(filetype: string) {
const registry = (await invoke('get_transform', { filetype })) as any;
transformerRegistry = registry.configs.map(
(transformerConfig: { key: string; label: string; is_enabled: boolean }) => {
return {
key: transformerConfig.key,
label: transformerConfig.label,
is_enabled: transformerConfig.is_enabled
};
}
);
}
$: getTransformerRegistry(filetype);
</script>

<div>
Expand Down Expand Up @@ -164,6 +176,37 @@
{/each}
</select>
</div>
{#if transformerRegistry && transformerRegistry.length > 0}
<div class="flex flex-col gap-1.5">
<label for="transform-select" class="font-bold">出力の詳細設定</label>
{#each transformerRegistry as config}
<div class="inline-flex items-center gap-6">
<label
for={config.key}
class="mt-px mb-0 ml-3 font-light text-gray-700 cursor-pointer select-none text-sm w-52"
>
{config.label}
</label>
<div class="relative inline-block w-10 h-6 rounded-full cursor-pointer">
<input
bind:checked={config.is_enabled}
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>
{/each}
</div>
{/if}

<div class=" flex flex-col gap-1.5">
<label for="mapping-rule-select" class="font-bold">属性マッピングルール</label>
Expand Down
5 changes: 4 additions & 1 deletion nusamai-citygml/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ impl<'b, R: BufRead> SubTreeReader<'_, 'b, R> {

pub fn skip_current_element(&mut self) -> Result<(), ParseError> {
let Some(start) = &self.state.current_start else {
panic!("skip_current_element() must be called immediately after encountering a new starting tag.");
panic!(
"skip_current_element() must be called immediately after encountering a new \
starting tag."
);
};
self.reader
.read_to_end_into(start.name(), &mut self.state.buf1)?;
Expand Down
5 changes: 4 additions & 1 deletion nusamai-gltf/examples/make_gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ fn main() -> io::Result<()> {
byte_length,
..Default::default()
};
buffer.uri = "data:application/octet-stream;base64,AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAA=".to_string().into();
buffer.uri = "data:application/octet-stream;base64,AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/\
AAAAAAAAAAAAAAAAAACAPwAAAAA="
.to_string()
.into();

let buffer_view1 = BufferView {
name: None,
Expand Down
38 changes: 24 additions & 14 deletions nusamai-gpkg/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,12 @@ impl GpkgHandler {
pub async fn gpkg_geometry_columns(
&self,
) -> Result<Vec<(String, String, String, i32, i8, i8)>, GpkgError> {
let result = sqlx::query("SELECT table_name, column_name, geometry_type_name, srs_id, z, m FROM gpkg_geometry_columns;")
.fetch_all(&self.pool)
.await?;
let result = sqlx::query(
"SELECT table_name, column_name, geometry_type_name, srs_id, z, m FROM \
gpkg_geometry_columns;",
)
.fetch_all(&self.pool)
.await?;

let rows = result
.iter()
Expand Down Expand Up @@ -213,7 +216,8 @@ impl<'c> GpkgTransaction<'c> {

// Add the table to `gpkg_contents`
sqlx::query(
"INSERT INTO gpkg_contents (table_name, data_type, identifier, srs_id) VALUES (?, ?, ?, ?);",
"INSERT INTO gpkg_contents (table_name, data_type, identifier, srs_id) VALUES (?, ?, \
?, ?);",
)
.bind(table_info.name.as_str())
.bind(if table_info.has_geometry {
Expand All @@ -229,13 +233,17 @@ impl<'c> GpkgTransaction<'c> {
// Add the table to `gpkg_geometry_columns`
if table_info.has_geometry {
sqlx::query(
"INSERT INTO gpkg_geometry_columns (table_name, column_name, geometry_type_name, srs_id, z, m) VALUES (?, ?, ?, ?, ?, ?);"
).bind(table_info.name.as_str())
"INSERT INTO gpkg_geometry_columns (table_name, column_name, geometry_type_name, \
srs_id, z, m) VALUES (?, ?, ?, ?, ?, ?);",
)
.bind(table_info.name.as_str())
.bind("geometry")
.bind("MULTIPOLYGON") // Fixed for now - TODO: Change according to the data
.bind(srs_id)
.bind(1)
.bind(0).execute(&mut *executor).await?;
.bind(0)
.execute(&mut *executor)
.await?;
}

// TODO: add MIME type to `gpkg_data_columns`
Expand Down Expand Up @@ -319,13 +327,15 @@ impl<'c> GpkgTransaction<'c> {
(min_x, min_y, max_x, max_y): (f64, f64, f64, f64),
) -> Result<(), GpkgError> {
let executor = self.tx.acquire().await.unwrap();
let query = sqlx::query("UPDATE gpkg_contents SET min_x = ?, min_y = ?, max_x = ?, max_y = ? WHERE table_name = ?;"
)
.bind(min_x)
.bind(min_y)
.bind(max_x)
.bind(max_y)
.bind(table_name);
let query = sqlx::query(
"UPDATE gpkg_contents SET min_x = ?, min_y = ?, max_x = ?, max_y = ? WHERE table_name \
= ?;",
)
.bind(min_x)
.bind(min_y)
.bind(max_x)
.bind(max_y)
.bind(table_name);
query.execute(&mut *executor).await?;
Ok(())
}
Expand Down
4 changes: 1 addition & 3 deletions nusamai-kml/src/conversion.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::{collections::HashMap, vec};

use flatgeom::{Coord, MultiPoint, MultiPoint3, MultiPolygon, MultiPolygon3, Polygon, Polygon3};
use kml::types::{
AltitudeMode, Coord as KmlCoord, Geometry, LinearRing, MultiGeometry, Point,
Polygon as KmlPolygon,
};
use flatgeom::{
Coord, MultiPoint, MultiPoint3, MultiPolygon, MultiPolygon3, Polygon, Polygon3,
};

pub fn multipolygon_to_kml(mpoly: &MultiPolygon3) -> Vec<KmlPolygon> {
multipolygon_to_kml_with_mapping(mpoly, |c| c)
Expand Down
2 changes: 1 addition & 1 deletion nusamai-plateau/src/appearance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
use std::hash::{Hash, Hasher};

use flatgeom::LineString2;
use hashbrown::HashMap;
use nusamai_citygml::{appearance::TextureAssociation, Color, LocalId, SurfaceSpan};
use flatgeom::LineString2;
use url::Url;

use crate::models::appearance::{self, ParameterizedTexture, SurfaceDataProperty, X3DMaterial};
Expand Down
Loading

0 comments on commit 7ec7adc

Please sign in to comment.