v2-ui #83
|
@ -9,6 +9,7 @@ import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '..
|
|||
import { useMaterialStore } from '../../../../../store/simulation/useMaterialStore';
|
||||
import { useArmBotStore } from '../../../../../store/simulation/useArmBotStore';
|
||||
import { useProductStore } from '../../../../../store/simulation/useProductStore';
|
||||
import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore';
|
||||
import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore';
|
||||
import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler';
|
||||
|
||||
|
@ -26,9 +27,10 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
|||
let startTime: number;
|
||||
|
||||
const { setArmBotActive, setArmBotState, removeCurrentAction } = useArmBotStore();
|
||||
const { decrementVehicleLoad, removeLastMaterial } = useVehicleStore();
|
||||
const { setIsVisible, getMaterialById } = useMaterialStore();
|
||||
const { selectedProduct } = useSelectedProduct();
|
||||
const { getActionByUuid } = useProductStore();
|
||||
const { getActionByUuid, getEventByModelUuid } = useProductStore();
|
||||
const { triggerPointActions } = useTriggerHandler();
|
||||
const { isPlaying } = usePlayButtonStore();
|
||||
const { isReset } = useResetButtonStore();
|
||||
|
@ -73,8 +75,29 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
|||
logStatus(armBot.modelUuid, "picking the object");
|
||||
setPath(curve.points.map(point => [point.x, point.y, point.z]))
|
||||
|
||||
if (armBot.currentAction) {
|
||||
setIsVisible(armBot.currentAction.materialId || '', false);
|
||||
if (armBot.currentAction && armBot.currentAction.materialId) {
|
||||
const material = getMaterialById(armBot.currentAction.materialId)
|
||||
if (material && material.previous && material.previous.modelUuid) {
|
||||
|
||||
const model = getEventByModelUuid(selectedProduct.productId, material.previous.modelUuid);
|
||||
|
||||
if (model) {
|
||||
if (model.type === 'transfer') {
|
||||
setIsVisible(armBot.currentAction.materialId, false);
|
||||
} else if (model.type === 'machine') {
|
||||
|
||||
} else if (model.type === 'vehicle') {
|
||||
decrementVehicleLoad(model.modelUuid, 1);
|
||||
removeLastMaterial(model.modelUuid);
|
||||
} else if (model.type === 'storageUnit') {
|
||||
|
||||
}
|
||||
} else {
|
||||
setIsVisible(armBot.currentAction.materialId, false);
|
||||
}
|
||||
} else {
|
||||
setIsVisible(armBot.currentAction.materialId, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ export function useTriggerHandler() {
|
|||
const { getEventByTriggerUuid, getEventByModelUuid, getActionByUuid, getModelUuidByActionUuid } = useProductStore();
|
||||
const { getArmBotById } = useArmBotStore();
|
||||
const { getVehicleById } = useVehicleStore();
|
||||
const { setCurrentLocation, setNextLocation, getMaterialById, setIsPaused, setIsVisible, setEndTime } = useMaterialStore();
|
||||
const { setCurrentLocation, setNextLocation, setPreviousLocation, getMaterialById, setIsPaused, setIsVisible, setEndTime } = useMaterialStore();
|
||||
|
||||
const handleTrigger = (trigger: TriggerSchema, action: Action, materialId?: string) => {
|
||||
|
||||
|
@ -28,6 +28,12 @@ export function useTriggerHandler() {
|
|||
if (material) {
|
||||
if (material.next) {
|
||||
|
||||
setPreviousLocation(material.materialId, {
|
||||
modelUuid: material.current.modelUuid,
|
||||
pointUuid: material.current.pointUuid,
|
||||
actionUuid: material.current.actionUuid,
|
||||
})
|
||||
|
||||
setCurrentLocation(material.materialId, {
|
||||
modelUuid: material.next.modelUuid,
|
||||
pointUuid: material.next.pointUuid,
|
||||
|
@ -55,6 +61,12 @@ export function useTriggerHandler() {
|
|||
const action = getActionByUuid(selectedProduct.productId, trigger.triggeredAsset.triggeredAction.actionUuid);
|
||||
const vehicle = getVehicleById(trigger.triggeredAsset?.triggeredModel.modelUuid);
|
||||
|
||||
setPreviousLocation(material.materialId, {
|
||||
modelUuid: material.current.modelUuid,
|
||||
pointUuid: material.current.pointUuid,
|
||||
actionUuid: material.current.actionUuid,
|
||||
})
|
||||
|
||||
setCurrentLocation(material.materialId, {
|
||||
modelUuid: material.next.modelUuid,
|
||||
pointUuid: material.next.pointUuid,
|
||||
|
@ -101,6 +113,12 @@ export function useTriggerHandler() {
|
|||
const action = getActionByUuid(selectedProduct.productId, trigger.triggeredAsset.triggeredAction.actionUuid);
|
||||
const armBot = getArmBotById(trigger.triggeredAsset?.triggeredModel.modelUuid);
|
||||
|
||||
setPreviousLocation(material.materialId, {
|
||||
modelUuid: material.current.modelUuid,
|
||||
pointUuid: material.current.pointUuid,
|
||||
actionUuid: material.current.actionUuid,
|
||||
})
|
||||
|
||||
setCurrentLocation(material.materialId, {
|
||||
modelUuid: material.next.modelUuid,
|
||||
pointUuid: material.next.pointUuid,
|
||||
|
@ -142,6 +160,12 @@ export function useTriggerHandler() {
|
|||
if (material) {
|
||||
const action = getActionByUuid(selectedProduct.productId, trigger.triggeredAsset.triggeredAction.actionUuid);
|
||||
|
||||
setPreviousLocation(material.materialId, {
|
||||
modelUuid: material.current.modelUuid,
|
||||
pointUuid: material.current.pointUuid,
|
||||
actionUuid: material.current.actionUuid,
|
||||
})
|
||||
|
||||
setCurrentLocation(material.materialId, {
|
||||
modelUuid: trigger.triggeredAsset.triggeredModel.modelUuid,
|
||||
pointUuid: trigger.triggeredAsset.triggeredPoint.pointUuid,
|
||||
|
@ -179,6 +203,12 @@ export function useTriggerHandler() {
|
|||
const action = getActionByUuid(selectedProduct.productId, trigger.triggeredAsset.triggeredAction.actionUuid);
|
||||
const armBot = getArmBotById(trigger.triggeredAsset?.triggeredModel.modelUuid);
|
||||
|
||||
setPreviousLocation(material.materialId, {
|
||||
modelUuid: material.current.modelUuid,
|
||||
pointUuid: material.current.pointUuid,
|
||||
actionUuid: material.current.actionUuid,
|
||||
})
|
||||
|
||||
setCurrentLocation(material.materialId, {
|
||||
modelUuid: trigger.triggeredAsset.triggeredModel.modelUuid,
|
||||
pointUuid: trigger.triggeredAsset.triggeredPoint.pointUuid,
|
||||
|
@ -237,6 +267,12 @@ export function useTriggerHandler() {
|
|||
if (material) {
|
||||
setIsPaused(material.materialId, false);
|
||||
|
||||
setPreviousLocation(material.materialId, {
|
||||
modelUuid: material.current.modelUuid,
|
||||
pointUuid: material.current.pointUuid,
|
||||
actionUuid: material.current.actionUuid,
|
||||
})
|
||||
|
||||
setCurrentLocation(material.materialId, {
|
||||
modelUuid: trigger.triggeredAsset.triggeredModel.modelUuid,
|
||||
pointUuid: trigger.triggeredAsset.triggeredPoint.pointUuid,
|
||||
|
@ -269,6 +305,12 @@ export function useTriggerHandler() {
|
|||
const action = getActionByUuid(selectedProduct.productId, trigger.triggeredAsset.triggeredAction.actionUuid);
|
||||
const vehicle = getVehicleById(trigger.triggeredAsset?.triggeredModel.modelUuid);
|
||||
|
||||
setPreviousLocation(material.materialId, {
|
||||
modelUuid: material.current.modelUuid,
|
||||
pointUuid: material.current.pointUuid,
|
||||
actionUuid: material.current.actionUuid,
|
||||
})
|
||||
|
||||
setCurrentLocation(material.materialId, {
|
||||
modelUuid: trigger.triggeredAsset.triggeredModel.modelUuid,
|
||||
pointUuid: trigger.triggeredAsset.triggeredPoint.pointUuid,
|
||||
|
@ -344,6 +386,12 @@ export function useTriggerHandler() {
|
|||
if (material) {
|
||||
const currentTime = performance.now();
|
||||
|
||||
setPreviousLocation(material.materialId, {
|
||||
modelUuid: material.current.modelUuid,
|
||||
pointUuid: material.current.pointUuid,
|
||||
actionUuid: material.current.actionUuid,
|
||||
})
|
||||
|
||||
setCurrentLocation(material.materialId, {
|
||||
modelUuid: material.next?.modelUuid || '',
|
||||
pointUuid: material.next?.pointUuid || '',
|
||||
|
|
|
@ -10,6 +10,15 @@ type MaterialsStore = {
|
|||
clearMaterials: () => void;
|
||||
updateMaterial: (materialId: string, updates: Partial<MaterialSchema>) => MaterialSchema | undefined;
|
||||
|
||||
setPreviousLocation: (
|
||||
materialId: string,
|
||||
location: {
|
||||
modelUuid: string;
|
||||
pointUuid: string;
|
||||
actionUuid: string;
|
||||
}
|
||||
) => MaterialSchema | undefined;
|
||||
|
||||
setCurrentLocation: (
|
||||
materialId: string,
|
||||
location: {
|
||||
|
@ -93,6 +102,18 @@ export const useMaterialStore = create<MaterialsStore>()(
|
|||
return updatedMaterial;
|
||||
},
|
||||
|
||||
setPreviousLocation: (materialId, location) => {
|
||||
let updatedMaterial: MaterialSchema | undefined;
|
||||
set((state) => {
|
||||
const material = state.materials.find(m => m.materialId === materialId);
|
||||
if (material) {
|
||||
material.previous = location;
|
||||
updatedMaterial = JSON.parse(JSON.stringify(material));
|
||||
}
|
||||
});
|
||||
return updatedMaterial;
|
||||
},
|
||||
|
||||
setCurrentLocation: (materialId, location) => {
|
||||
let updatedMaterial: MaterialSchema | undefined;
|
||||
set((state) => {
|
||||
|
|
|
@ -207,6 +207,12 @@ interface MaterialSchema {
|
|||
cost?: number;
|
||||
weight?: number;
|
||||
|
||||
previous?: {
|
||||
modelUuid: string;
|
||||
pointUuid: string;
|
||||
actionUuid: string;
|
||||
};
|
||||
|
||||
current: {
|
||||
modelUuid: string;
|
||||
pointUuid: string;
|
||||
|
|
Loading…
Reference in New Issue