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