Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/FUNDING.yml

This file was deleted.

18 changes: 18 additions & 0 deletions bindings/javascript/embind/binding_ent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,23 @@ emscripten::val dwg_entity_polyline_3d_get_vertices_wrapper(Dwg_Object_Ptr obj_p
return result;
}

emscripten::val dwg_entity_insert_get_attribs_wrapper(Dwg_Object_Entity_Ptr obj_ptr) {
Dwg_Entity_INSERT* ent = reinterpret_cast<Dwg_Entity_INSERT*>(obj_ptr);
emscripten::val result = emscripten::val::object();
emscripten::val attribs = emscripten::val::array();
result.set("data", attribs);

Dwg_Object *o;
for (BITCODE_BL j = 0; j < ent->num_owned; j++) {
o = ent->attribs && ent->attribs[j] ? ent->attribs[j]->obj : NULL;
if (o && o->fixedtype == DWG_TYPE_ATTRIB) {
attribs.call<void>("push", reinterpret_cast<uintptr_t>(o));
}
}

return result;
}

EMSCRIPTEN_BINDINGS(libredwg_dwg_entity) {
DEFINE_FUNC(dwg_entity_owner);
DEFINE_FUNC(dwg_entity_polyline_2d_get_numpoints);
Expand All @@ -336,6 +353,7 @@ EMSCRIPTEN_BINDINGS(libredwg_dwg_entity) {
DEFINE_FUNC(dwg_entity_polyline_3d_get_points);
DEFINE_FUNC(dwg_entity_polyline_3d_get_vertices);
DEFINE_FUNC(dwg_entity_block_header_get_preview);
DEFINE_FUNC(dwg_entity_insert_get_attribs);
}

emscripten::val dwg_object_dictionary_get_texts_wrapper(Dwg_Object_Ptr obj_ptr) {
Expand Down
2 changes: 1 addition & 1 deletion bindings/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A DWG/DXF JavaScript parser based on libredwg",
"license": "GPL-2.0-only",
"private": false,
"version": "0.6.5",
"version": "0.6.6",
"author": "MLight Lee <mlight.lee@outlook.com>",
"type": "module",
"repository": {
Expand Down
75 changes: 73 additions & 2 deletions bindings/javascript/src/converter/entityConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DwgArcEntity,
DwgAttachmentPoint,
DwgAttdefEntity,
DwgAttribEntity,
DwgBoundaryPath,
DwgBoundaryPathEdge,
DwgBoundaryPathEdgeType,
Expand Down Expand Up @@ -138,6 +139,8 @@ export class LibreEntityConverter {
return this.convertArc(entity_tio, commonAttrs)
} else if (fixedtype == Dwg_Object_Type.DWG_TYPE_ATTDEF) {
return this.convertAttdef(entity_tio, commonAttrs)
} else if (fixedtype == Dwg_Object_Type.DWG_TYPE_ATTRIB) {
return this.convertAttrib(entity_tio, commonAttrs)
} else if (fixedtype == Dwg_Object_Type.DWG_TYPE_CIRCLE) {
return this.convertCircle(entity_tio, commonAttrs)
} else if (
Expand Down Expand Up @@ -389,7 +392,7 @@ export class LibreEntityConverter {
).data as number
const isReallyLocked = libredwg.dwg_dynapi_entity_value(
entity,
'is_locked_in_block'
'is_really_locked'
).data as number
// TODO: double check whether 'mtext_type' is 'mtextFlag'
const mtextFlag = libredwg.dwg_dynapi_entity_value(entity, 'mtext_type')
Expand Down Expand Up @@ -418,6 +421,58 @@ export class LibreEntityConverter {
}
}

private convertAttrib(
entity: Dwg_Object_Entity_Ptr,
commonAttrs: DwgCommonAttributes
): DwgAttribEntity {
const libredwg = this.libredwg

const text = this.convertTextBase(entity)
const tag = libredwg.dwg_dynapi_entity_value(entity, 'tag').data as string
const flags = libredwg.dwg_dynapi_entity_value(entity, 'flags')
.data as number
const fieldLength = libredwg.dwg_dynapi_entity_value(entity, 'field_length')
.data as number
const lockPositionFlag = libredwg.dwg_dynapi_entity_value(
entity,
'lock_position_flag'
).data as number
const duplicateRecordCloningFlag = libredwg.dwg_dynapi_entity_value(
entity,
'keep_duplicate_records'
).data as number
// TODO: double check whether 'mtext_type' is 'mtextFlag'
const mtextFlag = libredwg.dwg_dynapi_entity_value(entity, 'mtext_type')
.data as number
const isReallyLocked = libredwg.dwg_dynapi_entity_value(
entity,
'is_really_locked'
).data as number
const alignmentPoint = libredwg.dwg_dynapi_entity_value(
entity,
'alignment_pt'
).data as DwgPoint2D

return {
type: 'ATTRIB',
...commonAttrs,
text: text,
tag: tag,
flags: flags,
fieldLength: fieldLength,
lockPositionFlag: !!lockPositionFlag,
duplicateRecordCloningFlag: !!duplicateRecordCloningFlag,
mtextFlag: mtextFlag,
isReallyLocked: !!isReallyLocked,
numberOfSecondaryAttrs: 0, // TODO: libredwg doesn't support it yet.
secondaryAttrsHardId: '0', // TODO: libredwg doesn't support it yet.
alignmentPoint: { ...alignmentPoint, z: 0 },
annotationScale: 1, // TODO: Set the correct value
attrTag: '', // TODO: Set the correct value
mtext: this.convertEmbeddedMText(entity, 'ATTDEF_mtext')
}
}

private convertCircle(
entity: Dwg_Object_Entity_Ptr,
commonAttrs: DwgCommonAttributes
Expand Down Expand Up @@ -919,6 +974,21 @@ export class LibreEntityConverter {
'extrusion'
).data as DwgPoint3D

const attrib_ptr_array = libredwg.dwg_entity_insert_get_attribs(entity)
const attribs: DwgAttribEntity[] = []
attrib_ptr_array.forEach(object_ptr => {
const entity = libredwg.dwg_object_to_entity(object_ptr)
const entity_tio = libredwg.dwg_object_to_entity_tio(object_ptr)
if (entity && entity_tio) {
// Get values of the common attributes of ATTRIB entity
const commonAttrs = this.getCommonAttrs(entity)
const fixedtype = libredwg.dwg_object_get_fixedtype(object_ptr)
if (fixedtype == Dwg_Object_Type.DWG_TYPE_ATTRIB) {
attribs.push(this.convertAttrib(entity_tio, commonAttrs))
}
}
})

// TODO: convert block attributes
return {
type: 'INSERT',
Expand All @@ -933,7 +1003,8 @@ export class LibreEntityConverter {
rowCount: rowCount,
columnSpacing: columnSpacing,
rowSpacing: rowSpacing,
extrusionDirection: extrusionDirection
extrusionDirection: extrusionDirection,
attribs: attribs
}
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/javascript/src/database/entities/attrib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface DwgAttribEntity extends DwgEntity {
/**
* hard-pointer id of secondary attribute(s) or attribute definition(s)
*/
secondaryAttrsHardId: number
secondaryAttrsHardId: string
/**
* Alignment point of attribute or attribute definition.
*/
Expand Down
5 changes: 5 additions & 0 deletions bindings/javascript/src/database/entities/insert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DwgPoint3D } from '../common'
import { DwgAttribEntity } from './attrib'
import { DwgEntity } from './entity'

export interface DwgInsertEntity extends DwgEntity {
Expand Down Expand Up @@ -56,4 +57,8 @@ export interface DwgInsertEntity extends DwgEntity {
* Extrusion direction (optional; default = 0, 0, 1)
*/
extrusionDirection: DwgPoint3D
/**
* Attributes associated with the INSERT entity
*/
attribs: DwgAttribEntity[]
}
14 changes: 14 additions & 0 deletions bindings/javascript/src/libredwg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,20 @@ export class LibreDwg {
.data as Dwg_Entity_VERTEX_3D[]
}

/**
* Returns attributes associated with INSERT entity.
* @group Dwg_Entity_INSERT Methods
* @param ptr Pointer to one Dwg_Object (not Dwg_Entity_INSERT) instance.
* @returns Returns attributes associated with INSERT entity.
*/
dwg_entity_insert_get_attribs(
ptr: Dwg_Object_Ptr
): number[] {
const wasmInstance = this.wasmInstance
return wasmInstance.dwg_entity_insert_get_attribs(ptr)
.data as number[]
}

/**
* Returns texts in Dwg_Object_DICTIONARY.
* @group Dwg_Object_DICTIONARY Methods
Expand Down
1 change: 1 addition & 0 deletions bindings/javascript/wasm/libredwg-web.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ interface EmbindModule {
dwg_entity_polyline_3d_get_points(_0: number): any;
dwg_entity_polyline_3d_get_vertices(_0: number): any;
dwg_entity_block_header_get_preview(_0: number): any;
dwg_entity_insert_get_attribs(_0: number): any;
dwg_object_dictionary_get_texts(_0: number): any;
dwg_read_file(_0: EmbindString): any;
dwg_bmp(_0: number): any;
Expand Down
Binary file modified bindings/javascript/wasm/libredwg-web.wasm
Binary file not shown.
Loading