Merge remote-tracking branch 'origin/simulation' into rtViz
This commit is contained in:
commit
939f6e5086
|
@ -199,14 +199,12 @@ const SelectionControls: React.FC = () => {
|
|||
setDuplicatedObjects([]);
|
||||
setSelectedAssets([]);
|
||||
};
|
||||
|
||||
const updateBackend = async (updatedPaths: (SimulationTypes.ConveyorEventsSchema | SimulationTypes.VehicleEventsSchema | SimulationTypes.StaticMachineEventsSchema | SimulationTypes.ArmBotEventsSchema)[]) => {
|
||||
if (updatedPaths.length === 0) return;
|
||||
const email = localStorage.getItem("email");
|
||||
const organization = email ? email.split("@")[1].split(".")[0] : "";
|
||||
|
||||
updatedPaths.forEach(async (updatedPath) => {
|
||||
|
||||
if (updatedPath.type === "Conveyor") {
|
||||
// await setEventApi(
|
||||
// organization,
|
||||
|
@ -225,9 +223,7 @@ const SelectionControls: React.FC = () => {
|
|||
};
|
||||
|
||||
socket.emit("v2:model-asset:updateEventData", data);
|
||||
|
||||
} else if (updatedPath.type === "Vehicle") {
|
||||
|
||||
// await setEventApi(
|
||||
// organization,
|
||||
// updatedPath.modeluuid,
|
||||
|
@ -241,9 +237,7 @@ const SelectionControls: React.FC = () => {
|
|||
};
|
||||
|
||||
socket.emit("v2:model-asset:updateEventData", data);
|
||||
|
||||
} else if (updatedPath.type === "StaticMachine") {
|
||||
|
||||
// await setEventApi(
|
||||
// organization,
|
||||
// updatedPath.modeluuid,
|
||||
|
@ -257,9 +251,7 @@ const SelectionControls: React.FC = () => {
|
|||
};
|
||||
|
||||
socket.emit("v2:model-asset:updateEventData", data);
|
||||
|
||||
} else if (updatedPath.type === "ArmBot") {
|
||||
|
||||
// await setEventApi(
|
||||
// organization,
|
||||
// updatedPath.modeluuid,
|
||||
|
@ -274,239 +266,118 @@ const SelectionControls: React.FC = () => {
|
|||
|
||||
socket.emit("v2:model-asset:updateEventData", data);
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
// 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;
|
||||
}
|
||||
});
|
||||
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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
// ArmBot type
|
||||
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)
|
||||
);
|
||||
// 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 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;
|
||||
}
|
||||
|
||||
return shouldInclude ? [state] : [];
|
||||
// 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 = () => {
|
||||
|
@ -552,65 +423,17 @@ const SelectionControls: React.FC = () => {
|
|||
});
|
||||
|
||||
setSimulationStates((prevEvents: (| SimulationTypes.ConveyorEventsSchema | SimulationTypes.VehicleEventsSchema | SimulationTypes.StaticMachineEventsSchema | SimulationTypes.ArmBotEventsSchema)[]) => {
|
||||
const updatedEvents = (prevEvents || []).filter(
|
||||
(event) => event.modeluuid !== selectedMesh.uuid
|
||||
);
|
||||
const updatedEvents = (prevEvents || []).filter((event) => event.modeluuid !== selectedMesh.uuid);
|
||||
return updatedEvents;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
itemsGroupRef.current?.remove(selectedMesh);
|
||||
});
|
||||
|
||||
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(
|
||||
(item: { modeluuid: string }) => !selectedUUIDs.includes(item.modeluuid)
|
||||
);
|
||||
const updatedItems = floorItems.filter((item: { modeluuid: string }) => !selectedUUIDs.includes(item.modeluuid));
|
||||
setFloorItems(updatedItems);
|
||||
}
|
||||
toast.success("Selected models removed!");
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue