@mlightcad/libredwg-web
Version:
A DWG/DXF JavaScript parser based on libredwg
925 lines • 38.4 kB
JavaScript
import createModule from '../wasm/libredwg-web.js';
import { LibreDwgConverter } from './converter';
import { dwgCodePageToEncoding, dwgVersions } from './database';
import { SvgConverter } from './svg';
import { Dwg_File_Type, Dwg_Object_Type } from './types';
export { createModule };
export var DwgThumbnailImageType;
(function (DwgThumbnailImageType) {
DwgThumbnailImageType[DwgThumbnailImageType["BMP"] = 2] = "BMP";
DwgThumbnailImageType[DwgThumbnailImageType["WMF"] = 3] = "WMF";
DwgThumbnailImageType[DwgThumbnailImageType["PNG"] = 6] = "PNG";
})(DwgThumbnailImageType || (DwgThumbnailImageType = {}));
export class LibreDwg {
static instance;
wasmInstance;
decoder;
constructor(wasmInstance) {
this.wasmInstance = wasmInstance;
return new Proxy(this, {
get: (target, prop, receiver) => {
if (prop in target) {
return Reflect.get(target, prop, receiver);
}
// Delegate to the wasmInstance for WebAssembly methods
return Reflect.get(target.wasmInstance, prop, receiver);
}
});
}
dwg_read_data(fileContent, fileType) {
if (fileType == Dwg_File_Type.DWG) {
const fileName = 'tmp.dwg';
this.wasmInstance.FS.writeFile(fileName, new Uint8Array(fileContent));
const result = this.wasmInstance.dwg_read_file(fileName);
if (result.error != 0) {
console.log('Open dwg file with error code: ', result.error);
}
this.wasmInstance.FS.unlink(fileName);
return result.data;
}
// else if (fileType == Dwg_File_Type.DXF) {
// const fileName = "tmp.dxf";
// this.wasmInstance.FS.writeFile(fileName, new Uint8Array(fileContent as ArrayBuffer));
// const result = this.wasmInstance.dxf_read_file(fileName);
// if (result.error != 0) {
// console.log('Open dxf file with error code: ', result.error);
// }
// this.wasmInstance.FS.unlink(fileName);
// return result.data as Dwg_Data_Ptr;
// }
}
/**
* Gets the version of the dwg.
* @param data Pointer to Dwg_Data instance.
* @returns Return the version of the dwg
*/
dwg_get_version_type(data) {
const version = this.wasmInstance.dwg_get_version_type(data);
return dwgVersions[version];
}
/**
* Gets code page of the dwg.
* @param data Pointer to Dwg_Data instance.
* @returns Return code page of the dwg
*/
dwg_get_codepage(data) {
const codepage = this.wasmInstance.dwg_get_codepage(data);
return codepage;
}
/**
* Extracts thumbnail image from dwg.
* @param data Pointer to Dwg_Data instance.
* @returns Return thumbnail image data
*/
dwg_bmp(data) {
return this.wasmInstance.dwg_bmp(data);
}
/**
* Returns the number of classes in dwg file.
* @param data Pointer to Dwg_Data instance.
* @returns Returns the number of classes in dwg file.
*/
dwg_get_num_classes(data) {
return this.wasmInstance.dwg_get_num_classes(data);
}
/**
* Returns the nth class in dwg file.
* @param data Pointer to Dwg_Data instance.
* @param index Index of the class
* @returns Returns the nth class in dwg file.
*/
dwg_get_class(data, index) {
return this.wasmInstance.dwg_get_class(data, index);
}
/**
* Converts Dwg_Data instance to DwgDatabase instance. DwgDatabase instance doesn't depend on
* Dwg_Data instance any more after conversion. So you can call function dwg_free to free memory
* occupied by Dwg_Data.
* @param data Pointer to Dwg_Data instance.
* @returns Returns the converted DwgDatabase.
*/
convert(data) {
const codepage = this.dwg_get_codepage(data);
const encoding = dwgCodePageToEncoding(codepage);
this.decoder = new TextDecoder(encoding);
const converter = new LibreDwgConverter(this);
return converter.convert(data);
}
/**
* Converts Dwg_Data instance to DwgDatabase instance and returns conversion statistics.
* DwgDatabase instance doesn't depend on Dwg_Data instance any more after conversion.
* So you can call function dwg_free to free memory occupied by Dwg_Data.
* @param data Pointer to Dwg_Data instance.
* @returns Returns the converted DwgDatabase and conversion statistics.
*/
convertEx(data) {
const codepage = this.dwg_get_codepage(data);
const encoding = dwgCodePageToEncoding(codepage);
this.decoder = new TextDecoder(encoding);
const converter = new LibreDwgConverter(this);
return {
database: converter.convert(data),
stats: converter.getConversionStats()
};
}
/**
* Converts DwgDatabase instance to svg string.
* @param data DwgDatabase instance.
* @returns Returns the converted svg string.
*/
dwg_to_svg(data) {
const converter = new SvgConverter();
return converter.convert(data);
}
/**
* Frees the whole DWG. all tables, sections, objects, ...
* @param data Pointer to Dwg_Data instance.
*/
dwg_free(data) {
this.wasmInstance.dwg_free(data);
}
/**
* Frees the object (all three structs and its fields)
* @group Dwg_Object Methods
* @param ptr Pointer to one Dwg_Object instance.
*/
dwg_free_object(obj_ptr) {
this.wasmInstance.dwg_free_object(obj_ptr);
}
/**
* Gets an object by its handle.
* @group Handle Conversion Methods
* @param data Pointer to Dwg_Data instance.
* @param ref_ptr Pointer to Dwg_Object_Ref instance.
* @returns Returns the object whose handle is equal to the given handle.
*/
dwg_ref_object(data, ref_ptr) {
return this.wasmInstance.dwg_ref_object(data, ref_ptr);
}
/**
* Gets an object by its handle without warning message.
* @group Handle Conversion Methods
* @param data Pointer to Dwg_Data instance.
* @param ref_ptr Pointer to Dwg_Object_Ref instance.
* @returns Returns the object whose handle is equal to the given handle.
*/
dwg_ref_object_silent(data, ref_ptr) {
return this.wasmInstance.dwg_ref_object_silent(data, ref_ptr);
}
/**
* Gets an object given its handle and relative base object.
* @group Handle Conversion Methods
* @param data Pointer to Dwg_Data instance.
* @param ref_ptr Pointer to Dwg_Object_Ref instance.
* @param obj_ptr Pointer to the relative base object (Dwg_Object instance).
* @returns Returns the object given its handle and relative base object.
*/
dwg_ref_object_relative(data, ref_ptr, obj_ptr) {
return this.wasmInstance.dwg_ref_object_relative(data, ref_ptr, obj_ptr);
}
/**
* Resolves handle absref value to Dwg_Object instance.
* @group Handle Conversion Methods
* @param data Pointer to Dwg_Data instance.
* @param absref Handle absref value.
* @returns Returns the object with the given handle absref value.
*/
dwg_resolve_handle(data, absref) {
return this.wasmInstance.dwg_resolve_handle(data, absref);
}
/**
* Resolves handle absref value to Dwg_Object instance without warning message.
* @group Handle Conversion Methods
* @param data Pointer to Dwg_Data instance.
* @param absref Handle absref value.
* @returns Returns the object with the given handle absref value.
*/
dwg_resolve_handle_silent(data, absref) {
return this.wasmInstance.dwg_resolve_handle_silent(data, absref);
}
/**
* Sets ref->absolute_ref from the specified obj for a subsequent dwg_resolve_handle
* @group Handle Conversion Methods
* @param ref_ptr Pointer to Dwg_Object_Ref instance.
* @param obj_ptr Pointer to Dwg_Object instance.
* @returns Returns 1 if set absref value correctly. Otherwise, return 0.
*/
dwg_resolve_handleref(ref_ptr, obj_ptr) {
return this.wasmInstance.dwg_resolve_handleref(ref_ptr, obj_ptr);
}
/**
* Returns object (such as line type, layer name, dimension style, and etc.) name by its handle.
* @group Handle Conversion Methods
* @param ref_ptr Pointer to Dwg_Object_Ref instance.
* @returns Returns object name by its handle.
*/
dwg_ref_get_object_name(ref_ptr) {
const wasmInstance = this.wasmInstance;
const obj = wasmInstance.dwg_ref_get_object(ref_ptr);
const obj_tio = wasmInstance.dwg_object_to_object_tio(obj);
const obj_name = this.dwg_dynapi_entity_value(obj_tio, 'name')
.data;
return obj_name;
}
/**
* Converts Dwg_Object_Object instance to Dwg_Object instance.
* @group Object Conversion Methods
* @param obj_ptr Pointer to Dwg_Object_Object instance.
* @returns Returns one pointer to Dwg_Object instance.
*/
dwg_obj_obj_to_object(obj_obj_ptr) {
return this.wasmInstance.dwg_obj_obj_to_object(obj_obj_ptr);
}
/**
* Converts Dwg_Object_* instance to Dwg_Object instance.
* @group Object Conversion Methods
* @param obj_generic_ptr Pointer to Dwg_Object_* instance.
* @returns Returns one pointer to Dwg_Object instance.
*/
dwg_obj_generic_to_object(obj_generic_ptr) {
return this.wasmInstance.dwg_obj_generic_to_object(obj_generic_ptr);
}
/**
* Converts Dwg_Object instance to Dwg_Object_Object instance.
* @group Object Conversion Methods
* @param obj_ptr Pointer to Dwg_Object instance.
* @returns Returns one pointer to Dwg_Object_Object instance.
*/
dwg_object_to_object(obj_ptr) {
return this.wasmInstance.dwg_object_to_object(obj_ptr);
}
/**
* Gets Dwg_Object_* instance (such as Dwg_Entity_LAYER, Dwg_Entity_STYLE, and etc.)
* from Dwg_Object instance.
* @group Object Conversion Methods
* @param obj_ptr Pointer to Dwg_Object instance.
* @returns Returns one pointer to Dwg_Object_Object_TIO_Ptr instance.
*/
dwg_object_to_object_tio(obj_ptr) {
return this.wasmInstance.dwg_object_to_object_tio(obj_ptr);
}
/**
* Converts Dwg_Object instance to Dwg_Object_Entity instance.
* @group Object Conversion Methods
* @param obj_ptr Pointer to Dwg_Object instance.
* @returns Returns one pointer to Dwg_Object_Entity instance.
*/
dwg_object_to_entity(obj_ptr) {
return this.wasmInstance.dwg_object_to_entity(obj_ptr);
}
/**
* Gets Dwg_Entity_* instance (such as Dwg_Entity_LINE, Dwg_Entity_SPLINE, and etc.)
* from Dwg_Object instance.
* @group Object Conversion Methods
* @param obj_ptr Pointer to Dwg_Object instance.
* @returns Returns one pointer to Dwg_Object_Object_TIO_Ptr instance.
*/
dwg_object_to_entity_tio(obj_ptr) {
return this.wasmInstance.dwg_object_to_entity_tio(obj_ptr);
}
/**
* Returns all of entities in the model space. Each item in returned array
* is one Dwg_Object pointer (Dwg_Object*).
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of entities in the model space.
*/
dwg_getall_entities_in_model_space(data) {
const wasmInstance = this.wasmInstance;
const model_space = wasmInstance.dwg_model_space_object(data);
const entities = [];
let next = wasmInstance.get_first_owned_entity(model_space);
while (next) {
entities.push(next);
next = wasmInstance.get_next_owned_entity(model_space, next);
}
return entities;
}
/**
* Returns all of objects in Dwg_Data instance with the specified type.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @param type Object type.
* @returns Returns all of objects with the specified type.
*/
dwg_getall_object_by_type(data, type) {
const wasmInstance = this.wasmInstance;
const num_objects = wasmInstance.dwg_get_num_objects(data);
const results = [];
for (let i = 0; i < num_objects; i++) {
const obj = wasmInstance.dwg_get_object(data, i);
const tio = wasmInstance.dwg_object_to_object_tio(obj);
if (tio && wasmInstance.dwg_object_get_fixedtype(obj) == type) {
results.push(tio);
}
}
return results;
}
/**
* Returns all of objects in Dwg_Data instance with the specified type.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @param type Object type.
* @returns Returns all of objects with the specified type.
*/
dwg_getall_entity_by_type(data, type) {
const wasmInstance = this.wasmInstance;
const num_objects = wasmInstance.dwg_get_num_objects(data);
const results = [];
for (let i = 0; i < num_objects; i++) {
const obj = wasmInstance.dwg_get_object(data, i);
const tio = wasmInstance.dwg_object_to_entity_tio(obj);
if (tio && wasmInstance.dwg_object_get_fixedtype(obj) == type) {
results.push(tio);
}
}
return results;
}
/**
* Returns all of layer objects in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of layer objects in Dwg_Data instance.
*/
dwg_getall_LAYER(data) {
return this.dwg_getall_object_by_type(data, Dwg_Object_Type.DWG_TYPE_LAYER);
}
/**
* Returns all of line type objects in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of line type objects in Dwg_Data instance.
*/
dwg_getall_LTYPE(data) {
return this.dwg_getall_object_by_type(data, Dwg_Object_Type.DWG_TYPE_LTYPE);
}
/**
* Returns all of text style objects in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of text style objects in Dwg_Data instance.
*/
dwg_getall_STYLE(data) {
return this.dwg_getall_object_by_type(data, Dwg_Object_Type.DWG_TYPE_STYLE);
}
/**
* Returns all of dimension style objects in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of dimension style objects in Dwg_Data instance.
*/
dwg_getall_DIMSTYLE(data) {
return this.dwg_getall_object_by_type(data, Dwg_Object_Type.DWG_TYPE_DIMSTYLE);
}
/**
* Returns all of viewport objects in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of viewport objects in Dwg_Data instance.
*/
dwg_getall_VPORT(data) {
return this.dwg_getall_object_by_type(data, Dwg_Object_Type.DWG_TYPE_VPORT);
}
/**
* Returns all of layout objects in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of layout objects in Dwg_Data instance.
*/
dwg_getall_LAYOUT(data) {
return this.dwg_getall_object_by_type(data, Dwg_Object_Type.DWG_TYPE_LAYOUT);
}
/**
* Returns all of block objects in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of block objects in Dwg_Data instance.
*/
dwg_getall_BLOCK(data) {
return this.dwg_getall_object_by_type(data, Dwg_Object_Type.DWG_TYPE_BLOCK);
}
/**
* Returns all of block header objects in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of block header objects in Dwg_Data instance.
*/
dwg_getall_BLOCK_HEADER(data) {
return this.dwg_getall_object_by_type(data, Dwg_Object_Type.DWG_TYPE_BLOCK_HEADER);
}
/**
* Returns all of image definition objects in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of image definition objects in Dwg_Data instance.
*/
dwg_getall_IMAGEDEF(data) {
return this.dwg_getall_object_by_type(data, Dwg_Object_Type.DWG_TYPE_IMAGEDEF);
}
/**
* Returns all of 2d vertex objects in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of 2d vertex objects in Dwg_Data instance.
*/
dwg_getall_VERTEX_2D(data) {
return this.dwg_getall_entity_by_type(data, Dwg_Object_Type.DWG_TYPE_VERTEX_2D);
}
/**
* Returns all of 3d vertex objects in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of 3d vertex objects in Dwg_Data instance.
*/
dwg_getall_VERTEX_3D(data) {
return this.dwg_getall_entity_by_type(data, Dwg_Object_Type.DWG_TYPE_VERTEX_3D);
}
/**
* Returns all of 2d polyline entities in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of 2d polyline entities in Dwg_Data instance.
*/
dwg_getall_POLYLINE_2D(data) {
return this.dwg_getall_entity_by_type(data, Dwg_Object_Type.DWG_TYPE_POLYLINE_2D);
}
/**
* Returns all of 3d polyline entities in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of 3d polyline entities in Dwg_Data instance.
*/
dwg_getall_POLYLINE_3D(data) {
return this.dwg_getall_entity_by_type(data, Dwg_Object_Type.DWG_TYPE_POLYLINE_3D);
}
/**
* Returns all of image entities in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of image entities in Dwg_Data instance.
*/
dwg_getall_IMAGE(data) {
return this.dwg_getall_entity_by_type(data, Dwg_Object_Type.DWG_TYPE_IMAGE);
}
/**
* Returns all of lwpolyline entities in Dwg_Data instance.
* @group GetAll Methods
* @param data Pointer to Dwg_Data instance.
* @returns Returns all of lwpolyline entities in Dwg_Data instance.
*/
dwg_getall_LWPOLYLINE(data) {
return this.dwg_getall_entity_by_type(data, Dwg_Object_Type.DWG_TYPE_LWPOLYLINE);
}
/**
* Converts one C++ unsigned char array to one JavaScript number array.
* @group Array Methods
* @param ptr Pointer to C++ unsigned char array.
* @param size The size of C++ unsigned char array.
* @returns Returns one JavaScript number array from the specified C++ unsigned char array.
*/
dwg_ptr_to_unsigned_char_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_unsigned_char_array(ptr, size);
}
/**
* Converts one C++ signed char array to one JavaScript number array.
* @group Array Methods
* @param ptr Pointer to C++ signed char array.
* @param size The size of C++ signed char array.
* @returns Returns one JavaScript number array from the specified C++ signed char array.
*/
dwg_ptr_to_signed_char_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_signed_char_array(ptr, size);
}
/**
* Converts one C++ unsigned int16 array to one JavaScript number array.
* @group Array Methods
* @param ptr Pointer to C++ unsigned int16 array.
* @param size The size of C++ unsigned int16 array.
* @returns Returns one JavaScript number array from the specified C++ unsigned int16 array.
*/
dwg_ptr_to_uint16_t_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_uint16_t_array(ptr, size);
}
/**
* Converts one C++ int16 array to one JavaScript number array.
* @group Array Methods
* @param ptr Pointer to C++ int16 array.
* @param size The size of C++ int16 array.
* @returns Returns one JavaScript number array from the specified C++ int16 array.
*/
dwg_ptr_to_int16_t_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_int16_t_array(ptr, size);
}
/**
* Converts one C++ unsigned int32 array to one JavaScript number array.
* @group Array Methods
* @param ptr Pointer to C++ unsigned int32 array.
* @param size The size of C++ unsigned int32 array.
* @returns Returns one JavaScript number array from the specified C++ unsigned int32 array.
*/
dwg_ptr_to_uint32_t_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_uint32_t_array(ptr, size);
}
/**
* Converts one C++ int32 array to one JavaScript number array.
* @group Array Methods
* @param ptr Pointer to C++ int32 array.
* @param size The size of C++ int32 array.
* @returns Returns one JavaScript number array from the specified C++ int32 array.
*/
dwg_ptr_to_int32_t_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_int32_t_array(ptr, size);
}
/**
* Converts one C++ unsigned int64 array to one JavaScript number array.
* @group Array Methods
* @param ptr Pointer to C++ unsigned int64 array.
* @param size The size of C++ unsigned int64 array.
* @returns Returns one JavaScript number array from the specified C++ unsigned int64 array.
*/
dwg_ptr_to_uint64_t_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_uint64_t_array(ptr, size);
}
/**
* Converts one C++ int64 array to one JavaScript number array.
* @group Array Methods
* @param ptr Pointer to C++ int64 array.
* @param size The size of C++ int64 array.
* @returns Returns one JavaScript number array from the specified C++ int64 array.
*/
dwg_ptr_to_int64_t_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_int64_t_array(ptr, size);
}
/**
* Converts one C++ double array to one JavaScript number array.
* @group Array Methods
* @param ptr Pointer to C++ double array.
* @param size The size of C++ double array.
* @returns Returns one JavaScript number array from the specified C++ double array.
*/
dwg_ptr_to_double_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_double_array(ptr, size);
}
/**
* Converts one C++ 2d point array to one JavaScript 2d point array.
* @group Array Methods
* @param ptr Pointer to C++ 2d point array.
* @param size The size of C++ 2 point array.
* @returns Returns one JavaScript 2d point array from the specified C++ 2d point array.
*/
dwg_ptr_to_point2d_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_point2d_array(ptr, size);
}
/**
* Converts one C++ 3d point array to one JavaScript 3d point array.
* @group Array Methods
* @param ptr Pointer to C++ 3d point array.
* @param size The size of C++ 3d point array.
* @returns Returns one JavaScript 3d point array from the specified C++ 3d point array.
*/
dwg_ptr_to_point3d_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_point3d_array(ptr, size);
}
/**
* Converts one C++ 4d point array to one JavaScript 4d point array.
* @group Array Methods
* @param ptr Pointer to C++ 4d point array.
* @param size The size of C++ 4d point array.
* @returns Returns one JavaScript 4d point array from the specified C++ 4d point array.
*/
dwg_ptr_to_point4d_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_point4d_array(ptr, size);
}
/**
* Converts one C++ line type array to one JavaScript line type array.
* @group Array Methods
* @param ptr Pointer to C++ line type array.
* @param size The size of C++ line type array.
* @returns Returns one JavaScript line type array from the specified C++ line type array.
*/
dwg_ptr_to_ltype_dash_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_ltype_dash_array(ptr, size);
}
/**
* Converts one C++ table cell array to one JavaScript table cell array.
* @group Array Methods
* @group Dwg_Entity_TABLE Methods
* @param ptr Pointer to C++ table cell array.
* @param size The size of C++ table cell array.
* @returns Returns one JavaScript table cell array from the specified C++ table cell array.
*/
dwg_ptr_to_table_cell_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_table_cell_array(ptr, size);
}
/**
* Converts one C++ hatch definition line array to one JavaScript hatch definition line array.
* @group Array Methods
* @group Dwg_Entity_HATCH Methods
* @param ptr Pointer to C++ hatch definition line array.
* @param size The size of C++ hatch definition line array.
* @returns Returns one JavaScript hatch definition line array from the specified C++ hatch definition line array.
*/
dwg_ptr_to_hatch_defline_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_hatch_defline_array(ptr, size);
}
/**
* Converts one C++ hatch path array to one JavaScript hatch path array.
* @group Array Methods
* @group Dwg_Entity_HATCH Methods
* @param ptr Pointer to C++ hatch path array.
* @param size The size of C++ hatch path array.
* @returns Returns one JavaScript hatch path array from the specified C++ hatch path array.
*/
dwg_ptr_to_hatch_path_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_hatch_path_array(ptr, size);
}
/**
* Converts one C++ mline vertex array to one JavaScript mline vertex array.
* @group Array Methods
* @group Dwg_Entity_MLINE Methods
* @param ptr Pointer to C++ mline vertex array.
* @param size The size of C++ mline vertex array.
* @returns Returns one JavaScript mline vertex array from the specified C++ mline vertex array.
*/
dwg_ptr_to_mline_vertex_array(ptr, size) {
return this.wasmInstance.dwg_ptr_to_mline_vertex_array(ptr, size);
}
/**
* Generic field value getter. Used to get the field value of one object or entity.
* @group Dynamic API Methods
* @param obj Pointer to one object or entity
* @param field Field name of one object or entity
* @returns Returns the field value of one object or entity.
*/
dwg_dynapi_entity_value(obj, field) {
const value = this.wasmInstance.dwg_dynapi_entity_value(obj, field);
if (value.bin && this.decoder) {
value.data = this.decoder.decode(value.bin);
}
return value;
}
/**
* Header field value getter. Used to get the field value of dwg/dxf header.
* @group Dynamic API Methods
* @param data Pointer to Dwg_Data instance.
* @param field Field name of header.
* @returns Returns the field value of dwg/dxf header.
*/
dwg_dynapi_header_value(data, field) {
return this.wasmInstance.dwg_dynapi_header_value(data, field);
}
/**
* The common field value getter. Used to get the value of object or entity common fields.
* @group Dynamic API Methods
* @param obj Pointer to one object or entity
* @param field The name of object or entity common fields.
* @returns Returns the value of object or entity common fields.
*/
dwg_dynapi_common_value(obj, field) {
return this.wasmInstance.dwg_dynapi_common_value(obj, field);
}
/**
* The field of one object or entity may not be primitive type. It means one field may consist of
* multiple sub-fields. This method is used to get the sub-field value of those complex field.
* @group Dynamic API Methods
* @param obj Pointer to one object or entity.
* @param subclass The class name of the field with complex type.
* @param field The field name of one object or entit.
* @returns Returns the sub-field value of one complex field.
*/
dwg_dynapi_subclass_value(obj, subclass, field) {
return this.wasmInstance.dwg_dynapi_subclass_value(obj, subclass, field);
}
/**
* Returns the handle of one Dwg_Object instance.
* @group Dwg_Object Methods
* @param ptr Pointer to one Dwg_Object instance.
* @returns Returns the handle of one Dwg_Object instance.
*/
dwg_object_get_handle_object(ptr) {
return this.wasmInstance.dwg_object_get_handle_object(ptr);
}
/**
* Returns the handle of one Dwg_Object_Object instance.
* @group Dwg_Object_Object Methods
* @param ptr Pointer to one Dwg_Object_Object instance.
* @returns Returns the handle of one Dwg_Object_Object instance.
*/
dwg_object_object_get_handle_object(ptr) {
return this.wasmInstance.dwg_object_object_get_handle_object(ptr);
}
/**
* Returns the owner handle of one Dwg_Object_Object instance.
* @group Dwg_Object_Object Methods
* @param ptr Pointer to one Dwg_Object_Object instance.
* @returns Returns the owner handle of one Dwg_Object_Object instance.
*/
dwg_object_object_get_ownerhandle_object(ptr) {
return this.wasmInstance.dwg_object_object_get_ownerhandle_object(ptr);
}
/**
* Returns the handle of one Dwg_Object_Entity instance.
* @group Dwg_Object_Entity Methods
* @param ptr Pointer to one Dwg_Object_Entity instance.
* @returns Returns the handle of one Dwg_Object_Entity instance.
*/
dwg_object_entity_get_handle_object(ptr) {
return this.wasmInstance.dwg_object_entity_get_handle_object(ptr);
}
/**
* Returns the owner handle of one Dwg_Object_Entity instance.
* @group Dwg_Object_Entity Methods
* @param ptr Pointer to one Dwg_Object_Entity instance.
* @returns Returns the owner handle of one Dwg_Object_Entity instance.
*/
dwg_object_entity_get_ownerhandle_object(ptr) {
return this.wasmInstance.dwg_object_entity_get_ownerhandle_object(ptr);
}
/**
* Returns the layer handle of one Dwg_Object_Entity instance.
* @group Dwg_Object_Entity Methods
* @param ptr Pointer to one Dwg_Object_Entity instance.
* @returns Returns the layer handle of one Dwg_Object_Entity instance.
*/
dwg_object_entity_get_layer_object_ref(ptr) {
return this.wasmInstance.dwg_object_entity_get_layer_object_ref(ptr);
}
/**
* Returns the line type handle of one Dwg_Object_Entity instance.
* @group Dwg_Object_Entity Methods
* @param ptr Pointer to one Dwg_Object_Entity instance.
* @returns Returns the line type handle of one Dwg_Object_Entity instance.
*/
dwg_object_entity_get_ltype_object_ref(ptr) {
return this.wasmInstance.dwg_object_entity_get_ltype_object_ref(ptr);
}
/**
* Returns color value of one Dwg_Object_Entity instance.
* @group Dwg_Object_Entity Methods
* @param ptr Pointer to one Dwg_Object_Entity instance.
* @returns Returns color value of one Dwg_Object_Entity instance.
*/
dwg_object_entity_get_color_object(ptr) {
return this.wasmInstance.dwg_object_entity_get_color_object(ptr);
}
/**
* Returns block name of one Dwg_Entity_* instance with one block field. For example,
* dimension entities have one 'block' field which represents the block that contains
* the entities that make up the dimension picture.
* @group Dwg_Entity_* Methods
* @param ptr Pointer to one Dwg_Entity_* instance with one block field.
* @param field Field name of the block.
* @returns Returns block name of one Dwg_Entity_* instance.
*/
dwg_entity_get_block_name(ptr, field) {
const wasmInstance = this.wasmInstance;
const block_header_ref = wasmInstance.dwg_dynapi_entity_value(ptr, field)
.data;
const block_header_obj = wasmInstance.dwg_ref_get_object(block_header_ref);
const block_header_tio = wasmInstance.dwg_object_to_object_tio(block_header_obj);
const block = this.dwg_entity_block_header_get_block(block_header_tio);
return block.name;
}
/**
* Returns dimension style name of one Dwg_Entity_* instance with one dimension style
* field.
* @group Dwg_Entity_* Methods
* @param ptr Pointer to one Dwg_Entity_* instance.
* @param field Field name of the dimension style.
* @returns Returns dimension style name of one Dwg_Entity_* instance.
*/
dwg_entity_get_dimstyle_name(ptr, field = 'dimstyle') {
const wasmInstance = this.wasmInstance;
const dimstyle_ref = wasmInstance.dwg_dynapi_entity_value(ptr, field)
.data;
const dimstyle_obj = wasmInstance.dwg_ref_get_object(dimstyle_ref);
const dimstyle_tio = wasmInstance.dwg_object_to_object_tio(dimstyle_obj);
const dimstyle_name = this.dwg_dynapi_entity_value(dimstyle_tio, 'name')
.data;
return dimstyle_name;
}
/**
* Returns block entity pointed by the specified block header.
* @group Dwg_Entity_BLOCK_HEADER Methods
* @param ptr Pointer to one Dwg_Entity_BLOCK_HEADER instance.
* @returns Returns block entity pointed by the specified block header.
*/
dwg_entity_block_header_get_block(ptr) {
const wasmInstance = this.wasmInstance;
const block_ref = wasmInstance.dwg_dynapi_entity_value(ptr, 'block_entity')
.data;
const block_obj = wasmInstance.dwg_ref_get_object(block_ref);
const block_tio = wasmInstance.dwg_object_to_entity_tio(block_obj);
const name = wasmInstance.dwg_dynapi_entity_value(block_tio, 'name')
.data;
const base_pt = wasmInstance.dwg_dynapi_entity_value(block_tio, 'base_pt')
.data;
return {
name,
base_pt // preR13 only
};
}
/**
* Returns preview image of the block pointed by the specified block header.
* @group Dwg_Entity_BLOCK_HEADER Methods
* @param ptr Pointer to one Dwg_Entity_BLOCK_HEADER instance.
* @returns Returns preview image of the block pointed by the specified block header.
*/
dwg_entity_block_header_get_preview(ptr) {
const wasmInstance = this.wasmInstance;
return wasmInstance.dwg_entity_block_header_get_preview(ptr)
.data;
}
/**
* Returns the first entity owned by the block header or null
* @group Dwg_Entity_BLOCK_HEADER Methods
* @param ptr Pointer to the block header.
* @returns Returns the first entity owned by the block header or null
*/
get_first_owned_entity(ptr) {
return this.wasmInstance.get_first_owned_entity(ptr);
}
/**
* Returns the next entity owned by the block header or null.
* @group Dwg_Entity_BLOCK_HEADER Methods
* @param ptr Pointer to the block header.
* @param current Pointer to the current entity in the block header.
* @returns Returns the next entity owned by the block header or null.
*/
get_next_owned_entity(ptr, current) {
return this.wasmInstance.get_next_owned_entity(ptr, current);
}
/**
* Returns text style name of one Dwg_Entity_MTEXT instance.
* @group Dwg_Entity_MTEXT Methods
* @param ptr Pointer to one Dwg_Entity_MTEXT instance.
* @returns Returns text style name of one Dwg_Entity_MTEXT instance.
*/
dwg_entity_mtext_get_style_name(ptr) {
const wasmInstance = this.wasmInstance;
const style_ref = wasmInstance.dwg_dynapi_entity_value(ptr, 'style')
.data;
const style_obj = wasmInstance.dwg_ref_get_object(style_ref);
const style_tio = wasmInstance.dwg_object_to_object_tio(style_obj);
const name = wasmInstance.dwg_dynapi_entity_value(style_tio, 'name')
.data;
return name;
}
/**
* Returns text style name of one Dwg_Entity_TEXT instance.
* @group Dwg_Entity_TEXT Methods
* @param ptr Pointer to one Dwg_Entity_TEXT instance.
* @returns Returns text style name of one Dwg_Entity_TEXT instance.
*/
dwg_entity_text_get_style_name(ptr) {
return this.dwg_entity_mtext_get_style_name(ptr);
}
/**
* Returns the number of points in Dwg_Entity_POLYLINE_2D.
* @group Dwg_Entity_POLYLINE_2D Methods
* @param ptr Pointer to one Dwg_Object (not Dwg_Entity_POLYLINE_2D) instance.
* @returns Returns the number of points in one Dwg_Entity_POLYLINE_2D.
*/
dwg_entity_polyline_2d_get_numpoints(ptr) {
const wasmInstance = this.wasmInstance;
return wasmInstance.dwg_entity_polyline_2d_get_numpoints(ptr).data;
}
/**
* Returns points in Dwg_Entity_POLYLINE_2D.
* @group Dwg_Entity_POLYLINE_2D Methods
* @param ptr Pointer to one Dwg_Object (not Dwg_Entity_POLYLINE_2D) instance.
* @returns Returns points in one Dwg_Entity_POLYLINE_2D.
*/
dwg_entity_polyline_2d_get_points(ptr) {
const wasmInstance = this.wasmInstance;
return wasmInstance.dwg_entity_polyline_2d_get_points(ptr)
.data;
}
/**
* Returns vertices in Dwg_Entity_POLYLINE_2D.
* @group Dwg_Entity_POLYLINE_2D Methods
* @param ptr Pointer to one Dwg_Object (not Dwg_Entity_POLYLINE_2D) instance.
* @returns Returns vertices in one Dwg_Entity_POLYLINE_2D.
*/
dwg_entity_polyline_2d_get_vertices(ptr) {
const wasmInstance = this.wasmInstance;
return wasmInstance.dwg_entity_polyline_2d_get_vertices(ptr)
.data;
}
static createByWasmInstance(wasmInstance) {
return this.instance == null
? new LibreDwg(wasmInstance)
: this.instance;
}
static async create(filepath) {
const wasmInstance = filepath == null
? await createModule()
: await createModule({
locateFile: (filename) => {
return `${filepath}/${filename}`;
}
});
return this.createByWasmInstance(wasmInstance);
}
}
//# sourceMappingURL=libredwg.js.map