added multiple actions to storage unit
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { MathUtils } from "three";
|
||||||
import RenameInput from "../../../../../ui/inputs/RenameInput";
|
import RenameInput from "../../../../../ui/inputs/RenameInput";
|
||||||
import LabledDropdown from "../../../../../ui/inputs/LabledDropdown";
|
import LabledDropdown from "../../../../../ui/inputs/LabledDropdown";
|
||||||
import Trigger from "../trigger/Trigger";
|
import Trigger from "../trigger/Trigger";
|
||||||
@@ -6,79 +7,88 @@ import StorageAction from "../actions/StorageAction";
|
|||||||
import ActionsList from "../components/ActionsList";
|
import ActionsList from "../components/ActionsList";
|
||||||
import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
|
import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
|
||||||
import { useSelectedAction, useSelectedEventData } from "../../../../../../store/simulation/useSimulationStore";
|
import { useSelectedAction, useSelectedEventData } from "../../../../../../store/simulation/useSimulationStore";
|
||||||
import * as THREE from 'three';
|
|
||||||
import { useProductContext } from "../../../../../../modules/simulation/products/productContext";
|
import { useProductContext } from "../../../../../../modules/simulation/products/productContext";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useVersionContext } from "../../../../../../modules/builder/version/versionContext";
|
import { useVersionContext } from "../../../../../../modules/builder/version/versionContext";
|
||||||
import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
|
import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
|
||||||
|
|
||||||
function StorageMechanics() {
|
function StorageMechanics() {
|
||||||
const [activeOption, setActiveOption] = useState<"default" | "store" | "spawn">("default");
|
const [activeOption, setActiveOption] = useState<"store" | "spawn">("store");
|
||||||
const [currentCapacity, setCurrentCapacity] = useState("1");
|
const [currentCapacity, setCurrentCapacity] = useState("1");
|
||||||
const [spawnedCount, setSpawnedCount] = useState("0");
|
const [spawnedCount, setSpawnedCount] = useState("0");
|
||||||
const [spawnedMaterial, setSpawnedMaterial] = useState("Default material");
|
const [spawnedMaterial, setSpawnedMaterial] = useState("Default material");
|
||||||
const [selectedPointData, setSelectedPointData] = useState<StoragePointSchema | undefined>();
|
const [selectedPointData, setSelectedPointData] = useState<StoragePointSchema | undefined>();
|
||||||
|
const [currentAction, setCurrentAction] = useState<StorageAction | undefined>();
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventData } = useSelectedEventData();
|
||||||
const { productStore } = useSceneContext();
|
const { productStore } = useSceneContext();
|
||||||
const { getPointByUuid, updateAction, updateEvent, getEventByModelUuid } = productStore();
|
const { getPointByUuid, updateAction, updateEvent, getEventByModelUuid, getActionByUuid, addAction, removeAction } = productStore();
|
||||||
const { selectedProductStore } = useProductContext();
|
const { selectedProductStore } = useProductContext();
|
||||||
const { selectedProduct } = selectedProductStore();
|
const { selectedProduct } = selectedProductStore();
|
||||||
const { setSelectedAction, clearSelectedAction } = useSelectedAction();
|
const { selectedAction, setSelectedAction, clearSelectedAction } = useSelectedAction();
|
||||||
const { selectedVersionStore } = useVersionContext();
|
const { selectedVersionStore } = useVersionContext();
|
||||||
const { selectedVersion } = selectedVersionStore();
|
const { selectedVersion } = selectedVersionStore();
|
||||||
const { projectId } = useParams();
|
const { projectId } = useParams();
|
||||||
|
|
||||||
const updateSelectedPointData = () => {
|
|
||||||
if (selectedEventData && selectedProduct) {
|
|
||||||
const point = getPointByUuid(
|
|
||||||
selectedProduct.productUuid,
|
|
||||||
selectedEventData?.data.modelUuid,
|
|
||||||
selectedEventData?.selectedPoint
|
|
||||||
) as StoragePointSchema | undefined;
|
|
||||||
if (point && "action" in point) {
|
|
||||||
setSelectedPointData(point);
|
|
||||||
const uiOption = point.action.actionType === "retrieve" ? "spawn" : point.action.actionType;
|
|
||||||
setActiveOption(uiOption as "store" | "spawn");
|
|
||||||
setSelectedAction(point.action.actionUuid, point.action.actionName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedEventData) {
|
if (selectedEventData && selectedEventData.data.type === "storageUnit") {
|
||||||
const point = getPointByUuid(
|
const point = getPointByUuid(
|
||||||
selectedProduct.productUuid,
|
selectedProduct.productUuid,
|
||||||
selectedEventData?.data.modelUuid,
|
selectedEventData.data.modelUuid,
|
||||||
selectedEventData?.selectedPoint
|
selectedEventData.selectedPoint
|
||||||
) as StoragePointSchema | undefined;
|
) as StoragePointSchema | undefined;
|
||||||
if (point && "action" in point) {
|
|
||||||
|
if (point?.actions?.length) {
|
||||||
setSelectedPointData(point);
|
setSelectedPointData(point);
|
||||||
const uiOption = point.action.actionType === "retrieve" ? "spawn" : point.action.actionType;
|
const firstAction = point.actions[0];
|
||||||
setActiveOption(uiOption as "store" | "spawn");
|
setCurrentAction(firstAction);
|
||||||
setCurrentCapacity(
|
|
||||||
(getEventByModelUuid(
|
const eventData = getEventByModelUuid(
|
||||||
selectedProduct.productUuid,
|
selectedProduct.productUuid,
|
||||||
selectedEventData.data.modelUuid
|
selectedEventData.data.modelUuid
|
||||||
) as StorageEventSchema | undefined)?.storageCapacity?.toString() || "1"
|
) as StorageEventSchema | undefined;
|
||||||
);
|
|
||||||
setSpawnedCount(
|
setCurrentCapacity(eventData?.storageCapacity?.toString() || "1");
|
||||||
(getEventByModelUuid(
|
setSpawnedCount(eventData?.storageCount?.toString() || "0");
|
||||||
selectedProduct.productUuid,
|
setSpawnedMaterial(eventData?.materialType?.toString() || "Default material");
|
||||||
selectedEventData.data.modelUuid
|
|
||||||
) as StorageEventSchema | undefined)?.storageCount?.toString() || "0"
|
const actionUuid = selectedAction.actionId || firstAction.actionUuid;
|
||||||
)
|
const newCurrentAction = getActionByUuid(selectedProduct.productUuid, actionUuid);
|
||||||
setSpawnedMaterial(
|
|
||||||
(getEventByModelUuid(
|
if (newCurrentAction) {
|
||||||
selectedProduct.productUuid,
|
const uiOption = newCurrentAction.actionType === "retrieve" ? "spawn" : "store";
|
||||||
selectedEventData.data.modelUuid
|
setActiveOption(uiOption);
|
||||||
) as StorageEventSchema | undefined)?.materialType?.toString() || "Default material"
|
setSelectedAction(newCurrentAction.actionUuid, newCurrentAction.actionName);
|
||||||
)
|
}
|
||||||
setSelectedAction(point.action.actionUuid, point.action.actionName);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
clearSelectedAction();
|
clearSelectedAction();
|
||||||
|
setCurrentAction(undefined);
|
||||||
}
|
}
|
||||||
}, [selectedProduct, selectedEventData]);
|
}, [selectedEventData, selectedProduct]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedEventData && selectedEventData.data.type === "storageUnit" && selectedAction.actionId) {
|
||||||
|
const point = getPointByUuid(
|
||||||
|
selectedProduct.productUuid,
|
||||||
|
selectedEventData.data.modelUuid,
|
||||||
|
selectedEventData.selectedPoint
|
||||||
|
) as StoragePointSchema | undefined;
|
||||||
|
|
||||||
|
const newCurrentAction = getActionByUuid(selectedProduct.productUuid, selectedAction.actionId);
|
||||||
|
|
||||||
|
if (newCurrentAction && (newCurrentAction.actionType === 'store' || newCurrentAction.actionType === 'retrieve')) {
|
||||||
|
if (!selectedAction.actionId) {
|
||||||
|
setSelectedAction(newCurrentAction.actionUuid, newCurrentAction.actionName);
|
||||||
|
}
|
||||||
|
setCurrentAction(newCurrentAction);
|
||||||
|
const uiOption = newCurrentAction.actionType === "retrieve" ? "spawn" : "store";
|
||||||
|
setActiveOption(uiOption);
|
||||||
|
} else {
|
||||||
|
clearSelectedAction();
|
||||||
|
setCurrentAction(undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [selectedAction, selectedProduct, selectedEventData]);
|
||||||
|
|
||||||
const updateBackend = (
|
const updateBackend = (
|
||||||
productName: string,
|
productName: string,
|
||||||
@@ -96,14 +106,26 @@ function StorageMechanics() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleActionTypeChange = (option: string) => {
|
const handleActionTypeChange = (option: string) => {
|
||||||
if (!selectedEventData || !selectedPointData) return;
|
if (!selectedAction.actionId || !currentAction || !selectedPointData) return;
|
||||||
const internalOption = actionTypeMap[option as keyof typeof actionTypeMap] as "store" | "retrieve";
|
|
||||||
|
|
||||||
setActiveOption(option as "store" | "spawn");
|
const internalOption = option === "spawn" ? "retrieve" : "store";
|
||||||
|
|
||||||
const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, {
|
const updatedAction = {
|
||||||
actionType: internalOption,
|
...currentAction,
|
||||||
});
|
actionType: internalOption as "store" | "retrieve"
|
||||||
|
};
|
||||||
|
|
||||||
|
const updatedActions = selectedPointData.actions.map(action =>
|
||||||
|
action.actionUuid === updatedAction.actionUuid ? updatedAction : action
|
||||||
|
);
|
||||||
|
|
||||||
|
const updatedPoint = { ...selectedPointData, actions: updatedActions };
|
||||||
|
|
||||||
|
const event = updateAction(
|
||||||
|
selectedProduct.productUuid,
|
||||||
|
selectedAction.actionId,
|
||||||
|
updatedAction
|
||||||
|
);
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
updateBackend(
|
updateBackend(
|
||||||
@@ -112,58 +134,67 @@ function StorageMechanics() {
|
|||||||
projectId || '',
|
projectId || '',
|
||||||
event
|
event
|
||||||
);
|
);
|
||||||
updateSelectedPointData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCurrentAction(updatedAction);
|
||||||
|
setSelectedPointData(updatedPoint);
|
||||||
|
setActiveOption(option as "store" | "spawn");
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCapacityChange = (value: string) => {
|
const handleCapacityChange = (value: string) => {
|
||||||
if (!selectedEventData || !selectedPointData) return;
|
if (!selectedEventData) return;
|
||||||
|
|
||||||
const newCapacity = parseInt(value);
|
const numericValue = parseInt(value);
|
||||||
let updatedEvent: EventsSchema | undefined;
|
if (isNaN(numericValue)) return;
|
||||||
|
|
||||||
updatedEvent = updateEvent(
|
const updatedEvent = {
|
||||||
selectedProduct.productUuid,
|
...selectedEventData.data,
|
||||||
selectedEventData.data.modelUuid,
|
storageCapacity: numericValue
|
||||||
{ storageCapacity: newCapacity }
|
} as StorageEventSchema;
|
||||||
);
|
|
||||||
|
|
||||||
const currentCount = parseInt(spawnedCount);
|
const currentCount = parseInt(spawnedCount);
|
||||||
if (currentCount > newCapacity) {
|
if (currentCount > numericValue) {
|
||||||
updatedEvent = updateEvent(
|
updatedEvent.storageCount = numericValue;
|
||||||
|
setSpawnedCount(numericValue.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
const event = updateEvent(
|
||||||
|
selectedProduct.productUuid,
|
||||||
|
selectedEventData.data.modelUuid,
|
||||||
|
updatedEvent
|
||||||
|
);
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
updateBackend(
|
||||||
|
selectedProduct.productName,
|
||||||
selectedProduct.productUuid,
|
selectedProduct.productUuid,
|
||||||
selectedEventData.data.modelUuid,
|
projectId || '',
|
||||||
{ storageCount: newCapacity }
|
event
|
||||||
);
|
);
|
||||||
setSpawnedCount(newCapacity.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurrentCapacity(value);
|
setCurrentCapacity(value);
|
||||||
|
|
||||||
if (updatedEvent) {
|
|
||||||
updateBackend(
|
|
||||||
selectedProduct.productName,
|
|
||||||
selectedProduct.productUuid,
|
|
||||||
projectId || '',
|
|
||||||
updatedEvent
|
|
||||||
);
|
|
||||||
updateSelectedPointData();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSpawnCountChange = (value: string) => {
|
const handleSpawnCountChange = (value: string) => {
|
||||||
if (!selectedEventData || !selectedPointData) return;
|
if (!selectedEventData) return;
|
||||||
|
|
||||||
|
const numericValue = parseInt(value);
|
||||||
|
if (isNaN(numericValue)) return;
|
||||||
|
|
||||||
const newCount = parseInt(value);
|
|
||||||
const maxCapacity = parseInt(currentCapacity);
|
const maxCapacity = parseInt(currentCapacity);
|
||||||
|
if (numericValue > maxCapacity) return;
|
||||||
|
|
||||||
if (newCount > maxCapacity) return;
|
const updatedEvent = {
|
||||||
|
...selectedEventData.data,
|
||||||
|
storageCount: numericValue
|
||||||
|
} as StorageEventSchema;
|
||||||
|
|
||||||
const event = updateEvent(selectedProduct.productUuid, selectedEventData.data.modelUuid, {
|
const event = updateEvent(
|
||||||
storageCount: newCount,
|
selectedProduct.productUuid,
|
||||||
});
|
selectedEventData.data.modelUuid,
|
||||||
|
updatedEvent
|
||||||
setSpawnedCount(value);
|
);
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
updateBackend(
|
updateBackend(
|
||||||
@@ -172,16 +203,24 @@ function StorageMechanics() {
|
|||||||
projectId || '',
|
projectId || '',
|
||||||
event
|
event
|
||||||
);
|
);
|
||||||
updateSelectedPointData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSpawnedCount(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMaterialTypeChange = (value: string) => {
|
const handleMaterialTypeChange = (value: string) => {
|
||||||
if (!selectedEventData || !selectedPointData) return;
|
if (!selectedEventData) return;
|
||||||
|
|
||||||
const event = updateEvent(selectedProduct.productUuid, selectedEventData.data.modelUuid, {
|
const updatedEvent = {
|
||||||
materialType: value,
|
...selectedEventData.data,
|
||||||
});
|
materialType: value
|
||||||
|
} as StorageEventSchema;
|
||||||
|
|
||||||
|
const event = updateEvent(
|
||||||
|
selectedProduct.productUuid,
|
||||||
|
selectedEventData.data.modelUuid,
|
||||||
|
updatedEvent
|
||||||
|
);
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
updateBackend(
|
updateBackend(
|
||||||
@@ -190,28 +229,73 @@ function StorageMechanics() {
|
|||||||
projectId || '',
|
projectId || '',
|
||||||
event
|
event
|
||||||
);
|
);
|
||||||
updateSelectedPointData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSpawnedMaterial(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const currentActionName = useMemo(() =>
|
const handleAddAction = () => {
|
||||||
selectedPointData ? selectedPointData.action.actionName : "Action Name",
|
if (!selectedEventData || !selectedPointData) return;
|
||||||
[selectedPointData]
|
|
||||||
);
|
|
||||||
|
|
||||||
const availableActions = {
|
const newAction: StorageAction = {
|
||||||
defaultOption: "store",
|
actionUuid: MathUtils.generateUUID(),
|
||||||
options: ["store", "spawn"],
|
actionName: `Action ${selectedPointData.actions.length + 1}`,
|
||||||
|
actionType: "store",
|
||||||
|
triggers: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const updatedActions = [...(selectedPointData.actions || []), newAction];
|
||||||
|
const updatedPoint = { ...selectedPointData, actions: updatedActions };
|
||||||
|
|
||||||
|
const event = addAction(
|
||||||
|
selectedProduct.productUuid,
|
||||||
|
selectedEventData.data.modelUuid,
|
||||||
|
selectedEventData.selectedPoint,
|
||||||
|
newAction
|
||||||
|
);
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedPointData(updatedPoint);
|
||||||
|
setSelectedAction(newAction.actionUuid, newAction.actionName);
|
||||||
};
|
};
|
||||||
|
|
||||||
const actionTypeMap = {
|
const handleDeleteAction = (actionUuid: string) => {
|
||||||
spawn: "retrieve",
|
if (!selectedPointData || !actionUuid) return;
|
||||||
store: "store"
|
|
||||||
|
const updatedActions = selectedPointData.actions.filter(action => action.actionUuid !== actionUuid);
|
||||||
|
const updatedPoint = { ...selectedPointData, actions: updatedActions };
|
||||||
|
|
||||||
|
const event = removeAction(
|
||||||
|
selectedProduct.productUuid,
|
||||||
|
actionUuid
|
||||||
|
);
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedPointData(updatedPoint);
|
||||||
|
|
||||||
|
const index = selectedPointData.actions.findIndex((a) => a.actionUuid === selectedAction.actionId);
|
||||||
|
const nextAction = updatedPoint.actions[index] || updatedPoint.actions[index - 1];
|
||||||
|
if (nextAction) {
|
||||||
|
setSelectedAction(nextAction.actionUuid, nextAction.actionName);
|
||||||
|
const action = getActionByUuid(selectedProduct.productUuid, nextAction.actionUuid);
|
||||||
|
if (action) {
|
||||||
|
setCurrentAction(action as StorageAction);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
clearSelectedAction();
|
||||||
|
setCurrentAction(undefined);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{selectedEventData && (
|
{selectedEventData && selectedEventData.data.type === "storageUnit" && (
|
||||||
<>
|
<>
|
||||||
<section>
|
<section>
|
||||||
<StorageAction
|
<StorageAction
|
||||||
@@ -229,25 +313,33 @@ function StorageMechanics() {
|
|||||||
<section>
|
<section>
|
||||||
<ActionsList
|
<ActionsList
|
||||||
selectedPointData={selectedPointData}
|
selectedPointData={selectedPointData}
|
||||||
|
multipleAction={true}
|
||||||
|
handleAddAction={handleAddAction}
|
||||||
|
handleDeleteAction={handleDeleteAction}
|
||||||
/>
|
/>
|
||||||
<div className="selected-actions-details">
|
|
||||||
<div className="selected-actions-header">
|
{selectedAction.actionId && currentAction && (
|
||||||
<RenameInput
|
<div className="selected-actions-details">
|
||||||
value={currentActionName}
|
<div className="selected-actions-header">
|
||||||
canEdit={false}
|
<RenameInput
|
||||||
/>
|
value={selectedAction.actionName || ""}
|
||||||
|
canEdit={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="selected-actions-list">
|
||||||
|
<LabledDropdown
|
||||||
|
label="Action Type"
|
||||||
|
defaultOption={activeOption}
|
||||||
|
options={["store", "spawn"]}
|
||||||
|
onSelect={handleActionTypeChange}
|
||||||
|
disabled={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="tirgger">
|
||||||
|
<Trigger selectedPointData={selectedPointData as any} type={'StorageUnit'} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="selected-actions-list">
|
)}
|
||||||
<LabledDropdown
|
|
||||||
defaultOption={activeOption}
|
|
||||||
options={availableActions.options}
|
|
||||||
onSelect={handleActionTypeChange}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="tirgger">
|
|
||||||
<Trigger selectedPointData={selectedPointData as any} type={'StorageUnit'} />
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
|
|||||||
|
|
||||||
type TriggerProps = {
|
type TriggerProps = {
|
||||||
selectedPointData?: PointsScheme | undefined;
|
selectedPointData?: PointsScheme | undefined;
|
||||||
type?: "Conveyor" | "Vehicle" | "RoboticArm" | "Machine" | "StorageUnit" | "Human";
|
type?: "Conveyor" | "Vehicle" | "RoboticArm" | "Machine" | "StorageUnit" | "Human" | "Crane";
|
||||||
};
|
};
|
||||||
|
|
||||||
const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
@@ -36,9 +36,9 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
|||||||
|
|
||||||
let actionUuid: string | undefined;
|
let actionUuid: string | undefined;
|
||||||
|
|
||||||
if (type === "Conveyor" || type === "Vehicle" || type === "Machine" || type === "StorageUnit") {
|
if (type === "Conveyor" || type === "Vehicle" || type === "Machine") {
|
||||||
actionUuid = (selectedPointData as | ConveyorPointSchema | VehiclePointSchema | MachinePointSchema | StoragePointSchema).action?.actionUuid;
|
actionUuid = (selectedPointData as | ConveyorPointSchema | VehiclePointSchema | MachinePointSchema).action?.actionUuid;
|
||||||
} else if ((type === "RoboticArm" || type === "Human") && selectedAction.actionId) {
|
} else if ((type === "RoboticArm" || type === "Human" || type === "StorageUnit" || type === 'Crane') && selectedAction.actionId) {
|
||||||
actionUuid = selectedAction.actionId;
|
actionUuid = selectedAction.actionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -240,12 +240,14 @@ function AssetsGroup({ plane }: { readonly plane: RefMesh }) {
|
|||||||
uuid: item.eventData.point?.uuid || THREE.MathUtils.generateUUID(),
|
uuid: item.eventData.point?.uuid || THREE.MathUtils.generateUUID(),
|
||||||
position: [item.eventData.point?.position[0] || 0, item.eventData.point?.position[1] || 0, item.eventData.point?.position[2] || 0],
|
position: [item.eventData.point?.position[0] || 0, item.eventData.point?.position[1] || 0, item.eventData.point?.position[2] || 0],
|
||||||
rotation: [item.eventData.point?.rotation[0] || 0, item.eventData.point?.rotation[1] || 0, item.eventData.point?.rotation[2] || 0],
|
rotation: [item.eventData.point?.rotation[0] || 0, item.eventData.point?.rotation[1] || 0, item.eventData.point?.rotation[2] || 0],
|
||||||
action: {
|
actions: [
|
||||||
actionUuid: THREE.MathUtils.generateUUID(),
|
{
|
||||||
actionName: "Action 1",
|
actionUuid: THREE.MathUtils.generateUUID(),
|
||||||
actionType: "store",
|
actionName: "Action 1",
|
||||||
triggers: []
|
actionType: "store",
|
||||||
}
|
triggers: []
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
addEvent(storageEvent);
|
addEvent(storageEvent);
|
||||||
|
|||||||
@@ -353,12 +353,14 @@ async function handleModelLoad(
|
|||||||
uuid: THREE.MathUtils.generateUUID(),
|
uuid: THREE.MathUtils.generateUUID(),
|
||||||
position: [data.points[0].x, data.points[0].y, data.points[0].z],
|
position: [data.points[0].x, data.points[0].y, data.points[0].z],
|
||||||
rotation: [0, 0, 0],
|
rotation: [0, 0, 0],
|
||||||
action: {
|
actions: [
|
||||||
actionUuid: THREE.MathUtils.generateUUID(),
|
{
|
||||||
actionName: "Action 1",
|
actionUuid: THREE.MathUtils.generateUUID(),
|
||||||
actionType: "store",
|
actionName: "Action 1",
|
||||||
triggers: [],
|
actionType: "store",
|
||||||
},
|
triggers: [],
|
||||||
|
}
|
||||||
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
addEvent(storageEvent);
|
addEvent(storageEvent);
|
||||||
|
|||||||
@@ -383,12 +383,14 @@ const CopyPasteControls3D = ({
|
|||||||
uuid: THREE.MathUtils.generateUUID(),
|
uuid: THREE.MathUtils.generateUUID(),
|
||||||
position: [updatedEventData.point.position[0], updatedEventData.point.position[1], updatedEventData.point.position[2]],
|
position: [updatedEventData.point.position[0], updatedEventData.point.position[1], updatedEventData.point.position[2]],
|
||||||
rotation: [updatedEventData.point.rotation[0], updatedEventData.point.rotation[1], updatedEventData.point.rotation[2]],
|
rotation: [updatedEventData.point.rotation[0], updatedEventData.point.rotation[1], updatedEventData.point.rotation[2]],
|
||||||
action: {
|
actions: [
|
||||||
actionUuid: THREE.MathUtils.generateUUID(),
|
{
|
||||||
actionName: "Action 1",
|
actionUuid: THREE.MathUtils.generateUUID(),
|
||||||
actionType: "store",
|
actionName: "Action 1",
|
||||||
triggers: []
|
actionType: "store",
|
||||||
}
|
triggers: []
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addEvent(storageEvent);
|
addEvent(storageEvent);
|
||||||
|
|||||||
@@ -453,12 +453,14 @@ const DuplicationControls3D = ({
|
|||||||
uuid: THREE.MathUtils.generateUUID(),
|
uuid: THREE.MathUtils.generateUUID(),
|
||||||
position: [updatedEventData.point.position[0], updatedEventData.point.position[1], updatedEventData.point.position[2]],
|
position: [updatedEventData.point.position[0], updatedEventData.point.position[1], updatedEventData.point.position[2]],
|
||||||
rotation: [updatedEventData.point.rotation[0], updatedEventData.point.rotation[1], updatedEventData.point.rotation[2]],
|
rotation: [updatedEventData.point.rotation[0], updatedEventData.point.rotation[1], updatedEventData.point.rotation[2]],
|
||||||
action: {
|
actions: [
|
||||||
actionUuid: THREE.MathUtils.generateUUID(),
|
{
|
||||||
actionName: "Action 1",
|
actionUuid: THREE.MathUtils.generateUUID(),
|
||||||
actionType: "store",
|
actionName: "Action 1",
|
||||||
triggers: []
|
actionType: "store",
|
||||||
}
|
triggers: []
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addEvent(storageEvent);
|
addEvent(storageEvent);
|
||||||
|
|||||||
@@ -171,8 +171,9 @@ export function useRetrieveHandler() {
|
|||||||
if (retrieval.action.triggers[0]?.triggeredAsset.triggeredAction?.actionUuid) {
|
if (retrieval.action.triggers[0]?.triggeredAsset.triggeredAction?.actionUuid) {
|
||||||
const action = getActionByUuid(selectedProduct.productUuid, retrieval.action.triggers[0]?.triggeredAsset.triggeredAction.actionUuid);
|
const action = getActionByUuid(selectedProduct.productUuid, retrieval.action.triggers[0]?.triggeredAsset.triggeredAction.actionUuid);
|
||||||
if (action && action.triggers.length > 0 && action.triggers[0]?.triggeredAsset?.triggeredModel.modelUuid) {
|
if (action && action.triggers.length > 0 && action.triggers[0]?.triggeredAsset?.triggeredModel.modelUuid) {
|
||||||
const model = getEventByModelUuid(selectedProduct.productUuid, action.triggers[0]?.triggeredAsset.triggeredModel.modelUuid);
|
const model = getEventByModelUuid(selectedProduct.productUuid, action?.triggers[0]?.triggeredAsset?.triggeredModel.modelUuid || '');
|
||||||
if (model) {
|
const triggeredAction = getActionByUuid(selectedProduct.productUuid, action?.triggers[0]?.triggeredAsset?.triggeredAction?.actionUuid || '');
|
||||||
|
if (model && triggeredAction) {
|
||||||
if (model.type === 'vehicle') {
|
if (model.type === 'vehicle') {
|
||||||
const vehicle = getVehicleById(model.modelUuid);
|
const vehicle = getVehicleById(model.modelUuid);
|
||||||
if (vehicle && !vehicle.isActive && vehicle.state === 'idle' && vehicle.isPicking && vehicle.currentLoad < vehicle.point.action.loadCapacity) {
|
if (vehicle && !vehicle.isActive && vehicle.state === 'idle' && vehicle.isPicking && vehicle.currentLoad < vehicle.point.action.loadCapacity) {
|
||||||
@@ -180,7 +181,7 @@ export function useRetrieveHandler() {
|
|||||||
const material = createNewMaterial(
|
const material = createNewMaterial(
|
||||||
lastMaterial.materialId,
|
lastMaterial.materialId,
|
||||||
lastMaterial.materialType,
|
lastMaterial.materialType,
|
||||||
storageUnit.point.action
|
triggeredAction as StorageAction
|
||||||
);
|
);
|
||||||
if (material) {
|
if (material) {
|
||||||
|
|
||||||
@@ -193,11 +194,11 @@ export function useRetrieveHandler() {
|
|||||||
retrieveLogStatus(material.materialName, `is being picked by ${armBot?.modelName}`);
|
retrieveLogStatus(material.materialName, `is being picked by ${armBot?.modelName}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (triggeredAction) {
|
||||||
const material = createNewMaterial(
|
const material = createNewMaterial(
|
||||||
lastMaterial.materialId,
|
lastMaterial.materialId,
|
||||||
lastMaterial.materialType,
|
lastMaterial.materialType,
|
||||||
storageUnit.point.action
|
triggeredAction as StorageAction
|
||||||
);
|
);
|
||||||
if (material) {
|
if (material) {
|
||||||
|
|
||||||
@@ -271,10 +272,15 @@ export function useRetrieveHandler() {
|
|||||||
const lastMaterial = getLastMaterial(storageUnit.modelUuid);
|
const lastMaterial = getLastMaterial(storageUnit.modelUuid);
|
||||||
if (lastMaterial) {
|
if (lastMaterial) {
|
||||||
if (vehicle?.currentLoad < vehicle.point.action.loadCapacity) {
|
if (vehicle?.currentLoad < vehicle.point.action.loadCapacity) {
|
||||||
|
const triggeredAction = getActionByUuid(
|
||||||
|
selectedProduct.productUuid,
|
||||||
|
retrieval.action.triggers[0]?.triggeredAsset.triggeredAction?.actionUuid || ''
|
||||||
|
);
|
||||||
|
|
||||||
const material = createNewMaterial(
|
const material = createNewMaterial(
|
||||||
lastMaterial.materialId,
|
lastMaterial.materialId,
|
||||||
lastMaterial.materialType,
|
lastMaterial.materialType,
|
||||||
storageUnit.point.action
|
triggeredAction as StorageAction
|
||||||
);
|
);
|
||||||
|
|
||||||
if (material) {
|
if (material) {
|
||||||
@@ -322,6 +328,12 @@ export function useRetrieveHandler() {
|
|||||||
const triggeredModel = action.triggers[0]?.triggeredAsset?.triggeredModel?.modelUuid
|
const triggeredModel = action.triggers[0]?.triggeredAsset?.triggeredModel?.modelUuid
|
||||||
? getEventByModelUuid(selectedProduct.productUuid, action.triggers[0].triggeredAsset.triggeredModel.modelUuid)
|
? getEventByModelUuid(selectedProduct.productUuid, action.triggers[0].triggeredAsset.triggeredModel.modelUuid)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
const triggeredAction = getActionByUuid(
|
||||||
|
selectedProduct.productUuid,
|
||||||
|
action.triggers[0]?.triggeredAsset?.triggeredAction?.actionUuid || ''
|
||||||
|
);
|
||||||
|
|
||||||
if (triggeredModel?.type === 'vehicle') {
|
if (triggeredModel?.type === 'vehicle') {
|
||||||
const model = getVehicleById(triggeredModel.modelUuid);
|
const model = getVehicleById(triggeredModel.modelUuid);
|
||||||
if (model && !model.isActive && model.state === 'idle' && model.isPicking && model.currentLoad < model.point.action.loadCapacity) {
|
if (model && !model.isActive && model.state === 'idle' && model.isPicking && model.currentLoad < model.point.action.loadCapacity) {
|
||||||
@@ -333,7 +345,7 @@ export function useRetrieveHandler() {
|
|||||||
const material = createNewMaterial(
|
const material = createNewMaterial(
|
||||||
lastMaterial.materialId,
|
lastMaterial.materialId,
|
||||||
lastMaterial.materialType,
|
lastMaterial.materialType,
|
||||||
storageUnit.point.action
|
triggeredAction as StorageAction
|
||||||
);
|
);
|
||||||
if (material) {
|
if (material) {
|
||||||
removeLastMaterial(storageUnit.modelUuid);
|
removeLastMaterial(storageUnit.modelUuid);
|
||||||
@@ -359,7 +371,7 @@ export function useRetrieveHandler() {
|
|||||||
const material = createNewMaterial(
|
const material = createNewMaterial(
|
||||||
lastMaterial.materialId,
|
lastMaterial.materialId,
|
||||||
lastMaterial.materialType,
|
lastMaterial.materialType,
|
||||||
storageUnit.point.action
|
triggeredAction as StorageAction
|
||||||
);
|
);
|
||||||
if (material) {
|
if (material) {
|
||||||
removeLastMaterial(storageUnit.modelUuid);
|
removeLastMaterial(storageUnit.modelUuid);
|
||||||
@@ -385,7 +397,7 @@ export function useRetrieveHandler() {
|
|||||||
const material = createNewMaterial(
|
const material = createNewMaterial(
|
||||||
lastMaterial.materialId,
|
lastMaterial.materialId,
|
||||||
lastMaterial.materialType,
|
lastMaterial.materialType,
|
||||||
storageUnit.point.action
|
triggeredAction as StorageAction
|
||||||
);
|
);
|
||||||
if (material) {
|
if (material) {
|
||||||
removeLastMaterial(storageUnit.modelUuid);
|
removeLastMaterial(storageUnit.modelUuid);
|
||||||
@@ -417,7 +429,7 @@ export function useRetrieveHandler() {
|
|||||||
const material = createNewMaterial(
|
const material = createNewMaterial(
|
||||||
lastMaterial.materialId,
|
lastMaterial.materialId,
|
||||||
lastMaterial.materialType,
|
lastMaterial.materialType,
|
||||||
storageUnit.point.action
|
triggeredAction as StorageAction
|
||||||
);
|
);
|
||||||
if (material) {
|
if (material) {
|
||||||
removeLastMaterial(storageUnit.modelUuid);
|
removeLastMaterial(storageUnit.modelUuid);
|
||||||
@@ -438,7 +450,7 @@ export function useRetrieveHandler() {
|
|||||||
const material = createNewMaterial(
|
const material = createNewMaterial(
|
||||||
lastMaterial.materialId,
|
lastMaterial.materialId,
|
||||||
lastMaterial.materialType,
|
lastMaterial.materialType,
|
||||||
storageUnit.point.action
|
triggeredAction as StorageAction
|
||||||
);
|
);
|
||||||
if (material) {
|
if (material) {
|
||||||
removeLastMaterial(storageUnit.modelUuid);
|
removeLastMaterial(storageUnit.modelUuid);
|
||||||
@@ -484,10 +496,15 @@ export function useRetrieveHandler() {
|
|||||||
|
|
||||||
const lastMaterial = getLastMaterial(storageUnit.modelUuid);
|
const lastMaterial = getLastMaterial(storageUnit.modelUuid);
|
||||||
if (lastMaterial) {
|
if (lastMaterial) {
|
||||||
|
const triggeredAction = getActionByUuid(
|
||||||
|
selectedProduct.productUuid,
|
||||||
|
action?.triggers[0]?.triggeredAsset?.triggeredAction?.actionUuid || ''
|
||||||
|
);
|
||||||
|
|
||||||
const material = createNewMaterial(
|
const material = createNewMaterial(
|
||||||
lastMaterial.materialId,
|
lastMaterial.materialId,
|
||||||
lastMaterial.materialType,
|
lastMaterial.materialType,
|
||||||
storageUnit.point.action
|
triggeredAction as StorageAction
|
||||||
);
|
);
|
||||||
if (material) {
|
if (material) {
|
||||||
removeLastMaterial(storageUnit.modelUuid);
|
removeLastMaterial(storageUnit.modelUuid);
|
||||||
|
|||||||
@@ -144,8 +144,8 @@ function TriggerConnector() {
|
|||||||
// Handle StorageUnit point
|
// Handle StorageUnit point
|
||||||
else if (event.type === "storageUnit" && 'point' in event) {
|
else if (event.type === "storageUnit" && 'point' in event) {
|
||||||
const point = event.point;
|
const point = event.point;
|
||||||
if (point.action?.triggers) {
|
point.actions?.forEach(action => {
|
||||||
point.action.triggers.forEach(trigger => {
|
action.triggers?.forEach(trigger => {
|
||||||
if (trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint) {
|
if (trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint) {
|
||||||
newConnections.push({
|
newConnections.push({
|
||||||
id: `${point.uuid}-${trigger.triggeredAsset.triggeredPoint.pointUuid}-${trigger.triggerUuid}`,
|
id: `${point.uuid}-${trigger.triggeredAsset.triggeredPoint.pointUuid}-${trigger.triggerUuid}`,
|
||||||
@@ -155,7 +155,7 @@ function TriggerConnector() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
// Handle Human point
|
// Handle Human point
|
||||||
else if (event.type === "human" && 'point' in event) {
|
else if (event.type === "human" && 'point' in event) {
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ function WorkerInstance({ human }: { human: HumanStatus }) {
|
|||||||
if (!human.isActive && human.state === 'idle' && human.currentPhase === 'init') {
|
if (!human.isActive && human.state === 'idle' && human.currentPhase === 'init') {
|
||||||
const humanMesh = scene.getObjectByProperty('uuid', human.modelUuid);
|
const humanMesh = scene.getObjectByProperty('uuid', human.modelUuid);
|
||||||
if (!humanMesh) return;
|
if (!humanMesh) return;
|
||||||
|
|
||||||
const toPickupPath = computePath(humanMesh.position.toArray(), action?.pickUpPoint?.position || [0, 0, 0]);
|
const toPickupPath = computePath(humanMesh.position.toArray(), action?.pickUpPoint?.position || [0, 0, 0]);
|
||||||
|
|
||||||
setPath(toPickupPath);
|
setPath(toPickupPath);
|
||||||
@@ -233,15 +233,13 @@ function WorkerInstance({ human }: { human: HumanStatus }) {
|
|||||||
|
|
||||||
const checkAnimation = () => {
|
const checkAnimation = () => {
|
||||||
if (humanAsset?.animationState?.isCompleted) {
|
if (humanAsset?.animationState?.isCompleted) {
|
||||||
if (model.point.action.actionType === 'store') {
|
loopMaterialDropToStorage(
|
||||||
loopMaterialDropToStorage(
|
human.modelUuid,
|
||||||
human.modelUuid,
|
human.currentLoad,
|
||||||
human.currentLoad,
|
model.modelUuid,
|
||||||
model.modelUuid,
|
model.storageCapacity,
|
||||||
model.storageCapacity,
|
(action as HumanAction)
|
||||||
(action as HumanAction)
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
requestAnimationFrame(checkAnimation);
|
requestAnimationFrame(checkAnimation);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,16 +388,14 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>)
|
|||||||
|
|
||||||
function handleMaterialDropToStorageUnit(model: StorageEventSchema) {
|
function handleMaterialDropToStorageUnit(model: StorageEventSchema) {
|
||||||
if (model) {
|
if (model) {
|
||||||
if (model.point.action.actionType === 'store') {
|
loopMaterialDropToStorage(
|
||||||
loopMaterialDropToStorage(
|
agvDetail.modelUuid,
|
||||||
agvDetail.modelUuid,
|
agvDetail.currentLoad,
|
||||||
agvDetail.currentLoad,
|
agvDetail.point.action.unLoadDuration,
|
||||||
agvDetail.point.action.unLoadDuration,
|
model.modelUuid,
|
||||||
model.modelUuid,
|
model.storageCapacity,
|
||||||
model.storageCapacity,
|
agvDetail.point.action
|
||||||
agvDetail.point.action
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
app/src/types/simulationTypes.d.ts
vendored
2
app/src/types/simulationTypes.d.ts
vendored
@@ -153,7 +153,7 @@ interface StoragePointSchema {
|
|||||||
uuid: string;
|
uuid: string;
|
||||||
position: [number, number, number];
|
position: [number, number, number];
|
||||||
rotation: [number, number, number];
|
rotation: [number, number, number];
|
||||||
action: StorageAction;
|
actions: StorageAction[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface HumanPointSchema {
|
interface HumanPointSchema {
|
||||||
|
|||||||
Reference in New Issue
Block a user