@mlightcad/libredwg-converter 3.7.5 → 3.7.7

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.
@@ -19,6 +19,7 @@ export declare class AcDbEntityConverter {
19
19
  private convertLine;
20
20
  private convertSpline;
21
21
  private convertPoint;
22
+ private convertShape;
22
23
  private convertSolid;
23
24
  private convertLWPolyline;
24
25
  private convertPolyline2d;
@@ -43,11 +44,18 @@ export declare class AcDbEntityConverter {
43
44
  private convertBlockReference;
44
45
  private processDimensionCommonAttrs;
45
46
  private processCommonAttrs;
47
+ private convertMLeaderEntityColor;
48
+ private readMLeaderEntityColor;
49
+ private isValidHandleId;
46
50
  private readNumber;
51
+ private readPositiveNumber;
47
52
  private readString;
48
53
  private readBoolean;
49
54
  private readPoint;
50
55
  private readLeaderLineArray;
56
+ private readMLeaderLeaders;
57
+ private readMLeaderLine;
58
+ private readMLeaderBreaks;
51
59
  private isPointLike;
52
60
  }
53
61
  //# sourceMappingURL=AcDbEntitiyConverter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AcDbEntitiyConverter.d.ts","sourceRoot":"","sources":["../src/AcDbEntitiyConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAiBL,UAAU,EAsDa,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,EAcV,SAAS,EA2BV,MAAM,yBAAyB,CAAA;AAsDhC,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,IAAI;IAQ7C;;;;OAIG;IACH,OAAO,CAAC,YAAY;IA6DpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAoB1B,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,cAAc;IAetB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,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ined.");
22
22
  };
23
- import { AcCmColor, AcCmTransparency, 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, AcDbProxyEntity, AcDbRadialDimension, AcDbRasterImage, AcDbRay, AcDbRotatedDimension, AcDbSpline, AcDbTable, AcDbText, AcDbTrace, AcDbViewport, AcDbWipeout, AcDbXline, AcGeCircArc2d, AcGeEllipseArc2d, AcGeLine2d, AcGeLoop2d, AcGePoint2d, AcGePoint3d, AcGePolyline2d, AcGeSpline3d, AcGeVector2d, AcGeVector3d, hexStringsToBytes, transformOcsPointToWcs } from '@mlightcad/data-model';
23
+ import { AcCmColor, AcCmTransparency, 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, AcDbProxyEntity, AcDbRadialDimension, AcDbRasterImage, AcDbRay, AcDbRotatedDimension, AcDbShape, AcDbSpline, AcDbTable, AcDbText, AcDbTrace, AcDbViewport, AcDbWipeout, AcDbXline, AcGeCircArc2d, AcGeEllipseArc2d, AcGeLine2d, AcGeLoop2d, AcGePoint2d, AcGePoint3d, AcGePolyline2d, AcGeSpline3d, AcGeVector2d, AcGeVector3d, decodeMLeaderStyleRawColor, hexStringsToBytes, transformOcsPointToWcs } from '@mlightcad/data-model';
24
24
  var AcDbEntityConverter = /** @class */ (function () {
25
25
  function AcDbEntityConverter() {
26
26
  }
@@ -103,6 +103,9 @@ var AcDbEntityConverter = /** @class */ (function () {
103
103
  else if (entity.type == 'TEXT') {
104
104
  return this.convertText(entity);
105
105
  }
106
+ else if (entity.type == 'SHAPE') {
107
+ return this.convertShape(entity);
108
+ }
106
109
  else if (entity.type == 'SOLID') {
107
110
  return this.convertSolid(entity);
108
111
  }
@@ -205,6 +208,23 @@ var AcDbEntityConverter = /** @class */ (function () {
205
208
  dbEntity.position = point.position;
206
209
  return dbEntity;
207
210
  };
211
+ AcDbEntityConverter.prototype.convertShape = function (shape) {
212
+ var _a, _b, _c, _d, _e;
213
+ var normal = (_a = shape.extrusionDirection) !== null && _a !== void 0 ? _a : AcGeVector3d.Z_AXIS;
214
+ var dbEntity = new AcDbShape();
215
+ dbEntity.position = transformOcsPointToWcs(shape.insertionPoint, normal);
216
+ dbEntity.size = shape.size;
217
+ dbEntity.shapeNumber = shape.shapeNumber;
218
+ if (shape.styleName) {
219
+ dbEntity.styleName = shape.styleName;
220
+ }
221
+ dbEntity.rotation = (_b = shape.rotation) !== null && _b !== void 0 ? _b : 0;
222
+ dbEntity.widthFactor = (_c = shape.xScale) !== null && _c !== void 0 ? _c : 1;
223
+ dbEntity.oblique = (_d = shape.obliqueAngle) !== null && _d !== void 0 ? _d : 0;
224
+ dbEntity.thickness = (_e = shape.thickness) !== null && _e !== void 0 ? _e : 0;
225
+ dbEntity.normal.copy(normal);
226
+ return dbEntity;
227
+ };
208
228
  AcDbEntityConverter.prototype.convertSolid = function (solid) {
209
229
  var dbEntity = new AcDbTrace();
210
230
  dbEntity.setPointAt(0, __assign(__assign({}, solid.corner1), { z: 0 }));
@@ -617,58 +637,154 @@ var AcDbEntityConverter = /** @class */ (function () {
617
637
  return dbEntity;
618
638
  };
619
639
  AcDbEntityConverter.prototype.convertMLeader = function (mleader) {
620
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
640
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
621
641
  var dbEntity = new AcDbMLeader();
622
642
  var raw = mleader;
623
- dbEntity.leaderLineType = ((_a = this.readNumber(raw, [
624
- 'multileaderType',
625
- 'leaderLineType',
626
- 'leaderType'
627
- ])) !== null && _a !== void 0 ? _a : AcDbMLeaderLineType.StraightLeader);
628
- var contentType = (_b = this.readNumber(raw, ['contentType'])) !== null && _b !== void 0 ? _b : (mleader.textContent
643
+ dbEntity.version = mleader.version;
644
+ dbEntity.leaderStyleId = mleader.leaderStyleId;
645
+ if (mleader.leaderStyleId)
646
+ dbEntity.mleaderStyleId = mleader.leaderStyleId;
647
+ dbEntity.propertyOverrideFlag = mleader.propertyOverrideFlag;
648
+ dbEntity.leaderLineType = ((_a = mleader.leaderLineType) !== null && _a !== void 0 ? _a : AcDbMLeaderLineType.StraightLeader);
649
+ if (mleader.leaderLineColor != null) {
650
+ dbEntity.leaderLineColor = this.convertMLeaderEntityColor(mleader.leaderLineColor);
651
+ }
652
+ dbEntity.leaderLineTypeId = mleader.leaderLineTypeId;
653
+ dbEntity.leaderLineWeight = mleader.leaderLineWeight;
654
+ dbEntity.landingEnabled = mleader.landingEnabled;
655
+ dbEntity.doglegEnabled = (_b = mleader.doglegEnabled) !== null && _b !== void 0 ? _b : false;
656
+ dbEntity.doglegLength = (_c = mleader.doglegLength) !== null && _c !== void 0 ? _c : 0;
657
+ dbEntity.arrowheadId = mleader.arrowheadId;
658
+ dbEntity.arrowheadSize = mleader.arrowheadSize;
659
+ dbEntity.textStyleId = mleader.textStyleId;
660
+ dbEntity.textLeftAttachmentType = mleader.textLeftAttachmentType;
661
+ dbEntity.textRightAttachmentType = mleader.textRightAttachmentType;
662
+ dbEntity.textAngleType = mleader.textAngleType;
663
+ dbEntity.textAlignmentType = mleader.textAlignmentType;
664
+ if (mleader.textColor != null) {
665
+ dbEntity.textColor = this.convertMLeaderEntityColor(mleader.textColor);
666
+ }
667
+ dbEntity.textFrameEnabled = mleader.textFrameEnabled;
668
+ dbEntity.landingGap = mleader.landingGap;
669
+ dbEntity.textAttachment = mleader.textAttachment;
670
+ dbEntity.textFlowDirection = mleader.textFlowDirection;
671
+ if (this.isValidHandleId(mleader.blockContentId)) {
672
+ dbEntity.blockContentId = mleader.blockContentId;
673
+ }
674
+ if (mleader.blockContentColor != null) {
675
+ dbEntity.blockContentColor = this.convertMLeaderEntityColor(mleader.blockContentColor);
676
+ }
677
+ dbEntity.blockContentRotation = mleader.blockContentRotation;
678
+ dbEntity.blockContentConnectionType = mleader.blockContentConnectionType;
679
+ dbEntity.annotativeScaleEnabled = mleader.annotativeScaleEnabled;
680
+ dbEntity.arrowheadOverrides = mleader.arrowheadOverrides
681
+ ? mleader.arrowheadOverrides.map(function (item) { return (__assign({}, item)); })
682
+ : [];
683
+ dbEntity.blockAttributes = mleader.blockAttributes
684
+ ? mleader.blockAttributes.map(function (item) { return (__assign({}, item)); })
685
+ : [];
686
+ dbEntity.textDirectionNegative = mleader.textDirectionNegative;
687
+ dbEntity.textAlignInIPE = mleader.textAlignInIPE;
688
+ dbEntity.bottomTextAttachmentDirection =
689
+ mleader.bottomTextAttachmentDirection;
690
+ dbEntity.topTextAttachmentDirection = mleader.topTextAttachmentDirection;
691
+ dbEntity.contentScale = mleader.contentScale;
692
+ dbEntity.textLineSpacingStyle = mleader.textLineSpacingStyle;
693
+ if (mleader.textBackgroundColor != null) {
694
+ dbEntity.textBackgroundColor = this.convertMLeaderEntityColor(mleader.textBackgroundColor);
695
+ }
696
+ dbEntity.textBackgroundScaleFactor = mleader.textBackgroundScaleFactor;
697
+ dbEntity.textBackgroundTransparency = mleader.textBackgroundTransparency;
698
+ dbEntity.textBackgroundColorOn = mleader.textBackgroundColorOn;
699
+ dbEntity.textFillOn = mleader.textFillOn;
700
+ dbEntity.textColumnType = mleader.textColumnType;
701
+ dbEntity.textUseAutoHeight = mleader.textUseAutoHeight;
702
+ dbEntity.textColumnWidth = mleader.textColumnWidth;
703
+ dbEntity.textColumnGutterWidth = mleader.textColumnGutterWidth;
704
+ dbEntity.textColumnFlowReversed = mleader.textColumnFlowReversed;
705
+ dbEntity.textColumnHeight = mleader.textColumnHeight;
706
+ dbEntity.textUseWordBreak = mleader.textUseWordBreak;
707
+ dbEntity.hasMText = mleader.hasMText;
708
+ dbEntity.hasBlock = mleader.hasBlock;
709
+ dbEntity.planeNormalReversed = mleader.planeNormalReversed;
710
+ if (mleader.blockContentScale) {
711
+ dbEntity.blockContentScale = new AcGeVector3d(mleader.blockContentScale);
712
+ }
713
+ if (mleader.contentBasePosition) {
714
+ dbEntity.contentBasePosition = new AcGePoint3d().copy(mleader.contentBasePosition);
715
+ }
716
+ if (mleader.textAnchor) {
717
+ dbEntity.textAnchor = new AcGePoint3d().copy(mleader.textAnchor);
718
+ }
719
+ if (mleader.planeOrigin) {
720
+ dbEntity.planeOrigin = new AcGePoint3d().copy(mleader.planeOrigin);
721
+ }
722
+ if (mleader.planeXAxisDirection) {
723
+ dbEntity.planeXAxisDirection = new AcGeVector3d(mleader.planeXAxisDirection);
724
+ }
725
+ if (mleader.planeYAxisDirection) {
726
+ dbEntity.planeYAxisDirection = new AcGeVector3d(mleader.planeYAxisDirection);
727
+ }
728
+ var rawTextContent = raw.textContent;
729
+ var rawTextContentRecord = rawTextContent && typeof rawTextContent === 'object'
730
+ ? rawTextContent
731
+ : undefined;
732
+ var hasMTextContent = (typeof rawTextContent === 'string' && rawTextContent.length > 0) ||
733
+ this.readString(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, ['text', 'contents']) !=
734
+ null ||
735
+ this.readString(raw, ['text', 'contents', 'mtext']) != null;
736
+ var contentType = (_d = mleader.contentType) !== null && _d !== void 0 ? _d : (hasMTextContent
629
737
  ? AcDbMLeaderContentType.MTextContent
630
738
  : mleader.blockContent
631
739
  ? AcDbMLeaderContentType.BlockContent
632
740
  : AcDbMLeaderContentType.NoneContent);
633
741
  dbEntity.contentType = contentType;
634
- dbEntity.doglegEnabled =
635
- (_c = this.readBoolean(raw, ['doglegEnabled', 'enableDogleg'])) !== null && _c !== void 0 ? _c : false;
636
- dbEntity.doglegLength = (_d = this.readNumber(raw, ['doglegLength'])) !== null && _d !== void 0 ? _d : 0;
637
- if (mleader.landingPoint)
638
- dbEntity.landingPoint = mleader.landingPoint;
639
- if (mleader.doglegVector)
640
- dbEntity.doglegVector = mleader.doglegVector;
641
- var styleId = this.readString(raw, [
642
- 'mleaderStyleId',
643
- 'mLeaderStyleId',
644
- 'mleaderStyleHandle',
645
- 'styleHandle',
646
- 'styleName'
647
- ]);
648
- if (styleId)
649
- dbEntity.mleaderStyleId = styleId;
650
742
  var normal = this.readPoint(raw, ['normal', 'extrusionDirection']);
651
743
  if (normal)
652
744
  dbEntity.normal = normal;
653
- var textContent = mleader.textContent;
654
- var textStyleName = (_e = this.readString(textContent !== null && textContent !== void 0 ? textContent : {}, ['styleName', 'textStyleName'])) !== null && _e !== void 0 ? _e : this.readString(raw, ['textStyleName', 'textStyle', 'styleName']);
745
+ var textStyleName = (_e = this.readString(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
746
+ 'styleName',
747
+ 'textStyleName',
748
+ 'textStyle'
749
+ ])) !== null && _e !== void 0 ? _e : this.readString(raw, ['textStyleName', 'textStyle', 'styleName']);
655
750
  if (textStyleName)
656
751
  dbEntity.textStyleName = textStyleName;
657
- dbEntity.textHeight =
658
- (_g = (_f = this.readNumber(textContent !== null && textContent !== void 0 ? textContent : {}, ['textHeight', 'height'])) !== null && _f !== void 0 ? _f : this.readNumber(raw, [
659
- 'textHeight',
660
- 'mtextHeight',
661
- 'textContentHeight'
662
- ])) !== null && _g !== void 0 ? _g : dbEntity.textHeight;
663
- dbEntity.textWidth =
664
- (_j = (_h = this.readNumber(textContent !== null && textContent !== void 0 ? textContent : {}, ['textWidth', 'width'])) !== null && _h !== void 0 ? _h : this.readNumber(raw, ['textWidth', 'mtextWidth', 'textContentWidth'])) !== null && _j !== void 0 ? _j : dbEntity.textWidth;
665
- var textRotation = (_k = this.readNumber(textContent !== null && textContent !== void 0 ? textContent : {}, ['textRotation', 'rotation'])) !== null && _k !== void 0 ? _k : this.readNumber(raw, [
752
+ var textHeight = (_g = (_f = this.readPositiveNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
753
+ 'textHeight',
754
+ 'height'
755
+ ])) !== null && _f !== void 0 ? _f : this.readPositiveNumber(raw, [
756
+ 'textHeight',
757
+ 'mtextHeight',
758
+ 'textContentHeight'
759
+ ])) !== null && _g !== void 0 ? _g : this.readPositiveNumber(raw, ['arrowheadSize', 'contentScale']);
760
+ if (textHeight != null)
761
+ dbEntity.textHeight = textHeight;
762
+ var textWidth = (_h = this.readPositiveNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
763
+ 'textWidth',
764
+ 'width'
765
+ ])) !== null && _h !== void 0 ? _h : this.readPositiveNumber(raw, [
766
+ 'textWidth',
767
+ 'mtextWidth',
768
+ 'textContentWidth'
769
+ ]);
770
+ if (textWidth != null)
771
+ dbEntity.textWidth = textWidth;
772
+ dbEntity.textLineSpacingFactor =
773
+ (_k = (_j = this.readNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
774
+ 'lineSpacingFactor',
775
+ 'textLineSpacingFactor'
776
+ ])) !== null && _j !== void 0 ? _j : this.readNumber(raw, ['textLineSpacingFactor'])) !== null && _k !== void 0 ? _k : dbEntity.textLineSpacingFactor;
777
+ var textRotation = (_l = this.readNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
778
+ 'textRotation',
779
+ 'rotation'
780
+ ])) !== null && _l !== void 0 ? _l : this.readNumber(raw, [
666
781
  'textRotation',
667
782
  'mtextRotation',
668
783
  'textContentRotation'
669
784
  ]);
670
- if (textRotation != null)
785
+ if (textRotation != null) {
671
786
  dbEntity.textRotation = textRotation;
787
+ }
672
788
  var textDirection = this.readPoint(raw, [
673
789
  'textDirection',
674
790
  'mtextDirection',
@@ -680,10 +796,15 @@ var AcDbEntityConverter = /** @class */ (function () {
680
796
  'textAttachmentPoint',
681
797
  'attachmentPoint'
682
798
  ]);
683
- if (textAttachmentPoint != null) {
799
+ if (textAttachmentPoint != null && textAttachmentPoint !== 0) {
684
800
  dbEntity.textAttachmentPoint =
685
801
  textAttachmentPoint;
686
802
  }
803
+ var textAttachmentDirection = mleader.textAttachmentDirection;
804
+ if (textAttachmentDirection != null) {
805
+ dbEntity.textAttachmentDirection =
806
+ textAttachmentDirection;
807
+ }
687
808
  var textDrawingDirection = this.readNumber(raw, [
688
809
  'textDrawingDirection',
689
810
  'drawingDirection'
@@ -692,69 +813,78 @@ var AcDbEntityConverter = /** @class */ (function () {
692
813
  dbEntity.textDrawingDirection =
693
814
  textDrawingDirection;
694
815
  }
695
- if (((_l = mleader.textContent) === null || _l === void 0 ? void 0 : _l.text) != null && mleader.textContent.anchorPoint) {
696
- dbEntity.mtextContent = {
697
- text: mleader.textContent.text,
698
- anchorPoint: mleader.textContent.anchorPoint
699
- };
700
- }
701
- else {
702
- var text = this.readString(raw, ['text', 'contents', 'mtext']);
703
- var anchorPoint = this.readPoint(raw, [
704
- 'textLocation',
705
- 'textPosition',
706
- 'textAnchorPoint'
707
- ]);
708
- if (text != null && anchorPoint) {
709
- dbEntity.mtextContent = { text: text, anchorPoint: anchorPoint };
816
+ var text = typeof rawTextContent === 'string'
817
+ ? rawTextContent
818
+ : ((_m = this.readString(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, ['text', 'contents'])) !== null && _m !== void 0 ? _m : this.readString(raw, ['text', 'contents', 'mtext']));
819
+ var anchorPoint = (_o = this.readPoint(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
820
+ 'anchorPoint',
821
+ 'textAnchor',
822
+ 'textLocation',
823
+ 'textPosition',
824
+ 'textAnchorPoint'
825
+ ])) !== null && _o !== void 0 ? _o : this.readPoint(raw, [
826
+ 'textAnchor',
827
+ 'textLocation',
828
+ 'textPosition',
829
+ 'textAnchorPoint',
830
+ 'contentBasePosition'
831
+ ]);
832
+ if (text != null && anchorPoint) {
833
+ dbEntity.mtextContent = { text: text, anchorPoint: anchorPoint };
834
+ }
835
+ if (mleader.blockContent) {
836
+ var blockRecord = mleader.blockContent;
837
+ var blockContentId = mleader.blockContent.blockContentId;
838
+ if (this.isValidHandleId(blockContentId)) {
839
+ var rawBlockColor = this.readMLeaderEntityColor(blockRecord, ['color']);
840
+ dbEntity.blockContent = {
841
+ blockContentId: blockContentId,
842
+ normal: this.readPoint(blockRecord, ['normal']),
843
+ position: mleader.blockContent.position,
844
+ scale: this.readPoint(blockRecord, ['scale']),
845
+ rotation: this.readNumber(blockRecord, ['rotation']),
846
+ color: rawBlockColor,
847
+ transformationMatrix: Array.isArray(mleader.blockContent.transformationMatrix)
848
+ ? mleader.blockContent.transformationMatrix
849
+ : []
850
+ };
710
851
  }
711
852
  }
712
- if (((_m = mleader.blockContent) === null || _m === void 0 ? void 0 : _m.blockHandle) && mleader.blockContent.position) {
853
+ else if (this.isValidHandleId(mleader.blockContentId)) {
713
854
  dbEntity.blockContent = {
714
- blockHandle: mleader.blockContent.blockHandle,
715
- position: mleader.blockContent.position
855
+ blockContentId: mleader.blockContentId,
856
+ scale: mleader.blockContentScale,
857
+ rotation: mleader.blockContentRotation,
858
+ color: dbEntity.blockContentColor,
859
+ transformationMatrix: []
716
860
  };
717
861
  }
718
- else {
719
- var blockHandle = this.readString(raw, [
720
- 'blockHandle',
721
- 'blockContentHandle',
722
- 'blockId'
723
- ]);
724
- var blockPosition = this.readPoint(raw, [
725
- 'blockPosition',
726
- 'blockContentPosition'
727
- ]);
728
- if (blockHandle && blockPosition) {
729
- dbEntity.blockContent = {
730
- blockHandle: blockHandle,
731
- position: blockPosition
732
- };
733
- }
734
- }
735
- (_o = mleader.leaders) === null || _o === void 0 ? void 0 : _o.forEach(function (leader) {
736
- var _a, _b, _c, _d;
737
- var leaderIndex = dbEntity.addLeader({
738
- landingPoint: (_a = leader.landingPoint) !== null && _a !== void 0 ? _a : mleader.landingPoint,
739
- doglegVector: (_b = leader.doglegVector) !== null && _b !== void 0 ? _b : mleader.doglegVector,
740
- doglegLength: (_c = leader.doglegLength) !== null && _c !== void 0 ? _c : mleader.doglegLength
741
- });
742
- (_d = leader.leaderLines) === null || _d === void 0 ? void 0 : _d.forEach(function (line) {
743
- var _a, _b;
744
- var lineIndex = dbEntity.addLeaderLine(leaderIndex, (_a = line.vertices) !== null && _a !== void 0 ? _a : []);
745
- (_b = line.breaks) === null || _b === void 0 ? void 0 : _b.forEach(function (item) {
746
- dbEntity.addBreak(leaderIndex, lineIndex, item.start, item.end);
747
- });
862
+ (_p = this.readMLeaderLeaders(raw)) === null || _p === void 0 ? void 0 : _p.forEach(function (leader) {
863
+ var _a;
864
+ dbEntity.addLeader({
865
+ lastLeaderLinePoint: leader.lastLeaderLinePoint,
866
+ lastLeaderLinePointSet: leader.lastLeaderLinePointSet,
867
+ doglegVector: leader.doglegVector,
868
+ doglegVectorSet: leader.doglegVectorSet,
869
+ doglegLength: (_a = leader.doglegLength) !== null && _a !== void 0 ? _a : mleader.doglegLength,
870
+ breaks: leader.breaks,
871
+ leaderBranchIndex: leader.leaderBranchIndex,
872
+ leaderLines: leader.leaderLines
748
873
  });
749
874
  });
750
875
  if (dbEntity.numberOfLeaders === 0) {
751
- (_p = this.readLeaderLineArray(raw)) === null || _p === void 0 ? void 0 : _p.forEach(function (line) {
752
- var leaderIndex = dbEntity.addLeader({
753
- landingPoint: mleader.landingPoint,
754
- doglegVector: mleader.doglegVector,
876
+ (_q = this.readLeaderLineArray(raw)) === null || _q === void 0 ? void 0 : _q.forEach(function (line) {
877
+ dbEntity.addLeader({
755
878
  doglegLength: mleader.doglegLength
756
879
  });
757
- dbEntity.addLeaderLine(leaderIndex, line);
880
+ dbEntity.addLeaderLine(dbEntity.numberOfLeaders - 1, line);
881
+ });
882
+ }
883
+ if (dbEntity.numberOfLeaders === 0 && mleader.contentBasePosition) {
884
+ dbEntity.addLeader({
885
+ lastLeaderLinePoint: mleader.contentBasePosition,
886
+ lastLeaderLinePointSet: true,
887
+ doglegLength: mleader.doglegLength
758
888
  });
759
889
  }
760
890
  return dbEntity;
@@ -1036,14 +1166,18 @@ var AcDbEntityConverter = /** @class */ (function () {
1036
1166
  dbEntity.transparency = transparency;
1037
1167
  }
1038
1168
  };
1039
- AcDbEntityConverter.prototype.readNumber = function (source, names) {
1169
+ AcDbEntityConverter.prototype.convertMLeaderEntityColor = function (color) {
1170
+ return decodeMLeaderStyleRawColor(color);
1171
+ };
1172
+ AcDbEntityConverter.prototype.readMLeaderEntityColor = function (source, names) {
1040
1173
  var e_1, _a;
1041
1174
  try {
1042
1175
  for (var names_1 = __values(names), names_1_1 = names_1.next(); !names_1_1.done; names_1_1 = names_1.next()) {
1043
1176
  var name_1 = names_1_1.value;
1044
1177
  var value = source[name_1];
1045
- if (typeof value === 'number' && Number.isFinite(value))
1046
- return value;
1178
+ if (typeof value === 'number' && Number.isFinite(value)) {
1179
+ return decodeMLeaderStyleRawColor(value);
1180
+ }
1047
1181
  }
1048
1182
  }
1049
1183
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -1055,13 +1189,16 @@ var AcDbEntityConverter = /** @class */ (function () {
1055
1189
  }
1056
1190
  return undefined;
1057
1191
  };
1058
- AcDbEntityConverter.prototype.readString = function (source, names) {
1192
+ AcDbEntityConverter.prototype.isValidHandleId = function (id) {
1193
+ return id != null && id !== '' && id !== '0';
1194
+ };
1195
+ AcDbEntityConverter.prototype.readNumber = function (source, names) {
1059
1196
  var e_2, _a;
1060
1197
  try {
1061
1198
  for (var names_2 = __values(names), names_2_1 = names_2.next(); !names_2_1.done; names_2_1 = names_2.next()) {
1062
1199
  var name_2 = names_2_1.value;
1063
1200
  var value = source[name_2];
1064
- if (typeof value === 'string')
1201
+ if (typeof value === 'number' && Number.isFinite(value))
1065
1202
  return value;
1066
1203
  }
1067
1204
  }
@@ -1074,16 +1211,18 @@ var AcDbEntityConverter = /** @class */ (function () {
1074
1211
  }
1075
1212
  return undefined;
1076
1213
  };
1077
- AcDbEntityConverter.prototype.readBoolean = function (source, names) {
1214
+ AcDbEntityConverter.prototype.readPositiveNumber = function (source, names) {
1215
+ var value = this.readNumber(source, names);
1216
+ return value != null && value > 0 ? value : undefined;
1217
+ };
1218
+ AcDbEntityConverter.prototype.readString = function (source, names) {
1078
1219
  var e_3, _a;
1079
1220
  try {
1080
1221
  for (var names_3 = __values(names), names_3_1 = names_3.next(); !names_3_1.done; names_3_1 = names_3.next()) {
1081
1222
  var name_3 = names_3_1.value;
1082
1223
  var value = source[name_3];
1083
- if (typeof value === 'boolean')
1224
+ if (typeof value === 'string')
1084
1225
  return value;
1085
- if (typeof value === 'number')
1086
- return value !== 0;
1087
1226
  }
1088
1227
  }
1089
1228
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -1095,13 +1234,34 @@ var AcDbEntityConverter = /** @class */ (function () {
1095
1234
  }
1096
1235
  return undefined;
1097
1236
  };
1098
- AcDbEntityConverter.prototype.readPoint = function (source, names) {
1237
+ AcDbEntityConverter.prototype.readBoolean = function (source, names) {
1099
1238
  var e_4, _a;
1100
- var _b;
1101
1239
  try {
1102
1240
  for (var names_4 = __values(names), names_4_1 = names_4.next(); !names_4_1.done; names_4_1 = names_4.next()) {
1103
1241
  var name_4 = names_4_1.value;
1104
1242
  var value = source[name_4];
1243
+ if (typeof value === 'boolean')
1244
+ return value;
1245
+ if (typeof value === 'number')
1246
+ return value !== 0;
1247
+ }
1248
+ }
1249
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1250
+ finally {
1251
+ try {
1252
+ if (names_4_1 && !names_4_1.done && (_a = names_4.return)) _a.call(names_4);
1253
+ }
1254
+ finally { if (e_4) throw e_4.error; }
1255
+ }
1256
+ return undefined;
1257
+ };
1258
+ AcDbEntityConverter.prototype.readPoint = function (source, names) {
1259
+ var e_5, _a;
1260
+ var _b;
1261
+ try {
1262
+ for (var names_5 = __values(names), names_5_1 = names_5.next(); !names_5_1.done; names_5_1 = names_5.next()) {
1263
+ var name_5 = names_5_1.value;
1264
+ var value = source[name_5];
1105
1265
  if (this.isPointLike(value))
1106
1266
  return value;
1107
1267
  if (Array.isArray(value) &&
@@ -1111,12 +1271,12 @@ var AcDbEntityConverter = /** @class */ (function () {
1111
1271
  }
1112
1272
  }
1113
1273
  }
1114
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1274
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1115
1275
  finally {
1116
1276
  try {
1117
- if (names_4_1 && !names_4_1.done && (_a = names_4.return)) _a.call(names_4);
1277
+ if (names_5_1 && !names_5_1.done && (_a = names_5.return)) _a.call(names_5);
1118
1278
  }
1119
- finally { if (e_4) throw e_4.error; }
1279
+ finally { if (e_5) throw e_5.error; }
1120
1280
  }
1121
1281
  return undefined;
1122
1282
  };
@@ -1142,6 +1302,107 @@ var AcDbEntityConverter = /** @class */ (function () {
1142
1302
  }
1143
1303
  return undefined;
1144
1304
  };
1305
+ AcDbEntityConverter.prototype.readMLeaderLeaders = function (source) {
1306
+ var _this = this;
1307
+ var leaders = source.leaderSections;
1308
+ if (!Array.isArray(leaders))
1309
+ return undefined;
1310
+ var dbLeaders = [];
1311
+ leaders.forEach(function (leader) {
1312
+ if (!leader || typeof leader !== 'object')
1313
+ return;
1314
+ var leaderRecord = leader;
1315
+ var leaderLines = leaderRecord.leaderLines;
1316
+ var lines = Array.isArray(leaderLines)
1317
+ ? leaderLines.reduce(function (result, line) {
1318
+ var dbLine = _this.readMLeaderLine(line);
1319
+ if (dbLine)
1320
+ result.push(dbLine);
1321
+ return result;
1322
+ }, [])
1323
+ : undefined;
1324
+ var dbLeader = {};
1325
+ var lastLeaderLinePoint = _this.readPoint(leaderRecord, [
1326
+ 'lastLeaderLinePoint'
1327
+ ]);
1328
+ var doglegVector = _this.readPoint(leaderRecord, ['doglegVector']);
1329
+ var doglegLength = _this.readNumber(leaderRecord, ['doglegLength']);
1330
+ var leaderBreaks = _this.readMLeaderBreaks(leaderRecord.breaks);
1331
+ var leaderBranchIndex = _this.readNumber(leaderRecord, [
1332
+ 'leaderBranchIndex'
1333
+ ]);
1334
+ if (lastLeaderLinePoint)
1335
+ dbLeader.lastLeaderLinePoint = lastLeaderLinePoint;
1336
+ if (leaderRecord.lastLeaderLinePointSet != null) {
1337
+ dbLeader.lastLeaderLinePointSet = _this.readBoolean(leaderRecord, [
1338
+ 'lastLeaderLinePointSet'
1339
+ ]);
1340
+ }
1341
+ if (doglegVector)
1342
+ dbLeader.doglegVector = doglegVector;
1343
+ if (leaderRecord.doglegVectorSet != null) {
1344
+ dbLeader.doglegVectorSet = _this.readBoolean(leaderRecord, [
1345
+ 'doglegVectorSet'
1346
+ ]);
1347
+ }
1348
+ if (doglegLength != null)
1349
+ dbLeader.doglegLength = doglegLength;
1350
+ if (leaderBreaks)
1351
+ dbLeader.breaks = leaderBreaks;
1352
+ if (leaderBranchIndex != null) {
1353
+ dbLeader.leaderBranchIndex = leaderBranchIndex;
1354
+ }
1355
+ if (lines)
1356
+ dbLeader.leaderLines = lines;
1357
+ dbLeaders.push(dbLeader);
1358
+ });
1359
+ return dbLeaders;
1360
+ };
1361
+ AcDbEntityConverter.prototype.readMLeaderLine = function (value) {
1362
+ var _this = this;
1363
+ if (!value || typeof value !== 'object')
1364
+ return undefined;
1365
+ var lineRecord = value;
1366
+ var vertices = lineRecord.vertices;
1367
+ var dbVertices = Array.isArray(vertices)
1368
+ ? vertices.filter(function (point) { return _this.isPointLike(point); })
1369
+ : [];
1370
+ var dbBreaks = this.readMLeaderBreaks(lineRecord.breaks);
1371
+ var breakPointIndexes = Array.isArray(lineRecord.breakPointIndexes)
1372
+ ? lineRecord.breakPointIndexes.filter(function (item) { return typeof item === 'number'; })
1373
+ : undefined;
1374
+ var leaderLineIndex = this.readNumber(lineRecord, ['leaderLineIndex']);
1375
+ return dbVertices.length > 0 || (dbBreaks && dbBreaks.length > 0)
1376
+ ? {
1377
+ vertices: dbVertices,
1378
+ breakPointIndexes: breakPointIndexes,
1379
+ leaderLineIndex: leaderLineIndex,
1380
+ breaks: dbBreaks
1381
+ }
1382
+ : undefined;
1383
+ };
1384
+ AcDbEntityConverter.prototype.readMLeaderBreaks = function (value) {
1385
+ var _this = this;
1386
+ if (!Array.isArray(value))
1387
+ return undefined;
1388
+ var breaks = value
1389
+ .map(function (item) {
1390
+ if (!item || typeof item !== 'object')
1391
+ return undefined;
1392
+ var breakRecord = item;
1393
+ var start = _this.readPoint(breakRecord, ['start']);
1394
+ var end = _this.readPoint(breakRecord, ['end']);
1395
+ var index = _this.readNumber(breakRecord, ['index']);
1396
+ if (!start || !end)
1397
+ return undefined;
1398
+ var parsed = { start: start, end: end };
1399
+ if (index != null)
1400
+ parsed.index = index;
1401
+ return parsed;
1402
+ })
1403
+ .filter(function (item) { return !!item; });
1404
+ return breaks.length > 0 ? breaks : undefined;
1405
+ };
1145
1406
  AcDbEntityConverter.prototype.isPointLike = function (value) {
1146
1407
  return (!!value &&
1147
1408
  typeof value === 'object' &&