@mlightcad/data-model 1.7.27 → 1.7.28

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.
Files changed (64) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +224 -224
  3. package/dist/data-model.cjs +4 -3
  4. package/dist/data-model.js +5870 -3428
  5. package/dist/dxf-parser-worker.js +1002 -740
  6. package/lib/converter/AcDbDxfConverter.d.ts.map +1 -1
  7. package/lib/converter/AcDbDxfConverter.js +28 -0
  8. package/lib/converter/AcDbDxfConverter.js.map +1 -1
  9. package/lib/converter/AcDbEntitiyConverter.d.ts +12 -0
  10. package/lib/converter/AcDbEntitiyConverter.d.ts.map +1 -1
  11. package/lib/converter/AcDbEntitiyConverter.js +552 -3
  12. package/lib/converter/AcDbEntitiyConverter.js.map +1 -1
  13. package/lib/converter/AcDbObjectConverter.d.ts +10 -3
  14. package/lib/converter/AcDbObjectConverter.d.ts.map +1 -1
  15. package/lib/converter/AcDbObjectConverter.js +154 -1
  16. package/lib/converter/AcDbObjectConverter.js.map +1 -1
  17. package/lib/converter/AcDbRegenerator.d.ts.map +1 -1
  18. package/lib/converter/AcDbRegenerator.js +22 -4
  19. package/lib/converter/AcDbRegenerator.js.map +1 -1
  20. package/lib/database/AcDbDatabase.d.ts +4 -0
  21. package/lib/database/AcDbDatabase.d.ts.map +1 -1
  22. package/lib/database/AcDbDatabase.js +67 -15
  23. package/lib/database/AcDbDatabase.js.map +1 -1
  24. package/lib/entity/AcDbLeader.d.ts +32 -3
  25. package/lib/entity/AcDbLeader.d.ts.map +1 -1
  26. package/lib/entity/AcDbLeader.js +140 -10
  27. package/lib/entity/AcDbLeader.js.map +1 -1
  28. package/lib/entity/AcDbMLeader.d.ts +899 -0
  29. package/lib/entity/AcDbMLeader.d.ts.map +1 -0
  30. package/lib/entity/AcDbMLeader.js +2122 -0
  31. package/lib/entity/AcDbMLeader.js.map +1 -0
  32. package/lib/entity/AcDbMLine.d.ts +122 -0
  33. package/lib/entity/AcDbMLine.d.ts.map +1 -0
  34. package/lib/entity/AcDbMLine.js +548 -0
  35. package/lib/entity/AcDbMLine.js.map +1 -0
  36. package/lib/entity/dimension/AcDbDiametricDimension.d.ts +0 -33
  37. package/lib/entity/dimension/AcDbDiametricDimension.d.ts.map +1 -1
  38. package/lib/entity/dimension/AcDbDiametricDimension.js +0 -80
  39. package/lib/entity/dimension/AcDbDiametricDimension.js.map +1 -1
  40. package/lib/entity/dimension/AcDbDimension.d.ts +1 -9
  41. package/lib/entity/dimension/AcDbDimension.d.ts.map +1 -1
  42. package/lib/entity/dimension/AcDbDimension.js +0 -10
  43. package/lib/entity/dimension/AcDbDimension.js.map +1 -1
  44. package/lib/entity/dimension/AcDbRadialDimension.d.ts +0 -6
  45. package/lib/entity/dimension/AcDbRadialDimension.d.ts.map +1 -1
  46. package/lib/entity/dimension/AcDbRadialDimension.js +0 -8
  47. package/lib/entity/dimension/AcDbRadialDimension.js.map +1 -1
  48. package/lib/entity/index.d.ts +2 -0
  49. package/lib/entity/index.d.ts.map +1 -1
  50. package/lib/entity/index.js +2 -0
  51. package/lib/entity/index.js.map +1 -1
  52. package/lib/object/AcDbMLeaderStyle.d.ts +404 -0
  53. package/lib/object/AcDbMLeaderStyle.d.ts.map +1 -0
  54. package/lib/object/AcDbMLeaderStyle.js +1004 -0
  55. package/lib/object/AcDbMLeaderStyle.js.map +1 -0
  56. package/lib/object/AcDbMlineStyle.d.ts +57 -0
  57. package/lib/object/AcDbMlineStyle.d.ts.map +1 -0
  58. package/lib/object/AcDbMlineStyle.js +164 -0
  59. package/lib/object/AcDbMlineStyle.js.map +1 -0
  60. package/lib/object/index.d.ts +2 -0
  61. package/lib/object/index.d.ts.map +1 -1
  62. package/lib/object/index.js +2 -0
  63. package/lib/object/index.js.map +1 -1
  64. package/package.json +5 -5
@@ -34,10 +34,21 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
34
34
  }
35
35
  return to.concat(ar || Array.prototype.slice.call(from));
36
36
  };
37
+ var __values = (this && this.__values) || function(o) {
38
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
39
+ if (m) return m.call(o);
40
+ if (o && typeof o.length === "number") return {
41
+ next: function () {
42
+ if (o && i >= o.length) o = void 0;
43
+ return { value: o && o[i++], done: !o };
44
+ }
45
+ };
46
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
47
+ };
37
48
  import { AcCmTransparency } from '@mlightcad/common';
38
49
  import { HatchSolidFill, SmoothType, VertexFlag } from '@mlightcad/dxf-json';
39
50
  import { AcGeCircArc2d, AcGeEllipseArc2d, AcGeLine2d, AcGeLoop2d, AcGeMathUtil, AcGePoint2d, AcGePoint3d, AcGePolyline2d, AcGeSpline3d, AcGeVector2d, AcGeVector3d, transformOcsPointToWcs } from '@mlightcad/geometry-engine';
40
- import { AcDb2dPolyline, AcDb3dPolyline, AcDb3PointAngularDimension, AcDbAlignedDimension, AcDbArc, AcDbAttribute, AcDbAttributeDefinition, AcDbAttributeFlags, AcDbAttributeMTextFlag, AcDbBlockReference, AcDbCircle, AcDbDiametricDimension, AcDbEllipse, AcDbFace, AcDbHatch, AcDbHatchObjectType, AcDbLeader, AcDbLine, AcDbMText, AcDbOrdinateDimension, AcDbPoint, AcDbPoly2dType, AcDbPoly3dType, AcDbPolyFaceMesh, AcDbPolygonMesh, AcDbPolyline, AcDbRadialDimension, AcDbRasterImage, AcDbRay, AcDbRotatedDimension, AcDbSpline, AcDbTable, AcDbText, AcDbTrace, AcDbViewport, AcDbWipeout, AcDbXline } from '../entity';
51
+ import { AcDb2dPolyline, AcDb3dPolyline, AcDb3PointAngularDimension, AcDbAlignedDimension, AcDbArc, AcDbAttribute, AcDbAttributeDefinition, AcDbAttributeFlags, AcDbAttributeMTextFlag, AcDbBlockReference, AcDbCircle, AcDbDiametricDimension, AcDbEllipse, AcDbFace, AcDbHatch, AcDbHatchObjectType, AcDbLeader, AcDbLine, AcDbMLeader, AcDbMLeaderContentType, AcDbMLeaderLineType, AcDbMLine, AcDbMText, AcDbOrdinateDimension, AcDbPoint, AcDbPoly2dType, AcDbPoly3dType, AcDbPolyFaceMesh, AcDbPolygonMesh, AcDbPolyline, AcDbRadialDimension, AcDbRasterImage, AcDbRay, AcDbRotatedDimension, AcDbSpline, AcDbTable, AcDbText, AcDbTrace, AcDbViewport, AcDbWipeout, AcDbXline } from '../entity';
41
52
  /**
42
53
  * Converts DXF entities to AcDbEntity objects.
43
54
  *
@@ -138,6 +149,12 @@ var AcDbEntityConverter = /** @class */ (function () {
138
149
  else if (entity.type == 'MTEXT') {
139
150
  return this.convertMText(entity);
140
151
  }
152
+ else if (entity.type == 'MLINE') {
153
+ return this.convertMLine(entity);
154
+ }
155
+ else if (entity.type == 'MULTILEADER' || entity.type == 'MLEADER') {
156
+ return this.convertMLeader(entity);
157
+ }
141
158
  else if (entity.type == 'POLYLINE') {
142
159
  return this.convertPolyline(entity);
143
160
  }
@@ -616,16 +633,331 @@ var AcDbEntityConverter = /** @class */ (function () {
616
633
  return dbEntity;
617
634
  };
618
635
  AcDbEntityConverter.prototype.convertLeader = function (leader) {
636
+ var _a, _b, _c, _d, _e;
619
637
  var dbEntity = new AcDbLeader();
620
- leader.vertices.forEach(function (point) {
638
+ (_a = leader.vertices) === null || _a === void 0 ? void 0 : _a.forEach(function (point) {
621
639
  dbEntity.appendVertex(point);
622
640
  });
623
641
  dbEntity.hasArrowHead = leader.isArrowheadEnabled;
624
642
  dbEntity.hasHookLine = leader.isHooklineExists;
643
+ dbEntity.isHookLineSameDirection = leader.isHooklineSameDirection;
625
644
  dbEntity.isSplined = leader.isSpline;
626
- dbEntity.dimensionStyle = leader.styleName;
645
+ dbEntity.dimensionStyle = (_b = leader.styleName) !== null && _b !== void 0 ? _b : '';
627
646
  dbEntity.annoType =
628
647
  leader.leaderCreationFlag;
648
+ dbEntity.textHeight = (_c = leader.textHeight) !== null && _c !== void 0 ? _c : 0;
649
+ dbEntity.textWidth = (_d = leader.textWidth) !== null && _d !== void 0 ? _d : 0;
650
+ dbEntity.byBlockColor = leader.byBlockColor;
651
+ dbEntity.associatedAnnotation = (_e = leader.associatedAnnotation) !== null && _e !== void 0 ? _e : '';
652
+ if (leader.normal)
653
+ dbEntity.normal = leader.normal;
654
+ if (leader.horizontalDirection) {
655
+ dbEntity.horizontalDirection = leader.horizontalDirection;
656
+ }
657
+ if (leader.offsetFromBlock)
658
+ dbEntity.offsetFromBlock = leader.offsetFromBlock;
659
+ if (leader.offsetFromAnnotation) {
660
+ dbEntity.offsetFromAnnotation = leader.offsetFromAnnotation;
661
+ }
662
+ return dbEntity;
663
+ };
664
+ AcDbEntityConverter.prototype.convertMLine = function (mline) {
665
+ var _this = this;
666
+ var _a;
667
+ var dbEntity = new AcDbMLine();
668
+ var raw = mline;
669
+ dbEntity.styleName = mline.name;
670
+ dbEntity.styleObjectHandle = mline.styleObjectHandle;
671
+ dbEntity.scale = mline.scale;
672
+ dbEntity.justification =
673
+ mline.justification;
674
+ dbEntity.flags = mline.flags;
675
+ dbEntity.styleCount = mline.styleCount;
676
+ dbEntity.startPosition = mline.startPosition;
677
+ dbEntity.normal = (_a = mline.extrusionDirection) !== null && _a !== void 0 ? _a : AcGeVector3d.Z_AXIS;
678
+ if (Array.isArray(mline.segments) && mline.segments.length > 0) {
679
+ dbEntity.segments = mline.segments.map(function (segment) {
680
+ var _a, _b;
681
+ return ({
682
+ position: segment.position,
683
+ direction: segment.direction,
684
+ miterDirection: segment.miterDirection,
685
+ elements: (_b = (_a = segment.elements) === null || _a === void 0 ? void 0 : _a.map(function (element) {
686
+ var _a, _b;
687
+ return ({
688
+ parameterCount: element.parameterCount,
689
+ parameters: (_a = element.parameters) !== null && _a !== void 0 ? _a : [],
690
+ fillCount: element.fillCount,
691
+ fillParameters: (_b = element.fillParameters) !== null && _b !== void 0 ? _b : []
692
+ });
693
+ })) !== null && _b !== void 0 ? _b : []
694
+ });
695
+ });
696
+ }
697
+ else {
698
+ var vertices_1 = Array.isArray(raw.vertices)
699
+ ? raw.vertices.filter(function (point) { return _this.isPointLike(point); })
700
+ : [];
701
+ var segmentDirections_1 = Array.isArray(raw.segmentDirections)
702
+ ? raw.segmentDirections.filter(function (point) { return _this.isPointLike(point); })
703
+ : [];
704
+ var miterDirections_1 = Array.isArray(raw.miterDirections)
705
+ ? raw.miterDirections.filter(function (point) { return _this.isPointLike(point); })
706
+ : [];
707
+ var count = Math.min(vertices_1.length, segmentDirections_1.length, miterDirections_1.length);
708
+ if (count > 0) {
709
+ dbEntity.segments = Array.from({ length: count }, function (_, index) { return ({
710
+ position: vertices_1[index],
711
+ direction: segmentDirections_1[index],
712
+ miterDirection: miterDirections_1[index],
713
+ elements: []
714
+ }); });
715
+ }
716
+ }
717
+ return dbEntity;
718
+ };
719
+ AcDbEntityConverter.prototype.convertMLeader = function (mleader) {
720
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
721
+ var dbEntity = new AcDbMLeader();
722
+ var raw = mleader;
723
+ dbEntity.version = mleader.version;
724
+ dbEntity.leaderStyleId = mleader.leaderStyleId;
725
+ if (mleader.leaderStyleId)
726
+ dbEntity.mleaderStyleId = mleader.leaderStyleId;
727
+ dbEntity.propertyOverrideFlag = mleader.propertyOverrideFlag;
728
+ dbEntity.leaderLineType = ((_a = mleader.leaderLineType) !== null && _a !== void 0 ? _a : AcDbMLeaderLineType.StraightLeader);
729
+ dbEntity.leaderLineColor = mleader.leaderLineColor;
730
+ dbEntity.leaderLineTypeId = mleader.leaderLineTypeId;
731
+ dbEntity.leaderLineWeight = mleader.leaderLineWeight;
732
+ dbEntity.landingEnabled = mleader.landingEnabled;
733
+ dbEntity.doglegEnabled = (_b = mleader.doglegEnabled) !== null && _b !== void 0 ? _b : false;
734
+ dbEntity.doglegLength = (_c = mleader.doglegLength) !== null && _c !== void 0 ? _c : 0;
735
+ dbEntity.arrowheadId = mleader.arrowheadId;
736
+ dbEntity.arrowheadSize = mleader.arrowheadSize;
737
+ dbEntity.textStyleId = mleader.textStyleId;
738
+ dbEntity.textLeftAttachmentType = mleader.textLeftAttachmentType;
739
+ dbEntity.textRightAttachmentType = mleader.textRightAttachmentType;
740
+ dbEntity.textAngleType = mleader.textAngleType;
741
+ dbEntity.textAlignmentType = mleader.textAlignmentType;
742
+ dbEntity.textColor = mleader.textColor;
743
+ dbEntity.textFrameEnabled = mleader.textFrameEnabled;
744
+ dbEntity.landingGap = mleader.landingGap;
745
+ dbEntity.textAttachment = mleader.textAttachment;
746
+ dbEntity.textFlowDirection = mleader.textFlowDirection;
747
+ dbEntity.blockContentId = mleader.blockContentId;
748
+ dbEntity.blockContentColor = mleader.blockContentColor;
749
+ dbEntity.blockContentRotation = mleader.blockContentRotation;
750
+ dbEntity.blockContentConnectionType = mleader.blockContentConnectionType;
751
+ dbEntity.annotativeScaleEnabled = mleader.annotativeScaleEnabled;
752
+ dbEntity.arrowheadOverrides = mleader.arrowheadOverrides
753
+ ? mleader.arrowheadOverrides.map(function (item) { return (__assign({}, item)); })
754
+ : [];
755
+ dbEntity.blockAttributes = mleader.blockAttributes
756
+ ? mleader.blockAttributes.map(function (item) { return (__assign({}, item)); })
757
+ : [];
758
+ dbEntity.textDirectionNegative = mleader.textDirectionNegative;
759
+ dbEntity.textAlignInIPE = mleader.textAlignInIPE;
760
+ dbEntity.bottomTextAttachmentDirection =
761
+ mleader.bottomTextAttachmentDirection;
762
+ dbEntity.topTextAttachmentDirection = mleader.topTextAttachmentDirection;
763
+ dbEntity.contentScale = mleader.contentScale;
764
+ dbEntity.textLineSpacingStyle = mleader.textLineSpacingStyle;
765
+ dbEntity.textBackgroundColor = mleader.textBackgroundColor;
766
+ dbEntity.textBackgroundScaleFactor = mleader.textBackgroundScaleFactor;
767
+ dbEntity.textBackgroundTransparency = mleader.textBackgroundTransparency;
768
+ dbEntity.textBackgroundColorOn = mleader.textBackgroundColorOn;
769
+ dbEntity.textFillOn = mleader.textFillOn;
770
+ dbEntity.textColumnType = mleader.textColumnType;
771
+ dbEntity.textUseAutoHeight = mleader.textUseAutoHeight;
772
+ dbEntity.textColumnWidth = mleader.textColumnWidth;
773
+ dbEntity.textColumnGutterWidth = mleader.textColumnGutterWidth;
774
+ dbEntity.textColumnFlowReversed = mleader.textColumnFlowReversed;
775
+ dbEntity.textColumnHeight = mleader.textColumnHeight;
776
+ dbEntity.textUseWordBreak = mleader.textUseWordBreak;
777
+ dbEntity.hasMText = mleader.hasMText;
778
+ dbEntity.hasBlock = mleader.hasBlock;
779
+ dbEntity.planeNormalReversed = mleader.planeNormalReversed;
780
+ if (mleader.blockContentScale) {
781
+ dbEntity.blockContentScale = new AcGeVector3d(mleader.blockContentScale);
782
+ }
783
+ if (mleader.contentBasePosition) {
784
+ dbEntity.contentBasePosition = new AcGePoint3d().copy(mleader.contentBasePosition);
785
+ }
786
+ if (mleader.textAnchor) {
787
+ dbEntity.textAnchor = new AcGePoint3d().copy(mleader.textAnchor);
788
+ }
789
+ if (mleader.planeOrigin) {
790
+ dbEntity.planeOrigin = new AcGePoint3d().copy(mleader.planeOrigin);
791
+ }
792
+ if (mleader.planeXAxisDirection) {
793
+ dbEntity.planeXAxisDirection = new AcGeVector3d(mleader.planeXAxisDirection);
794
+ }
795
+ if (mleader.planeYAxisDirection) {
796
+ dbEntity.planeYAxisDirection = new AcGeVector3d(mleader.planeYAxisDirection);
797
+ }
798
+ var rawTextContent = raw.textContent;
799
+ var rawTextContentRecord = rawTextContent && typeof rawTextContent === 'object'
800
+ ? rawTextContent
801
+ : undefined;
802
+ var hasMTextContent = (typeof rawTextContent === 'string' && rawTextContent.length > 0) ||
803
+ this.readString(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, ['text', 'contents']) !=
804
+ null ||
805
+ this.readString(raw, ['text', 'contents', 'mtext']) != null;
806
+ var contentType = (_d = mleader.contentType) !== null && _d !== void 0 ? _d : (hasMTextContent
807
+ ? AcDbMLeaderContentType.MTextContent
808
+ : mleader.blockContent
809
+ ? AcDbMLeaderContentType.BlockContent
810
+ : AcDbMLeaderContentType.NoneContent);
811
+ dbEntity.contentType = contentType;
812
+ var normal = this.readPoint(raw, ['normal', 'extrusionDirection']);
813
+ if (normal)
814
+ dbEntity.normal = normal;
815
+ var textStyleName = (_e = this.readString(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
816
+ 'styleName',
817
+ 'textStyleName',
818
+ 'textStyle'
819
+ ])) !== null && _e !== void 0 ? _e : this.readString(raw, [
820
+ 'textStyleName',
821
+ 'textStyle',
822
+ 'styleName',
823
+ 'textStyleId'
824
+ ]);
825
+ if (textStyleName)
826
+ dbEntity.textStyleName = textStyleName;
827
+ var textHeight = (_g = (_f = this.readPositiveNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
828
+ 'textHeight',
829
+ 'height'
830
+ ])) !== null && _f !== void 0 ? _f : this.readPositiveNumber(raw, [
831
+ 'textHeight',
832
+ 'mtextHeight',
833
+ 'textContentHeight'
834
+ ])) !== null && _g !== void 0 ? _g : this.readPositiveNumber(raw, ['arrowheadSize', 'contentScale']);
835
+ if (textHeight != null)
836
+ dbEntity.textHeight = textHeight;
837
+ var textWidth = (_h = this.readPositiveNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
838
+ 'textWidth',
839
+ 'width'
840
+ ])) !== null && _h !== void 0 ? _h : this.readPositiveNumber(raw, [
841
+ 'textWidth',
842
+ 'mtextWidth',
843
+ 'textContentWidth'
844
+ ]);
845
+ if (textWidth != null)
846
+ dbEntity.textWidth = textWidth;
847
+ dbEntity.textLineSpacingFactor =
848
+ (_k = (_j = this.readNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
849
+ 'lineSpacingFactor',
850
+ 'textLineSpacingFactor'
851
+ ])) !== null && _j !== void 0 ? _j : this.readNumber(raw, ['textLineSpacingFactor'])) !== null && _k !== void 0 ? _k : dbEntity.textLineSpacingFactor;
852
+ var textRotation = (_l = this.readNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
853
+ 'textRotation',
854
+ 'rotation'
855
+ ])) !== null && _l !== void 0 ? _l : this.readNumber(raw, [
856
+ 'textRotation',
857
+ 'mtextRotation',
858
+ 'textContentRotation'
859
+ ]);
860
+ if (textRotation != null) {
861
+ dbEntity.textRotation = AcGeMathUtil.degToRad(textRotation);
862
+ }
863
+ var textDirection = this.readPoint(raw, [
864
+ 'textDirection',
865
+ 'mtextDirection',
866
+ 'textDirectionVector'
867
+ ]);
868
+ if (textDirection)
869
+ dbEntity.textDirection = textDirection;
870
+ var textAttachmentPoint = this.readNumber(raw, [
871
+ 'textAttachmentPoint',
872
+ 'attachmentPoint'
873
+ ]);
874
+ if (textAttachmentPoint != null) {
875
+ dbEntity.textAttachmentPoint =
876
+ textAttachmentPoint;
877
+ }
878
+ var textAttachmentDirection = mleader.textAttachmentDirection;
879
+ if (textAttachmentDirection != null) {
880
+ dbEntity.textAttachmentDirection =
881
+ textAttachmentDirection;
882
+ }
883
+ var textDrawingDirection = this.readNumber(raw, [
884
+ 'textDrawingDirection',
885
+ 'drawingDirection'
886
+ ]);
887
+ if (textDrawingDirection != null) {
888
+ dbEntity.textDrawingDirection =
889
+ textDrawingDirection;
890
+ }
891
+ var text = typeof rawTextContent === 'string'
892
+ ? rawTextContent
893
+ : ((_m = this.readString(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, ['text', 'contents'])) !== null && _m !== void 0 ? _m : this.readString(raw, ['text', 'contents', 'mtext']));
894
+ var anchorPoint = (_o = this.readPoint(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
895
+ 'anchorPoint',
896
+ 'textAnchor',
897
+ 'textLocation',
898
+ 'textPosition',
899
+ 'textAnchorPoint'
900
+ ])) !== null && _o !== void 0 ? _o : this.readPoint(raw, [
901
+ 'textAnchor',
902
+ 'textLocation',
903
+ 'textPosition',
904
+ 'textAnchorPoint',
905
+ 'contentBasePosition'
906
+ ]);
907
+ if (text != null && anchorPoint) {
908
+ dbEntity.mtextContent = { text: text, anchorPoint: anchorPoint };
909
+ }
910
+ if (mleader.blockContent) {
911
+ var blockRecord = mleader.blockContent;
912
+ dbEntity.blockContent = {
913
+ blockContentId: mleader.blockContent.blockContentId,
914
+ normal: this.readPoint(blockRecord, ['normal']),
915
+ position: mleader.blockContent.position,
916
+ scale: this.readPoint(blockRecord, ['scale']),
917
+ rotation: this.readNumber(blockRecord, ['rotation']),
918
+ color: this.readNumber(blockRecord, ['color']),
919
+ transformationMatrix: Array.isArray(mleader.blockContent.transformationMatrix)
920
+ ? mleader.blockContent.transformationMatrix
921
+ : []
922
+ };
923
+ }
924
+ else if (mleader.blockContentId) {
925
+ dbEntity.blockContent = {
926
+ blockContentId: mleader.blockContentId,
927
+ scale: mleader.blockContentScale,
928
+ rotation: mleader.blockContentRotation,
929
+ color: mleader.blockContentColor,
930
+ transformationMatrix: []
931
+ };
932
+ }
933
+ (_p = this.readMLeaderLeaders(raw)) === null || _p === void 0 ? void 0 : _p.forEach(function (leader) {
934
+ var _a;
935
+ dbEntity.addLeader({
936
+ lastLeaderLinePoint: leader.lastLeaderLinePoint,
937
+ lastLeaderLinePointSet: leader.lastLeaderLinePointSet,
938
+ doglegVector: leader.doglegVector,
939
+ doglegVectorSet: leader.doglegVectorSet,
940
+ doglegLength: (_a = leader.doglegLength) !== null && _a !== void 0 ? _a : mleader.doglegLength,
941
+ breaks: leader.breaks,
942
+ leaderBranchIndex: leader.leaderBranchIndex,
943
+ leaderLines: leader.leaderLines
944
+ });
945
+ });
946
+ if (dbEntity.numberOfLeaders === 0) {
947
+ (_q = this.readLeaderLineArray(raw)) === null || _q === void 0 ? void 0 : _q.forEach(function (line) {
948
+ dbEntity.addLeader({
949
+ doglegLength: mleader.doglegLength
950
+ });
951
+ dbEntity.addLeaderLine(dbEntity.numberOfLeaders - 1, line);
952
+ });
953
+ }
954
+ if (dbEntity.numberOfLeaders === 0 && mleader.contentBasePosition) {
955
+ dbEntity.addLeader({
956
+ lastLeaderLinePoint: mleader.contentBasePosition,
957
+ lastLeaderLinePointSet: true,
958
+ doglegLength: mleader.doglegLength
959
+ });
960
+ }
629
961
  return dbEntity;
630
962
  };
631
963
  AcDbEntityConverter.prototype.convertDimension = function (dimension) {
@@ -844,6 +1176,223 @@ var AcDbEntityConverter = /** @class */ (function () {
844
1176
  dbEntity.transparency = AcCmTransparency.deserialize(entity.transparency);
845
1177
  }
846
1178
  };
1179
+ AcDbEntityConverter.prototype.readNumber = function (source, names) {
1180
+ var e_1, _a;
1181
+ try {
1182
+ for (var names_1 = __values(names), names_1_1 = names_1.next(); !names_1_1.done; names_1_1 = names_1.next()) {
1183
+ var name_1 = names_1_1.value;
1184
+ var value = source[name_1];
1185
+ if (typeof value === 'number' && Number.isFinite(value))
1186
+ return value;
1187
+ }
1188
+ }
1189
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1190
+ finally {
1191
+ try {
1192
+ if (names_1_1 && !names_1_1.done && (_a = names_1.return)) _a.call(names_1);
1193
+ }
1194
+ finally { if (e_1) throw e_1.error; }
1195
+ }
1196
+ return undefined;
1197
+ };
1198
+ AcDbEntityConverter.prototype.readPositiveNumber = function (source, names) {
1199
+ var value = this.readNumber(source, names);
1200
+ return value != null && value > 0 ? value : undefined;
1201
+ };
1202
+ AcDbEntityConverter.prototype.readString = function (source, names) {
1203
+ var e_2, _a;
1204
+ try {
1205
+ for (var names_2 = __values(names), names_2_1 = names_2.next(); !names_2_1.done; names_2_1 = names_2.next()) {
1206
+ var name_2 = names_2_1.value;
1207
+ var value = source[name_2];
1208
+ if (typeof value === 'string')
1209
+ return value;
1210
+ }
1211
+ }
1212
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1213
+ finally {
1214
+ try {
1215
+ if (names_2_1 && !names_2_1.done && (_a = names_2.return)) _a.call(names_2);
1216
+ }
1217
+ finally { if (e_2) throw e_2.error; }
1218
+ }
1219
+ return undefined;
1220
+ };
1221
+ AcDbEntityConverter.prototype.readBoolean = function (source, names) {
1222
+ var e_3, _a;
1223
+ try {
1224
+ for (var names_3 = __values(names), names_3_1 = names_3.next(); !names_3_1.done; names_3_1 = names_3.next()) {
1225
+ var name_3 = names_3_1.value;
1226
+ var value = source[name_3];
1227
+ if (typeof value === 'boolean')
1228
+ return value;
1229
+ if (typeof value === 'number')
1230
+ return value !== 0;
1231
+ }
1232
+ }
1233
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1234
+ finally {
1235
+ try {
1236
+ if (names_3_1 && !names_3_1.done && (_a = names_3.return)) _a.call(names_3);
1237
+ }
1238
+ finally { if (e_3) throw e_3.error; }
1239
+ }
1240
+ return undefined;
1241
+ };
1242
+ AcDbEntityConverter.prototype.readPoint = function (source, names) {
1243
+ var e_4, _a;
1244
+ var _b;
1245
+ try {
1246
+ for (var names_4 = __values(names), names_4_1 = names_4.next(); !names_4_1.done; names_4_1 = names_4.next()) {
1247
+ var name_4 = names_4_1.value;
1248
+ var value = source[name_4];
1249
+ if (this.isPointLike(value))
1250
+ return value;
1251
+ if (Array.isArray(value) &&
1252
+ typeof value[0] === 'number' &&
1253
+ typeof value[1] === 'number') {
1254
+ return { x: value[0], y: value[1], z: (_b = value[2]) !== null && _b !== void 0 ? _b : 0 };
1255
+ }
1256
+ }
1257
+ }
1258
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1259
+ finally {
1260
+ try {
1261
+ if (names_4_1 && !names_4_1.done && (_a = names_4.return)) _a.call(names_4);
1262
+ }
1263
+ finally { if (e_4) throw e_4.error; }
1264
+ }
1265
+ return undefined;
1266
+ };
1267
+ AcDbEntityConverter.prototype.readLeaderLineArray = function (source) {
1268
+ var _this = this;
1269
+ var leaderLines = source.leaderLines;
1270
+ if (Array.isArray(leaderLines)) {
1271
+ return leaderLines
1272
+ .map(function (line) {
1273
+ if (!line || typeof line !== 'object')
1274
+ return undefined;
1275
+ var vertices = line.vertices;
1276
+ return Array.isArray(vertices)
1277
+ ? vertices.filter(function (point) { return _this.isPointLike(point); })
1278
+ : undefined;
1279
+ })
1280
+ .filter(function (line) { return !!line && line.length > 0; });
1281
+ }
1282
+ var vertices = source.vertices;
1283
+ if (Array.isArray(vertices)) {
1284
+ var line = vertices.filter(function (point) { return _this.isPointLike(point); });
1285
+ return line.length > 0 ? [line] : undefined;
1286
+ }
1287
+ return undefined;
1288
+ };
1289
+ AcDbEntityConverter.prototype.readMLeaderLeaders = function (source) {
1290
+ var _this = this;
1291
+ var leaders = source.leaderSections;
1292
+ if (!Array.isArray(leaders))
1293
+ return undefined;
1294
+ var dbLeaders = [];
1295
+ leaders.forEach(function (leader) {
1296
+ if (!leader || typeof leader !== 'object')
1297
+ return;
1298
+ var leaderRecord = leader;
1299
+ var leaderLines = leaderRecord.leaderLines;
1300
+ var lines = Array.isArray(leaderLines)
1301
+ ? leaderLines.reduce(function (result, line) {
1302
+ var dbLine = _this.readMLeaderLine(line);
1303
+ if (dbLine)
1304
+ result.push(dbLine);
1305
+ return result;
1306
+ }, [])
1307
+ : undefined;
1308
+ var dbLeader = {};
1309
+ var lastLeaderLinePoint = _this.readPoint(leaderRecord, [
1310
+ 'lastLeaderLinePoint'
1311
+ ]);
1312
+ var doglegVector = _this.readPoint(leaderRecord, ['doglegVector']);
1313
+ var doglegLength = _this.readNumber(leaderRecord, ['doglegLength']);
1314
+ var leaderBreaks = _this.readMLeaderBreaks(leaderRecord.breaks);
1315
+ var leaderBranchIndex = _this.readNumber(leaderRecord, [
1316
+ 'leaderBranchIndex'
1317
+ ]);
1318
+ if (lastLeaderLinePoint)
1319
+ dbLeader.lastLeaderLinePoint = lastLeaderLinePoint;
1320
+ if (leaderRecord.lastLeaderLinePointSet != null) {
1321
+ dbLeader.lastLeaderLinePointSet = _this.readBoolean(leaderRecord, [
1322
+ 'lastLeaderLinePointSet'
1323
+ ]);
1324
+ }
1325
+ if (doglegVector)
1326
+ dbLeader.doglegVector = doglegVector;
1327
+ if (leaderRecord.doglegVectorSet != null) {
1328
+ dbLeader.doglegVectorSet = _this.readBoolean(leaderRecord, [
1329
+ 'doglegVectorSet'
1330
+ ]);
1331
+ }
1332
+ if (doglegLength != null)
1333
+ dbLeader.doglegLength = doglegLength;
1334
+ if (leaderBreaks)
1335
+ dbLeader.breaks = leaderBreaks;
1336
+ if (leaderBranchIndex != null) {
1337
+ dbLeader.leaderBranchIndex = leaderBranchIndex;
1338
+ }
1339
+ if (lines)
1340
+ dbLeader.leaderLines = lines;
1341
+ dbLeaders.push(dbLeader);
1342
+ });
1343
+ return dbLeaders;
1344
+ };
1345
+ AcDbEntityConverter.prototype.readMLeaderLine = function (value) {
1346
+ var _this = this;
1347
+ if (!value || typeof value !== 'object')
1348
+ return undefined;
1349
+ var lineRecord = value;
1350
+ var vertices = lineRecord.vertices;
1351
+ var dbVertices = Array.isArray(vertices)
1352
+ ? vertices.filter(function (point) { return _this.isPointLike(point); })
1353
+ : [];
1354
+ var dbBreaks = this.readMLeaderBreaks(lineRecord.breaks);
1355
+ var breakPointIndexes = Array.isArray(lineRecord.breakPointIndexes)
1356
+ ? lineRecord.breakPointIndexes.filter(function (item) { return typeof item === 'number'; })
1357
+ : undefined;
1358
+ var leaderLineIndex = this.readNumber(lineRecord, ['leaderLineIndex']);
1359
+ return dbVertices.length > 0 || (dbBreaks && dbBreaks.length > 0)
1360
+ ? {
1361
+ vertices: dbVertices,
1362
+ breakPointIndexes: breakPointIndexes,
1363
+ leaderLineIndex: leaderLineIndex,
1364
+ breaks: dbBreaks
1365
+ }
1366
+ : undefined;
1367
+ };
1368
+ AcDbEntityConverter.prototype.readMLeaderBreaks = function (value) {
1369
+ var _this = this;
1370
+ if (!Array.isArray(value))
1371
+ return undefined;
1372
+ var breaks = value
1373
+ .map(function (item) {
1374
+ if (!item || typeof item !== 'object')
1375
+ return undefined;
1376
+ var breakRecord = item;
1377
+ var start = _this.readPoint(breakRecord, ['start']);
1378
+ var end = _this.readPoint(breakRecord, ['end']);
1379
+ var index = _this.readNumber(breakRecord, ['index']);
1380
+ if (!start || !end)
1381
+ return undefined;
1382
+ var parsed = { start: start, end: end };
1383
+ if (index != null)
1384
+ parsed.index = index;
1385
+ return parsed;
1386
+ })
1387
+ .filter(function (item) { return !!item; });
1388
+ return breaks.length > 0 ? breaks : undefined;
1389
+ };
1390
+ AcDbEntityConverter.prototype.isPointLike = function (value) {
1391
+ return (!!value &&
1392
+ typeof value === 'object' &&
1393
+ typeof value.x === 'number' &&
1394
+ typeof value.y === 'number');
1395
+ };
847
1396
  return AcDbEntityConverter;
848
1397
  }());
849
1398
  export { AcDbEntityConverter };