Skip to content

Commit

Permalink
Merge branch '20240225_mme_MultiLeader_rework' of https://github.com/…
Browse files Browse the repository at this point in the history
…nanoLogika/ACadSharp into 20240225_mme_MultiLeader_rework
  • Loading branch information
mme1950 committed Mar 1, 2024
2 parents 5d2cc56 + 003636b commit f90b346
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
9 changes: 9 additions & 0 deletions ACadSharp.Tests/IO/WriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)));
Expand Down
7 changes: 4 additions & 3 deletions ACadSharp/Entities/Hatch.BoundaryPath.Polyline.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ACadSharp.Attributes;
using CSMath;
using System.Collections.Generic;
using System.Linq;

namespace ACadSharp.Entities
{
Expand All @@ -17,7 +18,7 @@ public class Polyline : Edge
/// Has bulge flag
/// </summary>
[DxfCodeValue(72)]
public bool HasBulge { get { return Bulge != 0; } }
public bool HasBulge => this.Bulges.Any();

/// <summary>
/// Is closed flag
Expand All @@ -29,10 +30,10 @@ public class Polyline : Edge
/// Bulge
/// </summary>
/// <remarks>
/// optional, default = 0
/// optional, default empty
/// </remarks>
[DxfCodeValue(42)]
public double Bulge { get; set; } = 0.0;
public List<double> Bulges { get; set; } = new List<double>();

/// <remarks>
/// Position values are only X and Y
Expand Down
6 changes: 4 additions & 2 deletions ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
}
Expand Down
9 changes: 6 additions & 3 deletions ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions ACadSharp/IO/DWG/DwgStreamWriters/DwgStreamWriterAC18.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand All @@ -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)
Expand Down

0 comments on commit f90b346

Please sign in to comment.