Skip to content

Commit

Permalink
feat: configurable material
Browse files Browse the repository at this point in the history
  • Loading branch information
unrealsolver committed Dec 17, 2023
1 parent a586763 commit 2f1292e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/lib/Ggraphic/Info.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
`options.config.fixType.${rightSideFixation?.label}`
)}
</div>
</div>
</div></subsection
>
</details>
Expand Down
5 changes: 3 additions & 2 deletions src/lib/Options/MainMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
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])
</script>

<Accordion>
<Panel bind:open={panel1Open}>
<Header>
<OptionTitle title={$_("options.config.title")}>
<span slot="info"
>{!Number.isNaN($length.valueOf()) && `l=${$length}`}</span
>{!Number.isNaN($length.valueOf()) && `l=${$length.toLocaleString()}${lengthUnitName}`}</span
>
</OptionTitle>
<Toggler isOpen={panel1Open} slot="icon" />
Expand Down
39 changes: 36 additions & 3 deletions src/lib/Options/Material.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
</script>

<TextField
type="number"
label={`${$_("results.density")}`}
on:input={() => (isDirty = true)}
bind:value={$material.density}
/>
<TextField
type="number"
label={`${$_("results.eModulus")} (E, ${$_("units.mpa")})`}
on:input={() => (isDirty = true)}
bind:value={$material.E}
/>
<TextField
type="number"
label={`${$_("results.gModulus")} (G, ${$_("units.mpa")})`}
on:input={() => (isDirty = true)}
bind:value={$material.G}
/>
<TextField label="Filter" bind:value={query} />
<br>
<TreeView
style="padding-left: 0"
labelText="List of materials:"
children={filtered}
on:select={() => (isDirty = false)}
bind:activeId={materialId}
/>
4 changes: 3 additions & 1 deletion src/lib/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
}
},
"material": {
"other": "Other",
"title": "Material",
"filter": "Filter",
"desc": "List of materials"
Expand Down Expand Up @@ -122,6 +123,7 @@
"in": "in",
"H": "H",
"kg": "kg",
"lbf": "lb-force"
"lbf": "lb-force",
"mpa": "MPa"
}
}
4 changes: 3 additions & 1 deletion src/lib/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
}
},
"material": {
"other": "Другой",
"title": "Материал",
"filter": "Фильтровать",
"desc": "Список материалов"
Expand Down Expand Up @@ -122,6 +123,7 @@
"in": "дюйм",
"H": "Н",
"kg": "кг",
"lbf": "фунт-силы"
"lbf": "фунт-силы",
"mpa": "МПа"
}
}
2 changes: 1 addition & 1 deletion src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const LengthUnit = {
IN: "in",
} as const;

export const lengthUnit = writable<keyof typeof LengthUnit>("M");
export const lengthUnit = writable<keyof typeof LengthUnit>("MM");

export const ForceUnit = {
H: "H",
Expand Down

0 comments on commit 2f1292e

Please sign in to comment.