Enhance Machine and Vehicle components: add current action management and update machine sample structure
This commit is contained in:
parent
405dbe434f
commit
34c30bb5a2
|
@ -1,9 +1,14 @@
|
|||
import React from 'react'
|
||||
import React, { useEffect } from 'react'
|
||||
import MachineInstances from './instances/machineInstances'
|
||||
import { useMachineStore } from '../../../store/simulation/useMachineStore'
|
||||
import { useSelectedProduct } from '../../../store/simulation/useSimulationStore';
|
||||
|
||||
function Machine() {
|
||||
const { addMachine, addCurrentAction, removeMachine } = useMachineStore();
|
||||
const { selectedProduct } = useSelectedProduct();
|
||||
|
||||
const machineSample: MachineEventSchema = {
|
||||
const machineSample: MachineEventSchema[] = [
|
||||
{
|
||||
modelUuid: "machine-1234-5678-9012",
|
||||
modelName: "CNC Milling Machine",
|
||||
position: [10, 0, 5],
|
||||
|
@ -23,7 +28,15 @@ function Machine() {
|
|||
triggers: []
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
removeMachine(machineSample[0].modelUuid);
|
||||
addMachine(selectedProduct.productId, machineSample[0]);
|
||||
|
||||
// addCurrentAction(machineSample[0].modelUuid, machineSample[0].point.action.actionUuid);
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
@ -8,7 +8,7 @@ import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
|||
import { useProductStore } from "../../../store/simulation/useProductStore";
|
||||
|
||||
function Vehicles() {
|
||||
const { getProductById } = useProductStore();
|
||||
const { products, getProductById } = useProductStore();
|
||||
const { selectedProduct } = useSelectedProduct();
|
||||
const { vehicles, addVehicle, removeVehicle } = useVehicleStore();
|
||||
const { selectedEventSphere } = useSelectedEventSphere();
|
||||
|
@ -29,6 +29,19 @@ function Vehicles() {
|
|||
}
|
||||
}
|
||||
}, [selectedProduct]);
|
||||
|
||||
// useEffect(() => {
|
||||
// vehicles.forEach(vehicle => {
|
||||
// const product = getProductById(vehicle.productId);
|
||||
// if (product) {
|
||||
// const eventData = product.eventDatas.find(event => event.modelUuid === vehicle.modelUuid);
|
||||
// if (eventData) {
|
||||
// vehicle.eventData = eventData;
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }, [vehicles, products]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
// console.log('vehicles: ', vehicles);
|
||||
|
|
|
@ -12,6 +12,9 @@ interface MachineStore {
|
|||
updates: Partial<Omit<MachineStatus, 'modelUuid' | 'productId'>>
|
||||
) => void;
|
||||
|
||||
addCurrentAction: (modelUuid: string, actionUuid: string) => void;
|
||||
removeCurrentAction: (modelUuid: string) => void;
|
||||
|
||||
// Status updates
|
||||
setMachineActive: (modelUuid: string, isActive: boolean) => void;
|
||||
setMachineState: (modelUuid: string, newState: MachineStatus['state']) => void;
|
||||
|
@ -61,6 +64,31 @@ export const useMachineStore = create<MachineStore>()(
|
|||
});
|
||||
},
|
||||
|
||||
|
||||
addCurrentAction: (modelUuid) => {
|
||||
set((state) => {
|
||||
const armBot = state.machines.find(a => a.modelUuid === modelUuid);
|
||||
if (armBot) {
|
||||
const action = armBot.point.action;
|
||||
if (action) {
|
||||
armBot.currentAction = {
|
||||
actionUuid: action.actionUuid,
|
||||
actionName: action.actionName,
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeCurrentAction: (modelUuid) => {
|
||||
set((state) => {
|
||||
const armBot = state.machines.find(a => a.modelUuid === modelUuid);
|
||||
if (armBot) {
|
||||
armBot.currentAction = undefined;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Status updates
|
||||
setMachineActive: (modelUuid, isActive) => {
|
||||
set((state) => {
|
||||
|
|
|
@ -143,6 +143,10 @@ interface MachineStatus extends MachineEventSchema {
|
|||
isActive: boolean;
|
||||
idleTime: number;
|
||||
activeTime: number;
|
||||
currentAction?: {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface ArmBotStatus extends RoboticArmEventSchema {
|
||||
|
|
Loading…
Reference in New Issue