diff --git a/ACadSharp.Tests/IO/DWG/DwgWriterSingleObjectTests.cs b/ACadSharp.Tests/IO/DWG/DwgWriterSingleObjectTests.cs index 293bd7c8..6221d2b8 100644 --- a/ACadSharp.Tests/IO/DWG/DwgWriterSingleObjectTests.cs +++ b/ACadSharp.Tests/IO/DWG/DwgWriterSingleObjectTests.cs @@ -1,7 +1,6 @@ using ACadSharp.Entities; using ACadSharp.IO; using CSMath; -using System.Collections.Generic; using System.IO; using Xunit; using Xunit.Abstractions; @@ -83,14 +82,42 @@ static DwgWriterSingleObjectTests() [Theory()] [MemberData(nameof(Data))] public void WriteCasesAC1018(SingleCaseGenerator data) + { + this.writeFile(data, ACadVersion.AC1018); + } + + [Theory()] + [MemberData(nameof(Data))] + public void WriteCasesAC1024(SingleCaseGenerator data) + { + this.writeFile(data, ACadVersion.AC1024); + } + + [Theory()] + [MemberData(nameof(Data))] + public void WriteCasesAC1027(SingleCaseGenerator data) + { + this.writeFile(data, ACadVersion.AC1027); + } + + [Theory()] + [MemberData(nameof(Data))] + public void WriteCasesAC1032(SingleCaseGenerator data) + { + this.writeFile(data, ACadVersion.AC1032); + } + + private void writeFile(SingleCaseGenerator data, ACadVersion version) { if (!TestVariables.RunDwgWriterSingleCases) return; - var version = ACadVersion.AC1018; + string path = this.getPath(data.Name, version); data.Document.Header.Version = version; DwgWriter.Write(this.getPath(data.Name, version), data.Document, this.onNotification); + + this.checkDwgDocumentInAutocad(path); } private string getPath(string name, ACadVersion version) diff --git a/ACadSharp.Tests/IO/DWG/DwgWriterTests.cs b/ACadSharp.Tests/IO/DWG/DwgWriterTests.cs index 2acf5c92..b661a19a 100644 --- a/ACadSharp.Tests/IO/DWG/DwgWriterTests.cs +++ b/ACadSharp.Tests/IO/DWG/DwgWriterTests.cs @@ -72,7 +72,7 @@ public void WriteTest(ACadVersion version) CadDocument readed = re.Read(); } - //this.checkDwgDocumentInAutocad(Path.GetFullPath(path)); + this.checkDwgDocumentInAutocad(Path.GetFullPath(path)); } [Theory] @@ -179,10 +179,12 @@ private bool isSupportedVersion(ACadVersion version) case ACadVersion.AC1018: return true; case ACadVersion.AC1021: + return false; case ACadVersion.AC1024: + return true; case ACadVersion.AC1027: case ACadVersion.AC1032: - return false; + return true; case ACadVersion.Unknown: default: return false; diff --git a/ACadSharp.Tests/IO/IOTestsBase.cs b/ACadSharp.Tests/IO/IOTestsBase.cs index e167fe91..be5c1fad 100644 --- a/ACadSharp.Tests/IO/IOTestsBase.cs +++ b/ACadSharp.Tests/IO/IOTestsBase.cs @@ -257,7 +257,6 @@ protected void checkDwgDocumentInAutocad(string path) } finally { - process.WaitForExit(); process.Kill(); } } diff --git a/ACadSharp.Tests/TestVariables.cs b/ACadSharp.Tests/TestVariables.cs index 668119e4..312d7eaa 100644 --- a/ACadSharp.Tests/TestVariables.cs +++ b/ACadSharp.Tests/TestVariables.cs @@ -1,5 +1,4 @@ -using System; -using System.ComponentModel; +using CSUtilities; namespace ACadSharp.Tests { @@ -23,59 +22,8 @@ static TestVariables() EnvironmentVars.SetIfNull("DELTA", "0.00001"); EnvironmentVars.SetIfNull("DECIMAL_PRECISION", "5"); EnvironmentVars.SetIfNull("DXF_CONSOLE_CHECK", "true"); - EnvironmentVars.SetIfNull("DWG_CONSOLE_CHECK", "false"); + EnvironmentVars.SetIfNull("DWG_CONSOLE_CHECK", "true"); EnvironmentVars.SetIfNull("RUN_DWG_WRITER_SINGLE_CASES_TEST", "true"); } } - - [Obsolete("Replace for the one in CSUtilities")] - internal static class EnvironmentVars - { - public static void Set(string name, string value) - { - Environment.SetEnvironmentVariable(name, value, EnvironmentVariableTarget.Process); - } - - public static void SetIfNull(string name, string value) - { - if (Get(name) == null) - { - Set(name, value); - } - } - - public static void SetIfNull(string name, string value, EnvironmentVariableTarget target) - { - if (Get(name) == null) - { - Set(name, value); - } - } - - public static string Get(string name) - { - return Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process); - } - - public static string Get(string name, EnvironmentVariableTarget target) - { - return Environment.GetEnvironmentVariable(name, target); - } - - public static T Get(string name) - { - string value = Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process); - return (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(value); - } - - public static void Delete(string name) - { - Environment.SetEnvironmentVariable(name, null, EnvironmentVariableTarget.Process); - } - - public static void Delete(string name, EnvironmentVariableTarget target) - { - Environment.SetEnvironmentVariable(name, null, target); - } - } } diff --git a/ACadSharp/IO/DWG/DwgStreamWriters/DwgAppInfodWriter.cs b/ACadSharp/IO/DWG/DwgStreamWriters/DwgAppInfodWriter.cs index 4a907d2c..af0996ce 100644 --- a/ACadSharp/IO/DWG/DwgStreamWriters/DwgAppInfodWriter.cs +++ b/ACadSharp/IO/DWG/DwgStreamWriters/DwgAppInfodWriter.cs @@ -13,7 +13,7 @@ internal class DwgAppInfoWriter : DwgSectionIO public DwgAppInfoWriter(ACadVersion version, Stream stream) : base(version) { - this.writer = DwgStreamWriterBase.GetStreamHandler(version, stream, Encoding.Unicode); + this.writer = DwgStreamWriterBase.GetStreamWriter(version, stream, Encoding.Unicode); } public void Write() diff --git a/ACadSharp/IO/DWG/DwgStreamWriters/DwgAuxHeaderWriter.cs b/ACadSharp/IO/DWG/DwgStreamWriters/DwgAuxHeaderWriter.cs index 402fdcb5..cebeea1e 100644 --- a/ACadSharp/IO/DWG/DwgStreamWriters/DwgAuxHeaderWriter.cs +++ b/ACadSharp/IO/DWG/DwgStreamWriters/DwgAuxHeaderWriter.cs @@ -21,7 +21,7 @@ public DwgAuxHeaderWriter(MemoryStream stream, CadHeader header) public void Write() { - IDwgStreamWriter writer = DwgStreamWriterBase.GetStreamHandler(this._version, this._stream, TextEncoding.Windows1252()); + IDwgStreamWriter writer = DwgStreamWriterBase.GetStreamWriter(this._version, this._stream, TextEncoding.Windows1252()); //RC: 0xff 0x77 0x01 writer.WriteByte(0xFF); diff --git a/ACadSharp/IO/DWG/DwgStreamWriters/DwgClassesWriter.cs b/ACadSharp/IO/DWG/DwgStreamWriters/DwgClassesWriter.cs index 1c3e7648..46b57ef7 100644 --- a/ACadSharp/IO/DWG/DwgStreamWriters/DwgClassesWriter.cs +++ b/ACadSharp/IO/DWG/DwgStreamWriters/DwgClassesWriter.cs @@ -31,10 +31,10 @@ internal class DwgClassesWriter : DwgSectionIO public DwgClassesWriter(CadDocument document, ACadVersion version, Stream stream) : base(version) { this._document = document; - this._startWriter = DwgStreamWriterBase.GetStreamHandler(version, stream, TextEncoding.Windows1252()); + this._startWriter = DwgStreamWriterBase.GetStreamWriter(version, stream, TextEncoding.Windows1252()); this._sectionStream = new MemoryStream(); - this._writer = DwgStreamWriterBase.GetStreamHandler(version, _sectionStream, TextEncoding.Windows1252()); + this._writer = DwgStreamWriterBase.GetMergedWriter(version, _sectionStream, TextEncoding.Windows1252()); } public void Write() diff --git a/ACadSharp/IO/DWG/DwgStreamWriters/DwgFileHeaderWriterAC15.cs b/ACadSharp/IO/DWG/DwgStreamWriters/DwgFileHeaderWriterAC15.cs index bed27bc9..520cadef 100644 --- a/ACadSharp/IO/DWG/DwgStreamWriters/DwgFileHeaderWriterAC15.cs +++ b/ACadSharp/IO/DWG/DwgStreamWriters/DwgFileHeaderWriterAC15.cs @@ -98,7 +98,7 @@ private void writeFileHeader() MemoryStream memoryStream = new MemoryStream(); //0x00 6 “ACXXXX” version string - IDwgStreamWriter writer = DwgStreamWriterBase.GetStreamHandler(this._version, memoryStream, this._encoding); + IDwgStreamWriter writer = DwgStreamWriterBase.GetStreamWriter(this._version, memoryStream, this._encoding); writer.WriteBytes(Encoding.ASCII.GetBytes(this._document.Header.VersionString)); //The next 7 starting at offset 0x06 are to be six bytes of 0 //(in R14, 5 0’s and the ACADMAINTVER variable) and a byte of 1. diff --git a/ACadSharp/IO/DWG/DwgStreamWriters/DwgFileHeaderWriterAC18.cs b/ACadSharp/IO/DWG/DwgStreamWriters/DwgFileHeaderWriterAC18.cs index f5369c81..aa063192 100644 --- a/ACadSharp/IO/DWG/DwgStreamWriters/DwgFileHeaderWriterAC18.cs +++ b/ACadSharp/IO/DWG/DwgStreamWriters/DwgFileHeaderWriterAC18.cs @@ -166,7 +166,7 @@ protected MemoryStream applyCompression(byte[] buffer, int decompressedSize, ulo private void writeDescriptors() { MemoryStream stream = new MemoryStream(); - var swriter = DwgStreamWriterBase.GetStreamHandler(_version, stream, _encoding); + var swriter = DwgStreamWriterBase.GetStreamWriter(_version, stream, _encoding); //0x00 4 Number of section descriptions(NumDescriptions) swriter.WriteInt(this._descriptors.Count); diff --git a/ACadSharp/IO/DWG/DwgStreamWriters/DwgHeaderWriter.cs b/ACadSharp/IO/DWG/DwgStreamWriters/DwgHeaderWriter.cs index ae29c7c5..0f6e1ada 100644 --- a/ACadSharp/IO/DWG/DwgStreamWriters/DwgHeaderWriter.cs +++ b/ACadSharp/IO/DWG/DwgStreamWriters/DwgHeaderWriter.cs @@ -23,10 +23,10 @@ public DwgHeaderWriter(Stream stream, CadDocument document) : base(document.Head this._document = document; this._header = document.Header; - this._startWriter = DwgStreamWriterBase.GetStreamHandler(_version, stream, TextEncoding.Windows1252()); + this._startWriter = DwgStreamWriterBase.GetStreamWriter(_version, stream, TextEncoding.Windows1252()); this._msmain = new MemoryStream(); - this._writer = DwgStreamWriterBase.GetStreamHandler(_version, this._msmain, TextEncoding.Windows1252()); + this._writer = DwgStreamWriterBase.GetStreamWriter(_version, this._msmain, TextEncoding.Windows1252()); } public void Write() diff --git a/ACadSharp/IO/DWG/DwgStreamWriters/DwgPreviewWriter.cs b/ACadSharp/IO/DWG/DwgStreamWriters/DwgPreviewWriter.cs index 56aca919..65d84311 100644 --- a/ACadSharp/IO/DWG/DwgStreamWriters/DwgPreviewWriter.cs +++ b/ACadSharp/IO/DWG/DwgStreamWriters/DwgPreviewWriter.cs @@ -23,7 +23,7 @@ internal class DwgPreviewWriter : DwgSectionIO public DwgPreviewWriter(ACadVersion version, Stream stream) : base(version) { - this._swriter = DwgStreamWriterBase.GetStreamHandler(version, stream, TextEncoding.Windows1252()); + this._swriter = DwgStreamWriterBase.GetStreamWriter(version, stream, TextEncoding.Windows1252()); } public void Write() diff --git a/ACadSharp/IO/DWG/DwgStreamWriters/DwgStreamWriterBase.cs b/ACadSharp/IO/DWG/DwgStreamWriters/DwgStreamWriterBase.cs index 8ec669d1..ab4db21d 100644 --- a/ACadSharp/IO/DWG/DwgStreamWriters/DwgStreamWriterBase.cs +++ b/ACadSharp/IO/DWG/DwgStreamWriters/DwgStreamWriterBase.cs @@ -29,7 +29,7 @@ public DwgStreamWriterBase(Stream stream, Encoding encoding) : base(stream) this.Encoding = encoding; } - public static IDwgStreamWriter GetStreamHandler(ACadVersion version, Stream stream, Encoding encoding) + public static IDwgStreamWriter GetStreamWriter(ACadVersion version, Stream stream, Encoding encoding) { switch (version) { diff --git a/ACadSharp/IO/DWG/DwgWriter.cs b/ACadSharp/IO/DWG/DwgWriter.cs index 2a4e0a40..3a6ac318 100644 --- a/ACadSharp/IO/DWG/DwgWriter.cs +++ b/ACadSharp/IO/DWG/DwgWriter.cs @@ -138,14 +138,11 @@ private void getFileHeaderWriter() break; case ACadVersion.AC1021: throw new DwgNotSupportedException(this._document.Header.Version); - //this._fileHeaderWriter = new DwgFileHeaderWriterAC21(_stream, _document); - //break; case ACadVersion.AC1024: case ACadVersion.AC1027: case ACadVersion.AC1032: - throw new DwgNotSupportedException(this._document.Header.Version); - //this._fileHeaderWriter = new DwgFileHeaderWriterAC18(_stream, _document); - //break; + this._fileHeaderWriter = new DwgFileHeaderWriterAC18(_stream, encoding, _document); + break; case ACadVersion.Unknown: default: throw new DwgNotSupportedException(); @@ -179,7 +176,7 @@ private void writeSummaryInfo() return; MemoryStream stream = new MemoryStream(); - var writer = DwgStreamWriterBase.GetStreamHandler(_version, stream, TextEncoding.Windows1252()); + var writer = DwgStreamWriterBase.GetStreamWriter(_version, stream, TextEncoding.Windows1252()); CadSummaryInfo info = this._document.SummaryInfo; diff --git a/CSUtilities b/CSUtilities index d30a3ddb..0220ffee 160000 --- a/CSUtilities +++ b/CSUtilities @@ -1 +1 @@ -Subproject commit d30a3ddb67f002d96dc06e749d4a403d22980450 +Subproject commit 0220ffee4d9bcc74dbe111c76eafa3e464b0e8cd diff --git a/README.md b/README.md index b01d2f7f..2097019e 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,10 @@ AC1012 | :heavy_check_mark: | :heavy_check_mark: | :x: | :x AC1014 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | AC1015 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | AC1018 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | -AC1021 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | -AC1024 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | -AC1027 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | -AC1032 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | +AC1021 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | +AC1024 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | +AC1027 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | +AC1032 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | ### Current development @@ -39,9 +39,9 @@ AC1032 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_m - **AC1018** - AutoCAD 2004/2005/2006 - **MOST STABLE - RECOMENDED** - **AC1021** - AutoCAD 2007/2008/2009 - **NOT IMPLEMENTED** - This is a particular and isolated DWG version, it uses a different compression system and file distribution, due this difficulties, this version will not be implemented any time soon. -- **AC1024** - AutoCAD 2010/2011/2012 - **NOT IMPLEMENTED** +- **AC1024** - AutoCAD 2010/2011/2012 - **STABLE** - **AC1027** - AutoCAD 2013/2014/2015/2016/2017 - **NOT IMPLEMENTED** -- **AC1032** - AutoCAD 2018/2019/2020 - **NOT IMPLEMENTED** +- **AC1032** - AutoCAD 2018/2019/2020 - **STABLE** **IMPORTANT NOTE** when you open a file writen by ACadSharp with Autocad the following message may appear: *The drawing file requires recovery* press on Recover and it will open the file normally. This process may cause a **loss of information on the file**.