removed bug in wall asset dynamic position updation
This commit is contained in:
@@ -11,6 +11,7 @@ import { useParams } from 'react-router-dom';
|
||||
import { getUserData } from '../../../functions/getUserData';
|
||||
import { handleCanvasCursors } from '../../../utils/mouseUtils/handleCanvasCursors';
|
||||
import { useSelectedPoints } from '../../../store/simulation/useSimulationStore';
|
||||
import { calculateAssetTransformationOnWall } from '../wallAsset/Instances/Instance/functions/calculateAssetTransformationOnWall';
|
||||
|
||||
// import { upsertWallApi } from '../../../services/factoryBuilder/wall/upsertWallApi';
|
||||
// import { deleteWallApi } from '../../../services/factoryBuilder/wall/deleteWallApi';
|
||||
@@ -18,6 +19,8 @@ import { useSelectedPoints } from '../../../store/simulation/useSimulationStore'
|
||||
// import { deleteFloorApi } from '../../../services/factoryBuilder/floor/deleteFloorApi';
|
||||
// import { deleteZoneApi } from '../../../services/factoryBuilder/zone/deleteZoneApi';
|
||||
// import { upsertZoneApi } from '../../../services/factoryBuilder/zone/upsertZoneApi';
|
||||
// import { upsertWallAssetApi } from '../../../services/factoryBuilder/asset/wallAsset/upsertWallAssetApi';
|
||||
// import { deleteWallAssetApi } from '../../../services/factoryBuilder/asset/wallAsset/deleteWallAssetApi';
|
||||
|
||||
interface LineProps {
|
||||
points: [Point, Point];
|
||||
@@ -30,8 +33,9 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
const [isDeletable, setIsDeletable] = useState(false);
|
||||
const { socket } = useSocketStore();
|
||||
const { toolMode } = useToolMode();
|
||||
const { wallStore, floorStore, zoneStore, undoRedo2DStore } = useSceneContext();
|
||||
const { wallStore, floorStore, zoneStore, undoRedo2DStore, wallAssetStore } = useSceneContext();
|
||||
const { push2D } = undoRedo2DStore();
|
||||
const { getWallAssetsByWall, updateWallAsset, removeWallAsset } = wallAssetStore();
|
||||
const { removeWallByPoints, setPosition: setWallPosition, getWallByPoints, getConnectedWallsByWallId } = wallStore();
|
||||
const { removeFloorByPoints, setPosition: setFloorPosition, getFloorsByPointId, getFloorsByPoints } = floorStore();
|
||||
const { removeZoneByPoints, setPosition: setZonePosition, getZonesByPointId, getZonesByPoints } = zoneStore();
|
||||
@@ -110,6 +114,33 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
const removedWall = removeWallByPoints(points);
|
||||
if (removedWall && projectId) {
|
||||
|
||||
const assetsOnWall = getWallAssetsByWall(removedWall.wallUuid);
|
||||
|
||||
assetsOnWall.forEach((asset) => {
|
||||
if (projectId && asset) {
|
||||
|
||||
removeWallAsset(asset.modelUuid);
|
||||
|
||||
// API
|
||||
|
||||
// deleteWallAssetApi(projectId, selectedVersion?.versionId || '', asset.modelUuid, asset.wallUuid);
|
||||
|
||||
// SOCKET
|
||||
|
||||
const data = {
|
||||
projectId: projectId,
|
||||
versionId: selectedVersion?.versionId || '',
|
||||
userId: userId,
|
||||
organization: organization,
|
||||
modelUuid: asset.modelUuid,
|
||||
wallUuid: asset.wallUuid
|
||||
}
|
||||
|
||||
socket.emit('v1:wall-asset:delete', data);
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
// API
|
||||
|
||||
// deleteWallApi(projectId, selectedVersion?.versionId || '', removedWall.wallUuid);
|
||||
@@ -377,7 +408,7 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDragEnd = (points: [Point, Point]) => {
|
||||
const handleDragEnd = (points: [Point, Point]) => {
|
||||
if (toolMode !== 'move' || !dragOffset) return;
|
||||
handleCanvasCursors('default');
|
||||
setDragOffset(null);
|
||||
@@ -390,6 +421,39 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
if (updatedWalls.length > 0 && projectId) {
|
||||
updatedWalls.forEach(updatedWall => {
|
||||
|
||||
const initialWall = initialPositions.walls?.find(w => w.wallUuid === updatedWall.wallUuid);
|
||||
|
||||
if (initialWall) {
|
||||
const assetsOnWall = getWallAssetsByWall(updatedWall.wallUuid);
|
||||
|
||||
assetsOnWall.forEach(asset => {
|
||||
const { position, rotation } = calculateAssetTransformationOnWall(asset, initialWall, updatedWall);
|
||||
|
||||
const updatedWallAsset = updateWallAsset(asset.modelUuid, {
|
||||
position: [position[0], asset.position[1], position[2]],
|
||||
rotation: rotation
|
||||
});
|
||||
|
||||
if (projectId && updatedWallAsset) {
|
||||
// API
|
||||
|
||||
// upsertWallAssetApi(projectId, selectedVersion?.versionId || '', updatedWallAsset);
|
||||
|
||||
// SOCKET
|
||||
|
||||
const data = {
|
||||
wallAssetData: updatedWallAsset,
|
||||
projectId: projectId,
|
||||
versionId: selectedVersion?.versionId || '',
|
||||
userId: userId,
|
||||
organization: organization
|
||||
}
|
||||
|
||||
socket.emit('v1:wall-asset:add', data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
// upsertWallApi(projectId, selectedVersion?.versionId || '', updatedWall);
|
||||
|
||||
Reference in New Issue
Block a user