Merge remote-tracking branch 'origin/v2' into v2-ui
This commit is contained in:
commit
e39da61ed8
|
@ -36,7 +36,7 @@ const ActionsList: React.FC<ActionsListProps> = ({
|
||||||
const handleRenameAction = (newName: string) => {
|
const handleRenameAction = (newName: string) => {
|
||||||
if (!selectedAction.actionId) return;
|
if (!selectedAction.actionId) return;
|
||||||
const event = renameAction(selectedProduct.productId, selectedAction.actionId, newName);
|
const event = renameAction(selectedProduct.productId, selectedAction.actionId, newName);
|
||||||
|
setSelectedAction(selectedAction.actionId, newName);
|
||||||
if (event) {
|
if (event) {
|
||||||
upsertProductOrEventApi({
|
upsertProductOrEventApi({
|
||||||
productName: selectedProduct.productName,
|
productName: selectedProduct.productName,
|
||||||
|
|
|
@ -14,7 +14,7 @@ function RoboticArmMechanics() {
|
||||||
const [activeOption, setActiveOption] = useState<"default" | "pickAndPlace">("default");
|
const [activeOption, setActiveOption] = useState<"default" | "pickAndPlace">("default");
|
||||||
const [selectedPointData, setSelectedPointData] = useState<RoboticArmPointSchema | undefined>();
|
const [selectedPointData, setSelectedPointData] = useState<RoboticArmPointSchema | undefined>();
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventData } = useSelectedEventData();
|
||||||
const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction, addAction, removeAction } = useProductStore();
|
const { getPointByUuid, getEventByModelUuid, getActionByUuid, updateEvent, updateAction, addAction, removeAction } = useProductStore();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
const { selectedAction, setSelectedAction, clearSelectedAction } = useSelectedAction();
|
const { selectedAction, setSelectedAction, clearSelectedAction } = useSelectedAction();
|
||||||
|
|
||||||
|
@ -28,20 +28,28 @@ function RoboticArmMechanics() {
|
||||||
selectedEventData.data.modelUuid,
|
selectedEventData.data.modelUuid,
|
||||||
selectedEventData.selectedPoint
|
selectedEventData.selectedPoint
|
||||||
) as RoboticArmPointSchema | undefined;
|
) as RoboticArmPointSchema | undefined;
|
||||||
|
const action = getActionByUuid(selectedProduct.productId, selectedAction.actionId) as RoboticArmPointSchema["actions"][0] | undefined;
|
||||||
|
if (action) {
|
||||||
if (point?.actions) {
|
if (point?.actions) {
|
||||||
setSelectedPointData(point);
|
setSelectedPointData(point);
|
||||||
|
if (point.actions.length > 0 && action) {
|
||||||
|
setActiveOption(action.actionType as "default" | "pickAndPlace");
|
||||||
|
setSelectedAction(selectedAction.actionId, selectedAction.actionName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (point?.actions) {
|
||||||
|
setSelectedPointData(point);
|
||||||
|
if (point.actions.length > 0) {
|
||||||
setActiveOption(point.actions[0].actionType as "default" | "pickAndPlace");
|
setActiveOption(point.actions[0].actionType as "default" | "pickAndPlace");
|
||||||
if (point.actions.length > 0 && !selectedAction.actionId) {
|
setSelectedAction(point.actions[0].actionUuid, point.actions[0].actionName);
|
||||||
setSelectedAction(
|
}
|
||||||
point.actions[0].actionUuid,
|
|
||||||
point.actions[0].actionName
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
clearSelectedAction();
|
clearSelectedAction();
|
||||||
}
|
}
|
||||||
}, [clearSelectedAction, getPointByUuid, selectedAction.actionId, selectedEventData, selectedProduct, setSelectedAction,]);
|
}, [selectedAction, selectedEventData, selectedProduct]);
|
||||||
|
|
||||||
const updateBackend = (
|
const updateBackend = (
|
||||||
productName: string,
|
productName: string,
|
||||||
|
@ -192,9 +200,8 @@ function RoboticArmMechanics() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newActions = selectedPointData.actions.filter(
|
const index = selectedPointData.actions.findIndex(a => a.actionUuid === actionUuid);
|
||||||
(a: any) => a.actionUuid !== actionUuid
|
const newActions = selectedPointData.actions.filter(a => a.actionUuid !== actionUuid);
|
||||||
);
|
|
||||||
|
|
||||||
const updatedPoint = {
|
const updatedPoint = {
|
||||||
...selectedPointData,
|
...selectedPointData,
|
||||||
|
@ -203,8 +210,9 @@ function RoboticArmMechanics() {
|
||||||
setSelectedPointData(updatedPoint);
|
setSelectedPointData(updatedPoint);
|
||||||
|
|
||||||
if (selectedAction.actionId === actionUuid) {
|
if (selectedAction.actionId === actionUuid) {
|
||||||
if (newActions.length > 0) {
|
const nextAction = newActions[index] || newActions[index - 1];
|
||||||
setSelectedAction(newActions[0].actionUuid, newActions[0].actionName);
|
if (nextAction) {
|
||||||
|
setSelectedAction(nextAction.actionUuid, nextAction.actionName);
|
||||||
} else {
|
} else {
|
||||||
clearSelectedAction();
|
clearSelectedAction();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ type TriggerProps = {
|
||||||
const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
const [currentAction, setCurrentAction] = useState<string | undefined>();
|
const [currentAction, setCurrentAction] = useState<string | undefined>();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
const { getActionByUuid, addTrigger, removeTrigger, updateTrigger, renameTrigger, getProductById } = useProductStore();
|
const { getActionByUuid, getEventByModelUuid, getPointByUuid, getTriggerByUuid, addTrigger, removeTrigger, updateTrigger, renameTrigger, getProductById } = useProductStore();
|
||||||
const [triggers, setTriggers] = useState<TriggerSchema[]>([]);
|
const [triggers, setTriggers] = useState<TriggerSchema[]>([]);
|
||||||
const [selectedTrigger, setSelectedTrigger] = useState<TriggerSchema | undefined>();
|
const [selectedTrigger, setSelectedTrigger] = useState<TriggerSchema | undefined>();
|
||||||
const [activeOption, setActiveOption] = useState<"onComplete" | "onStart" | "onStop" | "delay" | "onError">("onComplete");
|
const [activeOption, setActiveOption] = useState<"onComplete" | "onStart" | "onStop" | "delay" | "onError">("onComplete");
|
||||||
|
@ -43,7 +43,6 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
setCurrentAction(actionUuid);
|
setCurrentAction(actionUuid);
|
||||||
}, [selectedPointData, selectedProduct, type]);
|
}, [selectedPointData, selectedProduct, type]);
|
||||||
|
|
||||||
|
|
||||||
const updateBackend = (
|
const updateBackend = (
|
||||||
productName: string,
|
productName: string,
|
||||||
productId: string,
|
productId: string,
|
||||||
|
@ -66,55 +65,32 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
setSelectedTrigger(actionTriggers[0]);
|
setSelectedTrigger(actionTriggers[0]);
|
||||||
}, [currentAction, selectedProduct]);
|
}, [currentAction, selectedProduct]);
|
||||||
|
|
||||||
const handleAddTrigger = () => {
|
const triggeredModel = useMemo(() => {
|
||||||
if (!selectedProduct || !currentAction) return;
|
if (!selectedProduct || !selectedTrigger?.triggeredAsset?.triggeredModel?.modelUuid) return undefined;
|
||||||
|
return getEventByModelUuid(selectedProduct.productId, selectedTrigger.triggeredAsset.triggeredModel.modelUuid);
|
||||||
|
}, [selectedProduct, selectedTrigger]);
|
||||||
|
|
||||||
const newTrigger: TriggerSchema = {
|
const triggeredPoint = useMemo(() => {
|
||||||
triggerUuid: THREE.MathUtils.generateUUID(),
|
if (!selectedProduct || !triggeredModel || !selectedTrigger?.triggeredAsset?.triggeredPoint?.pointUuid) return undefined;
|
||||||
triggerName: `New Trigger ${triggers.length + 1}`,
|
return getPointByUuid(
|
||||||
triggerType: activeOption,
|
selectedProduct.productId,
|
||||||
delay: 0,
|
triggeredModel.modelUuid,
|
||||||
triggeredAsset: null
|
selectedTrigger.triggeredAsset.triggeredPoint.pointUuid
|
||||||
};
|
);
|
||||||
|
}, [selectedProduct, triggeredModel, selectedTrigger]);
|
||||||
|
|
||||||
addTrigger(selectedProduct.productId, currentAction, newTrigger);
|
const triggeredAction = useMemo(() => {
|
||||||
setSelectedTrigger(newTrigger);
|
if (!selectedProduct || !selectedTrigger?.triggeredAsset?.triggeredAction?.actionUuid) return undefined;
|
||||||
};
|
return getActionByUuid(
|
||||||
|
selectedProduct.productId,
|
||||||
const handleRemoveTrigger = (triggerUuid: string) => {
|
selectedTrigger.triggeredAsset.triggeredAction.actionUuid
|
||||||
if (!selectedProduct) return;
|
);
|
||||||
removeTrigger(selectedProduct.productId, triggerUuid);
|
}, [selectedProduct, selectedTrigger]);
|
||||||
if (selectedTrigger?.triggerUuid === triggerUuid) {
|
|
||||||
const remainingTriggers = triggers.filter(t => t.triggerUuid !== triggerUuid);
|
|
||||||
setSelectedTrigger(remainingTriggers[0]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleTriggerRename = (triggerUuid: string, newName: string) => {
|
|
||||||
if (!selectedProduct) return;
|
|
||||||
renameTrigger(selectedProduct.productId, triggerUuid, newName);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleTriggerTypeChange = (option: string) => {
|
|
||||||
if (!selectedTrigger || !selectedProduct) return;
|
|
||||||
|
|
||||||
const validTypes: Array<TriggerSchema['triggerType']> = ["onComplete", "onStart", "onStop", "delay", "onError"];
|
|
||||||
if (!validTypes.includes(option as TriggerSchema['triggerType'])) return;
|
|
||||||
|
|
||||||
setActiveOption(option as TriggerSchema['triggerType']);
|
|
||||||
updateTrigger(selectedProduct.productId, selectedTrigger.triggerUuid, {
|
|
||||||
triggerType: option as TriggerSchema['triggerType']
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const triggeredModel = selectedTrigger?.triggeredAsset?.triggeredModel || { modelName: "Select Model", modelUuid: "" };
|
|
||||||
const triggeredPoint = selectedTrigger?.triggeredAsset?.triggeredPoint || { pointName: "Select Point", pointUuid: "" };
|
|
||||||
const triggeredAction = selectedTrigger?.triggeredAsset?.triggeredAction || { actionName: "Select Action", actionUuid: "" };
|
|
||||||
|
|
||||||
const modelOptions = getProductById(selectedProduct.productId)?.eventDatas || [];
|
const modelOptions = getProductById(selectedProduct.productId)?.eventDatas || [];
|
||||||
|
|
||||||
const pointOptions: PointsScheme[] = useMemo(() => {
|
const pointOptions: PointsScheme[] = useMemo(() => {
|
||||||
if (!triggeredModel.modelUuid) return [];
|
if (!triggeredModel) return [];
|
||||||
|
|
||||||
const model = modelOptions.find(m => m.modelUuid === triggeredModel.modelUuid);
|
const model = modelOptions.find(m => m.modelUuid === triggeredModel.modelUuid);
|
||||||
if (!model) return [];
|
if (!model) return [];
|
||||||
|
@ -125,11 +101,11 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
return [(model as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point];
|
return [(model as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point];
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}, [triggeredModel.modelUuid, modelOptions]);
|
}, [triggeredModel, modelOptions]);
|
||||||
|
|
||||||
const actionOptions: any = useMemo(() => {
|
const actionOptions: any = useMemo(() => {
|
||||||
if (!triggeredPoint.pointUuid) return [];
|
if (!triggeredPoint) return [];
|
||||||
const point = pointOptions.find((p) => p.uuid === triggeredPoint.pointUuid);
|
const point = pointOptions.find((p) => p.uuid === triggeredPoint.uuid);
|
||||||
if (!point) return [];
|
if (!point) return [];
|
||||||
|
|
||||||
if ('action' in point) {
|
if ('action' in point) {
|
||||||
|
@ -140,7 +116,7 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
return typedPoint.actions;
|
return typedPoint.actions;
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}, [triggeredPoint.pointUuid, pointOptions]);
|
}, [triggeredPoint, pointOptions]);
|
||||||
|
|
||||||
const handleModelSelect = (option: string, triggerUuid: string) => {
|
const handleModelSelect = (option: string, triggerUuid: string) => {
|
||||||
if (!selectedProduct) return;
|
if (!selectedProduct) return;
|
||||||
|
@ -160,6 +136,9 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
|
const updatedTrigger = getTriggerByUuid(selectedProduct.productId, triggerUuid);
|
||||||
|
setSelectedTrigger(updatedTrigger);
|
||||||
|
|
||||||
updateBackend(
|
updateBackend(
|
||||||
selectedProduct.productName,
|
selectedProduct.productName,
|
||||||
selectedProduct.productId,
|
selectedProduct.productId,
|
||||||
|
@ -172,8 +151,7 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
const handlePointSelect = (option: string, triggerUuid: string) => {
|
const handlePointSelect = (option: string, triggerUuid: string) => {
|
||||||
if (!selectedProduct || !selectedTrigger) return;
|
if (!selectedProduct || !selectedTrigger) return;
|
||||||
|
|
||||||
const pointUuid = pointOptions.find(p => `Point ${p.uuid.slice(0, 5)}` === option)?.uuid;
|
const pointUuid = pointOptions.find(p => `Point ${p.uuid.slice(0, 4)}` === option)?.uuid;
|
||||||
|
|
||||||
if (!pointUuid) return;
|
if (!pointUuid) return;
|
||||||
|
|
||||||
if (selectedTrigger.triggeredAsset?.triggeredModel) {
|
if (selectedTrigger.triggeredAsset?.triggeredModel) {
|
||||||
|
@ -189,6 +167,9 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
|
const updatedTrigger = getTriggerByUuid(selectedProduct.productId, triggerUuid);
|
||||||
|
setSelectedTrigger(updatedTrigger);
|
||||||
|
|
||||||
updateBackend(
|
updateBackend(
|
||||||
selectedProduct.productName,
|
selectedProduct.productName,
|
||||||
selectedProduct.productId,
|
selectedProduct.productId,
|
||||||
|
@ -199,6 +180,7 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleActionSelect = (option: string, triggerUuid: string) => {
|
const handleActionSelect = (option: string, triggerUuid: string) => {
|
||||||
if (!selectedProduct || !selectedTrigger) return;
|
if (!selectedProduct || !selectedTrigger) return;
|
||||||
|
|
||||||
|
@ -228,6 +210,94 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleAddTrigger = () => {
|
||||||
|
if (!selectedProduct || !currentAction) return;
|
||||||
|
|
||||||
|
const newTrigger: TriggerSchema = {
|
||||||
|
triggerUuid: THREE.MathUtils.generateUUID(),
|
||||||
|
triggerName: `New Trigger ${triggers.length + 1}`,
|
||||||
|
triggerType: activeOption,
|
||||||
|
delay: 0,
|
||||||
|
triggeredAsset: null
|
||||||
|
};
|
||||||
|
|
||||||
|
const event = addTrigger(selectedProduct.productId, currentAction, newTrigger);
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
updateBackend(
|
||||||
|
selectedProduct.productName,
|
||||||
|
selectedProduct.productId,
|
||||||
|
organization,
|
||||||
|
event
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedAction = getActionByUuid(selectedProduct.productId, currentAction);
|
||||||
|
const updatedTriggers = updatedAction?.triggers || [];
|
||||||
|
|
||||||
|
setTriggers(updatedTriggers);
|
||||||
|
setSelectedTrigger(newTrigger);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRemoveTrigger = (triggerUuid: string) => {
|
||||||
|
if (!selectedProduct || !currentAction) return;
|
||||||
|
|
||||||
|
const event = removeTrigger(selectedProduct.productId, triggerUuid);
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
updateBackend(
|
||||||
|
selectedProduct.productName,
|
||||||
|
selectedProduct.productId,
|
||||||
|
organization,
|
||||||
|
event
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const index = triggers.findIndex(t => t.triggerUuid === triggerUuid);
|
||||||
|
const newTriggers = triggers.filter(t => t.triggerUuid !== triggerUuid);
|
||||||
|
setTriggers(newTriggers);
|
||||||
|
|
||||||
|
if (selectedTrigger?.triggerUuid === triggerUuid) {
|
||||||
|
const nextTrigger = newTriggers[index] || newTriggers[index - 1];
|
||||||
|
setSelectedTrigger(nextTrigger);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTriggerRename = (triggerUuid: string, newName: string) => {
|
||||||
|
if (!selectedProduct) return;
|
||||||
|
const event = renameTrigger(selectedProduct.productId, triggerUuid, newName);
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
updateBackend(
|
||||||
|
selectedProduct.productName,
|
||||||
|
selectedProduct.productId,
|
||||||
|
organization,
|
||||||
|
event
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTriggerTypeChange = (option: string) => {
|
||||||
|
if (!selectedTrigger || !selectedProduct) return;
|
||||||
|
|
||||||
|
const validTypes: Array<TriggerSchema['triggerType']> = ["onComplete", "onStart", "onStop", "delay", "onError"];
|
||||||
|
if (!validTypes.includes(option as TriggerSchema['triggerType'])) return;
|
||||||
|
|
||||||
|
setActiveOption(option as TriggerSchema['triggerType']);
|
||||||
|
const event = updateTrigger(selectedProduct.productId, selectedTrigger.triggerUuid, {
|
||||||
|
triggerType: option as TriggerSchema['triggerType']
|
||||||
|
});
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
updateBackend(
|
||||||
|
selectedProduct.productName,
|
||||||
|
selectedProduct.productId,
|
||||||
|
organization,
|
||||||
|
event
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="trigger-wrapper">
|
<div className="trigger-wrapper">
|
||||||
<div className="header">
|
<div className="header">
|
||||||
|
@ -296,19 +366,19 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
<div className="trigger-options">
|
<div className="trigger-options">
|
||||||
<LabledDropdown
|
<LabledDropdown
|
||||||
label="Triggered Object"
|
label="Triggered Object"
|
||||||
defaultOption={triggeredModel.modelName}
|
defaultOption={triggeredModel?.modelName || ""}
|
||||||
options={[...modelOptions.map((option) => (option.modelName))]}
|
options={[...modelOptions.map((option) => (option.modelName))]}
|
||||||
onSelect={(option) => { handleModelSelect(option, selectedTrigger.triggerUuid) }}
|
onSelect={(option) => { handleModelSelect(option, selectedTrigger.triggerUuid) }}
|
||||||
/>
|
/>
|
||||||
<LabledDropdown
|
<LabledDropdown
|
||||||
label="Triggered Point"
|
label="Triggered Point"
|
||||||
defaultOption={triggeredPoint.pointName}
|
defaultOption={triggeredPoint?.uuid ? `Point ${triggeredPoint?.uuid.slice(0, 4)}` : ''}
|
||||||
options={[...pointOptions.map((option) => (`Point ${option.uuid.slice(0, 5)}`))]}
|
options={[...pointOptions.map((option) => (`Point ${option.uuid.slice(0, 4)}`))]}
|
||||||
onSelect={(option) => { handlePointSelect(option, selectedTrigger.triggerUuid) }}
|
onSelect={(option) => { handlePointSelect(option, selectedTrigger.triggerUuid) }}
|
||||||
/>
|
/>
|
||||||
<LabledDropdown
|
<LabledDropdown
|
||||||
label="Triggered Action"
|
label="Triggered Action"
|
||||||
defaultOption={triggeredAction.actionName}
|
defaultOption={triggeredAction?.actionName || ''}
|
||||||
options={[...actionOptions.map((option: any) => (option.actionName))]}
|
options={[...actionOptions.map((option: any) => (option.actionName))]}
|
||||||
onSelect={(option) => { handleActionSelect(option, selectedTrigger.triggerUuid) }}
|
onSelect={(option) => { handleActionSelect(option, selectedTrigger.triggerUuid) }}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -228,7 +228,7 @@ function processLoadedModel(
|
||||||
rotation: [point.rotation[0], point.rotation[1], point.rotation[2]],
|
rotation: [point.rotation[0], point.rotation[1], point.rotation[2]],
|
||||||
action: {
|
action: {
|
||||||
actionUuid: THREE.MathUtils.generateUUID(),
|
actionUuid: THREE.MathUtils.generateUUID(),
|
||||||
actionName: `Action ${index + 1}`,
|
actionName: `Action 1`,
|
||||||
actionType: 'default',
|
actionType: 'default',
|
||||||
material: 'Default material',
|
material: 'Default material',
|
||||||
delay: 0,
|
delay: 0,
|
||||||
|
|
|
@ -173,7 +173,7 @@ const CopyPasteControls = ({ itemsGroupRef, copiedObjects, setCopiedObjects, pas
|
||||||
rotation: [point.rotation[0], point.rotation[1], point.rotation[2]],
|
rotation: [point.rotation[0], point.rotation[1], point.rotation[2]],
|
||||||
action: {
|
action: {
|
||||||
actionUuid: THREE.MathUtils.generateUUID(),
|
actionUuid: THREE.MathUtils.generateUUID(),
|
||||||
actionName: `Action ${index}`,
|
actionName: `Action 1`,
|
||||||
actionType: 'default',
|
actionType: 'default',
|
||||||
material: 'Default Material',
|
material: 'Default Material',
|
||||||
delay: 0,
|
delay: 0,
|
||||||
|
|
|
@ -151,7 +151,7 @@ const DuplicationControls = ({ itemsGroupRef, duplicatedObjects, setDuplicatedOb
|
||||||
rotation: [point.rotation[0], point.rotation[1], point.rotation[2]],
|
rotation: [point.rotation[0], point.rotation[1], point.rotation[2]],
|
||||||
action: {
|
action: {
|
||||||
actionUuid: THREE.MathUtils.generateUUID(),
|
actionUuid: THREE.MathUtils.generateUUID(),
|
||||||
actionName: `Action ${index}`,
|
actionName: `Action 1`,
|
||||||
actionType: 'default',
|
actionType: 'default',
|
||||||
material: 'Default Material',
|
material: 'Default Material',
|
||||||
delay: 0,
|
delay: 0,
|
||||||
|
|
|
@ -15,21 +15,13 @@ import { useThree } from "@react-three/fiber";
|
||||||
function PointsCreator() {
|
function PointsCreator() {
|
||||||
const { gl, raycaster, scene, pointer, camera } = useThree();
|
const { gl, raycaster, scene, pointer, camera } = useThree();
|
||||||
const { subModule } = useSubModuleStore();
|
const { subModule } = useSubModuleStore();
|
||||||
const { events, updatePoint, getPointByUuid, getEventByModelUuid } =
|
const { events, updatePoint, getPointByUuid, getEventByModelUuid } = useEventsStore();
|
||||||
useEventsStore();
|
|
||||||
const { activeModule } = useModuleStore();
|
const { activeModule } = useModuleStore();
|
||||||
const transformRef = useRef<any>(null);
|
const transformRef = useRef<any>(null);
|
||||||
const [transformMode, setTransformMode] = useState<
|
const [transformMode, setTransformMode] = useState<"translate" | "rotate" | null>(null);
|
||||||
"translate" | "rotate" | null
|
|
||||||
>(null);
|
|
||||||
const sphereRefs = useRef<{ [key: string]: THREE.Mesh }>({});
|
const sphereRefs = useRef<{ [key: string]: THREE.Mesh }>({});
|
||||||
const {
|
const { selectedEventSphere, setSelectedEventSphere, clearSelectedEventSphere, } = useSelectedEventSphere();
|
||||||
selectedEventSphere,
|
const { selectedEventData, setSelectedEventData, clearSelectedEventData } = useSelectedEventData();
|
||||||
setSelectedEventSphere,
|
|
||||||
clearSelectedEventSphere,
|
|
||||||
} = useSelectedEventSphere();
|
|
||||||
const { setSelectedEventData, clearSelectedEventData } =
|
|
||||||
useSelectedEventData();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedEventSphere) {
|
if (selectedEventSphere) {
|
||||||
|
@ -136,16 +128,16 @@ function PointsCreator() {
|
||||||
{activeModule === "simulation" && (
|
{activeModule === "simulation" && (
|
||||||
<>
|
<>
|
||||||
<group name="EventPointsGroup">
|
<group name="EventPointsGroup">
|
||||||
{events.map((event, index) => {
|
{events.map((event, i) => {
|
||||||
if (event.type === "transfer") {
|
if (event.type === "transfer") {
|
||||||
return (
|
return (
|
||||||
<group
|
<group
|
||||||
key={`${index}-${event.modelUuid}`}
|
key={i}
|
||||||
position={new THREE.Vector3(...event.position)}
|
position={event.position}
|
||||||
|
rotation={event.rotation}
|
||||||
>
|
>
|
||||||
{event.points.map((point, i) => (
|
{event.points.map((point, j) => (
|
||||||
<mesh
|
<mesh
|
||||||
key={`${i}-${point.uuid}`}
|
|
||||||
name="Event-Sphere"
|
name="Event-Sphere"
|
||||||
uuid={point.uuid}
|
uuid={point.uuid}
|
||||||
ref={(el) => (sphereRefs.current[point.uuid] = el!)}
|
ref={(el) => (sphereRefs.current[point.uuid] = el!)}
|
||||||
|
@ -155,6 +147,7 @@ function PointsCreator() {
|
||||||
sphereRefs.current[point.uuid]
|
sphereRefs.current[point.uuid]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
key={`${i}-${j}`}
|
||||||
position={new THREE.Vector3(...point.position)}
|
position={new THREE.Vector3(...point.position)}
|
||||||
userData={{
|
userData={{
|
||||||
modelUuid: event.modelUuid,
|
modelUuid: event.modelUuid,
|
||||||
|
@ -170,8 +163,9 @@ function PointsCreator() {
|
||||||
} else if (event.type === "vehicle") {
|
} else if (event.type === "vehicle") {
|
||||||
return (
|
return (
|
||||||
<group
|
<group
|
||||||
key={`${index}-${event.modelUuid}`}
|
key={i}
|
||||||
position={new THREE.Vector3(...event.position)}
|
position={event.position}
|
||||||
|
rotation={event.rotation}
|
||||||
>
|
>
|
||||||
<mesh
|
<mesh
|
||||||
name="Event-Sphere"
|
name="Event-Sphere"
|
||||||
|
@ -197,8 +191,9 @@ function PointsCreator() {
|
||||||
} else if (event.type === "roboticArm") {
|
} else if (event.type === "roboticArm") {
|
||||||
return (
|
return (
|
||||||
<group
|
<group
|
||||||
key={`${index}-${event.modelUuid}`}
|
key={i}
|
||||||
position={new THREE.Vector3(...event.position)}
|
position={event.position}
|
||||||
|
rotation={event.rotation}
|
||||||
>
|
>
|
||||||
<mesh
|
<mesh
|
||||||
name="Event-Sphere"
|
name="Event-Sphere"
|
||||||
|
@ -224,8 +219,9 @@ function PointsCreator() {
|
||||||
} else if (event.type === "machine") {
|
} else if (event.type === "machine") {
|
||||||
return (
|
return (
|
||||||
<group
|
<group
|
||||||
key={`${index}-${event.modelUuid}`}
|
key={i}
|
||||||
position={new THREE.Vector3(...event.position)}
|
position={event.position}
|
||||||
|
rotation={event.rotation}
|
||||||
>
|
>
|
||||||
<mesh
|
<mesh
|
||||||
name="Event-Sphere"
|
name="Event-Sphere"
|
||||||
|
|
|
@ -5,10 +5,14 @@ import { useSelectedProduct } from '../../../store/simulation/useSimulationStore
|
||||||
import AddOrRemoveEventsInProducts from './events/addOrRemoveEventsInProducts';
|
import AddOrRemoveEventsInProducts from './events/addOrRemoveEventsInProducts';
|
||||||
import { upsertProductOrEventApi } from '../../../services/simulation/UpsertProductOrEventApi';
|
import { upsertProductOrEventApi } from '../../../services/simulation/UpsertProductOrEventApi';
|
||||||
import { getAllProductsApi } from '../../../services/simulation/getallProductsApi';
|
import { getAllProductsApi } from '../../../services/simulation/getallProductsApi';
|
||||||
|
import { useVehicleStore } from '../../../store/simulation/useVehicleStore';
|
||||||
|
import { useArmBotStore } from '../../../store/simulation/useArmBotStore';
|
||||||
|
|
||||||
function Products() {
|
function Products() {
|
||||||
const { addProduct, setProducts } = useProductStore();
|
const { products, getProductById, addProduct, setProducts } = useProductStore();
|
||||||
const { setSelectedProduct } = useSelectedProduct();
|
const { selectedProduct, setSelectedProduct } = useSelectedProduct();
|
||||||
|
const { addVehicle, clearvehicles } = useVehicleStore();
|
||||||
|
const { addArmBot, clearArmBots } = useArmBotStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const email = localStorage.getItem('email')
|
const email = localStorage.getItem('email')
|
||||||
|
@ -27,6 +31,34 @@ function Products() {
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedProduct.productId) {
|
||||||
|
const product = getProductById(selectedProduct.productId);
|
||||||
|
if (product) {
|
||||||
|
clearvehicles();
|
||||||
|
product.eventDatas.forEach(events => {
|
||||||
|
if (events.type === 'vehicle') {
|
||||||
|
addVehicle(selectedProduct.productId, events);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [selectedProduct, products]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedProduct.productId) {
|
||||||
|
const product = getProductById(selectedProduct.productId);
|
||||||
|
if (product) {
|
||||||
|
clearArmBots();
|
||||||
|
product.eventDatas.forEach(events => {
|
||||||
|
if (events.type === 'roboticArm') {
|
||||||
|
addArmBot(selectedProduct.productId, events);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [selectedProduct, products]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
||||||
|
|
|
@ -147,8 +147,7 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
||||||
else if (armBot && !armBot.isActive && armBot.state === "idle" && currentPhase === "rest" && !armBot.currentAction) {
|
else if (armBot && !armBot.isActive && armBot.state === "idle" && currentPhase === "rest" && !armBot.currentAction) {
|
||||||
logStatus(armBot.modelUuid, "Waiting to trigger CurrentAction")
|
logStatus(armBot.modelUuid, "Waiting to trigger CurrentAction")
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
addCurrentAction(armBot.modelUuid, selectedAction?.actionId);
|
addCurrentAction(armBot.modelUuid, armBot.point.actions[0].actionUuid);
|
||||||
console.log('selectedAction?.actionId: ', selectedAction?.actionId);
|
|
||||||
}, 3000);
|
}, 3000);
|
||||||
return () => clearTimeout(timeoutId);
|
return () => clearTimeout(timeoutId);
|
||||||
}
|
}
|
||||||
|
@ -159,7 +158,6 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
||||||
setArmBotState(armBot.modelUuid, "running");
|
setArmBotState(armBot.modelUuid, "running");
|
||||||
setCurrentPhase("rest-to-start");
|
setCurrentPhase("rest-to-start");
|
||||||
let actiondata = getActionByUuid(selectedProduct.productId, selectedAction.actionId)
|
let actiondata = getActionByUuid(selectedProduct.productId, selectedAction.actionId)
|
||||||
console.log('actiondata: ', actiondata);
|
|
||||||
const startPoint = armBot.point.actions[0].process.startPoint;
|
const startPoint = armBot.point.actions[0].process.startPoint;
|
||||||
if (startPoint) {
|
if (startPoint) {
|
||||||
let curve = createCurveBetweenTwoPoints(restPosition, new THREE.Vector3(startPoint[0], startPoint[1], startPoint[2]));
|
let curve = createCurveBetweenTwoPoints(restPosition, new THREE.Vector3(startPoint[0], startPoint[1], startPoint[2]));
|
||||||
|
|
|
@ -1,46 +1,27 @@
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import RoboticArmInstances from "./instances/roboticArmInstances";
|
import RoboticArmInstances from "./instances/roboticArmInstances";
|
||||||
import { useArmBotStore } from "../../../store/simulation/useArmBotStore";
|
import { useArmBotStore } from "../../../store/simulation/useArmBotStore";
|
||||||
import { useSelectedEventData, useSelectedEventSphere, useSelectedProduct } from "../../../store/simulation/useSimulationStore";
|
import { useSelectedEventData, useSelectedEventSphere } from "../../../store/simulation/useSimulationStore";
|
||||||
import { useProductStore } from "../../../store/simulation/useProductStore";
|
|
||||||
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
|
||||||
import ArmBotUI from "../ui/arm/armBotUI";
|
import ArmBotUI from "../ui/arm/armBotUI";
|
||||||
|
|
||||||
function RoboticArm() {
|
function RoboticArm() {
|
||||||
const { armBots, addArmBot, clearArmBots } = useArmBotStore();
|
const { armBots } = useArmBotStore();
|
||||||
const { products, getProductById } = useProductStore();
|
|
||||||
const { selectedProduct } = useSelectedProduct();
|
|
||||||
const { selectedEventSphere } = useSelectedEventSphere();
|
const { selectedEventSphere } = useSelectedEventSphere();
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventData } = useSelectedEventData();
|
||||||
const { isPlaying } = usePlayButtonStore();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (selectedProduct.productId) {
|
|
||||||
const product = getProductById(selectedProduct.productId);
|
|
||||||
if (product) {
|
|
||||||
clearArmBots();
|
|
||||||
product.eventDatas.forEach(events => {
|
|
||||||
if (events.type === 'roboticArm') {
|
|
||||||
addArmBot(selectedProduct.productId, events);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [selectedProduct, products]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// console.log('armBots: ', armBots);
|
||||||
}, [armBots])
|
}, [armBots])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
|
|
||||||
}, [selectedEventData, selectedEventSphere, isPlaying]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
||||||
<RoboticArmInstances />
|
<RoboticArmInstances />
|
||||||
|
|
||||||
{selectedEventSphere && selectedEventData?.data.type === "roboticArm" &&
|
{selectedEventSphere && selectedEventData?.data.type === "roboticArm" &&
|
||||||
< ArmBotUI />
|
< ArmBotUI />
|
||||||
}
|
}
|
||||||
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useSelectedAction, useSelectedEventData, useSelectedProduct } from '../../../../store/simulation/useSimulationStore';
|
import { useSelectedAction, useSelectedEventData, useSelectedEventSphere, useSelectedProduct } from '../../../../store/simulation/useSimulationStore';
|
||||||
import { useGLTF } from '@react-three/drei';
|
import { useGLTF } from '@react-three/drei';
|
||||||
import { useThree } from '@react-three/fiber';
|
import { useThree } from '@react-three/fiber';
|
||||||
import { useProductStore } from '../../../../store/simulation/useProductStore';
|
import { useProductStore } from '../../../../store/simulation/useProductStore';
|
||||||
|
@ -19,7 +19,7 @@ type Positions = {
|
||||||
|
|
||||||
const ArmBotUI = () => {
|
const ArmBotUI = () => {
|
||||||
const { getEventByModelUuid, updateAction, getActionByUuid } = useProductStore();
|
const { getEventByModelUuid, updateAction, getActionByUuid } = useProductStore();
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventSphere } = useSelectedEventSphere();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
const { scene } = useThree();
|
const { scene } = useThree();
|
||||||
const { selectedAction } = useSelectedAction();
|
const { selectedAction } = useSelectedAction();
|
||||||
|
@ -50,14 +50,14 @@ const ArmBotUI = () => {
|
||||||
|
|
||||||
// Fetch and setup selected ArmBot data
|
// Fetch and setup selected ArmBot data
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedEventData?.data.type === "roboticArm") {
|
if (selectedEventSphere) {
|
||||||
const selectedArmBot = getEventByModelUuid(selectedProduct.productId, selectedEventData.data.modelUuid);
|
const selectedArmBot = getEventByModelUuid(selectedProduct.productId, selectedEventSphere.userData.modelUuid);
|
||||||
|
|
||||||
if (selectedArmBot?.type === "roboticArm") {
|
if (selectedArmBot?.type === "roboticArm") {
|
||||||
setSelectedArmBotData(selectedArmBot);
|
setSelectedArmBotData(selectedArmBot);
|
||||||
const defaultPositions = getDefaultPositions(selectedArmBot.modelUuid);
|
const defaultPositions = getDefaultPositions(selectedArmBot.modelUuid);
|
||||||
const matchingAction = getActionByUuid(selectedProduct.productId, selectedAction.actionId);
|
const matchingAction = getActionByUuid(selectedProduct.productId, selectedAction.actionId);
|
||||||
if (matchingAction) {
|
if (matchingAction && (matchingAction as RoboticArmPointSchema["actions"][0]).process) {
|
||||||
const startPoint = (matchingAction as RoboticArmPointSchema["actions"][0]).process.startPoint;
|
const startPoint = (matchingAction as RoboticArmPointSchema["actions"][0]).process.startPoint;
|
||||||
const pickPosition = (!startPoint || (Array.isArray(startPoint) && startPoint.every(v => v === 0)))
|
const pickPosition = (!startPoint || (Array.isArray(startPoint) && startPoint.every(v => v === 0)))
|
||||||
? defaultPositions.pick
|
? defaultPositions.pick
|
||||||
|
@ -73,8 +73,7 @@ const ArmBotUI = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [selectedEventData, selectedProduct, getEventByModelUuid, selectedAction]);
|
}, [selectedEventSphere, selectedProduct, getEventByModelUuid, selectedAction]);
|
||||||
|
|
||||||
|
|
||||||
function getDefaultPositions(modelUuid: string): Positions {
|
function getDefaultPositions(modelUuid: string): Positions {
|
||||||
const modelData = getEventByModelUuid(selectedProduct.productId, modelUuid);
|
const modelData = getEventByModelUuid(selectedProduct.productId, modelUuid);
|
||||||
|
@ -117,8 +116,8 @@ const ArmBotUI = () => {
|
||||||
obj.getWorldPosition(newPosition);
|
obj.getWorldPosition(newPosition);
|
||||||
const worldPositionArray = newPosition.toArray() as [number, number, number];
|
const worldPositionArray = newPosition.toArray() as [number, number, number];
|
||||||
|
|
||||||
if (selectedEventData?.data.type === "roboticArm") {
|
if (selectedEventSphere) {
|
||||||
const selectedArmBot = getEventByModelUuid(selectedProduct.productId, selectedEventData.data.modelUuid);
|
const selectedArmBot = getEventByModelUuid(selectedProduct.productId, selectedEventSphere.userData.modelUuid);
|
||||||
|
|
||||||
const armBot = selectedArmBot?.modelUuid === modelUuid ? selectedArmBot : null;
|
const armBot = selectedArmBot?.modelUuid === modelUuid ? selectedArmBot : null;
|
||||||
if (!armBot) return;
|
if (!armBot) return;
|
||||||
|
|
|
@ -15,7 +15,7 @@ interface VehicleAnimatorProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetail, reset }: VehicleAnimatorProps) {
|
function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetail, reset }: VehicleAnimatorProps) {
|
||||||
const { decrementVehicleLoad } = useVehicleStore();
|
const { decrementVehicleLoad, getVehicleById } = useVehicleStore();
|
||||||
const { isPaused } = usePauseButtonStore();
|
const { isPaused } = usePauseButtonStore();
|
||||||
const { isPlaying } = usePlayButtonStore();
|
const { isPlaying } = usePlayButtonStore();
|
||||||
const { speed } = useAnimationPlaySpeed();
|
const { speed } = useAnimationPlaySpeed();
|
||||||
|
@ -34,7 +34,6 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
|
||||||
let coveredDistance = progressRef.current;
|
let coveredDistance = progressRef.current;
|
||||||
let objectRotation = (agvDetail.point?.action?.pickUpPoint?.rotation || { x: 0, y: 0, z: 0 }) as { x: number; y: number; z: number } | undefined;
|
let objectRotation = (agvDetail.point?.action?.pickUpPoint?.rotation || { x: 0, y: 0, z: 0 }) as { x: number; y: number; z: number } | undefined;
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentPhase === 'stationed-pickup' && path.length > 0) {
|
if (currentPhase === 'stationed-pickup' && path.length > 0) {
|
||||||
setCurrentPath(path);
|
setCurrentPath(path);
|
||||||
|
@ -69,9 +68,10 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
|
||||||
isPausedRef.current = false;
|
isPausedRef.current = false;
|
||||||
pauseTimeRef.current = 0;
|
pauseTimeRef.current = 0;
|
||||||
const object = scene.getObjectByProperty('uuid', agvUuid);
|
const object = scene.getObjectByProperty('uuid', agvUuid);
|
||||||
if (object) {
|
const vehicle = getVehicleById(agvDetail.modelUuid);
|
||||||
object.position.set(agvDetail.position[0], agvDetail.position[1], agvDetail.position[2]);
|
if (object && vehicle) {
|
||||||
object.rotation.set(agvDetail.rotation[0], agvDetail.rotation[1], agvDetail.rotation[2]);
|
object.position.set(vehicle.position[0], vehicle.position[1], vehicle.position[2]);
|
||||||
|
object.rotation.set(vehicle.rotation[0], vehicle.rotation[1], vehicle.rotation[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [isReset, isPlaying])
|
}, [isReset, isPlaying])
|
||||||
|
|
|
@ -1,35 +1,18 @@
|
||||||
import React, { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import VehicleInstances from "./instances/vehicleInstances";
|
import VehicleInstances from "./instances/vehicleInstances";
|
||||||
import { useVehicleStore } from "../../../store/simulation/useVehicleStore";
|
import { useVehicleStore } from "../../../store/simulation/useVehicleStore";
|
||||||
import { useSelectedEventData, useSelectedEventSphere, useSelectedProduct } from "../../../store/simulation/useSimulationStore";
|
import { useSelectedEventData, useSelectedEventSphere } from "../../../store/simulation/useSimulationStore";
|
||||||
import VehicleUI from "../ui/vehicle/vehicleUI";
|
import VehicleUI from "../ui/vehicle/vehicleUI";
|
||||||
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
||||||
import { useProductStore } from "../../../store/simulation/useProductStore";
|
|
||||||
|
|
||||||
function Vehicles() {
|
function Vehicles() {
|
||||||
const { products, getProductById } = useProductStore();
|
const { vehicles } = useVehicleStore();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
|
||||||
const { vehicles, addVehicle, clearvehicles } = useVehicleStore();
|
|
||||||
const { selectedEventSphere } = useSelectedEventSphere();
|
const { selectedEventSphere } = useSelectedEventSphere();
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventData } = useSelectedEventData();
|
||||||
const { isPlaying } = usePlayButtonStore();
|
const { isPlaying } = usePlayButtonStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedProduct.productId) {
|
// console.log('vehicles: ', vehicles);
|
||||||
const product = getProductById(selectedProduct.productId);
|
|
||||||
if (product) {
|
|
||||||
clearvehicles();
|
|
||||||
product.eventDatas.forEach(events => {
|
|
||||||
if (events.type === 'vehicle') {
|
|
||||||
addVehicle(selectedProduct.productId, events);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [selectedProduct, products]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
//
|
|
||||||
}, [vehicles])
|
}, [vehicles])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -56,7 +56,7 @@ type ProductsStore = {
|
||||||
// Renaming functions
|
// Renaming functions
|
||||||
renameProduct: (productId: string, newName: string) => void;
|
renameProduct: (productId: string, newName: string) => void;
|
||||||
renameAction: (productId: string, actionUuid: string, newName: string) => EventsSchema | undefined;
|
renameAction: (productId: string, actionUuid: string, newName: string) => EventsSchema | undefined;
|
||||||
renameTrigger: (productId: string, triggerUuid: string, newName: string) => void;
|
renameTrigger: (productId: string, triggerUuid: string, newName: string) => EventsSchema | undefined;
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
getProductById: (productId: string) => { productName: string; productId: string; eventDatas: EventsSchema[] } | undefined;
|
getProductById: (productId: string) => { productName: string; productId: string; eventDatas: EventsSchema[] } | undefined;
|
||||||
|
@ -482,6 +482,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
},
|
},
|
||||||
|
|
||||||
renameTrigger: (productId, triggerUuid, newName) => {
|
renameTrigger: (productId, triggerUuid, newName) => {
|
||||||
|
let updatedEvent: EventsSchema | undefined;
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const product = state.products.find(p => p.productId === productId);
|
const product = state.products.find(p => p.productId === productId);
|
||||||
if (product) {
|
if (product) {
|
||||||
|
@ -492,6 +493,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
|
const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
|
||||||
if (trigger) {
|
if (trigger) {
|
||||||
trigger.triggerName = newName;
|
trigger.triggerName = newName;
|
||||||
|
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -502,6 +504,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||||
if (trigger) {
|
if (trigger) {
|
||||||
trigger.triggerName = newName;
|
trigger.triggerName = newName;
|
||||||
|
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if ('actions' in point) {
|
} else if ('actions' in point) {
|
||||||
|
@ -510,6 +513,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||||
if (trigger) {
|
if (trigger) {
|
||||||
trigger.triggerName = newName;
|
trigger.triggerName = newName;
|
||||||
|
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -519,6 +523,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return updatedEvent;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
|
|
Loading…
Reference in New Issue