added multiple actions for storage unit , and simulation bug fix
This commit is contained in:
@@ -125,26 +125,6 @@ function ConveyorMechanics() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRenameAction = (newName: string) => {
|
|
||||||
if (!selectedPointData) return;
|
|
||||||
|
|
||||||
setActionName(newName);
|
|
||||||
const event = updateAction(
|
|
||||||
selectedProduct.productUuid,
|
|
||||||
selectedPointData.action.actionUuid,
|
|
||||||
{ actionName: newName }
|
|
||||||
);
|
|
||||||
|
|
||||||
if (event) {
|
|
||||||
updateBackend(
|
|
||||||
selectedProduct.productName,
|
|
||||||
selectedProduct.productUuid,
|
|
||||||
projectId || '',
|
|
||||||
event
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSpawnCountChange = (value: string) => {
|
const handleSpawnCountChange = (value: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
|
|
||||||
|
|||||||
@@ -62,36 +62,6 @@ function CraneMechanics() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRenameAction = (newName: string) => {
|
|
||||||
if (!selectedAction.actionId || !selectedPointData) return;
|
|
||||||
|
|
||||||
const event = updateAction(
|
|
||||||
selectedProduct.productUuid,
|
|
||||||
selectedAction.actionId,
|
|
||||||
{ actionName: newName }
|
|
||||||
);
|
|
||||||
|
|
||||||
const updatedActions = selectedPointData.actions.map(action =>
|
|
||||||
action.actionUuid === selectedAction.actionId
|
|
||||||
? { ...action, actionName: newName }
|
|
||||||
: action
|
|
||||||
);
|
|
||||||
|
|
||||||
setSelectedPointData({
|
|
||||||
...selectedPointData,
|
|
||||||
actions: updatedActions,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (event) {
|
|
||||||
updateBackend(
|
|
||||||
selectedProduct.productName,
|
|
||||||
selectedProduct.productUuid,
|
|
||||||
projectId || '',
|
|
||||||
event
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleAddAction = () => {
|
const handleAddAction = () => {
|
||||||
if (!selectedEventData || !selectedPointData) return;
|
if (!selectedEventData || !selectedPointData) return;
|
||||||
|
|
||||||
|
|||||||
@@ -142,7 +142,6 @@ function HumanMechanics() {
|
|||||||
if (isNaN(numericValue)) return;
|
if (isNaN(numericValue)) return;
|
||||||
|
|
||||||
const updatedEvent = {
|
const updatedEvent = {
|
||||||
...selectedEventData.data,
|
|
||||||
speed: numericValue
|
speed: numericValue
|
||||||
} as HumanEventSchema;
|
} as HumanEventSchema;
|
||||||
|
|
||||||
|
|||||||
@@ -71,36 +71,6 @@ function RoboticArmMechanics() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRenameAction = (newName: string) => {
|
|
||||||
if (!selectedAction.actionId || !selectedPointData) return;
|
|
||||||
|
|
||||||
const event = updateAction(
|
|
||||||
selectedProduct.productUuid,
|
|
||||||
selectedAction.actionId,
|
|
||||||
{ actionName: newName }
|
|
||||||
);
|
|
||||||
|
|
||||||
const updatedActions = selectedPointData.actions.map(action =>
|
|
||||||
action.actionUuid === selectedAction.actionId
|
|
||||||
? { ...action, actionName: newName }
|
|
||||||
: action
|
|
||||||
);
|
|
||||||
|
|
||||||
setSelectedPointData({
|
|
||||||
...selectedPointData,
|
|
||||||
actions: updatedActions,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (event) {
|
|
||||||
updateBackend(
|
|
||||||
selectedProduct.productName,
|
|
||||||
selectedProduct.productUuid,
|
|
||||||
projectId || '',
|
|
||||||
event
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSpeedChange = (value: string) => {
|
const handleSpeedChange = (value: string) => {
|
||||||
if (!selectedEventData) return;
|
if (!selectedEventData) return;
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ function StorageMechanics() {
|
|||||||
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, getActionByUuid, addAction, removeAction } = productStore();
|
const { getPointByUuid, updateAction, updateEvent, getEventByModelUuid, getActionByUuid, addAction, removeAction } = productStore();
|
||||||
@@ -40,7 +39,6 @@ function StorageMechanics() {
|
|||||||
if (point?.actions?.length) {
|
if (point?.actions?.length) {
|
||||||
setSelectedPointData(point);
|
setSelectedPointData(point);
|
||||||
const firstAction = point.actions[0];
|
const firstAction = point.actions[0];
|
||||||
setCurrentAction(firstAction);
|
|
||||||
|
|
||||||
const eventData = getEventByModelUuid(
|
const eventData = getEventByModelUuid(
|
||||||
selectedProduct.productUuid,
|
selectedProduct.productUuid,
|
||||||
@@ -62,7 +60,6 @@ function StorageMechanics() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
clearSelectedAction();
|
clearSelectedAction();
|
||||||
setCurrentAction(undefined);
|
|
||||||
}
|
}
|
||||||
}, [selectedEventData, selectedProduct]);
|
}, [selectedEventData, selectedProduct]);
|
||||||
|
|
||||||
@@ -74,18 +71,18 @@ function StorageMechanics() {
|
|||||||
selectedEventData.selectedPoint
|
selectedEventData.selectedPoint
|
||||||
) as StoragePointSchema | undefined;
|
) as StoragePointSchema | undefined;
|
||||||
|
|
||||||
const newCurrentAction = getActionByUuid(selectedProduct.productUuid, selectedAction.actionId);
|
const actionUuid = selectedAction.actionId || point?.actions[0].actionUuid || '';
|
||||||
|
|
||||||
|
const newCurrentAction = getActionByUuid(selectedProduct.productUuid, actionUuid);
|
||||||
|
|
||||||
if (newCurrentAction && (newCurrentAction.actionType === 'store' || newCurrentAction.actionType === 'retrieve')) {
|
if (newCurrentAction && (newCurrentAction.actionType === 'store' || newCurrentAction.actionType === 'retrieve')) {
|
||||||
if (!selectedAction.actionId) {
|
if (!selectedAction.actionId) {
|
||||||
setSelectedAction(newCurrentAction.actionUuid, newCurrentAction.actionName);
|
setSelectedAction(newCurrentAction.actionUuid, newCurrentAction.actionName);
|
||||||
}
|
}
|
||||||
setCurrentAction(newCurrentAction);
|
|
||||||
const uiOption = newCurrentAction.actionType === "retrieve" ? "spawn" : "store";
|
const uiOption = newCurrentAction.actionType === "retrieve" ? "spawn" : "store";
|
||||||
setActiveOption(uiOption);
|
setActiveOption(uiOption);
|
||||||
} else {
|
} else {
|
||||||
clearSelectedAction();
|
clearSelectedAction();
|
||||||
setCurrentAction(undefined);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [selectedAction, selectedProduct, selectedEventData]);
|
}, [selectedAction, selectedProduct, selectedEventData]);
|
||||||
@@ -106,17 +103,19 @@ function StorageMechanics() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleActionTypeChange = (option: string) => {
|
const handleActionTypeChange = (option: string) => {
|
||||||
if (!selectedAction.actionId || !currentAction || !selectedPointData) return;
|
if (!selectedAction.actionId || !selectedPointData) return;
|
||||||
|
|
||||||
const internalOption = option === "spawn" ? "retrieve" : "store";
|
const internalOption = option === "spawn" ? "retrieve" : "store";
|
||||||
|
|
||||||
const updatedAction = {
|
const updatedAction = {
|
||||||
...currentAction,
|
|
||||||
actionType: internalOption as "store" | "retrieve"
|
actionType: internalOption as "store" | "retrieve"
|
||||||
};
|
};
|
||||||
|
|
||||||
const updatedActions = selectedPointData.actions.map(action =>
|
const updatedActions = selectedPointData.actions.map(action =>
|
||||||
action.actionUuid === updatedAction.actionUuid ? updatedAction : action
|
action.actionUuid === selectedAction.actionId ? {
|
||||||
|
...action,
|
||||||
|
actionType: updatedAction.actionType
|
||||||
|
} : action
|
||||||
);
|
);
|
||||||
|
|
||||||
const updatedPoint = { ...selectedPointData, actions: updatedActions };
|
const updatedPoint = { ...selectedPointData, actions: updatedActions };
|
||||||
@@ -136,7 +135,6 @@ function StorageMechanics() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurrentAction(updatedAction);
|
|
||||||
setSelectedPointData(updatedPoint);
|
setSelectedPointData(updatedPoint);
|
||||||
setActiveOption(option as "store" | "spawn");
|
setActiveOption(option as "store" | "spawn");
|
||||||
};
|
};
|
||||||
@@ -148,7 +146,6 @@ function StorageMechanics() {
|
|||||||
if (isNaN(numericValue)) return;
|
if (isNaN(numericValue)) return;
|
||||||
|
|
||||||
const updatedEvent = {
|
const updatedEvent = {
|
||||||
...selectedEventData.data,
|
|
||||||
storageCapacity: numericValue
|
storageCapacity: numericValue
|
||||||
} as StorageEventSchema;
|
} as StorageEventSchema;
|
||||||
|
|
||||||
@@ -186,7 +183,6 @@ function StorageMechanics() {
|
|||||||
if (numericValue > maxCapacity) return;
|
if (numericValue > maxCapacity) return;
|
||||||
|
|
||||||
const updatedEvent = {
|
const updatedEvent = {
|
||||||
...selectedEventData.data,
|
|
||||||
storageCount: numericValue
|
storageCount: numericValue
|
||||||
} as StorageEventSchema;
|
} as StorageEventSchema;
|
||||||
|
|
||||||
@@ -212,7 +208,6 @@ function StorageMechanics() {
|
|||||||
if (!selectedEventData) return;
|
if (!selectedEventData) return;
|
||||||
|
|
||||||
const updatedEvent = {
|
const updatedEvent = {
|
||||||
...selectedEventData.data,
|
|
||||||
materialType: value
|
materialType: value
|
||||||
} as StorageEventSchema;
|
} as StorageEventSchema;
|
||||||
|
|
||||||
@@ -283,13 +278,8 @@ function StorageMechanics() {
|
|||||||
const nextAction = updatedPoint.actions[index] || updatedPoint.actions[index - 1];
|
const nextAction = updatedPoint.actions[index] || updatedPoint.actions[index - 1];
|
||||||
if (nextAction) {
|
if (nextAction) {
|
||||||
setSelectedAction(nextAction.actionUuid, nextAction.actionName);
|
setSelectedAction(nextAction.actionUuid, nextAction.actionName);
|
||||||
const action = getActionByUuid(selectedProduct.productUuid, nextAction.actionUuid);
|
|
||||||
if (action) {
|
|
||||||
setCurrentAction(action as StorageAction);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
clearSelectedAction();
|
clearSelectedAction();
|
||||||
setCurrentAction(undefined);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -318,7 +308,7 @@ function StorageMechanics() {
|
|||||||
handleDeleteAction={handleDeleteAction}
|
handleDeleteAction={handleDeleteAction}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{selectedAction.actionId && currentAction && (
|
{selectedAction.actionId && (
|
||||||
<div className="selected-actions-details">
|
<div className="selected-actions-details">
|
||||||
<div className="selected-actions-header">
|
<div className="selected-actions-header">
|
||||||
<RenameInput
|
<RenameInput
|
||||||
|
|||||||
@@ -119,26 +119,6 @@ function VehicleMechanics() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRenameAction = (newName: string) => {
|
|
||||||
if (!selectedPointData) return;
|
|
||||||
|
|
||||||
setActionName(newName);
|
|
||||||
const event = updateAction(
|
|
||||||
selectedProduct.productUuid,
|
|
||||||
selectedPointData.action.actionUuid,
|
|
||||||
{ actionName: newName }
|
|
||||||
);
|
|
||||||
|
|
||||||
if (event) {
|
|
||||||
updateBackend(
|
|
||||||
selectedProduct.productName,
|
|
||||||
selectedProduct.productUuid,
|
|
||||||
projectId || '',
|
|
||||||
event
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleLoadCapacityChange = (value: string) => {
|
const handleLoadCapacityChange = (value: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
|
|
||||||
|
|||||||
@@ -44,35 +44,29 @@ export function useRetrieveHandler() {
|
|||||||
if (!modelUuid || !pointUuid) return null;
|
if (!modelUuid || !pointUuid) return null;
|
||||||
const currentTime = performance.now();
|
const currentTime = performance.now();
|
||||||
|
|
||||||
if (action.triggers[0]?.triggeredAsset?.triggeredModel.modelUuid &&
|
const newMaterial: MaterialSchema = {
|
||||||
action.triggers[0]?.triggeredAsset?.triggeredPoint?.pointUuid &&
|
materialId: materialId,
|
||||||
action.triggers[0]?.triggeredAsset?.triggeredAction?.actionUuid
|
materialName: `${materialType}-${Date.now()}`,
|
||||||
) {
|
materialType: materialType,
|
||||||
const newMaterial: MaterialSchema = {
|
isActive: false,
|
||||||
materialId: materialId,
|
isVisible: false,
|
||||||
materialName: `${materialType}-${Date.now()}`,
|
isPaused: false,
|
||||||
materialType: materialType,
|
isRendered: true,
|
||||||
isActive: false,
|
startTime: currentTime,
|
||||||
isVisible: false,
|
previous: {
|
||||||
isPaused: false,
|
modelUuid: modelUuid,
|
||||||
isRendered: true,
|
pointUuid: pointUuid,
|
||||||
startTime: currentTime,
|
actionUuid: action.actionUuid
|
||||||
previous: {
|
},
|
||||||
modelUuid: modelUuid,
|
current: {
|
||||||
pointUuid: pointUuid,
|
modelUuid: modelUuid,
|
||||||
actionUuid: action.actionUuid
|
pointUuid: pointUuid,
|
||||||
},
|
actionUuid: action.actionUuid
|
||||||
current: {
|
},
|
||||||
modelUuid: modelUuid,
|
};
|
||||||
pointUuid: pointUuid,
|
|
||||||
actionUuid: action.actionUuid
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
addMaterial(newMaterial);
|
addMaterial(newMaterial);
|
||||||
return newMaterial;
|
return newMaterial;
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}, [addMaterial, getModelUuidByActionUuid, getPointUuidByActionUuid, selectedProduct.productUuid]);
|
}, [addMaterial, getModelUuidByActionUuid, getPointUuidByActionUuid, selectedProduct.productUuid]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -112,12 +106,16 @@ export function useRetrieveHandler() {
|
|||||||
getModelUuidByActionUuid(selectedProduct.productUuid, retrieval.action.actionUuid) ?? ''
|
getModelUuidByActionUuid(selectedProduct.productUuid, retrieval.action.actionUuid) ?? ''
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!storageUnit || storageUnit.currentLoad <= 0) {
|
if (!storageUnit) {
|
||||||
completedActions.push(actionUuid);
|
completedActions.push(actionUuid);
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (storageUnit.currentLoad <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (retrieval.action.triggers.length === 0 || !retrieval.action.triggers[0]?.triggeredAsset) {
|
if (retrieval.action.triggers.length === 0 || !retrieval.action.triggers[0]?.triggeredAsset) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ function PillarJibAnimator({
|
|||||||
if (crane.currentPhase === 'init-pickup') {
|
if (crane.currentPhase === 'init-pickup') {
|
||||||
if (crane.currentMaterials.length > 0) {
|
if (crane.currentMaterials.length > 0) {
|
||||||
const materials = scene.getObjectsByProperty('uuid', crane.currentMaterials[0].materialId);
|
const materials = scene.getObjectsByProperty('uuid', crane.currentMaterials[0].materialId);
|
||||||
console.log('materials: ', materials);
|
|
||||||
const material = materials.find((material) => material.visible === true);
|
const material = materials.find((material) => material.visible === true);
|
||||||
if (material) {
|
if (material) {
|
||||||
const materialWorld = new THREE.Vector3();
|
const materialWorld = new THREE.Vector3();
|
||||||
|
|||||||
@@ -35,17 +35,15 @@ function PillarJibInstance({ crane }: { crane: CraneStatus }) {
|
|||||||
if (!crane.isActive && crane.currentPhase === 'init' && crane.currentMaterials.length > 0 && action.maxPickUpCount <= crane.currentMaterials.length) {
|
if (!crane.isActive && crane.currentPhase === 'init' && crane.currentMaterials.length > 0 && action.maxPickUpCount <= crane.currentMaterials.length) {
|
||||||
setCurrentPhase(crane.modelUuid, 'init-pickup');
|
setCurrentPhase(crane.modelUuid, 'init-pickup');
|
||||||
} else if (crane.currentPhase === 'picking' && crane.currentMaterials.length > 0 && action.maxPickUpCount <= crane.currentMaterials.length && !crane.isCarrying) {
|
} else if (crane.currentPhase === 'picking' && crane.currentMaterials.length > 0 && action.maxPickUpCount <= crane.currentMaterials.length && !crane.isCarrying) {
|
||||||
if (action.triggers.length > 0) {
|
if (humanAsset?.animationState?.current === "working_standing" && humanAsset?.animationState?.isCompleted && humanId && humanAction && humanAction.actionType === 'operator') {
|
||||||
if (humanAsset?.animationState?.current === "working_standing" && humanAsset?.animationState?.isCompleted && humanId && humanAction && humanAction.actionType === 'operator') {
|
setCurrentAnimation(humanId, 'idle', true, true, true);
|
||||||
setCurrentAnimation(humanId, 'idle', true, true, true);
|
setIsCaryying(crane.modelUuid, true);
|
||||||
setIsCaryying(crane.modelUuid, true);
|
setCurrentPhase(crane.modelUuid, 'pickup-drop');
|
||||||
setCurrentPhase(crane.modelUuid, 'pickup-drop');
|
} else {
|
||||||
} else {
|
setCurrentPhaseHuman(humanId, 'hooking');
|
||||||
setCurrentPhaseHuman(humanId, 'hooking');
|
setHumanActive(humanId, true);
|
||||||
setHumanActive(humanId, true);
|
setHumanState(humanId, 'running');
|
||||||
setHumanState(humanId, 'running');
|
setCurrentAnimation(humanId, 'working_standing', true, false, false);
|
||||||
setCurrentAnimation(humanId, 'working_standing', true, false, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (crane.currentPhase === 'dropping' && crane.currentMaterials.length > 0 && action.maxPickUpCount <= crane.currentMaterials.length && crane.isCarrying && human.currentPhase === 'hooking') {
|
} else if (crane.currentPhase === 'dropping' && crane.currentMaterials.length > 0 && action.maxPickUpCount <= crane.currentMaterials.length && crane.isCarrying && human.currentPhase === 'hooking') {
|
||||||
setCurrentPhaseHuman(humanId, 'loadPoint-unloadPoint');
|
setCurrentPhaseHuman(humanId, 'loadPoint-unloadPoint');
|
||||||
|
|||||||
@@ -126,9 +126,11 @@ function OperatorInstance({ human }: { human: HumanStatus }) {
|
|||||||
humanStatus(human.modelUuid, 'Started from loadPoint, heading to unloadPoint');
|
humanStatus(human.modelUuid, 'Started from loadPoint, heading to unloadPoint');
|
||||||
}
|
}
|
||||||
} else if (human.state === 'idle' && human.currentPhase === 'unhooking') {
|
} else if (human.state === 'idle' && human.currentPhase === 'unhooking') {
|
||||||
setHumanState(human.modelUuid, 'running');
|
setTimeout(() => {
|
||||||
setHumanActive(human.modelUuid, true);
|
setHumanState(human.modelUuid, 'running');
|
||||||
setCurrentAnimation(human.modelUuid, 'working_standing', true, false, false);
|
setHumanActive(human.modelUuid, true);
|
||||||
|
setCurrentAnimation(human.modelUuid, 'working_standing', true, false, false);
|
||||||
|
}, 1)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reset()
|
reset()
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import { extractTriggersFromPoint } from "./extractTriggersFromPoint";
|
import { extractTriggersFromPoint } from "./extractTriggersFromPoint";
|
||||||
|
|
||||||
export function determineExecutionOrder(products: productsSchema): PointsScheme[] {
|
export function determineExecutionOrder(products: productsSchema): Action[] {
|
||||||
// Create maps for all events and points
|
// Create maps for all events and points
|
||||||
const eventMap = new Map<string, EventsSchema>();
|
const eventMap = new Map<string, EventsSchema>();
|
||||||
const pointMap = new Map<string, PointsScheme>();
|
const pointMap = new Map<string, PointsScheme>();
|
||||||
const allPoints: PointsScheme[] = [];
|
const allPoints: PointsScheme[] = [];
|
||||||
|
const spawnActions: Action[] = [];
|
||||||
|
|
||||||
// First pass: collect all points
|
// First pass: collect all points and identify spawn actions
|
||||||
products.forEach(product => {
|
products.forEach(product => {
|
||||||
product.eventDatas.forEach(event => {
|
product.eventDatas.forEach(event => {
|
||||||
eventMap.set(event.modelUuid, event);
|
eventMap.set(event.modelUuid, event);
|
||||||
@@ -15,6 +16,11 @@ export function determineExecutionOrder(products: productsSchema): PointsScheme[
|
|||||||
event.points.forEach(point => {
|
event.points.forEach(point => {
|
||||||
pointMap.set(point.uuid, point);
|
pointMap.set(point.uuid, point);
|
||||||
allPoints.push(point);
|
allPoints.push(point);
|
||||||
|
|
||||||
|
// Check for spawn actions in conveyors
|
||||||
|
if (point.action.actionType === 'spawn') {
|
||||||
|
spawnActions.push(point.action);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else if (event.type === 'vehicle' ||
|
} else if (event.type === 'vehicle' ||
|
||||||
event.type === 'machine' ||
|
event.type === 'machine' ||
|
||||||
@@ -25,6 +31,16 @@ export function determineExecutionOrder(products: productsSchema): PointsScheme[
|
|||||||
) {
|
) {
|
||||||
pointMap.set(event.point.uuid, event.point);
|
pointMap.set(event.point.uuid, event.point);
|
||||||
allPoints.push(event.point);
|
allPoints.push(event.point);
|
||||||
|
|
||||||
|
// Check for spawn actions in storage units and other types
|
||||||
|
if (event.type === 'storageUnit') {
|
||||||
|
const storagePoint = event.point as StoragePointSchema;
|
||||||
|
storagePoint.actions.forEach(action => {
|
||||||
|
if (action.actionType === 'retrieve') {
|
||||||
|
spawnActions.push(action);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -33,11 +49,19 @@ export function determineExecutionOrder(products: productsSchema): PointsScheme[
|
|||||||
const graph = new Map<string, string[]>();
|
const graph = new Map<string, string[]>();
|
||||||
const reverseGraph = new Map<string, string[]>();
|
const reverseGraph = new Map<string, string[]>();
|
||||||
const allTriggeredPoints = new Set<string>();
|
const allTriggeredPoints = new Set<string>();
|
||||||
|
const actionMap = new Map<string, Action>(); // Map point UUID to its primary action
|
||||||
|
|
||||||
allPoints.forEach(point => {
|
allPoints.forEach(point => {
|
||||||
const triggers = extractTriggersFromPoint(point);
|
const triggers = extractTriggersFromPoint(point);
|
||||||
const dependencies: string[] = [];
|
const dependencies: string[] = [];
|
||||||
|
|
||||||
|
// Store the primary action for this point
|
||||||
|
if ('action' in point) {
|
||||||
|
actionMap.set(point.uuid, point.action);
|
||||||
|
} else if ('actions' in point && point.actions.length > 0) {
|
||||||
|
actionMap.set(point.uuid, point.actions[0]); // Use first action as primary
|
||||||
|
}
|
||||||
|
|
||||||
triggers.forEach(trigger => {
|
triggers.forEach(trigger => {
|
||||||
const targetUuid = trigger.triggeredAsset?.triggeredPoint?.pointUuid;
|
const targetUuid = trigger.triggeredAsset?.triggeredPoint?.pointUuid;
|
||||||
if (targetUuid && pointMap.has(targetUuid)) {
|
if (targetUuid && pointMap.has(targetUuid)) {
|
||||||
@@ -58,15 +82,12 @@ export function determineExecutionOrder(products: productsSchema): PointsScheme[
|
|||||||
const rootPoints = allPoints
|
const rootPoints = allPoints
|
||||||
.filter(point => !allTriggeredPoints.has(point.uuid))
|
.filter(point => !allTriggeredPoints.has(point.uuid))
|
||||||
.filter(point => {
|
.filter(point => {
|
||||||
// Only include roots that actually have triggers pointing FROM them
|
|
||||||
const triggers = extractTriggersFromPoint(point);
|
const triggers = extractTriggersFromPoint(point);
|
||||||
return triggers.some(t => t.triggeredAsset?.triggeredPoint?.pointUuid);
|
return triggers.some(t => t.triggeredAsset?.triggeredPoint?.pointUuid);
|
||||||
});
|
});
|
||||||
|
|
||||||
// If no root points found but we have triggered points, find the earliest triggers
|
// If no root points found but we have triggered points, find the earliest triggers
|
||||||
if (rootPoints.length === 0 && allTriggeredPoints.size > 0) {
|
if (rootPoints.length === 0 && allTriggeredPoints.size > 0) {
|
||||||
// This handles cases where we have circular dependencies
|
|
||||||
// but still want to include the triggered points
|
|
||||||
const minTriggerCount = Math.min(
|
const minTriggerCount = Math.min(
|
||||||
...Array.from(allTriggeredPoints)
|
...Array.from(allTriggeredPoints)
|
||||||
.map(uuid => (graph.get(uuid) || []).length)
|
.map(uuid => (graph.get(uuid) || []).length)
|
||||||
@@ -105,11 +126,18 @@ export function determineExecutionOrder(products: productsSchema): PointsScheme[
|
|||||||
// Start processing from root points
|
// Start processing from root points
|
||||||
rootPoints.forEach(root => visit(root.uuid));
|
rootPoints.forEach(root => visit(root.uuid));
|
||||||
|
|
||||||
// Convert UUIDs back to points and filter out untriggered points
|
// Convert UUIDs back to actions
|
||||||
const triggeredPoints = order
|
const triggeredActions = order
|
||||||
.map(uuid => pointMap.get(uuid)!)
|
.map(uuid => actionMap.get(uuid))
|
||||||
.filter(point => allTriggeredPoints.has(point.uuid) ||
|
.filter((action): action is Action => action !== undefined);
|
||||||
rootPoints.some(root => root.uuid === point.uuid));
|
|
||||||
|
|
||||||
return triggeredPoints;
|
// Combine triggered actions with ALL spawn actions
|
||||||
|
const allExecutionActions = [...triggeredActions, ...spawnActions];
|
||||||
|
|
||||||
|
// Remove duplicate actions while preserving order
|
||||||
|
const uniqueActions = allExecutionActions.filter((action, index, array) =>
|
||||||
|
array.findIndex(a => a.actionUuid === action.actionUuid) === index
|
||||||
|
);
|
||||||
|
|
||||||
|
return uniqueActions;
|
||||||
}
|
}
|
||||||
@@ -21,12 +21,13 @@ function Simulator() {
|
|||||||
if (!product) return;
|
if (!product) return;
|
||||||
|
|
||||||
const executionOrder = determineExecutionOrder([product]);
|
const executionOrder = determineExecutionOrder([product]);
|
||||||
executionOrder.forEach(point => {
|
|
||||||
const action = 'actions' in point ? point.actions[0] : point.action;
|
executionOrder.forEach(action => {
|
||||||
handleAction(action);
|
handleAction(action);
|
||||||
});
|
});
|
||||||
}, [products, isPlaying, isReset, selectedProduct]);
|
}, [products, isPlaying, isReset, selectedProduct]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ export function useTriggerHandler() {
|
|||||||
|
|
||||||
// Handle current action using Event Manager
|
// Handle current action using Event Manager
|
||||||
addVehicleToMonitor(vehicle.modelUuid, () => {
|
addVehicleToMonitor(vehicle.modelUuid, () => {
|
||||||
|
setIsVisible(materialId, false);
|
||||||
handleAction(action, materialId);
|
handleAction(action, materialId);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -392,7 +393,7 @@ export function useTriggerHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (toEvent?.type === 'crane') {
|
} else if (toEvent?.type === 'crane') {
|
||||||
// Transfer to Human
|
// Transfer to Crane
|
||||||
if (materialId && trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) {
|
if (materialId && trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) {
|
||||||
const material = getMaterialById(materialId);
|
const material = getMaterialById(materialId);
|
||||||
if (material) {
|
if (material) {
|
||||||
@@ -622,7 +623,7 @@ export function useTriggerHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (toEvent?.type === 'crane') {
|
} else if (toEvent?.type === 'crane') {
|
||||||
// Vehicle to Human
|
// Vehicle to Crane
|
||||||
if (materialId && trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) {
|
if (materialId && trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) {
|
||||||
const material = getMaterialById(materialId);
|
const material = getMaterialById(materialId);
|
||||||
if (material) {
|
if (material) {
|
||||||
@@ -1801,25 +1802,25 @@ export function useTriggerHandler() {
|
|||||||
}
|
}
|
||||||
} else if (fromEvent?.type === 'crane') {
|
} else if (fromEvent?.type === 'crane') {
|
||||||
if (toEvent?.type === 'transfer') {
|
if (toEvent?.type === 'transfer') {
|
||||||
// Crane Unit to Transfer
|
// Crane to Transfer
|
||||||
|
|
||||||
} else if (toEvent?.type === 'vehicle') {
|
} else if (toEvent?.type === 'vehicle') {
|
||||||
// Crane Unit to Vehicle
|
// Crane to Vehicle
|
||||||
|
|
||||||
} else if (toEvent?.type === 'machine') {
|
} else if (toEvent?.type === 'machine') {
|
||||||
// Crane Unit to Machine
|
// Crane to Machine
|
||||||
|
|
||||||
} else if (toEvent?.type === 'roboticArm') {
|
} else if (toEvent?.type === 'roboticArm') {
|
||||||
// Crane Unit to Robotic Arm
|
// Crane to Robotic Arm
|
||||||
|
|
||||||
} else if (toEvent?.type === 'storageUnit') {
|
} else if (toEvent?.type === 'storageUnit') {
|
||||||
// Crane Unit to Storage Unit
|
// Crane to Storage Unit
|
||||||
|
|
||||||
} else if (toEvent?.type === 'human') {
|
} else if (toEvent?.type === 'human') {
|
||||||
// Crane Unit to Human
|
// Crane to Human
|
||||||
|
|
||||||
} else if (toEvent?.type === 'crane') {
|
} else if (toEvent?.type === 'crane') {
|
||||||
// Crane Unit to Human
|
// Crane to Human
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -378,8 +378,10 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>)
|
|||||||
|
|
||||||
const human = getHumanById(humanId);
|
const human = getHumanById(humanId);
|
||||||
const humanAction = human?.point.actions.find((action) => action.actionUuid === humanActionId);
|
const humanAction = human?.point.actions.find((action) => action.actionUuid === humanActionId);
|
||||||
if (human && human.currentAction?.actionUuid !== humanActionId && human.currentLoad < (humanAction?.loadCapacity || 0)) {
|
if (human && human.currentLoad < (humanAction?.loadCapacity || 0)) {
|
||||||
addCurrentAction(humanId, humanActionId);
|
if (human.currentAction?.actionUuid !== humanActionId) {
|
||||||
|
addCurrentAction(humanId, humanActionId);
|
||||||
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
unloadLoop();
|
unloadLoop();
|
||||||
}, 500)
|
}, 500)
|
||||||
|
|||||||
@@ -80,7 +80,13 @@ export const createMaterialStore = () => {
|
|||||||
addMaterial: (material) => {
|
addMaterial: (material) => {
|
||||||
let updatedMaterial: MaterialSchema | undefined;
|
let updatedMaterial: MaterialSchema | undefined;
|
||||||
set((state) => {
|
set((state) => {
|
||||||
|
const existingIndex = state.materials.findIndex(m => m.materialId === material.materialId);
|
||||||
|
if (existingIndex !== -1) {
|
||||||
|
state.materials.splice(existingIndex, 1);
|
||||||
|
}
|
||||||
|
|
||||||
state.materials.push(material);
|
state.materials.push(material);
|
||||||
|
updatedMaterial = JSON.parse(JSON.stringify(material));
|
||||||
});
|
});
|
||||||
return updatedMaterial;
|
return updatedMaterial;
|
||||||
},
|
},
|
||||||
|
|||||||
1
app/src/types/simulationTypes.d.ts
vendored
1
app/src/types/simulationTypes.d.ts
vendored
@@ -456,7 +456,6 @@ type ConveyorPoints = NormalConveyor | YJunctionConveyor | CurvedConveyor;
|
|||||||
|
|
||||||
// Crane Constraints
|
// Crane Constraints
|
||||||
|
|
||||||
|
|
||||||
type PillarJibCrane = {
|
type PillarJibCrane = {
|
||||||
trolleySpeed: number;
|
trolleySpeed: number;
|
||||||
hookSpeed: number;
|
hookSpeed: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user