@mlightcad/libredwg-web 0.4.6 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
14
14
  const isPaperSpace = (name) => {
15
15
  return name && name.toUpperCase().startsWith(MODEL_SPACE_PREFIX);
16
16
  };
17
+ const idToString = (id) => {
18
+ return id.toString(16).toUpperCase();
19
+ };
20
+ const isValidPointer = (ptr) => {
21
+ if (typeof ptr === "bigint") {
22
+ return ptr !== 0n;
23
+ } else {
24
+ return ptr !== 0;
25
+ }
26
+ };
17
27
  var DwgCodePage = /* @__PURE__ */ ((DwgCodePage2) => {
18
28
  DwgCodePage2[DwgCodePage2["CP_UTF8"] = 0] = "CP_UTF8";
19
29
  DwgCodePage2[DwgCodePage2["CP_US_ASCII"] = 1] = "CP_US_ASCII";
@@ -6684,14 +6694,26 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6684
6694
  const gridSpacing = libredwg.dwg_dynapi_entity_value(entity, "GRIDUNIT").data;
6685
6695
  const viewDirection = libredwg.dwg_dynapi_entity_value(entity, "VIEWDIR").data;
6686
6696
  const targetPoint = libredwg.dwg_dynapi_entity_value(entity, "view_target").data;
6687
- const perspectiveLensLength = libredwg.dwg_dynapi_entity_value(entity, "lens_length").data;
6697
+ const perspectiveLensLength = libredwg.dwg_dynapi_entity_value(
6698
+ entity,
6699
+ "lens_length"
6700
+ ).data;
6688
6701
  const frontClipZ = libredwg.dwg_dynapi_entity_value(entity, "front_clip_z").data;
6689
6702
  const backClipZ = libredwg.dwg_dynapi_entity_value(entity, "back_clip_z").data;
6690
6703
  const viewHeight = libredwg.dwg_dynapi_entity_value(entity, "VIEWSIZE").data;
6691
6704
  const snapAngle = libredwg.dwg_dynapi_entity_value(entity, "SNAPANG").data;
6692
- const viewTwistAngle = libredwg.dwg_dynapi_entity_value(entity, "twist_angle").data;
6693
- const circleZoomPercent = libredwg.dwg_dynapi_entity_value(entity, "circle_zoom").data;
6694
- const statusBitFlags = libredwg.dwg_dynapi_entity_value(entity, "status_flag").data;
6705
+ const viewTwistAngle = libredwg.dwg_dynapi_entity_value(
6706
+ entity,
6707
+ "twist_angle"
6708
+ ).data;
6709
+ const circleZoomPercent = libredwg.dwg_dynapi_entity_value(
6710
+ entity,
6711
+ "circle_zoom"
6712
+ ).data;
6713
+ const statusBitFlags = libredwg.dwg_dynapi_entity_value(
6714
+ entity,
6715
+ "status_flag"
6716
+ ).data;
6695
6717
  const sheetName = libredwg.dwg_dynapi_entity_value(entity, "style_sheet").data;
6696
6718
  const renderMode = libredwg.dwg_dynapi_entity_value(entity, "render_mode").data;
6697
6719
  const ucsPerViewport = libredwg.dwg_dynapi_entity_value(entity, "UCSVP").data;
@@ -6702,19 +6724,40 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6702
6724
  const ucsId = libredwg.dwg_ref_get_absref(named_ucs_ref);
6703
6725
  const base_ucs_ref = libredwg.dwg_dynapi_entity_value(entity, "base_ucs").data;
6704
6726
  const ucsBaseId = libredwg.dwg_ref_get_absref(base_ucs_ref);
6705
- const orthographicType = libredwg.dwg_dynapi_entity_value(entity, "UCSORTHOVIEW").data;
6727
+ const orthographicType = libredwg.dwg_dynapi_entity_value(
6728
+ entity,
6729
+ "UCSORTHOVIEW"
6730
+ ).data;
6706
6731
  const elevation = libredwg.dwg_dynapi_entity_value(entity, "ucs_elevation").data;
6707
- const shadePlotMode = libredwg.dwg_dynapi_entity_value(entity, "shadeplot_mode").data;
6708
- const isDefaultLighting = libredwg.dwg_dynapi_entity_value(entity, "use_default_lights").data;
6709
- const defaultLightingType = libredwg.dwg_dynapi_entity_value(entity, "default_lighting_type").data;
6732
+ const shadePlotMode = libredwg.dwg_dynapi_entity_value(
6733
+ entity,
6734
+ "shadeplot_mode"
6735
+ ).data;
6736
+ const isDefaultLighting = libredwg.dwg_dynapi_entity_value(
6737
+ entity,
6738
+ "use_default_lights"
6739
+ ).data;
6740
+ const defaultLightingType = libredwg.dwg_dynapi_entity_value(
6741
+ entity,
6742
+ "default_lighting_type"
6743
+ ).data;
6710
6744
  const brightness = libredwg.dwg_dynapi_entity_value(entity, "brightness").data;
6711
6745
  const contrast = libredwg.dwg_dynapi_entity_value(entity, "contrast").data;
6712
- const majorGridFrequency = libredwg.dwg_dynapi_entity_value(entity, "grid_major").data;
6713
- const background_ref = libredwg.dwg_dynapi_entity_value(entity, "background").data;
6746
+ const majorGridFrequency = libredwg.dwg_dynapi_entity_value(
6747
+ entity,
6748
+ "grid_major"
6749
+ ).data;
6750
+ const background_ref = libredwg.dwg_dynapi_entity_value(
6751
+ entity,
6752
+ "background"
6753
+ ).data;
6714
6754
  const backgroundId = libredwg.dwg_ref_get_absref(background_ref);
6715
6755
  const shadeplot_ref = libredwg.dwg_dynapi_entity_value(entity, "shadeplot").data;
6716
6756
  const shadePlotId = libredwg.dwg_ref_get_absref(shadeplot_ref);
6717
- const visualstyle_ref = libredwg.dwg_dynapi_entity_value(entity, "visualstyle").data;
6757
+ const visualstyle_ref = libredwg.dwg_dynapi_entity_value(
6758
+ entity,
6759
+ "visualstyle"
6760
+ ).data;
6718
6761
  const visualStyleId = libredwg.dwg_ref_get_absref(visualstyle_ref);
6719
6762
  const sun_ref = libredwg.dwg_dynapi_entity_value(entity, "sun").data;
6720
6763
  const sunId = libredwg.dwg_ref_get_absref(sun_ref);
@@ -6746,20 +6789,20 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6746
6789
  ucsOrigin,
6747
6790
  ucsXAxis,
6748
6791
  ucsYAxis,
6749
- ucsId: ucsId.toString(),
6750
- ucsBaseId: ucsBaseId.toString(),
6792
+ ucsId: idToString(ucsId),
6793
+ ucsBaseId: idToString(ucsBaseId),
6751
6794
  orthographicType,
6752
6795
  elevation,
6753
6796
  shadePlotMode,
6754
6797
  majorGridFrequency,
6755
- backgroundId: backgroundId.toString(),
6756
- shadePlotId: shadePlotId.toString(),
6757
- visualStyleId: visualStyleId.toString(),
6798
+ backgroundId: idToString(backgroundId),
6799
+ shadePlotId: idToString(shadePlotId),
6800
+ visualStyleId: idToString(visualStyleId),
6758
6801
  isDefaultLighting: !!isDefaultLighting,
6759
6802
  defaultLightingType,
6760
6803
  brightness,
6761
6804
  contrast,
6762
- sunId: sunId.toString()
6805
+ sunId: idToString(sunId)
6763
6806
  };
6764
6807
  }
6765
6808
  convertWipeout(entity, commonAttrs) {
@@ -6896,8 +6939,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6896
6939
  const lineTypeScale = libredwg.dwg_object_entity_get_ltype_scale(entity);
6897
6940
  const isVisible = !libredwg.dwg_object_entity_get_invisible(entity);
6898
6941
  return {
6899
- handle: handle.value,
6900
- ownerBlockRecordSoftId: ownerhandle.absolute_ref,
6942
+ handle: idToString(handle.value),
6943
+ ownerBlockRecordSoftId: idToString(ownerhandle.absolute_ref),
6901
6944
  layer,
6902
6945
  color: rgbColor,
6903
6946
  colorIndex,
@@ -6913,13 +6956,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6913
6956
  getLayerName(entity) {
6914
6957
  const libredwg = this.libredwg;
6915
6958
  const layer = libredwg.dwg_object_entity_get_layer_object_ref(entity);
6916
- const name = this.layers.get(layer.handleref.value);
6959
+ const name = this.layers.get(idToString(layer.handleref.value));
6917
6960
  return name ?? "0";
6918
6961
  }
6919
6962
  getLtypeName(entity) {
6920
6963
  const libredwg = this.libredwg;
6921
6964
  const ltype = libredwg.dwg_object_entity_get_ltype_object_ref(entity);
6922
- const name = this.ltypes.get(ltype.handleref.value);
6965
+ const name = this.ltypes.get(idToString(ltype.handleref.value));
6923
6966
  return name ?? "";
6924
6967
  }
6925
6968
  }
@@ -6998,7 +7041,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6998
7041
  {
6999
7042
  const btr = this.convertBlockRecord(tio, obj);
7000
7043
  db.tables.BLOCK_RECORD.entries.push(btr);
7001
- btr.entities.forEach((entity) => db.entities.push(entity));
7044
+ if (isModelSpace(btr.name) || isPaperSpace(btr.name)) {
7045
+ btr.entities.forEach((entity) => db.entities.push(entity));
7046
+ }
7002
7047
  }
7003
7048
  break;
7004
7049
  case Dwg_Object_Type.DWG_TYPE_DIMSTYLE:
@@ -7094,7 +7139,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7094
7139
  let entities = this.convertEntities(obj, commonAttrs.handle);
7095
7140
  if (entities.length == 0) {
7096
7141
  const entities_ptr = libredwg.dwg_dynapi_entity_value(item, "entities").data;
7097
- const object_ref_ptr_array = libredwg.dwg_ptr_to_object_ref_ptr_array(entities_ptr, num_owned);
7142
+ const object_ref_ptr_array = libredwg.dwg_ptr_to_object_ref_ptr_array(
7143
+ entities_ptr,
7144
+ num_owned
7145
+ );
7098
7146
  const converter = this.entityConverter;
7099
7147
  entities = [];
7100
7148
  for (let index = 0; index < num_owned; index++) {
@@ -7456,9 +7504,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7456
7504
  const elevation = libredwg.dwg_dynapi_entity_value(item, "ucs_elevation").data;
7457
7505
  const majorGridLines = libredwg.dwg_dynapi_entity_value(item, "grid_major").data;
7458
7506
  const background = libredwg.dwg_dynapi_entity_value(item, "background").data;
7459
- const backgroundObjectId = background ? libredwg.dwg_ref_get_absref(background).toString() : void 0;
7507
+ const backgroundObjectId = background ? idToString(libredwg.dwg_ref_get_absref(background)) : void 0;
7460
7508
  const visualstyle = libredwg.dwg_dynapi_entity_value(item, "visualstyle").data;
7461
- const visualStyleObjectId = visualstyle ? libredwg.dwg_ref_get_absref(visualstyle).toString() : void 0;
7509
+ const visualStyleObjectId = visualstyle ? idToString(libredwg.dwg_ref_get_absref(visualstyle)) : void 0;
7462
7510
  return {
7463
7511
  ...commonAttrs,
7464
7512
  standardFlag,
@@ -7510,8 +7558,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7510
7558
  const ownerhandle = libredwg.dwg_object_object_get_ownerhandle_object(object_tio);
7511
7559
  const handle = libredwg.dwg_object_get_handle_object(obj);
7512
7560
  return {
7513
- handle: handle.value,
7514
- ownerHandle: ownerhandle.absolute_ref,
7561
+ handle: idToString(handle.value),
7562
+ ownerHandle: idToString(ownerhandle.absolute_ref),
7515
7563
  name: libredwg.dwg_dynapi_entity_value(tio, "name").data
7516
7564
  };
7517
7565
  }
@@ -7551,6 +7599,22 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7551
7599
  const minExtent = libredwg.dwg_dynapi_entity_value(item, "EXTMIN").data;
7552
7600
  const maxExtent = libredwg.dwg_dynapi_entity_value(item, "EXTMAX").data;
7553
7601
  const elevation = libredwg.dwg_dynapi_entity_value(item, "ucs_elevation").data;
7602
+ const block_header_ref = libredwg.dwg_dynapi_entity_value(
7603
+ item,
7604
+ "block_header"
7605
+ ).data;
7606
+ const paperSpaceTableId = idToString(
7607
+ libredwg.dwg_ref_get_absref(block_header_ref)
7608
+ );
7609
+ const active_viewport_ref = libredwg.dwg_dynapi_entity_value(
7610
+ item,
7611
+ "active_viewport"
7612
+ ).data;
7613
+ const viewportId = idToString(
7614
+ libredwg.dwg_ref_get_absref(active_viewport_ref)
7615
+ );
7616
+ const named_ucs_ref = libredwg.dwg_dynapi_entity_value(item, "named_ucs").data;
7617
+ const namedUcsId = isValidPointer(named_ucs_ref) ? idToString(libredwg.dwg_ref_get_absref(named_ucs_ref)) : void 0;
7554
7618
  return {
7555
7619
  ...commonAttrs,
7556
7620
  layoutName,
@@ -7566,11 +7630,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7566
7630
  ucsXAxis,
7567
7631
  ucsYAxis,
7568
7632
  orthographicType,
7569
- paperSpaceTableId: "",
7570
- // TODO: Set the correct value
7571
- viewportId: "",
7572
- // TODO: Set the correct value
7573
- // namedUcsId?: string;
7633
+ paperSpaceTableId,
7634
+ viewportId,
7635
+ namedUcsId,
7574
7636
  // orthographicUcsId?: string;
7575
7637
  shadePlotId: ""
7576
7638
  // TODO: Set the correct value
@@ -9063,8 +9125,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
9063
9125
  return converter.convert(data);
9064
9126
  }
9065
9127
  /**
9066
- * Converts Dwg_Data instance to DwgDatabase instance and returns conversion statistics.
9067
- * DwgDatabase instance doesn't depend on Dwg_Data instance any more after conversion.
9128
+ * Converts Dwg_Data instance to DwgDatabase instance and returns conversion statistics.
9129
+ * DwgDatabase instance doesn't depend on Dwg_Data instance any more after conversion.
9068
9130
  * So you can call function dwg_free to free memory occupied by Dwg_Data.
9069
9131
  * @param data Pointer to Dwg_Data instance.
9070
9132
  * @returns Returns the converted DwgDatabase and conversion statistics.
@@ -9987,7 +10049,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
9987
10049
  exports2.createModule = createModule;
9988
10050
  exports2.dwgCodePageToEncoding = dwgCodePageToEncoding;
9989
10051
  exports2.dwgVersions = dwgVersions;
10052
+ exports2.idToString = idToString;
9990
10053
  exports2.isModelSpace = isModelSpace;
9991
10054
  exports2.isPaperSpace = isPaperSpace;
10055
+ exports2.isValidPointer = isValidPointer;
9992
10056
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
9993
10057
  });
@@ -1,4 +1,4 @@
1
- import { HEADER_VARIABLES } from '../database';
1
+ import { HEADER_VARIABLES, idToString, isModelSpace, isPaperSpace, isValidPointer } from '../database';
2
2
  import { Dwg_Object_Type } from '../types';
3
3
  import { LibreEntityConverter } from './entityConverter';
4
4
  /**
@@ -81,7 +81,10 @@ export class LibreDwgConverter {
81
81
  {
82
82
  const btr = this.convertBlockRecord(tio, obj);
83
83
  db.tables.BLOCK_RECORD.entries.push(btr);
84
- btr.entities.forEach(entity => db.entities.push(entity));
84
+ // db.entities should contains entities in model space and paper space only
85
+ if (isModelSpace(btr.name) || isPaperSpace(btr.name)) {
86
+ btr.entities.forEach(entity => db.entities.push(entity));
87
+ }
85
88
  }
86
89
  break;
87
90
  case Dwg_Object_Type.DWG_TYPE_DIMSTYLE:
@@ -150,7 +153,7 @@ export class LibreDwgConverter {
150
153
  wasAProxyFlag: cls.s_zombie,
151
154
  // DWG_TYPE_PROXY_ENTITY = 0x1F2 /* 498 */,
152
155
  // DWG_TYPE_PROXY_OBJECT = 0x1F3 /* 499 */,
153
- isAnEntityFlag: cls.item_class_id === 0x1F2
156
+ isAnEntityFlag: cls.item_class_id === 0x1f2
154
157
  });
155
158
  }
156
159
  }
@@ -164,7 +167,8 @@ export class LibreDwgConverter {
164
167
  commonAttrs.name = block.name;
165
168
  }
166
169
  // The number of entities
167
- const num_owned = libredwg.dwg_dynapi_entity_value(item, 'num_owned').data;
170
+ const num_owned = libredwg.dwg_dynapi_entity_value(item, 'num_owned')
171
+ .data;
168
172
  const flags = libredwg.dwg_dynapi_entity_value(item, 'flag').data;
169
173
  const description = libredwg.dwg_dynapi_entity_value(item, 'description')
170
174
  .data;
@@ -195,7 +199,8 @@ export class LibreDwgConverter {
195
199
  // on libredwg too. In this time, I try to use property 'entities' of block header to iterate entities.
196
200
  let entities = this.convertEntities(obj, commonAttrs.handle);
197
201
  if (entities.length == 0) {
198
- const entities_ptr = libredwg.dwg_dynapi_entity_value(item, 'entities').data;
202
+ const entities_ptr = libredwg.dwg_dynapi_entity_value(item, 'entities')
203
+ .data;
199
204
  const object_ref_ptr_array = libredwg.dwg_ptr_to_object_ref_ptr_array(entities_ptr, num_owned);
200
205
  const converter = this.entityConverter;
201
206
  entities = [];
@@ -507,13 +512,13 @@ export class LibreDwgConverter {
507
512
  // - 0xc8 for none (also c3 and rgb of 0x101)
508
513
  const method = color.method;
509
514
  let colorIndex = 256;
510
- let rgbColor = 0xFFFFFF;
515
+ let rgbColor = 0xffffff;
511
516
  // It looks like that libredwg always returns 256 for property 'index' in Dwg_Color
512
- if (method === 0xC3 || ((color.rgb >>> 24) & 0xFF) === 0xC3) {
513
- colorIndex = color.rgb & 0x000000FF;
517
+ if (method === 0xc3 || ((color.rgb >>> 24) & 0xff) === 0xc3) {
518
+ colorIndex = color.rgb & 0x000000ff;
514
519
  }
515
- else if (method == 0xC2 || ((color.rgb >>> 24) & 0xFF) === 0xC2) {
516
- rgbColor = color.rgb & 0x00FFFFFF;
520
+ else if (method == 0xc2 || ((color.rgb >>> 24) & 0xff) === 0xc2) {
521
+ rgbColor = color.rgb & 0x00ffffff;
517
522
  }
518
523
  return {
519
524
  ...commonAttrs,
@@ -543,8 +548,11 @@ export class LibreDwgConverter {
543
548
  .data;
544
549
  const patternLen = libredwg.dwg_dynapi_entity_value(item, 'pattern_len')
545
550
  .data;
546
- const dashes = libredwg.dwg_dynapi_entity_value(item, 'dashes').data;
547
- const dashArray = dashes ? libredwg.dwg_ptr_to_ltype_dash_array(dashes, numDashes) : [];
551
+ const dashes = libredwg.dwg_dynapi_entity_value(item, 'dashes')
552
+ .data;
553
+ const dashArray = dashes
554
+ ? libredwg.dwg_ptr_to_ltype_dash_array(dashes, numDashes)
555
+ : [];
548
556
  return {
549
557
  ...commonAttrs,
550
558
  description: description,
@@ -664,12 +672,12 @@ export class LibreDwgConverter {
664
672
  const background = libredwg.dwg_dynapi_entity_value(item, 'background')
665
673
  .data;
666
674
  const backgroundObjectId = background
667
- ? libredwg.dwg_ref_get_absref(background).toString()
675
+ ? idToString(libredwg.dwg_ref_get_absref(background))
668
676
  : undefined;
669
677
  const visualstyle = libredwg.dwg_dynapi_entity_value(item, 'visualstyle')
670
678
  .data;
671
679
  const visualStyleObjectId = visualstyle
672
- ? libredwg.dwg_ref_get_absref(visualstyle).toString()
680
+ ? idToString(libredwg.dwg_ref_get_absref(visualstyle))
673
681
  : undefined;
674
682
  // BITCODE_B UCSFOLLOW;
675
683
  // BITCODE_B FASTZOOM;
@@ -731,8 +739,8 @@ export class LibreDwgConverter {
731
739
  const ownerhandle = libredwg.dwg_object_object_get_ownerhandle_object(object_tio);
732
740
  const handle = libredwg.dwg_object_get_handle_object(obj);
733
741
  return {
734
- handle: handle.value,
735
- ownerHandle: ownerhandle.absolute_ref,
742
+ handle: idToString(handle.value),
743
+ ownerHandle: idToString(ownerhandle.absolute_ref),
736
744
  name: libredwg.dwg_dynapi_entity_value(tio, 'name').data
737
745
  };
738
746
  }
@@ -788,10 +796,16 @@ export class LibreDwgConverter {
788
796
  .data;
789
797
  const elevation = libredwg.dwg_dynapi_entity_value(item, 'ucs_elevation')
790
798
  .data;
791
- // BITCODE_H block_header;
792
- // BITCODE_H active_viewport;
799
+ const block_header_ref = libredwg.dwg_dynapi_entity_value(item, 'block_header').data;
800
+ const paperSpaceTableId = idToString(libredwg.dwg_ref_get_absref(block_header_ref));
801
+ const active_viewport_ref = libredwg.dwg_dynapi_entity_value(item, 'active_viewport').data;
802
+ const viewportId = idToString(libredwg.dwg_ref_get_absref(active_viewport_ref));
803
+ const named_ucs_ref = libredwg.dwg_dynapi_entity_value(item, 'named_ucs')
804
+ .data;
805
+ const namedUcsId = isValidPointer(named_ucs_ref)
806
+ ? idToString(libredwg.dwg_ref_get_absref(named_ucs_ref))
807
+ : undefined;
793
808
  // BITCODE_H base_ucs;
794
- // BITCODE_H named_ucs;
795
809
  // BITCODE_BL num_viewports; // r2004+
796
810
  // BITCODE_H *viewports; // r2004+
797
811
  return {
@@ -809,9 +823,9 @@ export class LibreDwgConverter {
809
823
  ucsXAxis: ucsXAxis,
810
824
  ucsYAxis: ucsYAxis,
811
825
  orthographicType: orthographicType,
812
- paperSpaceTableId: '', // TODO: Set the correct value
813
- viewportId: '', // TODO: Set the correct value
814
- // namedUcsId?: string;
826
+ paperSpaceTableId: paperSpaceTableId,
827
+ viewportId: viewportId,
828
+ namedUcsId: namedUcsId,
815
829
  // orthographicUcsId?: string;
816
830
  shadePlotId: '' // TODO: Set the correct value
817
831
  };
@@ -3,8 +3,8 @@ import { LibreDwgEx } from '../libredwg';
3
3
  import { Dwg_Object_Ptr } from '../types';
4
4
  export declare class LibreEntityConverter {
5
5
  libredwg: LibreDwgEx;
6
- layers: Map<number, string>;
7
- ltypes: Map<number, string>;
6
+ layers: Map<string, string>;
7
+ ltypes: Map<string, string>;
8
8
  unknownEntityCount: number;
9
9
  constructor(instance: LibreDwgEx);
10
10
  prepare(db: DwgDatabase, force?: boolean): void;
@@ -1,4 +1,4 @@
1
- import { DwgBoundaryPathEdgeType, DwgHatchAssociativity, DwgHatchSolidFill } from '../database';
1
+ import { DwgBoundaryPathEdgeType, DwgHatchAssociativity, DwgHatchSolidFill, idToString } from '../database';
2
2
  import { Dwg_Hatch_Edge_Type, Dwg_Object_Type } from '../types';
3
3
  export class LibreEntityConverter {
4
4
  libredwg;
@@ -957,7 +957,8 @@ export class LibreEntityConverter {
957
957
  convertPolyline2d(entity, commonAttrs, object) {
958
958
  const libredwg = this.libredwg;
959
959
  const flag = libredwg.dwg_dynapi_entity_value(entity, 'flag').data;
960
- const smoothType = libredwg.dwg_dynapi_entity_value(entity, 'curve_type').data;
960
+ const smoothType = libredwg.dwg_dynapi_entity_value(entity, 'curve_type')
961
+ .data;
961
962
  const startWidth = libredwg.dwg_dynapi_entity_value(entity, 'start_width')
962
963
  .data;
963
964
  const endWidth = libredwg.dwg_dynapi_entity_value(entity, 'end_width')
@@ -993,13 +994,14 @@ export class LibreEntityConverter {
993
994
  meshMVertexCount: 0,
994
995
  meshNVertexCount: 0,
995
996
  surfaceMDensity: 0,
996
- surfaceNDensity: 0,
997
+ surfaceNDensity: 0
997
998
  };
998
999
  }
999
1000
  convertPolyline3d(entity, commonAttrs, object) {
1000
1001
  const libredwg = this.libredwg;
1001
1002
  const flag = libredwg.dwg_dynapi_entity_value(entity, 'flag').data;
1002
- const smoothType = libredwg.dwg_dynapi_entity_value(entity, 'curve_type').data;
1003
+ const smoothType = libredwg.dwg_dynapi_entity_value(entity, 'curve_type')
1004
+ .data;
1003
1005
  const startWidth = libredwg.dwg_dynapi_entity_value(entity, 'start_width')
1004
1006
  .data;
1005
1007
  const endWidth = libredwg.dwg_dynapi_entity_value(entity, 'end_width')
@@ -1343,24 +1345,20 @@ export class LibreEntityConverter {
1343
1345
  .data;
1344
1346
  const targetPoint = libredwg.dwg_dynapi_entity_value(entity, 'view_target')
1345
1347
  .data;
1346
- const perspectiveLensLength = libredwg.dwg_dynapi_entity_value(entity, 'lens_length')
1347
- .data;
1348
+ const perspectiveLensLength = libredwg.dwg_dynapi_entity_value(entity, 'lens_length').data;
1348
1349
  const frontClipZ = libredwg.dwg_dynapi_entity_value(entity, 'front_clip_z')
1349
1350
  .data;
1350
1351
  const backClipZ = libredwg.dwg_dynapi_entity_value(entity, 'back_clip_z')
1351
1352
  .data;
1352
- // TODO: I am not sure whether view size in libredwg represents view height
1353
+ // TODO: I am not sure whether view size in libredwg represents view height
1353
1354
  const viewHeight = libredwg.dwg_dynapi_entity_value(entity, 'VIEWSIZE')
1354
1355
  .data;
1355
1356
  const snapAngle = libredwg.dwg_dynapi_entity_value(entity, 'SNAPANG')
1356
1357
  .data;
1357
- const viewTwistAngle = libredwg.dwg_dynapi_entity_value(entity, 'twist_angle')
1358
- .data;
1359
- const circleZoomPercent = libredwg.dwg_dynapi_entity_value(entity, 'circle_zoom')
1360
- .data;
1358
+ const viewTwistAngle = libredwg.dwg_dynapi_entity_value(entity, 'twist_angle').data;
1359
+ const circleZoomPercent = libredwg.dwg_dynapi_entity_value(entity, 'circle_zoom').data;
1361
1360
  // TODO: convert frozenLayerIds and clippingBoundaryId
1362
- const statusBitFlags = libredwg.dwg_dynapi_entity_value(entity, 'status_flag')
1363
- .data;
1361
+ const statusBitFlags = libredwg.dwg_dynapi_entity_value(entity, 'status_flag').data;
1364
1362
  const sheetName = libredwg.dwg_dynapi_entity_value(entity, 'style_sheet')
1365
1363
  .data;
1366
1364
  const renderMode = libredwg.dwg_dynapi_entity_value(entity, 'render_mode')
@@ -1381,30 +1379,23 @@ export class LibreEntityConverter {
1381
1379
  .data;
1382
1380
  const ucsBaseId = libredwg.dwg_ref_get_absref(base_ucs_ref);
1383
1381
  // TODO: Not sure whether UCSORTHOVIEW represents orthographicType
1384
- const orthographicType = libredwg.dwg_dynapi_entity_value(entity, 'UCSORTHOVIEW')
1385
- .data;
1382
+ const orthographicType = libredwg.dwg_dynapi_entity_value(entity, 'UCSORTHOVIEW').data;
1386
1383
  const elevation = libredwg.dwg_dynapi_entity_value(entity, 'ucs_elevation')
1387
1384
  .data;
1388
- const shadePlotMode = libredwg.dwg_dynapi_entity_value(entity, 'shadeplot_mode')
1389
- .data;
1390
- const isDefaultLighting = libredwg.dwg_dynapi_entity_value(entity, 'use_default_lights')
1391
- .data;
1392
- const defaultLightingType = libredwg.dwg_dynapi_entity_value(entity, 'default_lighting_type')
1393
- .data;
1385
+ const shadePlotMode = libredwg.dwg_dynapi_entity_value(entity, 'shadeplot_mode').data;
1386
+ const isDefaultLighting = libredwg.dwg_dynapi_entity_value(entity, 'use_default_lights').data;
1387
+ const defaultLightingType = libredwg.dwg_dynapi_entity_value(entity, 'default_lighting_type').data;
1394
1388
  const brightness = libredwg.dwg_dynapi_entity_value(entity, 'brightness')
1395
1389
  .data;
1396
1390
  const contrast = libredwg.dwg_dynapi_entity_value(entity, 'contrast')
1397
1391
  .data;
1398
- const majorGridFrequency = libredwg.dwg_dynapi_entity_value(entity, 'grid_major')
1399
- .data;
1400
- const background_ref = libredwg.dwg_dynapi_entity_value(entity, 'background')
1401
- .data;
1392
+ const majorGridFrequency = libredwg.dwg_dynapi_entity_value(entity, 'grid_major').data;
1393
+ const background_ref = libredwg.dwg_dynapi_entity_value(entity, 'background').data;
1402
1394
  const backgroundId = libredwg.dwg_ref_get_absref(background_ref);
1403
1395
  const shadeplot_ref = libredwg.dwg_dynapi_entity_value(entity, 'shadeplot')
1404
1396
  .data;
1405
1397
  const shadePlotId = libredwg.dwg_ref_get_absref(shadeplot_ref);
1406
- const visualstyle_ref = libredwg.dwg_dynapi_entity_value(entity, 'visualstyle')
1407
- .data;
1398
+ const visualstyle_ref = libredwg.dwg_dynapi_entity_value(entity, 'visualstyle').data;
1408
1399
  const visualStyleId = libredwg.dwg_ref_get_absref(visualstyle_ref);
1409
1400
  // TODO: convert ambientLightColor
1410
1401
  const sun_ref = libredwg.dwg_dynapi_entity_value(entity, 'sun')
@@ -1438,20 +1429,20 @@ export class LibreEntityConverter {
1438
1429
  ucsOrigin: ucsOrigin,
1439
1430
  ucsXAxis: ucsXAxis,
1440
1431
  ucsYAxis: ucsYAxis,
1441
- ucsId: ucsId.toString(),
1442
- ucsBaseId: ucsBaseId.toString(),
1432
+ ucsId: idToString(ucsId),
1433
+ ucsBaseId: idToString(ucsBaseId),
1443
1434
  orthographicType: orthographicType,
1444
1435
  elevation: elevation,
1445
1436
  shadePlotMode: shadePlotMode,
1446
1437
  majorGridFrequency: majorGridFrequency,
1447
- backgroundId: backgroundId.toString(),
1448
- shadePlotId: shadePlotId.toString(),
1449
- visualStyleId: visualStyleId.toString(),
1438
+ backgroundId: idToString(backgroundId),
1439
+ shadePlotId: idToString(shadePlotId),
1440
+ visualStyleId: idToString(visualStyleId),
1450
1441
  isDefaultLighting: !!isDefaultLighting,
1451
1442
  defaultLightingType: defaultLightingType,
1452
1443
  brightness: brightness,
1453
1444
  contrast: contrast,
1454
- sunId: sunId.toString()
1445
+ sunId: idToString(sunId)
1455
1446
  };
1456
1447
  }
1457
1448
  convertWipeout(entity, commonAttrs) {
@@ -1574,8 +1565,8 @@ export class LibreEntityConverter {
1574
1565
  const method = color.method;
1575
1566
  let colorIndex = color.index;
1576
1567
  let rgbColor = undefined;
1577
- if (method == 0xC2 || ((color.rgb >>> 24) & 0xFF) === 0xC2) {
1578
- rgbColor = color.rgb & 0x00FFFFFF;
1568
+ if (method == 0xc2 || ((color.rgb >>> 24) & 0xff) === 0xc2) {
1569
+ rgbColor = color.rgb & 0x00ffffff;
1579
1570
  }
1580
1571
  const layer = this.getLayerName(entity);
1581
1572
  const handle = libredwg.dwg_object_entity_get_handle_object(entity);
@@ -1585,8 +1576,8 @@ export class LibreEntityConverter {
1585
1576
  const lineTypeScale = libredwg.dwg_object_entity_get_ltype_scale(entity);
1586
1577
  const isVisible = !libredwg.dwg_object_entity_get_invisible(entity);
1587
1578
  return {
1588
- handle: handle.value,
1589
- ownerBlockRecordSoftId: ownerhandle.absolute_ref,
1579
+ handle: idToString(handle.value),
1580
+ ownerBlockRecordSoftId: idToString(ownerhandle.absolute_ref),
1590
1581
  layer: layer,
1591
1582
  color: rgbColor,
1592
1583
  colorIndex: colorIndex,
@@ -1602,13 +1593,13 @@ export class LibreEntityConverter {
1602
1593
  getLayerName(entity) {
1603
1594
  const libredwg = this.libredwg;
1604
1595
  const layer = libredwg.dwg_object_entity_get_layer_object_ref(entity);
1605
- const name = this.layers.get(layer.handleref.value);
1596
+ const name = this.layers.get(idToString(layer.handleref.value));
1606
1597
  return name ?? '0';
1607
1598
  }
1608
1599
  getLtypeName(entity) {
1609
1600
  const libredwg = this.libredwg;
1610
1601
  const ltype = libredwg.dwg_object_entity_get_ltype_object_ref(entity);
1611
- const name = this.ltypes.get(ltype.handleref.value);
1602
+ const name = this.ltypes.get(idToString(ltype.handleref.value));
1612
1603
  return name ?? '';
1613
1604
  }
1614
1605
  }
@@ -1,5 +1,7 @@
1
1
  export declare const isModelSpace: (name: string) => boolean | "";
2
2
  export declare const isPaperSpace: (name: string) => boolean | "";
3
+ export declare const idToString: (id: number | bigint) => string;
4
+ export declare const isValidPointer: (ptr: number | bigint) => boolean;
3
5
  export interface DwgPoint2D {
4
6
  x: number;
5
7
  y: number;
@@ -6,4 +6,15 @@ export const isModelSpace = (name) => {
6
6
  export const isPaperSpace = (name) => {
7
7
  return name && name.toUpperCase().startsWith(MODEL_SPACE_PREFIX);
8
8
  };
9
+ export const idToString = (id) => {
10
+ return id.toString(16).toUpperCase();
11
+ };
12
+ export const isValidPointer = (ptr) => {
13
+ if (typeof ptr === 'bigint') {
14
+ return ptr !== 0n;
15
+ }
16
+ else {
17
+ return ptr !== 0;
18
+ }
19
+ };
9
20
  //# sourceMappingURL=common.js.map
@@ -7,11 +7,11 @@ export interface DwgEntity {
7
7
  /**
8
8
  * Handle
9
9
  */
10
- handle: number;
10
+ handle: string;
11
11
  /**
12
12
  * Soft-pointer ID/handle to owner BLOCK_RECORD object
13
13
  */
14
- ownerBlockRecordSoftId: number;
14
+ ownerBlockRecordSoftId: string;
15
15
  /**
16
16
  * Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
17
17
  */
@@ -1,7 +1,7 @@
1
1
  export interface DwgCommonTableEntry {
2
2
  name: string;
3
- handle: number;
4
- ownerHandle: number;
3
+ handle: string;
4
+ ownerHandle: string;
5
5
  }
6
6
  export interface DwgTable<T extends DwgCommonTableEntry> {
7
7
  entries: T[];
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A DWG/DXF JavaScript parser based on libredwg",
4
4
  "license": "GPL-2.0-only",
5
5
  "private": false,
6
- "version": "0.4.6",
6
+ "version": "0.6.0",
7
7
  "author": "MLight Lee <mlight.lee@outlook.com>",
8
8
  "type": "module",
9
9
  "repository": {