Skip to content

Commit

Permalink
viewport scale fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Dec 6, 2024
1 parent bb8e671 commit 2dade95
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public SingleCaseGenerator() { }
public SingleCaseGenerator(string name)
{
this.Name = name;
this.Document.Header.ShowModelSpace = true;
}

public override string ToString()
Expand Down
29 changes: 24 additions & 5 deletions src/ACadSharp/Entities/Viewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,38 @@ public Scale Scale
{
get
{
return this._scale;
if (this.Document != null)
{
if (this.XDictionary != null && this.XDictionary.TryGetEntry(ASDK_XREC_ANNOTATION_SCALE_INFO, out XRecord record))
{
foreach (XRecord.Entry item in record.Entries)
{
if (item.Code == 340)
{
return item.Value as Scale;
}
}
}

return null;
}
else
{
return this._scale;
}
}
set
{
if (this.Document != null)
{
this._scale = this.updateCollection(value, this.Document.Scales);
this.updateScaleXRecord();
}
else
{
this._scale = value;
}

this.updateScaleXRecord();
}
}

Expand Down Expand Up @@ -433,7 +452,7 @@ internal override void AssignDocument(CadDocument doc)
{
base.AssignDocument(doc);

this._scale = this.updateCollection(this.Scale, doc.Scales);
this._scale = this.updateCollection(this._scale, doc.Scales);

this.Document.Scales.OnRemove += this.scalesOnRemove;
}
Expand Down Expand Up @@ -468,7 +487,7 @@ private void updateScaleXRecord()
{
if (item.Code == 340)
{
item.Value = this._scale.Handle;
item.Value = this._scale;
}
}
}
Expand All @@ -477,7 +496,7 @@ private void updateScaleXRecord()
record = new XRecord(ASDK_XREC_ANNOTATION_SCALE_INFO);
this.XDictionary.Add(record);

record.CreateEntry(340, _scale.Handle);
record.CreateEntry(340, _scale);
}
}
}
Expand Down

0 comments on commit 2dade95

Please sign in to comment.