Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Oct 1, 2024
1 parent cfe076d commit 468605f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
32 changes: 28 additions & 4 deletions src/ACadSharp/Entities/Viewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ namespace ACadSharp.Entities
[DxfSubClass(DxfSubclassMarker.Viewport)]
public class Viewport : Entity
{
/// <summary>
/// Paper view Id, it indicates that the viewport acts as a paper size.
/// </summary>
public const int PaperViewId = 1;

/// <inheritdoc/>
public override ObjectType ObjectType => ObjectType.VIEWPORT;

Expand Down Expand Up @@ -48,7 +53,26 @@ public class Viewport : Entity
/// Viewport ID
/// </summary>
[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;
}
}

/// <summary>
/// View center point(in DCS)
Expand Down Expand Up @@ -274,7 +298,7 @@ public double ViewWidth
/// View contrast
/// </summary>
[DxfCodeValue(142)]
public double Constrast { get; set; }
public double Contrast { get; set; }

/// <summary>
/// Ambient light color.Write only if not black color.
Expand Down Expand Up @@ -310,8 +334,8 @@ public override CadObject Clone()
/// <inheritdoc/>
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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 468605f

Please sign in to comment.