// Einstellungen eines Gelände-/Umgebungs-Elements (Netzkörper, Gelände, Baugrube) in der Objekt-Info ([137]:
// ein angeklicktes Gelände bzw. eine Baugrube zeigt dort ihre Felder). Gelände zusätzlich: Sichtbarkeit seiner
// Klasse und Glättung (aus den Höhenlinien neu erzeugt, ein Undo-Schritt); Raster-Gelände (swissALTI3D, ohne
// Höhenlinien) additiv nachglätten. [181] Sichtbarkeit nur über die Klasse — kein Einzel-Ausblenden, keine Import-Liste.
//
// Bezeichner englisch, UI-Text/Kommentare deutsch. Alle sichtbaren Texte über t(...).
import { t } from "../i18n";
import { usePanelHost } from "./host";
import { useStore } from "../state/appStore";
import type { ContextObject } from "../model/types";
import { flattenCategories } from "../model/types";
import { resmoothGridTerrain } from "../model/terrain";
import { useEffect, useMemo, useState } from "react";
import type { ExcavationQuantity } from "../core";
/** Zahl-Eingabe für ein Feld eines Kontext-Objekts (leer = Standard, ungültig = keine Änderung). */
export function NumField(props: {
label: string;
value: number | undefined;
step: number;
min?: number;
placeholder?: string;
/** Einheit hinter dem Feld (nicht im Label). */
unit?: string;
title?: string;
onChange: (v: number | undefined) => void;
}) {
return (
{props.label}
{
const raw = e.target.value.trim();
if (raw === "") return props.onChange(undefined);
const v = Number(raw);
if (Number.isFinite(v)) props.onChange(v);
}}
/>
{props.unit}
);
}
const fmt1 = (v: number) => v.toLocaleString("de-CH", { maximumFractionDigits: 1, minimumFractionDigits: 1 });
function ExcavationQty({ q }: { q: ExcavationQuantity | undefined }) {
if (!q) return
{t("site.excavation.noTerrain")}
;
return (
{t("site.excavation.qty", { cut: fmt1(q.cut), fill: fmt1(q.fill), backfill: fmt1(q.backfill) })}
{q.workingSpace > 0 && !q.workingSpaceOk && (
{t("site.excavation.workingSpaceWarn", { min: q.workingSpaceMin.toFixed(2), need: q.workingSpace.toFixed(2), n: q.workingSpaceSpots.length })}
)}
);
}
/** Glättungsstufen der Gelände-Erzeugung (`terrain.rs`, 0 = roh). */
const SMOOTH_LEVELS = [0, 1, 2, 3] as const;
/** [137] Zusätzliche Glättungs-Durchgänge für Raster-Gelände. */
const RESMOOTH_PASSES = [1, 2, 4] as const;
/** [193] Netzpunkt wählen (Nummer ab 1) und seine Höhe setzen; Zuschneiden des Netzes auf die Parzelle. */
function MeshPointFields({ obj }: { obj: Extract }) {
const host = usePanelHost();
const setMeshPointHeight = useStore((s) => s.setMeshPointHeight);
const cropMesh = useStore((s) => s.cropMesh);
const notify = useStore((s) => s.notify);
const parcel = useStore((s) => s.project.siteRules?.parcel);
const deleteMeshPoint = useStore((s) => s.deleteMeshPoint);
const active = useStore((s) => s.activeMeshPoint);
const [nr, setNr] = useState("1");
// Klick auf einen Netzpunkt-Griff im Grundriss wählt den Punkt: Nummer (und damit Höhe) vorausgefüllt.
const activeIndex = active?.id === obj.id ? active.index : null;
useEffect(() => {
if (activeIndex != null) setNr(String(activeIndex + 1));
}, [activeIndex]);
const n = Math.floor(obj.positions.length / 3);
const i = Math.round(Number(nr)) - 1;
const valid = Number.isFinite(i) && i >= 0 && i < n;
return (
<>
{t("site.meshPoint")}
setNr(e.target.value)} />
{t("site.meshPoint.z")}
{
if (valid && e.target.value.trim() !== "") setMeshPointHeight(obj.id, i, Number(e.target.value), `site-${obj.id}-meshZ-${i}`);
}}
/>
m
{
if (valid) deleteMeshPoint(obj.id, i);
}}
>
{t("site.meshPointDelete")}
= 3 ? t("site.meshCrop.hint") : t("site.meshCrop.noParcel")}
onClick={() => {
if (parcel && !cropMesh(obj.id, parcel)) notify(t("site.meshCrop.nothing"), "info");
}}
>
{t("site.meshCrop")}
host.onRunCommand("meshcrop")}>
{t("site.meshCrop.draw")}
>
);
}
/** [193] Höhenversatz (alle Höhen um dz) und, bei Höhenlinien, die Höhe je Linie. */
function HeightFields({ obj }: { obj: ContextObject }) {
const offsetContextHeight = useStore((s) => s.offsetContextHeight);
const setContourHeight = useStore((s) => s.setContourHeight);
const groundContextObjects = useStore((s) => s.groundContextObjects);
const hasTerrain = useStore((s) => s.project.context?.some((c) => c.type === "terrainMesh") ?? false);
const notify = useStore((s) => s.notify);
const [dz, setDz] = useState("");
if (obj.type === "image") return null;
const apply = () => {
if (dz.trim() !== "") offsetContextHeight(obj.id, Number(dz.replace(",", ".")));
setDz("");
};
return (
<>
{t("site.heightOffset")}
setDz(e.target.value)}
onKeyDown={(e) => e.key === "Enter" && apply()}
onBlur={apply}
/>
m
{obj.type === "importedMesh" && (
// [227] Kontextgebäude auf den tiefsten Geländepunkt unter dem Grundriss setzen.
{
if (!groundContextObjects([obj.id])) notify(t("site.ground.nothing"), "info");
}}
>
{t("site.ground")}
)}
{(obj.type === "terrainMesh" || obj.type === "importedMesh") && }
{obj.type === "contourSet" && (
{t("site.contours", { n: obj.contours.length })}
{obj.contours.map((c, i) => (
{`${i + 1} · ${t("site.contour.points", { n: c.pts.length })}`}
{
if (e.target.value.trim() !== "") setContourHeight(obj.id, i, Number(e.target.value), `site-${obj.id}-contourZ-${i}`);
}}
/>
m
))}
)}
>
);
}
/** Felder eines Kontext-Objekts; `null` für Arten ohne eigene Einstellungen (Höhenlinien, Luftbild). */
export function ContextObjectProps({ obj, quantities }: { obj: ContextObject; quantities: readonly ExcavationQuantity[] }) {
return (
<>
>
);
}
function KindFields({ obj, quantities }: { obj: ContextObject; quantities: readonly ExcavationQuantity[] }) {
const host = usePanelHost();
const project = useStore((s) => s.project);
const notify = useStore((s) => s.notify);
const regenerateTerrain = useStore((s) => s.regenerateTerrain);
const resmoothTerrain = useStore((s) => s.resmoothTerrain);
// [137] Raster-Gelände (swissALTI3D) lässt sich ohne Höhenlinien nachglätten; Prüfung nur bei Netz-Wechsel.
const terrainPositions = obj.type === "terrainMesh" ? obj.positions : null;
const isGrid = useMemo(() => (terrainPositions ? resmoothGridTerrain(terrainPositions, 0) !== null : false), [terrainPositions]);
const patch = (field: string) => (v: number | undefined) => host.onPatchContextObject(obj.id, { [field]: v }, `site-${obj.id}-${field}`);
if (obj.type === "importedMesh") {
// [T4] Glatt oder kantig schattieren, Knickwinkel je Mesh (Vorgabe 30°).
return (
{t("site.smoothShading")}
host.onPatchContextObject(obj.id, { smoothShading: e.target.checked }, `site-${obj.id}-smoothShading`)}
/>
{obj.smoothShading === true && (
)}
);
}
if (obj.type === "terrainMesh") {
const cat = flattenCategories(project.layers).find((c) => c.code === obj.categoryCode);
const hasSource = (project.context ?? []).some((o) => o.type === "contourSet");
return (
{cat && (
{t("site.terrain.visible")}
host.onToggleCategory(cat.code)} />
)}
{hasSource && (
{t("site.terrain.smooth")}
{
const v = Number(e.target.value);
if (e.target.value === "" || !Number.isFinite(v)) return;
if (!regenerateTerrain(obj.id, v)) notify(t("site.terrainFailed"), "error");
}}
>
{obj.smooth === undefined && — }
{SMOOTH_LEVELS.map((n) => (
{n === 0 ? t("site.terrain.smooth.raw") : t("site.terrain.smooth.level", { n })}
))}
)}
{!hasSource && (
{t("site.terrain.smooth")}
{
const n = Number(e.target.value);
if (!(n > 0)) return;
if (!resmoothTerrain(obj.id, n)) notify(t("site.terrain.resmooth.unavailable"), "error");
}}
>
{obj.smooth ? t("site.terrain.resmooth.current", { n: obj.smooth }) : t("site.terrain.resmooth.none")}
{isGrid &&
RESMOOTH_PASSES.map((n) => (
{t("site.terrain.resmooth.more", { n })}
))}
)}
{/* [212] Material der Oberfläche (Bauteil): Farbe und Bildkarten im 3D, Pathtracer und Blender-Paket. */}
{t("site.terrain.material")}
host.onPatchContextObject(obj.id, { componentId: e.target.value || undefined })}
>
{t("site.terrain.material.none")}
{(project.components ?? []).map((c) => (
{c.name}
))}
);
}
if (obj.type === "excavation") {
return (
);
}
return null;
}