From 2f1292edfddd487c8b7d0ecf4d511ab7b00cc978 Mon Sep 17 00:00:00 2001 From: Ruslan Panasiuk Date: Mon, 18 Dec 2023 01:54:05 +0500 Subject: [PATCH] feat: configurable material --- src/lib/Ggraphic/Info.svelte | 1 - src/lib/Options/MainMenu.svelte | 5 +++-- src/lib/Options/Material.svelte | 39 ++++++++++++++++++++++++++++++--- src/lib/locales/en.json | 4 +++- src/lib/locales/ru.json | 4 +++- src/lib/store.ts | 2 +- 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/lib/Ggraphic/Info.svelte b/src/lib/Ggraphic/Info.svelte index e18d2e0..2f7a1f8 100644 --- a/src/lib/Ggraphic/Info.svelte +++ b/src/lib/Ggraphic/Info.svelte @@ -38,7 +38,6 @@ `options.config.fixType.${rightSideFixation?.label}` )} - diff --git a/src/lib/Options/MainMenu.svelte b/src/lib/Options/MainMenu.svelte index 19cadd8..30e922c 100644 --- a/src/lib/Options/MainMenu.svelte +++ b/src/lib/Options/MainMenu.svelte @@ -7,13 +7,14 @@ import Toggler from "./Toggler.svelte"; import { Icon } from "@smui/icon-button"; import { _ } from "svelte-i18n"; - import { length, profileInfo, material, loads } from "../store"; + import { length, lengthUnit, LengthUnit, profileInfo, material, loads } from "../store"; import { menuRoute } from "./menuRouter" import BeamConfig from "./BeamConfig.svelte"; let panel1Open = true; let panel2Open = false; let panel3Open = false; + $: lengthUnitName = $_("units." + LengthUnit[$lengthUnit]) @@ -21,7 +22,7 @@
{!Number.isNaN($length.valueOf()) && `l=${$length}`}{!Number.isNaN($length.valueOf()) && `l=${$length.toLocaleString()}${lengthUnitName}`} diff --git a/src/lib/Options/Material.svelte b/src/lib/Options/Material.svelte index c163f0d..1898f81 100644 --- a/src/lib/Options/Material.svelte +++ b/src/lib/Options/Material.svelte @@ -2,6 +2,7 @@ import { material } from "../store"; import TextField from "@smui/textfield"; import { TreeView } from "carbon-components-svelte"; + import { _ } from "svelte-i18n"; import materials from "../materials"; type TreeNodeId = string | number; @@ -37,17 +38,49 @@ })); } - let materialId: number = 0; + let materialId: number | undefined = 0; let filtered: TreeNode[] = []; - $: $material = materials[materialId]; + + let isDirty = false; + + $: { + // Set material to other + if (isDirty) { + // Deselect + materialId = undefined; + $material.name = $_("options.material.other"); + } else if (materialId !== undefined) { + // Copying + $material = Object.assign({}, materials[materialId]); + } + } + $: filtered = mfilter(materials, query); + (isDirty = true)} + bind:value={$material.density} +/> + (isDirty = true)} + bind:value={$material.E} +/> + (isDirty = true)} + bind:value={$material.G} +/> -
(isDirty = false)} bind:activeId={materialId} /> diff --git a/src/lib/locales/en.json b/src/lib/locales/en.json index d408b9b..f90edfc 100644 --- a/src/lib/locales/en.json +++ b/src/lib/locales/en.json @@ -40,6 +40,7 @@ } }, "material": { + "other": "Other", "title": "Material", "filter": "Filter", "desc": "List of materials" @@ -122,6 +123,7 @@ "in": "in", "H": "H", "kg": "kg", - "lbf": "lb-force" + "lbf": "lb-force", + "mpa": "MPa" } } diff --git a/src/lib/locales/ru.json b/src/lib/locales/ru.json index f3d7d68..596905d 100644 --- a/src/lib/locales/ru.json +++ b/src/lib/locales/ru.json @@ -40,6 +40,7 @@ } }, "material": { + "other": "Другой", "title": "Материал", "filter": "Фильтровать", "desc": "Список материалов" @@ -122,6 +123,7 @@ "in": "дюйм", "H": "Н", "kg": "кг", - "lbf": "фунт-силы" + "lbf": "фунт-силы", + "mpa": "МПа" } } diff --git a/src/lib/store.ts b/src/lib/store.ts index c586c54..cdc334d 100644 --- a/src/lib/store.ts +++ b/src/lib/store.ts @@ -124,7 +124,7 @@ export const LengthUnit = { IN: "in", } as const; -export const lengthUnit = writable("M"); +export const lengthUnit = writable("MM"); export const ForceUnit = { H: "H",