2025-05-14 07:51:29 +00:00
|
|
|
import { create } from "zustand";
|
|
|
|
import { immer } from "zustand/middleware/immer";
|
feat: Implement Zustand stores for machine, simulation, storage unit, vehicle, and visualization management
- Added `useMachineStore` for managing machine statuses, including actions for adding, removing, and updating machines.
- Introduced `useSimulationStore` to handle product and event management with actions for adding, removing, and updating products and events.
- Created `useStorageUnitStore` for managing storage unit statuses, including load tracking and state updates.
- Developed `useVehicleStore` for vehicle management, including load and state updates.
- Implemented `useChartStore` for managing measurement data and visualization settings.
- Added `useDroppedObjectsStore` for handling dropped objects in visualization zones, including object manipulation actions.
- Created `useZone3DWidgetStore` for managing 3D widget data in zones, including position and rotation updates.
- Introduced `useZoneStore` for managing selected zone states and widget configurations.
2025-04-22 08:58:29 +00:00
|
|
|
|
|
|
|
interface MachineStore {
|
2025-05-14 07:51:29 +00:00
|
|
|
machines: MachineStatus[];
|
|
|
|
|
|
|
|
addMachine: (productId: string, machine: MachineEventSchema) => void;
|
|
|
|
removeMachine: (modelUuid: string) => void;
|
|
|
|
updateMachine: (
|
|
|
|
modelUuid: string,
|
|
|
|
updates: Partial<Omit<MachineStatus, "modelUuid" | "productId">>
|
|
|
|
) => void;
|
|
|
|
clearMachines: () => void;
|
|
|
|
|
|
|
|
addCurrentAction: (
|
|
|
|
modelUuid: string,
|
|
|
|
actionUuid: string,
|
|
|
|
materialType: string,
|
|
|
|
materialId: string
|
|
|
|
) => void;
|
|
|
|
removeCurrentAction: (modelUuid: string) => void;
|
|
|
|
|
|
|
|
setMachineActive: (modelUuid: string, isActive: boolean) => void;
|
|
|
|
setMachineState: (
|
|
|
|
modelUuid: string,
|
|
|
|
newState: MachineStatus["state"]
|
|
|
|
) => void;
|
|
|
|
|
|
|
|
incrementActiveTime: (modelUuid: string, incrementBy: number) => void;
|
|
|
|
incrementIdleTime: (modelUuid: string, incrementBy: number) => void;
|
|
|
|
resetTime: (modelUuid: string) => void;
|
|
|
|
|
|
|
|
getMachineById: (modelUuid: string) => MachineStatus | undefined;
|
|
|
|
getMachinesByProduct: (productId: string) => MachineStatus[];
|
|
|
|
getMachinesBystate: (state: string) => MachineStatus[];
|
|
|
|
getActiveMachines: () => MachineStatus[];
|
|
|
|
getIdleMachines: () => MachineStatus[];
|
feat: Implement Zustand stores for machine, simulation, storage unit, vehicle, and visualization management
- Added `useMachineStore` for managing machine statuses, including actions for adding, removing, and updating machines.
- Introduced `useSimulationStore` to handle product and event management with actions for adding, removing, and updating products and events.
- Created `useStorageUnitStore` for managing storage unit statuses, including load tracking and state updates.
- Developed `useVehicleStore` for vehicle management, including load and state updates.
- Implemented `useChartStore` for managing measurement data and visualization settings.
- Added `useDroppedObjectsStore` for handling dropped objects in visualization zones, including object manipulation actions.
- Created `useZone3DWidgetStore` for managing 3D widget data in zones, including position and rotation updates.
- Introduced `useZoneStore` for managing selected zone states and widget configurations.
2025-04-22 08:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const useMachineStore = create<MachineStore>()(
|
2025-05-14 07:51:29 +00:00
|
|
|
immer((set, get) => ({
|
|
|
|
machines: [],
|
|
|
|
|
|
|
|
addMachine: (productId, machine) => {
|
|
|
|
set((state) => {
|
|
|
|
const exists = state.machines.some(
|
|
|
|
(m) => m.modelUuid === machine.modelUuid
|
|
|
|
);
|
|
|
|
if (!exists) {
|
|
|
|
state.machines.push({
|
|
|
|
...machine,
|
|
|
|
productId,
|
|
|
|
isActive: false,
|
|
|
|
idleTime: 0,
|
|
|
|
activeTime: 0,
|
|
|
|
state: "idle",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
removeMachine: (modelUuid) => {
|
|
|
|
set((state) => {
|
|
|
|
state.machines = state.machines.filter(
|
|
|
|
(m) => m.modelUuid !== modelUuid
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
updateMachine: (modelUuid, updates) => {
|
|
|
|
set((state) => {
|
|
|
|
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
|
|
|
|
if (machine) {
|
|
|
|
Object.assign(machine, updates);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
clearMachines: () => {
|
|
|
|
set((state) => {
|
|
|
|
state.machines = [];
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
addCurrentAction: (modelUuid, actionUuid, materialType, materialId) => {
|
|
|
|
set((state) => {
|
|
|
|
const armBot = state.machines.find((a) => a.modelUuid === modelUuid);
|
|
|
|
if (armBot) {
|
|
|
|
const action = armBot.point.action;
|
|
|
|
if (action) {
|
|
|
|
armBot.currentAction = {
|
|
|
|
actionUuid: actionUuid,
|
|
|
|
actionName: action.actionName,
|
|
|
|
materialType: materialType,
|
|
|
|
materialId: materialId,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
removeCurrentAction: (modelUuid) => {
|
|
|
|
set((state) => {
|
|
|
|
const armBot = state.machines.find((a) => a.modelUuid === modelUuid);
|
|
|
|
if (armBot) {
|
|
|
|
armBot.currentAction = undefined;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setMachineActive: (modelUuid, isActive) => {
|
|
|
|
set((state) => {
|
|
|
|
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
|
|
|
|
if (machine) {
|
|
|
|
machine.isActive = isActive;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setMachineState: (modelUuid, newState) => {
|
|
|
|
set((state) => {
|
|
|
|
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
|
|
|
|
if (machine) {
|
|
|
|
machine.state = newState;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
incrementActiveTime: (modelUuid, incrementBy) => {
|
|
|
|
set((state) => {
|
|
|
|
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
|
|
|
|
if (machine) {
|
|
|
|
machine.activeTime += incrementBy;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
incrementIdleTime: (modelUuid, incrementBy) => {
|
|
|
|
set((state) => {
|
|
|
|
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
|
|
|
|
if (machine) {
|
|
|
|
machine.idleTime += incrementBy;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
resetTime: (modelUuid) => {
|
|
|
|
set((state) => {
|
|
|
|
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
|
|
|
|
if (machine) {
|
|
|
|
machine.activeTime = 0;
|
|
|
|
machine.idleTime = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
getMachineById: (modelUuid) => {
|
|
|
|
return get().machines.find((m) => m.modelUuid === modelUuid);
|
|
|
|
},
|
|
|
|
|
|
|
|
getMachinesByProduct: (productId) => {
|
|
|
|
return get().machines.filter((m) => m.productId === productId);
|
|
|
|
},
|
|
|
|
|
|
|
|
getMachinesBystate: (state) => {
|
|
|
|
return get().machines.filter((m) => m.state === state);
|
|
|
|
},
|
|
|
|
|
|
|
|
getActiveMachines: () => {
|
|
|
|
return get().machines.filter((m) => m.isActive);
|
|
|
|
},
|
|
|
|
|
|
|
|
getIdleMachines: () => {
|
|
|
|
return get().machines.filter((m) => !m.isActive && m.state === "idle");
|
|
|
|
},
|
|
|
|
}))
|
2025-04-22 09:14:09 +00:00
|
|
|
);
|