Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mleaderstyle defaults #385

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ACadSharp/Entities/MultiLeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public object Clone()
/// or the attached <see cref="MultiLeaderAnnotContext"/>.
/// </summary>
[DxfCodeValue(90)]
public MultiLeaderPropertyOverrideFlags PropertyOverrideFlags { get; set; }
public MultiLeaderPropertyOverrideFlags PropertyOverrideFlags { get; set; } = MultiLeaderPropertyOverrideFlags.None;

/// <summary>
/// Gets or sets a value indicating the path type of this <see cref="MultiLeader"/>
Expand Down
20 changes: 14 additions & 6 deletions ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private void writeMLineStyle(MLineStyle mlineStyle)

private void writeMultiLeaderStyle(MultiLeaderStyle mLeaderStyle)
{
if (!R2010Plus)
if (!this.R2010Plus)
{
return;
}
Expand Down
87 changes: 85 additions & 2 deletions ACadSharp/Objects/MultiLeaderStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ACadSharp.Entities;
using ACadSharp.Tables;
using CSMath;
using System;

namespace ACadSharp.Objects
{
Expand Down Expand Up @@ -155,7 +156,26 @@ public class MultiLeaderStyle : NonGraphicalObject
/// </para>
/// </remarks>
[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;
}
}
}

/// <summary>
/// Gets or sets a value specifying the lineweight to be applied to all leader lines of the multileader.
Expand Down Expand Up @@ -297,7 +317,26 @@ public class MultiLeaderStyle : NonGraphicalObject
/// </para>
/// </remarks>
[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;
}
}
}

/// <summary>
/// Gets or sets the Text Left Attachment Type.
Expand Down Expand Up @@ -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;

/// <summary>
/// Initializes a new instance of the <see cref="MultiLeaderStyle"/> class.
/// </summary>
Expand All @@ -636,10 +679,50 @@ public MultiLeaderStyle(string name) : base()
this.Name = name;
}

/// <inheritdoc/>
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];
}
}
}
}
Loading