@mlightcad/libredwg-converter 3.7.6 → 3.7.8

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.
@@ -20,7 +20,7 @@ var __values = (this && this.__values) || function(o) {
20
20
  };
21
21
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
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
  }
@@ -185,26 +188,31 @@ var AcDbEntityConverter = /** @class */ (function () {
185
188
  return dbEntity;
186
189
  };
187
190
  AcDbEntityConverter.prototype.convertSpline = function (spline) {
188
- // Catch error to construct spline because it maybe one spline in one block.
189
- // If don't catch the error, the block conversion may be interruptted.
190
- try {
191
- if (spline.numberOfControlPoints > 0 && spline.numberOfKnots > 0) {
192
- return new AcDbSpline(spline.controlPoints, spline.knots, spline.weights, spline.degree, !!(spline.flag & 0x01));
193
- }
194
- else if (spline.numberOfFitPoints > 0) {
195
- return new AcDbSpline(spline.fitPoints, 'Uniform', spline.degree, !!(spline.flag & 0x01));
196
- }
197
- }
198
- catch (error) {
199
- console.log("Failed to convert spline with error: ".concat(error));
200
- }
201
- return null;
191
+ // One invalid spline must not interrupt block conversion.
192
+ return AcDbSpline.fromDwgSpline(spline);
202
193
  };
203
194
  AcDbEntityConverter.prototype.convertPoint = function (point) {
204
195
  var dbEntity = new AcDbPoint();
205
196
  dbEntity.position = point.position;
206
197
  return dbEntity;
207
198
  };
199
+ AcDbEntityConverter.prototype.convertShape = function (shape) {
200
+ var _a, _b, _c, _d, _e;
201
+ var normal = (_a = shape.extrusionDirection) !== null && _a !== void 0 ? _a : AcGeVector3d.Z_AXIS;
202
+ var dbEntity = new AcDbShape();
203
+ dbEntity.position = transformOcsPointToWcs(shape.insertionPoint, normal);
204
+ dbEntity.size = shape.size;
205
+ dbEntity.shapeNumber = shape.shapeNumber;
206
+ if (shape.styleName) {
207
+ dbEntity.styleName = shape.styleName;
208
+ }
209
+ dbEntity.rotation = (_b = shape.rotation) !== null && _b !== void 0 ? _b : 0;
210
+ dbEntity.widthFactor = (_c = shape.xScale) !== null && _c !== void 0 ? _c : 1;
211
+ dbEntity.oblique = (_d = shape.obliqueAngle) !== null && _d !== void 0 ? _d : 0;
212
+ dbEntity.thickness = (_e = shape.thickness) !== null && _e !== void 0 ? _e : 0;
213
+ dbEntity.normal.copy(normal);
214
+ return dbEntity;
215
+ };
208
216
  AcDbEntityConverter.prototype.convertSolid = function (solid) {
209
217
  var dbEntity = new AcDbTrace();
210
218
  dbEntity.setPointAt(0, __assign(__assign({}, solid.corner1), { z: 0 }));
@@ -433,32 +441,9 @@ var AcDbEntityConverter = /** @class */ (function () {
433
441
  edges_1.push(new AcGeEllipseArc2d(__assign(__assign({}, ellipse.center), { z: 0 }), majorAxisRadius, minorAxisRadius, startAngle, endAngle, !ellipse.isCCW, rotation));
434
442
  }
435
443
  else if (edge.type == 4) {
436
- var spline = edge;
437
- if (spline.numberOfControlPoints > 0 && spline.numberOfKnots > 0) {
438
- var controlPoints = spline.controlPoints.map(function (item) {
439
- return {
440
- x: item.x,
441
- y: item.y,
442
- z: 0
443
- };
444
- });
445
- var hasWeights_1 = true;
446
- var weights = spline.controlPoints.map(function (item) {
447
- if (item.weight == null)
448
- hasWeights_1 = false;
449
- return item.weight || 1;
450
- });
451
- edges_1.push(new AcGeSpline3d(controlPoints, spline.knots, hasWeights_1 ? weights : undefined));
452
- }
453
- else if (spline.numberOfFitData > 0) {
454
- var fitPoints = spline.fitDatum.map(function (item) {
455
- return {
456
- x: item.x,
457
- y: item.y,
458
- z: 0
459
- };
460
- });
461
- edges_1.push(new AcGeSpline3d(fitPoints, 'Uniform'));
444
+ var splineEdge = AcGeSpline3d.fromDwgSplineEdge(edge);
445
+ if (splineEdge) {
446
+ edges_1.push(splineEdge);
462
447
  }
463
448
  }
464
449
  });
@@ -617,58 +602,154 @@ var AcDbEntityConverter = /** @class */ (function () {
617
602
  return dbEntity;
618
603
  };
619
604
  AcDbEntityConverter.prototype.convertMLeader = function (mleader) {
620
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
605
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
621
606
  var dbEntity = new AcDbMLeader();
622
607
  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
608
+ dbEntity.version = mleader.version;
609
+ dbEntity.leaderStyleId = mleader.leaderStyleId;
610
+ if (mleader.leaderStyleId)
611
+ dbEntity.mleaderStyleId = mleader.leaderStyleId;
612
+ dbEntity.propertyOverrideFlag = mleader.propertyOverrideFlag;
613
+ dbEntity.leaderLineType = ((_a = mleader.leaderLineType) !== null && _a !== void 0 ? _a : AcDbMLeaderLineType.StraightLeader);
614
+ if (mleader.leaderLineColor != null) {
615
+ dbEntity.leaderLineColor = this.convertMLeaderEntityColor(mleader.leaderLineColor);
616
+ }
617
+ dbEntity.leaderLineTypeId = mleader.leaderLineTypeId;
618
+ dbEntity.leaderLineWeight = mleader.leaderLineWeight;
619
+ dbEntity.landingEnabled = mleader.landingEnabled;
620
+ dbEntity.doglegEnabled = (_b = mleader.doglegEnabled) !== null && _b !== void 0 ? _b : false;
621
+ dbEntity.doglegLength = (_c = mleader.doglegLength) !== null && _c !== void 0 ? _c : 0;
622
+ dbEntity.arrowheadId = mleader.arrowheadId;
623
+ dbEntity.arrowheadSize = mleader.arrowheadSize;
624
+ dbEntity.textStyleId = mleader.textStyleId;
625
+ dbEntity.textLeftAttachmentType = mleader.textLeftAttachmentType;
626
+ dbEntity.textRightAttachmentType = mleader.textRightAttachmentType;
627
+ dbEntity.textAngleType = mleader.textAngleType;
628
+ dbEntity.textAlignmentType = mleader.textAlignmentType;
629
+ if (mleader.textColor != null) {
630
+ dbEntity.textColor = this.convertMLeaderEntityColor(mleader.textColor);
631
+ }
632
+ dbEntity.textFrameEnabled = mleader.textFrameEnabled;
633
+ dbEntity.landingGap = mleader.landingGap;
634
+ dbEntity.textAttachment = mleader.textAttachment;
635
+ dbEntity.textFlowDirection = mleader.textFlowDirection;
636
+ if (this.isValidHandleId(mleader.blockContentId)) {
637
+ dbEntity.blockContentId = mleader.blockContentId;
638
+ }
639
+ if (mleader.blockContentColor != null) {
640
+ dbEntity.blockContentColor = this.convertMLeaderEntityColor(mleader.blockContentColor);
641
+ }
642
+ dbEntity.blockContentRotation = mleader.blockContentRotation;
643
+ dbEntity.blockContentConnectionType = mleader.blockContentConnectionType;
644
+ dbEntity.annotativeScaleEnabled = mleader.annotativeScaleEnabled;
645
+ dbEntity.arrowheadOverrides = mleader.arrowheadOverrides
646
+ ? mleader.arrowheadOverrides.map(function (item) { return (__assign({}, item)); })
647
+ : [];
648
+ dbEntity.blockAttributes = mleader.blockAttributes
649
+ ? mleader.blockAttributes.map(function (item) { return (__assign({}, item)); })
650
+ : [];
651
+ dbEntity.textDirectionNegative = mleader.textDirectionNegative;
652
+ dbEntity.textAlignInIPE = mleader.textAlignInIPE;
653
+ dbEntity.bottomTextAttachmentDirection =
654
+ mleader.bottomTextAttachmentDirection;
655
+ dbEntity.topTextAttachmentDirection = mleader.topTextAttachmentDirection;
656
+ dbEntity.contentScale = mleader.contentScale;
657
+ dbEntity.textLineSpacingStyle = mleader.textLineSpacingStyle;
658
+ if (mleader.textBackgroundColor != null) {
659
+ dbEntity.textBackgroundColor = this.convertMLeaderEntityColor(mleader.textBackgroundColor);
660
+ }
661
+ dbEntity.textBackgroundScaleFactor = mleader.textBackgroundScaleFactor;
662
+ dbEntity.textBackgroundTransparency = mleader.textBackgroundTransparency;
663
+ dbEntity.textBackgroundColorOn = mleader.textBackgroundColorOn;
664
+ dbEntity.textFillOn = mleader.textFillOn;
665
+ dbEntity.textColumnType = mleader.textColumnType;
666
+ dbEntity.textUseAutoHeight = mleader.textUseAutoHeight;
667
+ dbEntity.textColumnWidth = mleader.textColumnWidth;
668
+ dbEntity.textColumnGutterWidth = mleader.textColumnGutterWidth;
669
+ dbEntity.textColumnFlowReversed = mleader.textColumnFlowReversed;
670
+ dbEntity.textColumnHeight = mleader.textColumnHeight;
671
+ dbEntity.textUseWordBreak = mleader.textUseWordBreak;
672
+ dbEntity.hasMText = mleader.hasMText;
673
+ dbEntity.hasBlock = mleader.hasBlock;
674
+ dbEntity.planeNormalReversed = mleader.planeNormalReversed;
675
+ if (mleader.blockContentScale) {
676
+ dbEntity.blockContentScale = new AcGeVector3d(mleader.blockContentScale);
677
+ }
678
+ if (mleader.contentBasePosition) {
679
+ dbEntity.contentBasePosition = new AcGePoint3d().copy(mleader.contentBasePosition);
680
+ }
681
+ if (mleader.textAnchor) {
682
+ dbEntity.textAnchor = new AcGePoint3d().copy(mleader.textAnchor);
683
+ }
684
+ if (mleader.planeOrigin) {
685
+ dbEntity.planeOrigin = new AcGePoint3d().copy(mleader.planeOrigin);
686
+ }
687
+ if (mleader.planeXAxisDirection) {
688
+ dbEntity.planeXAxisDirection = new AcGeVector3d(mleader.planeXAxisDirection);
689
+ }
690
+ if (mleader.planeYAxisDirection) {
691
+ dbEntity.planeYAxisDirection = new AcGeVector3d(mleader.planeYAxisDirection);
692
+ }
693
+ var rawTextContent = raw.textContent;
694
+ var rawTextContentRecord = rawTextContent && typeof rawTextContent === 'object'
695
+ ? rawTextContent
696
+ : undefined;
697
+ var hasMTextContent = (typeof rawTextContent === 'string' && rawTextContent.length > 0) ||
698
+ this.readString(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, ['text', 'contents']) !=
699
+ null ||
700
+ this.readString(raw, ['text', 'contents', 'mtext']) != null;
701
+ var contentType = (_d = mleader.contentType) !== null && _d !== void 0 ? _d : (hasMTextContent
629
702
  ? AcDbMLeaderContentType.MTextContent
630
703
  : mleader.blockContent
631
704
  ? AcDbMLeaderContentType.BlockContent
632
705
  : AcDbMLeaderContentType.NoneContent);
633
706
  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
707
  var normal = this.readPoint(raw, ['normal', 'extrusionDirection']);
651
708
  if (normal)
652
709
  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']);
710
+ var textStyleName = (_e = this.readString(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
711
+ 'styleName',
712
+ 'textStyleName',
713
+ 'textStyle'
714
+ ])) !== null && _e !== void 0 ? _e : this.readString(raw, ['textStyleName', 'textStyle', 'styleName']);
655
715
  if (textStyleName)
656
716
  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, [
717
+ var textHeight = (_g = (_f = this.readPositiveNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
718
+ 'textHeight',
719
+ 'height'
720
+ ])) !== null && _f !== void 0 ? _f : this.readPositiveNumber(raw, [
721
+ 'textHeight',
722
+ 'mtextHeight',
723
+ 'textContentHeight'
724
+ ])) !== null && _g !== void 0 ? _g : this.readPositiveNumber(raw, ['arrowheadSize', 'contentScale']);
725
+ if (textHeight != null)
726
+ dbEntity.textHeight = textHeight;
727
+ var textWidth = (_h = this.readPositiveNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
728
+ 'textWidth',
729
+ 'width'
730
+ ])) !== null && _h !== void 0 ? _h : this.readPositiveNumber(raw, [
731
+ 'textWidth',
732
+ 'mtextWidth',
733
+ 'textContentWidth'
734
+ ]);
735
+ if (textWidth != null)
736
+ dbEntity.textWidth = textWidth;
737
+ dbEntity.textLineSpacingFactor =
738
+ (_k = (_j = this.readNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
739
+ 'lineSpacingFactor',
740
+ 'textLineSpacingFactor'
741
+ ])) !== null && _j !== void 0 ? _j : this.readNumber(raw, ['textLineSpacingFactor'])) !== null && _k !== void 0 ? _k : dbEntity.textLineSpacingFactor;
742
+ var textRotation = (_l = this.readNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
743
+ 'textRotation',
744
+ 'rotation'
745
+ ])) !== null && _l !== void 0 ? _l : this.readNumber(raw, [
666
746
  'textRotation',
667
747
  'mtextRotation',
668
748
  'textContentRotation'
669
749
  ]);
670
- if (textRotation != null)
750
+ if (textRotation != null) {
671
751
  dbEntity.textRotation = textRotation;
752
+ }
672
753
  var textDirection = this.readPoint(raw, [
673
754
  'textDirection',
674
755
  'mtextDirection',
@@ -680,10 +761,15 @@ var AcDbEntityConverter = /** @class */ (function () {
680
761
  'textAttachmentPoint',
681
762
  'attachmentPoint'
682
763
  ]);
683
- if (textAttachmentPoint != null) {
764
+ if (textAttachmentPoint != null && textAttachmentPoint !== 0) {
684
765
  dbEntity.textAttachmentPoint =
685
766
  textAttachmentPoint;
686
767
  }
768
+ var textAttachmentDirection = mleader.textAttachmentDirection;
769
+ if (textAttachmentDirection != null) {
770
+ dbEntity.textAttachmentDirection =
771
+ textAttachmentDirection;
772
+ }
687
773
  var textDrawingDirection = this.readNumber(raw, [
688
774
  'textDrawingDirection',
689
775
  'drawingDirection'
@@ -692,69 +778,78 @@ var AcDbEntityConverter = /** @class */ (function () {
692
778
  dbEntity.textDrawingDirection =
693
779
  textDrawingDirection;
694
780
  }
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 };
781
+ var text = typeof rawTextContent === 'string'
782
+ ? rawTextContent
783
+ : ((_m = this.readString(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, ['text', 'contents'])) !== null && _m !== void 0 ? _m : this.readString(raw, ['text', 'contents', 'mtext']));
784
+ var anchorPoint = (_o = this.readPoint(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
785
+ 'anchorPoint',
786
+ 'textAnchor',
787
+ 'textLocation',
788
+ 'textPosition',
789
+ 'textAnchorPoint'
790
+ ])) !== null && _o !== void 0 ? _o : this.readPoint(raw, [
791
+ 'textAnchor',
792
+ 'textLocation',
793
+ 'textPosition',
794
+ 'textAnchorPoint',
795
+ 'contentBasePosition'
796
+ ]);
797
+ if (text != null && anchorPoint) {
798
+ dbEntity.mtextContent = { text: text, anchorPoint: anchorPoint };
799
+ }
800
+ if (mleader.blockContent) {
801
+ var blockRecord = mleader.blockContent;
802
+ var blockContentId = mleader.blockContent.blockContentId;
803
+ if (this.isValidHandleId(blockContentId)) {
804
+ var rawBlockColor = this.readMLeaderEntityColor(blockRecord, ['color']);
805
+ dbEntity.blockContent = {
806
+ blockContentId: blockContentId,
807
+ normal: this.readPoint(blockRecord, ['normal']),
808
+ position: mleader.blockContent.position,
809
+ scale: this.readPoint(blockRecord, ['scale']),
810
+ rotation: this.readNumber(blockRecord, ['rotation']),
811
+ color: rawBlockColor,
812
+ transformationMatrix: Array.isArray(mleader.blockContent.transformationMatrix)
813
+ ? mleader.blockContent.transformationMatrix
814
+ : []
815
+ };
710
816
  }
711
817
  }
712
- if (((_m = mleader.blockContent) === null || _m === void 0 ? void 0 : _m.blockHandle) && mleader.blockContent.position) {
818
+ else if (this.isValidHandleId(mleader.blockContentId)) {
713
819
  dbEntity.blockContent = {
714
- blockHandle: mleader.blockContent.blockHandle,
715
- position: mleader.blockContent.position
820
+ blockContentId: mleader.blockContentId,
821
+ scale: mleader.blockContentScale,
822
+ rotation: mleader.blockContentRotation,
823
+ color: dbEntity.blockContentColor,
824
+ transformationMatrix: []
716
825
  };
717
826
  }
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
- });
827
+ (_p = this.readMLeaderLeaders(raw)) === null || _p === void 0 ? void 0 : _p.forEach(function (leader) {
828
+ var _a;
829
+ dbEntity.addLeader({
830
+ lastLeaderLinePoint: leader.lastLeaderLinePoint,
831
+ lastLeaderLinePointSet: leader.lastLeaderLinePointSet,
832
+ doglegVector: leader.doglegVector,
833
+ doglegVectorSet: leader.doglegVectorSet,
834
+ doglegLength: (_a = leader.doglegLength) !== null && _a !== void 0 ? _a : mleader.doglegLength,
835
+ breaks: leader.breaks,
836
+ leaderBranchIndex: leader.leaderBranchIndex,
837
+ leaderLines: leader.leaderLines
748
838
  });
749
839
  });
750
840
  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,
841
+ (_q = this.readLeaderLineArray(raw)) === null || _q === void 0 ? void 0 : _q.forEach(function (line) {
842
+ dbEntity.addLeader({
755
843
  doglegLength: mleader.doglegLength
756
844
  });
757
- dbEntity.addLeaderLine(leaderIndex, line);
845
+ dbEntity.addLeaderLine(dbEntity.numberOfLeaders - 1, line);
846
+ });
847
+ }
848
+ if (dbEntity.numberOfLeaders === 0 && mleader.contentBasePosition) {
849
+ dbEntity.addLeader({
850
+ lastLeaderLinePoint: mleader.contentBasePosition,
851
+ lastLeaderLinePointSet: true,
852
+ doglegLength: mleader.doglegLength
758
853
  });
759
854
  }
760
855
  return dbEntity;
@@ -1036,14 +1131,18 @@ var AcDbEntityConverter = /** @class */ (function () {
1036
1131
  dbEntity.transparency = transparency;
1037
1132
  }
1038
1133
  };
1039
- AcDbEntityConverter.prototype.readNumber = function (source, names) {
1134
+ AcDbEntityConverter.prototype.convertMLeaderEntityColor = function (color) {
1135
+ return decodeMLeaderStyleRawColor(color);
1136
+ };
1137
+ AcDbEntityConverter.prototype.readMLeaderEntityColor = function (source, names) {
1040
1138
  var e_1, _a;
1041
1139
  try {
1042
1140
  for (var names_1 = __values(names), names_1_1 = names_1.next(); !names_1_1.done; names_1_1 = names_1.next()) {
1043
1141
  var name_1 = names_1_1.value;
1044
1142
  var value = source[name_1];
1045
- if (typeof value === 'number' && Number.isFinite(value))
1046
- return value;
1143
+ if (typeof value === 'number' && Number.isFinite(value)) {
1144
+ return decodeMLeaderStyleRawColor(value);
1145
+ }
1047
1146
  }
1048
1147
  }
1049
1148
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -1055,13 +1154,16 @@ var AcDbEntityConverter = /** @class */ (function () {
1055
1154
  }
1056
1155
  return undefined;
1057
1156
  };
1058
- AcDbEntityConverter.prototype.readString = function (source, names) {
1157
+ AcDbEntityConverter.prototype.isValidHandleId = function (id) {
1158
+ return id != null && id !== '' && id !== '0';
1159
+ };
1160
+ AcDbEntityConverter.prototype.readNumber = function (source, names) {
1059
1161
  var e_2, _a;
1060
1162
  try {
1061
1163
  for (var names_2 = __values(names), names_2_1 = names_2.next(); !names_2_1.done; names_2_1 = names_2.next()) {
1062
1164
  var name_2 = names_2_1.value;
1063
1165
  var value = source[name_2];
1064
- if (typeof value === 'string')
1166
+ if (typeof value === 'number' && Number.isFinite(value))
1065
1167
  return value;
1066
1168
  }
1067
1169
  }
@@ -1074,16 +1176,18 @@ var AcDbEntityConverter = /** @class */ (function () {
1074
1176
  }
1075
1177
  return undefined;
1076
1178
  };
1077
- AcDbEntityConverter.prototype.readBoolean = function (source, names) {
1179
+ AcDbEntityConverter.prototype.readPositiveNumber = function (source, names) {
1180
+ var value = this.readNumber(source, names);
1181
+ return value != null && value > 0 ? value : undefined;
1182
+ };
1183
+ AcDbEntityConverter.prototype.readString = function (source, names) {
1078
1184
  var e_3, _a;
1079
1185
  try {
1080
1186
  for (var names_3 = __values(names), names_3_1 = names_3.next(); !names_3_1.done; names_3_1 = names_3.next()) {
1081
1187
  var name_3 = names_3_1.value;
1082
1188
  var value = source[name_3];
1083
- if (typeof value === 'boolean')
1189
+ if (typeof value === 'string')
1084
1190
  return value;
1085
- if (typeof value === 'number')
1086
- return value !== 0;
1087
1191
  }
1088
1192
  }
1089
1193
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -1095,13 +1199,34 @@ var AcDbEntityConverter = /** @class */ (function () {
1095
1199
  }
1096
1200
  return undefined;
1097
1201
  };
1098
- AcDbEntityConverter.prototype.readPoint = function (source, names) {
1202
+ AcDbEntityConverter.prototype.readBoolean = function (source, names) {
1099
1203
  var e_4, _a;
1100
- var _b;
1101
1204
  try {
1102
1205
  for (var names_4 = __values(names), names_4_1 = names_4.next(); !names_4_1.done; names_4_1 = names_4.next()) {
1103
1206
  var name_4 = names_4_1.value;
1104
1207
  var value = source[name_4];
1208
+ if (typeof value === 'boolean')
1209
+ return value;
1210
+ if (typeof value === 'number')
1211
+ return value !== 0;
1212
+ }
1213
+ }
1214
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1215
+ finally {
1216
+ try {
1217
+ if (names_4_1 && !names_4_1.done && (_a = names_4.return)) _a.call(names_4);
1218
+ }
1219
+ finally { if (e_4) throw e_4.error; }
1220
+ }
1221
+ return undefined;
1222
+ };
1223
+ AcDbEntityConverter.prototype.readPoint = function (source, names) {
1224
+ var e_5, _a;
1225
+ var _b;
1226
+ try {
1227
+ for (var names_5 = __values(names), names_5_1 = names_5.next(); !names_5_1.done; names_5_1 = names_5.next()) {
1228
+ var name_5 = names_5_1.value;
1229
+ var value = source[name_5];
1105
1230
  if (this.isPointLike(value))
1106
1231
  return value;
1107
1232
  if (Array.isArray(value) &&
@@ -1111,12 +1236,12 @@ var AcDbEntityConverter = /** @class */ (function () {
1111
1236
  }
1112
1237
  }
1113
1238
  }
1114
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1239
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1115
1240
  finally {
1116
1241
  try {
1117
- if (names_4_1 && !names_4_1.done && (_a = names_4.return)) _a.call(names_4);
1242
+ if (names_5_1 && !names_5_1.done && (_a = names_5.return)) _a.call(names_5);
1118
1243
  }
1119
- finally { if (e_4) throw e_4.error; }
1244
+ finally { if (e_5) throw e_5.error; }
1120
1245
  }
1121
1246
  return undefined;
1122
1247
  };
@@ -1142,6 +1267,107 @@ var AcDbEntityConverter = /** @class */ (function () {
1142
1267
  }
1143
1268
  return undefined;
1144
1269
  };
1270
+ AcDbEntityConverter.prototype.readMLeaderLeaders = function (source) {
1271
+ var _this = this;
1272
+ var leaders = source.leaderSections;
1273
+ if (!Array.isArray(leaders))
1274
+ return undefined;
1275
+ var dbLeaders = [];
1276
+ leaders.forEach(function (leader) {
1277
+ if (!leader || typeof leader !== 'object')
1278
+ return;
1279
+ var leaderRecord = leader;
1280
+ var leaderLines = leaderRecord.leaderLines;
1281
+ var lines = Array.isArray(leaderLines)
1282
+ ? leaderLines.reduce(function (result, line) {
1283
+ var dbLine = _this.readMLeaderLine(line);
1284
+ if (dbLine)
1285
+ result.push(dbLine);
1286
+ return result;
1287
+ }, [])
1288
+ : undefined;
1289
+ var dbLeader = {};
1290
+ var lastLeaderLinePoint = _this.readPoint(leaderRecord, [
1291
+ 'lastLeaderLinePoint'
1292
+ ]);
1293
+ var doglegVector = _this.readPoint(leaderRecord, ['doglegVector']);
1294
+ var doglegLength = _this.readNumber(leaderRecord, ['doglegLength']);
1295
+ var leaderBreaks = _this.readMLeaderBreaks(leaderRecord.breaks);
1296
+ var leaderBranchIndex = _this.readNumber(leaderRecord, [
1297
+ 'leaderBranchIndex'
1298
+ ]);
1299
+ if (lastLeaderLinePoint)
1300
+ dbLeader.lastLeaderLinePoint = lastLeaderLinePoint;
1301
+ if (leaderRecord.lastLeaderLinePointSet != null) {
1302
+ dbLeader.lastLeaderLinePointSet = _this.readBoolean(leaderRecord, [
1303
+ 'lastLeaderLinePointSet'
1304
+ ]);
1305
+ }
1306
+ if (doglegVector)
1307
+ dbLeader.doglegVector = doglegVector;
1308
+ if (leaderRecord.doglegVectorSet != null) {
1309
+ dbLeader.doglegVectorSet = _this.readBoolean(leaderRecord, [
1310
+ 'doglegVectorSet'
1311
+ ]);
1312
+ }
1313
+ if (doglegLength != null)
1314
+ dbLeader.doglegLength = doglegLength;
1315
+ if (leaderBreaks)
1316
+ dbLeader.breaks = leaderBreaks;
1317
+ if (leaderBranchIndex != null) {
1318
+ dbLeader.leaderBranchIndex = leaderBranchIndex;
1319
+ }
1320
+ if (lines)
1321
+ dbLeader.leaderLines = lines;
1322
+ dbLeaders.push(dbLeader);
1323
+ });
1324
+ return dbLeaders;
1325
+ };
1326
+ AcDbEntityConverter.prototype.readMLeaderLine = function (value) {
1327
+ var _this = this;
1328
+ if (!value || typeof value !== 'object')
1329
+ return undefined;
1330
+ var lineRecord = value;
1331
+ var vertices = lineRecord.vertices;
1332
+ var dbVertices = Array.isArray(vertices)
1333
+ ? vertices.filter(function (point) { return _this.isPointLike(point); })
1334
+ : [];
1335
+ var dbBreaks = this.readMLeaderBreaks(lineRecord.breaks);
1336
+ var breakPointIndexes = Array.isArray(lineRecord.breakPointIndexes)
1337
+ ? lineRecord.breakPointIndexes.filter(function (item) { return typeof item === 'number'; })
1338
+ : undefined;
1339
+ var leaderLineIndex = this.readNumber(lineRecord, ['leaderLineIndex']);
1340
+ return dbVertices.length > 0 || (dbBreaks && dbBreaks.length > 0)
1341
+ ? {
1342
+ vertices: dbVertices,
1343
+ breakPointIndexes: breakPointIndexes,
1344
+ leaderLineIndex: leaderLineIndex,
1345
+ breaks: dbBreaks
1346
+ }
1347
+ : undefined;
1348
+ };
1349
+ AcDbEntityConverter.prototype.readMLeaderBreaks = function (value) {
1350
+ var _this = this;
1351
+ if (!Array.isArray(value))
1352
+ return undefined;
1353
+ var breaks = value
1354
+ .map(function (item) {
1355
+ if (!item || typeof item !== 'object')
1356
+ return undefined;
1357
+ var breakRecord = item;
1358
+ var start = _this.readPoint(breakRecord, ['start']);
1359
+ var end = _this.readPoint(breakRecord, ['end']);
1360
+ var index = _this.readNumber(breakRecord, ['index']);
1361
+ if (!start || !end)
1362
+ return undefined;
1363
+ var parsed = { start: start, end: end };
1364
+ if (index != null)
1365
+ parsed.index = index;
1366
+ return parsed;
1367
+ })
1368
+ .filter(function (item) { return !!item; });
1369
+ return breaks.length > 0 ? breaks : undefined;
1370
+ };
1145
1371
  AcDbEntityConverter.prototype.isPointLike = function (value) {
1146
1372
  return (!!value &&
1147
1373
  typeof value === 'object' &&