From 5e58606f8fbced4c6596d5119cda5c5416e70796 Mon Sep 17 00:00:00 2001 From: Jerald-Golden-B Date: Wed, 28 May 2025 16:24:08 +0530 Subject: [PATCH] Refactor store creation for Conveyor, Machine, Storage Unit, and Vehicle - Changed the store creation functions to `createConveyorStore`, `createMachineStore`, `createStorageUnitStore`, and `createVehicleStore` for better clarity and consistency. - Updated the internal state management methods to maintain functionality while improving readability. - Ensured that all stores now return their respective types for better type safety. --- .../mechanics/storageMechanics.tsx | 5 +- .../mechanics/vehicleMechanics.tsx | 34 +- .../aisle/Instances/aisleInstances.tsx | 2 +- app/src/modules/builder/aisle/aislesGroup.tsx | 1 - app/src/modules/scene/sceneContext.tsx | 28 +- .../conveyor/actionHandler/useSpawnHandler.ts | 5 +- .../actionHandler/useProcessHandler.ts | 5 +- .../actionHandler/usePickAndPlaceHandler.ts | 5 +- .../actionHandler/useRetrieveHandler.ts | 11 +- .../actionHandler/useStoreHandler.ts | 5 +- .../vehicle/actionHandler/useTravelHandler.ts | 5 +- .../analysis/throughPut/throughPutData.tsx | 17 +- .../eventManager/useConveyorEventManager.ts | 5 +- .../conveyorInstance/conveyorInstance.tsx | 5 +- .../conveyor/instances/conveyorInstances.tsx | 5 +- .../eventManager/useMachineEventManager.ts | 5 +- .../instances/animator/machineAnimator.tsx | 6 +- .../machineInstance/machineInstance.tsx | 7 +- .../machine/instances/machineInstances.tsx | 5 +- .../instances/animator/materialAnimator.tsx | 5 +- .../modules/simulation/products/products.tsx | 19 +- .../eventManager/useArmBotEventManager.ts | 5 +- .../instances/animator/roboticArmAnimator.tsx | 2 +- .../armInstance/roboticArmInstance.tsx | 15 +- .../instances/roboticArmInstances.tsx | 5 +- .../simulation/roboticArm/roboticArm.tsx | 5 +- .../checkActiveRoboticArmsInSubsequence.ts | 5 +- .../simulation/spatialUI/arm/armBotUI.tsx | 5 +- .../spatialUI/vehicle/vehicleUI.tsx | 5 +- .../instances/storageUnitInstances.tsx | 7 +- .../triggerHandler/useTriggerHandler.ts | 17 +- .../eventManager/useVehicleEventManager.ts | 5 +- .../instances/animator/vehicleAnimator.tsx | 7 +- .../instances/instance/vehicleInstance.tsx | 16 +- .../vehicle/instances/vehicleInstances.tsx | 5 +- .../modules/simulation/vehicle/vehicles.tsx | 5 +- app/src/store/simulation/useArmBotStore.ts | 310 +++++++------- app/src/store/simulation/useConveyorStore.ts | 192 ++++----- app/src/store/simulation/useMachineStore.ts | 254 ++++++------ .../store/simulation/useStorageUnitStore.ts | 310 +++++++------- app/src/store/simulation/useVehicleStore.ts | 380 +++++++++--------- 41 files changed, 884 insertions(+), 856 deletions(-) diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/storageMechanics.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/storageMechanics.tsx index 202daa7..4ea5687 100644 --- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/storageMechanics.tsx +++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/storageMechanics.tsx @@ -6,18 +6,19 @@ import StorageAction from "../actions/StorageAction"; import ActionsList from "../components/ActionsList"; import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi"; import { useProductStore } from "../../../../../../store/simulation/useProductStore"; -import { useStorageUnitStore } from "../../../../../../store/simulation/useStorageUnitStore"; import { useSelectedAction, useSelectedEventData, useSelectedProduct } from "../../../../../../store/simulation/useSimulationStore"; import * as THREE from 'three'; +import { useSceneContext } from "../../../../../../modules/scene/sceneContext"; function StorageMechanics() { + const { storageUnitStore } = useSceneContext(); const [activeOption, setActiveOption] = useState<"default" | "store" | "spawn">("default"); const [selectedPointData, setSelectedPointData] = useState(); const { selectedEventData } = useSelectedEventData(); const { getPointByUuid, updateAction } = useProductStore(); const { selectedProduct } = useSelectedProduct(); const { setSelectedAction, clearSelectedAction } = useSelectedAction(); - const { setCurrentMaterials, clearCurrentMaterials, updateCurrentLoad, getStorageUnitById } = useStorageUnitStore(); + const { setCurrentMaterials, clearCurrentMaterials, updateCurrentLoad, getStorageUnitById } = storageUnitStore(); const email = localStorage.getItem('email') const organization = (email!.split("@")[1]).split(".")[0]; diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/vehicleMechanics.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/vehicleMechanics.tsx index 2894e33..8e61dcf 100644 --- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/vehicleMechanics.tsx +++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/vehicleMechanics.tsx @@ -13,21 +13,17 @@ import { useProductStore } from "../../../../../../store/simulation/useProductSt import TravelAction from "../actions/TravelAction"; import ActionsList from "../components/ActionsList"; import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi"; -import { useVehicleStore } from "../../../../../../store/simulation/useVehicleStore"; +import { useSceneContext } from "../../../../../../modules/scene/sceneContext"; function VehicleMechanics() { - const [activeOption, setActiveOption] = useState<"default" | "travel">( - "default" - ); - const [selectedPointData, setSelectedPointData] = useState< - VehiclePointSchema | undefined - >(); + const { vehicleStore } = useSceneContext(); + const [activeOption, setActiveOption] = useState<"default" | "travel">("default"); + const [selectedPointData, setSelectedPointData] = useState(); const { selectedEventData } = useSelectedEventData(); - const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction } = - useProductStore(); + const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction } = useProductStore(); const { selectedProduct } = useSelectedProduct(); const { setSelectedAction, clearSelectedAction } = useSelectedAction(); - const { getVehicleById } = useVehicleStore(); + const { getVehicleById } = vehicleStore(); const email = localStorage.getItem("email"); const organization = email!.split("@")[1].split(".")[0]; @@ -255,7 +251,7 @@ function VehicleMechanics() { defaultValue={"0.5"} max={10} activeOption="m/s" - onClick={() => {}} + onClick={() => { }} onChange={handleSpeedChange} /> @@ -294,14 +290,14 @@ function VehicleMechanics() { onChange: handleUnloadDurationChange, }} clearPoints={handleClearPoints} - // pickPoint={{ - // value: currentPickPoint, - // onChange: handlePickPointChange, - // }} - // unloadPoint={{ - // value: currentUnloadPoint, - // onChange: handleUnloadPointChange, - // }} + // pickPoint={{ + // value: currentPickPoint, + // onChange: handlePickPointChange, + // }} + // unloadPoint={{ + // value: currentUnloadPoint, + // onChange: handleUnloadPointChange, + // }} /> )} diff --git a/app/src/modules/builder/aisle/Instances/aisleInstances.tsx b/app/src/modules/builder/aisle/Instances/aisleInstances.tsx index 1ec9308..efcbf58 100644 --- a/app/src/modules/builder/aisle/Instances/aisleInstances.tsx +++ b/app/src/modules/builder/aisle/Instances/aisleInstances.tsx @@ -6,7 +6,7 @@ function AisleInstances() { const { aisles } = useAisleStore(); useEffect(() => { - console.log('aisles: ', aisles); + // console.log('aisles: ', aisles); }, [aisles]); return ( diff --git a/app/src/modules/builder/aisle/aislesGroup.tsx b/app/src/modules/builder/aisle/aislesGroup.tsx index 6639672..f163bed 100644 --- a/app/src/modules/builder/aisle/aislesGroup.tsx +++ b/app/src/modules/builder/aisle/aislesGroup.tsx @@ -1,4 +1,3 @@ -import React from 'react' import AisleCreator from './aisleCreator/aisleCreator' import AisleInstances from './Instances/aisleInstances' diff --git a/app/src/modules/scene/sceneContext.tsx b/app/src/modules/scene/sceneContext.tsx index fe8f244..1eea293 100644 --- a/app/src/modules/scene/sceneContext.tsx +++ b/app/src/modules/scene/sceneContext.tsx @@ -1,16 +1,40 @@ import { createContext, useContext, useMemo } from 'react'; import { createMaterialStore, MaterialStoreType } from '../../store/simulation/useMaterialStore'; +import { createArmBotStore, ArmBotStoreType } from '../../store/simulation/useArmBotStore'; +import { createMachineStore, MachineStoreType } from '../../store/simulation/useMachineStore'; +import { createConveyorStore, ConveyorStoreType } from '../../store/simulation/useConveyorStore'; +import { createVehicleStore, VehicleStoreType } from '../../store/simulation/useVehicleStore'; +import { createStorageUnitStore, StorageUnitStoreType } from '../../store/simulation/useStorageUnitStore'; type SceneContextValue = { materialStore: MaterialStoreType; - // Add other stores here if needed + armBotStore: ArmBotStoreType; + machineStore: MachineStoreType; + conveyorStore: ConveyorStoreType; + vehicleStore: VehicleStoreType; + storageUnitStore: StorageUnitStoreType; }; const SceneContext = createContext(null); export function SceneProvider({ children }: { readonly children: React.ReactNode }) { const materialStore = useMemo(() => createMaterialStore(), []); - const contextValue = useMemo(() => ({ materialStore }), [materialStore]); + const armBotStore = useMemo(() => createArmBotStore(), []); + const machineStore = useMemo(() => createMachineStore(), []); + const conveyorStore = useMemo(() => createConveyorStore(), []); + const vehicleStore = useMemo(() => createVehicleStore(), []); + const storageUnitStore = useMemo(() => createStorageUnitStore(), []); + + const contextValue = useMemo(() => ( + { + materialStore, + armBotStore, + machineStore, + conveyorStore, + vehicleStore, + storageUnitStore + } + ), [materialStore, armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore]); return ( diff --git a/app/src/modules/simulation/actions/conveyor/actionHandler/useSpawnHandler.ts b/app/src/modules/simulation/actions/conveyor/actionHandler/useSpawnHandler.ts index 3b186c0..a2efcfb 100644 --- a/app/src/modules/simulation/actions/conveyor/actionHandler/useSpawnHandler.ts +++ b/app/src/modules/simulation/actions/conveyor/actionHandler/useSpawnHandler.ts @@ -4,7 +4,6 @@ import { useFrame } from "@react-three/fiber"; import { useProductStore } from "../../../../../store/simulation/useProductStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; import { usePlayButtonStore, useAnimationPlaySpeed, usePauseButtonStore, useResetButtonStore } from "../../../../../store/usePlayButtonStore"; -import { useConveyorStore } from "../../../../../store/simulation/useConveyorStore"; import { useSceneContext } from "../../../../scene/sceneContext"; interface SpawnInstance { @@ -23,9 +22,9 @@ interface SpawnInstance { } export function useSpawnHandler() { - const { materialStore } = useSceneContext(); + const { materialStore, conveyorStore } = useSceneContext(); const { addMaterial } = materialStore(); - const { getConveyorById } = useConveyorStore(); + const { getConveyorById } = conveyorStore(); const { getModelUuidByActionUuid, getPointUuidByActionUuid } = useProductStore(); const { isPlaying } = usePlayButtonStore(); const { isPaused } = usePauseButtonStore(); diff --git a/app/src/modules/simulation/actions/machine/actionHandler/useProcessHandler.ts b/app/src/modules/simulation/actions/machine/actionHandler/useProcessHandler.ts index 9f536d5..c7dc10b 100644 --- a/app/src/modules/simulation/actions/machine/actionHandler/useProcessHandler.ts +++ b/app/src/modules/simulation/actions/machine/actionHandler/useProcessHandler.ts @@ -1,13 +1,12 @@ import { useCallback } from "react"; -import { useMachineStore } from "../../../../../store/simulation/useMachineStore"; import { useProductStore } from "../../../../../store/simulation/useProductStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; import { useSceneContext } from "../../../../scene/sceneContext"; export function useProcessHandler() { - const { materialStore } = useSceneContext(); + const { materialStore, machineStore } = useSceneContext(); const { getMaterialById, setMaterial } = materialStore(); - const { addCurrentAction } = useMachineStore(); + const { addCurrentAction } = machineStore(); const { getModelUuidByActionUuid } = useProductStore(); const { selectedProduct } = useSelectedProduct(); diff --git a/app/src/modules/simulation/actions/roboticArm/actionHandler/usePickAndPlaceHandler.ts b/app/src/modules/simulation/actions/roboticArm/actionHandler/usePickAndPlaceHandler.ts index ec0cabd..9f53c80 100644 --- a/app/src/modules/simulation/actions/roboticArm/actionHandler/usePickAndPlaceHandler.ts +++ b/app/src/modules/simulation/actions/roboticArm/actionHandler/usePickAndPlaceHandler.ts @@ -1,13 +1,12 @@ import { useCallback } from "react"; -import { useArmBotStore } from "../../../../../store/simulation/useArmBotStore"; import { useProductStore } from "../../../../../store/simulation/useProductStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; import { useSceneContext } from "../../../../scene/sceneContext"; export function usePickAndPlaceHandler() { - const { materialStore } = useSceneContext(); + const { materialStore, armBotStore } = useSceneContext(); const { getMaterialById } = materialStore(); - const { addCurrentAction } = useArmBotStore(); + const { addCurrentAction } = armBotStore(); const { getModelUuidByActionUuid } = useProductStore(); const { selectedProduct } = useSelectedProduct(); diff --git a/app/src/modules/simulation/actions/storageUnit/actionHandler/useRetrieveHandler.ts b/app/src/modules/simulation/actions/storageUnit/actionHandler/useRetrieveHandler.ts index c0981b6..3f4f9a8 100644 --- a/app/src/modules/simulation/actions/storageUnit/actionHandler/useRetrieveHandler.ts +++ b/app/src/modules/simulation/actions/storageUnit/actionHandler/useRetrieveHandler.ts @@ -2,20 +2,17 @@ import { useCallback, useState, useEffect, useRef } from "react"; import { useFrame } from "@react-three/fiber"; import { useProductStore } from "../../../../../store/simulation/useProductStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; -import { useStorageUnitStore } from "../../../../../store/simulation/useStorageUnitStore"; -import { useArmBotStore } from "../../../../../store/simulation/useArmBotStore"; -import { useVehicleStore } from "../../../../../store/simulation/useVehicleStore"; import { usePlayButtonStore, usePauseButtonStore, useResetButtonStore, useAnimationPlaySpeed } from "../../../../../store/usePlayButtonStore"; import { useSceneContext } from "../../../../scene/sceneContext"; export function useRetrieveHandler() { - const { materialStore } = useSceneContext(); + const { materialStore, armBotStore, vehicleStore, storageUnitStore } = useSceneContext(); const { addMaterial } = materialStore(); const { getModelUuidByActionUuid, getPointUuidByActionUuid, getEventByModelUuid, getActionByUuid } = useProductStore(); - const { getStorageUnitById, getLastMaterial, updateCurrentLoad, removeLastMaterial } = useStorageUnitStore(); - const { getVehicleById, incrementVehicleLoad, addCurrentMaterial } = useVehicleStore(); + const { getStorageUnitById, getLastMaterial, updateCurrentLoad, removeLastMaterial } = storageUnitStore(); + const { getVehicleById, incrementVehicleLoad, addCurrentMaterial } = vehicleStore(); const { selectedProduct } = useSelectedProduct(); - const { getArmBotById, addCurrentAction } = useArmBotStore(); + const { getArmBotById, addCurrentAction } = armBotStore(); const { isPlaying } = usePlayButtonStore(); const { speed } = useAnimationPlaySpeed(); const { isPaused } = usePauseButtonStore(); diff --git a/app/src/modules/simulation/actions/storageUnit/actionHandler/useStoreHandler.ts b/app/src/modules/simulation/actions/storageUnit/actionHandler/useStoreHandler.ts index d9d356f..61e1f94 100644 --- a/app/src/modules/simulation/actions/storageUnit/actionHandler/useStoreHandler.ts +++ b/app/src/modules/simulation/actions/storageUnit/actionHandler/useStoreHandler.ts @@ -1,13 +1,12 @@ import { useCallback } from "react"; -import { useStorageUnitStore } from "../../../../../store/simulation/useStorageUnitStore"; import { useProductStore } from "../../../../../store/simulation/useProductStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; import { useSceneContext } from "../../../../scene/sceneContext"; export function useStoreHandler() { - const { materialStore } = useSceneContext(); + const { materialStore, storageUnitStore } = useSceneContext(); const { getMaterialById, removeMaterial, setEndTime } = materialStore(); - const { addCurrentMaterial, updateCurrentLoad } = useStorageUnitStore(); + const { addCurrentMaterial, updateCurrentLoad } = storageUnitStore(); const { getModelUuidByActionUuid } = useProductStore(); const { selectedProduct } = useSelectedProduct(); diff --git a/app/src/modules/simulation/actions/vehicle/actionHandler/useTravelHandler.ts b/app/src/modules/simulation/actions/vehicle/actionHandler/useTravelHandler.ts index bb96cb8..69c18b5 100644 --- a/app/src/modules/simulation/actions/vehicle/actionHandler/useTravelHandler.ts +++ b/app/src/modules/simulation/actions/vehicle/actionHandler/useTravelHandler.ts @@ -1,15 +1,14 @@ import { useCallback } from "react"; import { useProductStore } from "../../../../../store/simulation/useProductStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; -import { useVehicleStore } from "../../../../../store/simulation/useVehicleStore"; import { useSceneContext } from "../../../../scene/sceneContext"; export function useTravelHandler() { - const { materialStore } = useSceneContext(); + const { materialStore, vehicleStore } = useSceneContext(); const { getMaterialById } = materialStore(); const { getModelUuidByActionUuid } = useProductStore(); const { selectedProduct } = useSelectedProduct(); - const { incrementVehicleLoad, addCurrentMaterial } = useVehicleStore(); + const { incrementVehicleLoad, addCurrentMaterial } = vehicleStore(); const travelLogStatus = (materialUuid: string, status: string) => { echo.info(`${materialUuid}, ${status}`); diff --git a/app/src/modules/simulation/analysis/throughPut/throughPutData.tsx b/app/src/modules/simulation/analysis/throughPut/throughPutData.tsx index 84b4c35..6fde8db 100644 --- a/app/src/modules/simulation/analysis/throughPut/throughPutData.tsx +++ b/app/src/modules/simulation/analysis/throughPut/throughPutData.tsx @@ -2,24 +2,19 @@ import { useEffect } from 'react'; import { useSelectedProduct } from '../../../../store/simulation/useSimulationStore'; import { useProductStore } from '../../../../store/simulation/useProductStore'; import { determineExecutionMachineSequences } from '../../simulator/functions/determineExecutionMachineSequences'; -import { useArmBotStore } from '../../../../store/simulation/useArmBotStore'; import { useMachineCount, useMachineUptime, useMaterialCycle, useProcessBar, useThroughPutData } from '../../../../store/builder/store'; -import { useVehicleStore } from '../../../../store/simulation/useVehicleStore'; -import { useMachineStore } from '../../../../store/simulation/useMachineStore'; -import { useConveyorStore } from '../../../../store/simulation/useConveyorStore'; -import { useStorageUnitStore } from '../../../../store/simulation/useStorageUnitStore'; import { usePlayButtonStore } from '../../../../store/usePlayButtonStore'; import { useSceneContext } from '../../../scene/sceneContext'; export default function ThroughPutData() { + const { materialStore, armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore } = useSceneContext(); const { selectedProduct } = useSelectedProduct(); const { products, getProductById } = useProductStore(); - const { armBots } = useArmBotStore(); - const { vehicles } = useVehicleStore(); - const { machines } = useMachineStore(); - const { conveyors } = useConveyorStore(); - const { storageUnits } = useStorageUnitStore(); - const { materialStore } = useSceneContext(); + const { armBots } = armBotStore(); + const { vehicles } = vehicleStore(); + const { machines } = machineStore(); + const { conveyors } = conveyorStore(); + const { storageUnits } = storageUnitStore(); const { materialHistory } = materialStore(); const { machineCount, setMachineCount } = useMachineCount(); const { machineActiveTime, setMachineActiveTime } = useMachineUptime(); diff --git a/app/src/modules/simulation/conveyor/eventManager/useConveyorEventManager.ts b/app/src/modules/simulation/conveyor/eventManager/useConveyorEventManager.ts index 4870613..34407c9 100644 --- a/app/src/modules/simulation/conveyor/eventManager/useConveyorEventManager.ts +++ b/app/src/modules/simulation/conveyor/eventManager/useConveyorEventManager.ts @@ -1,7 +1,7 @@ import { useEffect, useRef } from 'react'; import { useFrame } from '@react-three/fiber'; -import { useConveyorStore } from '../../../../store/simulation/useConveyorStore'; import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore'; +import { useSceneContext } from '../../../scene/sceneContext'; type ConveyorCallback = { conveyorId: string; @@ -9,7 +9,8 @@ type ConveyorCallback = { }; export function useConveyorEventManager() { - const { getConveyorById } = useConveyorStore(); + const { conveyorStore } = useSceneContext(); + const { getConveyorById } = conveyorStore(); const callbacksRef = useRef([]); const isMonitoringRef = useRef(false); const { isPlaying } = usePlayButtonStore(); diff --git a/app/src/modules/simulation/conveyor/instances/conveyorInstance/conveyorInstance.tsx b/app/src/modules/simulation/conveyor/instances/conveyorInstance/conveyorInstance.tsx index fb17b36..69061d6 100644 --- a/app/src/modules/simulation/conveyor/instances/conveyorInstance/conveyorInstance.tsx +++ b/app/src/modules/simulation/conveyor/instances/conveyorInstance/conveyorInstance.tsx @@ -1,5 +1,4 @@ import { useEffect } from 'react' -import { useConveyorStore } from '../../../../../store/simulation/useConveyorStore'; import { useResetButtonStore } from '../../../../../store/usePlayButtonStore'; import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore'; import { useProductStore } from '../../../../../store/simulation/useProductStore'; @@ -9,10 +8,10 @@ import { useSceneContext } from '../../../../scene/sceneContext'; function ConveyorInstance({ conveyor }: { conveyor: ConveyorStatus }) { const { getProductById } = useProductStore(); const { selectedProduct } = useSelectedProduct(); - const { materialStore } = useSceneContext(); + const { materialStore, conveyorStore } = useSceneContext(); const { getMaterialsByCurrentModelUuid, materials } = materialStore(); const { isReset } = useResetButtonStore(); - const { setConveyorPaused } = useConveyorStore(); + const { setConveyorPaused } = conveyorStore(); useEffect(() => { const product = getProductById(selectedProduct.productId); diff --git a/app/src/modules/simulation/conveyor/instances/conveyorInstances.tsx b/app/src/modules/simulation/conveyor/instances/conveyorInstances.tsx index 4bc4252..75557ed 100644 --- a/app/src/modules/simulation/conveyor/instances/conveyorInstances.tsx +++ b/app/src/modules/simulation/conveyor/instances/conveyorInstances.tsx @@ -1,10 +1,11 @@ import React from 'react' import ConveyorInstance from './conveyorInstance/conveyorInstance' -import { useConveyorStore } from '../../../../store/simulation/useConveyorStore' +import { useSceneContext } from '../../../scene/sceneContext'; function ConveyorInstances() { - const { conveyors } = useConveyorStore(); + const { conveyorStore } = useSceneContext(); + const { conveyors } = conveyorStore(); return ( <> diff --git a/app/src/modules/simulation/machine/eventManager/useMachineEventManager.ts b/app/src/modules/simulation/machine/eventManager/useMachineEventManager.ts index 35c6418..66dda67 100644 --- a/app/src/modules/simulation/machine/eventManager/useMachineEventManager.ts +++ b/app/src/modules/simulation/machine/eventManager/useMachineEventManager.ts @@ -1,7 +1,7 @@ import { useEffect, useRef } from 'react'; import { useFrame } from '@react-three/fiber'; -import { useMachineStore } from '../../../../store/simulation/useMachineStore'; import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore'; +import { useSceneContext } from '../../../scene/sceneContext'; type MachineCallback = { machineId: string; @@ -9,7 +9,8 @@ type MachineCallback = { }; export function useMachineEventManager() { - const { getMachineById } = useMachineStore(); + const { machineStore } = useSceneContext(); + const { getMachineById } = machineStore(); const callbacksRef = useRef([]); const isMonitoringRef = useRef(false); const { isPlaying } = usePlayButtonStore(); diff --git a/app/src/modules/simulation/machine/instances/animator/machineAnimator.tsx b/app/src/modules/simulation/machine/instances/animator/machineAnimator.tsx index 8f1505f..d510784 100644 --- a/app/src/modules/simulation/machine/instances/animator/machineAnimator.tsx +++ b/app/src/modules/simulation/machine/instances/animator/machineAnimator.tsx @@ -1,7 +1,6 @@ import { useEffect, useRef } from 'react'; -import { useMachineStore } from '../../../../../store/simulation/useMachineStore'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore'; - +import { useSceneContext } from '../../../../scene/sceneContext'; interface MachineAnimatorProps { currentPhase: string; @@ -19,7 +18,8 @@ const MachineAnimator = ({ currentPhase, handleCallBack, processingTime, machine const animationFrameId = useRef(null); const pauseTimeRef = useRef(null); const { isPaused } = usePauseButtonStore(); - const { removeCurrentAction } = useMachineStore(); + const { machineStore } = useSceneContext(); + const { removeCurrentAction } = machineStore(); const { isReset } = useResetButtonStore(); const { isPlaying } = usePlayButtonStore(); const { speed } = useAnimationPlaySpeed(); diff --git a/app/src/modules/simulation/machine/instances/machineInstance/machineInstance.tsx b/app/src/modules/simulation/machine/instances/machineInstance/machineInstance.tsx index ae8c97f..da8ea2f 100644 --- a/app/src/modules/simulation/machine/instances/machineInstance/machineInstance.tsx +++ b/app/src/modules/simulation/machine/instances/machineInstance/machineInstance.tsx @@ -1,12 +1,12 @@ import { useEffect, useRef, useState } from 'react' -import { useMachineStore } from '../../../../../store/simulation/useMachineStore'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore'; import MachineAnimator from '../animator/machineAnimator'; import { useProductStore } from '../../../../../store/simulation/useProductStore'; import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore'; import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler'; +import { useSceneContext } from '../../../../scene/sceneContext'; -function MachineInstance({ machineDetail }: { machineDetail: MachineStatus }) { +function MachineInstance({ machineDetail }: { readonly machineDetail: MachineStatus }) { const [currentPhase, setCurrentPhase] = useState('idle'); let isIncrememtable = useRef(true); const idleTimeRef = useRef(0); @@ -16,7 +16,8 @@ function MachineInstance({ machineDetail }: { machineDetail: MachineStatus }) { const isSpeedRef = useRef(0); const isPausedRef = useRef(false); const { isPlaying } = usePlayButtonStore(); - const { machines, setMachineState, setMachineActive, incrementIdleTime, incrementActiveTime, resetTime } = useMachineStore(); + const { machineStore } = useSceneContext(); + const { machines, setMachineState, setMachineActive, incrementIdleTime, incrementActiveTime, resetTime } = machineStore(); const { selectedProduct } = useSelectedProduct(); const { getActionByUuid } = useProductStore(); const { triggerPointActions } = useTriggerHandler(); diff --git a/app/src/modules/simulation/machine/instances/machineInstances.tsx b/app/src/modules/simulation/machine/instances/machineInstances.tsx index e228b01..eac048f 100644 --- a/app/src/modules/simulation/machine/instances/machineInstances.tsx +++ b/app/src/modules/simulation/machine/instances/machineInstances.tsx @@ -1,10 +1,11 @@ import React from "react"; import MachineInstance from "./machineInstance/machineInstance"; -import { useMachineStore } from "../../../../store/simulation/useMachineStore"; import MachineContentUi from "../../ui3d/MachineContentUi"; +import { useSceneContext } from "../../../scene/sceneContext"; function MachineInstances() { - const { machines } = useMachineStore(); + const { machineStore } = useSceneContext(); + const { machines } = machineStore(); return ( <> {machines.map((machine: MachineStatus) => ( diff --git a/app/src/modules/simulation/materials/instances/animator/materialAnimator.tsx b/app/src/modules/simulation/materials/instances/animator/materialAnimator.tsx index 4afe359..5cf20c7 100644 --- a/app/src/modules/simulation/materials/instances/animator/materialAnimator.tsx +++ b/app/src/modules/simulation/materials/instances/animator/materialAnimator.tsx @@ -2,7 +2,7 @@ import React, { useEffect, useState, useRef } from 'react'; import * as THREE from 'three'; import { useFrame, useThree } from '@react-three/fiber'; import { usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore'; -import { useConveyorStore } from '../../../../../store/simulation/useConveyorStore'; +import { useSceneContext } from '../../../../scene/sceneContext'; interface MaterialAnimatorProps { matRef: React.RefObject; @@ -20,7 +20,8 @@ function MaterialAnimator({ const { scene } = useThree(); const [targetPosition, setTargetPosition] = useState(null); const [isAnimating, setIsAnimating] = useState(false); - const { getConveyorById } = useConveyorStore(); + const { conveyorStore } = useSceneContext(); + const { getConveyorById } = conveyorStore(); const animationState = useRef({ startTime: 0, startPosition: new THREE.Vector3(), diff --git a/app/src/modules/simulation/products/products.tsx b/app/src/modules/simulation/products/products.tsx index 1ea1b21..49310e2 100644 --- a/app/src/modules/simulation/products/products.tsx +++ b/app/src/modules/simulation/products/products.tsx @@ -4,21 +4,18 @@ import { useProductStore } from '../../../store/simulation/useProductStore'; import { useSelectedProduct } from '../../../store/simulation/useSimulationStore'; import { upsertProductOrEventApi } from '../../../services/simulation/products/UpsertProductOrEventApi'; import { getAllProductsApi } from '../../../services/simulation/products/getallProductsApi'; -import { useVehicleStore } from '../../../store/simulation/useVehicleStore'; -import { useArmBotStore } from '../../../store/simulation/useArmBotStore'; -import { useConveyorStore } from '../../../store/simulation/useConveyorStore'; -import { useMachineStore } from '../../../store/simulation/useMachineStore'; -import { useStorageUnitStore } from '../../../store/simulation/useStorageUnitStore'; import { usePlayButtonStore, useResetButtonStore } from '../../../store/usePlayButtonStore'; +import { useSceneContext } from '../../scene/sceneContext'; function Products() { + const { armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore } = useSceneContext(); const { products, getProductById, addProduct, setProducts } = useProductStore(); const { selectedProduct, setSelectedProduct } = useSelectedProduct(); - const { addVehicle, clearvehicles } = useVehicleStore(); - const { addArmBot, clearArmBots } = useArmBotStore(); - const { addMachine, clearMachines } = useMachineStore(); - const { addConveyor, clearConveyors } = useConveyorStore(); - const { setCurrentMaterials, clearStorageUnits, updateCurrentLoad, addStorageUnit } = useStorageUnitStore(); + const { addVehicle, clearvehicles } = vehicleStore(); + const { addArmBot, clearArmBots } = armBotStore(); + const { addMachine, clearMachines } = machineStore(); + const { addConveyor, clearConveyors } = conveyorStore(); + const { setCurrentMaterials, clearStorageUnits, updateCurrentLoad, addStorageUnit } = storageUnitStore(); const { isReset } = useResetButtonStore(); const { isPlaying } = usePlayButtonStore(); @@ -105,7 +102,7 @@ function Products() { addStorageUnit(selectedProduct.productId, event); if (event.point.action.actionType === 'retrieve') { - const storageAction = event.point.action as StorageAction; + const storageAction = event.point.action; const materials = Array.from({ length: storageAction.storageCapacity }, () => ({ materialType: storageAction.materialType || 'Default material', materialId: THREE.MathUtils.generateUUID() diff --git a/app/src/modules/simulation/roboticArm/eventManager/useArmBotEventManager.ts b/app/src/modules/simulation/roboticArm/eventManager/useArmBotEventManager.ts index 59004fa..3f07ea9 100644 --- a/app/src/modules/simulation/roboticArm/eventManager/useArmBotEventManager.ts +++ b/app/src/modules/simulation/roboticArm/eventManager/useArmBotEventManager.ts @@ -1,7 +1,7 @@ import { useEffect, useRef } from 'react'; import { useFrame } from '@react-three/fiber'; -import { useArmBotStore } from '../../../../store/simulation/useArmBotStore'; import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore'; +import { useSceneContext } from '../../../scene/sceneContext'; type ArmBotCallback = { armBotId: string; @@ -9,7 +9,8 @@ type ArmBotCallback = { }; export function useArmBotEventManager() { - const { getArmBotById } = useArmBotStore(); + const {armBotStore} = useSceneContext(); + const { getArmBotById } = armBotStore(); const callbacksRef = useRef([]); const isMonitoringRef = useRef(false); const { isPlaying } = usePlayButtonStore(); diff --git a/app/src/modules/simulation/roboticArm/instances/animator/roboticArmAnimator.tsx b/app/src/modules/simulation/roboticArm/instances/animator/roboticArmAnimator.tsx index 52213fe..1ad53de 100644 --- a/app/src/modules/simulation/roboticArm/instances/animator/roboticArmAnimator.tsx +++ b/app/src/modules/simulation/roboticArm/instances/animator/roboticArmAnimator.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo, useRef, useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { useFrame, useThree } from '@react-three/fiber'; import * as THREE from 'three'; import { Line, Text } from '@react-three/drei'; diff --git a/app/src/modules/simulation/roboticArm/instances/armInstance/roboticArmInstance.tsx b/app/src/modules/simulation/roboticArm/instances/armInstance/roboticArmInstance.tsx index ab34ec3..e0c26bc 100644 --- a/app/src/modules/simulation/roboticArm/instances/armInstance/roboticArmInstance.tsx +++ b/app/src/modules/simulation/roboticArm/instances/armInstance/roboticArmInstance.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useRef, useState } from 'react' +import { useEffect, useRef, useState } from 'react' import * as THREE from "three"; import { useThree } from "@react-three/fiber"; import IKInstance from '../ikInstance/ikInstance'; @@ -6,15 +6,12 @@ import RoboticArmAnimator from '../animator/roboticArmAnimator'; import MaterialAnimator from '../animator/materialAnimator'; import armModel from "../../../../../assets/gltf-glb/rigged/ik_arm_1.glb"; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore'; -import { useArmBotStore } from '../../../../../store/simulation/useArmBotStore'; import { useProductStore } from '../../../../../store/simulation/useProductStore'; -import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore'; -import { useStorageUnitStore } from '../../../../../store/simulation/useStorageUnitStore'; import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore'; import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler'; import { useSceneContext } from '../../../../scene/sceneContext'; -function RoboticArmInstance({ armBot }: {readonly armBot: ArmBotStatus }) { +function RoboticArmInstance({ armBot }: { readonly armBot: ArmBotStatus }) { const [currentPhase, setCurrentPhase] = useState<(string)>("init"); const [path, setPath] = useState<[number, number, number][]>([]); @@ -28,10 +25,10 @@ function RoboticArmInstance({ armBot }: {readonly armBot: ArmBotStatus }) { const isSpeedRef = useRef(null); let startTime: number; - const { setArmBotActive, setArmBotState, removeCurrentAction, incrementActiveTime, incrementIdleTime } = useArmBotStore(); - const { decrementVehicleLoad, removeLastMaterial } = useVehicleStore(); - const { removeLastMaterial: removeLastStorageMaterial, updateCurrentLoad } = useStorageUnitStore(); - const { materialStore } = useSceneContext(); + const { materialStore, armBotStore, vehicleStore, storageUnitStore } = useSceneContext(); + const { setArmBotActive, setArmBotState, removeCurrentAction, incrementActiveTime, incrementIdleTime } = armBotStore(); + const { decrementVehicleLoad, removeLastMaterial } = vehicleStore(); + const { removeLastMaterial: removeLastStorageMaterial, updateCurrentLoad } = storageUnitStore(); const { getMaterialById, setIsVisible, setIsPaused } = materialStore(); const { selectedProduct } = useSelectedProduct(); const { getActionByUuid, getEventByActionUuid, getEventByModelUuid } = useProductStore(); diff --git a/app/src/modules/simulation/roboticArm/instances/roboticArmInstances.tsx b/app/src/modules/simulation/roboticArm/instances/roboticArmInstances.tsx index f57fbcd..b1295a3 100644 --- a/app/src/modules/simulation/roboticArm/instances/roboticArmInstances.tsx +++ b/app/src/modules/simulation/roboticArm/instances/roboticArmInstances.tsx @@ -1,10 +1,11 @@ +import { useSceneContext } from "../../../scene/sceneContext"; import RoboticArmInstance from "./armInstance/roboticArmInstance"; -import { useArmBotStore } from "../../../../store/simulation/useArmBotStore"; // import RoboticArmContentUi from "../../ui3d/RoboticArmContentUi"; import React from "react"; function RoboticArmInstances() { - const { armBots } = useArmBotStore(); + const {armBotStore} = useSceneContext(); + const { armBots } = armBotStore(); return ( <> diff --git a/app/src/modules/simulation/roboticArm/roboticArm.tsx b/app/src/modules/simulation/roboticArm/roboticArm.tsx index ffdb312..1946fce 100644 --- a/app/src/modules/simulation/roboticArm/roboticArm.tsx +++ b/app/src/modules/simulation/roboticArm/roboticArm.tsx @@ -1,12 +1,13 @@ import { useEffect, useState } from "react"; -import { useArmBotStore } from "../../../store/simulation/useArmBotStore"; import { useSelectedEventSphere } from "../../../store/simulation/useSimulationStore"; import { usePlayButtonStore } from "../../../store/usePlayButtonStore"; import RoboticArmInstances from "./instances/roboticArmInstances"; import ArmBotUI from "../spatialUI/arm/armBotUI"; +import { useSceneContext } from "../../scene/sceneContext"; function RoboticArm() { - const { getArmBotById } = useArmBotStore(); + const {armBotStore} = useSceneContext(); + const { getArmBotById } = armBotStore(); const { selectedEventSphere } = useSelectedEventSphere(); const { isPlaying } = usePlayButtonStore(); const [isArmBotSelected, setIsArmBotSelected] = useState(false); diff --git a/app/src/modules/simulation/simulator/functions/checkActiveRoboticArmsInSubsequence.ts b/app/src/modules/simulation/simulator/functions/checkActiveRoboticArmsInSubsequence.ts index 797f836..bfa8bfa 100644 --- a/app/src/modules/simulation/simulator/functions/checkActiveRoboticArmsInSubsequence.ts +++ b/app/src/modules/simulation/simulator/functions/checkActiveRoboticArmsInSubsequence.ts @@ -1,5 +1,5 @@ +import { useSceneContext } from "../../../scene/sceneContext"; import { extractTriggersFromPoint } from "./extractTriggersFromPoint"; -import { useArmBotStore } from "../../../../store/simulation/useArmBotStore"; export function getRoboticArmSequencesInProduct( product: { @@ -80,7 +80,8 @@ export function findRoboticArmSubsequence( // React component/hook that uses the pure functions export function useCheckActiveRoboticArmsInSubsequence() { - const { getArmBotById } = useArmBotStore(); + const {armBotStore} = useSceneContext(); + const { getArmBotById } = armBotStore(); return function (product: { productName: string; diff --git a/app/src/modules/simulation/spatialUI/arm/armBotUI.tsx b/app/src/modules/simulation/spatialUI/arm/armBotUI.tsx index 0775157..7a835f7 100644 --- a/app/src/modules/simulation/spatialUI/arm/armBotUI.tsx +++ b/app/src/modules/simulation/spatialUI/arm/armBotUI.tsx @@ -3,7 +3,6 @@ import { useSelectedAction, useSelectedEventSphere, useSelectedProduct } from '. import { useGLTF } from '@react-three/drei'; import { useThree } from '@react-three/fiber'; import { useProductStore } from '../../../../store/simulation/useProductStore'; -import { useArmBotStore } from '../../../../store/simulation/useArmBotStore'; import PickDropPoints from './PickDropPoints'; import useDraggableGLTF from './useDraggableGLTF'; import * as THREE from 'three'; @@ -11,6 +10,7 @@ import * as THREE from 'three'; import armPick from "../../../../assets/gltf-glb/ui/arm_ui_pick.glb"; import armDrop from "../../../../assets/gltf-glb/ui/arm_ui_drop.glb"; import { upsertProductOrEventApi } from '../../../../services/simulation/products/UpsertProductOrEventApi'; +import { useSceneContext } from '../../../scene/sceneContext'; type Positions = { pick: [number, number, number]; @@ -24,7 +24,8 @@ const ArmBotUI = () => { const { selectedProduct } = useSelectedProduct(); const { scene } = useThree(); const { selectedAction } = useSelectedAction(); - const { armBots } = useArmBotStore(); + const { armBotStore } = useSceneContext(); + const { armBots } = armBotStore(); const armUiPick = useGLTF(armPick) as any; const armUiDrop = useGLTF(armDrop) as any; diff --git a/app/src/modules/simulation/spatialUI/vehicle/vehicleUI.tsx b/app/src/modules/simulation/spatialUI/vehicle/vehicleUI.tsx index db55344..c60e7e9 100644 --- a/app/src/modules/simulation/spatialUI/vehicle/vehicleUI.tsx +++ b/app/src/modules/simulation/spatialUI/vehicle/vehicleUI.tsx @@ -8,13 +8,13 @@ import { useSelectedProduct, useIsRotating, } from "../../../../store/simulation/useSimulationStore"; -import { useVehicleStore } from "../../../../store/simulation/useVehicleStore"; import { useProductStore } from "../../../../store/simulation/useProductStore"; import { upsertProductOrEventApi } from "../../../../services/simulation/products/UpsertProductOrEventApi"; import { DoubleSide, Group, Plane, Vector3 } from "three"; import startPoint from "../../../../assets/gltf-glb/ui/arrow_green.glb"; import startEnd from "../../../../assets/gltf-glb/ui/arrow_red.glb"; +import { useSceneContext } from "../../../scene/sceneContext"; const VehicleUI = () => { const { scene: startScene } = useGLTF(startPoint) as any; @@ -24,7 +24,8 @@ const VehicleUI = () => { const prevMousePos = useRef({ x: 0, y: 0 }); const { selectedEventSphere } = useSelectedEventSphere(); const { selectedProduct } = useSelectedProduct(); - const { vehicles, getVehicleById } = useVehicleStore(); + const { vehicleStore } = useSceneContext(); + const { vehicles, getVehicleById } = vehicleStore(); const { updateEvent } = useProductStore(); const [startPosition, setStartPosition] = useState<[number, number, number]>([ 0, 1, 0, diff --git a/app/src/modules/simulation/storageUnit/instances/storageUnitInstances.tsx b/app/src/modules/simulation/storageUnit/instances/storageUnitInstances.tsx index 29b6ea0..72ad0e9 100644 --- a/app/src/modules/simulation/storageUnit/instances/storageUnitInstances.tsx +++ b/app/src/modules/simulation/storageUnit/instances/storageUnitInstances.tsx @@ -1,17 +1,18 @@ import React from 'react' import StorageUnitInstance from './storageUnitInstance/storageUnitInstance' -import { useStorageUnitStore } from '../../../../store/simulation/useStorageUnitStore' import StorageContentUi from '../../ui3d/StorageContentUi'; +import { useSceneContext } from '../../../scene/sceneContext'; function StorageUnitInstances() { - const { storageUnits } = useStorageUnitStore(); + const { storageUnitStore } = useSceneContext(); + const { storageUnits } = storageUnitStore(); return ( <> {storageUnits.map((storageUnit: StorageUnitStatus) => ( - + ))} diff --git a/app/src/modules/simulation/triggers/triggerHandler/useTriggerHandler.ts b/app/src/modules/simulation/triggers/triggerHandler/useTriggerHandler.ts index c01fa0e..8ef5d1a 100644 --- a/app/src/modules/simulation/triggers/triggerHandler/useTriggerHandler.ts +++ b/app/src/modules/simulation/triggers/triggerHandler/useTriggerHandler.ts @@ -2,31 +2,26 @@ import { useCallback } from 'react'; import { useActionHandler } from '../../actions/useActionHandler'; import { useProductStore } from '../../../../store/simulation/useProductStore'; import { useSelectedProduct } from '../../../../store/simulation/useSimulationStore'; -import { useArmBotStore } from '../../../../store/simulation/useArmBotStore'; -import { useVehicleStore } from '../../../../store/simulation/useVehicleStore'; -import { useMachineStore } from '../../../../store/simulation/useMachineStore'; -import { useStorageUnitStore } from '../../../../store/simulation/useStorageUnitStore'; import { useArmBotEventManager } from '../../roboticArm/eventManager/useArmBotEventManager'; -import { useConveyorStore } from '../../../../store/simulation/useConveyorStore'; import { useConveyorEventManager } from '../../conveyor/eventManager/useConveyorEventManager'; import { useVehicleEventManager } from '../../vehicle/eventManager/useVehicleEventManager'; import { useMachineEventManager } from '../../machine/eventManager/useMachineEventManager'; import { useSceneContext } from '../../../scene/sceneContext'; export function useTriggerHandler() { + const { materialStore, armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore } = useSceneContext(); const { handleAction } = useActionHandler(); const { selectedProduct } = useSelectedProduct(); const { getEventByTriggerUuid, getEventByModelUuid, getActionByUuid, getModelUuidByActionUuid } = useProductStore(); - const { getArmBotById } = useArmBotStore(); - const { getConveyorById } = useConveyorStore(); + const { getArmBotById } = armBotStore(); + const { getConveyorById } = conveyorStore(); const { addArmBotToMonitor } = useArmBotEventManager(); const { addConveyorToMonitor } = useConveyorEventManager(); const { addVehicleToMonitor } = useVehicleEventManager(); const { addMachineToMonitor } = useMachineEventManager(); - const { getVehicleById } = useVehicleStore(); - const { getMachineById } = useMachineStore(); - const { getStorageUnitById } = useStorageUnitStore(); - const { materialStore } = useSceneContext(); + const { getVehicleById } = vehicleStore(); + const { getMachineById } = machineStore(); + const { getStorageUnitById } = storageUnitStore(); const { getMaterialById, setCurrentLocation, setNextLocation, setPreviousLocation, setIsPaused, setIsVisible, setEndTime } = materialStore(); const handleTrigger = (trigger: TriggerSchema, action: Action, materialId?: string) => { diff --git a/app/src/modules/simulation/vehicle/eventManager/useVehicleEventManager.ts b/app/src/modules/simulation/vehicle/eventManager/useVehicleEventManager.ts index 7b2bb08..625beff 100644 --- a/app/src/modules/simulation/vehicle/eventManager/useVehicleEventManager.ts +++ b/app/src/modules/simulation/vehicle/eventManager/useVehicleEventManager.ts @@ -1,7 +1,7 @@ import { useEffect, useRef } from 'react'; import { useFrame } from '@react-three/fiber'; -import { useVehicleStore } from '../../../../store/simulation/useVehicleStore'; import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore'; +import { useSceneContext } from '../../../scene/sceneContext'; type VehicleCallback = { vehicleId: string; @@ -9,7 +9,8 @@ type VehicleCallback = { }; export function useVehicleEventManager() { - const { getVehicleById } = useVehicleStore(); + const { vehicleStore } = useSceneContext(); + const { getVehicleById } = vehicleStore(); const callbacksRef = useRef([]); const isMonitoringRef = useRef(false); const { isPlaying } = usePlayButtonStore(); diff --git a/app/src/modules/simulation/vehicle/instances/animator/vehicleAnimator.tsx b/app/src/modules/simulation/vehicle/instances/animator/vehicleAnimator.tsx index 9d51a8d..64501c1 100644 --- a/app/src/modules/simulation/vehicle/instances/animator/vehicleAnimator.tsx +++ b/app/src/modules/simulation/vehicle/instances/animator/vehicleAnimator.tsx @@ -3,7 +3,7 @@ import { useFrame, useThree } from '@react-three/fiber'; import * as THREE from 'three'; import { Line } from '@react-three/drei'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore'; -import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore'; +import { useSceneContext } from '../../../../scene/sceneContext'; interface VehicleAnimatorProps { path: [number, number, number][]; @@ -15,8 +15,9 @@ interface VehicleAnimatorProps { agvDetail: VehicleStatus; } -function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetail, reset, startUnloadingProcess }: VehicleAnimatorProps) { - const { getVehicleById } = useVehicleStore(); +function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetail, reset, startUnloadingProcess }: Readonly) { + const { vehicleStore } = useSceneContext(); + const { getVehicleById } = vehicleStore(); const { isPaused } = usePauseButtonStore(); const { isPlaying } = usePlayButtonStore(); const { speed } = useAnimationPlaySpeed(); diff --git a/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx b/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx index 81a2981..b9339cc 100644 --- a/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx +++ b/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx @@ -1,13 +1,9 @@ -import React, { useCallback, useEffect, useRef, useState } from 'react'; +import { useCallback, useEffect, useRef, useState } from 'react'; import VehicleAnimator from '../animator/vehicleAnimator'; import * as THREE from 'three'; import { NavMeshQuery } from '@recast-navigation/core'; import { useNavMesh } from '../../../../../store/builder/store'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore'; -import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore'; -import { useArmBotStore } from '../../../../../store/simulation/useArmBotStore'; -import { useConveyorStore } from '../../../../../store/simulation/useConveyorStore'; -import { useStorageUnitStore } from '../../../../../store/simulation/useStorageUnitStore'; import { useProductStore } from '../../../../../store/simulation/useProductStore'; import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore'; import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler'; @@ -17,15 +13,15 @@ import { useSceneContext } from '../../../../scene/sceneContext'; function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>) { const { navMesh } = useNavMesh(); const { isPlaying } = usePlayButtonStore(); - const { materialStore } = useSceneContext(); + const { materialStore, armBotStore, conveyorStore, vehicleStore, storageUnitStore } = useSceneContext(); const { removeMaterial, setEndTime } = materialStore(); - const { getStorageUnitById } = useStorageUnitStore(); - const { getArmBotById } = useArmBotStore(); - const { getConveyorById } = useConveyorStore(); + const { getStorageUnitById } = storageUnitStore(); + const { getArmBotById } = armBotStore(); + const { getConveyorById } = conveyorStore(); const { triggerPointActions } = useTriggerHandler(); const { getActionByUuid, getEventByModelUuid, getTriggerByUuid } = useProductStore(); const { selectedProduct } = useSelectedProduct(); - const { vehicles, setVehicleActive, setVehicleState, setVehiclePicking, clearCurrentMaterials, setVehicleLoad, decrementVehicleLoad, removeLastMaterial, getLastMaterial, incrementIdleTime, incrementActiveTime, resetTime } = useVehicleStore(); + const { vehicles, setVehicleActive, setVehicleState, setVehiclePicking, clearCurrentMaterials, setVehicleLoad, decrementVehicleLoad, removeLastMaterial, getLastMaterial, incrementIdleTime, incrementActiveTime, resetTime } = vehicleStore(); const [currentPhase, setCurrentPhase] = useState('stationed'); const [path, setPath] = useState<[number, number, number][]>([]); diff --git a/app/src/modules/simulation/vehicle/instances/vehicleInstances.tsx b/app/src/modules/simulation/vehicle/instances/vehicleInstances.tsx index 1c7cd51..708a4e1 100644 --- a/app/src/modules/simulation/vehicle/instances/vehicleInstances.tsx +++ b/app/src/modules/simulation/vehicle/instances/vehicleInstances.tsx @@ -1,10 +1,11 @@ import React from "react"; import VehicleInstance from "./instance/vehicleInstance"; -import { useVehicleStore } from "../../../../store/simulation/useVehicleStore"; import VehicleContentUi from "../../ui3d/VehicleContentUi"; +import { useSceneContext } from "../../../scene/sceneContext"; function VehicleInstances() { - const { vehicles } = useVehicleStore(); + const { vehicleStore } = useSceneContext(); + const { vehicles } = vehicleStore(); return ( <> diff --git a/app/src/modules/simulation/vehicle/vehicles.tsx b/app/src/modules/simulation/vehicle/vehicles.tsx index b9293cd..9e594a5 100644 --- a/app/src/modules/simulation/vehicle/vehicles.tsx +++ b/app/src/modules/simulation/vehicle/vehicles.tsx @@ -1,12 +1,13 @@ import { useEffect, useState } from "react"; -import { useVehicleStore } from "../../../store/simulation/useVehicleStore"; import { useSelectedEventSphere } from "../../../store/simulation/useSimulationStore"; import { usePlayButtonStore } from "../../../store/usePlayButtonStore"; import VehicleInstances from "./instances/vehicleInstances"; import VehicleUI from "../spatialUI/vehicle/vehicleUI"; +import { useSceneContext } from "../../scene/sceneContext"; function Vehicles() { - const { getVehicleById } = useVehicleStore(); + const { vehicleStore } = useSceneContext(); + const { getVehicleById } = vehicleStore(); const { selectedEventSphere } = useSelectedEventSphere(); const { isPlaying } = usePlayButtonStore(); const [isVehicleSelected, setIsVehicleSelected] = useState(false); diff --git a/app/src/store/simulation/useArmBotStore.ts b/app/src/store/simulation/useArmBotStore.ts index 7c4d38b..e05ee2b 100644 --- a/app/src/store/simulation/useArmBotStore.ts +++ b/app/src/store/simulation/useArmBotStore.ts @@ -34,173 +34,177 @@ interface ArmBotStore { getArmBotsByCurrentAction: (actionUuid: string) => ArmBotStatus[]; } -export const useArmBotStore = create()( - immer((set, get) => ({ - armBots: [], +export const createArmBotStore = () => { + return create()( + immer((set, get) => ({ + armBots: [], - addArmBot: (productId, event) => { - set((state) => { - const exists = state.armBots.some(a => a.modelUuid === event.modelUuid); - if (!exists) { - state.armBots.push({ - ...event, - productId, - isActive: false, - idleTime: 0, - activeTime: 0, - state: 'idle', - }); - } - }); - }, - - removeArmBot: (modelUuid) => { - set((state) => { - state.armBots = state.armBots.filter(a => a.modelUuid !== modelUuid); - }); - }, - - updateArmBot: (modelUuid, updates) => { - set((state) => { - const armBot = state.armBots.find(a => a.modelUuid === modelUuid); - if (armBot) { - Object.assign(armBot, updates); - } - }); - }, - - clearArmBots: () => { - set((state) => { - state.armBots = []; - }); - }, - - addCurrentAction: (modelUuid, actionUuid, materialType, materialId) => { - set((state) => { - const armBot = state.armBots.find(a => a.modelUuid === modelUuid); - if (armBot) { - const action = armBot.point.actions.find(a => a.actionUuid === actionUuid); - if (action) { - armBot.currentAction = { - actionUuid: action.actionUuid, - actionName: action.actionName, - materialType: materialType, - materialId: materialId - }; + addArmBot: (productId, event) => { + set((state) => { + const exists = state.armBots.some(a => a.modelUuid === event.modelUuid); + if (!exists) { + state.armBots.push({ + ...event, + productId, + isActive: false, + idleTime: 0, + activeTime: 0, + state: 'idle', + }); } - } - }); - }, + }); + }, - removeCurrentAction: (modelUuid) => { - set((state) => { - const armBot = state.armBots.find(a => a.modelUuid === modelUuid); - if (armBot) { - armBot.currentAction = undefined; - } - }); - }, + removeArmBot: (modelUuid) => { + set((state) => { + state.armBots = state.armBots.filter(a => a.modelUuid !== modelUuid); + }); + }, - addAction: (modelUuid, action) => { - set((state) => { - const armBot = state.armBots.find(a => a.modelUuid === modelUuid); - if (armBot) { - armBot.point.actions.push(action); - } - }); - }, - - removeAction: (modelUuid, actionUuid) => { - set((state) => { - const armBot = state.armBots.find(a => a.modelUuid === modelUuid); - if (armBot) { - armBot.point.actions = armBot.point.actions.filter(a => a.actionUuid !== actionUuid); - } - }); - }, - - updateStartPoint: (modelUuid, actionUuid, startPoint) => { - set((state) => { - const armBot = state.armBots.find(a => a.modelUuid === modelUuid); - if (armBot) { - const action = armBot.point.actions.find(a => a.actionUuid === actionUuid); - if (action) { - action.process.startPoint = startPoint; + updateArmBot: (modelUuid, updates) => { + set((state) => { + const armBot = state.armBots.find(a => a.modelUuid === modelUuid); + if (armBot) { + Object.assign(armBot, updates); } - } - }); - }, + }); + }, - updateEndPoint: (modelUuid, actionUuid, endPoint) => { - set((state) => { - const armBot = state.armBots.find(a => a.modelUuid === modelUuid); - if (armBot) { - const action = armBot.point.actions.find(a => a.actionUuid === actionUuid); - if (action) { - action.process.endPoint = endPoint; + clearArmBots: () => { + set((state) => { + state.armBots = []; + }); + }, + + addCurrentAction: (modelUuid, actionUuid, materialType, materialId) => { + set((state) => { + const armBot = state.armBots.find(a => a.modelUuid === modelUuid); + if (armBot) { + const action = armBot.point.actions.find(a => a.actionUuid === actionUuid); + if (action) { + armBot.currentAction = { + actionUuid: action.actionUuid, + actionName: action.actionName, + materialType: materialType, + materialId: materialId + }; + } } - } - }); - }, + }); + }, - setArmBotActive: (modelUuid, isActive) => { - set((state) => { - const armBot = state.armBots.find(a => a.modelUuid === modelUuid); - if (armBot) { - armBot.isActive = isActive; - } - }); - }, + removeCurrentAction: (modelUuid) => { + set((state) => { + const armBot = state.armBots.find(a => a.modelUuid === modelUuid); + if (armBot) { + armBot.currentAction = undefined; + } + }); + }, - setArmBotState: (modelUuid, newState) => { - set((state) => { - const armBot = state.armBots.find(a => a.modelUuid === modelUuid); - if (armBot) { - armBot.state = newState; - } - }); - }, + addAction: (modelUuid, action) => { + set((state) => { + const armBot = state.armBots.find(a => a.modelUuid === modelUuid); + if (armBot) { + armBot.point.actions.push(action); + } + }); + }, - incrementActiveTime: (modelUuid, incrementBy) => { - set((state) => { - const armBot = state.armBots.find(a => a.modelUuid === modelUuid); - if (armBot) { - armBot.activeTime += incrementBy; - } - }); - }, + removeAction: (modelUuid, actionUuid) => { + set((state) => { + const armBot = state.armBots.find(a => a.modelUuid === modelUuid); + if (armBot) { + armBot.point.actions = armBot.point.actions.filter(a => a.actionUuid !== actionUuid); + } + }); + }, - incrementIdleTime: (modelUuid, incrementBy) => { - set((state) => { - const armBot = state.armBots.find(a => a.modelUuid === modelUuid); - if (armBot) { - armBot.idleTime += incrementBy; - } - }); - }, + updateStartPoint: (modelUuid, actionUuid, startPoint) => { + set((state) => { + const armBot = state.armBots.find(a => a.modelUuid === modelUuid); + if (armBot) { + const action = armBot.point.actions.find(a => a.actionUuid === actionUuid); + if (action) { + action.process.startPoint = startPoint; + } + } + }); + }, - getArmBotById: (modelUuid) => { - return get().armBots.find(a => a.modelUuid === modelUuid); - }, + updateEndPoint: (modelUuid, actionUuid, endPoint) => { + set((state) => { + const armBot = state.armBots.find(a => a.modelUuid === modelUuid); + if (armBot) { + const action = armBot.point.actions.find(a => a.actionUuid === actionUuid); + if (action) { + action.process.endPoint = endPoint; + } + } + }); + }, - getArmBotsByProduct: (productId) => { - return get().armBots.filter(a => a.productId === productId); - }, + setArmBotActive: (modelUuid, isActive) => { + set((state) => { + const armBot = state.armBots.find(a => a.modelUuid === modelUuid); + if (armBot) { + armBot.isActive = isActive; + } + }); + }, - getArmBotsByState: (state) => { - return get().armBots.filter(a => a.state === state); - }, + setArmBotState: (modelUuid, newState) => { + set((state) => { + const armBot = state.armBots.find(a => a.modelUuid === modelUuid); + if (armBot) { + armBot.state = newState; + } + }); + }, - getActiveArmBots: () => { - return get().armBots.filter(a => a.isActive); - }, + incrementActiveTime: (modelUuid, incrementBy) => { + set((state) => { + const armBot = state.armBots.find(a => a.modelUuid === modelUuid); + if (armBot) { + armBot.activeTime += incrementBy; + } + }); + }, - getIdleArmBots: () => { - return get().armBots.filter(a => !a.isActive && a.state === 'idle'); - }, + incrementIdleTime: (modelUuid, incrementBy) => { + set((state) => { + const armBot = state.armBots.find(a => a.modelUuid === modelUuid); + if (armBot) { + armBot.idleTime += incrementBy; + } + }); + }, - getArmBotsByCurrentAction: (actionUuid) => { - return get().armBots.filter(a => a.currentAction?.actionUuid === actionUuid); - } - })) -); + getArmBotById: (modelUuid) => { + return get().armBots.find(a => a.modelUuid === modelUuid); + }, + + getArmBotsByProduct: (productId) => { + return get().armBots.filter(a => a.productId === productId); + }, + + getArmBotsByState: (state) => { + return get().armBots.filter(a => a.state === state); + }, + + getActiveArmBots: () => { + return get().armBots.filter(a => a.isActive); + }, + + getIdleArmBots: () => { + return get().armBots.filter(a => !a.isActive && a.state === 'idle'); + }, + + getArmBotsByCurrentAction: (actionUuid) => { + return get().armBots.filter(a => a.currentAction?.actionUuid === actionUuid); + } + })) + ) +} + +export type ArmBotStoreType = ReturnType; \ No newline at end of file diff --git a/app/src/store/simulation/useConveyorStore.ts b/app/src/store/simulation/useConveyorStore.ts index 6d920eb..40dfab4 100644 --- a/app/src/store/simulation/useConveyorStore.ts +++ b/app/src/store/simulation/useConveyorStore.ts @@ -26,111 +26,115 @@ interface ConveyorStore { getIdleConveyors: () => ConveyorStatus[]; } -export const useConveyorStore = create()( - immer((set, get) => ({ - conveyors: [], +export const createConveyorStore = () => { + return create()( + immer((set, get) => ({ + conveyors: [], - addConveyor: (productId, event) => { - set((state) => { - const exists = state.conveyors.some(c => c.modelUuid === event.modelUuid); - if (!exists) { - state.conveyors.push({ - ...event, - productId, - isActive: false, - isPaused: false, - idleTime: 0, - activeTime: 0, - state: 'idle', - }); - } - }); - }, + addConveyor: (productId, event) => { + set((state) => { + const exists = state.conveyors.some(c => c.modelUuid === event.modelUuid); + if (!exists) { + state.conveyors.push({ + ...event, + productId, + isActive: false, + isPaused: false, + idleTime: 0, + activeTime: 0, + state: 'idle', + }); + } + }); + }, - removeConveyor: (modelUuid) => { - set((state) => { - state.conveyors = state.conveyors.filter(c => c.modelUuid !== modelUuid); - }); - }, + removeConveyor: (modelUuid) => { + set((state) => { + state.conveyors = state.conveyors.filter(c => c.modelUuid !== modelUuid); + }); + }, - updateConveyor: (modelUuid, updates) => { - set((state) => { - const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); - if (conveyor) { - Object.assign(conveyor, updates); - } - }); - }, + updateConveyor: (modelUuid, updates) => { + set((state) => { + const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); + if (conveyor) { + Object.assign(conveyor, updates); + } + }); + }, - clearConveyors: () => { - set((state) => { - state.conveyors = []; - }); - }, + clearConveyors: () => { + set((state) => { + state.conveyors = []; + }); + }, - setConveyorActive: (modelUuid, isActive) => { - set((state) => { - const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); - if (conveyor) { - conveyor.isActive = isActive; - } - }); - }, + setConveyorActive: (modelUuid, isActive) => { + set((state) => { + const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); + if (conveyor) { + conveyor.isActive = isActive; + } + }); + }, - setConveyorState: (modelUuid, newState) => { - set((state) => { - const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); - if (conveyor) { - conveyor.state = newState; - } - }); - }, + setConveyorState: (modelUuid, newState) => { + set((state) => { + const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); + if (conveyor) { + conveyor.state = newState; + } + }); + }, - setConveyorPaused: (modelUuid, isPaused) => { - set((state) => { - const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); - if (conveyor) { - conveyor.isPaused = isPaused; - } - }); - }, + setConveyorPaused: (modelUuid, isPaused) => { + set((state) => { + const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); + if (conveyor) { + conveyor.isPaused = isPaused; + } + }); + }, - incrementActiveTime: (modelUuid, incrementBy) => { - set((state) => { - const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); - if (conveyor) { - conveyor.activeTime += incrementBy; - } - }); - }, + incrementActiveTime: (modelUuid, incrementBy) => { + set((state) => { + const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); + if (conveyor) { + conveyor.activeTime += incrementBy; + } + }); + }, - incrementIdleTime: (modelUuid, incrementBy) => { - set((state) => { - const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); - if (conveyor) { - conveyor.idleTime += incrementBy; - } - }); - }, + incrementIdleTime: (modelUuid, incrementBy) => { + set((state) => { + const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); + if (conveyor) { + conveyor.idleTime += incrementBy; + } + }); + }, - getConveyorById: (modelUuid) => { - return get().conveyors.find(c => c.modelUuid === modelUuid); - }, + getConveyorById: (modelUuid) => { + return get().conveyors.find(c => c.modelUuid === modelUuid); + }, - getConveyorsByProduct: (productId) => { - return get().conveyors.filter(c => c.productId === productId); - }, + getConveyorsByProduct: (productId) => { + return get().conveyors.filter(c => c.productId === productId); + }, - getConveyorsByState: (state) => { - return get().conveyors.filter(c => c.state === state); - }, + getConveyorsByState: (state) => { + return get().conveyors.filter(c => c.state === state); + }, - getActiveConveyors: () => { - return get().conveyors.filter(c => c.isActive); - }, + getActiveConveyors: () => { + return get().conveyors.filter(c => c.isActive); + }, - getIdleConveyors: () => { - return get().conveyors.filter(c => !c.isActive && c.state === 'idle'); - }, - })) -); + getIdleConveyors: () => { + return get().conveyors.filter(c => !c.isActive && c.state === 'idle'); + }, + })) + ) +} + +export type ConveyorStoreType = ReturnType; \ No newline at end of file diff --git a/app/src/store/simulation/useMachineStore.ts b/app/src/store/simulation/useMachineStore.ts index df480e0..8fb5b06 100644 --- a/app/src/store/simulation/useMachineStore.ts +++ b/app/src/store/simulation/useMachineStore.ts @@ -37,140 +37,144 @@ interface MachineStore { getIdleMachines: () => MachineStatus[]; } -export const useMachineStore = create()( - immer((set, get) => ({ - machines: [], +export const createMachineStore = () => { + return create()( + 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, - }; + 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", + }); } - } - }); - }, + }); + }, - removeCurrentAction: (modelUuid) => { - set((state) => { - const armBot = state.machines.find((a) => a.modelUuid === modelUuid); - if (armBot) { - armBot.currentAction = undefined; - } - }); - }, + removeMachine: (modelUuid) => { + set((state) => { + state.machines = state.machines.filter( + (m) => m.modelUuid !== modelUuid + ); + }); + }, - setMachineActive: (modelUuid, isActive) => { - set((state) => { - const machine = state.machines.find((m) => m.modelUuid === modelUuid); - if (machine) { - machine.isActive = isActive; - } - }); - }, + updateMachine: (modelUuid, updates) => { + set((state) => { + const machine = state.machines.find((m) => m.modelUuid === modelUuid); + if (machine) { + Object.assign(machine, updates); + } + }); + }, - setMachineState: (modelUuid, newState) => { - set((state) => { - const machine = state.machines.find((m) => m.modelUuid === modelUuid); - if (machine) { - machine.state = newState; - } - }); - }, + clearMachines: () => { + set((state) => { + state.machines = []; + }); + }, - incrementActiveTime: (modelUuid, incrementBy) => { - set((state) => { - const machine = state.machines.find((m) => m.modelUuid === modelUuid); - if (machine) { - machine.activeTime += incrementBy; - } - }); - }, + 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, + }; + } + } + }); + }, - 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; - } - }); - }, + removeCurrentAction: (modelUuid) => { + set((state) => { + const armBot = state.machines.find((a) => a.modelUuid === modelUuid); + if (armBot) { + armBot.currentAction = undefined; + } + }); + }, - getMachineById: (modelUuid) => { - return get().machines.find((m) => m.modelUuid === modelUuid); - }, + setMachineActive: (modelUuid, isActive) => { + set((state) => { + const machine = state.machines.find((m) => m.modelUuid === modelUuid); + if (machine) { + machine.isActive = isActive; + } + }); + }, - getMachinesByProduct: (productId) => { - return get().machines.filter((m) => m.productId === productId); - }, + setMachineState: (modelUuid, newState) => { + set((state) => { + const machine = state.machines.find((m) => m.modelUuid === modelUuid); + if (machine) { + machine.state = newState; + } + }); + }, - getMachinesBystate: (state) => { - return get().machines.filter((m) => m.state === state); - }, + incrementActiveTime: (modelUuid, incrementBy) => { + set((state) => { + const machine = state.machines.find((m) => m.modelUuid === modelUuid); + if (machine) { + machine.activeTime += incrementBy; + } + }); + }, - getActiveMachines: () => { - return get().machines.filter((m) => m.isActive); - }, + 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; + } + }); + }, - getIdleMachines: () => { - return get().machines.filter((m) => !m.isActive && m.state === "idle"); - }, - })) -); + 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"); + }, + })) + ) +} + +export type MachineStoreType = ReturnType; diff --git a/app/src/store/simulation/useStorageUnitStore.ts b/app/src/store/simulation/useStorageUnitStore.ts index 171f674..a71af3b 100644 --- a/app/src/store/simulation/useStorageUnitStore.ts +++ b/app/src/store/simulation/useStorageUnitStore.ts @@ -35,181 +35,185 @@ interface StorageUnitStore { getEmptyStorageUnits: () => StorageUnitStatus[]; } -export const useStorageUnitStore = create()( - immer((set, get) => ({ - storageUnits: [], +export const createStorageUnitStore = () => { + return create()( + immer((set, get) => ({ + storageUnits: [], - addStorageUnit: (productId, storageUnit) => { - set((state) => { - const exists = state.storageUnits.some(s => s.modelUuid === storageUnit.modelUuid); - if (!exists) { - state.storageUnits.push({ - ...storageUnit, - productId, - isActive: false, - idleTime: 0, - activeTime: 0, - currentLoad: 0, - currentMaterials: [], - state: 'idle' - }); - } - }); - }, + addStorageUnit: (productId, storageUnit) => { + set((state) => { + const exists = state.storageUnits.some(s => s.modelUuid === storageUnit.modelUuid); + if (!exists) { + state.storageUnits.push({ + ...storageUnit, + productId, + isActive: false, + idleTime: 0, + activeTime: 0, + currentLoad: 0, + currentMaterials: [], + state: 'idle' + }); + } + }); + }, - removeStorageUnit: (modelUuid) => { - set((state) => { - state.storageUnits = state.storageUnits.filter(s => s.modelUuid !== modelUuid); - }); - }, + removeStorageUnit: (modelUuid) => { + set((state) => { + state.storageUnits = state.storageUnits.filter(s => s.modelUuid !== modelUuid); + }); + }, - updateStorageUnit: (modelUuid, updates) => { - set((state) => { - const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); - if (unit) { - Object.assign(unit, updates); - } - }); - }, + updateStorageUnit: (modelUuid, updates) => { + set((state) => { + const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); + if (unit) { + Object.assign(unit, updates); + } + }); + }, - clearStorageUnits: () => { - set(() => ({ - storageUnits: [], - })); - }, + clearStorageUnits: () => { + set(() => ({ + storageUnits: [], + })); + }, - setStorageUnitActive: (modelUuid, isActive) => { - set((state) => { - const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); - if (unit) { - unit.isActive = isActive; - } - }); - }, + setStorageUnitActive: (modelUuid, isActive) => { + set((state) => { + const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); + if (unit) { + unit.isActive = isActive; + } + }); + }, - setStorageUnitState: (modelUuid, newState) => { - set((state) => { - const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); - if (unit) { - unit.state = newState; - } - }); - }, + setStorageUnitState: (modelUuid, newState) => { + set((state) => { + const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); + if (unit) { + unit.state = newState; + } + }); + }, - updateCurrentLoad: (modelUuid, incrementBy) => { - set((state) => { - const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); - if (unit) { - unit.currentLoad += incrementBy; - } - }); - }, + updateCurrentLoad: (modelUuid, incrementBy) => { + set((state) => { + const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); + if (unit) { + unit.currentLoad += incrementBy; + } + }); + }, - incrementActiveTime: (modelUuid, incrementBy) => { - set((state) => { - const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); - if (unit) { - unit.activeTime += incrementBy; - } - }); - }, + incrementActiveTime: (modelUuid, incrementBy) => { + set((state) => { + const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); + if (unit) { + unit.activeTime += incrementBy; + } + }); + }, - incrementIdleTime: (modelUuid, incrementBy) => { - set((state) => { - const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); - if (unit) { - unit.idleTime += incrementBy; - } - }); - }, + incrementIdleTime: (modelUuid, incrementBy) => { + set((state) => { + const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); + if (unit) { + unit.idleTime += incrementBy; + } + }); + }, - addCurrentMaterial: (modelUuid, materialType, materialId) => { - set((state) => { - const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); - if (storage) { - storage.currentMaterials.push({ materialType, materialId }); - } - }); - }, + addCurrentMaterial: (modelUuid, materialType, materialId) => { + set((state) => { + const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); + if (storage) { + storage.currentMaterials.push({ materialType, materialId }); + } + }); + }, - setCurrentMaterials: (modelUuid, materials) => { - set((state) => { - const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); - if (storage) { - storage.currentMaterials = materials; - } - }); - }, + setCurrentMaterials: (modelUuid, materials) => { + set((state) => { + const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); + if (storage) { + storage.currentMaterials = materials; + } + }); + }, - getLastMaterial: (modelUuid) => { - let removedMaterial: { materialId: string; materialType: string; } | undefined; - set((state) => { - const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); - if (storage) { - if (storage.currentMaterials.length > 0) { - const material = storage.currentMaterials[storage.currentMaterials.length - 1]; - if (material) { - removedMaterial = { materialId: material.materialId, materialType: material.materialType }; + getLastMaterial: (modelUuid) => { + let removedMaterial: { materialId: string; materialType: string; } | undefined; + set((state) => { + const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); + if (storage) { + if (storage.currentMaterials.length > 0) { + const material = storage.currentMaterials[storage.currentMaterials.length - 1]; + if (material) { + removedMaterial = { materialId: material.materialId, materialType: material.materialType }; + } } } - } - }); - return removedMaterial; - }, + }); + return removedMaterial; + }, - removeLastMaterial: (modelUuid) => { - let removedMaterial: { materialId: string; materialType: string; } | undefined; - set((state) => { - const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); - if (storage) { - if (storage.currentMaterials.length > 0) { - const material = storage.currentMaterials.pop(); - if (material) { - removedMaterial = { materialId: material.materialId, materialType: material.materialType }; + removeLastMaterial: (modelUuid) => { + let removedMaterial: { materialId: string; materialType: string; } | undefined; + set((state) => { + const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); + if (storage) { + if (storage.currentMaterials.length > 0) { + const material = storage.currentMaterials.pop(); + if (material) { + removedMaterial = { materialId: material.materialId, materialType: material.materialType }; + } } } - } - }); - return removedMaterial; - }, + }); + return removedMaterial; + }, - clearCurrentMaterials: (modelUuid) => { - set((state) => { - const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); - if (storage) { - storage.currentMaterials = []; - } - }); - }, + clearCurrentMaterials: (modelUuid) => { + set((state) => { + const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); + if (storage) { + storage.currentMaterials = []; + } + }); + }, - getStorageUnitById: (modelUuid) => { - return get().storageUnits.find(s => s.modelUuid === modelUuid); - }, + getStorageUnitById: (modelUuid) => { + return get().storageUnits.find(s => s.modelUuid === modelUuid); + }, - getStorageUnitsByProduct: (productId) => { - return get().storageUnits.filter(s => s.productId === productId); - }, + getStorageUnitsByProduct: (productId) => { + return get().storageUnits.filter(s => s.productId === productId); + }, - getStorageUnitsBystate: (state) => { - return get().storageUnits.filter(s => s.state === state); - }, + getStorageUnitsBystate: (state) => { + return get().storageUnits.filter(s => s.state === state); + }, - getActiveStorageUnits: () => { - return get().storageUnits.filter(s => s.isActive); - }, + getActiveStorageUnits: () => { + return get().storageUnits.filter(s => s.isActive); + }, - getIdleStorageUnits: () => { - return get().storageUnits.filter(s => !s.isActive && s.state === 'idle'); - }, + getIdleStorageUnits: () => { + return get().storageUnits.filter(s => !s.isActive && s.state === 'idle'); + }, - getFullStorageUnits: () => { - return get().storageUnits.filter( - s => s.currentLoad >= s.point.action.storageCapacity - ); - }, + getFullStorageUnits: () => { + return get().storageUnits.filter( + s => s.currentLoad >= s.point.action.storageCapacity + ); + }, - getEmptyStorageUnits: () => { - return get().storageUnits.filter(s => s.currentLoad === 0); - }, - })) -); + getEmptyStorageUnits: () => { + return get().storageUnits.filter(s => s.currentLoad === 0); + }, + })) + ) +} + +export type StorageUnitStoreType = ReturnType; \ No newline at end of file diff --git a/app/src/store/simulation/useVehicleStore.ts b/app/src/store/simulation/useVehicleStore.ts index d1ce04f..c41bb7c 100644 --- a/app/src/store/simulation/useVehicleStore.ts +++ b/app/src/store/simulation/useVehicleStore.ts @@ -37,217 +37,221 @@ interface VehiclesStore { getActiveVehicles: () => VehicleStatus[]; } -export const useVehicleStore = create()( - immer((set, get) => ({ - vehicles: [], +export const createVehicleStore = () => { + return create()( + immer((set, get) => ({ + vehicles: [], - addVehicle: (productId, event) => { - set((state) => { - const exists = state.vehicles.some((v) => v.modelUuid === event.modelUuid); - if (!exists) { - state.vehicles.push({ - ...event, - productId, - isActive: false, - isPicking: false, - idleTime: 0, - activeTime: 0, - currentLoad: 0, - currentMaterials: [], - distanceTraveled: 0, - state: 'idle' - }); - } - }); - }, + addVehicle: (productId, event) => { + set((state) => { + const exists = state.vehicles.some((v) => v.modelUuid === event.modelUuid); + if (!exists) { + state.vehicles.push({ + ...event, + productId, + isActive: false, + isPicking: false, + idleTime: 0, + activeTime: 0, + currentLoad: 0, + currentMaterials: [], + distanceTraveled: 0, + state: 'idle' + }); + } + }); + }, - removeVehicle: (modelUuid) => { - set((state) => { - state.vehicles = state.vehicles.filter( - (v) => v.modelUuid !== modelUuid - ); - }); - }, + removeVehicle: (modelUuid) => { + set((state) => { + state.vehicles = state.vehicles.filter( + (v) => v.modelUuid !== modelUuid + ); + }); + }, - updateVehicle: (modelUuid, updates) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - Object.assign(vehicle, updates); - } - }); - }, + updateVehicle: (modelUuid, updates) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + Object.assign(vehicle, updates); + } + }); + }, - clearvehicles: () => { - set((state) => { - state.vehicles = []; - }); - }, + clearvehicles: () => { + set((state) => { + state.vehicles = []; + }); + }, - setVehicleActive: (modelUuid, isActive) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.isActive = isActive; - } - }); - }, + setVehicleActive: (modelUuid, isActive) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.isActive = isActive; + } + }); + }, - setVehiclePicking: (modelUuid, isPicking) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.isPicking = isPicking; - } - }); - }, + setVehiclePicking: (modelUuid, isPicking) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.isPicking = isPicking; + } + }); + }, - updateSteeringAngle: (modelUuid, steeringAngle) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.point.action.steeringAngle = steeringAngle; - } - }); - }, + updateSteeringAngle: (modelUuid, steeringAngle) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.point.action.steeringAngle = steeringAngle; + } + }); + }, - incrementVehicleLoad: (modelUuid, incrementBy) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.currentLoad += incrementBy; - } - }); - }, + incrementVehicleLoad: (modelUuid, incrementBy) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.currentLoad += incrementBy; + } + }); + }, - decrementVehicleLoad: (modelUuid, decrementBy) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.currentLoad -= decrementBy; - } - }); - }, + decrementVehicleLoad: (modelUuid, decrementBy) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.currentLoad -= decrementBy; + } + }); + }, - setVehicleLoad: (modelUuid, load) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.currentLoad = load; - } - }); - }, + setVehicleLoad: (modelUuid, load) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.currentLoad = load; + } + }); + }, - setVehicleState: (modelUuid, newState) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.state = newState; - } - }); - }, + setVehicleState: (modelUuid, newState) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.state = newState; + } + }); + }, - addCurrentMaterial: (modelUuid, materialType, materialId) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.currentMaterials.push({ materialType, materialId }); - } - }); - }, + addCurrentMaterial: (modelUuid, materialType, materialId) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.currentMaterials.push({ materialType, materialId }); + } + }); + }, - setCurrentMaterials: (modelUuid, materials) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.currentMaterials = materials; - } - }); - }, + setCurrentMaterials: (modelUuid, materials) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.currentMaterials = materials; + } + }); + }, - removeLastMaterial: (modelUuid) => { - let removedMaterial: { materialId: string; materialType: string; } | undefined; - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - if (vehicle.currentMaterials.length > 0) { - const material = vehicle.currentMaterials.pop(); - if (material) { - removedMaterial = { materialId: material.materialId, materialType: material.materialType }; + removeLastMaterial: (modelUuid) => { + let removedMaterial: { materialId: string; materialType: string; } | undefined; + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + if (vehicle.currentMaterials.length > 0) { + const material = vehicle.currentMaterials.pop(); + if (material) { + removedMaterial = { materialId: material.materialId, materialType: material.materialType }; + } } } - } - }); - return removedMaterial; - }, + }); + return removedMaterial; + }, - getLastMaterial: (modelUuid) => { - let removedMaterial: { materialId: string; materialType: string; } | undefined; - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - if (vehicle.currentMaterials.length > 0) { - removedMaterial = { - materialId: vehicle.currentMaterials[vehicle.currentMaterials.length - 1].materialId, - materialType: vehicle.currentMaterials[vehicle.currentMaterials.length - 1].materialType - }; + getLastMaterial: (modelUuid) => { + let removedMaterial: { materialId: string; materialType: string; } | undefined; + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + if (vehicle.currentMaterials.length > 0) { + removedMaterial = { + materialId: vehicle.currentMaterials[vehicle.currentMaterials.length - 1].materialId, + materialType: vehicle.currentMaterials[vehicle.currentMaterials.length - 1].materialType + }; + } } - } - }); - return removedMaterial; - }, + }); + return removedMaterial; + }, - clearCurrentMaterials: (modelUuid) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.currentMaterials = []; - } - }); - }, + clearCurrentMaterials: (modelUuid) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.currentMaterials = []; + } + }); + }, - incrementActiveTime: (modelUuid, incrementBy) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.activeTime += incrementBy; - } - }); - }, + incrementActiveTime: (modelUuid, incrementBy) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.activeTime += incrementBy; + } + }); + }, - incrementIdleTime: (modelUuid, incrementBy) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.idleTime += incrementBy; - } - }); - }, + incrementIdleTime: (modelUuid, incrementBy) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.idleTime += incrementBy; + } + }); + }, - resetTime: (modelUuid) => { - set((state) => { - const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); - if (vehicle) { - vehicle.activeTime = 0; - vehicle.idleTime = 0; - } - }); - }, + resetTime: (modelUuid) => { + set((state) => { + const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); + if (vehicle) { + vehicle.activeTime = 0; + vehicle.idleTime = 0; + } + }); + }, - getVehicleById: (modelUuid) => { - return get().vehicles.find((v) => v.modelUuid === modelUuid); - }, + getVehicleById: (modelUuid) => { + return get().vehicles.find((v) => v.modelUuid === modelUuid); + }, - getVehiclesByProduct: (productId) => { - return get().vehicles.filter((v) => v.productId === productId); - }, + getVehiclesByProduct: (productId) => { + return get().vehicles.filter((v) => v.productId === productId); + }, - getVehiclesByState: (state) => { - return get().vehicles.filter((v) => v.state === state); - }, + getVehiclesByState: (state) => { + return get().vehicles.filter((v) => v.state === state); + }, - getActiveVehicles: () => { - return get().vehicles.filter((v) => v.isActive); - }, - })) -); + getActiveVehicles: () => { + return get().vehicles.filter((v) => v.isActive); + }, + })) + ) +} + +export type VehicleStoreType = ReturnType; \ No newline at end of file