Refactor floor management APIs: implement getFloorsApi, deleteFloorApi, and upsertFloorApi for enhanced floor data handling. Update FloorCreator for improved point snapping and floor creation logic. Modify ReferencePoint to include UUID and user data. Adjust usePointSnapping to handle temporary points more effectively.
This commit is contained in:
@@ -80,30 +80,34 @@ function FloorCreator() {
|
|||||||
newPoint.position = snappedPosition;
|
newPoint.position = snappedPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pointIntersects && !snappedPoint) {
|
if (pointIntersects) {
|
||||||
if (tempPoints.length > 2 && isCreating && pointIntersects.object.userData.pointUuid === tempPoints[0].pointUuid) {
|
if (tempPoints.length > 2 && isCreating && pointIntersects.object.uuid === tempPoints[0].pointUuid) {
|
||||||
if (tempPoints.length >= 3) {
|
const floor: Floor = {
|
||||||
const floor: Floor = {
|
floorUuid: THREE.MathUtils.generateUUID(),
|
||||||
floorUuid: THREE.MathUtils.generateUUID(),
|
points: tempPoints,
|
||||||
points: tempPoints,
|
topMaterial,
|
||||||
topMaterial,
|
sideMaterial,
|
||||||
sideMaterial,
|
floorDepth,
|
||||||
floorDepth,
|
isBeveled,
|
||||||
isBeveled,
|
bevelStrength,
|
||||||
bevelStrength,
|
decals: [],
|
||||||
decals: [],
|
};
|
||||||
};
|
|
||||||
|
|
||||||
addFloor(floor);
|
addFloor(floor);
|
||||||
}
|
setTempPoints([]);
|
||||||
|
setIsCreating(false);
|
||||||
|
} else if (tempPoints.length === 0) {
|
||||||
|
tempPoints.push(pointIntersects.object.userData as Point);
|
||||||
|
setIsCreating(true);
|
||||||
|
} else {
|
||||||
setTempPoints([]);
|
setTempPoints([]);
|
||||||
setIsCreating(false);
|
setIsCreating(false);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
setTempPoints(prev => [...prev, newPoint]);
|
||||||
|
setIsCreating(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTempPoints(prev => [...prev, newPoint]);
|
|
||||||
setIsCreating(true);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onContext = (event: any) => {
|
const onContext = (event: any) => {
|
||||||
@@ -157,7 +161,7 @@ function FloorCreator() {
|
|||||||
<>
|
<>
|
||||||
{toggleView &&
|
{toggleView &&
|
||||||
<>
|
<>
|
||||||
<group name='Wall-Reference-Points-Group'>
|
<group name='Floor-Reference-Points-Group'>
|
||||||
{tempPoints.map((point) => (
|
{tempPoints.map((point) => (
|
||||||
<ReferencePoint key={point.pointUuid} point={point} />
|
<ReferencePoint key={point.pointUuid} point={point} />
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -201,10 +201,13 @@ export const usePointSnapping = (currentPoint: { uuid: string, pointType: string
|
|||||||
);
|
);
|
||||||
}, [floors, currentPoint]);
|
}, [floors, currentPoint]);
|
||||||
|
|
||||||
const snapFloorPoint = useCallback((position: [number, number, number], tempPoints: Point[] | []) => {
|
const snapFloorPoint = useCallback((position: [number, number, number], tempPoints?: Point[] | []) => {
|
||||||
if (!currentPoint || !CAN_POINT_SNAP) return { position: position, isSnapped: false, snappedPoint: null };
|
if (!currentPoint || !CAN_POINT_SNAP) return { position: position, isSnapped: false, snappedPoint: null };
|
||||||
|
|
||||||
const otherPoints = [...getAllOtherFloorPoints(), ...tempPoints];
|
const otherPoints = getAllOtherFloorPoints();
|
||||||
|
if (tempPoints) {
|
||||||
|
otherPoints.concat(tempPoints);
|
||||||
|
}
|
||||||
const currentVec = new THREE.Vector3(...position);
|
const currentVec = new THREE.Vector3(...position);
|
||||||
|
|
||||||
for (const point of otherPoints) {
|
for (const point of otherPoints) {
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import { useSceneContext } from '../../scene/sceneContext';
|
|||||||
|
|
||||||
import { upsertAisleApi } from '../../../services/factoryBuilder/aisle/upsertAisleApi';
|
import { upsertAisleApi } from '../../../services/factoryBuilder/aisle/upsertAisleApi';
|
||||||
import { deleteAisleApi } from '../../../services/factoryBuilder/aisle/deleteAisleApi';
|
import { deleteAisleApi } from '../../../services/factoryBuilder/aisle/deleteAisleApi';
|
||||||
import { upsertWallApi } from '../../../services/factoryBuilder/wall/upsertWallApi';
|
// import { upsertWallApi } from '../../../services/factoryBuilder/wall/upsertWallApi';
|
||||||
import { deleteWallApi } from '../../../services/factoryBuilder/wall/deleteWallApi';
|
// import { deleteWallApi } from '../../../services/factoryBuilder/wall/deleteWallApi';
|
||||||
import { getUserData } from '../../../functions/getUserData';
|
import { getUserData } from '../../../functions/getUserData';
|
||||||
|
|
||||||
function Point({ point }: { readonly point: Point }) {
|
function Point({ point }: { readonly point: Point }) {
|
||||||
@@ -28,7 +28,7 @@ function Point({ point }: { readonly point: Point }) {
|
|||||||
const { setPosition: setAislePosition, removePoint: removeAislePoint, getAislesByPointId } = aisleStore();
|
const { setPosition: setAislePosition, removePoint: removeAislePoint, getAislesByPointId } = aisleStore();
|
||||||
const { setPosition: setWallPosition, removePoint: removeWallPoint, getWallsByPointId } = wallStore();
|
const { setPosition: setWallPosition, removePoint: removeWallPoint, getWallsByPointId } = wallStore();
|
||||||
const { setPosition: setFloorPosition, removePoint: removeFloorPoint } = floorStore();
|
const { setPosition: setFloorPosition, removePoint: removeFloorPoint } = floorStore();
|
||||||
const { snapAislePoint, snapAisleAngle, snapWallPoint, snapWallAngle } = usePointSnapping({ uuid: point.pointUuid, pointType: point.pointType, position: point.position });
|
const { snapAislePoint, snapAisleAngle, snapWallPoint, snapWallAngle, snapFloorPoint, snapFloorAngle } = usePointSnapping({ uuid: point.pointUuid, pointType: point.pointType, position: point.position });
|
||||||
const { hoveredPoint, setHoveredPoint } = useBuilderStore();
|
const { hoveredPoint, setHoveredPoint } = useBuilderStore();
|
||||||
const { userId, organization } = getUserData();
|
const { userId, organization } = getUserData();
|
||||||
const { selectedVersionStore } = useVersionContext();
|
const { selectedVersionStore } = useVersionContext();
|
||||||
@@ -121,8 +121,8 @@ function Point({ point }: { readonly point: Point }) {
|
|||||||
const finalSnapped = snapWallPoint(wallSnapped.position);
|
const finalSnapped = snapWallPoint(wallSnapped.position);
|
||||||
setWallPosition(point.pointUuid, finalSnapped.position);
|
setWallPosition(point.pointUuid, finalSnapped.position);
|
||||||
} else if (point.pointType === 'Floor') {
|
} else if (point.pointType === 'Floor') {
|
||||||
const floorSnapped = snapWallAngle(newPosition);
|
const floorSnapped = snapFloorAngle(newPosition);
|
||||||
const finalSnapped = snapWallPoint(floorSnapped.position);
|
const finalSnapped = snapFloorPoint(floorSnapped.position);
|
||||||
setFloorPosition(point.pointUuid, finalSnapped.position);
|
setFloorPosition(point.pointUuid, finalSnapped.position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ function ReferencePoint({ point }: { readonly point: Point }) {
|
|||||||
<mesh
|
<mesh
|
||||||
position={new THREE.Vector3(...point.position)}
|
position={new THREE.Vector3(...point.position)}
|
||||||
name={pointName}
|
name={pointName}
|
||||||
|
uuid={point.pointUuid}
|
||||||
|
userData={point}
|
||||||
>
|
>
|
||||||
<boxGeometry args={boxScale} />
|
<boxGeometry args={boxScale} />
|
||||||
<shaderMaterial
|
<shaderMaterial
|
||||||
|
|||||||
39
app/src/services/factoryBuilder/floor/deleteFloorApi.ts
Normal file
39
app/src/services/factoryBuilder/floor/deleteFloorApi.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
|
||||||
|
|
||||||
|
export const deleteFloorApi = async (
|
||||||
|
projectId: string,
|
||||||
|
versionId: string,
|
||||||
|
floorUuid: string
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${url_Backend_dwinzo}/api/V1/deleteFloor`, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer <access_token>",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
token: localStorage.getItem("token") || "",
|
||||||
|
refresh_token: localStorage.getItem("refreshToken") || "",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ projectId, versionId, floorUuid }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const newAccessToken = response.headers.get("x-access-token");
|
||||||
|
if (newAccessToken) {
|
||||||
|
localStorage.setItem("token", newAccessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
console.error("Failed to delete floor:", response.statusText);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
echo.error("Failed to delete floor");
|
||||||
|
if (error instanceof Error) {
|
||||||
|
console.log(error.message);
|
||||||
|
} else {
|
||||||
|
console.log("An unknown error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
37
app/src/services/factoryBuilder/floor/getFloorsApi.ts
Normal file
37
app/src/services/factoryBuilder/floor/getFloorsApi.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
|
||||||
|
|
||||||
|
export const getFloorsApi = async (
|
||||||
|
projectId: string,
|
||||||
|
versionId: string,
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${url_Backend_dwinzo}/api/V1/floors/${projectId}/${versionId}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer <access_token>",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
token: localStorage.getItem("token") || "",
|
||||||
|
refresh_token: localStorage.getItem("refreshToken") || "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const newAccessToken = response.headers.get("x-access-token");
|
||||||
|
if (newAccessToken) {
|
||||||
|
localStorage.setItem("token", newAccessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
console.error("Failed to get floors:", response.statusText);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
echo.error("Failed to get floors");
|
||||||
|
if (error instanceof Error) {
|
||||||
|
console.log(error.message);
|
||||||
|
} else {
|
||||||
|
console.log("An unknown error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
39
app/src/services/factoryBuilder/floor/upsertFloorApi.ts
Normal file
39
app/src/services/factoryBuilder/floor/upsertFloorApi.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
|
||||||
|
|
||||||
|
export const upsertFloorApi = async (
|
||||||
|
projectId: string,
|
||||||
|
versionId: string,
|
||||||
|
floorData: Wall
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${url_Backend_dwinzo}/api/V1/UpsertFloor`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer <access_token>",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
token: localStorage.getItem("token") || "",
|
||||||
|
refresh_token: localStorage.getItem("refreshToken") || "",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ projectId, versionId, floorData }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const newAccessToken = response.headers.get("x-access-token");
|
||||||
|
if (newAccessToken) {
|
||||||
|
localStorage.setItem("token", newAccessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
console.error("Failed to upsert floor:", response.statusText);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
echo.error("Failed to upsert floor");
|
||||||
|
if (error instanceof Error) {
|
||||||
|
console.log(error.message);
|
||||||
|
} else {
|
||||||
|
console.log("An unknown error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -21,13 +21,13 @@ export const getWallsApi = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error("Failed to get wall:", response.statusText);
|
console.error("Failed to get walls:", response.statusText);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
echo.error("Failed to get wall");
|
echo.error("Failed to get walls");
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ interface FloorStore {
|
|||||||
setPosition: (
|
setPosition: (
|
||||||
pointUuid: string,
|
pointUuid: string,
|
||||||
position: [number, number, number]
|
position: [number, number, number]
|
||||||
) => Floor | undefined;
|
) => Floor[] | [];
|
||||||
setIsBeveled: (uuid: string, isBeveled: boolean) => void;
|
setIsBeveled: (uuid: string, isBeveled: boolean) => void;
|
||||||
setBevelStrength: (uuid: string, strength: number) => void;
|
setBevelStrength: (uuid: string, strength: number) => void;
|
||||||
setDepth: (uuid: string, depth: number) => void;
|
setDepth: (uuid: string, depth: number) => void;
|
||||||
@@ -83,6 +83,7 @@ export const createFloorStore = () => {
|
|||||||
|
|
||||||
return removedFloors;
|
return removedFloors;
|
||||||
},
|
},
|
||||||
|
|
||||||
removeFloorByPoints: ([pointA, pointB]) => {
|
removeFloorByPoints: ([pointA, pointB]) => {
|
||||||
const removedFloors: Floor[] = [];
|
const removedFloors: Floor[] = [];
|
||||||
|
|
||||||
@@ -134,14 +135,13 @@ export const createFloorStore = () => {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
setPosition: (pointUuid, position) => {
|
setPosition: (pointUuid, position) => {
|
||||||
let updatedFloor: Floor | undefined;
|
let updatedFloor: Floor[] = [];
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const floor of state.floors) {
|
for (const floor of state.floors) {
|
||||||
const point = floor.points.find((p) => p.pointUuid === pointUuid);
|
const point = floor.points.find((p) => p.pointUuid === pointUuid);
|
||||||
if (point) {
|
if (point) {
|
||||||
point.position = position;
|
point.position = position;
|
||||||
updatedFloor = JSON.parse(JSON.stringify(floor));
|
updatedFloor.push(JSON.parse(JSON.stringify(floor)));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user