2025-03-25 06:17:41 +00:00
|
|
|
import React, { useEffect, useState, useRef } from "react";
|
|
|
|
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
|
|
|
import Panel from "./Panel";
|
|
|
|
import AddButtons from "./AddButtons";
|
|
|
|
import { useSelectedZoneStore } from "../../../store/useZoneStore";
|
|
|
|
import DisplayZone from "./DisplayZone";
|
2025-03-25 11:00:33 +00:00
|
|
|
import Scene from "../../../modules/scene/scene";
|
2025-03-26 07:02:04 +00:00
|
|
|
import useModuleStore from "../../../store/useModuleStore";
|
2025-03-26 13:00:33 +00:00
|
|
|
import { useZones } from "../../../store/store";
|
|
|
|
|
2025-03-26 06:58:22 +00:00
|
|
|
|
2025-03-25 06:17:41 +00:00
|
|
|
|
|
|
|
type Side = "top" | "bottom" | "left" | "right";
|
|
|
|
|
2025-03-26 06:58:22 +00:00
|
|
|
type FormattedZoneData = Record<
|
|
|
|
string,
|
|
|
|
{
|
|
|
|
activeSides: Side[];
|
|
|
|
panelOrder: Side[];
|
|
|
|
lockedPanels: Side[];
|
2025-03-26 13:00:33 +00:00
|
|
|
zoneId: string;
|
|
|
|
zoneViewPortTarget: number[];
|
|
|
|
zoneViewPortPosition: number[]
|
2025-03-26 06:58:22 +00:00
|
|
|
widgets: Widget[];
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
type Widget = {
|
2025-03-25 06:17:41 +00:00
|
|
|
id: string;
|
|
|
|
type: string;
|
|
|
|
title: string;
|
|
|
|
panel: Side;
|
|
|
|
data: any;
|
2025-03-26 06:58:22 +00:00
|
|
|
};
|
2025-03-25 06:17:41 +00:00
|
|
|
|
|
|
|
const RealTimeVisulization: React.FC = () => {
|
|
|
|
const [hiddenPanels, setHiddenPanels] = React.useState<Side[]>([]);
|
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
const { isPlaying } = usePlayButtonStore();
|
2025-03-26 07:02:04 +00:00
|
|
|
const { activeModule } = useModuleStore();
|
|
|
|
|
2025-03-26 06:58:22 +00:00
|
|
|
const [zonesData, setZonesData] = useState<FormattedZoneData>({});
|
2025-03-25 06:17:41 +00:00
|
|
|
const { selectedZone, setSelectedZone } = useSelectedZoneStore();
|
2025-03-26 13:00:33 +00:00
|
|
|
const { zones } = useZones()
|
2025-03-26 06:58:22 +00:00
|
|
|
|
2025-03-25 06:17:41 +00:00
|
|
|
useEffect(() => {
|
2025-03-26 13:00:33 +00:00
|
|
|
const data = Array.isArray(zones) ? zones : [];
|
|
|
|
console.log('data: ', data);
|
|
|
|
const formattedData = data.reduce<FormattedZoneData>((acc, zone) => {
|
|
|
|
acc[zone.zoneName] = {
|
|
|
|
activeSides: [],
|
|
|
|
panelOrder: [],
|
|
|
|
lockedPanels: [],
|
|
|
|
zoneId: zone.zoneId,
|
|
|
|
zoneViewPortTarget: zone.viewPortCenter,
|
|
|
|
zoneViewPortPosition: zone.viewPortposition,
|
|
|
|
widgets: [],
|
|
|
|
};
|
|
|
|
return acc;
|
|
|
|
}, {});
|
2025-03-26 06:58:22 +00:00
|
|
|
|
2025-03-26 13:00:33 +00:00
|
|
|
setZonesData(formattedData);
|
|
|
|
}, [zones]);
|
2025-03-26 06:58:22 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setZonesData((prev) => {
|
|
|
|
if (!selectedZone) return prev;
|
|
|
|
return {
|
|
|
|
...prev,
|
|
|
|
[selectedZone.zoneName]: {
|
|
|
|
...prev[selectedZone.zoneName], // Keep existing properties
|
|
|
|
activeSides: selectedZone.activeSides || [],
|
|
|
|
panelOrder: selectedZone.panelOrder || [],
|
|
|
|
lockedPanels: selectedZone.lockedPanels || [],
|
2025-03-26 13:00:33 +00:00
|
|
|
zoneId: selectedZone.zoneId || "",
|
|
|
|
zoneViewPortTarget: selectedZone.zoneViewPortTarget || [],
|
|
|
|
zoneViewPortPosition: selectedZone.zoneViewPortPosition || [],
|
2025-03-26 06:58:22 +00:00
|
|
|
widgets: selectedZone.widgets || [],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
2025-03-25 06:17:41 +00:00
|
|
|
}, [selectedZone]);
|
|
|
|
|
2025-03-26 13:00:33 +00:00
|
|
|
const handleDrop = (event: React.DragEvent<HTMLDivElement>) => {
|
|
|
|
event.preventDefault();
|
|
|
|
const canvas = document.querySelector(".scene-container");
|
|
|
|
if (canvas) {
|
|
|
|
// Extract relevant properties manually
|
|
|
|
const dragEvent = new DragEvent("drop", {
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true,
|
|
|
|
dataTransfer: event.dataTransfer, // Attach dataTransfer manually ✅
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log('dragEvent: ', dragEvent);
|
|
|
|
canvas.dispatchEvent(dragEvent);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2025-03-25 06:17:41 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
ref={containerRef}
|
|
|
|
id="real-time-vis-canvas"
|
2025-03-26 08:22:10 +00:00
|
|
|
className={`realTime-viz canvas ${isPlaying ? "playingFlase" : ""}`}
|
2025-03-25 06:17:41 +00:00
|
|
|
style={{
|
2025-03-26 07:02:04 +00:00
|
|
|
height: isPlaying || activeModule !== "visualization" ? "100vh" : "",
|
|
|
|
width: isPlaying || activeModule !== "visualization" ? "100vw" : "",
|
|
|
|
left: isPlaying || activeModule !== "visualization" ? "0%" : "",
|
2025-03-25 06:17:41 +00:00
|
|
|
}}
|
|
|
|
>
|
2025-03-25 11:00:33 +00:00
|
|
|
<div
|
|
|
|
className="scene-container"
|
2025-03-26 07:02:04 +00:00
|
|
|
style={{
|
|
|
|
height: "100%",
|
|
|
|
width: "100%",
|
|
|
|
borderRadius: isPlaying || activeModule !== "visualization" ? "" : "6px",
|
|
|
|
}}
|
2025-03-26 13:00:33 +00:00
|
|
|
onDrop={handleDrop}
|
2025-03-25 11:00:33 +00:00
|
|
|
>
|
2025-03-26 13:00:33 +00:00
|
|
|
{/* {objects.map((obj) => (
|
|
|
|
<mesh key={obj.id} position={obj.position}>
|
|
|
|
<boxGeometry args={[1, 1, 1]} />
|
|
|
|
<meshStandardMaterial color="green" />
|
|
|
|
</mesh>
|
|
|
|
))} */}
|
2025-03-25 11:00:33 +00:00
|
|
|
<Scene />
|
|
|
|
</div>
|
2025-03-26 07:02:04 +00:00
|
|
|
{activeModule === "visualization" && (
|
|
|
|
<>
|
|
|
|
<DisplayZone
|
|
|
|
zonesData={zonesData}
|
|
|
|
selectedZone={selectedZone}
|
|
|
|
setSelectedZone={setSelectedZone}
|
|
|
|
/>
|
|
|
|
|
2025-03-26 13:00:33 +00:00
|
|
|
{!isPlaying && selectedZone?.zoneName !== "" && (
|
2025-03-26 07:02:04 +00:00
|
|
|
<AddButtons
|
|
|
|
hiddenPanels={hiddenPanels}
|
|
|
|
setHiddenPanels={setHiddenPanels}
|
|
|
|
selectedZone={selectedZone}
|
|
|
|
setSelectedZone={setSelectedZone}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<Panel
|
2025-03-26 13:00:33 +00:00
|
|
|
hiddenPanels={hiddenPanels}
|
2025-03-26 07:02:04 +00:00
|
|
|
selectedZone={selectedZone}
|
|
|
|
setSelectedZone={setSelectedZone}
|
2025-03-26 07:02:09 +00:00
|
|
|
hiddenPanels={hiddenPanels}
|
2025-03-26 07:02:04 +00:00
|
|
|
/>
|
|
|
|
</>
|
2025-03-25 11:00:33 +00:00
|
|
|
)}
|
2025-03-25 06:17:41 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RealTimeVisulization;
|