Enhance Machine and Vehicle components: add current action management and update machine sample structure

This commit is contained in:
Jerald-Golden-B 2025-05-02 12:11:09 +05:30
parent 405dbe434f
commit 34c30bb5a2
4 changed files with 78 additions and 20 deletions

View File

@ -1,29 +1,42 @@
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 = {
modelUuid: "machine-1234-5678-9012",
modelName: "CNC Milling Machine",
position: [10, 0, 5],
rotation: [0, 0, 0],
state: "idle",
type: "machine",
point: {
uuid: "machine-point-9876-5432-1098",
position: [10, 0.5, 5.2],
const machineSample: MachineEventSchema[] = [
{
modelUuid: "machine-1234-5678-9012",
modelName: "CNC Milling Machine",
position: [10, 0, 5],
rotation: [0, 0, 0],
action: {
actionUuid: "machine-action-2468-1357-8024",
actionName: "Metal Processing",
actionType: "process",
processTime: 10,
swapMaterial: "steel",
triggers: []
state: "idle",
type: "machine",
point: {
uuid: "machine-point-9876-5432-1098",
position: [10, 0.5, 5.2],
rotation: [0, 0, 0],
action: {
actionUuid: "machine-action-2468-1357-8024",
actionName: "Metal Processing",
actionType: "process",
processTime: 10,
swapMaterial: "steel",
triggers: []
}
}
}
};
];
useEffect(() => {
removeMachine(machineSample[0].modelUuid);
addMachine(selectedProduct.productId, machineSample[0]);
// addCurrentAction(machineSample[0].modelUuid, machineSample[0].point.action.actionUuid);
}, [])
return (
<>

View File

@ -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);

View File

@ -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) => {

View File

@ -143,6 +143,10 @@ interface MachineStatus extends MachineEventSchema {
isActive: boolean;
idleTime: number;
activeTime: number;
currentAction?: {
actionUuid: string;
actionName: string;
};
}
interface ArmBotStatus extends RoboticArmEventSchema {