/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a // license agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// import { IHttpClient } from "./IHttpClient"; import { File } from "./File"; import { Assembly } from "./Assembly"; /** * The class representing the is a description of view of the file or assembly. For example, * for `dwg` it is a `Model` space or layout, and for `rvt` files it is a `3D` view. */ export class Model { private _data: any; private _file: File | Assembly; public httpClient: IHttpClient; public path: string; /** * @param data - An object that implements model data storage. * @param file - The `File` of 'Assembly' instance that owns the model. */ constructor(data: any, file: File | Assembly) { this.path = `${file.path}/downloads`; this.httpClient = file.httpClient; this._file = file; this._data = data; } /** * The `Assembly` instance that owns the model. * * @readonly */ get assembly(): Assembly { return this._file as Assembly; } /** * Raw model data received from the server. * * @readonly */ get data(): any { return this._data; } private set data(value: any) { this._data = value; } /** * Scene description file resource ID. Use {@link Model#downloadResource | downloadResource()} * to download scene description file. * * @readonly */ get database(): string { return this.data.database; } /** * `true` if this is default model. * * @readonly */ get default(): boolean { return this.data.default; } /** * The `File` instance that owns the model. * * @readonly */ get file(): File { return this._file as File; } /** * The ID of the file that owns the model. * * @readonly */ get fileId(): string { return this.data.fileId; } /** * The list of resource IDs for geometry data files. Use * {@link Model#downloadResource | downloadResource()} to download geometry data files. * * @readonly */ get geometry(): string[] { return this.data.geometry; } /** * Unique model ID. * * @readonly */ get id(): string { return this.data.id; } /** * Model name. * * @readonly */ get name(): string { return this.data.name; } // Reserved for future use. get version(): string { return this.data.version; } /** * Returns model viewpoint list. * * _**Note**: Assemblу models do not support viewpoints_. * * @async */ getViewpoints(): Promise { return this._file .getViewpoints() .then((array) => array.filter( ({ custom_fields = {} }) => custom_fields.modelId === this.id || custom_fields.modelName === this.name ) ); } /** * Add new model viewpoint. To create a new viewpoint use * {@link Viewer#createViewpoint | Viewer.createViewpoint()}. * * _**Note**: Assemblу models do not support viewpoints_. * * @async * @param viewpoint - Viewpoint. */ saveViewpoint(viewpoint: any): Promise { return this._file.saveViewpoint({ ...viewpoint, custom_fields: { ...viewpoint.custom_fields, modelId: this.id, modelName: this.name }, }); } /** * Delete model viewpoint. * * _**Note**: Assemblу models do not support viewpoints_. * * @async * @param guid - Viewpoint GUID. * @returns Returns the raw data of a deleted viewpoint. */ deleteViewpoint(guid: string): Promise { return this._file.deleteViewpoint(guid); } /** * Returns viewpoint preview image as Data URL. * * @async * @param guid - Viewpoint GIID. */ getSnapshot(guid: string): Promise { return this._file.getSnapshot(guid); } /** * Returns snapshot data. * * @async * @param guid - Viewpoint GUID. * @param bitmapGuid - Bitmap GUID. */ getSnapshotData(guid: string, bitmapGuid: string): Promise { return this._file.getSnapshotData(guid, bitmapGuid); } /** * Downloads model resource, such as scene description file or geometry data files. * * @async * @param resourceId - Resource ID. * @param onProgress - Download progress callback. * @param signal - An AbortSignal object instance. Allows to communicate with a fetch request * and abort it if desired. */ downloadResource( dataId: string, onProgress?: (progress: number) => void, signal?: AbortSignal ): Promise { return this._file.downloadResource(dataId, onProgress, signal); } // Internal download routines used by Viewer. partialDownloadResource( dataId: string, onProgress?: (progress: number, downloaded: Uint8Array) => void, signal?: AbortSignal ): Promise { return this._file.partialDownloadResource(dataId, onProgress, signal); } downloadFileRange( requestId: number, records: any | null, dataId: string, onProgress?: (progress: number, downloaded: Uint8Array, requestId: number) => void, signal?: AbortSignal ): Promise { return this._file.downloadFileRange(requestId, records, dataId, onProgress, signal); } /** * Returns a list of references to files used to extract geometry data. * * @async * @param [signal] - An AbortController * signal object instance, which can be used to abort waiting as desired. */ getReferences(signal?: AbortSignal) { return this._file.getReferences(signal); } }