- Updated various API service files to replace error throwing with console.error for better logging. - This change affects services related to aisles, assets, cameras, collaboration, comments, environment, lines, marketplace, simulation, visualization, and zones. - The modifications aim to improve error handling by logging errors to the console instead of interrupting the flow with thrown errors.
191 lines
8.7 KiB
TypeScript
191 lines
8.7 KiB
TypeScript
import { useEffect } from "react";
|
|
import * as Types from '../../../types/world/worldTypes';
|
|
import { useActiveLayer, useDeletedLines, useToolMode, useNewLines, useRemovedLayer, useSocketStore, useToggleView, useUpdateScene } from "../../../store/builder/store";
|
|
import Layer2DVisibility from "../geomentries/layers/layer2DVisibility";
|
|
import { useFrame, useThree } from "@react-three/fiber";
|
|
import DeletableLineorPoint from "../functions/deletableLineOrPoint";
|
|
import removeSoloPoint from "../geomentries/points/removeSoloPoint";
|
|
import removeReferenceLine from "../geomentries/lines/removeReferenceLine";
|
|
import DeleteLayer from "../geomentries/layers/deleteLayer";
|
|
import { getLines } from "../../../services/factoryBuilder/lines/getLinesApi";
|
|
import objectLinesToArray from "../geomentries/lines/lineConvertions/objectLinesToArray";
|
|
import loadInitialPoint from "../IntialLoad/loadInitialPoint";
|
|
import loadInitialLine from "../IntialLoad/loadInitialLine";
|
|
import deletePoint from "../geomentries/points/deletePoint";
|
|
import deleteLine from "../geomentries/lines/deleteLine";
|
|
import drawWall from "../geomentries/lines/drawWall";
|
|
import drawOnlyFloor from "../geomentries/floors/drawOnlyFloor";
|
|
import addDragControl from "../eventDeclaration/dragControlDeclaration";
|
|
import { useParams } from "react-router-dom";
|
|
import { getUserData } from "../../../functions/getUserData";
|
|
import { useVersionContext } from "../version/versionContext";
|
|
|
|
const FloorPlanGroup = ({ floorPlanGroup, floorPlanGroupLine, floorPlanGroupPoint, floorGroup, currentLayerPoint, dragPointControls, hoveredDeletablePoint, hoveredDeletableLine, plane, line, lines, onlyFloorline, onlyFloorlines, ReferenceLineMesh, LineCreated, isSnapped, ispreSnapped, snappedPoint, isSnappedUUID, isAngleSnapped, anglesnappedPoint }: any) => {
|
|
const state = useThree();
|
|
const { camera, gl, raycaster, controls } = state;
|
|
const { activeLayer } = useActiveLayer();
|
|
const { toggleView } = useToggleView();
|
|
const { toolMode } = useToolMode();
|
|
const { removedLayer, setRemovedLayer } = useRemovedLayer();
|
|
const { setUpdateScene } = useUpdateScene();
|
|
const { setNewLines } = useNewLines();
|
|
const { setDeletedLines } = useDeletedLines();
|
|
const { socket } = useSocketStore();
|
|
const { selectedVersionStore } = useVersionContext();
|
|
const { selectedVersion } = selectedVersionStore();
|
|
const { projectId } = useParams();
|
|
const { organization } = getUserData();
|
|
|
|
useEffect(() => {
|
|
if (toolMode === 'move') {
|
|
addDragControl(dragPointControls, currentLayerPoint, state, floorPlanGroupPoint, floorPlanGroupLine, lines, onlyFloorlines, socket, projectId, selectedVersion?.versionId || '',);
|
|
}
|
|
|
|
return () => {
|
|
if (dragPointControls.current) {
|
|
dragPointControls.current.enabled = false;
|
|
}
|
|
};
|
|
}, [toolMode, state]);
|
|
|
|
useEffect(() => {
|
|
if (!selectedVersion) return;
|
|
|
|
getLines(organization, projectId, selectedVersion?.versionId || '').then((data) => {
|
|
|
|
const Lines: Types.Lines = objectLinesToArray(data);
|
|
|
|
if (Lines) {
|
|
lines.current = Lines;
|
|
loadInitialPoint(lines, floorPlanGroupPoint, currentLayerPoint, dragPointControls);
|
|
loadInitialLine(floorPlanGroupLine, lines);
|
|
setUpdateScene(true);
|
|
}
|
|
})
|
|
}, [selectedVersion?.versionId]);
|
|
|
|
useEffect(() => {
|
|
if (!toggleView) {
|
|
removeSoloPoint(line, floorPlanGroupLine, floorPlanGroupPoint);
|
|
removeReferenceLine(floorPlanGroup, ReferenceLineMesh, LineCreated, line);
|
|
}
|
|
}, [toggleView]);
|
|
|
|
useEffect(() => {
|
|
removeSoloPoint(line, floorPlanGroupLine, floorPlanGroupPoint);
|
|
removeReferenceLine(floorPlanGroup, ReferenceLineMesh, LineCreated, line);
|
|
}, [toolMode]);
|
|
|
|
useEffect(() => {
|
|
if (toolMode === 'move' && toggleView) {
|
|
if (dragPointControls.current) {
|
|
dragPointControls.current.enabled = true;
|
|
}
|
|
} else {
|
|
if (dragPointControls.current) {
|
|
dragPointControls.current.enabled = false;
|
|
}
|
|
}
|
|
}, [toolMode, toggleView, state]);
|
|
|
|
useEffect(() => {
|
|
Layer2DVisibility(activeLayer, floorPlanGroup, floorPlanGroupLine, floorPlanGroupPoint, currentLayerPoint, dragPointControls);
|
|
}, [activeLayer]);
|
|
|
|
useEffect(() => {
|
|
if (removedLayer !== null) {
|
|
DeleteLayer(removedLayer, lines, floorPlanGroupLine, floorPlanGroupPoint, onlyFloorlines, floorGroup, setDeletedLines, setRemovedLayer, socket, projectId, selectedVersion?.versionId || '',);
|
|
}
|
|
}, [removedLayer]);
|
|
|
|
useEffect(() => {
|
|
|
|
const canvasElement = gl.domElement;
|
|
|
|
let drag = false;
|
|
let isLeftMouseDown = false;
|
|
|
|
const onMouseDown = (evt: any) => {
|
|
if (evt.button === 0) {
|
|
isLeftMouseDown = true;
|
|
drag = false;
|
|
}
|
|
};
|
|
|
|
const onMouseUp = (evt: any) => {
|
|
if (evt.button === 0) {
|
|
isLeftMouseDown = false;
|
|
}
|
|
if (controls) {
|
|
(controls as any).enabled = true;
|
|
}
|
|
}
|
|
|
|
const onMouseMove = () => {
|
|
if (isLeftMouseDown) {
|
|
drag = true;
|
|
}
|
|
};
|
|
|
|
const onContextMenu = (e: any) => {
|
|
e.preventDefault();
|
|
if (toolMode === "Wall" || toolMode === "Floor") {
|
|
removeSoloPoint(line, floorPlanGroupLine, floorPlanGroupPoint);
|
|
removeReferenceLine(floorPlanGroup, ReferenceLineMesh, LineCreated, line);
|
|
}
|
|
};
|
|
|
|
const onMouseClick = (evt: any) => {
|
|
if (!plane.current || drag) return;
|
|
|
|
if (toolMode === "2D-Delete") {
|
|
if (hoveredDeletablePoint.current !== null) {
|
|
deletePoint(hoveredDeletablePoint, onlyFloorlines, floorPlanGroupPoint, floorPlanGroupLine, lines, setDeletedLines, socket, projectId, selectedVersion?.versionId || '',);
|
|
}
|
|
if (hoveredDeletableLine.current !== null) {
|
|
deleteLine(hoveredDeletableLine, onlyFloorlines, lines, floorPlanGroupLine, floorPlanGroupPoint, setDeletedLines, socket, projectId, selectedVersion?.versionId || '',);
|
|
}
|
|
}
|
|
|
|
if (toolMode === "Wall") {
|
|
drawWall(raycaster, plane, floorPlanGroupPoint, snappedPoint, isSnapped, isSnappedUUID, line, ispreSnapped, anglesnappedPoint, isAngleSnapped, lines, floorPlanGroupLine, floorPlanGroup, ReferenceLineMesh, LineCreated, currentLayerPoint, dragPointControls, setNewLines, setDeletedLines, activeLayer, socket, projectId, selectedVersion?.versionId || '',);
|
|
}
|
|
|
|
if (toolMode === "Floor") {
|
|
drawOnlyFloor(raycaster, state, camera, plane, floorPlanGroupPoint, snappedPoint, isSnapped, isSnappedUUID, line, ispreSnapped, anglesnappedPoint, isAngleSnapped, onlyFloorline, onlyFloorlines, lines, floorPlanGroupLine, floorPlanGroup, ReferenceLineMesh, LineCreated, currentLayerPoint, dragPointControls, setNewLines, setDeletedLines, activeLayer, socket, projectId, selectedVersion?.versionId || '',);
|
|
}
|
|
}
|
|
|
|
if (toolMode === "2D-Delete" || toolMode === "Wall" || toolMode === "Floor") {
|
|
canvasElement.addEventListener("mousedown", onMouseDown);
|
|
canvasElement.addEventListener("mouseup", onMouseUp);
|
|
canvasElement.addEventListener("mousemove", onMouseMove);
|
|
canvasElement.addEventListener("click", onMouseClick);
|
|
canvasElement.addEventListener("contextmenu", onContextMenu);
|
|
}
|
|
|
|
return () => {
|
|
canvasElement.removeEventListener("mousedown", onMouseDown);
|
|
canvasElement.removeEventListener("mouseup", onMouseUp);
|
|
canvasElement.removeEventListener("mousemove", onMouseMove);
|
|
canvasElement.removeEventListener("click", onMouseClick);
|
|
canvasElement.removeEventListener("contextmenu", onContextMenu);
|
|
};
|
|
}, [toolMode, activeLayer])
|
|
|
|
|
|
useFrame(() => {
|
|
if (toolMode === '2D-Delete') {
|
|
DeletableLineorPoint(state, plane, floorPlanGroupLine, floorPlanGroupPoint, hoveredDeletableLine, hoveredDeletablePoint);
|
|
}
|
|
})
|
|
|
|
return (
|
|
<group ref={floorPlanGroup} visible={toggleView} name="floorPlanGroup">
|
|
<group ref={floorPlanGroupLine} name="floorPlanGroupLine"></group>
|
|
<group ref={floorPlanGroupPoint} name="floorPlanGroupPoint"></group>
|
|
</group>
|
|
)
|
|
}
|
|
|
|
export default FloorPlanGroup; |