@bitbybit-dev/occt-worker
Version:
Bit By Bit Developers CAD algorithms using OpenCascade Technology kernel adapted for WebWorker
89 lines (88 loc) • 3.46 kB
TypeScript
/**
* Constants for OCCT worker communication and shape handling.
* These constants define the protocol between the main thread and the worker.
*/
/**
* Shape reference type identifier used in serialized shape objects.
* When shapes are passed between main thread and worker, they are serialized
* as objects with this type identifier and a hash reference.
*/
export declare const SHAPE_TYPE_IDENTIFIER: "occ-shape";
/**
* Entity reference type identifier used in serialized OCCT objects that are not shapes.
* This includes assembly documents, handles, and other OCCT objects.
* When these objects are passed between main thread and worker, they are serialized
* as objects with this type identifier and a hash reference.
*/
export declare const ENTITY_TYPE_IDENTIFIER: "occ-entity";
/**
* Worker lifecycle and status messages.
*/
export declare const WorkerMessages: {
/** Sent when the worker has completed initialization */
readonly INITIALIZED: "occ-initialised";
/** Sent when the worker is processing a request */
readonly BUSY: "busy";
};
/**
* Reserved function names that have special handling in the worker.
* These functions bypass the standard caching mechanism and have custom logic.
*/
export declare const ReservedFunctions: {
/** Convert a single shape to mesh data for rendering */
readonly SHAPE_TO_MESH: "shapeToMesh";
/** Convert multiple shapes to mesh data for rendering */
readonly SHAPES_TO_MESHES: "shapesToMeshes";
/** Delete a single shape from cache */
readonly DELETE_SHAPE: "deleteShape";
/** Delete multiple shapes from cache */
readonly DELETE_SHAPES: "deleteShapes";
/** Signal that a new run has started (used for cache cleanup) */
readonly STARTED_THE_RUN: "startedTheRun";
/** Clean all cached shapes */
readonly CLEAN_ALL_CACHE: "cleanAllCache";
/** Add OpenCascade dependencies/plugins */
readonly ADD_OC: "addOc";
/** Save shape to STEP file format */
readonly SAVE_SHAPE_STEP: "saveShapeSTEP";
};
/**
* Set of function names that should not go through the standard caching flow.
* These functions either handle their own caching or don't need caching.
*/
export declare const NON_CACHEABLE_FUNCTIONS: Set<string>;
/**
* Maximum number of cached hashes before triggering a full cache cleanup.
* This prevents memory issues from accumulating too many cached shapes.
*/
export declare const CACHE_THRESHOLD = 10000;
/**
* Type for a serialized shape reference that can be passed between threads.
*/
export interface ShapeReference {
type: typeof SHAPE_TYPE_IDENTIFIER;
hash: number | string;
}
/**
* Type guard to check if a value is a ShapeReference.
*/
export declare function isShapeReference(value: unknown): value is ShapeReference;
/**
* Creates a shape reference object for serialization.
*/
export declare function createShapeReference(hash: number | string): ShapeReference;
/**
* Type for a serialized entity reference (non-shape OCCT objects) that can be passed between threads.
*/
export interface EntityReference {
type: typeof ENTITY_TYPE_IDENTIFIER;
hash: number | string;
}
/**
* Type guard to check if a value is an EntityReference.
*/
export declare function isEntityReference(value: unknown): value is EntityReference;
/**
* Creates an entity reference object for serialization.
*/
export declare function createEntityReference(hash: number | string): EntityReference;