feat(workbench): expose junction geometry parameters
This commit is contained in:
1 parent
f6f51fe90b
commit
60e28f6b7a
2 files changed
+69
-2
No files matched your search
@@ -192,6 +192,21 @@ function App() {
|
|||||||
const segmentOf = (roadId: string) => state.compiled.model.roads.find((road) => road.id === roadId)?.segmentId;
|
const segmentOf = (roadId: string) => state.compiled.model.roads.find((road) => road.id === roadId)?.segmentId;
|
||||||
return handlesForSegment(manifest, selected?.segmentId ?? null, segmentOf);
|
return handlesForSegment(manifest, selected?.segmentId ?? null, segmentOf);
|
||||||
}, [editMode, manifest, selected, state]);
|
}, [editMode, manifest, selected, state]);
|
||||||
|
// JunctionTools owns the three shape constraints for an ordinary node. Keep
|
||||||
|
// the same manifest objects and callbacks as the main parameter panel so
|
||||||
|
// number entry and dragging share one preview/undo protocol.
|
||||||
|
const junctionHandles = useMemo(() => {
|
||||||
|
if (!editMode || !junctionDescriptor || junctionDescriptor.ref.type !== 'node' || !manifest) return [];
|
||||||
|
const nodeIds = new Set(junctionDescriptor.nodeIds.map(String));
|
||||||
|
return manifest.handles.filter(
|
||||||
|
(handle) =>
|
||||||
|
(handle.kind === 'junction-approach-width' ||
|
||||||
|
handle.kind === 'junction-cutback' ||
|
||||||
|
handle.kind === 'junction-corner-radius') &&
|
||||||
|
'nodeId' in handle.anchor &&
|
||||||
|
nodeIds.has(String(handle.anchor.nodeId)),
|
||||||
|
);
|
||||||
|
}, [editMode, junctionDescriptor, manifest]);
|
||||||
// A greyed handle without a reason reads as a bug rather than an ownership
|
// A greyed handle without a reason reads as a bug rather than an ownership
|
||||||
// boundary, so the first blocked handle explains itself in the header.
|
// boundary, so the first blocked handle explains itself in the header.
|
||||||
const blockedHandle = editHandles.find((handle) => !handle.editable);
|
const blockedHandle = editHandles.find((handle) => !handle.editable);
|
||||||
@@ -700,6 +715,14 @@ function App() {
|
|||||||
(filter === 'candidates' ? Boolean(item.manualCandidates?.length) : !item.manualCandidates?.length)),
|
(filter === 'candidates' ? Boolean(item.manualCandidates?.length) : !item.manualCandidates?.length)),
|
||||||
);
|
);
|
||||||
const openJunction = (ref: JunctionRef) => {
|
const openJunction = (ref: JunctionRef) => {
|
||||||
|
// Seed direct-edit selection with the first approach so the existing
|
||||||
|
// manifest request loads junction shape handles before the workspace opens.
|
||||||
|
const descriptor = state ? hotspotAt(junctionDescriptors(state), ref) : null;
|
||||||
|
const approach = descriptor?.approachRoadIds[0];
|
||||||
|
if (approach) {
|
||||||
|
const road = state?.compiled.model.roads.find((item) => item.id === approach);
|
||||||
|
if (road) setSelected(road);
|
||||||
|
}
|
||||||
window.history.pushState({}, '', `/junction/${ref.type}/${encodeURIComponent(ref.id)}`);
|
window.history.pushState({}, '', `/junction/${ref.type}/${encodeURIComponent(ref.id)}`);
|
||||||
setJunctionRoute(ref);
|
setJunctionRoute(ref);
|
||||||
};
|
};
|
||||||
@@ -855,8 +878,12 @@ function App() {
|
|||||||
visible={layers}
|
visible={layers}
|
||||||
scene={scene}
|
scene={scene}
|
||||||
junctionHotspots={junctionHotspots}
|
junctionHotspots={junctionHotspots}
|
||||||
onJunctionHotspot={(ref: JunctionRef) => {
|
onJunctionHotspot={(ref: JunctionRef, _coordinate, descriptor) => {
|
||||||
openJunction(ref);
|
openJunction(ref);
|
||||||
|
const approachRoad = descriptor.approachRoadIds
|
||||||
|
.map((roadId) => state.compiled.model.roads.find((road) => road.id === roadId))
|
||||||
|
.find((road): road is Road => Boolean(road));
|
||||||
|
if (approachRoad) setSelected(approachRoad);
|
||||||
setStatus(ref.type === 'node' ? `已定位路口节点 ${ref.id}(可编辑)` : `已定位路口 ${ref.id}(只读)`);
|
setStatus(ref.type === 'node' ? `已定位路口节点 ${ref.id}(可编辑)` : `已定位路口 ${ref.id}(只读)`);
|
||||||
}}
|
}}
|
||||||
onSelectRoad={setSelected}
|
onSelectRoad={setSelected}
|
||||||
@@ -983,6 +1010,17 @@ function App() {
|
|||||||
setStatus((error as Error).message);
|
setStatus((error as Error).message);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
handles={junctionHandles}
|
||||||
|
onDraft={draftValue}
|
||||||
|
onSettle={(handle, value) => {
|
||||||
|
settleValue(handle, value);
|
||||||
|
setJunctionSession((current) => (current ? { ...current, status: 'draft', dirty: true } : current));
|
||||||
|
}}
|
||||||
|
onAbandon={abandonGesture}
|
||||||
|
onReset={(handle) => {
|
||||||
|
resetHandle(handle);
|
||||||
|
setJunctionSession((current) => (current ? { ...current, status: 'draft', dirty: true } : current));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { useMemo } from 'react';
|
|||||||
import type { JunctionDescriptor } from './hotspots';
|
import type { JunctionDescriptor } from './hotspots';
|
||||||
import { canEditJunction, type JunctionSession } from './workspace';
|
import { canEditJunction, type JunctionSession } from './workspace';
|
||||||
import { Button } from '../ui/button';
|
import { Button } from '../ui/button';
|
||||||
|
import { ParameterPanel } from '../components/ParameterPanel';
|
||||||
|
import type { EditHandle } from '../edit/types';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
descriptor: JunctionDescriptor;
|
descriptor: JunctionDescriptor;
|
||||||
@@ -10,9 +12,26 @@ interface Props {
|
|||||||
onApply: () => void;
|
onApply: () => void;
|
||||||
onDiscard: () => void;
|
onDiscard: () => void;
|
||||||
onSave: () => void;
|
onSave: () => void;
|
||||||
|
handles?: EditHandle[];
|
||||||
|
onDraft?: (handle: EditHandle, value: number) => void;
|
||||||
|
onSettle?: (handle: EditHandle, value: number) => void;
|
||||||
|
onAbandon?: () => void;
|
||||||
|
onReset?: (handle: EditHandle) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function JunctionWorkspace({ descriptor, session, onClose, onApply, onDiscard, onSave }: Props) {
|
export function JunctionWorkspace({
|
||||||
|
descriptor,
|
||||||
|
session,
|
||||||
|
onClose,
|
||||||
|
onApply,
|
||||||
|
onDiscard,
|
||||||
|
onSave,
|
||||||
|
handles = [],
|
||||||
|
onDraft,
|
||||||
|
onSettle,
|
||||||
|
onAbandon,
|
||||||
|
onReset,
|
||||||
|
}: Props) {
|
||||||
const editable = useMemo(() => canEditJunction(descriptor), [descriptor]);
|
const editable = useMemo(() => canEditJunction(descriptor), [descriptor]);
|
||||||
return (
|
return (
|
||||||
<section className="junction-workspace" aria-label="路口编辑工作区">
|
<section className="junction-workspace" aria-label="路口编辑工作区">
|
||||||
@@ -41,6 +60,15 @@ export function JunctionWorkspace({ descriptor, session, onClose, onApply, onDis
|
|||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
{editable ? (
|
{editable ? (
|
||||||
|
<>
|
||||||
|
<ParameterPanel
|
||||||
|
handles={handles}
|
||||||
|
hasSelection
|
||||||
|
onDraft={onDraft ?? (() => undefined)}
|
||||||
|
onSettle={onSettle ?? (() => undefined)}
|
||||||
|
onAbandon={onAbandon ?? (() => undefined)}
|
||||||
|
onReset={onReset ?? (() => undefined)}
|
||||||
|
/>
|
||||||
<div className="junction-workspace__actions">
|
<div className="junction-workspace__actions">
|
||||||
<Button onClick={onApply} disabled={!session.dirty}>
|
<Button onClick={onApply} disabled={!session.dirty}>
|
||||||
应用到工作区
|
应用到工作区
|
||||||
@@ -52,6 +80,7 @@ export function JunctionWorkspace({ descriptor, session, onClose, onApply, onDis
|
|||||||
放弃草稿
|
放弃草稿
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
Reference in new issue
Block a user