Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/DomCR/ACadSharp
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Oct 2, 2024
2 parents 5ed2c8f + 62beaca commit 7f2c7b5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 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
20 changes: 17 additions & 3 deletions src/ACadSharp/Tables/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,22 @@ public class Layer : TableEntry
/// if the index is negative, layer is off
/// </remarks>
[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;
}
}

/// <summary>
/// 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).
/// </summary>
[DxfCodeValue(DxfReferenceType.Name, 6)]
public LineType LineType
Expand Down Expand Up @@ -80,7 +92,7 @@ public LineType LineType
public bool PlotFlag { get; set; } = true;

/// <summary>
/// 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.
/// </summary>
[DxfCodeValue(370)]
public LineweightType LineWeight { get; set; } = LineweightType.Default;
Expand All @@ -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) { }
Expand Down

0 comments on commit 7f2c7b5

Please sign in to comment.