Repository navigation
DWG reader: keep plot style, xref block and dimension context data; read RTEXT #1272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
70c1ef9
feea1dd
bc19399
b89367e
65995f5
c7c962d
17034a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2000,10 +2000,11 @@ private void readEntityMode(CadEntityTemplate template) | |
|
|
||
| //R2000 +: | ||
| //Plotstyle flags BB 00 = bylayer, 01 = byblock, 11 = plotstyle handle present at end of object | ||
| if (this._objectReader.Read2Bits() == 3) | ||
| template.CadObject.PlotStyleFlags = this._objectReader.Read2Bits(); | ||
| if (template.CadObject.PlotStyleFlags == 3) | ||
| { | ||
| //PLOTSTYLE (hard pointer) present if plotstyle flags were 11 | ||
| long plotstyleFlags = (long)this.handleReference(); | ||
| template.CadObject.PlotStyleHandle = this.handleReference(); | ||
| } | ||
|
|
||
| //R2007 +: | ||
|
|
@@ -2714,12 +2715,10 @@ private CadTemplate readLayer() | |
| var color = this._mergedReaders.ReadCmColor(); | ||
| layer.Color = color.IsByBlock || color.IsByLayer ? Color.Default : color; | ||
|
|
||
| //TODO: This is not the Layer control handle | ||
| template.LayerControlHandle = this.handleReference(); | ||
| //Handle refs H Layer control (soft pointer) | ||
| //[Reactors(soft pointer)] | ||
| //xdicobjhandle(hard owner) | ||
| //External reference block handle(hard pointer) | ||
| //Handle refs H Layer control (soft pointer), [Reactors (soft pointer)] and xdicobjhandle | ||
| //(hard owner) are read with the common data; this one is the | ||
| //External reference block handle (hard pointer): the xref a dependent layer comes from | ||
| layer.XrefBlockHandle = this.handleReference(); | ||
|
|
||
| //R2000+: | ||
| if (this.R2000Plus) | ||
|
|
@@ -5091,7 +5090,7 @@ private void readPlotSettings(PlotSettings plot) | |
| plot.ShadePlotDPI = this._objectReader.ReadBitShort(); | ||
|
|
||
| //6 plot view handle(hard pointer) | ||
| ulong plotViewHandle = this.handleReference(); | ||
| plot.PlotViewHandle = this.handleReference(); | ||
| } | ||
|
|
||
| //R2007 +: | ||
|
|
@@ -6182,6 +6181,11 @@ private CadTemplate readUnlistedType(short classNumber) | |
| break; | ||
| } | ||
|
|
||
| if (template == null && c.DxfName.EndsWith("DIMOBJECTCONTEXTDATA_CLASS")) | ||
| { | ||
| template = this.readDimensionObjectContextData(); | ||
| } | ||
|
|
||
| if (template == null && c.IsAnEntity) | ||
| { | ||
| template = this.readUnknownEntity(c); | ||
|
|
@@ -7290,6 +7294,26 @@ private CadTemplate readUnknownEntity(DxfClass dxfClass) | |
|
|
||
| this.readCommonEntityData(template); | ||
|
|
||
| if (dxfClass?.DxfName == "RTEXT") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be in the switch in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: moved to |
||
| { | ||
| try | ||
| { | ||
| var rt = new UnknownEntity.RemoteText(); | ||
| rt.InsertPoint = this._objectReader.Read3BitDouble(); | ||
| rt.Normal = this._objectReader.Read3BitDouble(); | ||
| rt.Rotation = this._objectReader.ReadBitDouble(); | ||
| rt.Height = this._objectReader.ReadBitDouble(); | ||
| rt.Flags = this._objectReader.ReadBitShort(); | ||
| rt.Contents = this._textReader.ReadVariableText(); | ||
| rt.StyleHandle = this.handleReference(); | ||
| entity.RText = rt; | ||
| } | ||
| catch (System.Exception ex) | ||
| { | ||
| this._builder.Notify($"RTEXT could not be read: {ex.Message}", NotificationType.Warning); | ||
| } | ||
| } | ||
|
|
||
| return template; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using ACadSharp.Objects; | ||
| using ACadSharp.Tables; | ||
|
|
||
| namespace ACadSharp.IO.Templates; | ||
|
|
||
| internal class CadDimensionObjectContextDataTemplate : CadAnnotScaleObjectContextDataTemplate | ||
| { | ||
| public ulong? BlockHandle { get; set; } | ||
|
|
||
| public CadDimensionObjectContextDataTemplate(DimensionObjectContextData cadObject) : base(cadObject) { } | ||
|
|
||
| protected override void build(CadDocumentBuilder builder) | ||
| { | ||
| base.build(builder); | ||
|
|
||
| if (builder.TryGetCadObject(this.BlockHandle, out BlockRecord block)) | ||
| { | ||
| ((DimensionObjectContextData)this.CadObject).Block = block; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using ACadSharp.Tables; | ||
|
|
||
| namespace ACadSharp.Objects; | ||
|
|
||
| /// <summary> | ||
| /// Annotation scale representation of a dimension (ACDB_*DIMOBJECTCONTEXTDATA_CLASS): the dimension's | ||
| /// geometry block for one annotation scale. Only the block is read. | ||
| /// </summary> | ||
| public class DimensionObjectContextData : AnnotScaleObjectContextData | ||
| { | ||
| /// <summary>Anonymous block holding the dimension's graphics at <see cref="AnnotScaleObjectContextData.Scale"/>.</summary> | ||
| public BlockRecord Block { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override string ObjectName => "ACDB_DIMOBJECTCONTEXTDATA_CLASS"; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in the switch in
readUnlistedTypefollowing the same pattern.You can use "ACDB_DIMOBJECTCONTEXTDATA_CLASS".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved into the
readUnlistedTypeswitch. A singleACDB_DIMOBJECTCONTEXTDATA_CLASScase would never match, though: DWG/DXF files store one class per dimension type, and no file declares the base name (that is why I had usedEndsWith). I checked this against a drawing made in AutoCAD.So there is now one class and one
DxfFileTokenconstant per type, all derived from an abstractDimensionObjectContextData(AcDbDimensionObjectContextData):ACDB_ALDIMOBJECTCONTEXTDATA_CLASS→AlignedDimensionObjectContextData(aligned and linear)ACDB_ANGDIMOBJECTCONTEXTDATA_CLASS→AngularDimensionObjectContextData(angular and arc length)ACDB_DMDIMOBJECTCONTEXTDATA_CLASS→DiametricDimensionObjectContextDataACDB_ORDDIMOBJECTCONTEXTDATA_CLASS→OrdinateDimensionObjectContextDataACDB_RADIMOBJECTCONTEXTDATA_CLASS→RadialDimensionObjectContextDataACDB_RADIMLRGOBJECTCONTEXTDATA_CLASS→RadialDimensionLargeObjectContextData(extends the radial one)The data fields are now read as well, from both DWG and DXF: text location and rotation, the per-scale overrides (DIMTOFL, DIMSOXD, DIMTIX and the override flags), arrow flips, and each type's points. I decoded the DWG bit layout from that AutoCAD drawing and checked it against its DXF export. One finding: DWG stores DIMATFIT and DIMTMOVE only as "overridden" bits, so their values are read from DXF only.
The drawing is in
samples/annotative/, andDimensionObjectContextDataTestscompares the DWG and DXF reads. Known gaps:LARGE_RADIAL_DIMENSIONentities are not read yet, so the large radial context data is not covered by the tests (its layout was only checked by hand against the DXF), and the writers still skip these objects.