diff --git a/app/src/components/layout/scenes/ComparisonScene.tsx b/app/src/components/layout/scenes/ComparisonScene.tsx
index d933839..b1029df 100644
--- a/app/src/components/layout/scenes/ComparisonScene.tsx
+++ b/app/src/components/layout/scenes/ComparisonScene.tsx
@@ -1,6 +1,5 @@
import { useProductContext } from '../../../modules/simulation/products/productContext'
import RegularDropDown from '../../ui/inputs/RegularDropDown';
-import { useProductStore } from '../../../store/simulation/useProductStore';
import { useCompareProductDataStore, useLoadingProgress, useSaveVersion } from '../../../store/builder/store';
import useModuleStore from '../../../store/useModuleStore';
import CompareLayOut from '../../ui/compareVersion/CompareLayOut';
@@ -10,10 +9,12 @@ import { usePlayButtonStore } from '../../../store/usePlayButtonStore';
import { useEffect, useState } from 'react';
import { useVersionHistoryStore } from '../../../store/builder/useVersionHistoryStore';
import { useVersionContext } from '../../../modules/builder/version/versionContext';
+import { useSceneContext } from '../../../modules/scene/sceneContext';
function ComparisonScene() {
const { isPlaying } = usePlayButtonStore();
- const { products } = useProductStore();
+ const { productStore } = useSceneContext();
+ const { products } = productStore();
const { isVersionSaved } = useSaveVersion();
const { activeModule } = useModuleStore();
const { selectedProductStore } = useProductContext();
@@ -25,20 +26,27 @@ function ComparisonScene() {
const [shouldShowComparisonResult, setShouldShowComparisonResult] = useState(false);
const { versionHistory } = useVersionHistoryStore();
const { selectedVersionStore } = useVersionContext();
- const { setSelectedVersion } = selectedVersionStore();
+ const { selectedVersion, setSelectedVersion } = selectedVersionStore();
- const handleSelectLayout = (option: string) => {
+ const handleSelectVersion = (option: string) => {
+ const version = versionHistory.find((version) => version.versionName === option);
+ if (version) {
+ setSelectedVersion(version);
+ }
+ };
+
+ const handleSelectProduct = (option: string) => {
const product = products.find((product) => product.productName === option);
if (product) {
setComparisonProduct(product.productUuid, product.productName);
}
};
- useEffect(() => {
- if (versionHistory.length > 0) {
- setSelectedVersion(versionHistory[0])
- }
- }, [versionHistory])
+ // useEffect(() => {
+ // if (versionHistory.length > 0) {
+ // setSelectedVersion(versionHistory[0])
+ // }
+ // }, [versionHistory])
// useEffect(() => {
// setCompareProductsData([
@@ -69,7 +77,7 @@ function ComparisonScene() {
// }
// }
// ])
- // }, []); // ✅ Runs only once on mount
+ // }, []);
useEffect(() => {
@@ -91,12 +99,19 @@ function ComparisonScene() {
<>
{isVersionSaved && activeModule === "simulation" && selectedProduct && (
<>
- {comparisonProduct && !isPlaying &&
+ {selectedVersion && !isPlaying &&
+ v.versionName)} // Pass layout names as options
+ onSelect={handleSelectVersion}
+ search={false}
+ />
+
l.productName)} // Pass layout names as options
- onSelect={handleSelectLayout}
+ onSelect={handleSelectProduct}
search={false}
/>
diff --git a/app/src/components/layout/scenes/MainScene.tsx b/app/src/components/layout/scenes/MainScene.tsx
index ba4a73d..d2db26d 100644
--- a/app/src/components/layout/scenes/MainScene.tsx
+++ b/app/src/components/layout/scenes/MainScene.tsx
@@ -30,7 +30,6 @@ import {
useMainProduct,
} from "../../../store/simulation/useSimulationStore";
import { useProductContext } from "../../../modules/simulation/products/productContext";
-import { useProductStore } from "../../../store/simulation/useProductStore";
import RegularDropDown from "../../ui/inputs/RegularDropDown";
import RenameTooltip from "../../ui/features/RenameTooltip";
import { setAssetsApi } from "../../../services/factoryBuilder/assest/floorAsset/setAssetsApi";
@@ -42,7 +41,6 @@ import VersionSaved from "../sidebarRight/versionHisory/VersionSaved";
import Footer from "../../footer/Footer";
function MainScene() {
- const { products } = useProductStore();
const { setMainProduct } = useMainProduct();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
@@ -58,13 +56,14 @@ function MainScene() {
const { setFloatingWidget } = useFloatingWidget();
const { clearComparisonProduct } = useComparisonProduct();
const { selectedFloorItem, setSelectedFloorItem } = useSelectedFloorItem();
- const { assetStore } = useSceneContext();
+ const { assetStore, productStore } = useSceneContext();
+ const { products } = productStore();
const { setName } = assetStore();
const { projectId } = useParams()
const { isRenameMode, setIsRenameMode } = useRenameModeStore();
const { versionHistory } = useVersionHistoryStore();
const { selectedVersionStore } = useVersionContext();
- const { setSelectedVersion } = selectedVersionStore();
+ const { selectedVersion, setSelectedVersion } = selectedVersionStore();
useEffect(() => {
if (activeModule !== 'simulation') {
@@ -79,7 +78,14 @@ function MainScene() {
}
}, [versionHistory])
- const handleSelectLayout = (option: string) => {
+ const handleSelectVersion = (option: string) => {
+ const version = versionHistory.find((version) => version.versionName === option);
+ if (version) {
+ setSelectedVersion(version);
+ }
+ };
+
+ const handleSelectProduct = (option: string) => {
const product = products.find((product) => product.productName === option);
if (product) {
setMainProduct(product.productUuid, product.productName);
@@ -157,12 +163,19 @@ function MainScene() {
- {selectedProduct && isVersionSaved && !isPlaying && activeModule === "simulation" && (
+ {selectedProduct && selectedVersion && isVersionSaved && !isPlaying && activeModule === "simulation" && (
+ v.versionName)} // Pass layout names as options
+ onSelect={handleSelectVersion}
+ search={false}
+ />
+
l.productName)} // Pass layout names as options
- onSelect={handleSelectLayout}
+ onSelect={handleSelectProduct}
search={false}
/>
diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/EventProperties.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/EventProperties.tsx
index 58e9b2e..ed799e5 100644
--- a/app/src/components/layout/sidebarRight/properties/eventProperties/EventProperties.tsx
+++ b/app/src/components/layout/sidebarRight/properties/eventProperties/EventProperties.tsx
@@ -3,7 +3,6 @@ import {
useSelectedEventData,
useSelectedEventSphere,
} from "../../../../../store/simulation/useSimulationStore";
-import { useProductStore } from "../../../../../store/simulation/useProductStore";
import ConveyorMechanics from "./mechanics/conveyorMechanics";
import VehicleMechanics from "./mechanics/vehicleMechanics";
import RoboticArmMechanics from "./mechanics/roboticArmMechanics";
@@ -11,21 +10,19 @@ import MachineMechanics from "./mechanics/machineMechanics";
import StorageMechanics from "./mechanics/storageMechanics";
import { AddIcon } from "../../../../icons/ExportCommonIcons";
import { handleAddEventToProduct } from "../../../../../modules/simulation/events/points/functions/handleAddEventToProduct";
-import { useEventsStore } from "../../../../../store/simulation/useEventsStore";
import { useProductContext } from "../../../../../modules/simulation/products/productContext";
import { useParams } from "react-router-dom";
import { useVersionContext } from "../../../../../modules/builder/version/versionContext";
+import { useSceneContext } from "../../../../../modules/scene/sceneContext";
const EventProperties: React.FC = () => {
const { selectedEventData } = useSelectedEventData();
- const { getEventByModelUuid } = useProductStore();
const { selectedProductStore } = useProductContext();
+ const { eventStore, productStore } = useSceneContext();
const { selectedProduct } = selectedProductStore();
- const [currentEventData, setCurrentEventData] = useState(
- null
- );
+ const [currentEventData, setCurrentEventData] = useState(null);
const [assetType, setAssetType] = useState(null);
- const { products, addEvent } = useProductStore();
+ const { products, addEvent, getEventByModelUuid } = productStore();
const { selectedEventSphere } = useSelectedEventSphere();
const { selectedVersionStore } = useVersionContext();
const { selectedVersion } = selectedVersionStore();
@@ -105,7 +102,7 @@ const EventProperties: React.FC = () => {
onClick={() => {
if (selectedEventData) {
handleAddEventToProduct({
- event: useEventsStore
+ event: eventStore
.getState()
.getEventByModelUuid(
selectedEventData?.data.modelUuid
diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/components/ActionsList.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/components/ActionsList.tsx
index 1e62ca1..4656357 100644
--- a/app/src/components/layout/sidebarRight/properties/eventProperties/components/ActionsList.tsx
+++ b/app/src/components/layout/sidebarRight/properties/eventProperties/components/ActionsList.tsx
@@ -9,11 +9,11 @@ import { handleResize } from "../../../../../../functions/handleResizePannel";
import {
useSelectedAction,
} from "../../../../../../store/simulation/useSimulationStore";
-import { useProductStore } from "../../../../../../store/simulation/useProductStore";
import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
import { useProductContext } from "../../../../../../modules/simulation/products/productContext";
import { useParams } from "react-router-dom";
import { useVersionContext } from "../../../../../../modules/builder/version/versionContext";
+import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
interface ActionsListProps {
selectedPointData: any;
@@ -31,7 +31,9 @@ const ActionsList: React.FC = ({
const actionsContainerRef = useRef(null);
// store
- const { renameAction } = useProductStore();
+
+ const { productStore } = useSceneContext();
+ const { renameAction } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const { selectedAction, setSelectedAction } = useSelectedAction();
diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/conveyorMechanics.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/conveyorMechanics.tsx
index d95393b..3c1a2e4 100644
--- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/conveyorMechanics.tsx
+++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/conveyorMechanics.tsx
@@ -9,25 +9,26 @@ import SpawnAction from "../actions/SpawnAction";
import DefaultAction from "../actions/DefaultAction";
import Trigger from "../trigger/Trigger";
import { useSelectedAction, useSelectedEventData } from "../../../../../../store/simulation/useSimulationStore";
-import { useProductStore } from "../../../../../../store/simulation/useProductStore";
import ActionsList from "../components/ActionsList";
import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
import { useProductContext } from "../../../../../../modules/simulation/products/productContext";
import { useParams } from "react-router-dom";
import { useVersionContext } from "../../../../../../modules/builder/version/versionContext";
+import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
function ConveyorMechanics() {
const [activeOption, setActiveOption] = useState<"default" | "spawn" | "swap" | "delay" | "despawn">("default");
const [selectedPointData, setSelectedPointData] = useState();
const { selectedEventData } = useSelectedEventData();
- const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction } = useProductStore();
+ const { productStore } = useSceneContext();
+ const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const { setSelectedAction, clearSelectedAction } = useSelectedAction();
const { projectId } = useParams();
const { selectedVersionStore } = useVersionContext();
const { selectedVersion } = selectedVersionStore();
-
+
useEffect(() => {
if (selectedEventData) {
const point = getPointByUuid(
diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/machineMechanics.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/machineMechanics.tsx
index f339855..f714d69 100644
--- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/machineMechanics.tsx
+++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/machineMechanics.tsx
@@ -3,19 +3,20 @@ import RenameInput from "../../../../../ui/inputs/RenameInput";
import LabledDropdown from "../../../../../ui/inputs/LabledDropdown";
import Trigger from "../trigger/Trigger";
import { useSelectedAction, useSelectedEventData } from "../../../../../../store/simulation/useSimulationStore";
-import { useProductStore } from "../../../../../../store/simulation/useProductStore";
import ProcessAction from "../actions/ProcessAction";
import ActionsList from "../components/ActionsList";
import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
import { useProductContext } from "../../../../../../modules/simulation/products/productContext";
import { useParams } from "react-router-dom";
import { useVersionContext } from "../../../../../../modules/builder/version/versionContext";
+import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
function MachineMechanics() {
const [activeOption, setActiveOption] = useState<"default" | "process">("default");
const [selectedPointData, setSelectedPointData] = useState();
const { selectedEventData } = useSelectedEventData();
- const { getPointByUuid, updateAction } = useProductStore();
+ const { productStore } = useSceneContext();
+ const { getPointByUuid, updateAction } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const { setSelectedAction, clearSelectedAction } = useSelectedAction();
diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/roboticArmMechanics.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/roboticArmMechanics.tsx
index 1831aa5..d70f6ac 100644
--- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/roboticArmMechanics.tsx
+++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/roboticArmMechanics.tsx
@@ -5,19 +5,20 @@ import RenameInput from "../../../../../ui/inputs/RenameInput";
import LabledDropdown from "../../../../../ui/inputs/LabledDropdown";
import Trigger from "../trigger/Trigger";
import { useSelectedEventData, useSelectedAction } from "../../../../../../store/simulation/useSimulationStore";
-import { useProductStore } from "../../../../../../store/simulation/useProductStore";
import PickAndPlaceAction from "../actions/PickAndPlaceAction";
import ActionsList from "../components/ActionsList";
import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
import { useProductContext } from "../../../../../../modules/simulation/products/productContext";
import { useParams } from "react-router-dom";
import { useVersionContext } from "../../../../../../modules/builder/version/versionContext";
+import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
function RoboticArmMechanics() {
const [activeOption, setActiveOption] = useState<"default" | "pickAndPlace">("default");
const [selectedPointData, setSelectedPointData] = useState();
const { selectedEventData } = useSelectedEventData();
- const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction, addAction, removeAction, } = useProductStore();
+ const { productStore } = useSceneContext();
+ const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction, addAction, removeAction, } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const { selectedAction, setSelectedAction, clearSelectedAction } = useSelectedAction();
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 ed19650..b29feb5 100644
--- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/storageMechanics.tsx
+++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/storageMechanics.tsx
@@ -5,18 +5,19 @@ import Trigger from "../trigger/Trigger";
import StorageAction from "../actions/StorageAction";
import ActionsList from "../components/ActionsList";
import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
-import { useProductStore } from "../../../../../../store/simulation/useProductStore";
import { useSelectedAction, useSelectedEventData } from "../../../../../../store/simulation/useSimulationStore";
import * as THREE from 'three';
import { useProductContext } from "../../../../../../modules/simulation/products/productContext";
import { useParams } from "react-router-dom";
import { useVersionContext } from "../../../../../../modules/builder/version/versionContext";
+import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
function StorageMechanics() {
const [activeOption, setActiveOption] = useState<"default" | "store" | "spawn">("default");
const [selectedPointData, setSelectedPointData] = useState();
const { selectedEventData } = useSelectedEventData();
- const { getPointByUuid, updateAction } = useProductStore();
+ const { productStore } = useSceneContext();
+ const { getPointByUuid, updateAction } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const { setSelectedAction, clearSelectedAction } = useSelectedAction();
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 c67af50..78583d8 100644
--- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/vehicleMechanics.tsx
+++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/vehicleMechanics.tsx
@@ -7,19 +7,20 @@ import {
useSelectedAction,
useSelectedEventData,
} from "../../../../../../store/simulation/useSimulationStore";
-import { useProductStore } from "../../../../../../store/simulation/useProductStore";
import TravelAction from "../actions/TravelAction";
import ActionsList from "../components/ActionsList";
import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
import { useProductContext } from "../../../../../../modules/simulation/products/productContext";
import { useParams } from "react-router-dom";
import { useVersionContext } from "../../../../../../modules/builder/version/versionContext";
+import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
function VehicleMechanics() {
const [activeOption, setActiveOption] = useState<"default" | "travel">("default");
const [selectedPointData, setSelectedPointData] = useState();
const { selectedEventData } = useSelectedEventData();
- const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction } = useProductStore();
+ const { productStore } = useSceneContext();
+ const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const { setSelectedAction, clearSelectedAction } = useSelectedAction();
diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/trigger/Trigger.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/trigger/Trigger.tsx
index f3ca1ca..4ecb1e9 100644
--- a/app/src/components/layout/sidebarRight/properties/eventProperties/trigger/Trigger.tsx
+++ b/app/src/components/layout/sidebarRight/properties/eventProperties/trigger/Trigger.tsx
@@ -4,12 +4,12 @@ import { AddIcon, RemoveIcon, ResizeHeightIcon } from "../../../../../icons/Expo
import LabledDropdown from "../../../../../ui/inputs/LabledDropdown";
import RenameInput from "../../../../../ui/inputs/RenameInput";
import { handleResize } from "../../../../../../functions/handleResizePannel";
-import { useProductStore } from "../../../../../../store/simulation/useProductStore";
import { useSelectedAction } from "../../../../../../store/simulation/useSimulationStore";
import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
import { useProductContext } from "../../../../../../modules/simulation/products/productContext";
import { useParams } from "react-router-dom";
import { useVersionContext } from "../../../../../../modules/builder/version/versionContext";
+import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
type TriggerProps = {
selectedPointData?: PointsScheme | undefined;
@@ -20,7 +20,8 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
const [currentAction, setCurrentAction] = useState();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
- const { getActionByUuid, getEventByModelUuid, getPointByUuid, getTriggerByUuid, addTrigger, removeTrigger, updateTrigger, renameTrigger, getProductById, } = useProductStore();
+ const { productStore } = useSceneContext();
+ const { getActionByUuid, getEventByModelUuid, getPointByUuid, getTriggerByUuid, addTrigger, removeTrigger, updateTrigger, renameTrigger, getProductById, } = productStore();
const [triggers, setTriggers] = useState([]);
const [selectedTrigger, setSelectedTrigger] = useState();
const [activeOption, setActiveOption] = useState<"onComplete" | "onStart" | "onStop" | "delay" | "onError">("onComplete");
diff --git a/app/src/components/layout/sidebarRight/simulation/Simulations.tsx b/app/src/components/layout/sidebarRight/simulation/Simulations.tsx
index 5831789..0858e5d 100644
--- a/app/src/components/layout/sidebarRight/simulation/Simulations.tsx
+++ b/app/src/components/layout/sidebarRight/simulation/Simulations.tsx
@@ -3,12 +3,10 @@ import { AddIcon, ArrowIcon, RemoveIcon, ResizeHeightIcon, } from "../../../icon
import RenameInput from "../../../ui/inputs/RenameInput";
import { handleResize } from "../../../../functions/handleResizePannel";
import { useMainProduct, useSelectedAsset } from "../../../../store/simulation/useSimulationStore";
-import { useProductStore } from "../../../../store/simulation/useProductStore";
import { generateUUID } from "three/src/math/MathUtils";
import RenderOverlay from "../../../templates/Overlay";
import EditWidgetOption from "../../../ui/menu/EditWidgetOption";
import { handleAddEventToProduct } from "../../../../modules/simulation/events/points/functions/handleAddEventToProduct";
-import { useEventsStore } from "../../../../store/simulation/useEventsStore";
import { deleteEventDataApi } from "../../../../services/simulation/products/deleteEventDataApi";
import { upsertProductOrEventApi } from "../../../../services/simulation/products/UpsertProductOrEventApi";
import { deleteProductApi } from "../../../../services/simulation/products/deleteProductApi";
@@ -20,6 +18,7 @@ import { useToggleStore } from "../../../../store/useUIToggleStore";
import { useProductContext } from "../../../../modules/simulation/products/productContext";
import { useParams } from "react-router-dom";
import { useVersionContext } from "../../../../modules/builder/version/versionContext";
+import { useSceneContext } from "../../../../modules/scene/sceneContext";
interface Event {
modelName: string;
@@ -40,10 +39,11 @@ const List: React.FC = ({ val }) => {
const Simulations: React.FC = () => {
const productsContainerRef = useRef(null);
- const { products, addProduct, removeProduct, renameProduct, addEvent, removeEvent, getProductById, } = useProductStore();
+ const { eventStore, productStore } = useSceneContext();
+ const { products, addProduct, removeProduct, renameProduct, addEvent, removeEvent, getProductById, } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct, setSelectedProduct } = selectedProductStore();
- const { getEventByModelUuid } = useEventsStore();
+ const { getEventByModelUuid } = eventStore();
const { selectedAsset, clearSelectedAsset } = useSelectedAsset();
const [openObjects, setOpenObjects] = useState(true);
const [processes, setProcesses] = useState();
diff --git a/app/src/components/ui/compareVersion/CompareLayOut.tsx b/app/src/components/ui/compareVersion/CompareLayOut.tsx
index c52eb1d..29b062a 100644
--- a/app/src/components/ui/compareVersion/CompareLayOut.tsx
+++ b/app/src/components/ui/compareVersion/CompareLayOut.tsx
@@ -10,15 +10,22 @@ import {
} from "../../../store/builder/store";
import Search from "../inputs/Search";
import OuterClick from "../../../utils/outerClick";
-import { useProductStore } from "../../../store/simulation/useProductStore";
import Scene from "../../../modules/scene/scene";
import { useComparisonProduct } from "../../../store/simulation/useSimulationStore";
-import { usePauseButtonStore, usePlayButtonStore } from "../../../store/usePlayButtonStore";
+import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
+import { useVersionHistoryStore } from "../../../store/builder/useVersionHistoryStore";
+import { useVersionContext } from "../../../modules/builder/version/versionContext";
+import { useSceneContext } from "../../../modules/scene/sceneContext";
+import { getAllProductsApi } from "../../../services/simulation/products/getallProductsApi";
+import { useParams } from "react-router-dom";
const CompareLayOut = () => {
- const { comparisonProduct, setComparisonProduct, clearComparisonProduct } =
- useComparisonProduct();
- const { products } = useProductStore();
+ const { clearComparisonProduct, comparisonProduct, setComparisonProduct } = useComparisonProduct();
+ const { productStore } = useSceneContext();
+ const { products } = productStore();
+ const { versionHistory } = useVersionHistoryStore();
+ const { selectedVersionStore } = useVersionContext();
+ const { selectedVersion, setSelectedVersion, clearSelectedVersion } = selectedVersionStore();
const { setLoadingProgress } = useLoadingProgress();
const [width, setWidth] = useState("50vw");
const [isResizing, setIsResizing] = useState(false);
@@ -29,7 +36,13 @@ const CompareLayOut = () => {
const { setIsVersionSaved } = useSaveVersion();
const { loadingProgress } = useLoadingProgress();
const { setIsPlaying } = usePlayButtonStore();
- const { setIsPaused } = usePauseButtonStore();
+ const { projectId } = useParams();
+
+ useEffect(() => {
+ if (!comparisonProduct) {
+ clearSelectedVersion();
+ }
+ }, [comparisonProduct])
OuterClick({
contextClassName: ["displayLayouts-container", "selectLayout"],
@@ -113,12 +126,14 @@ const CompareLayOut = () => {
return () => window.removeEventListener("resize", handleResize);
}, [isResizing]);
- const handleSelectLayout = (option: string) => {
- const product = products.find((product) => product.productName === option);
- if (product) {
- setComparisonProduct(product.productUuid, product.productName);
- setLoadingProgress(1);
- }
+ const handleSelectLayout = (version: Version) => {
+ getAllProductsApi(projectId || '', version.versionId || '').then((data) => {
+ if (data && data.length > 0) {
+ setSelectedVersion(version);
+ setComparisonProduct(data[0].productUuid, data[0].productName);
+ setLoadingProgress(1);
+ }
+ })
};
return (
@@ -127,7 +142,7 @@ const CompareLayOut = () => {
ref={wrapperRef}
style={{ width }}
>
- {loadingProgress == 0 && comparisonProduct?.productUuid && (
+ {loadingProgress == 0 && selectedVersion?.versionId && (
{
)}
- {comparisonProduct && (
+ {selectedVersion?.versionId && (
@@ -147,35 +162,35 @@ const CompareLayOut = () => {
)}
{width !== "0px" &&
- !comparisonProduct && ( // Show only if no layout selected
+ !selectedVersion?.versionId && ( // Show only if no layout selected
-
Choose Layout to compare
+
Choose Version to compare
setShowLayoutDropdown(!showLayoutDropdown)}
>
- Select Layout
+ Select Version
{showLayoutDropdown && (
-
Layouts
+
Versions
{ }} />
- {products.map((layout) => (
+ {versionHistory.map((version) => (
{
- handleSelectLayout(layout.productName);
+ handleSelectLayout(version);
setShowLayoutDropdown(false);
}}
>
- {layout.productName}
+ {version.versionName}
))}
diff --git a/app/src/modules/builder/aisle/Instances/aisleInstances.tsx b/app/src/modules/builder/aisle/Instances/aisleInstances.tsx
index d83028b..ec38412 100644
--- a/app/src/modules/builder/aisle/Instances/aisleInstances.tsx
+++ b/app/src/modules/builder/aisle/Instances/aisleInstances.tsx
@@ -1,13 +1,14 @@
import React, { useEffect, useMemo } from 'react';
-import { useAisleStore } from '../../../../store/builder/useAisleStore';
import { useToggleView } from '../../../../store/builder/store';
import AisleInstance from './instance/aisleInstance';
import Point from '../../point/point';
import { Html } from '@react-three/drei';
import { Vector3 } from 'three';
+import { useSceneContext } from '../../../scene/sceneContext';
function AisleInstances() {
- const { aisles } = useAisleStore();
+ const { aisleStore } = useSceneContext();
+ const { aisles } = aisleStore();
const { toggleView } = useToggleView();
const allPoints = useMemo(() => {
@@ -26,8 +27,6 @@ function AisleInstances() {
return points;
}, [aisles]);
-
-
return (
<>
{toggleView &&
diff --git a/app/src/modules/builder/aisle/aisleCreator/aisleCreator.tsx b/app/src/modules/builder/aisle/aisleCreator/aisleCreator.tsx
index d189db4..e0805e9 100644
--- a/app/src/modules/builder/aisle/aisleCreator/aisleCreator.tsx
+++ b/app/src/modules/builder/aisle/aisleCreator/aisleCreator.tsx
@@ -2,13 +2,13 @@ import * as THREE from 'three'
import { useEffect, useMemo, useRef, useState } from 'react'
import { useThree } from '@react-three/fiber';
import { useActiveLayer, useSocketStore, useToggleView, useToolMode } from '../../../../store/builder/store';
-import { useAisleStore } from '../../../../store/builder/useAisleStore';
import ReferenceAisle from './referenceAisle';
import { useBuilderStore } from '../../../../store/builder/useBuilderStore';
import ReferencePoint from '../../point/reference/referencePoint';
import { createAisleApi } from '../../../../services/factoryBuilder/aisle/createAisleApi';
import { useParams } from 'react-router-dom';
import { useVersionContext } from '../../version/versionContext';
+import { useSceneContext } from '../../../scene/sceneContext';
function AisleCreator() {
const { scene, camera, raycaster, gl, pointer } = useThree();
@@ -17,7 +17,8 @@ function AisleCreator() {
const { toolMode } = useToolMode();
const { activeLayer } = useActiveLayer();
const { socket } = useSocketStore();
- const { addAisle, getAislePointById } = useAisleStore();
+ const { aisleStore } = useSceneContext();
+ const { addAisle, getAislePointById } = aisleStore();
const drag = useRef(false);
const isLeftMouseDown = useRef(false);
const { selectedVersionStore } = useVersionContext();
diff --git a/app/src/modules/builder/aisle/aislesGroup.tsx b/app/src/modules/builder/aisle/aislesGroup.tsx
index 96321a6..1415eac 100644
--- a/app/src/modules/builder/aisle/aislesGroup.tsx
+++ b/app/src/modules/builder/aisle/aislesGroup.tsx
@@ -3,21 +3,22 @@ import AisleCreator from './aisleCreator/aisleCreator'
import AisleInstances from './Instances/aisleInstances'
import { useParams } from 'react-router-dom';
import { getAisleApi } from '../../../services/factoryBuilder/aisle/getAisleApi';
-import { useAisleStore } from '../../../store/builder/useAisleStore';
import { useVersionContext } from '../version/versionContext';
+import { useSceneContext } from '../../scene/sceneContext';
function AislesGroup() {
const { selectedVersionStore } = useVersionContext();
const { selectedVersion } = selectedVersionStore();
+ const { aisleStore } = useSceneContext();
+ const { setAisles } = aisleStore();
const { projectId } = useParams();
- const { setAisles } = useAisleStore();
useEffect(() => {
if (projectId) {
getAisleApi(projectId, selectedVersion?.versionId || '').then((aisles) => {
if (aisles && aisles.length > 0) {
setAisles(aisles);
- }else{
+ } else {
setAisles([]);
}
}).catch((err) => {
diff --git a/app/src/modules/builder/asset/assetsGroup.tsx b/app/src/modules/builder/asset/assetsGroup.tsx
index 9f502ce..b597ab3 100644
--- a/app/src/modules/builder/asset/assetsGroup.tsx
+++ b/app/src/modules/builder/asset/assetsGroup.tsx
@@ -5,7 +5,6 @@ import { useLoadingProgress, useRenameModeStore, useSelectedFloorItem, useSelect
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
import { FloorItems, RefGroup, RefMesh } from "../../../types/world/worldTypes";
-import { useEventsStore } from "../../../store/simulation/useEventsStore";
import Models from "./models/models";
import useModuleStore from "../../../store/useModuleStore";
import { useThree } from "@react-three/fiber";
@@ -29,11 +28,11 @@ function AssetsGroup({ floorGroup, plane }: { readonly floorGroup: RefGroup, rea
const { socket } = useSocketStore();
const { controls, gl, pointer, camera, raycaster } = useThree();
const { setLoadingProgress } = useLoadingProgress();
- const { assetStore } = useSceneContext();
+ const { assetStore, eventStore } = useSceneContext();
const { selectedVersionStore } = useVersionContext();
const { selectedVersion } = selectedVersionStore();
const { setAssets, addAsset, clearAssets } = assetStore();
- const { addEvent } = useEventsStore();
+ const { addEvent, clearEvents } = eventStore();
const { setSelectedFloorItem } = useSelectedFloorItem();
const { selectedItem, setSelectedItem } = useSelectedItem();
const { projectId } = useParams();
@@ -52,6 +51,7 @@ function AssetsGroup({ floorGroup, plane }: { readonly floorGroup: RefGroup, rea
useEffect(() => {
if (!projectId || !selectedVersion) return;
+ clearEvents();
let totalAssets = 0;
let loadedAssets = 0;
diff --git a/app/src/modules/builder/asset/models/model/model.tsx b/app/src/modules/builder/asset/models/model/model.tsx
index 094f3a9..9354232 100644
--- a/app/src/modules/builder/asset/models/model/model.tsx
+++ b/app/src/modules/builder/asset/models/model/model.tsx
@@ -7,8 +7,6 @@ import { ThreeEvent, useFrame, useThree } from '@react-three/fiber';
import { useActiveTool, useDeletableFloorItem, useRenderDistance, useSelectedFloorItem, useSocketStore, useToggleView, useToolMode } from '../../../../../store/builder/store';
import { AssetBoundingBox } from '../../functions/assetBoundingBox';
import { CameraControls } from '@react-three/drei';
-import { useEventsStore } from "../../../../../store/simulation/useEventsStore";
-import { useProductStore } from "../../../../../store/simulation/useProductStore";
import useModuleStore, { useSubModuleStore } from '../../../../../store/useModuleStore';
import { useLeftData, useTopData } from '../../../../../store/visualization/useZone3DWidgetStore';
import { useSelectedAsset } from '../../../../../store/simulation/useSimulationStore';
@@ -24,12 +22,12 @@ function Model({ asset }: { readonly asset: Asset }) {
const { toggleView } = useToggleView();
const { subModule } = useSubModuleStore();
const { activeModule } = useModuleStore();
- const { assetStore } = useSceneContext();
+ const { assetStore, eventStore, productStore } = useSceneContext();
const { removeAsset } = assetStore();
const { setTop } = useTopData();
const { setLeft } = useLeftData();
- const { getIsEventInProduct } = useProductStore();
- const { getEventByModelUuid } = useEventsStore();
+ const { getIsEventInProduct } = productStore();
+ const { getEventByModelUuid } = eventStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const { setSelectedAsset, clearSelectedAsset } = useSelectedAsset();
@@ -188,8 +186,8 @@ function Model({ asset }: { readonly asset: Asset }) {
const response = socket.emit('v1:model-asset:delete', data)
- useEventsStore.getState().removeEvent(asset.modelUuid);
- useProductStore.getState().deleteEvent(asset.modelUuid);
+ eventStore.getState().removeEvent(asset.modelUuid);
+ productStore.getState().deleteEvent(asset.modelUuid);
if (response) {
diff --git a/app/src/modules/builder/groups/floorPlanGroup.tsx b/app/src/modules/builder/groups/floorPlanGroup.tsx
index 00f1662..4739c21 100644
--- a/app/src/modules/builder/groups/floorPlanGroup.tsx
+++ b/app/src/modules/builder/groups/floorPlanGroup.tsx
@@ -50,13 +50,10 @@ const FloorPlanGroup = ({ floorPlanGroup, floorPlanGroupLine, floorPlanGroupPoin
useEffect(() => {
- // Load data from localStorage if available
getLines(organization, projectId, selectedVersion?.versionId || '').then((data) => {
const Lines: Types.Lines = objectLinesToArray(data);
- // const data = localStorage.getItem("Lines");
-
if (Lines) {
lines.current = Lines;
loadInitialPoint(lines, floorPlanGroupPoint, currentLayerPoint, dragPointControls);
diff --git a/app/src/modules/builder/point/helpers/usePointSnapping.tsx b/app/src/modules/builder/point/helpers/usePointSnapping.tsx
index 4545fab..88c9890 100644
--- a/app/src/modules/builder/point/helpers/usePointSnapping.tsx
+++ b/app/src/modules/builder/point/helpers/usePointSnapping.tsx
@@ -1,7 +1,7 @@
import * as THREE from 'three';
import { useCallback } from 'react';
-import { useAisleStore } from '../../../../store/builder/useAisleStore';
import { useWallStore } from '../../../../store/builder/useWallStore';
+import { useSceneContext } from '../../../scene/sceneContext';
const POINT_SNAP_THRESHOLD = 0.5; // Distance threshold for snapping in meters
@@ -12,7 +12,8 @@ const ANGLE_SNAP_DISTANCE_THRESHOLD = 0.5; // Distance threshold for snapping i
const CAN_ANGLE_SNAP = true; // Whether snapping is enabled or not
export const usePointSnapping = (currentPoint: { uuid: string, pointType: string, position: [number, number, number] } | null) => {
- const { aisles, getConnectedPoints: getConnectedAislePoints } = useAisleStore();
+ const { aisleStore } = useSceneContext();
+ const { aisles, getConnectedPoints: getConnectedAislePoints } = aisleStore();
const { walls, getConnectedPoints: getConnectedWallPoints } = useWallStore();
// Wall Snapping
diff --git a/app/src/modules/builder/point/point.tsx b/app/src/modules/builder/point/point.tsx
index f2fcc22..425d24b 100644
--- a/app/src/modules/builder/point/point.tsx
+++ b/app/src/modules/builder/point/point.tsx
@@ -3,7 +3,6 @@ import * as Constants from '../../../types/world/worldConstants';
import { useRef, useState, useEffect, useMemo } from 'react';
import { useToolMode } from '../../../store/builder/store';
import { DragControls } from '@react-three/drei';
-import { useAisleStore } from '../../../store/builder/useAisleStore';
import { useThree } from '@react-three/fiber';
import { useBuilderStore } from '../../../store/builder/useBuilderStore';
import { usePointSnapping } from './helpers/usePointSnapping';
@@ -12,6 +11,7 @@ import { deleteAisleApi } from '../../../services/factoryBuilder/aisle/deleteAis
import { useParams } from 'react-router-dom';
import { createAisleApi } from '../../../services/factoryBuilder/aisle/createAisleApi';
import { useVersionContext } from '../version/versionContext';
+import { useSceneContext } from '../../scene/sceneContext';
function Point({ point }: { readonly point: Point }) {
const materialRef = useRef(null);
@@ -19,7 +19,8 @@ function Point({ point }: { readonly point: Point }) {
const plane = useMemo(() => new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), []);
const [isHovered, setIsHovered] = useState(false);
const { toolMode } = useToolMode();
- const { setPosition: setAislePosition, removePoint: removeAislePoint, getAislesByPointId } = useAisleStore();
+ const { aisleStore } = useSceneContext();
+ const { setPosition: setAislePosition, removePoint: removeAislePoint, getAislesByPointId } = aisleStore();
const { setPosition: setWallPosition, removePoint: removeWallPoint } = useWallStore();
const { snapAislePoint, snapAisleAngle, snapWallPoint, snapWallAngle } = usePointSnapping({ uuid: point.pointUuid, pointType: point.pointType, position: point.position });
const { hoveredPoint, setHoveredPoint } = useBuilderStore();
diff --git a/app/src/modules/collaboration/socket/socketResponses.dev.tsx b/app/src/modules/collaboration/socket/socketResponses.dev.tsx
index 078c6b4..6028329 100644
--- a/app/src/modules/collaboration/socket/socketResponses.dev.tsx
+++ b/app/src/modules/collaboration/socket/socketResponses.dev.tsx
@@ -32,8 +32,6 @@ import Layer2DVisibility from "../../builder/geomentries/layers/layer2DVisibilit
import { retrieveGLTF, storeGLTF } from "../../../utils/indexDB/idbUtils";
import { getZonesApi } from "../../../services/factoryBuilder/zones/getZonesApi";
import { useParams } from "react-router-dom";
-import { useEventsStore } from "../../../store/simulation/useEventsStore";
-import { useProductStore } from "../../../store/simulation/useProductStore";
import { getUserData } from "../../../functions/getUserData";
import { useSceneContext } from "../../scene/sceneContext";
import { useVersionContext } from "../../builder/version/versionContext";
@@ -62,7 +60,7 @@ export default function SocketResponses({
const { selectedVersionStore } = useVersionContext();
const { selectedVersion } = selectedVersionStore();
const { projectId } = useParams();
- const { assetStore } = useSceneContext();
+ const { assetStore, eventStore, productStore } = useSceneContext();
const { addAsset, updateAsset, removeAsset } = assetStore();
const { organization } = getUserData();
@@ -158,8 +156,8 @@ export default function SocketResponses({
try {
const deletedUUID = data.data.modelUuid;
- useEventsStore.getState().removeEvent(deletedUUID);
- useProductStore.getState().deleteEvent(deletedUUID);
+ eventStore.getState().removeEvent(deletedUUID);
+ productStore.getState().deleteEvent(deletedUUID);
removeAsset(deletedUUID);
diff --git a/app/src/modules/scene/controls/selectionControls/copyPasteControls.tsx b/app/src/modules/scene/controls/selectionControls/copyPasteControls.tsx
index 0831943..5e0333e 100644
--- a/app/src/modules/scene/controls/selectionControls/copyPasteControls.tsx
+++ b/app/src/modules/scene/controls/selectionControls/copyPasteControls.tsx
@@ -5,7 +5,6 @@ import { useSelectedAssets, useSocketStore, useToggleView } from "../../../../st
// import { setAssetsApi } from '../../../../services/factoryBuilder/assest/floorAsset/setAssetsApi';
import * as Types from "../../../../types/world/worldTypes";
import { detectModifierKeys } from "../../../../utils/shortcutkeys/detectModifierKeys";
-import { useEventsStore } from "../../../../store/simulation/useEventsStore";
import { useParams } from "react-router-dom";
import { getUserData } from "../../../../functions/getUserData";
import { useSceneContext } from "../../sceneContext";
@@ -29,9 +28,9 @@ const CopyPasteControls = ({
const { selectedAssets, setSelectedAssets } = useSelectedAssets();
const plane = useMemo(() => new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), []);
const { socket } = useSocketStore();
- const { addEvent } = useEventsStore();
+ const { assetStore, eventStore } = useSceneContext();
+ const { addEvent } = eventStore();
const { projectId } = useParams();
- const { assetStore } = useSceneContext();
const { assets, addAsset } = assetStore();
const { selectedVersionStore } = useVersionContext();
const { selectedVersion } = selectedVersionStore();
diff --git a/app/src/modules/scene/controls/selectionControls/duplicationControls.tsx b/app/src/modules/scene/controls/selectionControls/duplicationControls.tsx
index 1c19745..ef56601 100644
--- a/app/src/modules/scene/controls/selectionControls/duplicationControls.tsx
+++ b/app/src/modules/scene/controls/selectionControls/duplicationControls.tsx
@@ -5,7 +5,6 @@ import { useSelectedAssets, useSocketStore, useToggleView } from "../../../../st
// import { setAssetsApi } from '../../../../services/factoryBuilder/assest/floorAsset/setAssetsApi';
import * as Types from "../../../../types/world/worldTypes";
import { detectModifierKeys } from "../../../../utils/shortcutkeys/detectModifierKeys";
-import { useEventsStore } from "../../../../store/simulation/useEventsStore";
import { useParams } from "react-router-dom";
import { getUserData } from "../../../../functions/getUserData";
import { useSceneContext } from "../../sceneContext";
@@ -27,9 +26,9 @@ const DuplicationControls = ({
const { selectedAssets, setSelectedAssets } = useSelectedAssets();
const plane = useMemo(() => new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), []);
const { socket } = useSocketStore();
- const { addEvent } = useEventsStore();
+ const { assetStore, eventStore } = useSceneContext();
+ const { addEvent } = eventStore();
const { projectId } = useParams();
- const { assetStore } = useSceneContext();
const { assets, addAsset } = assetStore();
const { selectedVersionStore } = useVersionContext();
const { selectedVersion } = selectedVersionStore();
diff --git a/app/src/modules/scene/controls/selectionControls/moveControls.tsx b/app/src/modules/scene/controls/selectionControls/moveControls.tsx
index 6f1388b..70d32e9 100644
--- a/app/src/modules/scene/controls/selectionControls/moveControls.tsx
+++ b/app/src/modules/scene/controls/selectionControls/moveControls.tsx
@@ -5,8 +5,6 @@ import { useSelectedAssets, useSocketStore, useToggleView, } from "../../../../s
// import { setAssetsApi } from '../../../../services/factoryBuilder/assest/floorAsset/setAssetsApi';
import * as Types from "../../../../types/world/worldTypes";
import { detectModifierKeys } from "../../../../utils/shortcutkeys/detectModifierKeys";
-import { useEventsStore } from "../../../../store/simulation/useEventsStore";
-import { useProductStore } from "../../../../store/simulation/useProductStore";
import { upsertProductOrEventApi } from "../../../../services/simulation/products/UpsertProductOrEventApi";
import { snapControls } from "../../../../utils/handleSnap";
import DistanceFindingControls from "./distanceFindingControls";
@@ -39,7 +37,7 @@ function MoveControls({
const [keyEvent, setKeyEvent] = useState<"Ctrl" | "Shift" | "Ctrl+Shift" | "">("");
const { userId, organization } = getUserData();
const { projectId } = useParams();
- const { assetStore } = useSceneContext();
+ const { assetStore, eventStore, productStore } = useSceneContext();
const { updateAsset } = assetStore();
const AssetGroup = useRef(undefined);
const { selectedVersionStore } = useVersionContext();
@@ -249,18 +247,18 @@ function MoveControls({
};
if (obj.userData.eventData) {
- const eventData = useEventsStore.getState().getEventByModelUuid(obj.userData.modelUuid);
- const productData = useProductStore.getState().getEventByModelUuid(selectedProduct.productUuid, obj.userData.modelUuid);
+ const eventData = eventStore.getState().getEventByModelUuid(obj.userData.modelUuid);
+ const productData = productStore.getState().getEventByModelUuid(selectedProduct.productUuid, obj.userData.modelUuid);
if (eventData) {
- useEventsStore.getState().updateEvent(obj.userData.modelUuid, {
+ eventStore.getState().updateEvent(obj.userData.modelUuid, {
position: [worldPosition.x, worldPosition.y, worldPosition.z],
rotation: [obj.rotation.x, obj.rotation.y, obj.rotation.z],
});
}
if (productData) {
- const event = useProductStore
+ const event = productStore
.getState()
.updateEvent(
selectedProduct.productUuid,
diff --git a/app/src/modules/scene/controls/selectionControls/rotateControls.tsx b/app/src/modules/scene/controls/selectionControls/rotateControls.tsx
index c05a8d2..6592e72 100644
--- a/app/src/modules/scene/controls/selectionControls/rotateControls.tsx
+++ b/app/src/modules/scene/controls/selectionControls/rotateControls.tsx
@@ -4,8 +4,6 @@ import { useFrame, useThree } from "@react-three/fiber";
import { useSelectedAssets, useSocketStore, useToggleView } from "../../../../store/builder/store";
// import { setAssetsApi } from '../../../../services/factoryBuilder/assest/floorAsset/setAssetsApi';
import * as Types from "../../../../types/world/worldTypes";
-import { useEventsStore } from "../../../../store/simulation/useEventsStore";
-import { useProductStore } from "../../../../store/simulation/useProductStore";
import { upsertProductOrEventApi } from "../../../../services/simulation/products/UpsertProductOrEventApi";
import { useParams } from "react-router-dom";
import { useProductContext } from "../../../simulation/products/productContext";
@@ -35,7 +33,7 @@ function RotateControls({
const { socket } = useSocketStore();
const { userId, organization } = getUserData();
const { projectId } = useParams();
- const { assetStore } = useSceneContext();
+ const { assetStore, eventStore, productStore } = useSceneContext();
const { updateAsset } = assetStore();
const AssetGroup = useRef(undefined);
const { selectedVersionStore } = useVersionContext();
@@ -214,17 +212,17 @@ function RotateControls({
};
if (obj.userData.eventData) {
- const eventData = useEventsStore.getState().getEventByModelUuid(obj.userData.modelUuid);
- const productData = useProductStore.getState().getEventByModelUuid(selectedProductStore.getState().selectedProduct.productUuid, obj.userData.modelUuid);
+ const eventData = eventStore.getState().getEventByModelUuid(obj.userData.modelUuid);
+ const productData = productStore.getState().getEventByModelUuid(selectedProductStore.getState().selectedProduct.productUuid, obj.userData.modelUuid);
if (eventData) {
- useEventsStore.getState().updateEvent(obj.userData.modelUuid, {
+ eventStore.getState().updateEvent(obj.userData.modelUuid, {
position: [worldPosition.x, worldPosition.y, worldPosition.z],
rotation: [obj.rotation.x, obj.rotation.y, obj.rotation.z],
})
}
if (productData) {
- const event = useProductStore.getState().updateEvent(selectedProductStore.getState().selectedProduct.productUuid, obj.userData.modelUuid, {
+ const event = productStore.getState().updateEvent(selectedProductStore.getState().selectedProduct.productUuid, obj.userData.modelUuid, {
position: [worldPosition.x, worldPosition.y, worldPosition.z],
rotation: [obj.rotation.x, obj.rotation.y, obj.rotation.z],
})
diff --git a/app/src/modules/scene/controls/selectionControls/selectionControls.tsx b/app/src/modules/scene/controls/selectionControls/selectionControls.tsx
index a1a97c4..e5b6d55 100644
--- a/app/src/modules/scene/controls/selectionControls/selectionControls.tsx
+++ b/app/src/modules/scene/controls/selectionControls/selectionControls.tsx
@@ -13,8 +13,6 @@ import CopyPasteControls from "./copyPasteControls";
import MoveControls from "./moveControls";
import RotateControls from "./rotateControls";
import useModuleStore from "../../../../store/useModuleStore";
-import { useEventsStore } from "../../../../store/simulation/useEventsStore";
-import { useProductStore } from "../../../../store/simulation/useProductStore";
import { useParams } from "react-router-dom";
import { getUserData } from "../../../../functions/getUserData";
import { useSceneContext } from "../../sceneContext";
@@ -33,7 +31,7 @@ const SelectionControls: React.FC = () => {
const boundingBoxRef = useRef();
const { activeModule } = useModuleStore();
const { socket } = useSocketStore();
- const { assetStore } = useSceneContext();
+ const { assetStore, eventStore, productStore } = useSceneContext();
const { removeAsset } = assetStore();
const selectionBox = useMemo(() => new SelectionBox(camera, scene), [camera, scene]);
const { toolMode } = useToolMode();
@@ -285,8 +283,8 @@ const SelectionControls: React.FC = () => {
const response = socket.emit("v1:model-asset:delete", data);
- useEventsStore.getState().removeEvent(selectedMesh.uuid);
- useProductStore.getState().deleteEvent(selectedMesh.uuid);
+ eventStore.getState().removeEvent(selectedMesh.uuid);
+ productStore.getState().deleteEvent(selectedMesh.uuid);
if (response) {
diff --git a/app/src/modules/scene/controls/transformControls/transformControls.tsx b/app/src/modules/scene/controls/transformControls/transformControls.tsx
index 3efe057..0b6a061 100644
--- a/app/src/modules/scene/controls/transformControls/transformControls.tsx
+++ b/app/src/modules/scene/controls/transformControls/transformControls.tsx
@@ -5,8 +5,6 @@ import { useThree } from "@react-three/fiber";
import { useEffect, useState } from "react";
import { detectModifierKeys } from "../../../../utils/shortcutkeys/detectModifierKeys";
-import { useEventsStore } from "../../../../store/simulation/useEventsStore";
-import { useProductStore } from "../../../../store/simulation/useProductStore";
import { upsertProductOrEventApi } from "../../../../services/simulation/products/UpsertProductOrEventApi";
// import { setAssetsApi } from "../../../../services/factoryBuilder/assest/floorAsset/setAssetsApi";
import { useParams } from "react-router-dom";
@@ -25,7 +23,7 @@ export default function TransformControl() {
const { socket } = useSocketStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
- const { assetStore } = useSceneContext();
+ const { assetStore, eventStore, productStore } = useSceneContext();
const { updateAsset, getAssetById } = assetStore();
const { userId, organization } = getUserData();
const { selectedVersionStore } = useVersionContext();
@@ -70,18 +68,18 @@ export default function TransformControl() {
const asset = getAssetById(selectedFloorItem?.uuid);
if (asset) {
if (asset.eventData) {
- const eventData = useEventsStore.getState().getEventByModelUuid(asset.modelUuid);
- const productData = useProductStore.getState().getEventByModelUuid(selectedProduct.productUuid, asset.modelUuid);
+ const eventData = eventStore.getState().getEventByModelUuid(asset.modelUuid);
+ const productData = productStore.getState().getEventByModelUuid(selectedProduct.productUuid, asset.modelUuid);
if (eventData) {
- useEventsStore.getState().updateEvent(asset.modelUuid, {
+ eventStore.getState().updateEvent(asset.modelUuid, {
position: [selectedFloorItem.position.x, 0, selectedFloorItem.position.z] as [number, number, number],
rotation: [selectedFloorItem.rotation.x, selectedFloorItem.rotation.y, selectedFloorItem.rotation.z] as [number, number, number],
});
}
if (productData) {
- const event = useProductStore
+ const event = productStore
.getState()
.updateEvent(
selectedProduct.productUuid,
diff --git a/app/src/modules/scene/sceneContext.tsx b/app/src/modules/scene/sceneContext.tsx
index 5e46b99..8d742ed 100644
--- a/app/src/modules/scene/sceneContext.tsx
+++ b/app/src/modules/scene/sceneContext.tsx
@@ -1,6 +1,10 @@
import { createContext, useContext, useMemo } from 'react';
import { createAssetStore, AssetStoreType } from '../../store/builder/useAssetStore';
+import { createAisleStore, AisleStoreType } from '../../store/builder/useAisleStore';
+
+import { createEventStore, EventStoreType } from '../../store/simulation/useEventsStore';
+import { createProductStore, ProductStoreType } from '../../store/simulation/useProductStore';
import { createMaterialStore, MaterialStoreType } from '../../store/simulation/useMaterialStore';
import { createArmBotStore, ArmBotStoreType } from '../../store/simulation/useArmBotStore';
@@ -12,6 +16,10 @@ import { createStorageUnitStore, StorageUnitStoreType } from '../../store/simula
type SceneContextValue = {
assetStore: AssetStoreType,
+ aisleStore: AisleStoreType,
+
+ eventStore: EventStoreType,
+ productStore: ProductStoreType,
materialStore: MaterialStoreType;
armBotStore: ArmBotStoreType;
@@ -19,6 +27,7 @@ type SceneContextValue = {
conveyorStore: ConveyorStoreType;
vehicleStore: VehicleStoreType;
storageUnitStore: StorageUnitStoreType;
+
layout: 'Main Layout' | 'Comparison Layout';
};
@@ -33,6 +42,10 @@ export function SceneProvider({
}) {
const assetStore = useMemo(() => createAssetStore(), []);
+ const aisleStore = useMemo(() => createAisleStore(), []);
+
+ const eventStore = useMemo(() => createEventStore(), []);
+ const productStore = useMemo(() => createProductStore(), []);
const materialStore = useMemo(() => createMaterialStore(), []);
const armBotStore = useMemo(() => createArmBotStore(), []);
@@ -48,6 +61,9 @@ export function SceneProvider({
const contextValue = useMemo(() => (
{
assetStore,
+ aisleStore,
+ eventStore,
+ productStore,
materialStore,
armBotStore,
machineStore,
@@ -57,7 +73,7 @@ export function SceneProvider({
clearStores,
layout
}
- ), [assetStore, materialStore, armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore, clearStores, layout]);
+ ), [assetStore, aisleStore, eventStore, productStore, materialStore, armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore, clearStores, layout]);
return (
diff --git a/app/src/modules/simulation/actions/conveyor/actionHandler/useSpawnHandler.ts b/app/src/modules/simulation/actions/conveyor/actionHandler/useSpawnHandler.ts
index 6e1cfee..0fece9a 100644
--- a/app/src/modules/simulation/actions/conveyor/actionHandler/useSpawnHandler.ts
+++ b/app/src/modules/simulation/actions/conveyor/actionHandler/useSpawnHandler.ts
@@ -1,7 +1,6 @@
import { useCallback, useEffect, useState } from "react";
import * as THREE from 'three';
import { useFrame } from "@react-three/fiber";
-import { useProductStore } from "../../../../../store/simulation/useProductStore";
import { usePlayButtonStore, useAnimationPlaySpeed, usePauseButtonStore, useResetButtonStore } from "../../../../../store/usePlayButtonStore";
import { useSceneContext } from "../../../../scene/sceneContext";
import { useProductContext } from "../../../products/productContext";
@@ -22,10 +21,10 @@ interface SpawnInstance {
}
export function useSpawnHandler() {
- const { materialStore, conveyorStore } = useSceneContext();
+ const { materialStore, conveyorStore, productStore } = useSceneContext();
const { addMaterial } = materialStore();
const { getConveyorById } = conveyorStore();
- const { getModelUuidByActionUuid, getPointUuidByActionUuid } = useProductStore();
+ const { getModelUuidByActionUuid, getPointUuidByActionUuid } = productStore();
const { isPlaying } = usePlayButtonStore();
const { isPaused } = usePauseButtonStore();
const { speed } = useAnimationPlaySpeed();
diff --git a/app/src/modules/simulation/actions/machine/actionHandler/useProcessHandler.ts b/app/src/modules/simulation/actions/machine/actionHandler/useProcessHandler.ts
index f9c9733..2a0eb97 100644
--- a/app/src/modules/simulation/actions/machine/actionHandler/useProcessHandler.ts
+++ b/app/src/modules/simulation/actions/machine/actionHandler/useProcessHandler.ts
@@ -1,14 +1,13 @@
import { useCallback } from "react";
-import { useProductStore } from "../../../../../store/simulation/useProductStore";
import { useSceneContext } from "../../../../scene/sceneContext";
import { useProductContext } from "../../../products/productContext";
export function useProcessHandler() {
- const { materialStore, machineStore } = useSceneContext();
+ const { materialStore, machineStore, productStore } = useSceneContext();
const { selectedProductStore } = useProductContext();
const { getMaterialById, setMaterial } = materialStore();
const { addCurrentAction } = machineStore();
- const { getModelUuidByActionUuid } = useProductStore();
+ const { getModelUuidByActionUuid } = productStore();
const { selectedProduct } = selectedProductStore();
const processLogStatus = (materialUuid: string, status: string) => {
diff --git a/app/src/modules/simulation/actions/roboticArm/actionHandler/usePickAndPlaceHandler.ts b/app/src/modules/simulation/actions/roboticArm/actionHandler/usePickAndPlaceHandler.ts
index a85a775..cf7b667 100644
--- a/app/src/modules/simulation/actions/roboticArm/actionHandler/usePickAndPlaceHandler.ts
+++ b/app/src/modules/simulation/actions/roboticArm/actionHandler/usePickAndPlaceHandler.ts
@@ -1,14 +1,13 @@
import { useCallback } from "react";
-import { useProductStore } from "../../../../../store/simulation/useProductStore";
import { useSceneContext } from "../../../../scene/sceneContext";
import { useProductContext } from "../../../products/productContext";
export function usePickAndPlaceHandler() {
- const { materialStore, armBotStore } = useSceneContext();
+ const { materialStore, armBotStore, productStore } = useSceneContext();
const { selectedProductStore } = useProductContext();
const { getMaterialById } = materialStore();
const { addCurrentAction } = armBotStore();
- const { getModelUuidByActionUuid } = useProductStore();
+ const { getModelUuidByActionUuid } = productStore();
const { selectedProduct } = selectedProductStore();
const pickAndPlaceLogStatus = (materialUuid: string, status: string) => {
diff --git a/app/src/modules/simulation/actions/storageUnit/actionHandler/useRetrieveHandler.ts b/app/src/modules/simulation/actions/storageUnit/actionHandler/useRetrieveHandler.ts
index 769aad8..c4b4245 100644
--- a/app/src/modules/simulation/actions/storageUnit/actionHandler/useRetrieveHandler.ts
+++ b/app/src/modules/simulation/actions/storageUnit/actionHandler/useRetrieveHandler.ts
@@ -1,15 +1,14 @@
import { useCallback, useState, useEffect, useRef } from "react";
import { useFrame } from "@react-three/fiber";
-import { useProductStore } from "../../../../../store/simulation/useProductStore";
import { usePlayButtonStore, usePauseButtonStore, useResetButtonStore, useAnimationPlaySpeed } from "../../../../../store/usePlayButtonStore";
import { useSceneContext } from "../../../../scene/sceneContext";
import { useProductContext } from "../../../products/productContext";
export function useRetrieveHandler() {
- const { materialStore, armBotStore, vehicleStore, storageUnitStore } = useSceneContext();
+ const { materialStore, armBotStore, vehicleStore, storageUnitStore, productStore } = useSceneContext();
const { selectedProductStore } = useProductContext();
const { addMaterial } = materialStore();
- const { getModelUuidByActionUuid, getPointUuidByActionUuid, getEventByModelUuid, getActionByUuid } = useProductStore();
+ const { getModelUuidByActionUuid, getPointUuidByActionUuid, getEventByModelUuid, getActionByUuid } = productStore();
const { getStorageUnitById, getLastMaterial, updateCurrentLoad, removeLastMaterial } = storageUnitStore();
const { getVehicleById, incrementVehicleLoad, addCurrentMaterial } = vehicleStore();
const { selectedProduct } = selectedProductStore();
diff --git a/app/src/modules/simulation/actions/storageUnit/actionHandler/useStoreHandler.ts b/app/src/modules/simulation/actions/storageUnit/actionHandler/useStoreHandler.ts
index f52d4a7..2b223d1 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 { useProductStore } from "../../../../../store/simulation/useProductStore";
import { useSceneContext } from "../../../../scene/sceneContext";
import { useProductContext } from "../../../products/productContext";
export function useStoreHandler() {
- const { materialStore, storageUnitStore } = useSceneContext();
+ const { materialStore, storageUnitStore, productStore } = useSceneContext();
const { getMaterialById, removeMaterial, setEndTime } = materialStore();
const { addCurrentMaterial, updateCurrentLoad } = storageUnitStore();
- const { getModelUuidByActionUuid } = useProductStore();
+ const { getModelUuidByActionUuid } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
diff --git a/app/src/modules/simulation/actions/vehicle/actionHandler/useTravelHandler.ts b/app/src/modules/simulation/actions/vehicle/actionHandler/useTravelHandler.ts
index 944c420..421cf20 100644
--- a/app/src/modules/simulation/actions/vehicle/actionHandler/useTravelHandler.ts
+++ b/app/src/modules/simulation/actions/vehicle/actionHandler/useTravelHandler.ts
@@ -1,13 +1,12 @@
import { useCallback } from "react";
-import { useProductStore } from "../../../../../store/simulation/useProductStore";
import { useSceneContext } from "../../../../scene/sceneContext";
import { useProductContext } from "../../../products/productContext";
export function useTravelHandler() {
- const { materialStore, vehicleStore } = useSceneContext();
+ const { materialStore, vehicleStore, productStore } = useSceneContext();
const { selectedProductStore } = useProductContext();
const { getMaterialById } = materialStore();
- const { getModelUuidByActionUuid } = useProductStore();
+ const { getModelUuidByActionUuid } = productStore();
const { selectedProduct } = selectedProductStore();
const { incrementVehicleLoad, addCurrentMaterial } = vehicleStore();
diff --git a/app/src/modules/simulation/analysis/ROI/roiData.tsx b/app/src/modules/simulation/analysis/ROI/roiData.tsx
index 2a26f8d..b8bdf0f 100644
--- a/app/src/modules/simulation/analysis/ROI/roiData.tsx
+++ b/app/src/modules/simulation/analysis/ROI/roiData.tsx
@@ -2,7 +2,7 @@ import React, { useEffect } from 'react'
import { CompareProduct, useCompareProductDataStore, useInputValues, useMachineDowntime, useMachineUptime, useProductionCapacityData, useROISummaryData, useThroughPutData } from '../../../../store/builder/store';
import { usePlayButtonStore } from '../../../../store/usePlayButtonStore';
import { useProductContext } from '../../products/productContext';
-import { useProductStore } from '../../../../store/simulation/useProductStore';
+import { useSceneContext } from '../../../scene/sceneContext';
export default function ROIData() {
const { selectedProductStore } = useProductContext();
@@ -11,10 +11,11 @@ export default function ROIData() {
const { selectedProduct } = selectedProductStore();
const { isPlaying } = usePlayButtonStore();
const { setRoiSummaryData } = useROISummaryData();
- const { products, getProductById } = useProductStore();
+ const { productStore } = useSceneContext();
+ const { getProductById } = productStore();
const { compareProductsData, setCompareProductsData } = useCompareProductDataStore();
- const { machineActiveTime, setMachineActiveTime } = useMachineUptime();
- const { machineIdleTime, setMachineIdleTime } = useMachineDowntime();
+ const { machineActiveTime } = useMachineUptime();
+ const { machineIdleTime } = useMachineDowntime();
const { throughputData } = useThroughPutData()
useEffect(() => {
@@ -49,7 +50,7 @@ export default function ROIData() {
if (!isNaN(electricityCost) && !isNaN(fixedCost) && !isNaN(laborCost) && !isNaN(maintenanceCost) &&
!isNaN(materialCost) && !isNaN(productionPeriod) && !isNaN(salvageValue) && !isNaN(sellingPrice) &&
!isNaN(shiftLength) && !isNaN(shiftsPerDay) && !isNaN(workingDaysPerYear) && productionCapacityData > 0) {
-
+
// const totalHoursPerYear = shiftLength * shiftsPerDay * workingDaysPerYear;
// const annualProductionUnits = productionCapacityData * totalHoursPerYear;
@@ -187,7 +188,7 @@ export default function ROIData() {
}, [inputValues, productionCapacityData, throughputData, isPlaying]);
useEffect(() => {
-
+
}, [compareProductsData])
return null;
diff --git a/app/src/modules/simulation/analysis/throughPut/throughPutData.tsx b/app/src/modules/simulation/analysis/throughPut/throughPutData.tsx
index 87655cd..f6ea5c1 100644
--- a/app/src/modules/simulation/analysis/throughPut/throughPutData.tsx
+++ b/app/src/modules/simulation/analysis/throughPut/throughPutData.tsx
@@ -1,17 +1,15 @@
import { useEffect } from 'react';
-import { useProductStore } from '../../../../store/simulation/useProductStore';
import { determineExecutionMachineSequences } from '../../simulator/functions/determineExecutionMachineSequences';
import { useInputValues, useMachineCount, useMachineDowntime, useMachineUptime, useMaterialCycle, useProcessBar, useThroughPutData } from '../../../../store/builder/store';
import { usePlayButtonStore } from '../../../../store/usePlayButtonStore';
import { useSceneContext } from '../../../scene/sceneContext';
import { useProductContext } from '../../products/productContext';
-import { set } from 'immer/dist/internal';
export default function ThroughPutData() {
- const { materialStore, armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore } = useSceneContext();
+ const { materialStore, armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore, productStore } = useSceneContext();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
- const { products, getProductById } = useProductStore();
+ const { products, getProductById } = productStore();
const { armBots } = armBotStore();
const { vehicles } = vehicleStore();
const { machines } = machineStore();
@@ -219,7 +217,7 @@ export default function ThroughPutData() {
if (shiftLength > 0 && materialCycleTime > 0 && machineCount > 0 && isPlaying) {
const Units_per_shift = (shiftLength * 60) / (materialCycleTime / 60);
-
+
const Throughput_per_day = Units_per_shift * shiftsPerDay * (yieldRate / 100);
setThroughputData(Number(Throughput_per_day.toFixed(2))); // Keep as number
}
diff --git a/app/src/modules/simulation/conveyor/instances/conveyorInstance/conveyorInstance.tsx b/app/src/modules/simulation/conveyor/instances/conveyorInstance/conveyorInstance.tsx
index 5bd4133..120058b 100644
--- a/app/src/modules/simulation/conveyor/instances/conveyorInstance/conveyorInstance.tsx
+++ b/app/src/modules/simulation/conveyor/instances/conveyorInstance/conveyorInstance.tsx
@@ -1,15 +1,14 @@
import { useEffect } from 'react'
import { useResetButtonStore } from '../../../../../store/usePlayButtonStore';
-import { useProductStore } from '../../../../../store/simulation/useProductStore';
import { useSceneContext } from '../../../../scene/sceneContext';
import { useProductContext } from '../../../products/productContext';
// import { findConveyorSubsequence } from '../../../simulator/functions/getConveyorSequencesInProduct';
function ConveyorInstance({ conveyor }: { readonly conveyor: ConveyorStatus }) {
- const { getProductById } = useProductStore();
+ const { materialStore, conveyorStore, productStore } = useSceneContext();
+ const { getProductById } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
- const { materialStore, conveyorStore } = useSceneContext();
const { getMaterialsByCurrentModelUuid, materials } = materialStore();
const { isReset } = useResetButtonStore();
const { setConveyorPaused } = conveyorStore();
diff --git a/app/src/modules/simulation/events/points/creator/pointsCreator.tsx b/app/src/modules/simulation/events/points/creator/pointsCreator.tsx
index 9cb750c..9f9cbb4 100644
--- a/app/src/modules/simulation/events/points/creator/pointsCreator.tsx
+++ b/app/src/modules/simulation/events/points/creator/pointsCreator.tsx
@@ -1,7 +1,5 @@
import { useEffect, useRef, useState } from "react";
import * as THREE from "three";
-import { useEventsStore } from "../../../../../store/simulation/useEventsStore";
-import { useProductStore } from "../../../../../store/simulation/useProductStore";
import useModuleStore, { useSubModuleStore } from "../../../../../store/useModuleStore";
import { TransformControls } from "@react-three/drei";
import { detectModifierKeys } from "../../../../../utils/shortcutkeys/detectModifierKeys";
@@ -13,13 +11,15 @@ import { useProductContext } from "../../../products/productContext";
import { useParams } from "react-router-dom";
import { useToolMode } from "../../../../../store/builder/store";
import { useVersionContext } from "../../../../builder/version/versionContext";
+import { useSceneContext } from "../../../../scene/sceneContext";
function PointsCreator() {
const { gl, raycaster, scene, pointer, camera } = useThree();
const { subModule } = useSubModuleStore();
const { selectedProductStore } = useProductContext();
- const { events, updatePoint, getPointByUuid, getEventByModelUuid } = useEventsStore();
- const { getEventByModelUuid: getEventByModelUuidFromProduct, updatePoint: updatePointFromProduct, getEventByModelUuid: getEventByModelUuidFromProduct2, getPointByUuid: getPointByUuidFromProduct } = useProductStore();
+ const { eventStore, productStore } = useSceneContext();
+ const { events, updatePoint, getPointByUuid, getEventByModelUuid } = eventStore();
+ const { getEventByModelUuid: getEventByModelUuidFromProduct, updatePoint: updatePointFromProduct, getEventByModelUuid: getEventByModelUuidFromProduct2, getPointByUuid: getPointByUuidFromProduct } = productStore();
const { selectedProduct } = selectedProductStore();
const { activeModule } = useModuleStore();
const transformRef = useRef(null);
diff --git a/app/src/modules/simulation/events/points/functions/handleAddEventToProduct.ts b/app/src/modules/simulation/events/points/functions/handleAddEventToProduct.ts
index ff3f692..0ba13a7 100644
--- a/app/src/modules/simulation/events/points/functions/handleAddEventToProduct.ts
+++ b/app/src/modules/simulation/events/points/functions/handleAddEventToProduct.ts
@@ -17,7 +17,8 @@ export const handleAddEventToProduct = ({
addEvent,
selectedProduct,
clearSelectedAsset,
- projectId
+ projectId,
+ versionId
}: HandleAddEventToProductParams) => {
if (event && selectedProduct.productUuid) {
addEvent(selectedProduct.productUuid, event);
@@ -25,7 +26,8 @@ export const handleAddEventToProduct = ({
upsertProductOrEventApi({
productName: selectedProduct.productName,
productUuid: selectedProduct.productUuid,
- projectId: projectId ||'',
+ versionId,
+ projectId: projectId || '',
eventDatas: event
}).then((data) => {
// console.log(data);
diff --git a/app/src/modules/simulation/events/triggerConnections/triggerConnector.tsx b/app/src/modules/simulation/events/triggerConnections/triggerConnector.tsx
index c4f91c6..0b8cb2d 100644
--- a/app/src/modules/simulation/events/triggerConnections/triggerConnector.tsx
+++ b/app/src/modules/simulation/events/triggerConnections/triggerConnector.tsx
@@ -3,8 +3,6 @@ import { useFrame, useThree } from "@react-three/fiber";
import * as THREE from "three";
import { useSubModuleStore } from "../../../../store/useModuleStore";
import { useSelectedAction, useSelectedAsset } from "../../../../store/simulation/useSimulationStore";
-import { useProductStore } from "../../../../store/simulation/useProductStore";
-import { useEventsStore } from "../../../../store/simulation/useEventsStore";
import { handleAddEventToProduct } from "../points/functions/handleAddEventToProduct";
import { QuadraticBezierLine } from "@react-three/drei";
import { upsertProductOrEventApi } from "../../../../services/simulation/products/UpsertProductOrEventApi";
@@ -14,6 +12,7 @@ import { useProductContext } from "../../products/productContext";
import { useParams } from "react-router-dom";
import { useToolMode } from "../../../../store/builder/store";
import { useVersionContext } from "../../../builder/version/versionContext";
+import { useSceneContext } from "../../../scene/sceneContext";
interface ConnectionLine {
id: string;
@@ -26,7 +25,8 @@ function TriggerConnector() {
const { gl, raycaster, scene, pointer, camera } = useThree();
const { subModule } = useSubModuleStore();
const { selectedProductStore } = useProductContext();
- const { products, getPointByUuid, getIsEventInProduct, getActionByUuid, addTrigger, removeTrigger, addEvent, getEventByModelUuid, getPointUuidByActionUuid, getProductById } = useProductStore();
+ const { eventStore, productStore } = useSceneContext();
+ const { products, getPointByUuid, getIsEventInProduct, getActionByUuid, addTrigger, removeTrigger, addEvent, getEventByModelUuid, getPointUuidByActionUuid, getProductById } = productStore();
const { selectedAsset, clearSelectedAsset } = useSelectedAsset();
const { selectedProduct } = selectedProductStore();
const [hoveredLineKey, setHoveredLineKey] = useState(null);
@@ -283,7 +283,7 @@ function TriggerConnector() {
}
} else if (!getIsEventInProduct(selectedProduct.productUuid, modelUuid) && firstSelectedPoint) {
handleAddEventToProduct({
- event: useEventsStore.getState().getEventByModelUuid(modelUuid),
+ event: eventStore.getState().getEventByModelUuid(modelUuid),
addEvent,
selectedProduct,
projectId: projectId || '',
diff --git a/app/src/modules/simulation/machine/instances/machineInstance/machineInstance.tsx b/app/src/modules/simulation/machine/instances/machineInstance/machineInstance.tsx
index 2d87bf2..5715016 100644
--- a/app/src/modules/simulation/machine/instances/machineInstance/machineInstance.tsx
+++ b/app/src/modules/simulation/machine/instances/machineInstance/machineInstance.tsx
@@ -1,7 +1,6 @@
import { useEffect, useRef, useState } from 'react'
import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore';
import MachineAnimator from '../animator/machineAnimator';
-import { useProductStore } from '../../../../../store/simulation/useProductStore';
import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler';
import { useSceneContext } from '../../../../scene/sceneContext';
import { useProductContext } from '../../../products/productContext';
@@ -16,11 +15,11 @@ function MachineInstance({ machineDetail }: { readonly machineDetail: MachineSta
const isSpeedRef = useRef(0);
const isPausedRef = useRef(false);
const { isPlaying } = usePlayButtonStore();
- const { machineStore } = useSceneContext();
+ const { machineStore, productStore } = useSceneContext();
const { selectedProductStore } = useProductContext();
const { machines, setMachineState, setMachineActive, incrementIdleTime, incrementActiveTime, resetTime } = machineStore();
const { selectedProduct } = selectedProductStore();
- const { getActionByUuid } = useProductStore();
+ const { getActionByUuid } = productStore();
const { triggerPointActions } = useTriggerHandler();
const { speed } = useAnimationPlaySpeed();
const { isPaused } = usePauseButtonStore();
diff --git a/app/src/modules/simulation/materials/instances/instance/materialInstance.tsx b/app/src/modules/simulation/materials/instances/instance/materialInstance.tsx
index 5d62170..9dcfaab 100644
--- a/app/src/modules/simulation/materials/instances/instance/materialInstance.tsx
+++ b/app/src/modules/simulation/materials/instances/instance/materialInstance.tsx
@@ -1,18 +1,19 @@
import { useMemo, useRef } from 'react'
import * as THREE from 'three';
import MaterialAnimator from '../animator/materialAnimator';
-import { useProductStore } from '../../../../../store/simulation/useProductStore';
import { MaterialModel } from '../material/materialModel';
import { useThree } from '@react-three/fiber';
import { useAnimationPlaySpeed } from '../../../../../store/usePlayButtonStore';
import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler';
import { useProductContext } from '../../../products/productContext';
+import { useSceneContext } from '../../../../scene/sceneContext';
function MaterialInstance({ material }: { readonly material: MaterialSchema }) {
const matRef: any = useRef();
const { scene } = useThree();
const { selectedProductStore } = useProductContext();
- const { getModelUuidByPointUuid, getPointByUuid, getEventByModelUuid, getActionByUuid, getTriggerByUuid, getActionByPointUuid } = useProductStore();
+ const { productStore } = useSceneContext();
+ const { getModelUuidByPointUuid, getPointByUuid, getEventByModelUuid, getActionByPointUuid } = productStore();
const { selectedProduct } = selectedProductStore();
const { speed } = useAnimationPlaySpeed();
const { triggerPointActions } = useTriggerHandler();
diff --git a/app/src/modules/simulation/products/products.tsx b/app/src/modules/simulation/products/products.tsx
index bb57008..1839447 100644
--- a/app/src/modules/simulation/products/products.tsx
+++ b/app/src/modules/simulation/products/products.tsx
@@ -1,6 +1,5 @@
import * as THREE from 'three';
import { useEffect } from 'react';
-import { useProductStore } from '../../../store/simulation/useProductStore';
import { upsertProductOrEventApi } from '../../../services/simulation/products/UpsertProductOrEventApi';
import { getAllProductsApi } from '../../../services/simulation/products/getallProductsApi';
import { usePlayButtonStore, useResetButtonStore } from '../../../store/usePlayButtonStore';
@@ -11,8 +10,8 @@ import { useParams } from 'react-router-dom';
import { useVersionContext } from '../../builder/version/versionContext';
function Products() {
- const { armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore, layout } = useSceneContext();
- const { products, getProductById, addProduct, setProducts } = useProductStore();
+ const { armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore, layout, productStore } = useSceneContext();
+ const { products, getProductById, addProduct, setProducts } = productStore();
const { selectedProductStore } = useProductContext();
const { setMainProduct } = useMainProduct();
const { selectedProduct, setSelectedProduct } = selectedProductStore();
@@ -64,7 +63,7 @@ function Products() {
setMainProduct(data[0].productUuid, data[0].productName);
}
}
- }).catch((err)=>{
+ }).catch((err) => {
console.error(err);
})
}, [selectedVersion?.versionId])
diff --git a/app/src/modules/simulation/roboticArm/instances/armInstance/roboticArmInstance.tsx b/app/src/modules/simulation/roboticArm/instances/armInstance/roboticArmInstance.tsx
index e921bc0..5a2d724 100644
--- a/app/src/modules/simulation/roboticArm/instances/armInstance/roboticArmInstance.tsx
+++ b/app/src/modules/simulation/roboticArm/instances/armInstance/roboticArmInstance.tsx
@@ -6,14 +6,11 @@ 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 { useProductStore } from '../../../../../store/simulation/useProductStore';
import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler';
import { useSceneContext } from '../../../../scene/sceneContext';
import { useProductContext } from '../../../products/productContext';
-import { Preload } from '@react-three/drei';
function RoboticArmInstance({ armBot }: { readonly armBot: ArmBotStatus }) {
-
const [currentPhase, setCurrentPhase] = useState<(string)>("init");
const [path, setPath] = useState<[number, number, number][]>([]);
const [ikSolver, setIkSolver] = useState(null);
@@ -27,13 +24,13 @@ function RoboticArmInstance({ armBot }: { readonly armBot: ArmBotStatus }) {
let startTime: number;
const { selectedProductStore } = useProductContext();
- const { materialStore, armBotStore, vehicleStore, storageUnitStore } = useSceneContext();
+ const { materialStore, armBotStore, vehicleStore, storageUnitStore, productStore } = useSceneContext();
const { setArmBotActive, setArmBotState, removeCurrentAction, incrementActiveTime, incrementIdleTime } = armBotStore();
const { decrementVehicleLoad, removeLastMaterial } = vehicleStore();
const { removeLastMaterial: removeLastStorageMaterial, updateCurrentLoad } = storageUnitStore();
- const { getMaterialById, setIsVisible, setIsPaused } = materialStore();
+ const { getMaterialById, setIsVisible } = materialStore();
const { selectedProduct } = selectedProductStore();
- const { getActionByUuid, getEventByActionUuid, getEventByModelUuid } = useProductStore();
+ const { getActionByUuid, getEventByActionUuid, getEventByModelUuid } = productStore();
const { triggerPointActions } = useTriggerHandler();
const { isPlaying } = usePlayButtonStore();
const { isReset } = useResetButtonStore();
diff --git a/app/src/modules/simulation/simulation.tsx b/app/src/modules/simulation/simulation.tsx
index f918f56..3429393 100644
--- a/app/src/modules/simulation/simulation.tsx
+++ b/app/src/modules/simulation/simulation.tsx
@@ -1,6 +1,4 @@
import React, { useEffect } from 'react';
-import { useEventsStore } from '../../store/simulation/useEventsStore';
-import { useProductStore } from '../../store/simulation/useProductStore';
import Vehicles from './vehicle/vehicles';
import Points from './events/points/points';
import Conveyor from './conveyor/conveyor';
@@ -13,11 +11,13 @@ import Products from './products/products';
import Trigger from './triggers/trigger';
import useModuleStore from '../../store/useModuleStore';
import SimulationAnalysis from './analysis/simulationAnalysis';
+import { useSceneContext } from '../scene/sceneContext';
function Simulation() {
const { activeModule } = useModuleStore();
- const { events } = useEventsStore();
- const { products } = useProductStore();
+ const { eventStore, productStore } = useSceneContext();
+ const { events } = eventStore();
+ const { products } = productStore();
useEffect(() => {
// console.log('events: ', events);
diff --git a/app/src/modules/simulation/simulator/simulator.tsx b/app/src/modules/simulation/simulator/simulator.tsx
index 5b2f8a8..598d3d8 100644
--- a/app/src/modules/simulation/simulator/simulator.tsx
+++ b/app/src/modules/simulation/simulator/simulator.tsx
@@ -1,13 +1,15 @@
import { useEffect } from 'react';
-import { useProductStore } from '../../../store/simulation/useProductStore';
import { useActionHandler } from '../actions/useActionHandler';
import { usePlayButtonStore, useResetButtonStore } from '../../../store/usePlayButtonStore';
import { determineExecutionOrder } from './functions/determineExecutionOrder';
import { useProductContext } from '../products/productContext';
+import { useSceneContext } from '../../scene/sceneContext';
+import { useCompareProductDataStore } from '../../../store/builder/store';
function Simulator() {
const { selectedProductStore } = useProductContext();
- const { products, getProductById } = useProductStore();
+ const { productStore } = useSceneContext();
+ const { products, getProductById } = productStore();
const { handleAction } = useActionHandler();
const { selectedProduct } = selectedProductStore();
const { isPlaying } = usePlayButtonStore();
diff --git a/app/src/modules/simulation/spatialUI/arm/armBotUI.tsx b/app/src/modules/simulation/spatialUI/arm/armBotUI.tsx
index 2518f9f..5226369 100644
--- a/app/src/modules/simulation/spatialUI/arm/armBotUI.tsx
+++ b/app/src/modules/simulation/spatialUI/arm/armBotUI.tsx
@@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react';
import { useSelectedAction, useSelectedEventSphere } from '../../../../store/simulation/useSimulationStore';
import { useGLTF } from '@react-three/drei';
import { useThree } from '@react-three/fiber';
-import { useProductStore } from '../../../../store/simulation/useProductStore';
import PickDropPoints from './PickDropPoints';
import useDraggableGLTF from './useDraggableGLTF';
import * as THREE from 'three';
@@ -22,13 +21,13 @@ type Positions = {
};
const ArmBotUI = () => {
- const { getEventByModelUuid, updateAction, getActionByUuid } = useProductStore();
+ const { armBotStore, productStore } = useSceneContext();
+ const { getEventByModelUuid, updateAction, getActionByUuid } = productStore();
const { selectedEventSphere } = useSelectedEventSphere();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const { scene } = useThree();
const { selectedAction } = useSelectedAction();
- const { armBotStore } = useSceneContext();
const { armBots } = armBotStore();
const { selectedVersionStore } = useVersionContext();
const { selectedVersion } = selectedVersionStore();
diff --git a/app/src/modules/simulation/spatialUI/arm/useDraggableGLTF.ts b/app/src/modules/simulation/spatialUI/arm/useDraggableGLTF.ts
index 418376a..7c7d0b4 100644
--- a/app/src/modules/simulation/spatialUI/arm/useDraggableGLTF.ts
+++ b/app/src/modules/simulation/spatialUI/arm/useDraggableGLTF.ts
@@ -1,16 +1,17 @@
import { useRef, useState } from "react";
import * as THREE from "three";
import { ThreeEvent, useThree } from "@react-three/fiber";
-import { useProductStore } from "../../../../store/simulation/useProductStore";
import {
useSelectedEventData,
} from "../../../../store/simulation/useSimulationStore";
import { useProductContext } from "../../products/productContext";
+import { useSceneContext } from "../../../scene/sceneContext";
type OnUpdateCallback = (object: THREE.Object3D) => void;
export default function useDraggableGLTF(onUpdate: OnUpdateCallback) {
- const { getEventByModelUuid } = useProductStore();
+ const { productStore } = useSceneContext();
+ const { getEventByModelUuid } = productStore();
const { selectedEventData } = useSelectedEventData();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
diff --git a/app/src/modules/simulation/spatialUI/vehicle/vehicleUI.tsx b/app/src/modules/simulation/spatialUI/vehicle/vehicleUI.tsx
index f8b0bcf..9d889ed 100644
--- a/app/src/modules/simulation/spatialUI/vehicle/vehicleUI.tsx
+++ b/app/src/modules/simulation/spatialUI/vehicle/vehicleUI.tsx
@@ -3,7 +3,6 @@ import * as Types from "../../../../types/world/worldTypes";
import { useGLTF } from "@react-three/drei";
import { useFrame, useThree } from "@react-three/fiber";
import { useSelectedEventSphere, useIsDragging, useIsRotating, } from "../../../../store/simulation/useSimulationStore";
-import { useProductStore } from "../../../../store/simulation/useProductStore";
import { upsertProductOrEventApi } from "../../../../services/simulation/products/UpsertProductOrEventApi";
import { DoubleSide, Group, Plane, Vector3 } from "three";
@@ -22,10 +21,10 @@ const VehicleUI = () => {
const prevMousePos = useRef({ x: 0, y: 0 });
const { selectedEventSphere } = useSelectedEventSphere();
const { selectedProductStore } = useProductContext();
- const { vehicleStore } = useSceneContext();
+ const { vehicleStore, productStore } = useSceneContext();
const { selectedProduct } = selectedProductStore();
const { vehicles, getVehicleById } = vehicleStore();
- const { updateEvent } = useProductStore();
+ const { updateEvent } = productStore();
const [startPosition, setStartPosition] = useState<[number, number, number]>([0, 1, 0,]);
const [endPosition, setEndPosition] = useState<[number, number, number]>([0, 1, 0,]);
diff --git a/app/src/modules/simulation/triggers/triggerHandler/useTriggerHandler.ts b/app/src/modules/simulation/triggers/triggerHandler/useTriggerHandler.ts
index 5298c87..5731d9e 100644
--- a/app/src/modules/simulation/triggers/triggerHandler/useTriggerHandler.ts
+++ b/app/src/modules/simulation/triggers/triggerHandler/useTriggerHandler.ts
@@ -1,6 +1,5 @@
import { useCallback } from 'react';
import { useActionHandler } from '../../actions/useActionHandler';
-import { useProductStore } from '../../../../store/simulation/useProductStore';
import { useArmBotEventManager } from '../../roboticArm/eventManager/useArmBotEventManager';
import { useConveyorEventManager } from '../../conveyor/eventManager/useConveyorEventManager';
import { useVehicleEventManager } from '../../vehicle/eventManager/useVehicleEventManager';
@@ -9,11 +8,11 @@ import { useSceneContext } from '../../../scene/sceneContext';
import { useProductContext } from '../../products/productContext';
export function useTriggerHandler() {
- const { materialStore, armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore } = useSceneContext();
+ const { materialStore, armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore, productStore } = useSceneContext();
const { selectedProductStore } = useProductContext();
const { handleAction } = useActionHandler();
const { selectedProduct } = selectedProductStore();
- const { getEventByTriggerUuid, getEventByModelUuid, getActionByUuid, getModelUuidByActionUuid } = useProductStore();
+ const { getEventByTriggerUuid, getEventByModelUuid, getActionByUuid, getModelUuidByActionUuid } = productStore();
const { getArmBotById } = armBotStore();
const { getConveyorById } = conveyorStore();
const { addArmBotToMonitor } = useArmBotEventManager();
diff --git a/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx b/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx
index 6eb41a3..0709109 100644
--- a/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx
+++ b/app/src/modules/simulation/vehicle/instances/instance/vehicleInstance.tsx
@@ -4,7 +4,6 @@ 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 { useProductStore } from '../../../../../store/simulation/useProductStore';
import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler';
import MaterialAnimator from '../animator/materialAnimator';
import { useSceneContext } from '../../../../scene/sceneContext';
@@ -13,13 +12,13 @@ import { useProductContext } from '../../../products/productContext';
function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>) {
const { navMesh } = useNavMesh();
const { isPlaying } = usePlayButtonStore();
- const { materialStore, armBotStore, conveyorStore, vehicleStore, storageUnitStore } = useSceneContext();
+ const { materialStore, armBotStore, conveyorStore, vehicleStore, storageUnitStore, productStore } = useSceneContext();
const { removeMaterial, setEndTime } = materialStore();
const { getStorageUnitById } = storageUnitStore();
const { getArmBotById } = armBotStore();
const { getConveyorById } = conveyorStore();
const { triggerPointActions } = useTriggerHandler();
- const { getActionByUuid, getEventByModelUuid, getTriggerByUuid } = useProductStore();
+ const { getActionByUuid, getEventByModelUuid, getTriggerByUuid } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const { vehicles, setVehicleActive, setVehicleState, setVehiclePicking, clearCurrentMaterials, setVehicleLoad, decrementVehicleLoad, removeLastMaterial, getLastMaterial, incrementIdleTime, incrementActiveTime, resetTime } = vehicleStore();
diff --git a/app/src/modules/simulation/vehicle/navMesh/polygonGenerator.tsx b/app/src/modules/simulation/vehicle/navMesh/polygonGenerator.tsx
index a9aa9ed..eaf5a24 100644
--- a/app/src/modules/simulation/vehicle/navMesh/polygonGenerator.tsx
+++ b/app/src/modules/simulation/vehicle/navMesh/polygonGenerator.tsx
@@ -3,9 +3,8 @@ import { useEffect } from "react";
import * as turf from "@turf/turf";
import * as Types from "../../../../types/world/worldTypes";
import arrayLinesToObject from "../../../builder/geomentries/lines/lineConvertions/arrayLinesToObject";
-import { useAisleStore } from "../../../../store/builder/useAisleStore";
import { useThree } from "@react-three/fiber";
-import { clone } from "chart.js/dist/helpers/helpers.core";
+import { useSceneContext } from "../../../scene/sceneContext";
interface PolygonGeneratorProps {
groupRef: React.MutableRefObject;
@@ -16,7 +15,8 @@ export default function PolygonGenerator({
groupRef,
lines,
}: PolygonGeneratorProps) {
- const { aisles } = useAisleStore();
+ const { aisleStore } = useSceneContext();
+ const { aisles } = aisleStore();
const { scene } = useThree();
useEffect(() => {
diff --git a/app/src/pages/Dashboard.tsx b/app/src/pages/Dashboard.tsx
index 0ce9deb..15959c1 100644
--- a/app/src/pages/Dashboard.tsx
+++ b/app/src/pages/Dashboard.tsx
@@ -8,20 +8,11 @@ import DashboardTrash from "../components/Dashboard/DashboardTrash";
import { getUserData } from "../functions/getUserData";
import SidePannel from "../components/Dashboard/SidePannel";
import DashboardTutorial from "../components/Dashboard/DashboardTutorial";
-import { useProductStore } from "../store/simulation/useProductStore";
-import { useEventsStore } from "../store/simulation/useEventsStore";
const Dashboard: React.FC = () => {
const [activeTab, setActiveTab] = useState("Home");
const { socket } = useSocketStore();
const { organization, email } = getUserData();
- const { clearProducts } = useProductStore();
- const { clearEvents } = useEventsStore();
-
- useEffect(() => {
- clearEvents();
- clearProducts();
- }, [])
useEffect(() => {
const token = localStorage.getItem("token");
diff --git a/app/src/pages/Project.tsx b/app/src/pages/Project.tsx
index 3882239..34a9a24 100644
--- a/app/src/pages/Project.tsx
+++ b/app/src/pages/Project.tsx
@@ -20,7 +20,6 @@ import { useLogger } from "../components/ui/log/LoggerContext";
import RenderOverlay from "../components/templates/Overlay";
import LogList from "../components/ui/log/LogList";
import { useToggleStore } from "../store/useUIToggleStore";
-import { useProductStore } from "../store/simulation/useProductStore";
import { getAllProjects } from "../services/dashboard/getAllProjects";
import { viewProject } from "../services/dashboard/viewProject";
import ComparisonSceneProvider from "../components/layout/scenes/ComparisonSceneProvider";
@@ -42,14 +41,13 @@ const Project: React.FC = () => {
const { setWallItems } = useWallItems();
const { setZones } = useZones();
const { isVersionSaved } = useSaveVersion();
- const { setProducts } = useProductStore();
const { projectId } = useParams();
const { setProjectName } = useProjectName();
const { userId, email, organization, userName } = getUserData();
const { selectedUser } = useSelectedUserStore();
const { isLogListVisible } = useLogger();
const { setVersions } = useVersionHistoryStore();
- const { selectedComment, setSelectedComment, commentPositionState } = useSelectedComment();
+ const { selectedComment, commentPositionState } = useSelectedComment();
useEffect(() => {
if (!email || !userId) {
@@ -94,7 +92,6 @@ const Project: React.FC = () => {
useEffect(() => {
setWallItems([]);
setZones([]);
- setProducts([]);
setActiveModule("builder");
if (email) {
const token = localStorage.getItem("token");
diff --git a/app/src/store/builder/useAisleStore.ts b/app/src/store/builder/useAisleStore.ts
index a43b55e..35c79df 100644
--- a/app/src/store/builder/useAisleStore.ts
+++ b/app/src/store/builder/useAisleStore.ts
@@ -2,246 +2,250 @@ import { create } from "zustand";
import { immer } from "zustand/middleware/immer";
interface AisleStore {
- aisles: Aisles;
- setAisles: (aisles: Aisles) => void;
- addAisle: (aisle: Aisle) => void;
- updateAisle: (uuid: string, updated: Partial) => void;
- removeAisle: (uuid: string) => void;
- removePoint: (uuid: string) => Aisles;
- setPosition: (
- pointUuid: string,
- position: [number, number, number]
- ) => Aisle | undefined;
- setLayer: (pointUuid: string, layer: number) => void;
- setColor: (aisleUuid: string, color: AisleColors) => void;
+ aisles: Aisles;
+ setAisles: (aisles: Aisles) => void;
+ addAisle: (aisle: Aisle) => void;
+ updateAisle: (uuid: string, updated: Partial) => void;
+ removeAisle: (uuid: string) => void;
+ removePoint: (uuid: string) => Aisles;
+ setPosition: (
+ pointUuid: string,
+ position: [number, number, number]
+ ) => Aisle | undefined;
+ setLayer: (pointUuid: string, layer: number) => void;
+ setColor: (aisleUuid: string, color: AisleColors) => void;
- // Type-specific setters
- setSolidAisleWidth: (aisleUuid: string, width: number) => void;
- setDashedAisleProperties: (
- aisleUuid: string,
- props: { aisleWidth?: number; dashLength?: number; gapLength?: number }
- ) => void;
- setDottedAisleProperties: (
- aisleUuid: string,
- props: { dotRadius?: number; gapLength?: number }
- ) => void;
- setArrowAisleWidth: (aisleUuid: string, width: number) => void;
- setArrowsAisleProperties: (
- aisleUuid: string,
- props: { aisleWidth?: number; aisleLength?: number; gapLength?: number }
- ) => void;
- setArcAisleWidth: (
- aisleUuid: string,
- props: { aisleWidth?: number; isFlipped: boolean }
- ) => void;
- setCircleAisleWidth: (aisleUuid: string, width: number) => void;
- setJunctionAisleProperties: (
- aisleUuid: string,
- props: { aisleWidth?: number; isFlipped: boolean }
- ) => void;
+ // Type-specific setters
+ setSolidAisleWidth: (aisleUuid: string, width: number) => void;
+ setDashedAisleProperties: (
+ aisleUuid: string,
+ props: { aisleWidth?: number; dashLength?: number; gapLength?: number }
+ ) => void;
+ setDottedAisleProperties: (
+ aisleUuid: string,
+ props: { dotRadius?: number; gapLength?: number }
+ ) => void;
+ setArrowAisleWidth: (aisleUuid: string, width: number) => void;
+ setArrowsAisleProperties: (
+ aisleUuid: string,
+ props: { aisleWidth?: number; aisleLength?: number; gapLength?: number }
+ ) => void;
+ setArcAisleWidth: (
+ aisleUuid: string,
+ props: { aisleWidth?: number; isFlipped: boolean }
+ ) => void;
+ setCircleAisleWidth: (aisleUuid: string, width: number) => void;
+ setJunctionAisleProperties: (
+ aisleUuid: string,
+ props: { aisleWidth?: number; isFlipped: boolean }
+ ) => void;
- getAisleById: (uuid: string) => Aisle | undefined;
- getAislesByPointId: (uuid: string) => Aisle[] | [];
- getAislePointById: (uuid: string) => Point | undefined;
- getConnectedPoints: (uuid: string) => Point[] | [];
- getAisleType: (uuid: string) => T | undefined;
+ getAisleById: (uuid: string) => Aisle | undefined;
+ getAislesByPointId: (uuid: string) => Aisle[] | [];
+ getAislePointById: (uuid: string) => Point | undefined;
+ getConnectedPoints: (uuid: string) => Point[] | [];
+ getAisleType: (uuid: string) => T | undefined;
}
-export const useAisleStore = create()(
- immer((set, get) => ({
- aisles: [],
+export const createAisleStore = () => {
+ return create()(
+ immer((set, get) => ({
+ aisles: [],
- setAisles: (aisles) =>
- set((state) => {
- state.aisles = aisles;
- }),
+ setAisles: (aisles) =>
+ set((state) => {
+ state.aisles = aisles;
+ }),
- addAisle: (aisle) =>
- set((state) => {
- state.aisles.push(aisle);
- }),
+ addAisle: (aisle) =>
+ set((state) => {
+ state.aisles.push(aisle);
+ }),
- updateAisle: (uuid, updated) =>
- set((state) => {
- const aisle = state.aisles.find((a) => a.aisleUuid === uuid);
- if (aisle) {
- Object.assign(aisle, updated);
- }
- }),
+ updateAisle: (uuid, updated) =>
+ set((state) => {
+ const aisle = state.aisles.find((a) => a.aisleUuid === uuid);
+ if (aisle) {
+ Object.assign(aisle, updated);
+ }
+ }),
- removeAisle: (uuid) =>
- set((state) => {
- state.aisles = state.aisles.filter((a) => a.aisleUuid !== uuid);
- }),
+ removeAisle: (uuid) =>
+ set((state) => {
+ state.aisles = state.aisles.filter((a) => a.aisleUuid !== uuid);
+ }),
- removePoint: (uuid) => {
- const removedAisles: Aisle[] = [];
- set((state) => {
- state.aisles = state.aisles.filter((aisle) => {
- const hasPoint = aisle.points.some(
- (point) => point.pointUuid === uuid
- );
- if (hasPoint) {
- removedAisles.push(JSON.parse(JSON.stringify(aisle)));
- return false;
- }
- return true;
- });
- });
- return removedAisles;
- },
+ removePoint: (uuid) => {
+ const removedAisles: Aisle[] = [];
+ set((state) => {
+ state.aisles = state.aisles.filter((aisle) => {
+ const hasPoint = aisle.points.some(
+ (point) => point.pointUuid === uuid
+ );
+ if (hasPoint) {
+ removedAisles.push(JSON.parse(JSON.stringify(aisle)));
+ return false;
+ }
+ return true;
+ });
+ });
+ return removedAisles;
+ },
- setPosition: (pointUuid, position) => {
- let updatedAisle: Aisle | undefined;
- set((state) => {
- for (const aisle of state.aisles) {
- const point = aisle.points.find((p) => p.pointUuid === pointUuid);
- if (point) {
- point.position = position;
- updatedAisle = JSON.parse(JSON.stringify(aisle));
- }
- }
- });
- return updatedAisle;
- },
+ setPosition: (pointUuid, position) => {
+ let updatedAisle: Aisle | undefined;
+ set((state) => {
+ for (const aisle of state.aisles) {
+ const point = aisle.points.find((p) => p.pointUuid === pointUuid);
+ if (point) {
+ point.position = position;
+ updatedAisle = JSON.parse(JSON.stringify(aisle));
+ }
+ }
+ });
+ return updatedAisle;
+ },
- setLayer: (pointUuid, layer) =>
- set((state) => {
- for (const aisle of state.aisles) {
- const point = aisle.points.find((p) => p.pointUuid === pointUuid);
- if (point) {
- point.layer = layer;
- }
- }
- }),
+ setLayer: (pointUuid, layer) =>
+ set((state) => {
+ for (const aisle of state.aisles) {
+ const point = aisle.points.find((p) => p.pointUuid === pointUuid);
+ if (point) {
+ point.layer = layer;
+ }
+ }
+ }),
- setColor: (aisleUuid, color) =>
- set((state) => {
- const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
- if (aisle) {
- aisle.type.aisleColor = color;
- }
- }),
+ setColor: (aisleUuid, color) =>
+ set((state) => {
+ const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
+ if (aisle) {
+ aisle.type.aisleColor = color;
+ }
+ }),
- // Type-specific property setters
- setSolidAisleWidth: (aisleUuid, width) =>
- set((state) => {
- const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
- if (aisle && aisle.type.aisleType === "solid-aisle") {
- aisle.type.aisleWidth = width;
- }
- }),
+ // Type-specific property setters
+ setSolidAisleWidth: (aisleUuid, width) =>
+ set((state) => {
+ const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
+ if (aisle && aisle.type.aisleType === "solid-aisle") {
+ aisle.type.aisleWidth = width;
+ }
+ }),
- setDashedAisleProperties: (aisleUuid, props) =>
- set((state) => {
- const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
- if (aisle && aisle.type.aisleType === "dashed-aisle") {
- if (props.aisleWidth !== undefined)
- aisle.type.aisleWidth = props.aisleWidth;
- if (props.dashLength !== undefined)
- aisle.type.dashLength = props.dashLength;
- if (props.gapLength !== undefined)
- aisle.type.gapLength = props.gapLength;
- }
- }),
+ setDashedAisleProperties: (aisleUuid, props) =>
+ set((state) => {
+ const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
+ if (aisle && aisle.type.aisleType === "dashed-aisle") {
+ if (props.aisleWidth !== undefined)
+ aisle.type.aisleWidth = props.aisleWidth;
+ if (props.dashLength !== undefined)
+ aisle.type.dashLength = props.dashLength;
+ if (props.gapLength !== undefined)
+ aisle.type.gapLength = props.gapLength;
+ }
+ }),
- setDottedAisleProperties: (aisleUuid, props) =>
- set((state) => {
- const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
- if (aisle && aisle.type.aisleType === "dotted-aisle") {
- if (props.dotRadius !== undefined)
- aisle.type.dotRadius = props.dotRadius;
- if (props.gapLength !== undefined)
- aisle.type.gapLength = props.gapLength;
- }
- }),
+ setDottedAisleProperties: (aisleUuid, props) =>
+ set((state) => {
+ const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
+ if (aisle && aisle.type.aisleType === "dotted-aisle") {
+ if (props.dotRadius !== undefined)
+ aisle.type.dotRadius = props.dotRadius;
+ if (props.gapLength !== undefined)
+ aisle.type.gapLength = props.gapLength;
+ }
+ }),
- setArrowAisleWidth: (aisleUuid, width) =>
- set((state) => {
- const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
- if (aisle && aisle.type.aisleType === "arrow-aisle") {
- aisle.type.aisleWidth = width;
- }
- }),
+ setArrowAisleWidth: (aisleUuid, width) =>
+ set((state) => {
+ const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
+ if (aisle && aisle.type.aisleType === "arrow-aisle") {
+ aisle.type.aisleWidth = width;
+ }
+ }),
- setArrowsAisleProperties: (aisleUuid, props) =>
- set((state) => {
- const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
- if (aisle && aisle.type.aisleType === "arrows-aisle") {
- if (props.aisleWidth !== undefined)
- aisle.type.aisleWidth = props.aisleWidth;
- if (props.aisleLength !== undefined)
- aisle.type.aisleLength = props.aisleLength;
- if (props.gapLength !== undefined)
- aisle.type.gapLength = props.gapLength;
- }
- }),
+ setArrowsAisleProperties: (aisleUuid, props) =>
+ set((state) => {
+ const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
+ if (aisle && aisle.type.aisleType === "arrows-aisle") {
+ if (props.aisleWidth !== undefined)
+ aisle.type.aisleWidth = props.aisleWidth;
+ if (props.aisleLength !== undefined)
+ aisle.type.aisleLength = props.aisleLength;
+ if (props.gapLength !== undefined)
+ aisle.type.gapLength = props.gapLength;
+ }
+ }),
- setArcAisleWidth: (aisleUuid, props) =>
- set((state) => {
- const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
- if (aisle && aisle.type.aisleType === "arc-aisle") {
- if (props.aisleWidth !== undefined)
- aisle.type.aisleWidth = props.aisleWidth;
- if (props.isFlipped !== undefined)
- aisle.type.isFlipped = props.isFlipped;
- }
- }),
+ setArcAisleWidth: (aisleUuid, props) =>
+ set((state) => {
+ const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
+ if (aisle && aisle.type.aisleType === "arc-aisle") {
+ if (props.aisleWidth !== undefined)
+ aisle.type.aisleWidth = props.aisleWidth;
+ if (props.isFlipped !== undefined)
+ aisle.type.isFlipped = props.isFlipped;
+ }
+ }),
- setCircleAisleWidth: (aisleUuid, width) =>
- set((state) => {
- const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
- if (aisle && aisle.type.aisleType === "circle-aisle") {
- aisle.type.aisleWidth = width;
- }
- }),
+ setCircleAisleWidth: (aisleUuid, width) =>
+ set((state) => {
+ const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
+ if (aisle && aisle.type.aisleType === "circle-aisle") {
+ aisle.type.aisleWidth = width;
+ }
+ }),
- setJunctionAisleProperties: (aisleUuid, props) =>
- set((state) => {
- const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
- if (aisle && aisle.type.aisleType === "junction-aisle") {
- if (props.aisleWidth !== undefined)
- aisle.type.aisleWidth = props.aisleWidth;
- if (props.isFlipped !== undefined)
- aisle.type.isFlipped = props.isFlipped;
- }
- }),
+ setJunctionAisleProperties: (aisleUuid, props) =>
+ set((state) => {
+ const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
+ if (aisle && aisle.type.aisleType === "junction-aisle") {
+ if (props.aisleWidth !== undefined)
+ aisle.type.aisleWidth = props.aisleWidth;
+ if (props.isFlipped !== undefined)
+ aisle.type.isFlipped = props.isFlipped;
+ }
+ }),
- getAisleById: (uuid) => {
- return get().aisles.find((a) => a.aisleUuid === uuid);
- },
+ getAisleById: (uuid) => {
+ return get().aisles.find((a) => a.aisleUuid === uuid);
+ },
- getAislesByPointId: (uuid) => {
- return get().aisles.filter((a) => {
- return a.points.some((p) => p.pointUuid === uuid);
- })
- },
+ getAislesByPointId: (uuid) => {
+ return get().aisles.filter((a) => {
+ return a.points.some((p) => p.pointUuid === uuid);
+ })
+ },
- getAislePointById: (uuid) => {
- for (const aisle of get().aisles) {
- const point = aisle.points.find((p) => p.pointUuid === uuid);
- if (point) {
- return point;
- }
- }
- return undefined;
- },
+ getAislePointById: (uuid) => {
+ for (const aisle of get().aisles) {
+ const point = aisle.points.find((p) => p.pointUuid === uuid);
+ if (point) {
+ return point;
+ }
+ }
+ return undefined;
+ },
- getConnectedPoints: (uuid) => {
- const connected: Point[] = [];
- for (const aisle of get().aisles) {
- for (const point of aisle.points) {
- if (point.pointUuid === uuid) {
- connected.push(...aisle.points.filter((p) => p.pointUuid !== uuid));
- }
- }
- }
- return connected;
- },
+ getConnectedPoints: (uuid) => {
+ const connected: Point[] = [];
+ for (const aisle of get().aisles) {
+ for (const point of aisle.points) {
+ if (point.pointUuid === uuid) {
+ connected.push(...aisle.points.filter((p) => p.pointUuid !== uuid));
+ }
+ }
+ }
+ return connected;
+ },
- getAisleType: (uuid: string) => {
- const aisle = get().aisles.find((a) => a.aisleUuid === uuid);
- return aisle?.type as T | undefined;
- },
- }))
-);
+ getAisleType: (uuid: string) => {
+ const aisle = get().aisles.find((a) => a.aisleUuid === uuid);
+ return aisle?.type as T | undefined;
+ },
+ }))
+ )
+}
+
+export type AisleStoreType = ReturnType;
\ No newline at end of file
diff --git a/app/src/store/simulation/useEventsStore.ts b/app/src/store/simulation/useEventsStore.ts
index 105b0b5..becf55d 100644
--- a/app/src/store/simulation/useEventsStore.ts
+++ b/app/src/store/simulation/useEventsStore.ts
@@ -43,315 +43,319 @@ type EventsStore = {
getTriggerByUuid: (triggerUuid: string) => TriggerSchema | undefined;
};
-export const useEventsStore = create()(
- immer((set, get) => ({
- events: [],
+export const createEventStore = () => {
+ return create()(
+ immer((set, get) => ({
+ events: [],
- // Event-level actions
- addEvent: (event) => {
- set((state) => {
- if (!state.events.some(e => 'modelUuid' in e && e.modelUuid === event.modelUuid)) {
- state.events.push(event);
- }
- });
- },
-
- removeEvent: (modelUuid) => {
- set((state) => {
- state.events = state.events.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
- });
- },
-
- clearEvents: () => {
- set((state) => {
- state.events = [];
- });
- },
-
- updateEvent: (modelUuid, updates) => {
- let updatedEvent: EventsSchema | undefined;
- set((state) => {
- const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- if (event) {
- Object.assign(event, updates);
- updatedEvent = JSON.parse(JSON.stringify(event));
- }
- });
- return updatedEvent;
- },
-
- // Point-level actions
- addPoint: (modelUuid, point) => {
- set((state) => {
- const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- if (event && 'points' in event) {
- const existingPoint = (event as ConveyorEventSchema).points.find(p => p.uuid === point.uuid);
- if (!existingPoint) {
- (event as ConveyorEventSchema).points.push(point as ConveyorPointSchema);
+ // Event-level actions
+ addEvent: (event) => {
+ set((state) => {
+ if (!state.events.some(e => 'modelUuid' in e && e.modelUuid === event.modelUuid)) {
+ state.events.push(event);
}
- } else if (event && 'point' in event) {
- if (!(event as any).point || (event as any).point.uuid !== point.uuid) {
- (event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point = point as any;
- }
- }
- });
- },
+ });
+ },
- removePoint: (modelUuid, pointUuid) => {
- set((state) => {
- const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- if (event && 'points' in event) {
- (event as ConveyorEventSchema).points = (event as ConveyorEventSchema).points.filter(p => p.uuid !== pointUuid);
- }
- // For single-point events, you might want to handle differently
- });
- },
+ removeEvent: (modelUuid) => {
+ set((state) => {
+ state.events = state.events.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
+ });
+ },
- updatePoint: (modelUuid, pointUuid, updates) => {
- let updatedEvent: EventsSchema | undefined;
- set((state) => {
- const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- if (event && 'points' in event) {
- const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
- if (point) {
- Object.assign(point, updates);
+ clearEvents: () => {
+ set((state) => {
+ state.events = [];
+ });
+ },
+
+ updateEvent: (modelUuid, updates) => {
+ let updatedEvent: EventsSchema | undefined;
+ set((state) => {
+ const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ if (event) {
+ Object.assign(event, updates);
updatedEvent = JSON.parse(JSON.stringify(event));
}
- } else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
- Object.assign((event as any).point, updates);
- updatedEvent = JSON.parse(JSON.stringify(event));
- }
- });
- return updatedEvent;
- },
+ });
+ return updatedEvent;
+ },
- // Action-level actions
- addAction: (modelUuid, pointUuid, action) => {
- set((state) => {
- const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- if (event && 'points' in event) {
- const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
- if (point && (!point.action || point.action.actionUuid !== action.actionUuid)) {
- point.action = action as any;
- }
- } else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
- const point = (event as any).point;
- if ('action' in point && (!point.action || point.action.actionUuid !== action.actionUuid)) {
- point.action = action;
- } else if ('actions' in point && !point.actions.some((a: any) => a.actionUuid === action.actionUuid)) {
- point.actions.push(action);
- }
- }
- });
- },
-
- removeAction: (actionUuid) => {
- set((state) => {
- for (const event of state.events) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && point.action.actionUuid === actionUuid) {
- // Handle removal for single action points
- }
+ // Point-level actions
+ addPoint: (modelUuid, point) => {
+ set((state) => {
+ const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ if (event && 'points' in event) {
+ const existingPoint = (event as ConveyorEventSchema).points.find(p => p.uuid === point.uuid);
+ if (!existingPoint) {
+ (event as ConveyorEventSchema).points.push(point as ConveyorPointSchema);
}
- } else if ('point' in event) {
+ } else if (event && 'point' in event) {
+ if (!(event as any).point || (event as any).point.uuid !== point.uuid) {
+ (event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point = point as any;
+ }
+ }
+ });
+ },
+
+ removePoint: (modelUuid, pointUuid) => {
+ set((state) => {
+ const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ if (event && 'points' in event) {
+ (event as ConveyorEventSchema).points = (event as ConveyorEventSchema).points.filter(p => p.uuid !== pointUuid);
+ }
+ // For single-point events, you might want to handle differently
+ });
+ },
+
+ updatePoint: (modelUuid, pointUuid, updates) => {
+ let updatedEvent: EventsSchema | undefined;
+ set((state) => {
+ const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ if (event && 'points' in event) {
+ const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
+ if (point) {
+ Object.assign(point, updates);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ }
+ } else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
+ Object.assign((event as any).point, updates);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ }
+ });
+ return updatedEvent;
+ },
+
+ // Action-level actions
+ addAction: (modelUuid, pointUuid, action) => {
+ set((state) => {
+ const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ if (event && 'points' in event) {
+ const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
+ if (point && (!point.action || point.action.actionUuid !== action.actionUuid)) {
+ point.action = action as any;
+ }
+ } else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
const point = (event as any).point;
- if (event.type === "roboticArm") {
- if ('actions' in point) {
- point.actions = point.actions.filter((a: any) => a.actionUuid !== actionUuid);
- }
- } else if ('action' in point && point.action?.actionUuid === actionUuid) {
- // Handle single action
+ if ('action' in point && (!point.action || point.action.actionUuid !== action.actionUuid)) {
+ point.action = action;
+ } else if ('actions' in point && !point.actions.some((a: any) => a.actionUuid === action.actionUuid)) {
+ point.actions.push(action);
}
}
- }
- });
- },
+ });
+ },
- updateAction: (actionUuid, updates) => {
- set((state) => {
- for (const event of state.events) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && point.action.actionUuid === actionUuid) {
+ removeAction: (actionUuid) => {
+ set((state) => {
+ for (const event of state.events) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && point.action.actionUuid === actionUuid) {
+ // Handle removal for single action points
+ }
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if (event.type === "roboticArm") {
+ if ('actions' in point) {
+ point.actions = point.actions.filter((a: any) => a.actionUuid !== actionUuid);
+ }
+ } else if ('action' in point && point.action?.actionUuid === actionUuid) {
+ // Handle single action
+ }
+ }
+ }
+ });
+ },
+
+ updateAction: (actionUuid, updates) => {
+ set((state) => {
+ for (const event of state.events) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && point.action.actionUuid === actionUuid) {
+ Object.assign(point.action, updates);
+ return;
+ }
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && point.action.actionUuid === actionUuid) {
Object.assign(point.action, updates);
return;
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && point.action.actionUuid === actionUuid) {
- Object.assign(point.action, updates);
- return;
- } else if ('actions' in point) {
- const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
- if (action) {
- Object.assign(action, updates);
- return;
- }
- }
- }
- }
- });
- },
-
- // Trigger-level actions
- addTrigger: (actionUuid, trigger) => {
- set((state) => {
- for (const event of state.events) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && point.action.actionUuid === actionUuid) {
- if (!point.action.triggers.some(t => t.triggerUuid === trigger.triggerUuid)) {
- point.action.triggers.push(trigger);
- }
- return;
- }
- }
- } else if ('point' in event) {
- const point: MachinePointSchema | VehiclePointSchema = (event as any).point;
- if ('action' in point && point.action.actionUuid === actionUuid) {
- if (!point.action.triggers.some(t => t.triggerUuid === trigger.triggerUuid)) {
- point.action.triggers.push(trigger);
- }
- return;
- } else if ('actions' in point) {
- const action = (point as RoboticArmPointSchema).actions.find((a) => a.actionUuid === actionUuid);
- if (action && !action.triggers.some(t => t.triggerUuid === trigger.triggerUuid)) {
- action.triggers.push(trigger);
- return;
- }
- }
- }
- }
- });
- },
-
- removeTrigger: (triggerUuid) => {
- set((state) => {
- for (const event of state.events) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && 'triggers' in point.action) {
- point.action.triggers = point.action.triggers.filter(t => t.triggerUuid !== triggerUuid);
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && 'triggers' in point.action) {
- point.action.triggers = point.action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
- } else if ('actions' in point) {
- for (const action of point.actions) {
- if ('triggers' in action) {
- action.triggers = action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
- }
- }
- }
- }
- }
- });
- },
-
- updateTrigger: (triggerUuid, updates) => {
- set((state) => {
- for (const event of state.events) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && 'triggers' in point.action) {
- const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
- if (trigger) {
- Object.assign(trigger, updates);
+ } else if ('actions' in point) {
+ const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
+ if (action) {
+ Object.assign(action, updates);
return;
}
}
}
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && 'triggers' in point.action) {
- const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
- if (trigger) {
- Object.assign(trigger, updates);
- return;
+ }
+ });
+ },
+
+ // Trigger-level actions
+ addTrigger: (actionUuid, trigger) => {
+ set((state) => {
+ for (const event of state.events) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && point.action.actionUuid === actionUuid) {
+ if (!point.action.triggers.some(t => t.triggerUuid === trigger.triggerUuid)) {
+ point.action.triggers.push(trigger);
+ }
+ return;
+ }
}
- } else if ('actions' in point) {
- for (const action of point.actions) {
- if ('triggers' in action) {
- const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ } else if ('point' in event) {
+ const point: MachinePointSchema | VehiclePointSchema = (event as any).point;
+ if ('action' in point && point.action.actionUuid === actionUuid) {
+ if (!point.action.triggers.some(t => t.triggerUuid === trigger.triggerUuid)) {
+ point.action.triggers.push(trigger);
+ }
+ return;
+ } else if ('actions' in point) {
+ const action = (point as RoboticArmPointSchema).actions.find((a) => a.actionUuid === actionUuid);
+ if (action && !action.triggers.some(t => t.triggerUuid === trigger.triggerUuid)) {
+ action.triggers.push(trigger);
+ return;
+ }
+ }
+ }
+ }
+ });
+ },
+
+ removeTrigger: (triggerUuid) => {
+ set((state) => {
+ for (const event of state.events) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && 'triggers' in point.action) {
+ point.action.triggers = point.action.triggers.filter(t => t.triggerUuid !== triggerUuid);
+ }
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && 'triggers' in point.action) {
+ point.action.triggers = point.action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
+ } else if ('actions' in point) {
+ for (const action of point.actions) {
+ if ('triggers' in action) {
+ action.triggers = action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
+ }
+ }
+ }
+ }
+ }
+ });
+ },
+
+ updateTrigger: (triggerUuid, updates) => {
+ set((state) => {
+ for (const event of state.events) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && 'triggers' in point.action) {
+ const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
if (trigger) {
Object.assign(trigger, updates);
return;
}
}
}
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && 'triggers' in point.action) {
+ const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ if (trigger) {
+ Object.assign(trigger, updates);
+ return;
+ }
+ } else if ('actions' in point) {
+ for (const action of point.actions) {
+ if ('triggers' in action) {
+ const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ if (trigger) {
+ Object.assign(trigger, updates);
+ return;
+ }
+ }
+ }
+ }
}
}
+ });
+ },
+
+ // Helper functions
+ getEventByModelUuid: (modelUuid) => {
+ return get().events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ },
+
+ getPointByUuid: (modelUuid, pointUuid) => {
+ const event = get().events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ if (event && 'points' in event) {
+ return (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
+ } else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
+ return (event as any).point;
}
- });
- },
+ return undefined;
+ },
- // Helper functions
- getEventByModelUuid: (modelUuid) => {
- return get().events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- },
-
- getPointByUuid: (modelUuid, pointUuid) => {
- const event = get().events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- if (event && 'points' in event) {
- return (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
- } else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
- return (event as any).point;
- }
- return undefined;
- },
-
- getActionByUuid: (actionUuid) => {
- const state = get();
- for (const event of state.events) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && point.action.actionUuid === actionUuid) {
+ getActionByUuid: (actionUuid) => {
+ const state = get();
+ for (const event of state.events) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && point.action.actionUuid === actionUuid) {
+ return point.action;
+ }
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && point.action.actionUuid === actionUuid) {
return point.action;
+ } else if ('actions' in point) {
+ const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
+ if (action) return action;
}
}
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && point.action.actionUuid === actionUuid) {
- return point.action;
- } else if ('actions' in point) {
- const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
- if (action) return action;
- }
}
- }
- return undefined;
- },
+ return undefined;
+ },
- getTriggerByUuid: (triggerUuid) => {
- const state = get();
- for (const event of state.events) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && 'triggers' in point.action) {
- const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
- if (trigger) return trigger;
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && 'triggers' in point.action) {
- const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
- if (trigger) return trigger;
- } else if ('actions' in point) {
- for (const action of point.actions) {
- if ('triggers' in action) {
- const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ getTriggerByUuid: (triggerUuid) => {
+ const state = get();
+ for (const event of state.events) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && 'triggers' in point.action) {
+ const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
if (trigger) return trigger;
}
}
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && 'triggers' in point.action) {
+ const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ if (trigger) return trigger;
+ } else if ('actions' in point) {
+ for (const action of point.actions) {
+ if ('triggers' in action) {
+ const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ if (trigger) return trigger;
+ }
+ }
+ }
}
}
+ return undefined;
}
- return undefined;
- }
- }))
-);
+ }))
+ )
+}
+
+export type EventStoreType = ReturnType;
\ No newline at end of file
diff --git a/app/src/store/simulation/useProductStore.ts b/app/src/store/simulation/useProductStore.ts
index 7270233..695559d 100644
--- a/app/src/store/simulation/useProductStore.ts
+++ b/app/src/store/simulation/useProductStore.ts
@@ -75,370 +75,351 @@ type ProductsStore = {
getIsEventInProduct: (productUuid: string, modelUuid: string) => boolean;
};
-export const useProductStore = create()(
- immer((set, get) => ({
- products: [],
+export const createProductStore = () => {
+ return create()(
+ immer((set, get) => ({
+ products: [],
- // Product-level actions
- addProduct: (productName, productUuid) => {
- set((state) => {
- const existingProduct = state.products.find(p => p.productUuid === productUuid);
- if (!existingProduct) {
- const newProduct = {
- productName,
- productUuid: productUuid,
- eventDatas: []
- };
- state.products.push(newProduct);
- }
- });
- },
-
- setProducts: (products) => {
- set((state) => {
- state.products = products;
- });
- },
-
- clearProducts: () => {
- set((state) => {
- state.products = [];
- });
- },
-
- removeProduct: (productUuid) => {
- set((state) => {
- state.products = state.products.filter(p => p.productUuid !== productUuid);
- });
- },
-
- updateProduct: (productUuid, updates) => {
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- Object.assign(product, updates);
- }
- });
- },
-
- // Event-level actions
- addEvent: (productUuid, event) => {
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- const existingEvent = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === event.modelUuid);
- if (!existingEvent) {
- product.eventDatas.push(event);
+ // Product-level actions
+ addProduct: (productName, productUuid) => {
+ set((state) => {
+ const existingProduct = state.products.find(p => p.productUuid === productUuid);
+ if (!existingProduct) {
+ const newProduct = {
+ productName,
+ productUuid: productUuid,
+ eventDatas: []
+ };
+ state.products.push(newProduct);
}
- }
- });
- },
+ });
+ },
- removeEvent: (productUuid, modelUuid) => {
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- product.eventDatas = product.eventDatas.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
- }
- });
- },
+ setProducts: (products) => {
+ set((state) => {
+ state.products = products;
+ });
+ },
- deleteEvent: (modelUuid) => {
- set((state) => {
- for (const product of state.products) {
- product.eventDatas = product.eventDatas.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
- }
- });
- },
+ clearProducts: () => {
+ set((state) => {
+ state.products = [];
+ });
+ },
- updateEvent: (productUuid, modelUuid, updates) => {
- let updatedEvent: EventsSchema | undefined;
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- if (event) {
- Object.assign(event, updates);
- updatedEvent = JSON.parse(JSON.stringify(event));
+ removeProduct: (productUuid) => {
+ set((state) => {
+ state.products = state.products.filter(p => p.productUuid !== productUuid);
+ });
+ },
+
+ updateProduct: (productUuid, updates) => {
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ Object.assign(product, updates);
}
- }
- });
- return updatedEvent;
- },
+ });
+ },
- // Point-level actions
- addPoint: (productUuid, modelUuid, point) => {
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- if (event && 'points' in event) {
- const existingPoint = (event as ConveyorEventSchema).points.find(p => p.uuid === point.uuid);
- if (!existingPoint) {
- (event as ConveyorEventSchema).points.push(point as ConveyorPointSchema);
- }
- } else if (event && 'point' in event) {
- const existingPoint = (event as any).point?.uuid === point.uuid;
- if (!existingPoint) {
- (event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point = point as any;
+ // Event-level actions
+ addEvent: (productUuid, event) => {
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ const existingEvent = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === event.modelUuid);
+ if (!existingEvent) {
+ product.eventDatas.push(event);
}
}
- }
- });
- },
+ });
+ },
- removePoint: (productUuid, modelUuid, pointUuid) => {
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- if (event && 'points' in event) {
- (event as ConveyorEventSchema).points = (event as ConveyorEventSchema).points.filter(p => p.uuid !== pointUuid);
- } else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
- // For events with single point, we can't remove it, only reset to empty
+ removeEvent: (productUuid, modelUuid) => {
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ product.eventDatas = product.eventDatas.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
}
- }
- });
- },
+ });
+ },
- updatePoint: (productUuid, modelUuid, pointUuid, updates) => {
- let updatedEvent: EventsSchema | undefined;
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- if (event && 'points' in event) {
- const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
- if (point) {
- Object.assign(point, updates);
+ deleteEvent: (modelUuid) => {
+ set((state) => {
+ for (const product of state.products) {
+ product.eventDatas = product.eventDatas.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
+ }
+ });
+ },
+
+ updateEvent: (productUuid, modelUuid, updates) => {
+ let updatedEvent: EventsSchema | undefined;
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ if (event) {
+ Object.assign(event, updates);
updatedEvent = JSON.parse(JSON.stringify(event));
}
- } else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
- Object.assign((event as any).point, updates);
- updatedEvent = JSON.parse(JSON.stringify(event));
}
- }
- });
- return updatedEvent;
- },
+ });
+ return updatedEvent;
+ },
- // Action-level actions
- addAction: (productUuid, modelUuid, pointUuid, action) => {
- let updatedEvent: EventsSchema | undefined;
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- if (event && 'points' in event) {
- const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
- if (point && (!point.action || point.action.actionUuid !== action.actionUuid)) {
- point.action = action as any;
+ // Point-level actions
+ addPoint: (productUuid, modelUuid, point) => {
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ if (event && 'points' in event) {
+ const existingPoint = (event as ConveyorEventSchema).points.find(p => p.uuid === point.uuid);
+ if (!existingPoint) {
+ (event as ConveyorEventSchema).points.push(point as ConveyorPointSchema);
+ }
+ } else if (event && 'point' in event) {
+ const existingPoint = (event as any).point?.uuid === point.uuid;
+ if (!existingPoint) {
+ (event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point = point as any;
+ }
+ }
+ }
+ });
+ },
+
+ removePoint: (productUuid, modelUuid, pointUuid) => {
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ if (event && 'points' in event) {
+ (event as ConveyorEventSchema).points = (event as ConveyorEventSchema).points.filter(p => p.uuid !== pointUuid);
+ } else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
+ // For events with single point, we can't remove it, only reset to empty
+ }
+ }
+ });
+ },
+
+ updatePoint: (productUuid, modelUuid, pointUuid, updates) => {
+ let updatedEvent: EventsSchema | undefined;
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ if (event && 'points' in event) {
+ const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
+ if (point) {
+ Object.assign(point, updates);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ }
+ } else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
+ Object.assign((event as any).point, updates);
updatedEvent = JSON.parse(JSON.stringify(event));
}
- } else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
- if ('action' in (event as any).point) {
- if (!(event as any).point.action || (event as any).point.action.actionUuid !== action.actionUuid) {
- (event as any).point.action = action;
+ }
+ });
+ return updatedEvent;
+ },
+
+ // Action-level actions
+ addAction: (productUuid, modelUuid, pointUuid, action) => {
+ let updatedEvent: EventsSchema | undefined;
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ if (event && 'points' in event) {
+ const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
+ if (point && (!point.action || point.action.actionUuid !== action.actionUuid)) {
+ point.action = action as any;
updatedEvent = JSON.parse(JSON.stringify(event));
}
- } else if ('actions' in (event as any).point) {
- const existingAction = (event as any).point.actions.find((a: any) => a.actionUuid === action.actionUuid);
- if (!existingAction) {
- (event as any).point.actions.push(action);
- updatedEvent = JSON.parse(JSON.stringify(event));
+ } else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
+ if ('action' in (event as any).point) {
+ if (!(event as any).point.action || (event as any).point.action.actionUuid !== action.actionUuid) {
+ (event as any).point.action = action;
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ }
+ } else if ('actions' in (event as any).point) {
+ const existingAction = (event as any).point.actions.find((a: any) => a.actionUuid === action.actionUuid);
+ if (!existingAction) {
+ (event as any).point.actions.push(action);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ }
}
}
}
- }
- });
- return updatedEvent;
- },
+ });
+ return updatedEvent;
+ },
- removeAction: (productUuid, actionUuid) => {
- let updatedEvent: EventsSchema | undefined;
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- for (const event of product.eventDatas) {
- if ('points' in event) {
- // Handle ConveyorEventSchema
- for (const point of (event as ConveyorEventSchema).points) {
+ removeAction: (productUuid, actionUuid) => {
+ let updatedEvent: EventsSchema | undefined;
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ // Handle ConveyorEventSchema
+ for (const point of (event as ConveyorEventSchema).points) {
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if (event.type === "roboticArm") {
+ if ('actions' in point) {
+ const index = point.actions.findIndex((a: any) => a.actionUuid === actionUuid);
+ if (index !== -1) {
+ point.actions.splice(index, 1);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ return;
+ }
+ }
+ } else if ('action' in point && point.action?.actionUuid === actionUuid) {
+ point.action = undefined;
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ return;
+ }
}
- } else if ('point' in event) {
- const point = (event as any).point;
- if (event.type === "roboticArm") {
- if ('actions' in point) {
- const index = point.actions.findIndex((a: any) => a.actionUuid === actionUuid);
- if (index !== -1) {
- point.actions.splice(index, 1);
+ }
+ }
+ });
+ return updatedEvent;
+ },
+
+ updateAction: (productUuid, actionUuid, updates) => {
+ let updatedEvent: EventsSchema | undefined;
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && point.action.actionUuid === actionUuid) {
+ Object.assign(point.action, updates);
updatedEvent = JSON.parse(JSON.stringify(event));
return;
}
}
- } else if ('action' in point && point.action?.actionUuid === actionUuid) {
- point.action = undefined;
- updatedEvent = JSON.parse(JSON.stringify(event));
- return;
- }
- }
- }
- }
- });
- return updatedEvent;
- },
-
- updateAction: (productUuid, actionUuid, updates) => {
- let updatedEvent: EventsSchema | undefined;
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && point.action.actionUuid === actionUuid) {
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && point.action.actionUuid === actionUuid) {
Object.assign(point.action, updates);
updatedEvent = JSON.parse(JSON.stringify(event));
return;
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && point.action.actionUuid === actionUuid) {
- Object.assign(point.action, updates);
- updatedEvent = JSON.parse(JSON.stringify(event));
- return;
- } else if ('actions' in point) {
- const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
- if (action) {
- Object.assign(action, updates);
- updatedEvent = JSON.parse(JSON.stringify(event));
- return;
+ } else if ('actions' in point) {
+ const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
+ if (action) {
+ Object.assign(action, updates);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ return;
+ }
}
}
}
}
- }
- });
- return updatedEvent;
- },
+ });
+ return updatedEvent;
+ },
- // Trigger-level actions
- addTrigger: (productUuid, actionUuid, trigger) => {
- let updatedEvent: EventsSchema | undefined;
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && point.action.actionUuid === actionUuid) {
- const existingTrigger = point.action.triggers.find(t => t.triggerUuid === trigger.triggerUuid);
+ // Trigger-level actions
+ addTrigger: (productUuid, actionUuid, trigger) => {
+ let updatedEvent: EventsSchema | undefined;
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && point.action.actionUuid === actionUuid) {
+ const existingTrigger = point.action.triggers.find(t => t.triggerUuid === trigger.triggerUuid);
+ if (!existingTrigger) {
+ point.action.triggers.push(trigger);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ }
+ return;
+ }
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && point.action.actionUuid === actionUuid) {
+ const existingTrigger = point.action.triggers.find((t: any) => t.triggerUuid === trigger.triggerUuid);
if (!existingTrigger) {
point.action.triggers.push(trigger);
updatedEvent = JSON.parse(JSON.stringify(event));
}
return;
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && point.action.actionUuid === actionUuid) {
- const existingTrigger = point.action.triggers.find((t: any) => t.triggerUuid === trigger.triggerUuid);
- if (!existingTrigger) {
- point.action.triggers.push(trigger);
- updatedEvent = JSON.parse(JSON.stringify(event));
- }
- return;
- } else if ('actions' in point) {
- const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
- if (action) {
- const existingTrigger = action.triggers.find((t: any) => t.triggerUuid === trigger.triggerUuid);
- if (!existingTrigger) {
- action.triggers.push(trigger);
- updatedEvent = JSON.parse(JSON.stringify(event));
+ } else if ('actions' in point) {
+ const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
+ if (action) {
+ const existingTrigger = action.triggers.find((t: any) => t.triggerUuid === trigger.triggerUuid);
+ if (!existingTrigger) {
+ action.triggers.push(trigger);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ }
+ return;
}
- return;
}
}
}
}
- }
- });
- return updatedEvent;
- },
+ });
+ return updatedEvent;
+ },
- removeTrigger: (productUuid, triggerUuid) => {
- let updatedEvent: EventsSchema | undefined;
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && 'triggers' in point.action) {
- const Trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
- if (Trigger) {
- point.action.triggers = point.action.triggers.filter(t => t.triggerUuid !== triggerUuid);
- updatedEvent = JSON.parse(JSON.stringify(event));
+ removeTrigger: (productUuid, triggerUuid) => {
+ let updatedEvent: EventsSchema | undefined;
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && 'triggers' in point.action) {
+ const Trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
+ if (Trigger) {
+ point.action.triggers = point.action.triggers.filter(t => t.triggerUuid !== triggerUuid);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ }
}
}
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && 'triggers' in point.action) {
- const Trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
- if (Trigger) {
- point.action.triggers = point.action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
- updatedEvent = JSON.parse(JSON.stringify(event));
- }
- } else if ('actions' in point) {
- for (const action of point.actions) {
- if ('triggers' in action) {
- const Trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
- if (Trigger) {
- action.triggers = action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
- updatedEvent = JSON.parse(JSON.stringify(event));
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && 'triggers' in point.action) {
+ const Trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ if (Trigger) {
+ point.action.triggers = point.action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ }
+ } else if ('actions' in point) {
+ for (const action of point.actions) {
+ if ('triggers' in action) {
+ const Trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ if (Trigger) {
+ action.triggers = action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ }
}
}
}
}
}
}
- }
- });
- return updatedEvent;
- },
+ });
+ return updatedEvent;
+ },
- updateTrigger: (productUuid, triggerUuid, updates) => {
- let updatedEvent: EventsSchema | undefined;
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && 'triggers' in point.action) {
- const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
- if (trigger) {
- Object.assign(trigger, updates);
- updatedEvent = JSON.parse(JSON.stringify(event));
- return;
- }
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && 'triggers' in point.action) {
- const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
- if (trigger) {
- Object.assign(trigger, updates);
- updatedEvent = JSON.parse(JSON.stringify(event));
- return;
- }
- } else if ('actions' in point) {
- for (const action of point.actions) {
- if ('triggers' in action) {
- const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ updateTrigger: (productUuid, triggerUuid, updates) => {
+ let updatedEvent: EventsSchema | undefined;
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && 'triggers' in point.action) {
+ const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
if (trigger) {
Object.assign(trigger, updates);
updatedEvent = JSON.parse(JSON.stringify(event));
@@ -446,89 +427,89 @@ export const useProductStore = create()(
}
}
}
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && 'triggers' in point.action) {
+ const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ if (trigger) {
+ Object.assign(trigger, updates);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ return;
+ }
+ } else if ('actions' in point) {
+ for (const action of point.actions) {
+ if ('triggers' in action) {
+ const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ if (trigger) {
+ Object.assign(trigger, updates);
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ return;
+ }
+ }
+ }
+ }
}
}
}
- }
- });
- return updatedEvent;
- },
+ });
+ return updatedEvent;
+ },
- // Renaming functions
- renameProduct: (productUuid, newName) => {
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- product.productName = newName;
- }
- });
- },
+ // Renaming functions
+ renameProduct: (productUuid, newName) => {
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ product.productName = newName;
+ }
+ });
+ },
- renameAction: (productUuid, actionUuid, newName) => {
- let updatedEvent: EventsSchema | undefined;
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && point.action.actionUuid === actionUuid) {
+ renameAction: (productUuid, actionUuid, newName) => {
+ let updatedEvent: EventsSchema | undefined;
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && point.action.actionUuid === actionUuid) {
+ point.action.actionName = newName;
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ return;
+ }
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && point.action.actionUuid === actionUuid) {
point.action.actionName = newName;
updatedEvent = JSON.parse(JSON.stringify(event));
return;
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && point.action.actionUuid === actionUuid) {
- point.action.actionName = newName;
- updatedEvent = JSON.parse(JSON.stringify(event));
- return;
- } else if ('actions' in point) {
- const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
- if (action) {
- action.actionName = newName;
- updatedEvent = JSON.parse(JSON.stringify(event));
- return;
- }
- }
- }
- }
- }
- });
- return updatedEvent;
- },
-
- renameTrigger: (productUuid, triggerUuid, newName) => {
- let updatedEvent: EventsSchema | undefined;
- set((state) => {
- const product = state.products.find(p => p.productUuid === productUuid);
- if (product) {
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action && 'triggers' in point.action) {
- const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
- if (trigger) {
- trigger.triggerName = newName;
+ } else if ('actions' in point) {
+ const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
+ if (action) {
+ action.actionName = newName;
updatedEvent = JSON.parse(JSON.stringify(event));
return;
}
}
}
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && 'triggers' in point.action) {
- const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
- if (trigger) {
- trigger.triggerName = newName;
- updatedEvent = JSON.parse(JSON.stringify(event));
- return;
- }
- } else if ('actions' in point) {
- for (const action of point.actions) {
- if ('triggers' in action) {
- const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ }
+ }
+ });
+ return updatedEvent;
+ },
+
+ renameTrigger: (productUuid, triggerUuid, newName) => {
+ let updatedEvent: EventsSchema | undefined;
+ set((state) => {
+ const product = state.products.find(p => p.productUuid === productUuid);
+ if (product) {
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action && 'triggers' in point.action) {
+ const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
if (trigger) {
trigger.triggerName = newName;
updatedEvent = JSON.parse(JSON.stringify(event));
@@ -536,263 +517,286 @@ export const useProductStore = create()(
}
}
}
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && 'triggers' in point.action) {
+ const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ if (trigger) {
+ trigger.triggerName = newName;
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ return;
+ }
+ } else if ('actions' in point) {
+ for (const action of point.actions) {
+ if ('triggers' in action) {
+ const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
+ if (trigger) {
+ trigger.triggerName = newName;
+ updatedEvent = JSON.parse(JSON.stringify(event));
+ return;
+ }
+ }
+ }
+ }
}
}
}
- }
- });
- return updatedEvent;
- },
+ });
+ return updatedEvent;
+ },
- // Helper functions
- getProductById: (productUuid) => {
- return get().products.find(p => p.productUuid === productUuid);
- },
+ // Helper functions
+ getProductById: (productUuid) => {
+ return get().products.find(p => p.productUuid === productUuid);
+ },
- getEventByModelUuid: (productUuid, modelUuid) => {
- const product = get().getProductById(productUuid);
- if (!product) return undefined;
- return product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- },
+ getEventByModelUuid: (productUuid, modelUuid) => {
+ const product = get().getProductById(productUuid);
+ if (!product) return undefined;
+ return product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ },
- getEventByActionUuid: (productUuid, actionUuid) => {
- const product = get().getProductById(productUuid);
- if (!product) return undefined;
+ getEventByActionUuid: (productUuid, actionUuid) => {
+ const product = get().getProductById(productUuid);
+ if (!product) return undefined;
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action?.actionUuid === actionUuid) {
- return event;
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action?.actionUuid === actionUuid) {
+ return event;
+ }
}
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && point.action?.actionUuid === actionUuid) {
- return event;
- } else if ('actions' in point) {
- const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
- if (action) {
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && point.action?.actionUuid === actionUuid) {
return event;
- }
- }
- }
- }
- return undefined;
- },
-
- getEventByTriggerUuid: (productUuid, triggerUuid) => {
- const product = get().getProductById(productUuid);
- if (!product) return undefined;
-
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action?.triggers?.some(t => t.triggerUuid === triggerUuid)) {
- return event;
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point) {
- if (point.action?.triggers?.some((t: any) => t.triggerUuid === triggerUuid)) {
- return event;
- }
- } else if ('actions' in point) {
- for (const action of point.actions) {
- if (action.triggers?.some((t: any) => t.triggerUuid === triggerUuid)) {
+ } else if ('actions' in point) {
+ const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
+ if (action) {
return event;
}
}
}
}
- }
- return undefined;
- },
+ return undefined;
+ },
- getEventByPointUuid: (productUuid, pointUuid) => {
- const product = get().getProductById(productUuid);
- if (!product) return undefined;
+ getEventByTriggerUuid: (productUuid, triggerUuid) => {
+ const product = get().getProductById(productUuid);
+ if (!product) return undefined;
- for (const event of product.eventDatas) {
- if ('points' in event) {
- if ((event as ConveyorEventSchema).points.some(p => p.uuid === pointUuid)) {
- return event;
- }
- } else if ('point' in event) {
- if ((event as any).point?.uuid === pointUuid) {
- return event;
- }
- }
- }
- return undefined;
- },
-
- getPointByUuid: (productUuid, modelUuid, pointUuid) => {
- const event = get().getEventByModelUuid(productUuid, modelUuid);
- if (!event) return undefined;
-
- if ('points' in event) {
- return (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
- } else if ('point' in event && (event as any).point.uuid === pointUuid) {
- return (event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point;
- }
- return undefined;
- },
-
- getActionByUuid: (productUuid, actionUuid) => {
- const product = get().products.find(p => p.productUuid === productUuid);
- if (!product) return undefined;
-
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action?.actionUuid === actionUuid) {
- return point.action;
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && point.action?.actionUuid === actionUuid) {
- return point.action;
- } else if ('actions' in point) {
- const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
- if (action) return action;
- }
- }
- }
- return undefined;
- },
-
- getActionByPointUuid: (productUuid, pointUuid) => {
- const product = get().products.find(p => p.productUuid === productUuid);
- if (!product) return undefined;
-
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.uuid === pointUuid) {
- return point.action;
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if (point.uuid === pointUuid) {
- return point.action;
- }
- }
- }
- return undefined;
- },
-
- getModelUuidByPointUuid: (productUuid, pointUuid) => {
- const product = get().products.find(p => p.productUuid === productUuid);
- if (!product) return undefined;
-
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.uuid === pointUuid) {
- return event.modelUuid;
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if (point.uuid === pointUuid) {
- return event.modelUuid;
- }
- }
- }
- return undefined;
- },
-
- getModelUuidByActionUuid: (productUuid, actionUuid) => {
- const product = get().products.find(p => p.productUuid === productUuid);
- if (!product) return undefined;
-
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action?.actionUuid === actionUuid) {
- return event.modelUuid;
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && point.action?.actionUuid === actionUuid) {
- return event.modelUuid;
- } else if ('actions' in point) {
- const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
- if (action) return event.modelUuid;
- }
- }
- }
- return undefined;
- },
-
- getPointUuidByActionUuid: (productUuid, actionUuid) => {
- const product = get().products.find(p => p.productUuid === productUuid);
- if (!product) return undefined;
-
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- if (point.action?.actionUuid === actionUuid) {
- return point.uuid;
- }
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point && point.action?.actionUuid === actionUuid) {
- return point.uuid;
- } else if ('actions' in point) {
- const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
- if (action) return point.uuid;
- }
- }
- }
- return undefined;
- },
-
- getTriggerByUuid: (productUuid, triggerUuid) => {
- const product = get().products.find(p => p.productUuid === productUuid);
- if (!product) return undefined;
-
- for (const event of product.eventDatas) {
- if ('points' in event) {
- for (const point of (event as ConveyorEventSchema).points) {
- for (const trigger of point.action?.triggers || []) {
- if (trigger.triggerUuid === triggerUuid) {
- return trigger;
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action?.triggers?.some(t => t.triggerUuid === triggerUuid)) {
+ return event;
}
}
- }
- } else if ('point' in event) {
- const point = (event as any).point;
- if ('action' in point) {
- for (const trigger of point.action?.triggers || []) {
- if (trigger.triggerUuid === triggerUuid) {
- return trigger;
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point) {
+ if (point.action?.triggers?.some((t: any) => t.triggerUuid === triggerUuid)) {
+ return event;
}
- }
- } else if ('actions' in point) {
- for (const action of point.actions) {
- for (const trigger of action.triggers || []) {
- if (trigger.triggerUuid === triggerUuid) {
- return trigger;
+ } else if ('actions' in point) {
+ for (const action of point.actions) {
+ if (action.triggers?.some((t: any) => t.triggerUuid === triggerUuid)) {
+ return event;
}
}
}
}
}
- }
- return undefined;
- },
+ return undefined;
+ },
- getIsEventInProduct: (productUuid, modelUuid) => {
- const product = get().getProductById(productUuid);
- if (!product) return false;
- return product.eventDatas.some(e => 'modelUuid' in e && e.modelUuid === modelUuid);
- }
- }))
-);
+ getEventByPointUuid: (productUuid, pointUuid) => {
+ const product = get().getProductById(productUuid);
+ if (!product) return undefined;
+
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ if ((event as ConveyorEventSchema).points.some(p => p.uuid === pointUuid)) {
+ return event;
+ }
+ } else if ('point' in event) {
+ if ((event as any).point?.uuid === pointUuid) {
+ return event;
+ }
+ }
+ }
+ return undefined;
+ },
+
+ getPointByUuid: (productUuid, modelUuid, pointUuid) => {
+ const event = get().getEventByModelUuid(productUuid, modelUuid);
+ if (!event) return undefined;
+
+ if ('points' in event) {
+ return (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
+ } else if ('point' in event && (event as any).point.uuid === pointUuid) {
+ return (event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point;
+ }
+ return undefined;
+ },
+
+ getActionByUuid: (productUuid, actionUuid) => {
+ const product = get().products.find(p => p.productUuid === productUuid);
+ if (!product) return undefined;
+
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action?.actionUuid === actionUuid) {
+ return point.action;
+ }
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && point.action?.actionUuid === actionUuid) {
+ return point.action;
+ } else if ('actions' in point) {
+ const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
+ if (action) return action;
+ }
+ }
+ }
+ return undefined;
+ },
+
+ getActionByPointUuid: (productUuid, pointUuid) => {
+ const product = get().products.find(p => p.productUuid === productUuid);
+ if (!product) return undefined;
+
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.uuid === pointUuid) {
+ return point.action;
+ }
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if (point.uuid === pointUuid) {
+ return point.action;
+ }
+ }
+ }
+ return undefined;
+ },
+
+ getModelUuidByPointUuid: (productUuid, pointUuid) => {
+ const product = get().products.find(p => p.productUuid === productUuid);
+ if (!product) return undefined;
+
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.uuid === pointUuid) {
+ return event.modelUuid;
+ }
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if (point.uuid === pointUuid) {
+ return event.modelUuid;
+ }
+ }
+ }
+ return undefined;
+ },
+
+ getModelUuidByActionUuid: (productUuid, actionUuid) => {
+ const product = get().products.find(p => p.productUuid === productUuid);
+ if (!product) return undefined;
+
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action?.actionUuid === actionUuid) {
+ return event.modelUuid;
+ }
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && point.action?.actionUuid === actionUuid) {
+ return event.modelUuid;
+ } else if ('actions' in point) {
+ const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
+ if (action) return event.modelUuid;
+ }
+ }
+ }
+ return undefined;
+ },
+
+ getPointUuidByActionUuid: (productUuid, actionUuid) => {
+ const product = get().products.find(p => p.productUuid === productUuid);
+ if (!product) return undefined;
+
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ if (point.action?.actionUuid === actionUuid) {
+ return point.uuid;
+ }
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point && point.action?.actionUuid === actionUuid) {
+ return point.uuid;
+ } else if ('actions' in point) {
+ const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
+ if (action) return point.uuid;
+ }
+ }
+ }
+ return undefined;
+ },
+
+ getTriggerByUuid: (productUuid, triggerUuid) => {
+ const product = get().products.find(p => p.productUuid === productUuid);
+ if (!product) return undefined;
+
+ for (const event of product.eventDatas) {
+ if ('points' in event) {
+ for (const point of (event as ConveyorEventSchema).points) {
+ for (const trigger of point.action?.triggers || []) {
+ if (trigger.triggerUuid === triggerUuid) {
+ return trigger;
+ }
+ }
+ }
+ } else if ('point' in event) {
+ const point = (event as any).point;
+ if ('action' in point) {
+ for (const trigger of point.action?.triggers || []) {
+ if (trigger.triggerUuid === triggerUuid) {
+ return trigger;
+ }
+ }
+ } else if ('actions' in point) {
+ for (const action of point.actions) {
+ for (const trigger of action.triggers || []) {
+ if (trigger.triggerUuid === triggerUuid) {
+ return trigger;
+ }
+ }
+ }
+ }
+ }
+ }
+ return undefined;
+ },
+
+ getIsEventInProduct: (productUuid, modelUuid) => {
+ const product = get().getProductById(productUuid);
+ if (!product) return false;
+ return product.eventDatas.some(e => 'modelUuid' in e && e.modelUuid === modelUuid);
+ }
+ }))
+ )
+}
+
+export type ProductStoreType = ReturnType;
\ No newline at end of file