feat(simulation): integrate infrastructure jobs and semantic scene editing
Integrate infrastructure preparation and qualified map delivery with local scenes. Add semantic editing, object provenance, survey caching and operator scene tools.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { Button } from "@nodedc/ui-react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import * as THREE from "three";
|
||||
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
||||
@@ -355,11 +356,11 @@ export function PolygonRoverScene({
|
||||
<div ref={hostRef} className="polygon-rover-scene__viewport">
|
||||
{renderError ? <p className="polygon-rover-scene__error">{renderError}</p> : null}
|
||||
</div>
|
||||
<div className="polygon-rover-scene__toolbar">
|
||||
<button type="button" onClick={() => setFollowRover((value) => !value)}>
|
||||
<div className="polygon-rover-scene__toolbar nodedc-viewport-controls">
|
||||
<Button onClick={() => setFollowRover((value) => !value)}>
|
||||
{followRover ? "Следовать за ровером" : "Свободная камера"}
|
||||
</button>
|
||||
<button type="button" onClick={resetCamera}>Сбросить ракурс</button>
|
||||
</Button>
|
||||
<Button onClick={resetCamera}>Сбросить ракурс</Button>
|
||||
</div>
|
||||
<div className="polygon-rover-scene__help">
|
||||
<span>ЛКМ · вращение</span>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useRoutePreparation } from "../../core/simulation/routePreparation";
|
||||
import { viewedAiRun } from "../../core/simulation/viewedAiRun";
|
||||
import { lazy, Suspense, useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Button, GlassSurface, Icon, IconButton, LoadingRegion, InspectorSelectField, ResourceList, ResourceRow, StatusBadge, ToastStack } from "@nodedc/ui-react";
|
||||
import { Button, GlassSurface, Icon, IconButton, LoadingRegion, InspectorSelectField, StatusBadge, ToastStack } from "@nodedc/ui-react";
|
||||
import { AiLocationCatalog } from "../../components/simulation/AiLocationCatalog";
|
||||
import { SimulationSourceImport } from "../../components/simulation/SimulationSourceImport";
|
||||
import { AiWorldImport } from "../../components/simulation/AiWorldImport";
|
||||
import { AiWorldStream } from "../../components/simulation/AiWorldStream";
|
||||
@@ -13,6 +14,7 @@ import { AiConfiguration } from "../../components/simulation/AiConfiguration";
|
||||
import { AiSessionSection } from "../../components/simulation/AiSessionSection";
|
||||
import { AiTaskSelect } from "../../components/simulation/AiTaskSelect";
|
||||
import { AiPlanSaveWindow } from "../../components/simulation/AiPlanSaveWindow";
|
||||
import { plannerActions } from "../../core/simulation/plannerActions";
|
||||
import { planMatchesDraft } from "../../core/simulation/planDraft";
|
||||
import type { AiPlan, AiWaypoint } from "../../core/simulation/aiPolygon";
|
||||
import { aiPlanName, updateAiPlan, removeAiRun, fetchAiCatalog, fetchAiModules, startAiRun, type AiCatalog, type AiSource, type AiWorld, type AiRun, type AiModules } from "../../core/simulation/aiPolygon";
|
||||
@@ -22,16 +24,19 @@ import { RoverSettingsWindow } from "../../components/simulation/RoverSettingsWi
|
||||
import { currentSelection } from "../../core/simulation/runConfiguration";
|
||||
|
||||
import { saveLocalPlan } from "../../core/simulation/aiEditor";
|
||||
import {useSimulationLayout} from "../../components/simulation/useSimulationLayout";
|
||||
import type { LocalDraft } from "../../components/simulation/AiLocalPlanner";
|
||||
const LocalManualScene = lazy(() => import("../../components/simulation/LocalManualScene").then((m) => ({ default: m.LocalManualScene })));
|
||||
const AiLocalPlanner = lazy(() => import("../../components/simulation/AiLocalPlanner").then((m) => ({ default: m.AiLocalPlanner })));
|
||||
const EMPTY_POINTS:AiWaypoint[]=[];
|
||||
|
||||
export function AiPolygonWorkspace() {
|
||||
export function AiPolygonWorkspace({headerToolsHost}:{headerToolsHost?:HTMLElement|null}) {
|
||||
const [mode,setMode] = useState<"manual"|"inference">("inference");
|
||||
const [manual,setManual] = useState(false);
|
||||
const [importChoice,setImportChoice] = useState(false);
|
||||
const [planning, setPlanning] = useState(false);
|
||||
const [layout,updateLayout]=useSimulationLayout();
|
||||
const sceneMode=layout.mode, setSceneMode=(mode:typeof sceneMode)=>updateLayout({mode});
|
||||
const [draft, setDraft] = useState<LocalDraft | null>(null);
|
||||
const [catalog, setCatalog] = useState<AiCatalog | null>(null);
|
||||
const [selectedId, setSelectedId] = useState<string | null>(null);
|
||||
@@ -121,7 +126,11 @@ export function AiPolygonWorkspace() {
|
||||
const openWorld = (world: AiWorld) => {
|
||||
if (world.status === "uploading") setImporting({ source: world, resume: world });
|
||||
else {
|
||||
setSelectedId(world.world_id); setRunId(catalog?.runtime.active_run?.world.world_id===world.world_id?catalog.runtime.active_run.run_id:null); setPlanId(null);setEditorPlan(null);setSettingsOpen(!world.settings.prepared);
|
||||
const active=catalog?.runtime.active_run?.world.world_id===world.world_id?catalog.runtime.active_run:null;
|
||||
const saved=catalog?.plans.find(p=>p.world_id===world.world_id&&p.robot_id===robot?.robot_id&&p.robot_sha256===robot?.sha256);
|
||||
setSelectedId(world.world_id);setMode("inference");setManual(false);setRunId(active?.run_id??null);
|
||||
setPlanId(saved?.plan_id??"");setEditorPlan(saved??null);setDraft(null);
|
||||
setSettingsOpen(!world.settings.prepared);setPlanning(world.settings.prepared&&!active);
|
||||
}
|
||||
};
|
||||
const returnToLocations = () => { setManual(false); setPlanning(false); setDraft(null); setSelectedId(null); setRunId(null); };
|
||||
@@ -136,9 +145,17 @@ export function AiPolygonWorkspace() {
|
||||
plan?.settings?.max_speed_mps ?? selected?.settings.max_speed_mps ?? .15);
|
||||
const routeRequired=!!selected?.local_scene;
|
||||
const preparation=useRoutePreparation(draft?.cache??null,robot,draft?.points??EMPTY_POINTS,plan,setError);
|
||||
const available=plannerActions({draft,robot,plan,routeRequired,route:preparation.route,routeKey:preparation.key,
|
||||
busy:starting||saving||preparation.busy,runtimeAvailable:!!catalog?.runtime.available,
|
||||
inferenceReady:selected?.inference_ready!==false,activeRun:!!catalog?.runtime.active_run});
|
||||
const canEdit=!!robot && !!selected?.settings.prepared && !starting;
|
||||
const canLaunchSaved=!!robot && !!plan && plan.points.length>=2 && (!routeRequired||!!plan.prepared_route)
|
||||
&& selected?.inference_ready!==false && !!catalog?.runtime.available && !catalog.runtime.active_run && !starting;
|
||||
const start = (purpose: "planning" | "evaluation", task=plan) => {
|
||||
if (!selected || !robot) return;
|
||||
if (purpose === "planning") { setEditorPlan(plan??(planId===null?previousPlan:null)??null);setSettingsOpen(false); setDraft(null); setPlanning(true); return; }
|
||||
if (!selected || !robot || starting) return;
|
||||
if (purpose === "planning") { setSceneMode("planning");setEditorPlan(plan??(planId===null?previousPlan:null)??null);setSettingsOpen(false); setDraft(null); setPlanning(true); return; }
|
||||
if(!task || task.points.length<2 || (routeRequired&&!task.prepared_route)
|
||||
|| selected.inference_ready===false || !catalog?.runtime.available || catalog.runtime.active_run)return;
|
||||
setStarting(true);
|
||||
void fetchAiModules().then((fresh) => {
|
||||
setModules(fresh);
|
||||
@@ -148,7 +165,7 @@ export function AiPolygonWorkspace() {
|
||||
}).then(acceptRun).catch((caught: Error) => setError(caught.message)).finally(() => setStarting(false));
|
||||
};
|
||||
const save = () => {
|
||||
if (!draft || !robot) return;
|
||||
if (!draft || !robot || !available.save) return;
|
||||
setSaving(true);setSaveError(null);
|
||||
void saveLocalPlan(draft.cache, robot, draft.points, planName, draft.id, draft.sequence, preparation.key).then(async (saved) => {
|
||||
setPlanId(saved.plan_id);setSaveOpen(false);
|
||||
@@ -160,14 +177,37 @@ export function AiPolygonWorkspace() {
|
||||
setSaveError(null);setLaunchAfterSave(launch);setPlanName(plan?aiPlanName(plan):`${selected?.name} · маршрут`);setSaveOpen(true);
|
||||
};
|
||||
const launchDraft = () => {
|
||||
if(!draft||!robot)return;
|
||||
if(!draft||!robot||!available.launch)return;
|
||||
if(routeRequired && (!preparation.route || !preparation.key))return;
|
||||
if(planMatchesDraft(plan,draft.cache.key,robot.sha256,draft.points) && (!routeRequired || plan?.prepared_route?.sha256===preparation.route?.sha256))start("evaluation",plan);
|
||||
else openSave(true);
|
||||
};
|
||||
const planLocation=(world:AiWorld)=>{
|
||||
if(!robot||!world.settings.prepared)return;
|
||||
const saved=catalog?.plans.find(p=>p.world_id===world.world_id&&p.robot_id===robot.robot_id&&p.robot_sha256===robot.sha256);
|
||||
setSelectedId(world.world_id);setMode("inference");setManual(false);setRunId(null);setSettingsOpen(false);
|
||||
setSceneMode("planning");
|
||||
setPlanId(saved?.plan_id??"");setEditorPlan(saved??null);setDraft(null);setPlanning(true);
|
||||
};
|
||||
const connection = <StatusBadge tone={catalog?.runtime.available ? "success" : "neutral"}>
|
||||
{catalog?.runtime.available ? "Симулятор подключён" : "Симулятор не подключён"}
|
||||
</StatusBadge>;
|
||||
const taskSelector = mode==="inference"&&!running&&!starting?<AiTaskSelect inspector={!planning} plans={plans} value={plan?.plan_id??""}
|
||||
disabled={running||starting||saving||preparation.busy} onUpdated={planUpdated}
|
||||
onChange={(id)=>{setPlanId(id);setEditorPlan(plans.find(p=>p.plan_id===id)??null);setSettingsOpen(false);setPlanning(true);}}/>:null;
|
||||
const routeActions = selected && catalog ? <div className="ai-polygon__actions">{mode === "manual" ? (manual||canEdit?<Button variant="primary" icon={<Icon name={manual ? "stop" : "play"} />}
|
||||
onClick={()=>{setSettingsOpen(false);setManual(!manual);}}>{manual ? "Завершить" : "Старт"}</Button>:null) : planning ? <>
|
||||
{available.save?<Button onClick={()=>openSave()}>Сохранить задание</Button>:null}
|
||||
{available.prepare||preparation.busy?<Button variant="primary" icon={<Icon name="plan"/>} loading={preparation.busy}
|
||||
title="Рассчитать путь между точками по геометрии поверхности"
|
||||
onClick={()=>{if(available.prepare)void preparation.prepare();}}>Спланировать маршрут</Button>:null}
|
||||
{available.launch||starting?<IconButton label="Запустить симуляцию" aria-busy={starting} disabled={starting}
|
||||
onClick={launchDraft}><Icon name="play"/></IconButton>:null}
|
||||
</> : !running ? <>
|
||||
{canEdit?<Button onClick={() => start("planning")}>Подготовить маршрут</Button>:null}
|
||||
{canLaunchSaved||starting?<Button variant="primary" icon={<Icon name="play" />} loading={starting}
|
||||
onClick={() => start("evaluation")}>Запустить симуляцию</Button>:null}
|
||||
</> : <AiRunActions run={run!} onChange={acceptRun} />}</div> : null;
|
||||
const sceneActions = selected && catalog ? <>
|
||||
{!planning&&!manual&&!running&&!starting?<><div className="ai-polygon__robot-select"><InspectorSelectField label="Режим" value={mode}
|
||||
options={[{value:"inference",label:"Inference"},{value:"manual",label:"Ручное управление"}]}
|
||||
@@ -177,31 +217,12 @@ export function AiPolygonWorkspace() {
|
||||
value={running ? run.robot?.robot_id ?? "" : robot?.robot_id ?? ""}
|
||||
options={(catalog.robots ?? []).map((item) => ({ value: item.robot_id, label: item.name }))}
|
||||
disabled={planning || manual || starting || running} onChange={(id)=>{setRobotId(id);setPlanId(null);}} /></div>
|
||||
<IconButton label="Настройки ровера" disabled={!robot || !roverSettings || starting}
|
||||
onClick={()=>setRoverSettingsOpen(true)}><Icon name="settings"/></IconButton>
|
||||
{robot&&roverSettings&&!starting?<IconButton label="Настройки ровера"
|
||||
onClick={()=>setRoverSettingsOpen(true)}><Icon name="settings"/></IconButton>:null}
|
||||
</div>
|
||||
{roverSettings?<p>{roverSettings.max_speed_mps} м/с · {roverSettings.base_mass_kg+roverSettings.payload_mass_kg} кг с грузом</p>:null}</>:null}
|
||||
{mode==="inference"&&!running&&!starting?<AiTaskSelect inspector={!planning} plans={plans} value={plan?.plan_id??""}
|
||||
disabled={running||starting||saving||preparation.busy} onUpdated={planUpdated}
|
||||
onChange={(id)=>{setPlanId(id);setEditorPlan(plans.find(p=>p.plan_id===id)??null);setSettingsOpen(false);setPlanning(true);}}/>:null}
|
||||
<div className="ai-polygon__actions">{mode === "manual" ? <Button variant="primary" icon={<Icon name={manual ? "stop" : "play"} />}
|
||||
disabled={!robot || !selected.settings.prepared}
|
||||
onClick={()=>{setSettingsOpen(false);setManual(!manual);}}>{manual ? "Завершить" : "Старт"}</Button> : planning ? <>
|
||||
<Button disabled={starting || saving || preparation.busy || (routeRequired && !preparation.route) || !draft || draft.points.length < 2}
|
||||
onClick={()=>openSave()}>Сохранить задание</Button>
|
||||
{!routeRequired || preparation.route ? <Button variant="primary" icon={<Icon name="play"/>} loading={starting}
|
||||
disabled={saving || !draft || selected.inference_ready===false || !catalog.runtime.available || !!catalog.runtime.active_run}
|
||||
onClick={launchDraft}>Запустить симуляцию</Button> : <Button variant="primary" icon={<Icon name="plan"/>}
|
||||
loading={preparation.busy} disabled={saving || starting || !draft || draft.points.length<2 || !catalog.runtime.available}
|
||||
onClick={()=>void preparation.prepare()}>Спланировать маршрут</Button>}
|
||||
{preparation.busy?<p role="status">Рассчитываем маршрут по сцене</p>:null}
|
||||
</> : !running ? <>
|
||||
<Button loading={starting} disabled={!robot || !selected.settings.prepared}
|
||||
onClick={() => start("planning")}>Подготовить маршрут</Button>
|
||||
<Button variant="primary" icon={<Icon name="play" />} loading={starting}
|
||||
disabled={!robot || !plan || (routeRequired && !plan.prepared_route) || selected.inference_ready === false || !catalog.runtime.available || !!catalog.runtime.active_run}
|
||||
onClick={() => start("evaluation")}>Запустить симуляцию</Button>
|
||||
</> : <AiRunActions run={run!} onChange={acceptRun} />}</div>
|
||||
{taskSelector}
|
||||
{routeActions}
|
||||
</> : null;
|
||||
return <div className="ai-polygon">
|
||||
<header className="ai-polygon__head">
|
||||
@@ -211,8 +232,9 @@ export function AiPolygonWorkspace() {
|
||||
</IconButton> : null}
|
||||
<h2>{selected?.name ?? "Доступные локации"}</h2>
|
||||
</div>
|
||||
<div className="ai-polygon__actions" ref={setActionsHost}>
|
||||
{selected ? null : <>{connection}
|
||||
<div className="ai-polygon__actions ai-polygon__location-actions" ref={setActionsHost}>
|
||||
{selected ? !planning&&!manual&&!running&&canEdit?<IconButton label="Подготовить маршрут"
|
||||
onClick={()=>start("planning")}><Icon name="plan"/></IconButton>:null : <>{connection}
|
||||
<Button icon={<Icon name="upload" />} onClick={() => setImportChoice(true)}>Импорт локации</Button></>}
|
||||
</div>
|
||||
</header>
|
||||
@@ -223,14 +245,9 @@ export function AiPolygonWorkspace() {
|
||||
<Button disabled={removing!==null} onClick={()=>void undoRemove()}>Отменить удаление</Button>
|
||||
</GlassSurface>:null}
|
||||
{catalog ? !selected ? <section aria-label="Доступные локации" className="ai-polygon__section">
|
||||
<ResourceList>{catalog.worlds.map((world) => <li key={world.world_id}>
|
||||
<ResourceRow title={world.name} icon={<Icon name="globe"/>}
|
||||
status={catalog.runtime.active_run?.world.world_id === world.world_id ? <StatusBadge tone="neutral">
|
||||
{catalog.runtime.active_run.state === "paused" ? "На паузе" : "Сцена открыта"}
|
||||
</StatusBadge> : undefined}
|
||||
actions={<IconButton label={world.status === "uploading" ? `Продолжить импорт ${world.name}` : `Открыть ${world.name}`}
|
||||
onClick={() => openWorld(world)}><Icon name={world.status === "uploading" ? "upload" : "eye"}/></IconButton>}/>
|
||||
</li>)}</ResourceList>
|
||||
<AiLocationCatalog worlds={catalog.worlds} removedWorlds={catalog.removed_worlds ?? []}
|
||||
activeWorldId={catalog.runtime.active_run?.world.world_id}
|
||||
paused={catalog.runtime.active_run?.state === "paused"} onOpen={openWorld} onPlan={planLocation} canPlan={!!robot} onChanged={load}/>
|
||||
</section> : <section className="ai-polygon__section" aria-label={`Симуляция ${selected.name}`}>
|
||||
{!running && !planning && !manual ? <AiSessionSection key={`${selected.world_id}:configuration`}
|
||||
scope={`${selected.world_id}:configuration`} title="Конфигурация">
|
||||
@@ -255,13 +272,15 @@ export function AiPolygonWorkspace() {
|
||||
{mode === "inference" && !planning && !running && catalog.runtime.active_run ? <div className="ai-polygon__facts"><p>Выполняется симуляция «{catalog.runtime.active_run.world.name}».</p>
|
||||
{catalog.runtime.active_run.world.world_id===selected.world_id?<Button onClick={()=>acceptRun(catalog.runtime.active_run!)}>Открыть текущую симуляцию</Button>:null}</div> : null}
|
||||
{manual && robot ? <Suspense fallback={<LoadingRegion loading label="Открываем ручное управление" />}>
|
||||
<LocalManualScene key={selected.world_id} world={selected} robot={robot} settings={roverSettings} actionsHost={actionsHost} headerActions={sceneActions} />
|
||||
<LocalManualScene key={selected.world_id} world={selected} robot={robot} settings={roverSettings} actionsHost={headerToolsHost??actionsHost} headerActions={sceneActions} />
|
||||
</Suspense> : planning ? <Suspense fallback={<LoadingRegion loading label="Открываем редактор" />}>
|
||||
<AiLocalPlanner key={selected.world_id} world={selected} initialPoints={editorPlan?.points ?? EMPTY_POINTS}
|
||||
busy={starting || saving || preparation.busy} preparedRoute={preparation.route} onDraft={setDraft} actionsHost={actionsHost} headerActions={sceneActions} />
|
||||
sceneMode={sceneMode} onSceneMode={setSceneMode}
|
||||
busy={starting || saving || preparation.busy} preparedRoute={preparation.route} onDraft={setDraft}
|
||||
actionsHost={headerToolsHost??actionsHost} headerActions={taskSelector} routeActions={routeActions} routeActionsHost={actionsHost} />
|
||||
</Suspense> : <LoadingRegion loading={starting} label="Открываем симуляцию на Worker">
|
||||
{mode === "inference" && running && run ? <AiWorldStream key={run.run_id} world={selected} run={run} onBack={returnToLocations} onChange={acceptRun}
|
||||
actionsHost={actionsHost} headerActions={sceneActions}
|
||||
actionsHost={headerToolsHost??actionsHost} headerActions={sceneActions}
|
||||
controls={<AiRunView run={run} />} /> : mode === "inference" ? <div className="ai-polygon__telemetry-row ai-polygon__telemetry-row--local">{connection}{selected.inference_ready===false?<p>{selected.inference_message}</p>:null}</div> : null}
|
||||
</LoadingRegion>}
|
||||
{mode === "inference" && !planning ? <AiRunReport key={selected.world_id} worldId={selected.world_id} modules={modules} onRemove={removeRun} removing={removing} runs={catalog.runs.filter((item) => item.world.world_id === selected.world_id)} /> : null}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AiPolygonWorkspace } from "./AiPolygonWorkspace";
|
||||
|
||||
/** One location library; execution mode is selected inside the location. */
|
||||
export function SimulationWorkspace() {
|
||||
return <AiPolygonWorkspace />;
|
||||
export function SimulationWorkspace({headerToolsHost}:{headerToolsHost?:HTMLElement|null}) {
|
||||
return <AiPolygonWorkspace headerToolsHost={headerToolsHost} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user