Skip to content

Commit

Permalink
Merge pull request #212 from DomCR/DwgWriter-Versions
Browse files Browse the repository at this point in the history
DwgWriter versions AC1024 | AC1032
  • Loading branch information
DomCR authored Nov 28, 2023
2 parents a8a50b4 + bdea3d9 commit 65d1d9b
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 82 deletions.
31 changes: 29 additions & 2 deletions ACadSharp.Tests/IO/DWG/DwgWriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using ACadSharp.Entities;
using ACadSharp.IO;
using CSMath;
using System.Collections.Generic;
using System.IO;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions ACadSharp.Tests/IO/DWG/DwgWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void WriteTest(ACadVersion version)
CadDocument readed = re.Read();
}

//this.checkDwgDocumentInAutocad(Path.GetFullPath(path));
this.checkDwgDocumentInAutocad(Path.GetFullPath(path));
}

[Theory]
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion ACadSharp.Tests/IO/IOTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ protected void checkDwgDocumentInAutocad(string path)
}
finally
{
process.WaitForExit();
process.Kill();
}
}
Expand Down
56 changes: 2 additions & 54 deletions ACadSharp.Tests/TestVariables.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;
using CSUtilities;

namespace ACadSharp.Tests
{
Expand All @@ -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<T>(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);
}
}
}
2 changes: 1 addition & 1 deletion ACadSharp/IO/DWG/DwgStreamWriters/DwgAppInfodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion ACadSharp/IO/DWG/DwgStreamWriters/DwgAuxHeaderWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions ACadSharp/IO/DWG/DwgStreamWriters/DwgClassesWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions ACadSharp/IO/DWG/DwgStreamWriters/DwgHeaderWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion ACadSharp/IO/DWG/DwgStreamWriters/DwgPreviewWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion ACadSharp/IO/DWG/DwgStreamWriters/DwgStreamWriterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
9 changes: 3 additions & 6 deletions ACadSharp/IO/DWG/DwgWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion CSUtilities
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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**.
Expand Down

0 comments on commit 65d1d9b

Please sign in to comment.