Skip to content

Commit d4e1bf1

Browse files
authored
Merge pull request #582 from DomCR/issue-580_dxfclasses-dwgreader-fix
Dwg DxfClasses reader fix
2 parents 5d7d965 + 627bf3e commit d4e1bf1

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

src/ACadSharp/Exceptions/CadNotSupportedException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace ACadSharp.Exceptions
55
[Serializable]
66
public class CadNotSupportedException : NotSupportedException
77
{
8-
public CadNotSupportedException() : base($"File version not recognised") { }
8+
public CadNotSupportedException() : base($"File version not recognized") { }
99

1010
public CadNotSupportedException(ACadVersion version) : base($"File version not supported: {version}") { }
1111
}

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public DxfClassCollection Read()
6565

6666
if (this._fileHeader.AcadVersion == ACadVersion.AC1018)
6767
{
68-
//BS : Maxiumum class number
68+
//BS : Maximum class number
6969
this._sreader.ReadBitShort();
7070
//RC: 0x00
7171
this._sreader.ReadRawChar();
@@ -113,20 +113,10 @@ public DxfClassCollection Read()
113113
//BL : Number of objects created of this type in the current DB(DXF 91).
114114
dxfClass.InstanceCount = this._sreader.ReadBitLong();
115115

116-
if (this._fileHeader.AcadVersion == ACadVersion.AC1018)
117-
{
118-
//BS : Dwg Version
119-
dxfClass.DwgVersion = (ACadVersion)this._sreader.ReadBitShort();
120-
//BS : Maintenance release version.
121-
dxfClass.MaintenanceVersion = this._sreader.ReadBitShort();
122-
}
123-
else if (this._fileHeader.AcadVersion > ACadVersion.AC1018)
124-
{
125-
//BS : Dwg Version
126-
dxfClass.DwgVersion = (ACadVersion)this._sreader.ReadBitLong();
127-
//BS : Maintenance release version.
128-
dxfClass.MaintenanceVersion = (short)this._sreader.ReadBitLong();
129-
}
116+
//BS : Dwg Version
117+
dxfClass.DwgVersion = (ACadVersion)this._sreader.ReadBitLong();
118+
//BS : Maintenance release version.
119+
dxfClass.MaintenanceVersion = (short)this._sreader.ReadBitLong();
130120

131121
//BL : Unknown(normally 0L)
132122
this._sreader.ReadBitLong();

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
using CSUtilities.IO;
55
using CSUtilities.Text;
66
using System;
7-
using System.Collections.Generic;
87
using System.IO;
8+
using System.Runtime.CompilerServices;
99
using System.Text;
1010

1111
namespace ACadSharp.IO.DWG
@@ -41,7 +41,6 @@ public static IDwgStreamReader GetStreamHandler(ACadVersion version, Stream stre
4141
switch (version)
4242
{
4343
case ACadVersion.Unknown:
44-
throw new Exception();
4544
case ACadVersion.MC0_0:
4645
case ACadVersion.AC1_2:
4746
case ACadVersion.AC1_4:
@@ -52,7 +51,7 @@ public static IDwgStreamReader GetStreamHandler(ACadVersion version, Stream stre
5251
case ACadVersion.AC1004:
5352
case ACadVersion.AC1006:
5453
case ACadVersion.AC1009:
55-
throw new NotSupportedException($"Dwg version not supported: {version}");
54+
throw new CadNotSupportedException(version);
5655
case ACadVersion.AC1012:
5756
case ACadVersion.AC1014:
5857
reader = new DwgStreamReaderAC12(stream, resetPositon);
@@ -72,7 +71,7 @@ public static IDwgStreamReader GetStreamHandler(ACadVersion version, Stream stre
7271
reader = new DwgStreamReaderAC24(stream, resetPositon);
7372
break;
7473
default:
75-
throw new NotSupportedException($"Dwg version not supported: {version}");
74+
throw new CadNotSupportedException();
7675
}
7776

7877
if (encoding != null)
@@ -105,7 +104,7 @@ public static Dictionary<string, object> Explore(IDwgStreamReader reader)
105104
tryGetValue(reader, values, reader.ReadRawChar);
106105
tryGetValue(reader, values, reader.ReadRawLong);
107106
tryGetValue(reader, values, reader.Read2RawDouble);
108-
107+
109108
tryGetValue(reader, values, reader.HandleReference);
110109

111110
tryGetValue(reader, values, reader.ReadTextUnicode);
@@ -271,7 +270,7 @@ public short ReadBitShort()
271270
value = 256;
272271
break;
273272
default:
274-
throw new Exception();
273+
throw this.throwException();
275274
}
276275
return value;
277276
}
@@ -308,7 +307,7 @@ public int ReadBitLong()
308307
break;
309308
default:
310309
//11 : not used
311-
throw new Exception();
310+
throw new Exception("Failed to read ReadBitLong");
312311
}
313312
return value;
314313
}
@@ -344,7 +343,7 @@ public double ReadBitDouble()
344343
value = 0.0;
345344
break;
346345
default:
347-
throw new Exception();
346+
throw this.throwException();
348347
}
349348

350349
return value;
@@ -824,7 +823,7 @@ public double ReadBitDoubleWithDefault(double def)
824823
case 3:
825824
return this.ReadDouble();
826825
default:
827-
throw new Exception();
826+
throw this.throwException();
828827
}
829828
}
830829

@@ -859,7 +858,6 @@ public TimeSpan ReadTimeSpan()
859858
if (hours < 0 || hours > TimeSpan.MaxValue.TotalHours || milliseconds < 0 || milliseconds > TimeSpan.MaxValue.TotalMilliseconds)
860859
{
861860
return TimeSpan.FromHours(0) + TimeSpan.FromMilliseconds(0);
862-
863861
}
864862

865863
return TimeSpan.FromHours(hours) + TimeSpan.FromMilliseconds(milliseconds);
@@ -963,6 +961,11 @@ protected byte applyShiftToLasByte()
963961
return (byte)((uint)value | (byte)((uint)this._lastByte >> 8 - this.BitShift));
964962
}
965963

964+
protected DwgException throwException([CallerMemberName] string callerName = null)
965+
{
966+
return new DwgException($"Failed to read {callerName}");
967+
}
968+
966969
private void applyShiftToArr(int length, byte[] arr)
967970
{
968971
//Empty Stream

src/CodeMaid.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
serializeAs="String">
9090
<value>True</value>
9191
</setting>
92+
<setting name="Cleaning_InsertBlankLinePaddingBeforeCaseStatements"
93+
serializeAs="String">
94+
<value>False</value>
95+
</setting>
9296
</SteveCadwallader.CodeMaid.Properties.Settings>
9397
</userSettings>
9498
</configuration>

0 commit comments

Comments
 (0)