integrated the removeConnections in path connector
This commit is contained in:
@@ -1133,26 +1133,27 @@ function PathConnector({
|
|||||||
(state.modeluuid === connection2.model &&
|
(state.modeluuid === connection2.model &&
|
||||||
state.points.uuid === connection2.point)
|
state.points.uuid === connection2.point)
|
||||||
) {
|
) {
|
||||||
const updatedStaticMachine: SimulationTypes.StaticMachineEventsSchema = {
|
const updatedStaticMachine: SimulationTypes.StaticMachineEventsSchema =
|
||||||
...state,
|
{
|
||||||
points: {
|
...state,
|
||||||
...state.points,
|
points: {
|
||||||
connections: {
|
...state.points,
|
||||||
...state.points.connections,
|
connections: {
|
||||||
targets: state.points.connections.targets.filter((target) => {
|
...state.points.connections,
|
||||||
return !(
|
targets: state.points.connections.targets.filter((target) => {
|
||||||
(target.modelUUID === connection1.model &&
|
return !(
|
||||||
target.pointUUID === connection1.point) ||
|
(target.modelUUID === connection1.model &&
|
||||||
(target.modelUUID === connection2.model &&
|
target.pointUUID === connection1.point) ||
|
||||||
target.pointUUID === connection2.point)
|
(target.modelUUID === connection2.model &&
|
||||||
);
|
target.pointUUID === connection2.point)
|
||||||
}),
|
);
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
// Ensure all required StaticMachine point properties are included
|
||||||
|
actions: state.points.actions,
|
||||||
|
triggers: state.points.triggers,
|
||||||
},
|
},
|
||||||
// Ensure all required StaticMachine point properties are included
|
};
|
||||||
actions: state.points.actions,
|
|
||||||
triggers: state.points.triggers,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
return updatedStaticMachine;
|
return updatedStaticMachine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1211,6 +1212,125 @@ function PathConnector({
|
|||||||
|
|
||||||
setSimulationStates(updatedStates);
|
setSimulationStates(updatedStates);
|
||||||
};
|
};
|
||||||
|
const removeConnection = (deletedModelUUIDs: string[]) => {
|
||||||
|
const updatedStates = simulationStates.map((state) => {
|
||||||
|
// Handle Conveyor
|
||||||
|
if (state.type === "Conveyor") {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
});
|
||||||
|
|
||||||
|
const filteredStates = updatedStates.filter(
|
||||||
|
(state) => !deletedModelUUIDs.includes(state.modeluuid)
|
||||||
|
);
|
||||||
|
|
||||||
|
updateBackend(filteredStates);
|
||||||
|
setSimulationStates(filteredStates);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<group name="simulationConnectionGroup" visible={!isPlaying}>
|
<group name="simulationConnectionGroup" visible={!isPlaying}>
|
||||||
|
|||||||
Reference in New Issue
Block a user