Merge remote-tracking branch 'origin/rtViz' into simulation
This commit is contained in:
commit
77b0a9bbf9
|
@ -46,7 +46,7 @@ const StateWorking: React.FC<StateWorkingProps> = ({ id, type, position, rotatio
|
||||||
socket.on("connect", startStream);
|
socket.on("connect", startStream);
|
||||||
socket.on("lastOutput", (response) => {
|
socket.on("lastOutput", (response) => {
|
||||||
const responseData = response;
|
const responseData = response;
|
||||||
console.log("responceeeeeeeeeee", response);
|
|
||||||
|
|
||||||
setDatas(responseData);
|
setDatas(responseData);
|
||||||
});
|
});
|
||||||
|
@ -76,7 +76,7 @@ const StateWorking: React.FC<StateWorkingProps> = ({ id, type, position, rotatio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("dataaaaa", datas);
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -50,6 +50,7 @@ export default function Dropped3dWidgets() {
|
||||||
const rotationStartRef = useRef<[number, number, number]>([0, 0, 0]);
|
const rotationStartRef = useRef<[number, number, number]>([0, 0, 0]);
|
||||||
const mouseStartRef = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
|
const mouseStartRef = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activeModule !== "visualization") return;
|
if (activeModule !== "visualization") return;
|
||||||
if (!selectedZone.zoneId) return;
|
if (!selectedZone.zoneId) return;
|
||||||
|
@ -139,8 +140,6 @@ export default function Dropped3dWidgets() {
|
||||||
|
|
||||||
if (rightSelect === "Duplicate") {
|
if (rightSelect === "Duplicate") {
|
||||||
async function duplicateWidget() {
|
async function duplicateWidget() {
|
||||||
|
|
||||||
|
|
||||||
const widgetToDuplicate = activeZoneWidgets.find((w: WidgetData) => w.id === rightClickSelected);
|
const widgetToDuplicate = activeZoneWidgets.find((w: WidgetData) => w.id === rightClickSelected);
|
||||||
if (!widgetToDuplicate) return;
|
if (!widgetToDuplicate) return;
|
||||||
const newWidget: WidgetData = {
|
const newWidget: WidgetData = {
|
||||||
|
@ -154,12 +153,15 @@ export default function Dropped3dWidgets() {
|
||||||
rotation: widgetToDuplicate.rotation || [0, 0, 0],
|
rotation: widgetToDuplicate.rotation || [0, 0, 0],
|
||||||
};
|
};
|
||||||
const adding3dWidget = {
|
const adding3dWidget = {
|
||||||
organization,
|
organization: organization,
|
||||||
widget: newWidget,
|
widget: newWidget,
|
||||||
zoneId: selectedZone.zoneId
|
zoneId: selectedZone.zoneId
|
||||||
};
|
};
|
||||||
let response = await adding3dWidgets(selectedZone.zoneId, organization, newWidget)
|
if (visualizationSocket) {
|
||||||
console.log('response: ', response);
|
visualizationSocket.emit("v2:viz-3D-widget:add", adding3dWidget);
|
||||||
|
}
|
||||||
|
// let response = await adding3dWidgets(selectedZone.zoneId, organization, newWidget)
|
||||||
|
// console.log('response: ', response);
|
||||||
|
|
||||||
addWidget(selectedZone.zoneId, newWidget);
|
addWidget(selectedZone.zoneId, newWidget);
|
||||||
setRightSelect(null);
|
setRightSelect(null);
|
||||||
|
@ -173,23 +175,20 @@ export default function Dropped3dWidgets() {
|
||||||
try {
|
try {
|
||||||
const deleteWidget = {
|
const deleteWidget = {
|
||||||
organization,
|
organization,
|
||||||
widgetId: rightClickSelected,
|
id: rightClickSelected,
|
||||||
zoneId: selectedZone.zoneId,
|
zoneId: selectedZone.zoneId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('deleteWidget: ', deleteWidget);
|
||||||
|
if (visualizationSocket) {
|
||||||
|
visualizationSocket.emit("v2:viz-3D-widget:delete", deleteWidget);
|
||||||
|
}
|
||||||
// Call the API to delete the widget
|
// Call the API to delete the widget
|
||||||
const response = await delete3dWidgetApi(selectedZone.zoneId, organization, rightClickSelected);
|
// const response = await delete3dWidgetApi(selectedZone.zoneId, organization, rightClickSelected);
|
||||||
|
|
||||||
|
|
||||||
// if (response?.success) {
|
|
||||||
// Remove from state only if API call succeeds
|
|
||||||
setZoneWidgetData(
|
setZoneWidgetData(
|
||||||
selectedZone.zoneId,
|
selectedZone.zoneId,
|
||||||
activeZoneWidgets.filter((w: WidgetData) => w.id !== rightClickSelected)
|
activeZoneWidgets.filter((w: WidgetData) => w.id !== rightClickSelected)
|
||||||
);
|
);
|
||||||
// } else {
|
|
||||||
// console.error("Failed to delete widget:", response?.message);
|
|
||||||
// }
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error deleting widget:", error);
|
console.error("Error deleting widget:", error);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -298,44 +297,60 @@ export default function Dropped3dWidgets() {
|
||||||
|
|
||||||
const handleMouseUp = () => {
|
const handleMouseUp = () => {
|
||||||
if (!rightClickSelected || !rightSelect) return;
|
if (!rightClickSelected || !rightSelect) return;
|
||||||
|
|
||||||
const selectedZone = Object.keys(zoneWidgetData).find(zoneId =>
|
const selectedZone = Object.keys(zoneWidgetData).find(zoneId =>
|
||||||
zoneWidgetData[zoneId].some(widget => widget.id === rightClickSelected)
|
zoneWidgetData[zoneId].some(widget => widget.id === rightClickSelected)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!selectedZone) return;
|
if (!selectedZone) return;
|
||||||
|
|
||||||
const selectedWidget = zoneWidgetData[selectedZone].find(widget => widget.id === rightClickSelected);
|
const selectedWidget = zoneWidgetData[selectedZone].find(widget => widget.id === rightClickSelected);
|
||||||
if (!selectedWidget) return;
|
if (!selectedWidget) return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Format values to 2 decimal places
|
// Format values to 2 decimal places
|
||||||
const formatValues = (vals: number[]) => vals.map(val => parseFloat(val.toFixed(2)));
|
const formatValues = (vals: number[]) => vals.map(val => parseFloat(val.toFixed(2)));
|
||||||
|
|
||||||
if (rightSelect === "Horizontal Move" || rightSelect === "Vertical Move") {
|
if (rightSelect === "Horizontal Move" || rightSelect === "Vertical Move") {
|
||||||
console.log(`${rightSelect} Completed - Full Position:`, formatValues(selectedWidget.position));
|
console.log(`${rightSelect} Completed - Full Position:`, formatValues(selectedWidget.position));
|
||||||
let lastPosition = formatValues(selectedWidget.position) as [number, number, number];
|
let lastPosition = formatValues(selectedWidget.position) as [number, number, number];
|
||||||
|
// (async () => {
|
||||||
|
// let response = await update3dWidget(selectedZone, organization, rightClickSelected, lastPosition);
|
||||||
|
// console.log('response: ', response);
|
||||||
|
// if (response) {
|
||||||
|
// console.log("Widget position updated in API:", response);
|
||||||
|
// }
|
||||||
|
// })();
|
||||||
|
let updatingPosition = {
|
||||||
|
organization: organization,
|
||||||
|
zoneId: selectedZone,
|
||||||
|
id: rightClickSelected,
|
||||||
|
position: lastPosition,
|
||||||
|
}
|
||||||
|
if (visualizationSocket) {
|
||||||
|
visualizationSocket.emit("v2:viz-3D-widget:modifyPositionRotation", updatingPosition);
|
||||||
|
}
|
||||||
|
|
||||||
(async () => {
|
|
||||||
let response = await update3dWidget(selectedZone, organization, rightClickSelected, lastPosition);
|
|
||||||
console.log('response: ', response);
|
|
||||||
if (response) {
|
|
||||||
console.log("Widget position updated in API:", response);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
}
|
||||||
else if (rightSelect.includes("Rotate")) {
|
else if (rightSelect.includes("Rotate")) {
|
||||||
const rotation = selectedWidget.rotation || [0, 0, 0];
|
const rotation = selectedWidget.rotation || [0, 0, 0];
|
||||||
console.log(`${rightSelect} Completed - Full Rotation:`, formatValues(rotation));
|
console.log(`${rightSelect} Completed - Full Rotation:`, formatValues(rotation));
|
||||||
let lastPosition = formatValues(rotation) as [number, number, number];
|
let lastRotation = formatValues(rotation) as [number, number, number];
|
||||||
console.log('lastPosition: ', lastPosition);
|
// (async () => {
|
||||||
|
// let response = await update3dWidgetRotation(selectedZone, organization, rightClickSelected, lastRotation);
|
||||||
(async () => {
|
// console.log('response: ', response);
|
||||||
let response = await update3dWidgetRotation(selectedZone, organization, rightClickSelected, lastPosition);
|
// if (response) {
|
||||||
console.log('response: ', response);
|
// console.log("Widget position updated in API:", response);
|
||||||
if (response) {
|
// }
|
||||||
console.log("Widget position updated in API:", response);
|
// })();
|
||||||
}
|
let updatingRotation = {
|
||||||
})();
|
organization: organization,
|
||||||
|
zoneId: selectedZone,
|
||||||
|
id: rightClickSelected,
|
||||||
|
rotation: lastRotation,
|
||||||
|
}
|
||||||
|
if (visualizationSocket) {
|
||||||
|
visualizationSocket.emit("v2:viz-3D-widget:modifyPositionRotation", updatingRotation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset selection
|
// Reset selection
|
||||||
|
|
|
@ -5,6 +5,14 @@ import { useDroppedObjectsStore } from "../../store/useDroppedObjectsStore";
|
||||||
import { useZoneWidgetStore } from "../../store/useZone3DWidgetStore";
|
import { useZoneWidgetStore } from "../../store/useZone3DWidgetStore";
|
||||||
import useTemplateStore from "../../store/useTemplateStore";
|
import useTemplateStore from "../../store/useTemplateStore";
|
||||||
|
|
||||||
|
type WidgetData = {
|
||||||
|
id: string;
|
||||||
|
type: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation?: [number, number, number];
|
||||||
|
tempPosition?: [number, number, number];
|
||||||
|
};
|
||||||
|
|
||||||
export default function SocketRealTimeViz() {
|
export default function SocketRealTimeViz() {
|
||||||
const { visualizationSocket } = useSocketStore();
|
const { visualizationSocket } = useSocketStore();
|
||||||
const { selectedZone, setSelectedZone } = useSelectedZoneStore();
|
const { selectedZone, setSelectedZone } = useSelectedZoneStore();
|
||||||
|
@ -14,6 +22,7 @@ export default function SocketRealTimeViz() {
|
||||||
const { addWidget } = useZoneWidgetStore()
|
const { addWidget } = useZoneWidgetStore()
|
||||||
const { templates, removeTemplate } = useTemplateStore();
|
const { templates, removeTemplate } = useTemplateStore();
|
||||||
const { setTemplates } = useTemplateStore();
|
const { setTemplates } = useTemplateStore();
|
||||||
|
const { zoneWidgetData, setZoneWidgetData, updateWidgetPosition, updateWidgetRotation } = useZoneWidgetStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const email = localStorage.getItem("email") || "";
|
const email = localStorage.getItem("email") || "";
|
||||||
|
@ -132,14 +141,36 @@ export default function SocketRealTimeViz() {
|
||||||
});
|
});
|
||||||
//add 3D Widget response
|
//add 3D Widget response
|
||||||
visualizationSocket.on("viz-widget3D:response:updates", (add3DWidget: any) => {
|
visualizationSocket.on("viz-widget3D:response:updates", (add3DWidget: any) => {
|
||||||
console.log('add3DWidget: ', add3DWidget);
|
|
||||||
|
|
||||||
|
console.log('add3DWidget: ', add3DWidget);
|
||||||
if (add3DWidget.success) {
|
if (add3DWidget.success) {
|
||||||
|
console.log('add3DWidget: ', add3DWidget);
|
||||||
if (add3DWidget.message === "Widget created successfully") {
|
if (add3DWidget.message === "Widget created successfully") {
|
||||||
addWidget(add3DWidget.data.zoneId, add3DWidget.data.widget);
|
addWidget(add3DWidget.data.zoneId, add3DWidget.data.widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
//delete 3D Widget response
|
||||||
|
visualizationSocket.on("viz-widget3D:response:delete", (delete3DWidget: any) => {
|
||||||
|
console.log('delete3DWidget: ', delete3DWidget);
|
||||||
|
// "3DWidget delete unsuccessfull"
|
||||||
|
if (delete3DWidget.success && delete3DWidget.message === "3DWidget delete successfull") {
|
||||||
|
const activeZoneWidgets = zoneWidgetData[delete3DWidget.data.zoneId] || [];
|
||||||
|
setZoneWidgetData(
|
||||||
|
delete3DWidget.data.zoneId,
|
||||||
|
activeZoneWidgets.filter((w: WidgetData) => w.id !== delete3DWidget.data.id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//update3D widget response
|
||||||
|
visualizationSocket.on("viz-widget3D:response:modifyPositionRotation", (update3DWidget: any) => {
|
||||||
|
console.log('update3DWidget: ', update3DWidget);
|
||||||
|
|
||||||
|
if (update3DWidget.success && update3DWidget.message==="widget update successfully") {
|
||||||
|
updateWidgetPosition(update3DWidget.data.zoneId, update3DWidget.data.widget.id, update3DWidget.data.widget.position);
|
||||||
|
updateWidgetRotation(update3DWidget.data.zoneId, update3DWidget.data.widget.id, update3DWidget.data.widget.rotation);
|
||||||
|
}
|
||||||
|
});
|
||||||
// add Template response
|
// add Template response
|
||||||
visualizationSocket.on("viz-template:response:add", (addingTemplate: any) => {
|
visualizationSocket.on("viz-template:response:add", (addingTemplate: any) => {
|
||||||
console.log('addingTemplate: ', addingTemplate);
|
console.log('addingTemplate: ', addingTemplate);
|
||||||
|
|
Loading…
Reference in New Issue