simulation #66
@@ -270,6 +270,20 @@ const SelectionControls: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const removeConnections = (deletedModelUUIDs: string[]) => {
|
const removeConnections = (deletedModelUUIDs: string[]) => {
|
||||||
|
|
||||||
|
const deletedPointUUIDs = new Set<string>();
|
||||||
|
simulationStates.forEach(state => {
|
||||||
|
if (deletedModelUUIDs.includes(state.modeluuid)) {
|
||||||
|
if (state.type === "Conveyor" && state.points) {
|
||||||
|
state.points.forEach(point => {
|
||||||
|
deletedPointUUIDs.add(point.uuid);
|
||||||
|
});
|
||||||
|
} else if (state.points && 'uuid' in state.points) {
|
||||||
|
deletedPointUUIDs.add(state.points.uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const updatedStates = simulationStates.map((state) => {
|
const updatedStates = simulationStates.map((state) => {
|
||||||
// Handle Conveyor
|
// Handle Conveyor
|
||||||
if (state.type === "Conveyor") {
|
if (state.type === "Conveyor") {
|
||||||
@@ -333,38 +347,41 @@ const SelectionControls: React.FC = () => {
|
|||||||
...state.points,
|
...state.points,
|
||||||
connections: {
|
connections: {
|
||||||
...state.points.connections,
|
...state.points.connections,
|
||||||
|
|
||||||
targets: state.points.connections.targets.filter(
|
targets: state.points.connections.targets.filter(
|
||||||
(target: any) => !deletedModelUUIDs.includes(target.modelUUID)
|
(target: any) => !deletedModelUUIDs.includes(target.modelUUID)
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
...state.points.actions,
|
...state.points.actions,
|
||||||
processes: (state.points.actions.processes =
|
processes: state.points.actions.processes?.filter((process) => {
|
||||||
state.points.actions.processes?.filter((process) => {
|
// Check if trigger is from deleted model
|
||||||
const matchedStates = simulationStates.filter((s) => deletedModelUUIDs.includes(s.modeluuid));
|
const matchedStates = simulationStates.filter((s) => deletedModelUUIDs.includes(s.modeluuid));
|
||||||
|
|
||||||
if (matchedStates.length > 0) {
|
if (matchedStates.length > 0) {
|
||||||
if (matchedStates[0]?.type === "StaticMachine") {
|
if (matchedStates[0]?.type === "StaticMachine") {
|
||||||
const trigPoints = matchedStates[0]?.points;
|
const trigPoints = matchedStates[0]?.points;
|
||||||
|
if (process.triggerId === trigPoints?.triggers?.uuid) {
|
||||||
return !(
|
return false;
|
||||||
process.triggerId === trigPoints?.triggers?.uuid
|
}
|
||||||
);
|
} else if (matchedStates[0]?.type === "Conveyor") {
|
||||||
} else if (matchedStates[0]?.type === "Conveyor") {
|
const trigPoints = matchedStates[0]?.points;
|
||||||
const trigPoints = matchedStates[0]?.points;
|
if (Array.isArray(trigPoints)) {
|
||||||
|
const nonEmptyTriggers = trigPoints.filter((point) => point && point.triggers && point.triggers.length > 0);
|
||||||
if (Array.isArray(trigPoints)) {
|
const allTriggerUUIDs = nonEmptyTriggers.flatMap((point) => point.triggers).map((trigger) => trigger.uuid);
|
||||||
const nonEmptyTriggers = trigPoints.filter((point) => point && point.triggers && point.triggers.length > 0);
|
if (allTriggerUUIDs.includes(process.triggerId)) {
|
||||||
|
return false;
|
||||||
const allTriggerUUIDs = nonEmptyTriggers.flatMap((point) => point.triggers).map((trigger) => trigger.uuid);
|
|
||||||
|
|
||||||
return !allTriggerUUIDs.includes(process.triggerId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
})),
|
|
||||||
|
// Check if startPoint or endPoint is from deleted model
|
||||||
|
if (deletedPointUUIDs.has(process.startPoint) || deletedPointUUIDs.has(process.endPoint)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -964,8 +964,21 @@ function PathConnector({ pathsGroupRef, }: { pathsGroupRef: React.MutableRefObje
|
|||||||
};
|
};
|
||||||
|
|
||||||
const removeConnections = (deletedModelUUIDs: string[]) => {
|
const removeConnections = (deletedModelUUIDs: string[]) => {
|
||||||
const updatedStates = simulationStates.map((state) => {
|
|
||||||
|
|
||||||
|
const deletedPointUUIDs = new Set<string>();
|
||||||
|
simulationStates.forEach(state => {
|
||||||
|
if (deletedModelUUIDs.includes(state.modeluuid)) {
|
||||||
|
if (state.type === "Conveyor" && state.points) {
|
||||||
|
state.points.forEach(point => {
|
||||||
|
deletedPointUUIDs.add(point.uuid);
|
||||||
|
});
|
||||||
|
} else if (state.points && 'uuid' in state.points) {
|
||||||
|
deletedPointUUIDs.add(state.points.uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const updatedStates = simulationStates.map((state) => {
|
||||||
// Handle Conveyor
|
// Handle Conveyor
|
||||||
if (state.type === "Conveyor") {
|
if (state.type === "Conveyor") {
|
||||||
const updatedConveyor: SimulationTypes.ConveyorEventsSchema = {
|
const updatedConveyor: SimulationTypes.ConveyorEventsSchema = {
|
||||||
@@ -1028,45 +1041,41 @@ function PathConnector({ pathsGroupRef, }: { pathsGroupRef: React.MutableRefObje
|
|||||||
...state.points,
|
...state.points,
|
||||||
connections: {
|
connections: {
|
||||||
...state.points.connections,
|
...state.points.connections,
|
||||||
|
|
||||||
targets: state.points.connections.targets.filter(
|
targets: state.points.connections.targets.filter(
|
||||||
(target: any) => !deletedModelUUIDs.includes(target.modelUUID)
|
(target: any) => !deletedModelUUIDs.includes(target.modelUUID)
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
...state.points.actions,
|
...state.points.actions,
|
||||||
processes: (state.points.actions.processes =
|
processes: state.points.actions.processes?.filter((process) => {
|
||||||
state.points.actions.processes?.filter((process) => {
|
// Check if trigger is from deleted model
|
||||||
const matchedStates = simulationStates.filter((s) =>
|
const matchedStates = simulationStates.filter((s) => deletedModelUUIDs.includes(s.modeluuid));
|
||||||
deletedModelUUIDs.includes(s.modeluuid)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (matchedStates.length > 0) {
|
if (matchedStates.length > 0) {
|
||||||
if (matchedStates[0]?.type === "StaticMachine") {
|
if (matchedStates[0]?.type === "StaticMachine") {
|
||||||
const trigPoints = matchedStates[0]?.points;
|
const trigPoints = matchedStates[0]?.points;
|
||||||
|
if (process.triggerId === trigPoints?.triggers?.uuid) {
|
||||||
return !(
|
return false;
|
||||||
process.triggerId === trigPoints?.triggers?.uuid
|
}
|
||||||
);
|
} else if (matchedStates[0]?.type === "Conveyor") {
|
||||||
} else if (matchedStates[0]?.type === "Conveyor") {
|
const trigPoints = matchedStates[0]?.points;
|
||||||
const trigPoints = matchedStates[0]?.points;
|
if (Array.isArray(trigPoints)) {
|
||||||
|
const nonEmptyTriggers = trigPoints.filter((point) => point && point.triggers && point.triggers.length > 0);
|
||||||
if (Array.isArray(trigPoints)) {
|
const allTriggerUUIDs = nonEmptyTriggers.flatMap((point) => point.triggers).map((trigger) => trigger.uuid);
|
||||||
const nonEmptyTriggers = trigPoints.filter(
|
if (allTriggerUUIDs.includes(process.triggerId)) {
|
||||||
(point) =>
|
return false;
|
||||||
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;
|
}
|
||||||
})),
|
|
||||||
|
// Check if startPoint or endPoint is from deleted model
|
||||||
|
if (deletedPointUUIDs.has(process.startPoint) || deletedPointUUIDs.has(process.endPoint)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -1076,9 +1085,7 @@ function PathConnector({ pathsGroupRef, }: { pathsGroupRef: React.MutableRefObje
|
|||||||
return state;
|
return state;
|
||||||
});
|
});
|
||||||
|
|
||||||
const filteredStates = updatedStates.filter(
|
const filteredStates = updatedStates.filter((state) => !deletedModelUUIDs.includes(state.modeluuid));
|
||||||
(state) => !deletedModelUUIDs.includes(state.modeluuid)
|
|
||||||
);
|
|
||||||
|
|
||||||
updateBackend(filteredStates);
|
updateBackend(filteredStates);
|
||||||
setSimulationStates(filteredStates);
|
setSimulationStates(filteredStates);
|
||||||
|
|||||||
Reference in New Issue
Block a user