ImportProgressClosure
ImportProgressClosure is a closure-backed conformance to OCCTSwift’s ImportProgress protocol. It lets you pass progress: to ShapeLoader.load / loadRobust as a closure instead of writing a one-shot subclass. STEP and IGES imports fire the callbacks; other formats don’t surface progress.
Topics
ImportProgressClosure.init(cancelCheck:progress:)
Creates a progress observer from a progress closure and an optional cancellation closure.
public init(
cancelCheck: @escaping @Sendable () -> Bool = { false },
progress: @escaping @Sendable (Double, String) -> Void
)
- Parameters:
cancelCheck— returntrueto cooperatively cancel the import. Defaults to{ false }. Common pattern:{ Task.isCancelled }to wire upstream Swift-task cancellation.progress— called withfractionin0.0...1.0and a human-readable step name (e.g."Reading STEP file").
- Note: callbacks fire on whatever thread the importer runs on (typically background when launched via the async
ShapeLoader.load). Hop to the main actor for UI updates. - Example:
let result = try await ShapeLoader.load( from: stepURL, format: .step, progress: ImportProgressClosure( cancelCheck: { Task.isCancelled }, progress: { fraction, step in Task { @MainActor in progressBar.doubleValue = fraction } } ) )
progress(fraction:step:)
ImportProgress protocol requirement; forwards to the stored progress closure.
public func progress(fraction: Double, step: String)
- Parameters:
fraction— completion in0.0...1.0;step— the current stage name.
shouldCancel()
ImportProgress protocol requirement; returns the result of the stored cancelCheck closure. When it returns true, the loader throws ImportError.cancelled.
public func shouldCancel() -> Bool