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);
|
||||
|
||||
@@ -52,7 +52,7 @@ function Point({ point }: { readonly point: Point }) {
|
||||
const boxScale: [number, number, number] = Constants.pointConfig.boxScale;
|
||||
const colors = getColor(point);
|
||||
|
||||
const [initialPositions, setInitialPositions] = useState<{
|
||||
const [initialStates, setInitialStates] = useState<{
|
||||
aisles?: Aisle[],
|
||||
walls?: Wall[],
|
||||
floors?: Floor[],
|
||||
@@ -167,16 +167,16 @@ function Point({ point }: { readonly point: Point }) {
|
||||
|
||||
if (point.pointType === 'Aisle') {
|
||||
const aisles = getAislesByPointId(point.pointUuid);
|
||||
setInitialPositions({ aisles });
|
||||
setInitialStates({ aisles });
|
||||
} else if (point.pointType === 'Wall') {
|
||||
const walls = getWallsByPointId(point.pointUuid);
|
||||
setInitialPositions({ walls });
|
||||
setInitialStates({ walls });
|
||||
} else if (point.pointType === 'Floor') {
|
||||
const floors = getFloorsByPointId(point.pointUuid);
|
||||
setInitialPositions({ floors });
|
||||
setInitialStates({ floors });
|
||||
} else if (point.pointType === 'Zone') {
|
||||
const zones = getZonesByPointId(point.pointUuid);
|
||||
setInitialPositions({ zones });
|
||||
setInitialStates({ zones });
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -208,8 +208,8 @@ function Point({ point }: { readonly point: Point }) {
|
||||
})
|
||||
})
|
||||
|
||||
if (initialPositions.aisles && initialPositions.aisles.length > 0) {
|
||||
const updatedPoints = initialPositions.aisles.map((aisle) => ({
|
||||
if (initialStates.aisles && initialStates.aisles.length > 0) {
|
||||
const updatedPoints = initialStates.aisles.map((aisle) => ({
|
||||
type: "Aisle" as const,
|
||||
lineData: aisle,
|
||||
newData: updatedAisles.find(a => a.aisleUuid === aisle.aisleUuid),
|
||||
@@ -230,7 +230,7 @@ function Point({ point }: { readonly point: Point }) {
|
||||
if (updatedWalls && updatedWalls.length > 0 && projectId) {
|
||||
updatedWalls.forEach((updatedWall) => {
|
||||
|
||||
const initialWall = initialPositions.walls?.find(w => w.wallUuid === updatedWall.wallUuid);
|
||||
const initialWall = initialStates.walls?.find(w => w.wallUuid === updatedWall.wallUuid);
|
||||
|
||||
if (initialWall) {
|
||||
const assetsOnWall = getWallAssetsByWall(updatedWall.wallUuid);
|
||||
@@ -281,8 +281,8 @@ function Point({ point }: { readonly point: Point }) {
|
||||
});
|
||||
}
|
||||
|
||||
if (initialPositions.walls && initialPositions.walls.length > 0) {
|
||||
const updatedPoints = initialPositions.walls.map((wall) => ({
|
||||
if (initialStates.walls && initialStates.walls.length > 0) {
|
||||
const updatedPoints = initialStates.walls.map((wall) => ({
|
||||
type: "Wall" as const,
|
||||
lineData: wall,
|
||||
newData: updatedWalls.find(w => w.wallUuid === wall.wallUuid),
|
||||
@@ -320,8 +320,8 @@ function Point({ point }: { readonly point: Point }) {
|
||||
});
|
||||
}
|
||||
|
||||
if (initialPositions.floors && initialPositions.floors.length > 0) {
|
||||
const updatedPoints = initialPositions.floors.map((floor) => ({
|
||||
if (initialStates.floors && initialStates.floors.length > 0) {
|
||||
const updatedPoints = initialStates.floors.map((floor) => ({
|
||||
type: "Floor" as const,
|
||||
lineData: floor,
|
||||
newData: updatedFloors.find(f => f.floorUuid === floor.floorUuid),
|
||||
@@ -359,8 +359,8 @@ function Point({ point }: { readonly point: Point }) {
|
||||
});
|
||||
}
|
||||
|
||||
if (initialPositions.zones && initialPositions.zones.length > 0) {
|
||||
const updatedPoints = initialPositions.zones.map((zone) => ({
|
||||
if (initialStates.zones && initialStates.zones.length > 0) {
|
||||
const updatedPoints = initialStates.zones.map((zone) => ({
|
||||
type: "Zone" as const,
|
||||
lineData: zone,
|
||||
newData: updatedZones.find(z => z.zoneUuid === zone.zoneUuid),
|
||||
@@ -377,7 +377,7 @@ function Point({ point }: { readonly point: Point }) {
|
||||
}
|
||||
}
|
||||
|
||||
setInitialPositions({});
|
||||
setInitialStates({});
|
||||
}
|
||||
|
||||
const handlePointClick = (point: Point) => {
|
||||
|
||||
Reference in New Issue
Block a user