integrated path while deleting the asset
This commit is contained in:
parent
3446507307
commit
c2a29fc893
|
@ -323,247 +323,124 @@ const SelectionControls: React.FC = () => {
|
|||
});
|
||||
};
|
||||
|
||||
// const removeConnection = (modelUUID: any) => {
|
||||
//
|
||||
// const removedPath = simulationStates?.flatMap((state) => {
|
||||
// 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
|
||||
const removeConnections = (deletedModelUUIDs: string[]) => {
|
||||
const updatedStates = simulationStates.map((state) => {
|
||||
// Handle Conveyor
|
||||
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) {
|
||||
point.connections.source = {};
|
||||
shouldInclude = true;
|
||||
}
|
||||
|
||||
if (targetMatch) {
|
||||
point.connections.targets = [];
|
||||
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;
|
||||
}
|
||||
const updatedConveyor: SimulationTypes.ConveyorEventsSchema = {
|
||||
...state,
|
||||
points: state.points.map((point) => {
|
||||
return {
|
||||
...point,
|
||||
connections: {
|
||||
...point.connections,
|
||||
targets: point.connections.targets.filter(
|
||||
(target) => !deletedModelUUIDs.includes(target.modelUUID)
|
||||
),
|
||||
},
|
||||
};
|
||||
}),
|
||||
};
|
||||
return updatedConveyor;
|
||||
}
|
||||
|
||||
// ArmBot type
|
||||
if (state.type === "ArmBot") {
|
||||
const sourceMatch = modelUUIDs.includes(
|
||||
state.points.connections?.source?.modelUUID
|
||||
);
|
||||
console.log("model", modelUUIDs);
|
||||
console.log("state.points.connections: ", state.points);
|
||||
|
||||
const targetMatch = state.points.connections?.targets?.some(
|
||||
(target: any) => modelUUIDs.includes(target.modelUUID)
|
||||
);
|
||||
// state.points.actions.processes = state.points.actions.processes.filter(
|
||||
// (process: any) =>
|
||||
// console.log(
|
||||
// !modelUUIDs.includes(process.startPoint),
|
||||
// !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;
|
||||
// }
|
||||
// Handle Vehicle
|
||||
else if (state.type === "Vehicle") {
|
||||
const updatedVehicle: SimulationTypes.VehicleEventsSchema = {
|
||||
...state,
|
||||
points: {
|
||||
...state.points,
|
||||
connections: {
|
||||
...state.points.connections,
|
||||
targets: state.points.connections.targets.filter(
|
||||
(target) => !deletedModelUUIDs.includes(target.modelUUID)
|
||||
),
|
||||
},
|
||||
},
|
||||
};
|
||||
return updatedVehicle;
|
||||
}
|
||||
|
||||
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);
|
||||
return removedPath;
|
||||
const filteredStates = updatedStates.filter(
|
||||
(state) => !deletedModelUUIDs.includes(state.modeluuid)
|
||||
);
|
||||
|
||||
updateBackend(filteredStates);
|
||||
setSimulationStates(filteredStates);
|
||||
};
|
||||
|
||||
const deleteSelection = () => {
|
||||
|
@ -633,51 +510,9 @@ const SelectionControls: React.FC = () => {
|
|||
itemsGroupRef.current?.remove(selectedMesh);
|
||||
});
|
||||
|
||||
console.log("selectedAssets: ", selectedAssets);
|
||||
const allUUIDs = selectedAssets.map((val: any) => val.uuid);
|
||||
removeConnection(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);
|
||||
removeConnections(allUUIDs);
|
||||
|
||||
const updatedItems = floorItems.filter(
|
||||
(item: { modeluuid: string }) => !selectedUUIDs.includes(item.modeluuid)
|
||||
|
|
Loading…
Reference in New Issue