feat: Integrate undo/redo functionality for aisle and line creation; enhance selection controls for better state management
This commit is contained in:
@@ -19,8 +19,9 @@ function AisleCreator() {
|
||||
const { toolMode } = useToolMode();
|
||||
const { activeLayer } = useActiveLayer();
|
||||
const { socket } = useSocketStore();
|
||||
const { aisleStore } = useSceneContext();
|
||||
const { aisleStore, undoRedo2DStore } = useSceneContext();
|
||||
const { addAisle, getAislePointById } = aisleStore();
|
||||
const { push2D } = undoRedo2DStore();
|
||||
const drag = useRef(false);
|
||||
const isLeftMouseDown = useRef(false);
|
||||
const { selectedVersionStore } = useVersionContext();
|
||||
@@ -107,7 +108,23 @@ function AisleCreator() {
|
||||
aisleWidth: aisleWidth
|
||||
}
|
||||
};
|
||||
|
||||
addAisle(aisle);
|
||||
|
||||
push2D({
|
||||
type: 'Draw',
|
||||
actions: [
|
||||
{
|
||||
actionType: 'Line-Create',
|
||||
point: {
|
||||
type: 'Aisle',
|
||||
lineData: aisle,
|
||||
timeStamp: new Date().toISOString(),
|
||||
}
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
if (projectId) {
|
||||
|
||||
// API
|
||||
@@ -145,7 +162,23 @@ function AisleCreator() {
|
||||
gapLength: gapLength
|
||||
}
|
||||
};
|
||||
|
||||
addAisle(aisle);
|
||||
|
||||
push2D({
|
||||
type: 'Draw',
|
||||
actions: [
|
||||
{
|
||||
actionType: 'Line-Create',
|
||||
point: {
|
||||
type: 'Aisle',
|
||||
lineData: aisle,
|
||||
timeStamp: new Date().toISOString(),
|
||||
}
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
if (projectId) {
|
||||
|
||||
// API
|
||||
@@ -182,7 +215,23 @@ function AisleCreator() {
|
||||
gapLength: gapLength
|
||||
}
|
||||
};
|
||||
|
||||
addAisle(aisle);
|
||||
|
||||
push2D({
|
||||
type: 'Draw',
|
||||
actions: [
|
||||
{
|
||||
actionType: 'Line-Create',
|
||||
point: {
|
||||
type: 'Aisle',
|
||||
lineData: aisle,
|
||||
timeStamp: new Date().toISOString(),
|
||||
}
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
if (projectId) {
|
||||
|
||||
// API
|
||||
@@ -218,7 +267,23 @@ function AisleCreator() {
|
||||
aisleWidth: aisleWidth
|
||||
}
|
||||
};
|
||||
|
||||
addAisle(aisle);
|
||||
|
||||
push2D({
|
||||
type: 'Draw',
|
||||
actions: [
|
||||
{
|
||||
actionType: 'Line-Create',
|
||||
point: {
|
||||
type: 'Aisle',
|
||||
lineData: aisle,
|
||||
timeStamp: new Date().toISOString(),
|
||||
}
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
if (projectId) {
|
||||
|
||||
// API
|
||||
@@ -256,7 +321,23 @@ function AisleCreator() {
|
||||
gapLength: gapLength
|
||||
}
|
||||
};
|
||||
|
||||
addAisle(aisle);
|
||||
|
||||
push2D({
|
||||
type: 'Draw',
|
||||
actions: [
|
||||
{
|
||||
actionType: 'Line-Create',
|
||||
point: {
|
||||
type: 'Aisle',
|
||||
lineData: aisle,
|
||||
timeStamp: new Date().toISOString(),
|
||||
}
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
if (projectId) {
|
||||
|
||||
// API
|
||||
@@ -293,7 +374,23 @@ function AisleCreator() {
|
||||
isFlipped: isFlipped
|
||||
}
|
||||
};
|
||||
|
||||
addAisle(aisle);
|
||||
|
||||
push2D({
|
||||
type: 'Draw',
|
||||
actions: [
|
||||
{
|
||||
actionType: 'Line-Create',
|
||||
point: {
|
||||
type: 'Aisle',
|
||||
lineData: aisle,
|
||||
timeStamp: new Date().toISOString(),
|
||||
}
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
if (projectId) {
|
||||
|
||||
// API
|
||||
@@ -329,7 +426,23 @@ function AisleCreator() {
|
||||
aisleWidth: aisleWidth
|
||||
}
|
||||
};
|
||||
|
||||
addAisle(aisle);
|
||||
|
||||
push2D({
|
||||
type: 'Draw',
|
||||
actions: [
|
||||
{
|
||||
actionType: 'Line-Create',
|
||||
point: {
|
||||
type: 'Aisle',
|
||||
lineData: aisle,
|
||||
timeStamp: new Date().toISOString(),
|
||||
}
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
if (projectId) {
|
||||
|
||||
// API
|
||||
@@ -366,7 +479,23 @@ function AisleCreator() {
|
||||
isFlipped: isFlipped
|
||||
}
|
||||
};
|
||||
|
||||
addAisle(aisle);
|
||||
|
||||
push2D({
|
||||
type: 'Draw',
|
||||
actions: [
|
||||
{
|
||||
actionType: 'Line-Create',
|
||||
point: {
|
||||
type: 'Aisle',
|
||||
lineData: aisle,
|
||||
timeStamp: new Date().toISOString(),
|
||||
}
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
if (projectId) {
|
||||
|
||||
// API
|
||||
|
||||
@@ -43,6 +43,13 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
const { hoveredLine, setHoveredLine, hoveredPoint } = useBuilderStore();
|
||||
const { selectedPoints } = useSelectedPoints();
|
||||
|
||||
const [initialPositions, setInitialPositions] = useState<{
|
||||
aisles?: Aisle[],
|
||||
walls?: Wall[],
|
||||
floors?: Floor[],
|
||||
zones?: Zone[]
|
||||
}>({});
|
||||
|
||||
const path = useMemo(() => {
|
||||
const [start, end] = points.map(p => new THREE.Vector3(...p.position));
|
||||
return new THREE.LineCurve3(start, end);
|
||||
@@ -353,6 +360,17 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
|
||||
const offset = new THREE.Vector3().subVectors(midPoint, hit);
|
||||
setDragOffset(offset);
|
||||
|
||||
if (points[0].pointType === 'Wall') {
|
||||
const walls = getWallsByPointId(points[0].pointUuid);
|
||||
setInitialPositions({ walls });
|
||||
} else if (points[0].pointType === 'Floor') {
|
||||
const floors = getFloorsByPointId(points[0].pointUuid);
|
||||
setInitialPositions({ floors });
|
||||
} else if (points[0].pointType === 'Zone') {
|
||||
const zones = getZonesByPointId(points[0].pointUuid);
|
||||
setInitialPositions({ zones });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -370,9 +388,7 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
|
||||
// API
|
||||
|
||||
// upsertWallApi(projectId, selectedVersion?.versionId || '', updatedWall).catch((error) => {
|
||||
// console.error('Error updating wall:', error);
|
||||
// });
|
||||
// upsertWallApi(projectId, selectedVersion?.versionId || '', updatedWall);
|
||||
|
||||
// SOCKET
|
||||
|
||||
@@ -386,6 +402,23 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
|
||||
socket.emit('v1:model-Wall:add', data);
|
||||
})
|
||||
|
||||
if (initialPositions.walls && initialPositions.walls.length > 0) {
|
||||
const updatedPoints = initialPositions.walls.map((wall) => ({
|
||||
type: "Wall" as const,
|
||||
lineData: wall,
|
||||
newData: updatedWalls.find(w => w.wallUuid === wall.wallUuid),
|
||||
timeStamp: new Date().toISOString(),
|
||||
}));
|
||||
|
||||
push2D({
|
||||
type: 'Draw',
|
||||
actions: [{
|
||||
actionType: 'Lines-Update',
|
||||
points: updatedPoints,
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (points[0].pointType === 'Floor' && points[1].pointType === 'Floor') {
|
||||
const updatedFloors1 = getFloorsByPointId(points[0].pointUuid);
|
||||
@@ -397,9 +430,7 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
|
||||
// API
|
||||
|
||||
// upsertFloorApi(projectId, selectedVersion?.versionId || '', updatedFloor).catch((error) => {
|
||||
// console.error('Error updating floor:', error);
|
||||
// });
|
||||
// upsertFloorApi(projectId, selectedVersion?.versionId || '', updatedFloor);
|
||||
|
||||
// SOCKET
|
||||
|
||||
@@ -413,6 +444,23 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
|
||||
socket.emit('v1:model-Floor:add', data);
|
||||
})
|
||||
|
||||
if (initialPositions.floors && initialPositions.floors.length > 0) {
|
||||
const updatedPoints = initialPositions.floors.map((floor) => ({
|
||||
type: "Floor" as const,
|
||||
lineData: floor,
|
||||
newData: updatedFloors.find(f => f.floorUuid === floor.floorUuid),
|
||||
timeStamp: new Date().toISOString(),
|
||||
}));
|
||||
|
||||
push2D({
|
||||
type: 'Draw',
|
||||
actions: [{
|
||||
actionType: 'Lines-Update',
|
||||
points: updatedPoints,
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (points[0].pointType === 'Zone' && points[1].pointType === 'Zone') {
|
||||
const updatedZones1 = getZonesByPointId(points[0].pointUuid);
|
||||
@@ -424,9 +472,7 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
|
||||
// API
|
||||
|
||||
// upsertZoneApi(projectId, selectedVersion?.versionId || '', updatedZone).catch((error) => {
|
||||
// console.error('Error updating zone:', error);
|
||||
// });
|
||||
// upsertZoneApi(projectId, selectedVersion?.versionId || '', updatedZone);
|
||||
|
||||
// SOCKET
|
||||
|
||||
@@ -440,6 +486,23 @@ function Line({ points }: Readonly<LineProps>) {
|
||||
|
||||
socket.emit('v1:zone:add', data);
|
||||
})
|
||||
|
||||
if (initialPositions.zones && initialPositions.zones.length > 0) {
|
||||
const updatedPoints = initialPositions.zones.map((zone) => ({
|
||||
type: "Zone" as const,
|
||||
lineData: zone,
|
||||
newData: updatedZones.find(z => z.zoneUuid === zone.zoneUuid),
|
||||
timeStamp: new Date().toISOString(),
|
||||
}));
|
||||
|
||||
push2D({
|
||||
type: 'Draw',
|
||||
actions: [{
|
||||
actionType: 'Lines-Update',
|
||||
points: updatedPoints,
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user