Refactor Trigger component: remove console logs and clean up unused code in Trigger and RoboticArm components; update ArmBotUI to improve state management and backend integration; fix typo in useProductStore comments.
This commit is contained in:
parent
9233bb97c8
commit
d29c4ce48a
app/src
components/layout/sidebarRight/properties/eventProperties/trigger
modules/simulation
store/simulation
|
@ -110,8 +110,6 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||||
const triggeredModel = selectedTrigger?.triggeredAsset?.triggeredModel || { modelName: "Select Model", modelUuid: "" };
|
const triggeredModel = selectedTrigger?.triggeredAsset?.triggeredModel || { modelName: "Select Model", modelUuid: "" };
|
||||||
const triggeredPoint = selectedTrigger?.triggeredAsset?.triggeredPoint || { pointName: "Select Point", pointUuid: "" };
|
const triggeredPoint = selectedTrigger?.triggeredAsset?.triggeredPoint || { pointName: "Select Point", pointUuid: "" };
|
||||||
const triggeredAction = selectedTrigger?.triggeredAsset?.triggeredAction || { actionName: "Select Action", actionUuid: "" };
|
const triggeredAction = selectedTrigger?.triggeredAsset?.triggeredAction || { actionName: "Select Action", actionUuid: "" };
|
||||||
console.log('selectedTrigger: ', selectedTrigger);
|
|
||||||
console.log('triggeredAction: ', triggeredAction);
|
|
||||||
|
|
||||||
const modelOptions = getProductById(selectedProduct.productId)?.eventDatas || [];
|
const modelOptions = getProductById(selectedProduct.productId)?.eventDatas || [];
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
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 { useFloorItems } from "../../../store/store";
|
|
||||||
import { useSelectedEventData, useSelectedEventSphere, useSelectedProduct } from "../../../store/simulation/useSimulationStore";
|
import { useSelectedEventData, useSelectedEventSphere, useSelectedProduct } from "../../../store/simulation/useSimulationStore";
|
||||||
import { useProductStore } from "../../../store/simulation/useProductStore";
|
import { useProductStore } from "../../../store/simulation/useProductStore";
|
||||||
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
||||||
|
@ -14,148 +13,6 @@ function RoboticArm() {
|
||||||
const { selectedEventSphere } = useSelectedEventSphere();
|
const { selectedEventSphere } = useSelectedEventSphere();
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventData } = useSelectedEventData();
|
||||||
const { isPlaying } = usePlayButtonStore();
|
const { isPlaying } = usePlayButtonStore();
|
||||||
const { floorItems } = useFloorItems();
|
|
||||||
|
|
||||||
const armBotStatusSample: RoboticArmEventSchema[] = [
|
|
||||||
{
|
|
||||||
state: "idle",
|
|
||||||
modelUuid: "8790b4d5-fb6e-49e0-8161-04945fe3fdc4",
|
|
||||||
modelName: "ArmBot-X200",
|
|
||||||
position: [4.317833205016363, 0, -3.2829924989068715],
|
|
||||||
rotation: [-1.3768690876192207e-15, 1.4883085074751308, 1.5407776675834467e-15],
|
|
||||||
type: "roboticArm",
|
|
||||||
speed: 1.5,
|
|
||||||
point: {
|
|
||||||
uuid: "point-123",
|
|
||||||
position: [0, 2.6, 0],
|
|
||||||
rotation: [0, 0, 0],
|
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
actionUuid: "action-003",
|
|
||||||
actionName: "Pick Component",
|
|
||||||
actionType: "pickAndPlace",
|
|
||||||
process: {
|
|
||||||
startPoint: [-1, 2, 1],
|
|
||||||
endPoint: [-2, 1, -1],
|
|
||||||
// startPoint: [-2, 1, -1],
|
|
||||||
// endPoint: [-1, 2, 1],
|
|
||||||
},
|
|
||||||
triggers: [
|
|
||||||
{
|
|
||||||
triggerUuid: "trigger-001",
|
|
||||||
triggerName: "Start Trigger",
|
|
||||||
triggerType: "onStart",
|
|
||||||
delay: 0,
|
|
||||||
triggeredAsset: {
|
|
||||||
triggeredModel: {
|
|
||||||
modelName: "Conveyor A1",
|
|
||||||
modelUuid: "conveyor-01",
|
|
||||||
},
|
|
||||||
triggeredPoint: {
|
|
||||||
pointName: "Start Point",
|
|
||||||
pointUuid: "conveyor-01-point-001",
|
|
||||||
},
|
|
||||||
triggeredAction: {
|
|
||||||
actionName: "Move Forward",
|
|
||||||
actionUuid: "conveyor-action-01",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
triggerUuid: "trigger-002",
|
|
||||||
triggerName: "Complete Trigger",
|
|
||||||
triggerType: "onComplete",
|
|
||||||
delay: 0,
|
|
||||||
triggeredAsset: {
|
|
||||||
triggeredModel: {
|
|
||||||
modelName: "StaticMachine B2",
|
|
||||||
modelUuid: "machine-02",
|
|
||||||
},
|
|
||||||
triggeredPoint: {
|
|
||||||
pointName: "Receive Point",
|
|
||||||
pointUuid: "machine-02-point-001",
|
|
||||||
},
|
|
||||||
triggeredAction: {
|
|
||||||
actionName: "Process Part",
|
|
||||||
actionUuid: "machine-action-01",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
state: "idle",
|
|
||||||
modelUuid: "armbot-xyz-002",
|
|
||||||
modelName: "ArmBot-X200",
|
|
||||||
position: [95.94347308985614, 0, 6.742905194869091],
|
|
||||||
rotation: [0, 0, 0],
|
|
||||||
type: "roboticArm",
|
|
||||||
speed: 0.1,
|
|
||||||
point: {
|
|
||||||
uuid: "point-123",
|
|
||||||
position: [0, 1.5, 0],
|
|
||||||
rotation: [0, 0, 0],
|
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
actionUuid: "action-001",
|
|
||||||
actionName: "Pick Component",
|
|
||||||
actionType: "pickAndPlace",
|
|
||||||
process: {
|
|
||||||
// startPoint: [2.52543010919071, 0, 8.433681161200905],
|
|
||||||
// endPoint: [95.3438373267953, 0, 9.0279187421610025],
|
|
||||||
startPoint: null,
|
|
||||||
endPoint: null,
|
|
||||||
},
|
|
||||||
triggers: [
|
|
||||||
{
|
|
||||||
triggerUuid: "trigger-001",
|
|
||||||
triggerName: "Start Trigger",
|
|
||||||
triggerType: "onStart",
|
|
||||||
delay: 0,
|
|
||||||
triggeredAsset: {
|
|
||||||
triggeredModel: {
|
|
||||||
modelName: "Conveyor A1",
|
|
||||||
modelUuid: "conveyor-01",
|
|
||||||
},
|
|
||||||
triggeredPoint: {
|
|
||||||
pointName: "Start Point",
|
|
||||||
pointUuid: "conveyor-01-point-001",
|
|
||||||
},
|
|
||||||
triggeredAction: {
|
|
||||||
actionName: "Move Forward",
|
|
||||||
actionUuid: "conveyor-action-01",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
triggerUuid: "trigger-002",
|
|
||||||
triggerName: "Complete Trigger",
|
|
||||||
triggerType: "onComplete",
|
|
||||||
delay: 0,
|
|
||||||
triggeredAsset: {
|
|
||||||
triggeredModel: {
|
|
||||||
modelName: "StaticMachine B2",
|
|
||||||
modelUuid: "machine-02",
|
|
||||||
},
|
|
||||||
triggeredPoint: {
|
|
||||||
pointName: "Receive Point",
|
|
||||||
pointUuid: "machine-02-point-001",
|
|
||||||
},
|
|
||||||
triggeredAction: {
|
|
||||||
actionName: "Process Part",
|
|
||||||
actionUuid: "machine-action-01",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedProduct.productId) {
|
if (selectedProduct.productId) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useSelectedAction, useSelectedEventData, useSelectedEventSphere, useSelectedProduct } from '../../../../store/simulation/useSimulationStore';
|
import { useSelectedAction, useSelectedEventData, useSelectedProduct } from '../../../../store/simulation/useSimulationStore';
|
||||||
import { useArmBotStore } from '../../../../store/simulation/useArmBotStore';
|
import { useArmBotStore } from '../../../../store/simulation/useArmBotStore';
|
||||||
import { useGLTF } from '@react-three/drei';
|
import { useGLTF } from '@react-three/drei';
|
||||||
import { useThree } from '@react-three/fiber';
|
import { useThree } from '@react-three/fiber';
|
||||||
|
@ -10,7 +10,7 @@ import * as THREE from 'three';
|
||||||
|
|
||||||
import armPick from "../../../../assets/gltf-glb/arm_ui_pick.glb";
|
import armPick from "../../../../assets/gltf-glb/arm_ui_pick.glb";
|
||||||
import armDrop from "../../../../assets/gltf-glb/arm_ui_drop.glb";
|
import armDrop from "../../../../assets/gltf-glb/arm_ui_drop.glb";
|
||||||
import useModuleStore from '../../../../store/useModuleStore';
|
import { upsertProductOrEventApi } from '../../../../services/simulation/UpsertProductOrEventApi';
|
||||||
|
|
||||||
type Positions = {
|
type Positions = {
|
||||||
pick: [number, number, number];
|
pick: [number, number, number];
|
||||||
|
@ -19,20 +19,37 @@ type Positions = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const ArmBotUI = () => {
|
const ArmBotUI = () => {
|
||||||
const { getEventByModelUuid } = useProductStore();
|
const { getEventByModelUuid, updateAction } = useProductStore();
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventData } = useSelectedEventData();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
const { armBots, updateStartPoint, updateEndPoint } = useArmBotStore();
|
const { armBots } = useArmBotStore();
|
||||||
const { scene } = useThree();
|
const { scene } = useThree();
|
||||||
const { selectedAction } = useSelectedAction();
|
const { selectedAction } = useSelectedAction();
|
||||||
|
|
||||||
const armUiPick = useGLTF(armPick) as any;
|
const armUiPick = useGLTF(armPick) as any;
|
||||||
const armUiDrop = useGLTF(armDrop) as any;
|
const armUiDrop = useGLTF(armDrop) as any;
|
||||||
|
|
||||||
const [startPosition, setStartPosition] = useState<[number, number, number]>([0, 0, 0]);
|
const [startPosition, setStartPosition] = useState<[number, number, number] | null>([0, 0, 0]);
|
||||||
const [endPosition, setEndPosition] = useState<[number, number, number]>([0, 0, 0]);
|
const [endPosition, setEndPosition] = useState<[number, number, number] | null>([0, 0, 0]);
|
||||||
const [selectedArmBotData, setSelectedArmBotData] = useState<any>(null);
|
const [selectedArmBotData, setSelectedArmBotData] = useState<any>(null);
|
||||||
|
|
||||||
|
const email = localStorage.getItem('email')
|
||||||
|
const organization = (email!.split("@")[1]).split(".")[0];
|
||||||
|
|
||||||
|
const updateBackend = (
|
||||||
|
productName: string,
|
||||||
|
productId: string,
|
||||||
|
organization: string,
|
||||||
|
eventData: EventsSchema
|
||||||
|
) => {
|
||||||
|
upsertProductOrEventApi({
|
||||||
|
productName: productName,
|
||||||
|
productId: productId,
|
||||||
|
organization: organization,
|
||||||
|
eventDatas: eventData
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch and setup selected ArmBot data
|
// Fetch and setup selected ArmBot data
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedEventData?.data.type === "roboticArm") {
|
if (selectedEventData?.data.type === "roboticArm") {
|
||||||
|
@ -59,7 +76,7 @@ const ArmBotUI = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [selectedEventData, selectedProduct, getEventByModelUuid, selectedAction]);
|
}, [selectedEventData, selectedProduct, getEventByModelUuid, selectedAction, armBots]);
|
||||||
|
|
||||||
|
|
||||||
function getDefaultPositions(modelUuid: string): Positions {
|
function getDefaultPositions(modelUuid: string): Positions {
|
||||||
|
@ -110,18 +127,34 @@ const ArmBotUI = () => {
|
||||||
if (!armBot) return;
|
if (!armBot) return;
|
||||||
|
|
||||||
if (armBot.type === "roboticArm") {
|
if (armBot.type === "roboticArm") {
|
||||||
armBot?.point?.actions?.map((action: any) => {
|
armBot?.point?.actions?.map((action) => {
|
||||||
if (action.actionUuid === actionUuid) {
|
if (action.actionUuid === actionUuid) {
|
||||||
const updatedProcess = { ...action.process };
|
const updatedProcess = { ...action.process };
|
||||||
|
|
||||||
if (actionType === "pick") {
|
if (actionType === "pick") {
|
||||||
updatedProcess.startPoint = getLocalPosition(modelUuid, worldPositionArray);
|
updatedProcess.startPoint = getLocalPosition(modelUuid, worldPositionArray);
|
||||||
setStartPosition(updatedProcess.startPoint)
|
setStartPosition(updatedProcess.startPoint)
|
||||||
updateStartPoint(modelUuid, actionUuid, updatedProcess.startPoint);
|
|
||||||
} else if (actionType === "drop") {
|
} else if (actionType === "drop") {
|
||||||
updatedProcess.endPoint = getLocalPosition(modelUuid, worldPositionArray);
|
updatedProcess.endPoint = getLocalPosition(modelUuid, worldPositionArray);
|
||||||
setEndPosition(updatedProcess.endPoint)
|
setEndPosition(updatedProcess.endPoint)
|
||||||
updateEndPoint(modelUuid, actionUuid, updatedProcess.endPoint);
|
}
|
||||||
|
|
||||||
|
const event = updateAction(selectedProduct.productId,
|
||||||
|
actionUuid,
|
||||||
|
{
|
||||||
|
actionUuid: action.actionUuid,
|
||||||
|
process: updatedProcess,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
updateBackend(
|
||||||
|
selectedProduct.productName,
|
||||||
|
selectedProduct.productId,
|
||||||
|
organization,
|
||||||
|
event
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...action,
|
...action,
|
||||||
|
@ -135,11 +168,6 @@ const ArmBotUI = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
|
|
||||||
|
|
||||||
}, [armBots])
|
|
||||||
|
|
||||||
const { handlePointerDown } = useDraggableGLTF(updatePointToState);
|
const { handlePointerDown } = useDraggableGLTF(updatePointToState);
|
||||||
|
|
||||||
if (!selectedArmBotData || !Array.isArray(selectedArmBotData.point?.actions)) {
|
if (!selectedArmBotData || !Array.isArray(selectedArmBotData.point?.actions)) {
|
||||||
|
@ -155,6 +183,8 @@ const ArmBotUI = () => {
|
||||||
position={new THREE.Vector3(...selectedArmBotData.position)}
|
position={new THREE.Vector3(...selectedArmBotData.position)}
|
||||||
rotation={new THREE.Euler(...selectedArmBotData.rotation)}
|
rotation={new THREE.Euler(...selectedArmBotData.rotation)}
|
||||||
>
|
>
|
||||||
|
{startPosition && endPosition && (
|
||||||
|
<>
|
||||||
<PickDropPoints
|
<PickDropPoints
|
||||||
position={startPosition}
|
position={startPosition}
|
||||||
modelUuid={selectedArmBotData.modelUuid}
|
modelUuid={selectedArmBotData.modelUuid}
|
||||||
|
@ -175,6 +205,8 @@ const ArmBotUI = () => {
|
||||||
handlePointerDown={handlePointerDown}
|
handlePointerDown={handlePointerDown}
|
||||||
isSelected={true}
|
isSelected={true}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</group>
|
</group>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
|
|
|
@ -40,7 +40,7 @@ type ProductsStore = {
|
||||||
updates: Partial<ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']>
|
updates: Partial<ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']>
|
||||||
) => EventsSchema | undefined;
|
) => EventsSchema | undefined;
|
||||||
|
|
||||||
// Trigger-level actions
|
// Trigger-level actionss
|
||||||
addTrigger: (
|
addTrigger: (
|
||||||
productId: string,
|
productId: string,
|
||||||
actionUuid: string,
|
actionUuid: string,
|
||||||
|
|
Loading…
Reference in New Issue