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:
@@ -18,7 +18,7 @@ function FloorCreator() {
|
||||
const { addFloor, removeDecal, getFloorPointById, getFloorByPoints } = floorStore();
|
||||
const drag = useRef(false);
|
||||
const isLeftMouseDown = useRef(false);
|
||||
|
||||
|
||||
const [tempPoints, setTempPoints] = useState<Point[]>([]);
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const { floorDepth, isBeveled, bevelStrength, sideMaterial, topMaterial, snappedPosition, snappedPoint } = useBuilderStore();
|
||||
@@ -80,30 +80,34 @@ function FloorCreator() {
|
||||
newPoint.position = snappedPosition;
|
||||
}
|
||||
|
||||
if (pointIntersects && !snappedPoint) {
|
||||
if (tempPoints.length > 2 && isCreating && pointIntersects.object.userData.pointUuid === tempPoints[0].pointUuid) {
|
||||
if (tempPoints.length >= 3) {
|
||||
const floor: Floor = {
|
||||
floorUuid: THREE.MathUtils.generateUUID(),
|
||||
points: tempPoints,
|
||||
topMaterial,
|
||||
sideMaterial,
|
||||
floorDepth,
|
||||
isBeveled,
|
||||
bevelStrength,
|
||||
decals: [],
|
||||
};
|
||||
if (pointIntersects) {
|
||||
if (tempPoints.length > 2 && isCreating && pointIntersects.object.uuid === tempPoints[0].pointUuid) {
|
||||
const floor: Floor = {
|
||||
floorUuid: THREE.MathUtils.generateUUID(),
|
||||
points: tempPoints,
|
||||
topMaterial,
|
||||
sideMaterial,
|
||||
floorDepth,
|
||||
isBeveled,
|
||||
bevelStrength,
|
||||
decals: [],
|
||||
};
|
||||
|
||||
addFloor(floor);
|
||||
}
|
||||
addFloor(floor);
|
||||
setTempPoints([]);
|
||||
setIsCreating(false);
|
||||
} else if (tempPoints.length === 0) {
|
||||
tempPoints.push(pointIntersects.object.userData as Point);
|
||||
setIsCreating(true);
|
||||
} else {
|
||||
setTempPoints([]);
|
||||
setIsCreating(false);
|
||||
}
|
||||
} else {
|
||||
setTempPoints(prev => [...prev, newPoint]);
|
||||
setIsCreating(true);
|
||||
}
|
||||
|
||||
setTempPoints(prev => [...prev, newPoint]);
|
||||
setIsCreating(true);
|
||||
|
||||
};
|
||||
|
||||
const onContext = (event: any) => {
|
||||
@@ -157,7 +161,7 @@ function FloorCreator() {
|
||||
<>
|
||||
{toggleView &&
|
||||
<>
|
||||
<group name='Wall-Reference-Points-Group'>
|
||||
<group name='Floor-Reference-Points-Group'>
|
||||
{tempPoints.map((point) => (
|
||||
<ReferencePoint key={point.pointUuid} point={point} />
|
||||
))}
|
||||
|
||||
@@ -201,10 +201,13 @@ export const usePointSnapping = (currentPoint: { uuid: string, pointType: string
|
||||
);
|
||||
}, [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 };
|
||||
|
||||
const otherPoints = [...getAllOtherFloorPoints(), ...tempPoints];
|
||||
const otherPoints = getAllOtherFloorPoints();
|
||||
if (tempPoints) {
|
||||
otherPoints.concat(tempPoints);
|
||||
}
|
||||
const currentVec = new THREE.Vector3(...position);
|
||||
|
||||
for (const point of otherPoints) {
|
||||
|
||||
@@ -12,8 +12,8 @@ import { useSceneContext } from '../../scene/sceneContext';
|
||||
|
||||
import { upsertAisleApi } from '../../../services/factoryBuilder/aisle/upsertAisleApi';
|
||||
import { deleteAisleApi } from '../../../services/factoryBuilder/aisle/deleteAisleApi';
|
||||
import { upsertWallApi } from '../../../services/factoryBuilder/wall/upsertWallApi';
|
||||
import { deleteWallApi } from '../../../services/factoryBuilder/wall/deleteWallApi';
|
||||
// import { upsertWallApi } from '../../../services/factoryBuilder/wall/upsertWallApi';
|
||||
// import { deleteWallApi } from '../../../services/factoryBuilder/wall/deleteWallApi';
|
||||
import { getUserData } from '../../../functions/getUserData';
|
||||
|
||||
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: setWallPosition, removePoint: removeWallPoint, getWallsByPointId } = wallStore();
|
||||
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 { userId, organization } = getUserData();
|
||||
const { selectedVersionStore } = useVersionContext();
|
||||
@@ -121,8 +121,8 @@ function Point({ point }: { readonly point: Point }) {
|
||||
const finalSnapped = snapWallPoint(wallSnapped.position);
|
||||
setWallPosition(point.pointUuid, finalSnapped.position);
|
||||
} else if (point.pointType === 'Floor') {
|
||||
const floorSnapped = snapWallAngle(newPosition);
|
||||
const finalSnapped = snapWallPoint(floorSnapped.position);
|
||||
const floorSnapped = snapFloorAngle(newPosition);
|
||||
const finalSnapped = snapFloorPoint(floorSnapped.position);
|
||||
setFloorPosition(point.pointUuid, finalSnapped.position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ function ReferencePoint({ point }: { readonly point: Point }) {
|
||||
<mesh
|
||||
position={new THREE.Vector3(...point.position)}
|
||||
name={pointName}
|
||||
uuid={point.pointUuid}
|
||||
userData={point}
|
||||
>
|
||||
<boxGeometry args={boxScale} />
|
||||
<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) {
|
||||
console.error("Failed to get wall:", response.statusText);
|
||||
console.error("Failed to get walls:", response.statusText);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
return result;
|
||||
} catch (error) {
|
||||
echo.error("Failed to get wall");
|
||||
echo.error("Failed to get walls");
|
||||
if (error instanceof Error) {
|
||||
console.log(error.message);
|
||||
} else {
|
||||
|
||||
@@ -13,7 +13,7 @@ interface FloorStore {
|
||||
setPosition: (
|
||||
pointUuid: string,
|
||||
position: [number, number, number]
|
||||
) => Floor | undefined;
|
||||
) => Floor[] | [];
|
||||
setIsBeveled: (uuid: string, isBeveled: boolean) => void;
|
||||
setBevelStrength: (uuid: string, strength: number) => void;
|
||||
setDepth: (uuid: string, depth: number) => void;
|
||||
@@ -83,6 +83,7 @@ export const createFloorStore = () => {
|
||||
|
||||
return removedFloors;
|
||||
},
|
||||
|
||||
removeFloorByPoints: ([pointA, pointB]) => {
|
||||
const removedFloors: Floor[] = [];
|
||||
|
||||
@@ -134,14 +135,13 @@ export const createFloorStore = () => {
|
||||
}),
|
||||
|
||||
setPosition: (pointUuid, position) => {
|
||||
let updatedFloor: Floor | undefined;
|
||||
let updatedFloor: Floor[] = [];
|
||||
set((state) => {
|
||||
for (const floor of state.floors) {
|
||||
const point = floor.points.find((p) => p.pointUuid === pointUuid);
|
||||
if (point) {
|
||||
point.position = position;
|
||||
updatedFloor = JSON.parse(JSON.stringify(floor));
|
||||
break;
|
||||
updatedFloor.push(JSON.parse(JSON.stringify(floor)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user