2025-04-08 18:31:57 +05:30
|
|
|
import React, { useRef, useMemo, useCallback, useState } from "react";
|
2025-04-07 18:16:34 +05:30
|
|
|
import { InfoIcon } from "../../../icons/ExportCommonIcons";
|
|
|
|
|
import InputWithDropDown from "../../../ui/inputs/InputWithDropDown";
|
2025-04-08 18:31:57 +05:30
|
|
|
import {
|
|
|
|
|
useSelectedActionSphere,
|
|
|
|
|
useSimulationStates,
|
|
|
|
|
useSocketStore
|
|
|
|
|
} from "../../../../store/store";
|
2025-04-07 18:16:34 +05:30
|
|
|
import * as Types from '../../../../types/world/worldTypes';
|
2025-04-08 18:31:57 +05:30
|
|
|
import LabeledButton from "../../../ui/inputs/LabledButton";
|
|
|
|
|
import LabledDropdown from "../../../ui/inputs/LabledDropdown";
|
2025-04-07 18:16:34 +05:30
|
|
|
|
|
|
|
|
const ArmBotMechanics: React.FC = () => {
|
|
|
|
|
const { selectedActionSphere } = useSelectedActionSphere();
|
|
|
|
|
const { simulationStates, setSimulationStates } = useSimulationStates();
|
|
|
|
|
const { socket } = useSocketStore();
|
2025-04-08 18:31:57 +05:30
|
|
|
const [selectedTrigger, setSelectedTrigger] = useState<string | null>(null);
|
2025-04-07 18:16:34 +05:30
|
|
|
|
|
|
|
|
const propertiesContainerRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
2025-04-08 18:31:57 +05:30
|
|
|
// Get connected models for dropdowns
|
|
|
|
|
const connectedModels = useMemo(() => {
|
|
|
|
|
if (!selectedActionSphere?.points?.uuid) return [];
|
2025-04-07 18:16:34 +05:30
|
|
|
|
2025-04-08 18:31:57 +05:30
|
|
|
}, [selectedActionSphere, simulationStates]);
|
|
|
|
|
|
|
|
|
|
// Get triggers only from connected models
|
|
|
|
|
const connectedTriggers = useMemo(() => {
|
|
|
|
|
}, [connectedModels, simulationStates]);
|
|
|
|
|
|
|
|
|
|
const { selectedPoint } = useMemo(() => {
|
|
|
|
|
if (!selectedActionSphere?.points?.uuid) return { selectedPoint: null };
|
|
|
|
|
|
|
|
|
|
const armBotPaths = simulationStates.filter(
|
2025-04-07 18:16:34 +05:30
|
|
|
(path): path is Types.ArmBotEventsSchema => path.type === "ArmBot"
|
|
|
|
|
);
|
|
|
|
|
|
2025-04-08 18:31:57 +05:30
|
|
|
const points = armBotPaths.find(
|
2025-04-07 18:16:34 +05:30
|
|
|
(path) => path.points.uuid === selectedActionSphere.points.uuid
|
|
|
|
|
)?.points;
|
|
|
|
|
|
|
|
|
|
return {
|
2025-04-08 18:31:57 +05:30
|
|
|
selectedPoint: points || null
|
2025-04-07 18:16:34 +05:30
|
|
|
};
|
|
|
|
|
}, [selectedActionSphere, simulationStates]);
|
|
|
|
|
|
|
|
|
|
const updateBackend = async (updatedPath: Types.ArmBotEventsSchema | undefined) => {
|
2025-04-08 18:31:57 +05:30
|
|
|
// if (!updatedPath) return;
|
|
|
|
|
// const email = localStorage.getItem("email");
|
|
|
|
|
// const organization = email ? email.split("@")[1].split(".")[0] : "";
|
2025-04-07 18:16:34 +05:30
|
|
|
|
2025-04-08 18:31:57 +05:30
|
|
|
// const data = {
|
|
|
|
|
// organization: organization,
|
|
|
|
|
// modeluuid: updatedPath.modeluuid,
|
|
|
|
|
// eventData: { type: "ArmBot", points: updatedPath.points }
|
|
|
|
|
// }
|
2025-04-07 18:16:34 +05:30
|
|
|
|
2025-04-08 18:31:57 +05:30
|
|
|
// socket.emit('v2:model-asset:updateEventData', data);
|
|
|
|
|
}
|
2025-04-07 18:16:34 +05:30
|
|
|
|
2025-04-08 18:31:57 +05:30
|
|
|
// const handleActionUpdate = useCallback((updatedAction: Partial<Types.ArmBotEventsSchema['points']['actions']>) => {
|
|
|
|
|
// if (!selectedActionSphere?.points?.uuid) return;
|
2025-04-07 18:16:34 +05:30
|
|
|
|
2025-04-08 18:31:57 +05:30
|
|
|
// const updatedPaths = simulationStates.map((path) => {
|
|
|
|
|
// return path;
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// const updatedPath = updatedPaths.find(
|
|
|
|
|
// (path): path is Types.ArmBotEventsSchema =>
|
|
|
|
|
// path.type === "ArmBot" &&
|
|
|
|
|
// path.points.uuid === selectedActionSphere.points.uuid
|
|
|
|
|
// );
|
|
|
|
|
// updateBackend(updatedPath);
|
|
|
|
|
|
|
|
|
|
// setSimulationStates(updatedPaths);
|
|
|
|
|
// }, [selectedActionSphere?.points?.uuid, simulationStates, setSimulationStates]);
|
2025-04-07 18:16:34 +05:30
|
|
|
|
2025-04-08 18:31:57 +05:30
|
|
|
// const handleSpeedChange = useCallback((speed: number) => {
|
|
|
|
|
// handleActionUpdate({ speed });
|
|
|
|
|
// }, [handleActionUpdate]);
|
|
|
|
|
|
|
|
|
|
// const handleProcessChange = useCallback((processes: Types.ArmBotEventsSchema['points']['actions']['processes']) => {
|
|
|
|
|
// handleActionUpdate({ processes });
|
|
|
|
|
// }, [handleActionUpdate]);
|
|
|
|
|
|
|
|
|
|
// const handleTriggerSelect = useCallback((displayName: string) => {
|
|
|
|
|
// const selected = connectedTriggers.find(t => t.displayName === displayName);
|
|
|
|
|
// setSelectedTrigger(selected?.uuid || null);
|
|
|
|
|
// }, [connectedTriggers]);
|
|
|
|
|
|
|
|
|
|
// const handleStartPointSelect = useCallback((pointUUID: string) => {
|
|
|
|
|
// if (!selectedTrigger || !selectedPoint) return;
|
|
|
|
|
|
|
|
|
|
// const updatedProcesses = selectedPoint.actions.processes?.map(process =>
|
|
|
|
|
// process.triggerId === selectedTrigger
|
|
|
|
|
// ? { ...process, startPoint: pointUUID }
|
|
|
|
|
// : process
|
|
|
|
|
// ) || [];
|
|
|
|
|
|
|
|
|
|
// handleProcessChange(updatedProcesses);
|
|
|
|
|
// }, [selectedTrigger, selectedPoint, handleProcessChange]);
|
|
|
|
|
|
|
|
|
|
// const handleEndPointSelect = useCallback((pointUUID: string) => {
|
|
|
|
|
// if (!selectedTrigger || !selectedPoint) return;
|
|
|
|
|
|
|
|
|
|
// const updatedProcesses = selectedPoint.actions.processes?.map(process =>
|
|
|
|
|
// process.triggerId === selectedTrigger
|
|
|
|
|
// ? { ...process, endPoint: pointUUID }
|
|
|
|
|
// : process
|
|
|
|
|
// ) || [];
|
|
|
|
|
|
|
|
|
|
// handleProcessChange(updatedProcesses);
|
|
|
|
|
// }, [selectedTrigger, selectedPoint, handleProcessChange]);
|
|
|
|
|
|
|
|
|
|
// const getCurrentProcess = useCallback(() => {
|
|
|
|
|
// if (!selectedTrigger || !selectedPoint) return null;
|
|
|
|
|
// return selectedPoint.actions.processes?.find(p => p.triggerId === selectedTrigger);
|
|
|
|
|
// }, [selectedTrigger, selectedPoint]);
|
2025-04-07 18:16:34 +05:30
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="machine-mechanics-container" key={selectedPoint?.uuid}>
|
|
|
|
|
<div className="machine-mechanics-header">
|
|
|
|
|
{selectedActionSphere?.path?.modelName || "ArmBot point not found"}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="machine-mechanics-content-container">
|
|
|
|
|
<div className="selected-properties-container" ref={propertiesContainerRef}>
|
|
|
|
|
<div className="properties-header">ArmBot Properties</div>
|
|
|
|
|
|
2025-04-08 18:31:57 +05:30
|
|
|
{/* {selectedPoint && (
|
2025-04-07 18:16:34 +05:30
|
|
|
<>
|
2025-04-08 18:31:57 +05:30
|
|
|
<InputWithDropDown
|
|
|
|
|
key={`speed-${selectedPoint.uuid}`}
|
|
|
|
|
label="ArmBot Speed"
|
|
|
|
|
value={selectedPoint.actions.speed.toString()}
|
|
|
|
|
onChange={(value) => handleSpeedChange(parseInt(value))}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<LabledDropdown
|
|
|
|
|
key={`trigger-select-${selectedPoint.uuid}`}
|
|
|
|
|
label="Select Trigger"
|
|
|
|
|
defaultOption={connectedTriggers.find(t => t.uuid === selectedTrigger)?.displayName || ''}
|
|
|
|
|
onSelect={handleTriggerSelect}
|
|
|
|
|
options={connectedTriggers.map(trigger => trigger.displayName)}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{selectedTrigger && (
|
|
|
|
|
<>
|
|
|
|
|
<LabledDropdown
|
|
|
|
|
key={`start-point-${selectedTrigger}`}
|
|
|
|
|
label="Start Point"
|
|
|
|
|
defaultOption={getCurrentProcess()?.startPoint || ''}
|
|
|
|
|
onSelect={handleStartPointSelect}
|
|
|
|
|
options={connectedModels.map((model, index) => `${model.modelName} [${index}]`)}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<LabledDropdown
|
|
|
|
|
key={`end-point-${selectedTrigger}`}
|
|
|
|
|
label="End Point"
|
|
|
|
|
defaultOption={getCurrentProcess()?.endPoint || ''}
|
|
|
|
|
onSelect={handleEndPointSelect}
|
|
|
|
|
options={connectedModels.map((model, index) => `${model.modelName} [${index}]`)}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2025-04-07 18:16:34 +05:30
|
|
|
</>
|
2025-04-08 18:31:57 +05:30
|
|
|
)} */}
|
2025-04-07 18:16:34 +05:30
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="footer">
|
|
|
|
|
<InfoIcon />
|
2025-04-08 18:31:57 +05:30
|
|
|
Configure ArmBot properties and trigger-based processes.
|
2025-04-07 18:16:34 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default React.memo(ArmBotMechanics);
|