From 6853cf78b906e02be54e1ea85b71f117ba63cf57 Mon Sep 17 00:00:00 2001 From: DomCR Date: Sun, 15 Dec 2024 12:50:20 +0100 Subject: [PATCH 1/6] added dim test --- src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs b/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs index 721e5e65..8dc55291 100644 --- a/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs +++ b/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs @@ -410,6 +410,15 @@ public void AddCustomScale() this.Document.Scales.Add(new Scale("Hello")); } + public void Dimensions() + { + DimensionAligned dim = new DimensionAligned(); + + dim.SecondPoint = new XYZ(10); + + this.Document.Entities.Add(dim); + } + public void AddCustomBookColor() { //var color = new BookColor("RAL CLASSIC$RAL 1006"); @@ -513,6 +522,7 @@ static WriterSingleObjectTests() Data.Add(new(nameof(SingleCaseGenerator.AddBlockWithAttributes))); Data.Add(new(nameof(SingleCaseGenerator.AddCustomScale))); Data.Add(new(nameof(SingleCaseGenerator.AddCustomBookColor))); + Data.Add(new(nameof(SingleCaseGenerator.Dimensions))); } protected string getPath(string name, string ext, ACadVersion version) From 94e6256ceced84cf4e780dbc4a155b997338115e Mon Sep 17 00:00:00 2001 From: DomCR Date: Mon, 16 Dec 2024 10:08:42 +0100 Subject: [PATCH 2/6] anonymous blocks fix --- .../DWG/DwgStreamReaders/DwgObjectReader.cs | 7 +---- .../DwgObjectWriter.Common.cs | 1 - .../DwgObjectWriter.Objects.cs | 26 ++++++++++++++++--- .../DWG/DwgStreamWriters/DwgObjectWriter.cs | 11 ++++++-- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs index a78448ab..ac5c81df 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs @@ -2683,11 +2683,6 @@ private CadTemplate readDictionary() this.readCommonDictionary(template); - if (cadDictionary.Handle == this._builder.HeaderHandles.DICTIONARY_NAMED_OBJECTS) - { - - } - return template; } @@ -3654,7 +3649,7 @@ private CadTemplate readBlockHeader() //Common: //Entry name TV 2 - //Warning: names ended with a number are not readed in this method + //Warning: anonymous blocks do not write the full name, only *{type character} string name = this._textReader.ReadVariableText(); if (name.Equals(BlockRecord.ModelSpaceName, System.StringComparison.CurrentCultureIgnoreCase) || name.Equals(BlockRecord.PaperSpaceName, System.StringComparison.CurrentCultureIgnoreCase)) diff --git a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Common.cs b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Common.cs index 7935d2e7..a64cc717 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Common.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Common.cs @@ -349,7 +349,6 @@ private void writeReactorsAndDictionaryHandle(CadObject cadObject) //R2004+: if (this.R2004Plus) { - this._writer.WriteBit(noDictionary); if (!noDictionary) { diff --git a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs index 8a1e27fa..21d6104e 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs @@ -3,6 +3,7 @@ using CSUtilities.Converters; using CSUtilities.IO; using System; +using System.Collections.Generic; using System.IO; using System.Linq; @@ -153,7 +154,24 @@ private void writeDictionary(CadDictionary dictionary) { //Common: //Numitems L number of dictonary items - this._writer.WriteBitLong(dictionary.Count()); + List entries = new List(); + foreach (var item in dictionary) + { + if (item is XRecord && !this.WriteXRecords) + { + continue; + } + + if (item is UnknownNonGraphicalObject) + { + continue; + } + + entries.Add(item); + } + + //16 + this._writer.WriteBitLong(entries.Count); //R14 Only: if (this._version == ACadVersion.AC1014) @@ -171,16 +189,16 @@ private void writeDictionary(CadDictionary dictionary) } //Common: - foreach (var item in dictionary) + foreach (var item in entries) { if (item is XRecord && !this.WriteXRecords) { - return; + continue; } if (item is UnknownNonGraphicalObject) { - return; + continue; } this._writer.WriteVariableText(item.Name); diff --git a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs index f7590efe..1270b39f 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs @@ -257,8 +257,15 @@ private void writeBlockHeader(BlockRecord record) //Common: //Entry name TV 2 - //Warning: names ended with a number are not readed in this method - this._writer.WriteVariableText(record.Name); + if (record.Flags.HasFlag(BlockTypeFlags.Anonymous)) + { + //Warning: anonymous blocks do not write the full name, only *{type character} + this._writer.WriteVariableText(record.Name.Substring(0, 2)); + } + else + { + this._writer.WriteVariableText(record.Name); + } this.writeXrefDependantBit(record); From d1c9dae411a83d42c5aa865d36939e6520cde3c6 Mon Sep 17 00:00:00 2001 From: DomCR Date: Mon, 16 Dec 2024 11:47:25 +0100 Subject: [PATCH 3/6] fix for dict with default --- src/ACadSharp/Objects/CadDictionaryWithDefault.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ACadSharp/Objects/CadDictionaryWithDefault.cs b/src/ACadSharp/Objects/CadDictionaryWithDefault.cs index 75d95f28..3fb35be3 100644 --- a/src/ACadSharp/Objects/CadDictionaryWithDefault.cs +++ b/src/ACadSharp/Objects/CadDictionaryWithDefault.cs @@ -13,10 +13,13 @@ namespace ACadSharp.Objects [DxfSubClass(DxfSubclassMarker.DictionaryWithDefault)] public class CadDictionaryWithDefault : CadDictionary { + /// public override ObjectType ObjectType { get { return ObjectType.UNLISTED; } } - public override string ObjectName => DxfFileToken.ObjectDictionary; + /// + public override string ObjectName => DxfFileToken.ObjectDictionaryWithDefault; + /// public override string SubclassMarker => DxfSubclassMarker.DictionaryWithDefault; /// From abf41ef3c0b2baeac8c0167ba17f2011dab4b739 Mon Sep 17 00:00:00 2001 From: DomCR Date: Mon, 16 Dec 2024 11:50:15 +0100 Subject: [PATCH 4/6] typo --- src/ACadSharp.Tests/IO/LocalSampleTests.cs | 28 +++++++++++++++++++ .../IO/WriterSingleObjectTests.cs | 8 ++++-- src/ACadSharp/Header/CadHeader.cs | 2 +- .../DWG/DwgStreamWriters/DwgHeaderWriter.cs | 2 +- src/ACadSharp/Tables/VPort.cs | 8 ++---- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/ACadSharp.Tests/IO/LocalSampleTests.cs b/src/ACadSharp.Tests/IO/LocalSampleTests.cs index 925f6a66..eec4a272 100644 --- a/src/ACadSharp.Tests/IO/LocalSampleTests.cs +++ b/src/ACadSharp.Tests/IO/LocalSampleTests.cs @@ -1,5 +1,6 @@ using ACadSharp.Entities; using ACadSharp.IO; +using ACadSharp.Tables; using ACadSharp.Tests.TestModels; using System.Diagnostics; using System.IO; @@ -36,6 +37,33 @@ public void ReadUserDwg(FileModel test) return; CadDocument doc = DwgReader.Read(test.Path, this._dwgConfiguration, this.onNotification); + + if (test.Path.Contains("out")) + { + return; + } + + CadDocument a = new CadDocument(); + + var b = doc.GetCadObject(0x94); + var b1 = doc.GetCadObject(14); + var b2 = doc.GetCadObject(25); + + var vport = doc.VPorts[VPort.DefaultName]; + //vport.ExtendedData.Clear(); + + //doc.VPorts.Remove(VPort.DefaultName); + //doc.VPorts.Add(VPort.Default); + + //doc.RootDictionary.Remove("AcDbVariableDictionary", out _); + + //doc.Header = new ACadSharp.Header.CadHeader(); + //doc.Header.Version = ACadVersion.AC1032; + + doc.RootDictionary.Remove("AcadPlotStyleName", out _); + + string path = Path.ChangeExtension(test.Path, ".out.dwg"); + DwgWriter.Write(path, doc, notification: this.onNotification); } [Theory] diff --git a/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs b/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs index 8dc55291..f43f9dc4 100644 --- a/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs +++ b/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs @@ -20,12 +20,14 @@ public class SingleCaseGenerator : IXunitSerializable public CadDocument Document { get; private set; } = new CadDocument(); - public SingleCaseGenerator() { } + public SingleCaseGenerator() + { + this.Document.Header.ShowModelSpace = true; + } - public SingleCaseGenerator(string name) + public SingleCaseGenerator(string name) : this() { this.Name = name; - this.Document.Header.ShowModelSpace = true; } public override string ToString() diff --git a/src/ACadSharp/Header/CadHeader.cs b/src/ACadSharp/Header/CadHeader.cs index 3f5f6583..79af2ca5 100644 --- a/src/ACadSharp/Header/CadHeader.cs +++ b/src/ACadSharp/Header/CadHeader.cs @@ -2967,7 +2967,7 @@ public static Dictionary GetHeaderMap() } /// - /// Set a valueo of a system variable by name + /// Set a value of a system variable by name /// /// name of the system var /// parameters for the constructor of the value diff --git a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgHeaderWriter.cs b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgHeaderWriter.cs index 401d90c2..a68f295f 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgHeaderWriter.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgHeaderWriter.cs @@ -45,7 +45,7 @@ public void Write() //R2013+: if (this.R2013Plus) { - //BLL : Variabele REQUIREDVERSIONS, default value 0, read only. + //BLL : Variable REQUIREDVERSIONS, default value 0, read only. this._writer.WriteBitLongLong(0); } diff --git a/src/ACadSharp/Tables/VPort.cs b/src/ACadSharp/Tables/VPort.cs index d2ba4fce..48430ef4 100644 --- a/src/ACadSharp/Tables/VPort.cs +++ b/src/ACadSharp/Tables/VPort.cs @@ -5,8 +5,6 @@ namespace ACadSharp.Tables { - //TODO: Implement UCS for VPORT - /// /// Represents a table entry /// @@ -144,13 +142,13 @@ public XYZ Direction /// Render mode /// [DxfCodeValue(281)] - public RenderMode RenderMode { get; set; } + public RenderMode RenderMode { get; set; } = RenderMode.Optimized2D; /// /// View mode(see VIEWMODE system variable) /// [DxfCodeValue(71)] - public ViewModeType ViewMode { get; set; } + public ViewModeType ViewMode { get; set; } = ViewModeType.FrontClippingZ; /// /// UCSICON setting @@ -223,7 +221,7 @@ public XYZ Direction /// Orthographic type of UCS /// [DxfCodeValue(79)] - public OrthographicType OrthographicType { get; set; } + public OrthographicType OrthographicType { get; set; } = OrthographicType.None; /// /// Elevation From 2486a019fedb6ca93141974535e5c473b9ba76ff Mon Sep 17 00:00:00 2001 From: DomCR Date: Mon, 16 Dec 2024 13:00:13 +0100 Subject: [PATCH 5/6] dimension fix --- src/ACadSharp.Tests/IO/LocalSampleTests.cs | 20 +------------------ src/ACadSharp/IO/DWG/DwgReader.cs | 2 ++ .../DwgObjectWriter.Entities.cs | 4 +++- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/ACadSharp.Tests/IO/LocalSampleTests.cs b/src/ACadSharp.Tests/IO/LocalSampleTests.cs index eec4a272..210e71e6 100644 --- a/src/ACadSharp.Tests/IO/LocalSampleTests.cs +++ b/src/ACadSharp.Tests/IO/LocalSampleTests.cs @@ -2,6 +2,7 @@ using ACadSharp.IO; using ACadSharp.Tables; using ACadSharp.Tests.TestModels; +using CSMath; using System.Diagnostics; using System.IO; using System.Linq; @@ -43,25 +44,6 @@ public void ReadUserDwg(FileModel test) return; } - CadDocument a = new CadDocument(); - - var b = doc.GetCadObject(0x94); - var b1 = doc.GetCadObject(14); - var b2 = doc.GetCadObject(25); - - var vport = doc.VPorts[VPort.DefaultName]; - //vport.ExtendedData.Clear(); - - //doc.VPorts.Remove(VPort.DefaultName); - //doc.VPorts.Add(VPort.Default); - - //doc.RootDictionary.Remove("AcDbVariableDictionary", out _); - - //doc.Header = new ACadSharp.Header.CadHeader(); - //doc.Header.Version = ACadVersion.AC1032; - - doc.RootDictionary.Remove("AcadPlotStyleName", out _); - string path = Path.ChangeExtension(test.Path, ".out.dwg"); DwgWriter.Write(path, doc, notification: this.onNotification); } diff --git a/src/ACadSharp/IO/DWG/DwgReader.cs b/src/ACadSharp/IO/DWG/DwgReader.cs index a6439513..2a9cc216 100644 --- a/src/ACadSharp/IO/DWG/DwgReader.cs +++ b/src/ACadSharp/IO/DWG/DwgReader.cs @@ -227,6 +227,8 @@ public override CadHeader ReadHeader() if (this._builder != null) this._builder.HeaderHandles = headerHandles; + header.Document = this._document; + return header; } diff --git a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs index 8d160315..85eb5a6f 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs @@ -341,7 +341,9 @@ private void writeCommonDimensionData(Dimension dimension) //H 3 DIMSTYLE(hard pointer) this._writer.HandleReference(DwgReferenceType.HardPointer, dimension.Style); //H 2 anonymous BLOCK(hard pointer) - this._writer.HandleReference(DwgReferenceType.HardPointer, dimension.Block); + //TODO: fix annotative dimensions + //this._writer.HandleReference(DwgReferenceType.HardPointer, dimension.Block); + this._writer.HandleReference(DwgReferenceType.HardPointer, null); } private void writeDimensionLinear(DimensionLinear dimension) From 5379b90b66a852586d42aec216b5550c2c74e1eb Mon Sep 17 00:00:00 2001 From: DomCR Date: Mon, 16 Dec 2024 13:53:25 +0100 Subject: [PATCH 6/6] cleanup --- src/ACadSharp.Tests/IO/LocalSampleTests.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/ACadSharp.Tests/IO/LocalSampleTests.cs b/src/ACadSharp.Tests/IO/LocalSampleTests.cs index 210e71e6..90feff3d 100644 --- a/src/ACadSharp.Tests/IO/LocalSampleTests.cs +++ b/src/ACadSharp.Tests/IO/LocalSampleTests.cs @@ -38,14 +38,6 @@ public void ReadUserDwg(FileModel test) return; CadDocument doc = DwgReader.Read(test.Path, this._dwgConfiguration, this.onNotification); - - if (test.Path.Contains("out")) - { - return; - } - - string path = Path.ChangeExtension(test.Path, ".out.dwg"); - DwgWriter.Write(path, doc, notification: this.onNotification); } [Theory]