From 8b5ab70628ed065486852bc1a1a3cfdf610ad8ff Mon Sep 17 00:00:00 2001 From: DomCR Date: Mon, 20 Nov 2023 20:43:36 +0100 Subject: [PATCH 1/5] Color using short implementation --- ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs b/ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs index 1d847dff..8c9feea5 100644 --- a/ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs +++ b/ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs @@ -89,7 +89,7 @@ public override Color ReadEnColor(out Transparency transparency, out bool flag) else { //Color index: if no flags were set, the color is looked up by the color number (ACI color). - color = new Color((byte)(size & 0b111111111111)); + color = new Color((short)(size & 0b111111111111)); } //0x2000: color is followed by a transparency BL From 96ecdcb185516a529933c8e680915fc3fbe7774e Mon Sep 17 00:00:00 2001 From: DomCR Date: Tue, 27 Feb 2024 04:42:30 +0100 Subject: [PATCH 2/5] layer test --- ACadSharp.Tests/IO/WriterSingleObjectTests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ACadSharp.Tests/IO/WriterSingleObjectTests.cs b/ACadSharp.Tests/IO/WriterSingleObjectTests.cs index 3eee8d2a..8943841b 100644 --- a/ACadSharp.Tests/IO/WriterSingleObjectTests.cs +++ b/ACadSharp.Tests/IO/WriterSingleObjectTests.cs @@ -36,6 +36,14 @@ public void DefaultLayer() this.Document.Layers.Add(new Layer("default_layer")); } + public void LayerTrueColor() + { + Layer layer = new Layer("Layer_true_color"); + layer.Color = Color.FromTrueColor(1151726); + + this.Document.Layers.Add(layer); + } + public void EntityColorByLayer() { Layer layer = new Layer("Test"); @@ -171,6 +179,7 @@ static WriterSingleObjectTests() Data.Add(new(nameof(SingleCaseGenerator.EntityColorByLayer))); Data.Add(new(nameof(SingleCaseGenerator.EntityColorTrueColor))); Data.Add(new(nameof(SingleCaseGenerator.DefaultLayer))); + Data.Add(new(nameof(SingleCaseGenerator.LayerTrueColor))); Data.Add(new(nameof(SingleCaseGenerator.SingleMText))); Data.Add(new(nameof(SingleCaseGenerator.SingleMTextSpecialCharacter))); Data.Add(new(nameof(SingleCaseGenerator.SingleMTextMultiline))); From f8de3bd8ed247e67a68259688fcd23bbc73aa62c Mon Sep 17 00:00:00 2001 From: DomCR Date: Tue, 27 Feb 2024 04:42:40 +0100 Subject: [PATCH 3/5] notes --- ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs b/ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs index e9e77a6d..ee7f1eb7 100644 --- a/ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs +++ b/ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs @@ -72,6 +72,7 @@ public override Color ReadEnColor(out Transparency transparency, out bool flag) { //color flags: first byte of the bitshort. ushort flags = (ushort)((ushort)size & 0b1111111100000000); + //0x4000: has AcDbColor reference (0x8000 is also set in this case). if ((flags & 0x4000) > 0) { @@ -83,6 +84,7 @@ public override Color ReadEnColor(out Transparency transparency, out bool flag) else if ((flags & 0x8000) > 0) { //Next value is a BS containing the RGB value(last 24 bits). + //flags: 0b1100_0010_0000_0000_0000_0000_0000_0000 uint rgb = (uint)this.ReadBitLong(); color = Color.FromTrueColor(rgb & 0b00000000111111111111111111111111); } From 9e656e0c75d22ffee52f6a42edeb5c250b0ea57d Mon Sep 17 00:00:00 2001 From: DomCR Date: Tue, 27 Feb 2024 04:42:49 +0100 Subject: [PATCH 4/5] fix --- .../IO/DWG/DwgStreamWriters/DwgStreamWriterAC18.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ACadSharp/IO/DWG/DwgStreamWriters/DwgStreamWriterAC18.cs b/ACadSharp/IO/DWG/DwgStreamWriters/DwgStreamWriterAC18.cs index 4570e0b5..12a0cee0 100644 --- a/ACadSharp/IO/DWG/DwgStreamWriters/DwgStreamWriterAC18.cs +++ b/ACadSharp/IO/DWG/DwgStreamWriters/DwgStreamWriterAC18.cs @@ -20,9 +20,9 @@ public override void WriteCmColor(Color value) if (value.IsTrueColor) { - arr[0] = (byte)(value.R); - arr[1] = (byte)(value.G); - arr[2] = (byte)(value.B); + arr[0] = (byte)value.R; + arr[1] = (byte)value.G; + arr[2] = (byte)value.B; arr[3] = 0b1100_0010; } else @@ -55,7 +55,7 @@ public override void WriteEnColor(Color color, Transparency transparency) //0x2000: color is followed by a transparency BL if (!transparency.IsByLayer) { - size = (ushort)(size | 0x2000); + size = (ushort)(size | 0b10000000000000); } //0x8000: complex color (rgb). @@ -73,7 +73,8 @@ public override void WriteEnColor(Color color, Transparency transparency) if (color.IsTrueColor) { - base.WriteBitLong(color.TrueColor); + uint rgb = (uint)(0b1100_0010_0000_0000_0000_0000_0000_0000 | color.TrueColor); + base.WriteBitLong((int)rgb); } if (!transparency.IsByLayer) From 014bc1a35b1044cdd655e83806919ace8e5677db Mon Sep 17 00:00:00 2001 From: Ihor Date: Thu, 29 Feb 2024 00:36:12 +0300 Subject: [PATCH 5/5] fix: Fixed bug in reading bulges for hatch.BoundaryPath.Polyline from dwg file --- ACadSharp/Entities/Hatch.BoundaryPath.Polyline.cs | 7 ++++--- ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs | 6 ++++-- .../IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs | 9 ++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ACadSharp/Entities/Hatch.BoundaryPath.Polyline.cs b/ACadSharp/Entities/Hatch.BoundaryPath.Polyline.cs index 2836f57b..d6c519ae 100644 --- a/ACadSharp/Entities/Hatch.BoundaryPath.Polyline.cs +++ b/ACadSharp/Entities/Hatch.BoundaryPath.Polyline.cs @@ -1,6 +1,7 @@ using ACadSharp.Attributes; using CSMath; using System.Collections.Generic; +using System.Linq; namespace ACadSharp.Entities { @@ -17,7 +18,7 @@ public class Polyline : Edge /// Has bulge flag /// [DxfCodeValue(72)] - public bool HasBulge { get { return Bulge != 0; } } + public bool HasBulge => this.Bulges.Any(); /// /// Is closed flag @@ -29,10 +30,10 @@ public class Polyline : Edge /// Bulge /// /// - /// optional, default = 0 + /// optional, default empty /// [DxfCodeValue(42)] - public double Bulge { get; set; } = 0.0; + public List Bulges { get; set; } = new List(); /// /// Position values are only X and Y diff --git a/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs b/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs index d8091d0b..922457e8 100644 --- a/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs +++ b/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs @@ -4968,9 +4968,11 @@ private CadTemplate readHatch() //pt0 2RD 10 point on polyline XY vertex = this._objectReader.Read2RawDouble(); - if (bulgespresent) + if (bulgespresent) { //bulge BD 42 bulge - pline.Bulge = this._objectReader.ReadBitDouble(); + double bulge = this._objectReader.ReadBitDouble(); + pline.Bulges.Add(bulge); + } //Add the vertex pline.Vertices.Add(new XY(vertex.X, vertex.Y)); diff --git a/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs b/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs index 19e56559..953b7b02 100644 --- a/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs +++ b/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs @@ -856,12 +856,15 @@ private void writeHatch(Hatch hatch) //numpathsegs BL 91 number of path segments this._writer.WriteBitLong(pline.Vertices.Count); - foreach (var vertex in pline.Vertices) + for (var i = 0; i < pline.Vertices.Count; ++i) { - this._writer.Write2RawDouble(vertex); + var vertex = pline.Vertices[i]; + var bulge = pline.Bulges[i]; + + this._writer.Write2RawDouble(new XY(vertex.X, vertex.Y)); if (pline.HasBulge) { - this._writer.WriteBitDouble(pline.Bulge); + this._writer.WriteBitDouble(bulge); } } }