integrated path while deleting the asset

This commit is contained in:
Poovizhi99 2025-04-15 15:37:11 +05:30
parent 3446507307
commit c2a29fc893
1 changed files with 113 additions and 278 deletions

View File

@ -323,247 +323,124 @@ const SelectionControls: React.FC = () => {
}); });
}; };
// const removeConnection = (modelUUID: any) => { const removeConnections = (deletedModelUUIDs: string[]) => {
// const updatedStates = simulationStates.map((state) => {
// const removedPath = simulationStates?.flatMap((state) => { // Handle Conveyor
// let shouldInclude = false;
// if (state.type === "Conveyor") {
// state.points.forEach((point: any) => {
// const sourceMatch =
// point.connections?.source?.modelUUID === modelUUID;
// const targetMatch = point.connections?.targets?.some(
// (target: any) => target.modelUUID === modelUUID
// );
// if (sourceMatch || targetMatch) shouldInclude = true;
// });
// }
// if (state.type === "Vehicle") {
// const targetMatch = state.points.connections?.targets?.some(
// (target: any) => target.modelUUID === modelUUID
// );
// if (targetMatch) shouldInclude = true;
// }
// if (state.type === "StaticMachine") {
// const targetMatch = state.points.connections?.targets?.some(
// (target: any) => target.modelUUID === modelUUID
// );
// if (targetMatch) shouldInclude = true;
// }
// if (state.type === "ArmBot") {
// const sourceMatch =
// state.points.connections?.source?.modelUUID === modelUUID;
// const targetMatch = state.points.connections?.targets?.some(
// (target: any) => target.modelUUID === modelUUID
// );
// const processMatch =
// state.points.actions?.processes?.some(
// (process: any) =>
// process.startPoint === modelUUID || process.endPoint === modelUUID
// ) ?? false;
// if (sourceMatch || targetMatch || processMatch) shouldInclude = true;
// }
// return shouldInclude ? [state] : [];
// });
// updateBackend(removedPath);
//
// return removedPath;
// // updateBackend(updatedPaths);
// // setSimulationStates(updatedStates);
// };
// const removeConnection = (modelUUIDs: any[]) => {
//
// const removedPath = simulationStates?.flatMap((state) => {
// let shouldInclude = false;
// if (state.type === "Conveyor") {
// state.points.forEach((point: any) => {
// const sourceMatch = modelUUIDs.includes(
// point.connections?.source?.modelUUID
// );
// const targetMatch = point.connections?.targets?.some((target: any) =>
// modelUUIDs.includes(target.modelUUID)
// );
// if (sourceMatch || targetMatch) shouldInclude = true;
// });
// }
// if (state.type === "Vehicle") {
// const targetMatch = state.points.connections?.targets?.some(
// (target: any) => modelUUIDs.includes(target.modelUUID)
// );
// if (targetMatch) shouldInclude = true;
// }
// if (state.type === "StaticMachine") {
// const targetMatch = state.points.connections?.targets?.some(
// (target: any) => modelUUIDs.includes(target.modelUUID)
// );
// if (targetMatch) shouldInclude = true;
// }
// if (state.type === "ArmBot") {
// const sourceMatch = modelUUIDs.includes(
// state.points.connections?.source?.modelUUID
// );
// const targetMatch = state.points.connections?.targets?.some(
// (target: any) => modelUUIDs.includes(target.modelUUID)
// );
// const processMatch =
// state.points.actions?.processes?.some(
// (process: any) =>
// modelUUIDs.includes(process.startPoint) ||
// modelUUIDs.includes(process.endPoint)
// ) ?? false;
// if (sourceMatch || targetMatch || processMatch) shouldInclude = true;
// }
// return shouldInclude ? [state] : [];
// });
// updateBackend(removedPath);
//
// return removedPath;
// };
const removeConnection = (modelUUIDs: any[]) => {
const removedPath = simulationStates?.flatMap((state: any) => {
let shouldInclude = false;
// Conveyor type
if (state.type === "Conveyor") { if (state.type === "Conveyor") {
state.points.forEach((point: any) => { const updatedConveyor: SimulationTypes.ConveyorEventsSchema = {
const sourceMatch = modelUUIDs.includes( ...state,
point.connections?.source?.modelUUID points: state.points.map((point) => {
); return {
const targetMatch = point.connections?.targets?.some((target: any) => ...point,
modelUUIDs.includes(target.modelUUID) connections: {
); ...point.connections,
targets: point.connections.targets.filter(
if (sourceMatch) { (target) => !deletedModelUUIDs.includes(target.modelUUID)
point.connections.source = {}; ),
shouldInclude = true; },
} };
}),
if (targetMatch) { };
point.connections.targets = []; return updatedConveyor;
shouldInclude = true;
}
});
}
// Vehicle & StaticMachine types
if (state.type === "Vehicle") {
const targets = state.points?.connections?.targets || [];
const targetMatch = targets.some((target: any) =>
modelUUIDs.includes(target.modelUUID)
);
if (targetMatch) {
state.points.connections.targets = [];
shouldInclude = true;
}
}
if (state.type === "StaticMachine") {
const targets = state.points?.connections?.targets || [];
const targetMatch = targets.some((target: any) =>
modelUUIDs.includes(target.modelUUID)
);
if (targetMatch) {
state.points.connections.targets = [];
shouldInclude = true;
}
} }
// ArmBot type // Handle Vehicle
if (state.type === "ArmBot") { else if (state.type === "Vehicle") {
const sourceMatch = modelUUIDs.includes( const updatedVehicle: SimulationTypes.VehicleEventsSchema = {
state.points.connections?.source?.modelUUID ...state,
); points: {
console.log("model", modelUUIDs); ...state.points,
console.log("state.points.connections: ", state.points); connections: {
...state.points.connections,
const targetMatch = state.points.connections?.targets?.some( targets: state.points.connections.targets.filter(
(target: any) => modelUUIDs.includes(target.modelUUID) (target) => !deletedModelUUIDs.includes(target.modelUUID)
); ),
// state.points.actions.processes = state.points.actions.processes.filter( },
// (process: any) => },
// console.log( };
// !modelUUIDs.includes(process.startPoint), return updatedVehicle;
// !modelUUIDs.includes(process.endPoint),
// modelUUIDs,
// process.startPoint,
// process.endPoint
// )
// );
// shouldInclude = true;
// const processMatches = state.points.actions?.processes?.some(
// (process: any) =>
// console.log(
// "process: ",
// process,
// modelUUIDs,
// process.startPoint,
// process.endPoint
// )
// // modelUUIDs.includes(process.startPoint) ||
// // modelUUIDs.includes(process.endPoint)
// );
// const processMatch = state.points.actions?.processes?.some(
// (process: any) =>
// modelUUIDs.includes(String(process.startPoint)) ||
// modelUUIDs.includes(String(process.endPoint))
// );
// console.log("processMatch: ", processMatch);
if (sourceMatch) {
state.points.connections.source = {};
shouldInclude = true;
}
if (targetMatch) {
state.points.connections.targets =
state.points.connections.targets.filter(
(target: any) => !modelUUIDs.includes(target.modelUUID)
);
shouldInclude = true;
}
// console.log("processMatch: ", processMatch);
// if (processMatch) {
// state.points.actions.processes =
// state.points.actions.processes.filter((process: any) => {
// const shouldRemove =
// modelUUIDs.includes(process.startPoint) ||
// modelUUIDs.includes(process.endPoint);
// console.log("shouldRemove: ", shouldRemove);
// return !shouldRemove;
// });
// shouldInclude = true;
// }
} }
return shouldInclude ? [state] : []; // Handle StaticMachine
else if (state.type === "StaticMachine") {
const updatedStaticMachine: SimulationTypes.StaticMachineEventsSchema =
{
...state,
points: {
...state.points,
connections: {
...state.points.connections,
targets: state.points.connections.targets.filter(
(target) => !deletedModelUUIDs.includes(target.modelUUID)
),
},
},
};
return updatedStaticMachine;
}
// Handle ArmBot
else if (state.type === "ArmBot") {
const updatedArmBot: SimulationTypes.ArmBotEventsSchema = {
...state,
points: {
...state.points,
connections: {
...state.points.connections,
targets: state.points.connections.targets.filter(
(target: any) => !deletedModelUUIDs.includes(target.modelUUID)
),
},
actions: {
...state.points.actions,
processes: (state.points.actions.processes =
state.points.actions.processes?.filter((process) => {
const matchedStates = simulationStates.filter((s) =>
deletedModelUUIDs.includes(s.modeluuid)
);
if (matchedStates.length > 0) {
if (matchedStates[0]?.type === "StaticMachine") {
const trigPoints = matchedStates[0]?.points;
return !(
process.triggerId === trigPoints?.triggers?.uuid
);
} else if (matchedStates[0]?.type === "Conveyor") {
const trigPoints = matchedStates[0]?.points;
if (Array.isArray(trigPoints)) {
const nonEmptyTriggers = trigPoints.filter(
(point) =>
point && point.triggers && point.triggers.length > 0
);
const allTriggerUUIDs = nonEmptyTriggers
.flatMap((point) => point.triggers)
.map((trigger) => trigger.uuid);
return !allTriggerUUIDs.includes(process.triggerId);
}
}
}
return true;
})),
},
},
};
return updatedArmBot;
}
return state;
}); });
updateBackend(removedPath); const filteredStates = updatedStates.filter(
return removedPath; (state) => !deletedModelUUIDs.includes(state.modeluuid)
);
updateBackend(filteredStates);
setSimulationStates(filteredStates);
}; };
const deleteSelection = () => { const deleteSelection = () => {
@ -633,51 +510,9 @@ const SelectionControls: React.FC = () => {
itemsGroupRef.current?.remove(selectedMesh); itemsGroupRef.current?.remove(selectedMesh);
}); });
console.log("selectedAssets: ", selectedAssets);
const allUUIDs = selectedAssets.map((val: any) => val.uuid); const allUUIDs = selectedAssets.map((val: any) => val.uuid);
removeConnection(allUUIDs); removeConnections(allUUIDs);
// const removedPath = simulationStates?.flatMap((path: any) => {
// let shouldInclude = false;
// if (Array.isArray(path.points)) {
// path.points.forEach((point: any) => {
// const sourceMatch =
// point.connections?.source?.modelUUID === selectedAssets[0].uuid;
// const targetMatch = point.connections?.targets?.some(
// (target: any) => target.modelUUID === selectedAssets[0].uuid
// );
// if (sourceMatch) {
// point.connections.source = {};
// shouldInclude = true;
// }
// if (targetMatch) {
// point.connections.targets = [];
// shouldInclude = true;
// }
// });
// } else {
// const sourceMatch =
// path.connections?.source?.modelUUID === selectedAssets[0].uuid;
// const targetMatch = path.connections?.targets?.some(
// (target: any) => target.modelUUID === selectedAssets[0].uuid
// );
// if (sourceMatch) {
// path.connections.source = {};
// shouldInclude = true;
// }
// if (targetMatch) {
// path.connections.targets = [];
// shouldInclude = true;
// }
// }
// return shouldInclude ? [path] : [];
// });
// updateBackend(removedPath);
const updatedItems = floorItems.filter( const updatedItems = floorItems.filter(
(item: { modeluuid: string }) => !selectedUUIDs.includes(item.modeluuid) (item: { modeluuid: string }) => !selectedUUIDs.includes(item.modeluuid)