feat(bms): discover JK batteries and integrate read-only telemetry scenes
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import {useRef,useState} from 'react';
|
||||
import {Button,ColorField,ControlRow,Description,FeatureSettingsWindow,Icon,IconButton,RangeControl,SettingsCard} from '@nodedc/ui-react';
|
||||
import {parseBatteryAppearance,type BatteryAppearance} from '../../core/batteryScene/appearance';
|
||||
import type {useBatteryAppearance} from '../../core/batteryScene/useBatteryAppearance';
|
||||
type Section='markings'|'panels';
|
||||
export function BatteryAppearanceSettings({open,onClose,profile}:{open:boolean;onClose:()=>void;profile:ReturnType<typeof useBatteryAppearance>}){
|
||||
const [section,setSection]=useState<Section>('markings'),input=useRef<HTMLInputElement>(null);
|
||||
const {value,update}=profile,p=value.panels,m=value.markings;
|
||||
const panel=(patch:Partial<BatteryAppearance['panels']>)=>update({...value,panels:{...p,...patch}});
|
||||
const glass=(patch:Partial<typeof p.glass>)=>panel({glass:{...p.glass,...patch}});
|
||||
const range=(label:string,value:number,min:number,max:number,onChange:(v:number)=>void)=><RangeControl label={label} value={value} min={min} max={max} step={1} exactValueBounds={{min,max}} onChange={onChange}/>;
|
||||
const exportJson=()=>{const url=URL.createObjectURL(new Blob([JSON.stringify(value,null,2)],{type:'application/json'}));const a=document.createElement('a');a.href=url;a.download='battery-ui.json';a.click();setTimeout(()=>URL.revokeObjectURL(url),1000);};
|
||||
return <FeatureSettingsWindow open={open} title="Настройки батареи" identity={{title:'Интерфейс батареи',subtitle:'Локальный профиль',avatarLabel:'АКБ'}} sections={[{id:'markings',label:'Маркировка ячеек',icon:'layers'},{id:'panels',label:'Плашки показаний',icon:'settings'}]} activeSection={section} onSectionChange={setSection} onClose={onClose}
|
||||
headerActions={<><IconButton label="Отменить настройку батареи" disabled={!profile.canUndo} onClick={profile.undo}><Icon name="undo"/></IconButton><IconButton label="Повторить настройку батареи" disabled={!profile.canRedo} onClick={profile.redo}><Icon name="redo"/></IconButton></>}
|
||||
footer={<><Button onClick={exportJson}>Экспорт JSON</Button><Button onClick={()=>input.current?.click()}>Импорт JSON</Button><input ref={input} type="file" accept="application/json,.json" hidden onChange={async event=>{const file=event.currentTarget.files?.[0];event.currentTarget.value='';if(!file)return;try{if(file.size>32000)throw new Error('Файл настроек слишком большой.');update(parseBatteryAppearance(JSON.parse(await file.text())));}catch(error){profile.setError(error instanceof Error?error.message:'Не удалось прочитать профиль.');}}}/></>}>
|
||||
{section==='markings'?<SettingsCard title="Маркировка ячеек" description="Номер и напряжение на заводских площадках модели. Размер меняет надпись внутри площадки.">
|
||||
<ControlRow label="Цвет маркировки"><ColorField label="Цвет маркировки" value={m.color} onChange={color=>update({...value,markings:{...m,color}})}/></ControlRow>
|
||||
{range('Размер маркировки, %',m.size,50,160,size=>update({...value,markings:{...m,size}}))}
|
||||
</SettingsCard>:<SettingsCard title="Плашки показаний" description="Общий вид верхних и нижних плашек над моделью.">
|
||||
{range('Высота плашек, px',p.height,56,160,height=>panel({height}))}
|
||||
{range('Радиус углов, px',p.radius,0,48,radius=>panel({radius}))}
|
||||
{range('Размер подписей, px',p.labelSize,10,20,labelSize=>panel({labelSize}))}
|
||||
{range('Размер значений, px',p.valueSize,12,30,valueSize=>panel({valueSize}))}
|
||||
<ControlRow label="Цвет текста"><ColorField label="Цвет текста" value={p.textColor} onChange={textColor=>panel({textColor})}/></ControlRow>
|
||||
<ControlRow label="Цвет стекла"><ColorField label="Цвет стекла" value={p.glass.tintHex} onChange={tintHex=>glass({tintHex})}/></ControlRow>
|
||||
{range('Прозрачность стекла, %',100-p.glass.tintOpacity,0,100,transparency=>glass({tintOpacity:100-transparency}))}
|
||||
{range('Размытие стекла, px',p.glass.blur,0,60,blur=>glass({blur}))}
|
||||
</SettingsCard>}
|
||||
<Description>Сохраняется на этом компьютере для этой батареи. Ctrl Z / ⌘ Z — отмена, Shift Ctrl Z / ⇧ ⌘ Z — повтор.</Description>
|
||||
</FeatureSettingsWindow>;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import {useEffect,useRef} from 'react';
|
||||
import * as pc from 'playcanvas';
|
||||
import type {PlayCanvasViewerProps} from '../rover/playcanvas/PlayCanvasViewer';
|
||||
import type {CellMarkingAppearance} from '../../core/batteryScene/appearance';
|
||||
import {cellDisplayIndex,drawCellDisplay} from '../../core/batteryScene/cellDisplay';
|
||||
type Api=Parameters<NonNullable<PlayCanvasViewerProps['onSceneReady']>>[0];
|
||||
/** GPU textures on the thirteen original Blender faces. Opaque geometry owns occlusion. */
|
||||
export function BatteryCellLabels({api,values,ready,appearance}:{api:Api|null;values:readonly number[];ready:boolean;appearance:CellMarkingAppearance}){
|
||||
const latest=useRef({values,appearance});latest.current={values,appearance};
|
||||
useEffect(()=>{
|
||||
if(!api||!ready)return;
|
||||
const displays=(api.modelRoot.findComponents('render') as pc.RenderComponent[]).flatMap(component=>component.meshInstances).flatMap(mesh=>{
|
||||
const index=cellDisplayIndex(mesh.node.name);if(index===null)return [];
|
||||
const canvas=document.createElement('canvas');canvas.width=canvas.height=256;const ctx=canvas.getContext('2d');if(!ctx)return [];
|
||||
const texture=new pc.Texture(api.app.graphicsDevice,{name:mesh.node.name,format:pc.PIXELFORMAT_SRGBA8,mipmaps:true,addressU:pc.ADDRESS_CLAMP_TO_EDGE,addressV:pc.ADDRESS_CLAMP_TO_EDGE});
|
||||
const original=mesh.material,material=new pc.StandardMaterial();material.name=mesh.node.name;
|
||||
material.diffuse.set(0,0,0);material.emissive.set(1,1,1);material.emissiveMap=texture;material.opacityMap=texture;material.opacityMapChannel='a';
|
||||
material.useLighting=false;material.useFog=false;material.blendType=pc.BLEND_NORMAL;material.depthTest=true;material.depthWrite=false;material.cull=pc.CULLFACE_BACK;material.update();
|
||||
return [{mesh,index,canvas,ctx,texture,material,original,signature:''}];
|
||||
});
|
||||
const update=()=>{for(const display of displays){
|
||||
const {values,appearance}=latest.current,value=values[display.index],signature=JSON.stringify([Number.isFinite(value)?value:null,appearance.color,appearance.size]);
|
||||
if(display.signature!==signature){drawCellDisplay(display.ctx,display.index,value,appearance);display.texture.setSource(display.canvas);display.texture.upload();display.signature=signature;}
|
||||
// These material slots carry live readings; their appearance is owned by battery settings.
|
||||
display.mesh.material=display.material;
|
||||
}};
|
||||
update();api.app.on('prerender',update);
|
||||
let disposed=false;
|
||||
const dispose=()=>{if(disposed)return;disposed=true;api.app.off('prerender',update);api.app.off('destroy',dispose);for(const display of displays){if(display.mesh.material===display.material)display.mesh.material=display.original;display.material.destroy();display.texture.destroy();}};
|
||||
// Viewer cleanup precedes sibling effect cleanup. Release GPU resources before the device.
|
||||
api.app.on('destroy',dispose);
|
||||
return dispose;
|
||||
},[api,ready]);
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import type {CellMarkingAppearance} from '../../core/batteryScene/appearance';
|
||||
import {BatteryCellLabels} from './BatteryCellLabels';
|
||||
import type {PlayCanvasViewerProps} from '../rover/playcanvas/PlayCanvasViewer';
|
||||
import {useMemo,useState} from 'react';
|
||||
import {Description} from '@nodedc/ui-react';
|
||||
import {SceneEditor} from '../rover/editor/RoverScene';
|
||||
import {useSceneDocument} from '../../core/roverScene/useSceneDocument';
|
||||
import {batterySceneProfile,defaultBatteryScene} from '../../core/batteryScene/profile';
|
||||
|
||||
export function BatteryScene({editing,soc,fresh,deviceId,seedKey,cellVoltages=[],markingAppearance}:{editing:boolean;soc:number|null;fresh:boolean;deviceId:string;seedKey?:string;cellVoltages?:readonly number[];markingAppearance:CellMarkingAppearance}){
|
||||
const profile=useMemo(()=>batterySceneProfile(seedKey),[seedKey]);
|
||||
const scene=useSceneDocument(deviceId,profile);
|
||||
const [api,setApi]=useState<Parameters<NonNullable<PlayCanvasViewerProps['onSceneReady']>>[0]|null>(null);
|
||||
const [phase,setPhase]=useState<'loading'|'ready'|'error'>('loading');
|
||||
return <div className="bms-scene" data-editing={editing} aria-label="3D-модель батареи R04">
|
||||
<SceneEditor scene={scene} defaults={defaultBatteryScene} editing={editing} modelUrl="/battery-scene/catl-r04.glb?objects-v5" minFitDistance={.6} chargeState={{soc,fresh}} onModelState={setPhase} onSceneReady={setApi}/>
|
||||
<BatteryCellLabels api={api} ready={phase==='ready'} values={cellVoltages} appearance={markingAppearance}/>
|
||||
{phase!=='ready'&&<div className="bms-scene-status"><Description role="status">{phase==='error'?'Модель не загрузилась. Показания BMS доступны ниже.':'Загружается модель аккумулятора…'}</Description></div>}
|
||||
</div>;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import {BatteryAppearanceSettings} from './BatteryAppearanceSettings';
|
||||
import {useBatteryAppearance} from '../../core/batteryScene/useBatteryAppearance';
|
||||
import type {BatteryAppearance} from '../../core/batteryScene/appearance';
|
||||
import {useEffect,useState,type ReactNode} from 'react';
|
||||
import {createPortal} from 'react-dom';
|
||||
import {EditorWorkspace,Icon,IconButton,ResizableViewport,ToastStack,useApplicationPanelFullscreen} from '@nodedc/ui-react';
|
||||
import {batteryViewHeight,batteryViewHeightKey,minBatteryViewHeight,maxBatteryViewHeight} from '../../core/batteryScene/viewHeight';
|
||||
|
||||
export function BatteryWorkspace({children,deviceId,title,headerActionsTarget,back}:{deviceId:string;title:string;headerActionsTarget?:HTMLElement|null;back:()=>void;children:(controls:{editing:boolean;appearance:BatteryAppearance;renderViewport:(children:ReactNode)=>ReactNode})=>ReactNode}){
|
||||
const full=useApplicationPanelFullscreen(),[editing,setEditing]=useState(false),[error,setError]=useState(''),[settings,setSettings]=useState(false);
|
||||
const profile=useBatteryAppearance(deviceId,settings);
|
||||
const [height,setHeight]=useState(()=>{try{return batteryViewHeight(localStorage.getItem(batteryViewHeightKey(deviceId)),window.innerHeight);}catch{return batteryViewHeight(null,window.innerHeight);}});
|
||||
const fullscreen=full?.fullscreen??false,setFullscreen=full?.setFullscreen;
|
||||
useEffect(()=>()=>{setFullscreen?.(false);},[setFullscreen]);
|
||||
useEffect(()=>{const escape=(event:KeyboardEvent)=>{
|
||||
if(event.key!=='Escape'||event.defaultPrevented||document.querySelector('[role=dialog],[role=listbox]'))return;
|
||||
event.preventDefault();if(fullscreen)setFullscreen?.(false);else if(editing)setEditing(false);else back();
|
||||
};window.addEventListener('keydown',escape);return()=>window.removeEventListener('keydown',escape);},[editing,fullscreen,setFullscreen,back]);
|
||||
const commitHeight=(value:number)=>{try{localStorage.setItem(batteryViewHeightKey(deviceId),JSON.stringify({height:value}));setError('');}catch{setError('Не удалось сохранить высоту окна на этом компьютере.');}};
|
||||
const actions=<>{full&&<IconButton label={fullscreen?'Восстановить окно батареи':'Развернуть окно батареи'} onClick={()=>setFullscreen?.(!fullscreen)}><Icon name={fullscreen?'minimize':'expand'}/></IconButton>}<IconButton label={editing?'Завершить редактирование сцены':'Редактировать сцену'} aria-pressed={editing} onClick={()=>{setSettings(false);setEditing(value=>!value);}}><Icon name="edit"/></IconButton><IconButton label="Настройки батареи" aria-pressed={settings} onClick={()=>{setEditing(false);setSettings(true);}}><Icon name="settings"/></IconButton></>;
|
||||
return <>{headerActionsTarget?createPortal(actions,headerActionsTarget):actions}{children({editing,appearance:profile.value,renderViewport:content=><ResizableViewport resizeIndicator={false} className="bms-stage" height={height} minHeight={minBatteryViewHeight} maxHeight={maxBatteryViewHeight} onHeightChange={setHeight} onHeightCommit={commitHeight}><EditorWorkspace editing={editing} title={title} subtitle="Редактирование сцены аккумулятора" onBack={()=>setEditing(false)}><div className="bms-stage bms-editor-content">{content}</div></EditorWorkspace></ResizableViewport>})}<BatteryAppearanceSettings open={settings} onClose={()=>setSettings(false)} profile={profile}/><ToastStack items={(error||profile.error)?[{id:'battery-view-save',title:error||profile.error,tone:'error'}]:[]} onDismiss={()=>{setError('');profile.setError('');}}/></>;
|
||||
}
|
||||
@@ -1,4 +1,11 @@
|
||||
import {usbCanSensorUi} from '../../../../plugins/usb-can/frontend/src/plugin';
|
||||
import {createElement} from 'react';
|
||||
import {jkBmsSensorUi} from '../../../../plugins/jk-bms/frontend/src/plugin';
|
||||
import {BmsDetail} from '../../../../plugins/jk-bms/frontend/src/BmsDetail';
|
||||
import type {BatteryState} from '../../../../plugins/jk-bms/frontend/src/model';
|
||||
import type {SensorDetailProps} from '../../../../packages/sensor-ui/src/extensions';
|
||||
import {BatteryScene} from '../components/battery/BatteryScene';
|
||||
import {BatteryWorkspace} from '../components/battery/BatteryWorkspace';
|
||||
import {vescSensorUi} from '../../../../plugins/vesc/frontend/src/plugin';
|
||||
import type { DeviceUiPlugin } from "../core/device-plugins/contracts";
|
||||
import { xgridsK1Plugin } from "@xgrids-k1/frontend/plugin";
|
||||
@@ -12,4 +19,6 @@ export const installedDevicePlugins: readonly DeviceUiPlugin[] = Object.freeze([
|
||||
|
||||
// Node-executed camera controls use the existing sensor contribution contract;
|
||||
// they do not register a desktop capture/AI runtime or a new product workspace.
|
||||
export const installedNodeSensorContributions = Object.freeze([insta360X4SensorUi,vescSensorUi,usbCanSensorUi]);
|
||||
|
||||
const CoreBmsDetail=(props:SensorDetailProps)=>createElement(BatteryWorkspace,{key:props.device.id,deviceId:props.device.id,title:`Аккумулятор / ${props.device.name}`,headerActionsTarget:props.headerActionsTarget,back:props.back,children:controls=>createElement(BmsDetail,{...props,presentation:'page',editing:controls.editing,panelAppearance:controls.appearance.panels,renderViewport:controls.renderViewport,renderScene:(state:BatteryState)=>createElement(BatteryScene,{editing:controls.editing,markingAppearance:controls.appearance.markings,deviceId:props.device.id,seedKey:props.sceneSeedKey,soc:state.sample?.soc_percent??null,fresh:state.fresh,cellVoltages:state.sample?.cell_voltages_v})})});
|
||||
export const installedNodeSensorContributions = Object.freeze([insta360X4SensorUi,vescSensorUi,usbCanSensorUi,{...jkBmsSensorUi,detailPresentation:'workspace' as const,Detail:CoreBmsDetail}]);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import {defaultGlassMaterial,type GlassMaterialSettings} from '@nodedc/ui-core';
|
||||
export type CellMarkingAppearance={color:string;size:number};
|
||||
export type BatteryPanelAppearance={height:number;radius:number;labelSize:number;valueSize:number;textColor:string;glass:GlassMaterialSettings};
|
||||
export type BatteryAppearance={schema:'missioncore.battery-ui/v1';markings:CellMarkingAppearance;panels:BatteryPanelAppearance};
|
||||
export const batteryAppearanceKey=(id:string)=>`missioncore.battery-ui/v1:${id}`;
|
||||
export function defaultBatteryAppearance():BatteryAppearance{return {schema:'missioncore.battery-ui/v1',markings:{color:'#ffffff',size:100},panels:{height:76,radius:24,labelSize:12,valueSize:18,textColor:'#f1f1ef',glass:{...defaultGlassMaterial,tintOpacity:52,blur:18}}};}
|
||||
const object=(v:unknown):Record<string,unknown>=>v!==null&&typeof v==='object'?v as Record<string,unknown>:{};
|
||||
const number=(v:unknown,fallback:number,min:number,max:number)=>typeof v==='number'&&Number.isFinite(v)?Math.min(max,Math.max(min,v)):fallback;
|
||||
const color=(v:unknown,fallback:string)=>typeof v==='string'&&/^#[0-9a-f]{6}$/i.test(v)?v.toLowerCase():fallback;
|
||||
export function parseBatteryAppearance(raw:unknown):BatteryAppearance{
|
||||
const source=object(raw);if(source.schema!=='missioncore.battery-ui/v1')throw new Error('Это не профиль интерфейса батареи.');
|
||||
const d=defaultBatteryAppearance(),m=object(source.markings),p=object(source.panels),g=object(p.glass);
|
||||
return {schema:d.schema,markings:{color:color(m.color,d.markings.color),size:number(m.size,100,50,160)},panels:{height:number(p.height,76,56,160),radius:number(p.radius,24,0,48),labelSize:number(p.labelSize,12,10,20),valueSize:number(p.valueSize,18,12,30),textColor:color(p.textColor,d.panels.textColor),glass:{...d.panels.glass,tintHex:color(g.tintHex,d.panels.glass.tintHex),tintOpacity:number(g.tintOpacity,52,0,100),blur:number(g.blur,18,0,60)}}};
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import type {CellMarkingAppearance} from './appearance';
|
||||
export function cellDisplayIndex(name:string){const match=/^bms\/cell-display\/C(0[1-9]|1[0-3])$/.exec(name);return match?Number(match[1])-1:null;}
|
||||
export function cellDisplayText(index:number,value:number|undefined){return {number:String(index+1).padStart(2,'0'),voltage:Number.isFinite(value)?`${value!.toLocaleString('ru-RU',{minimumFractionDigits:3,maximumFractionDigits:3})} В`:'— В'};}
|
||||
/** One fixed composition on each existing 27 × 29 mm label face. No camera projection. */
|
||||
export function drawCellDisplay(ctx:CanvasRenderingContext2D,index:number,value:number|undefined,appearance:CellMarkingAppearance){
|
||||
const text=cellDisplayText(index,value),size=appearance.size/100;
|
||||
ctx.clearRect(0,0,256,256);ctx.save();ctx.translate(128,128);ctx.scale(size,size);
|
||||
ctx.fillStyle=appearance.color;ctx.textAlign='center';ctx.textBaseline='middle';
|
||||
ctx.font='600 76px sans-serif';ctx.fillText(text.number,0,-36);
|
||||
ctx.font='500 40px sans-serif';ctx.fillText(text.voltage,0,46);
|
||||
ctx.restore();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import {defaultChargeGradient} from '../roverScene/chargeGradient';
|
||||
import r04 from './r04.json';
|
||||
import {defaultScene,parseScene,type SceneDocument} from '../roverScene/sceneDocument';
|
||||
import {readScene} from '../roverScene/sceneStorage';
|
||||
import type {SceneDocumentProfile} from '../roverScene/useSceneDocument';
|
||||
|
||||
export function defaultBatteryScene():SceneDocument {
|
||||
return {...defaultScene(),schema:'missioncore.battery-scene/v1',model:'catl-r04/v1',
|
||||
materials:{...structuredClone(r04.materials),'bms/cells':{...structuredClone(r04.materials['bms/cells']),chargeGradient:defaultChargeGradient()}},assignments:{},objects:{...r04.objects}};
|
||||
}
|
||||
function database():Promise<IDBDatabase>{return new Promise((resolve,reject)=>{
|
||||
const request=indexedDB.open('missioncore-battery-scenes',1);
|
||||
request.onupgradeneeded=()=>request.result.createObjectStore('scenes');
|
||||
request.onsuccess=()=>resolve(request.result);request.onerror=()=>reject(request.error);
|
||||
request.onblocked=()=>reject(new Error('Хранилище батареи занято другим окном.'));
|
||||
});}
|
||||
async function save(id:string,document:SceneDocument){const db=await database();try{await new Promise<void>((resolve,reject)=>{
|
||||
const tx=db.transaction('scenes','readwrite');tx.objectStore('scenes').put(document,id);
|
||||
tx.oncomplete=()=>resolve();tx.onerror=()=>reject(tx.error);tx.onabort=()=>reject(tx.error);
|
||||
});}finally{db.close();}}
|
||||
export function batterySceneProfile(seedKey?:string):SceneDocumentProfile {
|
||||
return {defaults:defaultBatteryScene,write:save,filename:'battery-r04-scene.json',read:async id=>{
|
||||
const db=await database();let raw:unknown;try{raw=await new Promise((resolve,reject)=>{
|
||||
const request=db.transaction('scenes').objectStore('scenes').get(id);
|
||||
request.onsuccess=()=>resolve(request.result);request.onerror=()=>reject(request.error);
|
||||
});}finally{db.close();}
|
||||
if(raw)return parseScene(raw,defaultBatteryScene);
|
||||
const seed=seedKey?await readScene(seedKey):null;
|
||||
const doc=defaultBatteryScene();
|
||||
if(seed){doc.postFx=structuredClone(seed.postFx);doc.cameraAutoRotate=seed.cameraAutoRotate;doc.cameraZoomStrength=seed.cameraZoomStrength;}
|
||||
// Copy once. Subsequent rover edits and battery edits have separate owners.
|
||||
await save(id,doc);return doc;
|
||||
}};
|
||||
}
|
||||
@@ -0,0 +1,501 @@
|
||||
{
|
||||
"materials": {
|
||||
"bms/Cable / red silicone": {
|
||||
"name": "Cable / red silicone",
|
||||
"color": "#ac1922",
|
||||
"metalness": 0,
|
||||
"roughness": 0.47999998927116394,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/Cable / graphite silicone": {
|
||||
"name": "Cable / graphite silicone",
|
||||
"color": "#22252a",
|
||||
"metalness": 0.05000000074505806,
|
||||
"roughness": 0.3700000047683716,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/Mount / G10 dielectric": {
|
||||
"name": "Mount / G10 dielectric",
|
||||
"color": "#3e8572",
|
||||
"metalness": 0,
|
||||
"roughness": 0.5199999809265137,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/Nickel plated copper / busbars": {
|
||||
"name": "Nickel plated copper / busbars",
|
||||
"color": "#c4ccd2",
|
||||
"metalness": 0.8299999833106995,
|
||||
"roughness": 0.27000001072883606,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/Sense / warm yellow": {
|
||||
"name": "Sense / warm yellow",
|
||||
"color": "#f6c629",
|
||||
"metalness": 0.05000000074505806,
|
||||
"roughness": 0.3199999928474426,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/labels": {
|
||||
"name": "Надписи",
|
||||
"color": "#e5eee8",
|
||||
"metalness": 0,
|
||||
"roughness": 0.9,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#ffffff",
|
||||
"emissiveIntensity": 0.08,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/Connector / ivory polymer": {
|
||||
"name": "Connector / ivory polymer",
|
||||
"color": "#e4e2d2",
|
||||
"metalness": 0.05000000074505806,
|
||||
"roughness": 0.4000000059604645,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/BMS / green PCB": {
|
||||
"name": "BMS / green PCB",
|
||||
"color": "#266c50",
|
||||
"metalness": 0.15000000596046448,
|
||||
"roughness": 0.4000000059604645,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/Aluminium / satin": {
|
||||
"name": "Aluminium / satin",
|
||||
"color": "#cdd6dd",
|
||||
"metalness": 0.800000011920929,
|
||||
"roughness": 0.3100000023841858,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/Lid / insulating black": {
|
||||
"name": "Lid / insulating black",
|
||||
"color": "#15191e",
|
||||
"metalness": 0,
|
||||
"roughness": 0.6499999761581421,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/Mount / adhesive film": {
|
||||
"name": "Mount / adhesive film",
|
||||
"color": "#6f756f",
|
||||
"metalness": 0,
|
||||
"roughness": 0.6200000047683716,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/Steel / fasteners": {
|
||||
"name": "Steel / fasteners",
|
||||
"color": "#bdc4ca",
|
||||
"metalness": 0.8799999952316284,
|
||||
"roughness": 0.23000000417232513,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/cells": {
|
||||
"name": "Ячейки · общий SOC",
|
||||
"color": "#487b80",
|
||||
"metalness": 0,
|
||||
"roughness": 0.68,
|
||||
"opacity": 0.82,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#ffffff",
|
||||
"emissiveIntensity": 0.65,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/Cell / wrapped lower edge": {
|
||||
"name": "Cell / wrapped lower edge",
|
||||
"color": "#223894",
|
||||
"metalness": 0.20000000298023224,
|
||||
"roughness": 0.3100000023841858,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/CASE | bead-blasted graphite": {
|
||||
"name": "CASE | bead-blasted graphite",
|
||||
"color": "#464a4f",
|
||||
"metalness": 0.3199999928474426,
|
||||
"roughness": 0.5199999809265137,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/glass": {
|
||||
"name": "Прозрачная часть корпуса",
|
||||
"color": "#7898a1",
|
||||
"metalness": 0.05,
|
||||
"roughness": 0.42,
|
||||
"opacity": 0.12,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/R04 | elastomer seal": {
|
||||
"name": "R04 | elastomer seal",
|
||||
"color": "#121517",
|
||||
"metalness": 0,
|
||||
"roughness": 0.699999988079071,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/R04 | graphite moulded polymer": {
|
||||
"name": "R04 | graphite moulded polymer",
|
||||
"color": "#222930",
|
||||
"metalness": 0,
|
||||
"roughness": 0.36000001430511475,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/R04 | smoked polycarbonate": {
|
||||
"name": "R04 | smoked polycarbonate",
|
||||
"color": "#98aab5",
|
||||
"metalness": 0,
|
||||
"roughness": 0.15000000596046448,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/R04 | display protective polycarbonate": {
|
||||
"name": "R04 | display protective polycarbonate",
|
||||
"color": "#eef7fa",
|
||||
"metalness": 0,
|
||||
"roughness": 0.11999999731779099,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/DISPLAY | black glass": {
|
||||
"name": "DISPLAY | black glass",
|
||||
"color": "#121f23",
|
||||
"metalness": 0.18000000715255737,
|
||||
"roughness": 0.2199999988079071,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/CASE | recessed black": {
|
||||
"name": "CASE | recessed black",
|
||||
"color": "#1e2227",
|
||||
"metalness": 0.11999999731779099,
|
||||
"roughness": 0.5,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/CASE | darker frame": {
|
||||
"name": "CASE | darker frame",
|
||||
"color": "#41464c",
|
||||
"metalness": 0.6499999761581421,
|
||||
"roughness": 0.3199999928474426,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/CASE | dielectric liner": {
|
||||
"name": "CASE | dielectric liner",
|
||||
"color": "#313437",
|
||||
"metalness": 0,
|
||||
"roughness": 0.6499999761581421,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/Connector / gold plated contacts": {
|
||||
"name": "Connector / gold plated contacts",
|
||||
"color": "#d6a44a",
|
||||
"metalness": 0.8500000238418579,
|
||||
"roughness": 0.25,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/XT90-S / anti spark green insert": {
|
||||
"name": "XT90-S / anti spark green insert",
|
||||
"color": "#30a455",
|
||||
"metalness": 0,
|
||||
"roughness": 0.4300000071525574,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
},
|
||||
"bms/XT90-S / yellow PA housing": {
|
||||
"name": "XT90-S / yellow PA housing",
|
||||
"color": "#f9bd22",
|
||||
"metalness": 0,
|
||||
"roughness": 0.3799999952316284,
|
||||
"opacity": 1,
|
||||
"reflectivity": 1,
|
||||
"clearCoat": 0,
|
||||
"clearCoatRoughness": 0.3,
|
||||
"emissive": "#000000",
|
||||
"emissiveIntensity": 0,
|
||||
"normalStrength": 1,
|
||||
"doubleSided": true,
|
||||
"tiling": 1,
|
||||
"textures": {}
|
||||
}
|
||||
},
|
||||
"objects": {
|
||||
"bms/Cable / red silicone": true,
|
||||
"bms/Cable / graphite silicone": true,
|
||||
"bms/Mount / G10 dielectric": true,
|
||||
"bms/Nickel plated copper / busbars": true,
|
||||
"bms/Sense / warm yellow": true,
|
||||
"bms/labels/electronics": true,
|
||||
"bms/Connector / ivory polymer": true,
|
||||
"bms/BMS / green PCB": true,
|
||||
"bms/Aluminium / satin": true,
|
||||
"bms/Lid / insulating black": true,
|
||||
"bms/Mount / adhesive film": true,
|
||||
"bms/Steel / fasteners": true,
|
||||
"bms/cells/C01": true,
|
||||
"bms/Cell / wrapped lower edge": true,
|
||||
"bms/labels/cells": true,
|
||||
"bms/cell-display/C01": true,
|
||||
"bms/cells/C02": true,
|
||||
"bms/cell-display/C02": true,
|
||||
"bms/cells/C03": true,
|
||||
"bms/cell-display/C03": true,
|
||||
"bms/cells/C04": true,
|
||||
"bms/cell-display/C04": true,
|
||||
"bms/cells/C05": true,
|
||||
"bms/cell-display/C05": true,
|
||||
"bms/cells/C06": true,
|
||||
"bms/cell-display/C06": true,
|
||||
"bms/cells/C07": true,
|
||||
"bms/cell-display/C07": true,
|
||||
"bms/cells/C08": true,
|
||||
"bms/cell-display/C08": true,
|
||||
"bms/cells/C09": true,
|
||||
"bms/cell-display/C09": true,
|
||||
"bms/cells/C10": true,
|
||||
"bms/cell-display/C10": true,
|
||||
"bms/cells/C11": true,
|
||||
"bms/cell-display/C11": true,
|
||||
"bms/cells/C12": true,
|
||||
"bms/cell-display/C12": true,
|
||||
"bms/cells/C13": true,
|
||||
"bms/cell-display/C13": true,
|
||||
"bms/CASE | bead-blasted graphite/CASE | base tray": true,
|
||||
"bms/CASE | bead-blasted graphite/CASE | front endplate": true,
|
||||
"bms/CASE | bead-blasted graphite/CASE | rear endplate": true,
|
||||
"bms/glass/CASE | removable solid top": true,
|
||||
"bms/glass/CASE | slotted side -1": true,
|
||||
"bms/glass/CASE | slotted side 1": true,
|
||||
"bms/R04 | elastomer seal": true,
|
||||
"bms/R04 | graphite moulded polymer": true,
|
||||
"bms/labels/enclosure": true,
|
||||
"bms/R04 | smoked polycarbonate": true,
|
||||
"bms/R04 | display protective polycarbonate": true,
|
||||
"bms/DISPLAY | black glass": true,
|
||||
"bms/CASE | recessed black": true,
|
||||
"bms/CASE | darker frame": true,
|
||||
"bms/CASE | bead-blasted graphite/HANDLE | folded aperture return": true,
|
||||
"bms/CASE | bead-blasted graphite/HANDLE | folded aperture return.001": true,
|
||||
"bms/CASE | bead-blasted graphite/HANDLE | integral web underside": true,
|
||||
"bms/CASE | dielectric liner": true,
|
||||
"bms/CASE | dielectric liner/left": true,
|
||||
"bms/CASE | dielectric liner/right": true,
|
||||
"bms/Connector / gold plated contacts": true,
|
||||
"bms/XT90-S / anti spark green insert": true,
|
||||
"bms/XT90-S / yellow PA housing": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import {useCallback,useEffect,useState} from 'react';
|
||||
import {SceneHistory,historyCommand} from '../roverScene/sceneHistory';
|
||||
import {batteryAppearanceKey,defaultBatteryAppearance,parseBatteryAppearance,type BatteryAppearance} from './appearance';
|
||||
export function useBatteryAppearance(id:string,active:boolean){
|
||||
const [error,setError]=useState('');
|
||||
const [history]=useState(()=>{let profile=defaultBatteryAppearance();try{const raw=localStorage.getItem(batteryAppearanceKey(id));if(raw)profile=parseBatteryAppearance(JSON.parse(raw));}catch{/* Keep the usable default if the local profile is unavailable. */}return new SceneHistory(profile);});
|
||||
const [value,setValue]=useState(history.present);
|
||||
const publish=useCallback(()=>{setValue(history.present);try{localStorage.setItem(batteryAppearanceKey(id),JSON.stringify(history.present));setError('');}catch{setError('Не удалось сохранить настройки батареи на этом компьютере.');}},[history,id]);
|
||||
const update=useCallback((next:BatteryAppearance)=>{if(JSON.stringify(next)!==JSON.stringify(history.present)){history.update(next);publish();}},[history,publish]);
|
||||
const undo=useCallback(()=>{if(history.undo())publish();},[history,publish]);
|
||||
const redo=useCallback(()=>{if(history.redo())publish();},[history,publish]);
|
||||
useEffect(()=>{
|
||||
if(!active)return;
|
||||
const begin=()=>history.begin(),end=()=>history.end();
|
||||
const key=(e:KeyboardEvent)=>{const command=historyCommand(e);if(command){e.preventDefault();e.stopImmediatePropagation();if(command==='undo')undo();else redo();}else if(!e.repeat&&e.key.startsWith('Arrow')&&(e.target as HTMLElement)?.closest?.('[role=slider],input[type=range]'))begin();};
|
||||
const up=(e:KeyboardEvent)=>{if(e.key.startsWith('Arrow'))end();};
|
||||
window.addEventListener('keydown',key,true);window.addEventListener('keyup',up,true);window.addEventListener('pointerdown',begin,true);window.addEventListener('pointerup',end);window.addEventListener('pointercancel',end);window.addEventListener('blur',end);
|
||||
return()=>{end();window.removeEventListener('keydown',key,true);window.removeEventListener('keyup',up,true);window.removeEventListener('pointerdown',begin,true);window.removeEventListener('pointerup',end);window.removeEventListener('pointercancel',end);window.removeEventListener('blur',end);};
|
||||
},[active,history,undo,redo]);
|
||||
return {value,update,undo,redo,canUndo:history.canUndo,canRedo:history.canRedo,error,setError};
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
/** Local view geometry is independent of imported scene/material JSON. */
|
||||
export const minBatteryViewHeight=360,maxBatteryViewHeight=2160;
|
||||
export const batteryViewHeightKey=(id:string)=>`missioncore.battery-view/v1:${encodeURIComponent(id)}`;
|
||||
export function batteryViewHeight(raw:string|null,viewportHeight:number):number{
|
||||
const fallback=Math.max(minBatteryViewHeight,Math.min(900,Math.round(viewportHeight-300)));
|
||||
try{const value=JSON.parse(raw??'null');return typeof value?.height==='number'&&Number.isFinite(value.height)?Math.max(minBatteryViewHeight,Math.min(maxBatteryViewHeight,Math.round(value.height))):fallback;}catch{return fallback;}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import {useMemo,useState} from 'react';
|
||||
import {createPortal} from 'react-dom';
|
||||
import {Description,Icon,IconButton,LoadingRegion,SettingsCard,ToastStack} from '@nodedc/ui-react';
|
||||
import {useDevicePluginHost} from '../../core/device-plugins/DevicePluginHost';
|
||||
import {createFleetSensorTransport} from '../../core/fleet/sensorTransport';
|
||||
import type {Vehicle} from '../../core/fleet/useFleet';
|
||||
import {sensorContribution} from '../../../../../packages/sensor-ui/src/extensions';
|
||||
import {useObservationInventory} from './observation/useObservationInventory';
|
||||
|
||||
/** Equipment details own a full workspace, alongside observation and monitoring. */
|
||||
export function VehicleDeviceView({vehicle,deviceID,enabled,back,headerToolsHost,titlePrefix,headerTitleHost}:{vehicle:Vehicle;deviceID:string;enabled:boolean;back:()=>void;headerToolsHost?:HTMLElement|null;titlePrefix:string;headerTitleHost?:HTMLElement|null}){
|
||||
const {registry}=useDevicePluginHost(),transport=useMemo(()=>createFleetSensorTransport(vehicle.id),[vehicle.id]);
|
||||
const {inventory,refresh}=useObservationInventory(transport);
|
||||
const [error,setError]=useState('');
|
||||
const device=inventory?.items.find(item=>item.id===deviceID),contribution=device?sensorContribution(registry.sensorContributions,device):undefined;
|
||||
const Detail=contribution?.Detail;
|
||||
const navigation=<IconButton label="Вернуться к оборудованию аппарата" onClick={back}><Icon name="chevron-left"/></IconButton>;
|
||||
return <>{headerTitleHost&&createPortal(`${titlePrefix}${device?` / ${device.name}`:""}`,headerTitleHost)}{headerToolsHost?createPortal(navigation,headerToolsHost):navigation}
|
||||
{!inventory?<LoadingRegion loading label="Получение устройства"/>:device&&Detail?<Detail key={device.id} headerActionsTarget={headerToolsHost} device={device} enabled={enabled&&inventory.fresh!==false} transport={transport} sceneSeedKey={vehicle.id} back={back} refresh={async()=>{await refresh();}} failure={value=>setError(value instanceof Error?value.message:String(value??''))}/>:<SettingsCard title="Устройство недоступно"><Description>Вернитесь к оборудованию и обновите список устройств.</Description></SettingsCard>}
|
||||
<ToastStack items={error?[{id:'equipment-detail',tone:'error',title:'Просмотр устройства',description:error}]:[]} onDismiss={()=>setError('')}/>
|
||||
</>;
|
||||
}
|
||||
@@ -5,13 +5,13 @@ import {boardStatus} from './BoardComputer';
|
||||
import {platformLabel} from './NodeInvitationForm';
|
||||
import {VehicleSensors} from './VehicleSensors';
|
||||
|
||||
export function VehicleFleetRow({vehicle,available,expanded,onToggle,onObserve,onAddComputer,onBoardSettings,onMonitor,onUpdated}:{vehicle:Vehicle;available:boolean;expanded:boolean;onToggle:()=>void;onObserve:()=>void;onAddComputer:()=>void;onBoardSettings:()=>void;onMonitor:()=>void;onUpdated:(vehicle:Vehicle)=>void}){
|
||||
export function VehicleFleetRow({vehicle,available,expanded,onToggle,onObserve,onAddComputer,onBoardSettings,onMonitor,onUpdated,onDeviceView}:{vehicle:Vehicle;available:boolean;expanded:boolean;onToggle:()=>void;onObserve:()=>void;onAddComputer:()=>void;onBoardSettings:()=>void;onMonitor:()=>void;onUpdated:(vehicle:Vehicle)=>void;onDeviceView?:(id:string)=>void}){
|
||||
const [settingsOpen,setSettingsOpen]=useState(false);
|
||||
const [equipmentActionsTarget,setEquipmentActionsTarget]=useState<HTMLSpanElement|null>(null);
|
||||
const branchID=useId();
|
||||
const enabled=available&&vehicle.enrollment==='paired'&&vehicle.connectivity==='online';
|
||||
const label=available?boardStatus(vehicle):'Нет свежих данных';
|
||||
const sensors={vehicle,enabled,onAddComputer,onSettings:onBoardSettings,onMonitor,onUpdated};
|
||||
const sensors={vehicle,enabled,onAddComputer,onSettings:onBoardSettings,onMonitor,onUpdated,onDeviceView};
|
||||
return <li>
|
||||
<ResourceRow icon={<Icon name="apps"/>} title={vehicle.name} description={platformLabel(vehicle.platform)} metadata={label} statusPlacement="leading" status={<StatusBadge variant="indicator" tone={enabled?'success':vehicle.enrollment==='pending'?'warning':'neutral'} aria-label={label} title={label}/>} actions={<>
|
||||
{expanded&&!settingsOpen&&<span ref={setEquipmentActionsTarget} className="fleet-equipment-actions"/>}
|
||||
|
||||
@@ -7,11 +7,11 @@ import {createFleetSensorTransport} from '../../core/fleet/sensorTransport';
|
||||
import type {Vehicle} from '../../core/fleet/useFleet';
|
||||
import {VehicleEquipment} from './VehicleEquipment';
|
||||
import {VehicleIdentitySettings} from './VehicleIdentitySettings';
|
||||
export function VehicleSensors({vehicle,enabled,mode='equipment',equipmentActionsTarget,onAddComputer,onSettings,onMonitor,onUpdated}:{vehicle:Vehicle;enabled:boolean;mode?:'equipment'|'settings';equipmentActionsTarget?:HTMLElement|null;onAddComputer:()=>void;onSettings:()=>void;onMonitor:()=>void;onUpdated:(vehicle:Vehicle)=>void}){
|
||||
export function VehicleSensors({vehicle,enabled,mode='equipment',equipmentActionsTarget,onAddComputer,onSettings,onMonitor,onUpdated,onDeviceView}:{vehicle:Vehicle;enabled:boolean;mode?:'equipment'|'settings';equipmentActionsTarget?:HTMLElement|null;onAddComputer:()=>void;onSettings:()=>void;onMonitor:()=>void;onUpdated:(vehicle:Vehicle)=>void;onDeviceView?:(id:string)=>void}){
|
||||
const vehicleID=vehicle.id;
|
||||
const {registry}=useDevicePluginHost();
|
||||
const sensorContributions=registry.sensorContributions;
|
||||
const layout=useMemo(()=>boardLayout(vehicleID),[vehicleID]);
|
||||
const transport=useMemo(()=>createFleetSensorTransport(vehicleID),[vehicleID]);
|
||||
return <SensorWorkspace contributions={sensorContributions} createRerunHost={createIsolatedRerunHost} key={`${vehicleID}:${vehicle.node_id}`} transport={transport} enabled={enabled} previewEnabled={vehicle.enrollment==='paired'} readOfflineInventory detailActionsTarget={equipmentActionsTarget} renderBoard={content=>mode==='settings'?<div className="sensor-content"><VehicleIdentitySettings vehicle={vehicle} onUpdated={onUpdated}/>{content.settings}</div>:<VehicleEquipment vehicle={vehicle} enabled={enabled} layout={layout} content={content} actionsTarget={equipmentActionsTarget} onAddComputer={onAddComputer} onSettings={onSettings} onMonitor={onMonitor}/>}/>;
|
||||
return <SensorWorkspace onOpenDetail={onDeviceView?device=>onDeviceView(device.id):undefined} sceneSeedKey={vehicleID} contributions={sensorContributions} createRerunHost={createIsolatedRerunHost} key={`${vehicleID}:${vehicle.node_id}`} transport={transport} enabled={enabled} previewEnabled={vehicle.enrollment==='paired'} readOfflineInventory detailActionsTarget={equipmentActionsTarget} renderBoard={content=>mode==='settings'?<div className="sensor-content"><VehicleIdentitySettings vehicle={vehicle} onUpdated={onUpdated}/>{content.settings}</div>:<VehicleEquipment vehicle={vehicle} enabled={enabled} layout={layout} content={content} actionsTarget={equipmentActionsTarget} onAddComputer={onAddComputer} onSettings={onSettings} onMonitor={onMonitor}/>}/>;
|
||||
}
|
||||
|
||||
@@ -6,13 +6,14 @@ import {BoardObservationCenter} from './observation/BoardObservationCenter';
|
||||
import {BoardMonitorView} from './BoardMonitorView';
|
||||
import {BoardComputerSettings} from './BoardComputer';
|
||||
import {NodeInvitationForm,platformLabel} from './NodeInvitationForm';
|
||||
import {VehicleDeviceView} from './VehicleDeviceView';
|
||||
import {VehicleFleetRow} from './VehicleFleetRow';
|
||||
import {OperatorNetworkWindow} from '../../components/network/OperatorNetworkWindow';
|
||||
import './fleet.css';
|
||||
|
||||
export function VehiclesWorkspace({headerToolsHost,headerTitleHost}:{headerToolsHost?:HTMLElement|null;headerTitleHost?:HTMLElement|null}){
|
||||
const fleet=useFleet();
|
||||
const [view,setView]=useState<{vehicleID:string;mode:'observation'|'monitor'}|null>(null);
|
||||
const [view,setView]=useState<{vehicleID:string;mode:'observation'|'monitor'|'device';deviceID?:string}|null>(null);
|
||||
const [expanded,setExpanded]=useState<string[]>([]);
|
||||
const [adding,setAdding]=useState<Vehicle|null|undefined>();
|
||||
const [boardSettings,setBoardSettings]=useState<string|null>(null);
|
||||
@@ -27,12 +28,13 @@ export function VehiclesWorkspace({headerToolsHost,headerTitleHost}:{headerTools
|
||||
const addButton=<><IconButton label="Сеть операторского компьютера" onClick={()=>setOperatorNetwork(true)}><Icon name="network"/></IconButton><IconButton label="Добавить аппарат" onClick={()=>setAdding(null)}><Icon name="plus"/></IconButton></>;
|
||||
const headerAdd=!detail&&(headerToolsHost?createPortal(addButton,headerToolsHost):addButton);
|
||||
const titleSuffix=detail?` — ${detail.name} / ${platformLabel(detail.platform)}`:'';
|
||||
const content=detail&&view?.mode==='observation'?<BoardObservationCenter key={detail.id} vehicleID={detail.id} name={detail.name} enabled={enabled(detail)} paired={detail.enrollment==='paired'} back={()=>setView(null)} configure={()=>showEquipment(detail.id)} headerToolsHost={headerToolsHost}/>
|
||||
const content=detail&&view?.mode==='device'&&view.deviceID?<VehicleDeviceView vehicle={detail} deviceID={view.deviceID} enabled={enabled(detail)} back={()=>showEquipment(detail.id)} headerToolsHost={headerToolsHost} titlePrefix={titleSuffix} headerTitleHost={headerTitleHost}/>
|
||||
:detail&&view?.mode==='observation'?<BoardObservationCenter key={detail.id} vehicleID={detail.id} name={detail.name} enabled={enabled(detail)} paired={detail.enrollment==='paired'} back={()=>setView(null)} configure={()=>showEquipment(detail.id)} headerToolsHost={headerToolsHost}/>
|
||||
:detail&&view?.mode==='monitor'?<BoardMonitorView vehicle={detail.id} name={detail.name} back={()=>showEquipment(detail.id)} headerToolsHost={headerToolsHost}/>
|
||||
:<div className="fleet-workspace">
|
||||
{!fleet.items?<LoadingRegion loading={!fleet.error} label="Получение аппаратов"/>:fleet.items.length===0?<SettingsCard title="Аппаратов пока нет" description="Создайте аппарат и подключите его бортовой компьютер по приглашению Mission Core Node."/>:<ResourceList aria-label="Аппараты">{fleet.items.map(item=><VehicleFleetRow key={item.id} vehicle={item} available={!fleet.error} expanded={expanded.includes(item.id)} onToggle={()=>setExpanded(current=>current.includes(item.id)?current.filter(id=>id!==item.id):[...current,item.id])} onObserve={()=>setView({vehicleID:item.id,mode:'observation'})} onAddComputer={()=>setAdding(item)} onBoardSettings={()=>setBoardSettings(item.id)} onMonitor={()=>setView({vehicleID:item.id,mode:'monitor'})} onUpdated={fleet.acceptVehicle}/>)}</ResourceList>}
|
||||
{!fleet.items?<LoadingRegion loading={!fleet.error} label="Получение аппаратов"/>:fleet.items.length===0?<SettingsCard title="Аппаратов пока нет" description="Создайте аппарат и подключите его бортовой компьютер по приглашению Mission Core Node."/>:<ResourceList aria-label="Аппараты">{fleet.items.map(item=><VehicleFleetRow key={item.id} vehicle={item} available={!fleet.error} expanded={expanded.includes(item.id)} onToggle={()=>setExpanded(current=>current.includes(item.id)?current.filter(id=>id!==item.id):[...current,item.id])} onDeviceView={deviceID=>setView({vehicleID:item.id,mode:'device',deviceID})} onObserve={()=>setView({vehicleID:item.id,mode:'observation'})} onAddComputer={()=>setAdding(item)} onBoardSettings={()=>setBoardSettings(item.id)} onMonitor={()=>setView({vehicleID:item.id,mode:'monitor'})} onUpdated={fleet.acceptVehicle}/>)}</ResourceList>}
|
||||
</div>;
|
||||
return <>{headerTitleHost&&createPortal(titleSuffix,headerTitleHost)}{headerAdd}{content}
|
||||
return <>{headerTitleHost&&view?.mode!=='device'&&createPortal(titleSuffix,headerTitleHost)}{headerAdd}{content}
|
||||
{operatorNetwork&&<OperatorNetworkWindow onClose={()=>setOperatorNetwork(false)}/>}
|
||||
{adding!==undefined&&<NodeInvitationForm key={adding?.id??'new'} vehicle={adding??undefined} onClose={()=>setAdding(undefined)} onComplete={complete} renderWindow={({content,actions,busy})=><Window open title={adding?'Подключить бортовой компьютер':'Добавить аппарат'} subtitle={adding?adding.name:'Создать аппарат и подключить БК по приглашению Node'} size="md" closeOnBackdrop={false} closeOnEscape={!busy} onClose={()=>{if(!busy)setAdding(undefined);}} footer={<WindowFooterActions>{actions}</WindowFooterActions>}>{content}</Window>}/>}
|
||||
{settingsVehicle&&<BoardComputerSettings vehicle={settingsVehicle} enabled={enabled(settingsVehicle)} onClose={()=>setBoardSettings(null)} onRevoke={()=>{setBoardSettings(null);setRevoking(settingsVehicle);}}/>}
|
||||
|
||||
Reference in New Issue
Block a user