import Foundation
|
|
public struct SpaceEnumerationRecord: Equatable, Sendable {
|
public let id: UInt64
|
public let cgsType: Int
|
public let displayUUID: String
|
|
public init(id: UInt64, cgsType: Int, displayUUID: String) {
|
self.id = id
|
self.cgsType = cgsType
|
self.displayUUID = displayUUID
|
}
|
}
|
|
public enum SpaceEnumerationPolicy {
|
public static let sharedDisplayUUID = "Main"
|
|
public static func spaceType(fromCGSType type: Int) -> AlignerSpaceType {
|
switch type {
|
case 0:
|
return .user
|
case 4:
|
return .fullscreen
|
default:
|
return .unknown(type)
|
}
|
}
|
|
public static func normalizedDisplays(
|
from records: [SpaceEnumerationRecord],
|
physicalDisplayUUIDs: Set<String> = []
|
) -> [AlignerDisplay] {
|
let grouped = Dictionary(grouping: records) { normalizedDisplayUUID($0.displayUUID) }
|
|
return grouped.keys.sorted().compactMap { displayUUID in
|
guard let records = grouped[displayUUID], !records.isEmpty else { return nil }
|
|
let spaces = records.enumerated().map { offset, record in
|
AlignerSpace(
|
id: record.id,
|
type: spaceType(fromCGSType: record.cgsType),
|
displayUUID: displayUUID,
|
index: offset + 1
|
)
|
}
|
|
return AlignerDisplay(
|
uuid: displayUUID,
|
physical: isPhysicalDisplay(displayUUID, physicalDisplayUUIDs: physicalDisplayUUIDs),
|
spaces: spaces
|
)
|
}
|
}
|
|
private static func normalizedDisplayUUID(_ displayUUID: String) -> String {
|
displayUUID.isEmpty ? sharedDisplayUUID : displayUUID
|
}
|
|
private static func isPhysicalDisplay(_ displayUUID: String, physicalDisplayUUIDs: Set<String>) -> Bool {
|
physicalDisplayUUIDs.isEmpty || physicalDisplayUUIDs.contains(displayUUID)
|
}
|
}
|