v2 #80
|
@ -61,7 +61,7 @@ export function useSpawnHandler() {
|
||||||
current: {
|
current: {
|
||||||
modelUuid: modelUuid,
|
modelUuid: modelUuid,
|
||||||
pointUuid: pointUuid,
|
pointUuid: pointUuid,
|
||||||
actionUuid: action?.actionUuid || ''
|
actionUuid: action.actionUuid
|
||||||
},
|
},
|
||||||
weight: 1,
|
weight: 1,
|
||||||
cost: 1
|
cost: 1
|
||||||
|
@ -74,7 +74,6 @@ export function useSpawnHandler() {
|
||||||
newMaterial.next = {
|
newMaterial.next = {
|
||||||
modelUuid: action.triggers[0].triggeredAsset?.triggeredModel.modelUuid,
|
modelUuid: action.triggers[0].triggeredAsset?.triggeredModel.modelUuid,
|
||||||
pointUuid: action.triggers[0].triggeredAsset?.triggeredPoint?.pointUuid,
|
pointUuid: action.triggers[0].triggeredAsset?.triggeredPoint?.pointUuid,
|
||||||
actionUuid: action.triggers[0].triggeredAsset?.triggeredAction?.actionUuid
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
import { useCallback } from "react";
|
||||||
|
import { useMaterialStore } from "../../../../../store/simulation/useMaterialStore";
|
||||||
|
import { useProductStore } from "../../../../../store/simulation/useProductStore";
|
||||||
|
import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore";
|
||||||
|
import { usePlayButtonStore } from "../../../../../store/usePlayButtonStore";
|
||||||
|
import * as THREE from 'three';
|
||||||
|
|
||||||
|
export function useSwapHandler() {
|
||||||
|
const { addMaterial, getMaterialByCurrentPointUuid, setMaterial } = useMaterialStore();
|
||||||
|
const { getPointUuidByActionUuid } = useProductStore();
|
||||||
|
const { selectedProduct } = useSelectedProduct();
|
||||||
|
const { isPlaying } = usePlayButtonStore();
|
||||||
|
|
||||||
|
const swapLogStatus = (materialUuid: string, status: string) => {
|
||||||
|
// console.log(`${materialUuid}, ${status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSwap = useCallback((action: ConveyorAction) => {
|
||||||
|
if (!action || action.actionType !== 'swap' || !isPlaying) return;
|
||||||
|
|
||||||
|
const { material: newMaterialType, actionUuid } = action;
|
||||||
|
const pointUuid = getPointUuidByActionUuid(selectedProduct.productId, actionUuid);
|
||||||
|
|
||||||
|
if (!pointUuid) return;
|
||||||
|
|
||||||
|
const currentMaterial = getMaterialByCurrentPointUuid(pointUuid);
|
||||||
|
|
||||||
|
if (currentMaterial) {
|
||||||
|
setMaterial(currentMaterial.materialId, newMaterialType);
|
||||||
|
swapLogStatus(currentMaterial.materialId, `Swapped to ${newMaterialType}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, [addMaterial, getMaterialByCurrentPointUuid, getPointUuidByActionUuid, isPlaying, setMaterial, selectedProduct.productId]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
handleSwap,
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,11 +1,12 @@
|
||||||
import { useEffect, useCallback, useRef } from "react";
|
import { useEffect, useCallback, useRef } from "react";
|
||||||
import { useSpawnHandler } from "./actionHandler/useSpawnHandler";
|
import { useSpawnHandler } from "./actionHandler/useSpawnHandler";
|
||||||
|
import { useSwapHandler } from "./actionHandler/useSwapHandler";
|
||||||
|
|
||||||
export function useConveyorActions() {
|
export function useConveyorActions() {
|
||||||
const { handleSpawn, clearCurrentSpawn } = useSpawnHandler();
|
const { handleSpawn, clearCurrentSpawn } = useSpawnHandler();
|
||||||
|
const { handleSwap } = useSwapHandler();
|
||||||
|
|
||||||
const handleDefaultAction = useCallback((action: ConveyorAction) => {
|
const handleDefaultAction = useCallback((action: ConveyorAction) => {
|
||||||
console.log('action: ', action);
|
|
||||||
console.log(`Default conveyor action ${action.actionUuid}`);
|
console.log(`Default conveyor action ${action.actionUuid}`);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
@ -14,8 +15,8 @@ export function useConveyorActions() {
|
||||||
}, [handleSpawn]);
|
}, [handleSpawn]);
|
||||||
|
|
||||||
const handleSwapAction = useCallback((action: ConveyorAction) => {
|
const handleSwapAction = useCallback((action: ConveyorAction) => {
|
||||||
console.log(`Swapping to material ${action.material}`);
|
handleSwap(action);
|
||||||
}, []);
|
}, [handleSwap]);
|
||||||
|
|
||||||
const handleDelayAction = useCallback((action: ConveyorAction) => {
|
const handleDelayAction = useCallback((action: ConveyorAction) => {
|
||||||
const delayMs = (action.delay || 0) * 1000;
|
const delayMs = (action.delay || 0) * 1000;
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHa
|
||||||
function MaterialInstance({ material }: { material: MaterialSchema }) {
|
function MaterialInstance({ material }: { material: MaterialSchema }) {
|
||||||
const matRef: any = useRef();
|
const matRef: any = useRef();
|
||||||
const { scene } = useThree();
|
const { scene } = useThree();
|
||||||
const { getModelUuidByPointUuid, getPointByUuid, getEventByModelUuid, getActionByUuid } = useProductStore();
|
const { getModelUuidByPointUuid, getPointByUuid, getEventByModelUuid, getActionByUuid, getTriggerByUuid, getActionByPointUuid } = useProductStore();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
const { speed } = useAnimationPlaySpeed();
|
const { speed } = useAnimationPlaySpeed();
|
||||||
const { triggerPointActions } = useTriggerHandler();
|
const { triggerPointActions } = useTriggerHandler();
|
||||||
|
@ -84,13 +84,45 @@ function MaterialInstance({ material }: { material: MaterialSchema }) {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// console.log('material: ', material);
|
// console.log('material: ', material);
|
||||||
|
if (material.current && material.next) {
|
||||||
|
// console.log('current: ', material.current.pointUuid);
|
||||||
|
// console.log('next: ', material.next.pointUuid);
|
||||||
|
}
|
||||||
}, [material])
|
}, [material])
|
||||||
|
|
||||||
const callTrigger = () => {
|
const callTrigger = () => {
|
||||||
const action = getActionByUuid(selectedProduct.productId, material.current.actionUuid)
|
if (!material.next) return;
|
||||||
|
const fromModel = getEventByModelUuid(selectedProduct.productId, material.next.modelUuid);
|
||||||
|
if (!fromModel) return;
|
||||||
|
const fromPoint = getPointByUuid(selectedProduct.productId, fromModel.modelUuid, material.next.pointUuid);
|
||||||
|
if (!fromPoint) return;
|
||||||
|
|
||||||
|
if (fromModel.type === 'transfer') {
|
||||||
|
const toModel = getEventByModelUuid(selectedProduct.productId, material.next.modelUuid);
|
||||||
|
if (!toModel) return;
|
||||||
|
if (toModel.type === 'transfer') {
|
||||||
|
const action = getActionByPointUuid(selectedProduct.productId, material.next.pointUuid);
|
||||||
if (action) {
|
if (action) {
|
||||||
triggerPointActions(action);
|
triggerPointActions(action);
|
||||||
}
|
}
|
||||||
|
} else if (toModel?.type === 'vehicle') {
|
||||||
|
// Transfer to Vehicle
|
||||||
|
|
||||||
|
} else if (toModel?.type === 'machine') {
|
||||||
|
// Transfer to Machine
|
||||||
|
|
||||||
|
} else if (toModel?.type === 'roboticArm') {
|
||||||
|
// Transfer to Robotic Arm
|
||||||
|
|
||||||
|
} else if (toModel?.type === 'storageUnit') {
|
||||||
|
// Transfer to Storage Unit
|
||||||
|
}
|
||||||
|
} else if (fromModel.type === 'vehicle') {
|
||||||
|
} else if (fromModel.type === 'machine') {
|
||||||
|
} else if (fromModel.type === 'roboticArm') {
|
||||||
|
} else if (fromModel.type === 'storageUnit') {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -6,7 +6,7 @@ function MaterialInstances() {
|
||||||
const { materials } = useMaterialStore();
|
const { materials } = useMaterialStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('materials: ', materials);
|
// console.log('materials: ', materials);
|
||||||
}, [materials])
|
}, [materials])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -138,7 +138,7 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
||||||
else if (armBot && !armBot.isActive && armBot.state === "idle" && currentPhase === "rest" && !armBot.currentAction) {
|
else if (armBot && !armBot.isActive && armBot.state === "idle" && currentPhase === "rest" && !armBot.currentAction) {
|
||||||
logStatus(armBot.modelUuid, "Waiting to trigger CurrentAction")
|
logStatus(armBot.modelUuid, "Waiting to trigger CurrentAction")
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
addCurrentAction(armBot.modelUuid, armBot.point.actions[0].actionUuid);
|
addCurrentAction(armBot.modelUuid, armBot.point.actions[0].actionUuid, 'Default material');
|
||||||
}, 3000);
|
}, 3000);
|
||||||
return () => clearTimeout(timeoutId);
|
return () => clearTimeout(timeoutId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,119 +10,116 @@ export function useTriggerHandler() {
|
||||||
const { getMaterialByCurrentModelUuid, setCurrentLocation, setNextLocation } = useMaterialStore();
|
const { getMaterialByCurrentModelUuid, setCurrentLocation, setNextLocation } = useMaterialStore();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
|
|
||||||
const handleTrigger = (trigger: TriggerSchema, actionUuid: string) => {
|
const handleTrigger = (trigger: TriggerSchema, action: Action) => {
|
||||||
|
|
||||||
// const fromEvent = getEventByTriggerUuid(selectedProduct.productId, trigger.triggerUuid);
|
const fromEvent = getEventByTriggerUuid(selectedProduct.productId, trigger.triggerUuid);
|
||||||
// console.log('fromEvent: ', fromEvent);
|
|
||||||
|
|
||||||
// const toEvent = getEventByModelUuid(selectedProduct.productId, trigger.triggeredAsset?.triggeredModel.modelUuid || '');
|
const toEvent = getEventByModelUuid(selectedProduct.productId, trigger.triggeredAsset?.triggeredModel.modelUuid || '');
|
||||||
// console.log('toEvent: ', toEvent);
|
|
||||||
|
|
||||||
// if (fromEvent?.type === 'transfer') {
|
if (fromEvent?.type === 'transfer') {
|
||||||
// if (toEvent?.type === 'transfer') {
|
if (toEvent?.type === 'transfer') {
|
||||||
// // console.log('toEvent: ', toEvent.type);
|
// Transfer to Transfer
|
||||||
// // Transfer to Transfer
|
if (trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) {
|
||||||
// const action = getActionByUuid(selectedProduct.productId, trigger.triggeredAsset?.triggeredAction?.actionUuid || '');
|
const material = getMaterialByCurrentModelUuid(fromEvent.modelUuid);
|
||||||
// if (action && trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) {
|
if (material) {
|
||||||
// const material = getMaterialByCurrentModelUuid(fromEvent.modelUuid);
|
if (material.next) {
|
||||||
// if (material) {
|
|
||||||
// if (material.next &&
|
|
||||||
// action.triggers[0].triggeredAsset?.triggeredAction?.actionUuid &&
|
|
||||||
// action.triggers[0].triggeredAsset?.triggeredPoint?.pointUuid) {
|
|
||||||
|
|
||||||
// setCurrentLocation(material.materialId, material.next);
|
setCurrentLocation(material.materialId, {
|
||||||
|
modelUuid: material.next.modelUuid,
|
||||||
|
pointUuid: material.next.pointUuid,
|
||||||
|
actionUuid: trigger.triggeredAsset?.triggeredAction?.actionUuid,
|
||||||
|
});
|
||||||
|
|
||||||
// setNextLocation(material.materialId, {
|
setNextLocation(material.materialId, {
|
||||||
// modelUuid: toEvent.modelUuid,
|
modelUuid: trigger.triggeredAsset.triggeredModel.modelUuid,
|
||||||
// pointUuid: action.triggers[0].triggeredAsset?.triggeredPoint?.pointUuid,
|
pointUuid: trigger.triggeredAsset.triggeredPoint.pointUuid,
|
||||||
// actionUuid: action.triggers[0].triggeredAsset?.triggeredAction?.actionUuid
|
});
|
||||||
// });
|
}
|
||||||
// }
|
handleAction(action);
|
||||||
// handleAction(action);
|
}
|
||||||
// }
|
}
|
||||||
// }
|
} else if (toEvent?.type === 'vehicle') {
|
||||||
// } else if (toEvent?.type === 'vehicle') {
|
// Transfer to Vehicle
|
||||||
// // Transfer to Vehicle
|
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'machine') {
|
} else if (toEvent?.type === 'machine') {
|
||||||
// // Transfer to Machine
|
// Transfer to Machine
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'roboticArm') {
|
} else if (toEvent?.type === 'roboticArm') {
|
||||||
// // Transfer to Robotic Arm
|
// Transfer to Robotic Arm
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'storageUnit') {
|
} else if (toEvent?.type === 'storageUnit') {
|
||||||
// // Transfer to Storage Unit
|
// Transfer to Storage Unit
|
||||||
|
|
||||||
// }
|
}
|
||||||
// } else if (fromEvent?.type === 'vehicle') {
|
} else if (fromEvent?.type === 'vehicle') {
|
||||||
// if (toEvent?.type === 'transfer') {
|
if (toEvent?.type === 'transfer') {
|
||||||
// // Vehicle to Transfer
|
// Vehicle to Transfer
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'vehicle') {
|
} else if (toEvent?.type === 'vehicle') {
|
||||||
// // Vehicle to Vehicle
|
// Vehicle to Vehicle
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'machine') {
|
} else if (toEvent?.type === 'machine') {
|
||||||
// // Vehicle to Machine
|
// Vehicle to Machine
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'roboticArm') {
|
} else if (toEvent?.type === 'roboticArm') {
|
||||||
// // Vehicle to Robotic Arm
|
// Vehicle to Robotic Arm
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'storageUnit') {
|
} else if (toEvent?.type === 'storageUnit') {
|
||||||
// // Vehicle to Storage Unit
|
// Vehicle to Storage Unit
|
||||||
|
|
||||||
// }
|
}
|
||||||
// } else if (fromEvent?.type === 'machine') {
|
} else if (fromEvent?.type === 'machine') {
|
||||||
// if (toEvent?.type === 'transfer') {
|
if (toEvent?.type === 'transfer') {
|
||||||
// // Machine to Transfer
|
// Machine to Transfer
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'vehicle') {
|
} else if (toEvent?.type === 'vehicle') {
|
||||||
// // Machine to Vehicle
|
// Machine to Vehicle
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'machine') {
|
} else if (toEvent?.type === 'machine') {
|
||||||
// // Machine to Machine
|
// Machine to Machine
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'roboticArm') {
|
} else if (toEvent?.type === 'roboticArm') {
|
||||||
// // Machine to Robotic Arm
|
// Machine to Robotic Arm
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'storageUnit') {
|
} else if (toEvent?.type === 'storageUnit') {
|
||||||
// // Machine to Storage Unit
|
// Machine to Storage Unit
|
||||||
|
|
||||||
// }
|
}
|
||||||
// } else if (fromEvent?.type === 'roboticArm') {
|
} else if (fromEvent?.type === 'roboticArm') {
|
||||||
// if (toEvent?.type === 'transfer') {
|
if (toEvent?.type === 'transfer') {
|
||||||
// // Robotic Arm to Transfer
|
// Robotic Arm to Transfer
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'vehicle') {
|
} else if (toEvent?.type === 'vehicle') {
|
||||||
// // Robotic Arm to Vehicle
|
// Robotic Arm to Vehicle
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'machine') {
|
} else if (toEvent?.type === 'machine') {
|
||||||
// // Robotic Arm to Machine
|
// Robotic Arm to Machine
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'roboticArm') {
|
} else if (toEvent?.type === 'roboticArm') {
|
||||||
// // Robotic Arm to Robotic Arm
|
// Robotic Arm to Robotic Arm
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'storageUnit') {
|
} else if (toEvent?.type === 'storageUnit') {
|
||||||
// // Robotic Arm to Storage Unit
|
// Robotic Arm to Storage Unit
|
||||||
|
|
||||||
// }
|
}
|
||||||
// } else if (fromEvent?.type === 'storageUnit') {
|
} else if (fromEvent?.type === 'storageUnit') {
|
||||||
// if (toEvent?.type === 'transfer') {
|
if (toEvent?.type === 'transfer') {
|
||||||
// // Storage Unit to Transfer
|
// Storage Unit to Transfer
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'vehicle') {
|
} else if (toEvent?.type === 'vehicle') {
|
||||||
// // Storage Unit to Vehicle
|
// Storage Unit to Vehicle
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'machine') {
|
} else if (toEvent?.type === 'machine') {
|
||||||
// // Storage Unit to Machine
|
// Storage Unit to Machine
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'roboticArm') {
|
} else if (toEvent?.type === 'roboticArm') {
|
||||||
// // Storage Unit to Robotic Arm
|
// Storage Unit to Robotic Arm
|
||||||
|
|
||||||
// } else if (toEvent?.type === 'storageUnit') {
|
} else if (toEvent?.type === 'storageUnit') {
|
||||||
// // Storage Unit to Storage Unit
|
// Storage Unit to Storage Unit
|
||||||
|
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const triggerPointActions = useCallback((action: Action) => {
|
const triggerPointActions = useCallback((action: Action) => {
|
||||||
|
@ -133,7 +130,7 @@ export function useTriggerHandler() {
|
||||||
case 'onStart':
|
case 'onStart':
|
||||||
break;
|
break;
|
||||||
case 'onComplete':
|
case 'onComplete':
|
||||||
handleTrigger(trigger, action.actionUuid);
|
handleTrigger(trigger, action);
|
||||||
break;
|
break;
|
||||||
case 'onStop':
|
case 'onStop':
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -12,7 +12,7 @@ interface ArmBotStore {
|
||||||
) => void;
|
) => void;
|
||||||
clearArmBots: () => void;
|
clearArmBots: () => void;
|
||||||
|
|
||||||
addCurrentAction: (modelUuid: string, actionUuid: string) => void;
|
addCurrentAction: (modelUuid: string, actionUuid: string, materialType: string) => void;
|
||||||
removeCurrentAction: (modelUuid: string) => void;
|
removeCurrentAction: (modelUuid: string) => void;
|
||||||
|
|
||||||
addAction: (modelUuid: string, action: RoboticArmPointSchema['actions'][number]) => void;
|
addAction: (modelUuid: string, action: RoboticArmPointSchema['actions'][number]) => void;
|
||||||
|
@ -75,7 +75,7 @@ export const useArmBotStore = create<ArmBotStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
addCurrentAction: (modelUuid, actionUuid) => {
|
addCurrentAction: (modelUuid, actionUuid, materialType) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
|
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
|
||||||
if (armBot) {
|
if (armBot) {
|
||||||
|
@ -84,7 +84,7 @@ export const useArmBotStore = create<ArmBotStore>()(
|
||||||
armBot.currentAction = {
|
armBot.currentAction = {
|
||||||
actionUuid: action.actionUuid,
|
actionUuid: action.actionUuid,
|
||||||
actionName: action.actionName,
|
actionName: action.actionName,
|
||||||
materialType: null
|
materialType: materialType
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,10 @@ type MaterialsStore = {
|
||||||
location?: {
|
location?: {
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
pointUuid: string;
|
pointUuid: string;
|
||||||
actionUuid: string;
|
|
||||||
} | null
|
} | null
|
||||||
) => MaterialSchema | undefined;
|
) => MaterialSchema | undefined;
|
||||||
|
|
||||||
|
setMaterial: (materialId: string, materialType: string) => MaterialSchema | undefined;
|
||||||
setStartTime: (materialId: string, startTime: string) => MaterialSchema | undefined;
|
setStartTime: (materialId: string, startTime: string) => MaterialSchema | undefined;
|
||||||
setEndTime: (materialId: string, endTime: string) => MaterialSchema | undefined;
|
setEndTime: (materialId: string, endTime: string) => MaterialSchema | undefined;
|
||||||
setCost: (materialId: string, cost: number) => MaterialSchema | undefined;
|
setCost: (materialId: string, cost: number) => MaterialSchema | undefined;
|
||||||
|
@ -37,6 +37,7 @@ type MaterialsStore = {
|
||||||
|
|
||||||
getMaterialById: (materialId: string) => MaterialSchema | undefined;
|
getMaterialById: (materialId: string) => MaterialSchema | undefined;
|
||||||
getMaterialByCurrentModelUuid: (currentModelUuid: string) => MaterialSchema | undefined;
|
getMaterialByCurrentModelUuid: (currentModelUuid: string) => MaterialSchema | undefined;
|
||||||
|
getMaterialByCurrentPointUuid: (currentPointUuid: string) => MaterialSchema | undefined;
|
||||||
getMaterialsByPoint: (pointUuid: string) => MaterialSchema[];
|
getMaterialsByPoint: (pointUuid: string) => MaterialSchema[];
|
||||||
getMaterialsByModel: (modelUuid: string) => MaterialSchema[];
|
getMaterialsByModel: (modelUuid: string) => MaterialSchema[];
|
||||||
};
|
};
|
||||||
|
@ -107,6 +108,18 @@ export const useMaterialStore = create<MaterialsStore>()(
|
||||||
return updatedMaterial;
|
return updatedMaterial;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setMaterial: (materialId, materialType) => {
|
||||||
|
let updatedMaterial: MaterialSchema | undefined;
|
||||||
|
set((state) => {
|
||||||
|
const material = state.materials.find(m => m.materialId === materialId);
|
||||||
|
if (material) {
|
||||||
|
material.materialType = materialType;
|
||||||
|
updatedMaterial = JSON.parse(JSON.stringify(material));
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return updatedMaterial;
|
||||||
|
},
|
||||||
|
|
||||||
setStartTime: (materialId, startTime) => {
|
setStartTime: (materialId, startTime) => {
|
||||||
let updatedMaterial: MaterialSchema | undefined;
|
let updatedMaterial: MaterialSchema | undefined;
|
||||||
set((state) => {
|
set((state) => {
|
||||||
|
@ -199,6 +212,10 @@ export const useMaterialStore = create<MaterialsStore>()(
|
||||||
return get().materials.find(m => m.current?.modelUuid === currentModelUuid);
|
return get().materials.find(m => m.current?.modelUuid === currentModelUuid);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getMaterialByCurrentPointUuid: (currentPointlUuid) => {
|
||||||
|
return get().materials.find(m => m.current?.pointUuid === currentPointlUuid);
|
||||||
|
},
|
||||||
|
|
||||||
getMaterialsByPoint: (pointUuid) => {
|
getMaterialsByPoint: (pointUuid) => {
|
||||||
return get().materials.filter(m =>
|
return get().materials.filter(m =>
|
||||||
m.current?.pointUuid === pointUuid ||
|
m.current?.pointUuid === pointUuid ||
|
||||||
|
|
|
@ -65,6 +65,7 @@ type ProductsStore = {
|
||||||
getEventByPointUuid: (productId: string, pointUuid: string) => EventsSchema | undefined;
|
getEventByPointUuid: (productId: string, pointUuid: string) => EventsSchema | undefined;
|
||||||
getPointByUuid: (productId: string, modelUuid: string, pointUuid: string) => ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | undefined;
|
getPointByUuid: (productId: string, modelUuid: string, pointUuid: string) => ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | undefined;
|
||||||
getActionByUuid: (productId: string, actionUuid: string) => (ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']) | undefined;
|
getActionByUuid: (productId: string, actionUuid: string) => (ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']) | undefined;
|
||||||
|
getActionByPointUuid: (productId: string, pointUuid: string) => (ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']) | undefined;
|
||||||
getModelUuidByPointUuid: (productId: string, actionUuid: string) => (string) | undefined;
|
getModelUuidByPointUuid: (productId: string, actionUuid: string) => (string) | undefined;
|
||||||
getModelUuidByActionUuid: (productId: string, actionUuid: string) => (string) | undefined;
|
getModelUuidByActionUuid: (productId: string, actionUuid: string) => (string) | undefined;
|
||||||
getPointUuidByActionUuid: (productId: string, actionUuid: string) => (string) | undefined;
|
getPointUuidByActionUuid: (productId: string, actionUuid: string) => (string) | undefined;
|
||||||
|
@ -625,6 +626,27 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
return undefined;
|
return undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getActionByPointUuid: (productId, pointUuid) => {
|
||||||
|
const product = get().products.find(p => p.productId === productId);
|
||||||
|
if (!product) return undefined;
|
||||||
|
|
||||||
|
for (const event of product.eventDatas) {
|
||||||
|
if ('points' in event) {
|
||||||
|
for (const point of (event as ConveyorEventSchema).points) {
|
||||||
|
if (point.uuid === pointUuid) {
|
||||||
|
return point.action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ('point' in event) {
|
||||||
|
const point = (event as any).point;
|
||||||
|
if (point.uuid === pointUuid) {
|
||||||
|
return point.action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
|
||||||
getModelUuidByPointUuid: (productId, pointUuid) => {
|
getModelUuidByPointUuid: (productId, pointUuid) => {
|
||||||
const product = get().products.find(p => p.productId === productId);
|
const product = get().products.find(p => p.productId === productId);
|
||||||
if (!product) return undefined;
|
if (!product) return undefined;
|
||||||
|
|
|
@ -125,7 +125,6 @@ interface StorageAction {
|
||||||
actionUuid: string;
|
actionUuid: string;
|
||||||
actionName: string;
|
actionName: string;
|
||||||
actionType: "store";
|
actionType: "store";
|
||||||
materials: { materialName: string; materialId: string; }[];
|
|
||||||
storageCapacity: number;
|
storageCapacity: number;
|
||||||
triggers: TriggerSchema[];
|
triggers: TriggerSchema[];
|
||||||
}
|
}
|
||||||
|
@ -190,6 +189,7 @@ interface StorageUnitStatus extends StorageEventSchema {
|
||||||
idleTime: number;
|
idleTime: number;
|
||||||
activeTime: number;
|
activeTime: number;
|
||||||
currentLoad: number;
|
currentLoad: number;
|
||||||
|
materials?: { materialName: string; materialId: string; }[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MaterialSchema {
|
interface MaterialSchema {
|
||||||
|
@ -213,7 +213,6 @@ interface MaterialSchema {
|
||||||
next?: {
|
next?: {
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
pointUuid: string;
|
pointUuid: string;
|
||||||
actionUuid: string;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue