Skip to content

Commit d584423

Browse files
authored
Merge pull request #653 from DomCR/mleader-dwg-reader-writer
transfer files for mleader dwg
2 parents 9a87bd9 + 823ef0a commit d584423

File tree

6 files changed

+85
-72
lines changed

6 files changed

+85
-72
lines changed

src/ACadSharp.Tests/IO/LocalSampleTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public void ReadUserDxf(FileModel test)
4848
return;
4949

5050
CadDocument doc = DxfReader.Read(test.Path, this.onNotification);
51-
doc.Header.Version = ACadVersion.AC1032;
5251
}
5352

5453
[Theory]
@@ -81,4 +80,4 @@ public void ReadStressFiles(FileModel test)
8180
Assert.True(stopwatch.Elapsed.TotalSeconds < 10);
8281
}
8382
}
84-
}
83+
}

src/ACadSharp/ACadSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PropertyGroup>
1818
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1919
<PackageReadmeFile>README.md</PackageReadmeFile>
20-
<Version>1.1.19</Version>
20+
<Version>1.1.20</Version>
2121
<PackageOutputPath>../nupkg</PackageOutputPath>
2222
</PropertyGroup>
2323

src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,10 +1054,6 @@ private CadTemplate readUnlistedType(short classNumber)
10541054
template = this.readMultiLeader();
10551055
break;
10561056
case "MLEADERSTYLE":
1057-
if (!this.R2010Plus) {
1058-
this.notify($"MLEADERSTYLE is not supported for {this._version}.", NotificationType.Warning);
1059-
return null;
1060-
}
10611057
template = this.readMultiLeaderStyle();
10621058
break;
10631059
case "PDFDEFINITION":
@@ -3129,12 +3125,14 @@ private CadTemplate readMultiLeader()
31293125
// Multileader Common data
31303126
// 340 Leader StyleId (handle)
31313127
template.LeaderStyleHandle = this.handleReference();
3128+
31323129
//BL 90 Property Override Flags (int32)
31333130
mLeader.PropertyOverrideFlags = (MultiLeaderPropertyOverrideFlags)this._objectReader.ReadBitLong();
31343131
//BS 170 LeaderLineType (short)
31353132
mLeader.PathType = (MultiLeaderPathType)this._objectReader.ReadBitShort();
31363133
//CMC 91 Leade LineColor (Color)
31373134
mLeader.LineColor = this._mergedReaders.ReadCmColor();
3135+
31383136
//H 341 LeaderLineTypeID (handle/LineType)
31393137
template.LeaderLineTypeHandle = this.handleReference();
31403138

@@ -3144,23 +3142,25 @@ private CadTemplate readMultiLeader()
31443142
mLeader.EnableLanding = this._objectReader.ReadBit();
31453143
//B 291 Enable Dogleg
31463144
mLeader.EnableDogleg = this._objectReader.ReadBit();
3147-
31483145
// 41 Dogleg Length / Landing distance
31493146
mLeader.LandingDistance = this._objectReader.ReadBitDouble();
3147+
31503148
// 342 Arrowhead ID
31513149
template.ArrowheadHandle = this.handleReference();
31523150

31533151
// 42 Arrowhead Size
31543152
mLeader.ArrowheadSize = this._objectReader.ReadBitDouble();
31553153
//BS 172 Content Type
31563154
mLeader.ContentType = (LeaderContentType)this._objectReader.ReadBitShort();
3155+
31573156
//H 343 Text Style ID (handle/TextStyle)
31583157
template.MTextStyleHandle = this.handleReference();
31593158

31603159
// 173 Text Left Attachment Type
31613160
mLeader.TextLeftAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
31623161
// 95 Text Right Attachment Type
31633162
mLeader.TextRightAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
3163+
31643164
// 174 Text Angle Type
31653165
mLeader.TextAngle = (TextAngleType)this._objectReader.ReadBitShort();
31663166
// 175 Text Alignment Type
@@ -3523,8 +3523,11 @@ private CadTemplate readMultiLeaderStyle()
35233523

35243524
this.readCommonNonEntityData(template);
35253525

3526-
// BS 179 Version expected: 2
3527-
var version = this._objectReader.ReadBitShort();
3526+
if (this.R2010Plus)
3527+
{
3528+
// BS 179 Version expected: 2
3529+
var version = this._objectReader.ReadBitShort();
3530+
}
35283531

35293532
// BS 170 Content type (see paragraph on LEADER for more details).
35303533
mLeaderStyle.ContentType = (LeaderContentType)this._objectReader.ReadBitShort();
@@ -3533,7 +3536,7 @@ private CadTemplate readMultiLeaderStyle()
35333536
// BS 172 Draw leader order (0 = draw leader head first, 1 = draw leader tail first)
35343537
mLeaderStyle.LeaderDrawOrder = (LeaderDrawOrderType)this._objectReader.ReadBitShort();
35353538
// BL 90 Maximum number of points for leader
3536-
mLeaderStyle.MaxLeaderSegmentsPoints = this._objectReader.ReadBitShort();
3539+
mLeaderStyle.MaxLeaderSegmentsPoints = this._objectReader.ReadBitLong();
35373540
// BD 40 First segment angle (radians)
35383541
mLeaderStyle.FirstSegmentAngleConstraint = this._objectReader.ReadBitDouble();
35393542
// BD 41 Second segment angle (radians)
@@ -3542,8 +3545,10 @@ private CadTemplate readMultiLeaderStyle()
35423545
mLeaderStyle.PathType = (MultiLeaderPathType)this._objectReader.ReadBitShort();
35433546
// CMC 91 Leader line color
35443547
mLeaderStyle.LineColor = this._mergedReaders.ReadCmColor();
3548+
35453549
// H 340 Leader line type handle (hard pointer)
35463550
template.LeaderLineTypeHandle = this.handleReference();
3551+
35473552
// BL 92 Leader line weight
35483553
mLeaderStyle.LeaderLineWeight = (LineweightType)this._objectReader.ReadBitLong();
35493554
// B 290 Is landing enabled?
@@ -3556,41 +3561,40 @@ private CadTemplate readMultiLeaderStyle()
35563561
mLeaderStyle.LandingDistance = this._objectReader.ReadBitDouble();
35573562
// TV 3 Style description
35583563
mLeaderStyle.Description = this._mergedReaders.ReadVariableText();
3564+
35593565
// H 341 Arrow head block handle (hard pointer)
35603566
template.ArrowheadHandle = this.handleReference();
3567+
35613568
// BD 44 Arrow head size
35623569
mLeaderStyle.ArrowheadSize = this._objectReader.ReadBitDouble();
35633570
// TV 300 Text default
35643571
mLeaderStyle.DefaultTextContents = this._mergedReaders.ReadVariableText();
3572+
35653573
// H 342 Text style handle (hard pointer)
35663574
template.MTextStyleHandle = this.handleReference();
3575+
35673576
// BS 174 Left attachment (see paragraph on LEADER for more details).
35683577
mLeaderStyle.TextLeftAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
35693578
// BS 178 Right attachment (see paragraph on LEADER for more details).
35703579
mLeaderStyle.TextRightAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
3571-
if (this.R2010Plus)
3572-
{// IF IsNewFormat OR DXF file
3573-
// BS 175 Text angle type (see paragraph on LEADER for more details).
3574-
mLeaderStyle.TextAngle = (TextAngleType)this._objectReader.ReadBitShort();
3575-
3576-
} // END IF IsNewFormat OR DXF file
3577-
// BS 176 Text alignment type
3580+
// BS 175 Text angle type (see paragraph on LEADER for more details).
3581+
mLeaderStyle.TextAngle = (TextAngleType)this._objectReader.ReadBitShort();
3582+
// BS 176 Text alignment type
35783583
mLeaderStyle.TextAlignment = (TextAlignmentType)this._objectReader.ReadBitShort();
35793584
// CMC 93 Text color
35803585
mLeaderStyle.TextColor = this._mergedReaders.ReadCmColor();
35813586
// BD 45 Text height
35823587
mLeaderStyle.TextHeight = this._objectReader.ReadBitDouble();
35833588
// B 292 Text frame enabled
35843589
mLeaderStyle.TextFrame = this._objectReader.ReadBit();
3585-
if (this.R2010Plus)
3586-
{// IF IsNewFormat OR DXF file
3587-
// B 297 Always align text left
3588-
mLeaderStyle.TextAlignAlwaysLeft = this._objectReader.ReadBit();
3589-
}// END IF IsNewFormat OR DXF file
3590-
// BD 46 Align space
3590+
// B 297 Always align text left
3591+
mLeaderStyle.TextAlignAlwaysLeft = this._objectReader.ReadBit();
3592+
// BD 46 Align space
35913593
mLeaderStyle.AlignSpace = this._objectReader.ReadBitDouble();
3594+
35923595
// H 343 Block handle (hard pointer)
35933596
template.BlockContentHandle = this.handleReference();
3597+
35943598
// CMC 94 Block color
35953599
mLeaderStyle.BlockContentColor = this._mergedReaders.ReadCmColor();
35963600
// 3BD 47,49,140 Block scale vector
@@ -3615,15 +3619,21 @@ private CadTemplate readMultiLeaderStyle()
36153619
// BD 143 Break size
36163620
mLeaderStyle.BreakGapSize = this._objectReader.ReadBitDouble();
36173621

3618-
// BS 271 Attachment direction (see paragraph on LEADER for more details).
3619-
mLeaderStyle.TextAttachmentDirection = (TextAttachmentDirectionType)this._objectReader.ReadBitShort();
3620-
// BS 273 Top attachment (see paragraph on LEADER for more details).
3621-
mLeaderStyle.TextBottomAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
3622-
// BS 272 Bottom attachment (see paragraph on LEADER for more details).
3623-
mLeaderStyle.TextTopAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
3622+
if (this.R2010Plus)
3623+
{
3624+
// BS 271 Attachment direction (see paragraph on LEADER for more details).
3625+
mLeaderStyle.TextAttachmentDirection = (TextAttachmentDirectionType)this._objectReader.ReadBitShort();
3626+
// BS 273 Top attachment (see paragraph on LEADER for more details).
3627+
mLeaderStyle.TextBottomAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
3628+
// BS 272 Bottom attachment (see paragraph on LEADER for more details).
3629+
mLeaderStyle.TextTopAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
3630+
}
36243631

3625-
// B 298 Undocumented, found in DXF
3626-
mLeaderStyle.UnknownFlag298 = this._objectReader.ReadBit();
3632+
if (this.R2013Plus)
3633+
{
3634+
// B 298 Undocumented, found in DXF
3635+
mLeaderStyle.UnknownFlag298 = this._objectReader.ReadBit();
3636+
}
36273637

36283638
return template;
36293639
}

src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ private void writeMultiLeader(MultiLeader multiLeader)
11431143
this._writer.WriteBitLong((int)multiLeader.PropertyOverrideFlags);
11441144
// 170 LeaderLineType (short)
11451145
this._writer.WriteBitShort((short)multiLeader.PathType);
1146-
// 91 Leade LineColor (Color)
1146+
// 91 Leader LineColor (Color)
11471147
this._writer.WriteCmColor(multiLeader.LineColor);
11481148
// 341 LeaderLineTypeID (handle/LineType)
11491149
this._writer.HandleReference(DwgReferenceType.HardPointer, multiLeader.LeaderLineType);
@@ -2449,4 +2449,4 @@ private void writeChildEntities(IEnumerable<Entity> entities, Seqend seqend)
24492449
}
24502450
}
24512451
}
2452-
}
2452+
}

src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ private void writeObject(CadObject obj)
2828
{
2929
case EvaluationGraph:
3030
case Material:
31-
case MultiLeaderAnnotContext:
32-
case MultiLeaderStyle when !this.R2010Plus:
3331
case SortEntitiesTable:
3432
case UnknownNonGraphicalObject:
3533
case VisualStyle:
@@ -532,22 +530,20 @@ private void writeMLineStyle(MLineStyle mlineStyle)
532530

533531
private void writeMultiLeaderStyle(MultiLeaderStyle mLeaderStyle)
534532
{
535-
if (!R2010Plus)
533+
if (this.R2010Plus)
536534
{
537-
return;
535+
// BS 179 Version expected: 2
536+
this._writer.WriteBitShort(2);
538537
}
539538

540-
// BS 179 Version expected: 2
541-
this._writer.WriteBitShort(2);
542-
543539
// BS 170 Content type (see paragraph on LEADER for more details).
544540
this._writer.WriteBitShort((short)mLeaderStyle.ContentType);
545541
// BS 171 Draw multi-leader order (0 = draw content first, 1 = draw leader first)
546542
this._writer.WriteBitShort((short)mLeaderStyle.MultiLeaderDrawOrder);
547543
// BS 172 Draw leader order (0 = draw leader head first, 1 = draw leader tail first)
548544
this._writer.WriteBitShort((short)mLeaderStyle.LeaderDrawOrder);
549545
// BL 90 Maximum number of points for leader
550-
this._writer.WriteBitShort((short)mLeaderStyle.MaxLeaderSegmentsPoints);
546+
this._writer.WriteBitLong((short)mLeaderStyle.MaxLeaderSegmentsPoints);
551547
// BD 40 First segment angle (radians)
552548
this._writer.WriteBitDouble(mLeaderStyle.FirstSegmentAngleConstraint);
553549
// BD 41 Second segment angle (radians)
@@ -556,8 +552,10 @@ private void writeMultiLeaderStyle(MultiLeaderStyle mLeaderStyle)
556552
this._writer.WriteBitShort((short)mLeaderStyle.PathType);
557553
// CMC 91 Leader line color
558554
this._writer.WriteCmColor(mLeaderStyle.LineColor);
555+
559556
// H 340 Leader line type handle (hard pointer)
560557
this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.LeaderLineType);
558+
561559
// BL 92 Leader line weight
562560
this._writer.WriteBitLong((short)mLeaderStyle.LeaderLineWeight);
563561
// B 290 Is landing enabled?
@@ -570,25 +568,24 @@ private void writeMultiLeaderStyle(MultiLeaderStyle mLeaderStyle)
570568
this._writer.WriteBitDouble(mLeaderStyle.LandingDistance);
571569
// TV 3 Style description
572570
this._writer.WriteVariableText(mLeaderStyle.Description);
571+
573572
// H 341 Arrow head block handle (hard pointer)
574573
this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.Arrowhead);
574+
575575
// BD 44 Arrow head size
576576
this._writer.WriteBitDouble(mLeaderStyle.ArrowheadSize);
577577
// TV 300 Text default
578578
this._writer.WriteVariableText(mLeaderStyle.DefaultTextContents);
579+
579580
// H 342 Text style handle (hard pointer)
580581
this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.TextStyle);
582+
581583
// BS 174 Left attachment (see paragraph on LEADER for more details).
582584
this._writer.WriteBitShort((short)mLeaderStyle.TextLeftAttachment);
583585
// BS 178 Right attachment (see paragraph on LEADER for more details).
584586
this._writer.WriteBitShort((short)mLeaderStyle.TextRightAttachment);
585-
if (R2010Plus)
586-
{
587-
// IF IsNewFormat OR DXF file
588-
// BS 175 Text angle type (see paragraph on LEADER for more details).
589-
this._writer.WriteBitShort((short)mLeaderStyle.TextAngle);
590-
// END IF IsNewFormat OR DXF file
591-
}
587+
// BS 175 Text angle type (see paragraph on LEADER for more details).
588+
this._writer.WriteBitShort((short)mLeaderStyle.TextAngle);
592589
// BS 176 Text alignment type
593590
this._writer.WriteBitShort((short)mLeaderStyle.TextAlignment);
594591
// CMC 93 Text color
@@ -597,17 +594,14 @@ private void writeMultiLeaderStyle(MultiLeaderStyle mLeaderStyle)
597594
this._writer.WriteBitDouble(mLeaderStyle.TextHeight);
598595
// B 292 Text frame enabled
599596
this._writer.WriteBit(mLeaderStyle.TextFrame);
600-
if (R2010Plus)
601-
{
602-
// IF IsNewFormat OR DXF file
603-
// B 297 Always align text left
604-
this._writer.WriteBit(mLeaderStyle.TextAlignAlwaysLeft);
605-
// END IF IsNewFormat OR DXF file
606-
}
597+
// B 297 Always align text left
598+
this._writer.WriteBit(mLeaderStyle.TextAlignAlwaysLeft);
607599
// BD 46 Align space
608600
this._writer.WriteBitDouble(mLeaderStyle.AlignSpace);
601+
609602
// H 343 Block handle (hard pointer)
610603
this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.BlockContent);
604+
611605
// CMC 94 Block color
612606
this._writer.WriteCmColor(mLeaderStyle.BlockContentColor);
613607
// 3BD 47,49,140 Block scale vector
@@ -632,15 +626,21 @@ private void writeMultiLeaderStyle(MultiLeaderStyle mLeaderStyle)
632626
// BD 143 Break size
633627
this._writer.WriteBitDouble(mLeaderStyle.BreakGapSize);
634628

635-
// BS 271 Attachment direction (see paragraph on LEADER for more details).
636-
this._writer.WriteBitShort((short)mLeaderStyle.TextAttachmentDirection);
637-
// BS 273 Top attachment (see paragraph on LEADER for more details).
638-
this._writer.WriteBitShort((short)mLeaderStyle.TextBottomAttachment);
639-
// BS 272 Bottom attachment (see paragraph on LEADER for more details).
640-
this._writer.WriteBitShort((short)mLeaderStyle.TextTopAttachment);
629+
if (this.R2010Plus)
630+
{
631+
// BS 271 Attachment direction (see paragraph on LEADER for more details).
632+
this._writer.WriteBitShort((short)mLeaderStyle.TextAttachmentDirection);
633+
// BS 273 Top attachment (see paragraph on LEADER for more details).
634+
this._writer.WriteBitShort((short)mLeaderStyle.TextBottomAttachment);
635+
// BS 272 Bottom attachment (see paragraph on LEADER for more details).
636+
this._writer.WriteBitShort((short)mLeaderStyle.TextTopAttachment);
637+
}
641638

642-
// B 298 Undocumented, found in DXF
643-
this._writer.WriteBit(mLeaderStyle.UnknownFlag298);
639+
if (this.R2013Plus)
640+
{
641+
// B 298 Undocumented, found in DXF
642+
this._writer.WriteBit(mLeaderStyle.UnknownFlag298);
643+
}
644644
}
645645

646646
private void writePlotSettings(PlotSettings plot)

src/ACadSharp/IO/Templates/CadMLeaderStyleTemplate.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ namespace ACadSharp.IO.Templates
55
{
66
internal class CadMLeaderStyleTemplate : CadTemplate<MultiLeaderStyle>
77
{
8-
public CadMLeaderStyleTemplate(MultiLeaderStyle entry) : base(entry) { }
8+
public ulong ArrowheadHandle { get; internal set; }
99

10-
public ulong LeaderLineTypeHandle { get; internal set; }
10+
public ulong BlockContentHandle { get; internal set; }
1111

12-
public ulong ArrowheadHandle { get; internal set; }
12+
public ulong LeaderLineTypeHandle { get; internal set; }
1313

1414
public ulong MTextStyleHandle { get; internal set; }
1515

16-
public ulong BlockContentHandle { get; internal set; }
16+
public CadMLeaderStyleTemplate(MultiLeaderStyle entry) : base(entry)
17+
{
18+
}
1719

1820
public override void Build(CadDocumentBuilder builder)
1921
{
@@ -24,9 +26,11 @@ public override void Build(CadDocumentBuilder builder)
2426
this.CadObject.LeaderLineType = lineType;
2527
}
2628

27-
//if (builder.TryGetCadObject(this.ArrowheadHandle, out Arr arrowhead)) {
28-
// this.CadObject.Arrowhead = arrowhead;
29-
//}
29+
if (builder.TryGetCadObject(this.ArrowheadHandle, out BlockRecord arrowhead))
30+
{
31+
this.CadObject.Arrowhead = arrowhead;
32+
}
33+
3034
if (builder.TryGetCadObject(this.MTextStyleHandle, out TextStyle textStyle))
3135
{
3236
this.CadObject.TextStyle = textStyle;
@@ -38,4 +42,4 @@ public override void Build(CadDocumentBuilder builder)
3842
}
3943
}
4044
}
41-
}
45+
}

0 commit comments

Comments
 (0)