From 468605fbf82ee654144320fa71c7ee979e5de4f4 Mon Sep 17 00:00:00 2001 From: DomCR Date: Tue, 1 Oct 2024 13:02:40 +0200 Subject: [PATCH 1/2] refactor --- src/ACadSharp/Entities/Viewport.cs | 32 ++++++++++++++++--- .../DWG/DwgStreamReaders/DwgObjectReader.cs | 2 +- .../DwgObjectWriter.Entities.cs | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/ACadSharp/Entities/Viewport.cs b/src/ACadSharp/Entities/Viewport.cs index 42ec53a5..6536e4d8 100644 --- a/src/ACadSharp/Entities/Viewport.cs +++ b/src/ACadSharp/Entities/Viewport.cs @@ -17,6 +17,11 @@ namespace ACadSharp.Entities [DxfSubClass(DxfSubclassMarker.Viewport)] public class Viewport : Entity { + /// + /// Paper view Id, it indicates that the viewport acts as a paper size. + /// + public const int PaperViewId = 1; + /// public override ObjectType ObjectType => ObjectType.VIEWPORT; @@ -48,7 +53,26 @@ public class Viewport : Entity /// Viewport ID /// [DxfCodeValue(69)] - public short Id { get; set; } = 1; + public short Id + { + get + { + if (this.Owner is BlockRecord record) + { + short id = 0; + foreach (Viewport viewport in record.Viewports) + { + id += 1; + if (viewport == this) + { + return id; + } + } + } + + return 0; + } + } /// /// View center point(in DCS) @@ -274,7 +298,7 @@ public double ViewWidth /// View contrast /// [DxfCodeValue(142)] - public double Constrast { get; set; } + public double Contrast { get; set; } /// /// Ambient light color.Write only if not black color. @@ -310,8 +334,8 @@ public override CadObject Clone() /// public override BoundingBox GetBoundingBox() { - XYZ min = new XYZ(Center.X - this.Width, Center.Y - this.Height, Center.Z); - XYZ max = new XYZ(Center.X + this.Width, Center.Y + this.Height, Center.Z); + XYZ min = new XYZ(this.Center.X - this.Width / 2, this.Center.Y - this.Height / 2, this.Center.Z); + XYZ max = new XYZ(this.Center.X + this.Width / 2, this.Center.Y + this.Height / 2, this.Center.Z); return new BoundingBox(min, max); } diff --git a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs index dac09e25..7d98092a 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs @@ -2305,7 +2305,7 @@ private CadTemplate readViewport() //Brightness BD 141 viewport.Brightness = this._objectReader.ReadBitDouble(); //Contrast BD 142 - viewport.Constrast = this._objectReader.ReadBitDouble(); + viewport.Contrast = this._objectReader.ReadBitDouble(); //Ambient light color CMC 63 viewport.AmbientLightColor = this._objectReader.ReadCmColor(); } diff --git a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs index 2fd799a6..7cab5414 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs @@ -2346,7 +2346,7 @@ private void writeViewport(Viewport viewport) //Brightness BD 141 this._writer.WriteBitDouble(viewport.Brightness); //Contrast BD 142 - this._writer.WriteBitDouble(viewport.Constrast); + this._writer.WriteBitDouble(viewport.Contrast); //Ambient light color CMC 63 this._writer.WriteCmColor(viewport.AmbientLightColor); } From 752c2695d77aa3339e2a46fc09c4f20da3260955 Mon Sep 17 00:00:00 2001 From: DomCR Date: Tue, 1 Oct 2024 13:03:26 +0200 Subject: [PATCH 2/2] minor layer fix --- src/ACadSharp/Tables/Layer.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ACadSharp/Tables/Layer.cs b/src/ACadSharp/Tables/Layer.cs index 354bcd1a..dd756bea 100644 --- a/src/ACadSharp/Tables/Layer.cs +++ b/src/ACadSharp/Tables/Layer.cs @@ -46,10 +46,22 @@ public class Layer : TableEntry /// if the index is negative, layer is off /// [DxfCodeValue(62, 420, 430)] - public Color Color { get; set; } = new Color(7); + public Color Color + { + get { return this._color; } + set + { + if (value.IsByLayer || value.IsByBlock) + { + throw new ArgumentException("The layer color cannot be ByLayer or ByBlock", nameof(value)); + } + + this._color = value; + } + } /// - /// The linetype of an object. The default linetype is the linetype of the layer (ByLayer). + /// The line type of an object. The default line type is the line type of the layer (ByLayer). /// [DxfCodeValue(DxfReferenceType.Name, 6)] public LineType LineType @@ -80,7 +92,7 @@ public LineType LineType public bool PlotFlag { get; set; } = true; /// - /// Specifies the lineweight of an individual object or the default lineweight for the drawing. + /// Specifies the line weight of an individual object or the default line weight for the drawing. /// [DxfCodeValue(370)] public LineweightType LineWeight { get; set; } = LineweightType.Default; @@ -104,6 +116,8 @@ public LineType LineType private LineType _lineType = LineType.Continuous; + private Color _color = new Color(7); + internal Layer() : base() { } public Layer(string name) : base(name) { }