diff --git a/ACadSharp/Entities/MultiLeader.cs b/ACadSharp/Entities/MultiLeader.cs index a21e823d..015807cf 100644 --- a/ACadSharp/Entities/MultiLeader.cs +++ b/ACadSharp/Entities/MultiLeader.cs @@ -115,7 +115,7 @@ public object Clone() /// or the attached . /// [DxfCodeValue(90)] - public MultiLeaderPropertyOverrideFlags PropertyOverrideFlags { get; set; } + public MultiLeaderPropertyOverrideFlags PropertyOverrideFlags { get; set; } = MultiLeaderPropertyOverrideFlags.None; /// /// Gets or sets a value indicating the path type of this diff --git a/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs b/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs index dcb97843..773a6029 100644 --- a/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs +++ b/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs @@ -3310,12 +3310,16 @@ private CadTemplate readMultiLeaderStyle() mLeaderStyle.TextLeftAttachment = (TextAttachmentType)this._objectReader.ReadBitShort(); // BS 178 Right attachment (see paragraph on LEADER for more details). mLeaderStyle.TextRightAttachment = (TextAttachmentType)this._objectReader.ReadBitShort(); + if (this.R2010Plus) - {// IF IsNewFormat OR DXF file - // BS 175 Text angle type (see paragraph on LEADER for more details). + { + // IF IsNewFormat OR DXF file + // BS 175 Text angle type (see paragraph on LEADER for more details). mLeaderStyle.TextAngle = (TextAngleType)this._objectReader.ReadBitShort(); - } // END IF IsNewFormat OR DXF file + } + // END IF IsNewFormat OR DXF file + // BS 176 Text alignment type mLeaderStyle.TextAlignment = (TextAlignmentType)this._objectReader.ReadBitShort(); // CMC 93 Text color @@ -3324,11 +3328,15 @@ private CadTemplate readMultiLeaderStyle() mLeaderStyle.TextHeight = this._objectReader.ReadBitDouble(); // B 292 Text frame enabled mLeaderStyle.TextFrame = this._objectReader.ReadBit(); + if (this.R2010Plus) - {// IF IsNewFormat OR DXF file - // B 297 Always align text left + { + // IF IsNewFormat OR DXF file + // B 297 Always align text left mLeaderStyle.TextAlignAlwaysLeft = this._objectReader.ReadBit(); - }// END IF IsNewFormat OR DXF file + } + // END IF IsNewFormat OR DXF file + // BD 46 Align space mLeaderStyle.AlignSpace = this._objectReader.ReadBitDouble(); // H 343 Block handle (hard pointer) diff --git a/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs b/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs index dcca76e4..d44517f9 100644 --- a/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs +++ b/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs @@ -337,7 +337,7 @@ private void writeMLineStyle(MLineStyle mlineStyle) private void writeMultiLeaderStyle(MultiLeaderStyle mLeaderStyle) { - if (!R2010Plus) + if (!this.R2010Plus) { return; } diff --git a/ACadSharp/Objects/MultiLeaderStyle.cs b/ACadSharp/Objects/MultiLeaderStyle.cs index 326ce52b..2f99d999 100644 --- a/ACadSharp/Objects/MultiLeaderStyle.cs +++ b/ACadSharp/Objects/MultiLeaderStyle.cs @@ -2,6 +2,7 @@ using ACadSharp.Entities; using ACadSharp.Tables; using CSMath; +using System; namespace ACadSharp.Objects { @@ -155,7 +156,26 @@ public class MultiLeaderStyle : NonGraphicalObject /// /// [DxfCodeValue(DxfReferenceType.Handle, 340)] - public LineType LeaderLineType { get; set; } + public LineType LeaderLineType + { + get { return this._lineType; } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + if (this.Document != null) + { + this._lineType = this.updateTable(value, this.Document.LineTypes); + } + else + { + this._lineType = value; + } + } + } /// /// Gets or sets a value specifying the lineweight to be applied to all leader lines of the multileader. @@ -297,7 +317,26 @@ public class MultiLeaderStyle : NonGraphicalObject /// /// [DxfCodeValue(DxfReferenceType.Handle, 342)] - public TextStyle TextStyle { get; set; } + public TextStyle TextStyle + { + get { return this._textStyle; } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + if (this.Document != null) + { + this._textStyle = this.updateTable(value, this.Document.TextStyles); + } + else + { + this._textStyle = value; + } + } + } /// /// Gets or sets the Text Left Attachment Type. @@ -622,6 +661,10 @@ public class MultiLeaderStyle : NonGraphicalObject [DxfCodeValue(273)] public TextAttachmentType TextTopAttachment { get; set; } + public TextStyle _textStyle = TextStyle.Default; + + private LineType _lineType = LineType.ByLayer; + /// /// Initializes a new instance of the class. /// @@ -636,10 +679,50 @@ public MultiLeaderStyle(string name) : base() this.Name = name; } + /// public override CadObject Clone() { MultiLeaderStyle clone = (MultiLeaderStyle)base.Clone(); + + clone.TextStyle = (TextStyle)this.TextStyle.Clone(); + clone.LeaderLineType = (LineType)this.LeaderLineType.Clone(); + return clone; } + + internal override void AssignDocument(CadDocument doc) + { + base.AssignDocument(doc); + + this._textStyle = this.updateTable(this.TextStyle, doc.TextStyles); + this._lineType = this.updateTable(this.LeaderLineType, doc.LineTypes); + + doc.TextStyles.OnRemove += this.tableOnRemove; + doc.LineTypes.OnRemove += this.tableOnRemove; + } + + internal override void UnassignDocument() + { + this.Document.TextStyles.OnRemove -= this.tableOnRemove; + this.Document.LineTypes.OnRemove -= this.tableOnRemove; + + base.UnassignDocument(); + + this.TextStyle = (TextStyle)this.TextStyle.Clone(); + this.LeaderLineType = (LineType)this.LeaderLineType.Clone(); + } + + protected virtual void tableOnRemove(object sender, CollectionChangedEventArgs e) + { + if (e.Item.Equals(this.TextStyle)) + { + this.TextStyle = this.Document.TextStyles[Layer.DefaultName]; + } + + if (e.Item.Equals(this.LeaderLineType)) + { + this.LeaderLineType = this.Document.LineTypes[LineType.ByLayerName]; + } + } } }