Skip to content
2 changes: 1 addition & 1 deletion src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ static WriterSingleObjectTests()
Data.Add(new(nameof(SingleCaseGenerator.Dimensions)));
Data.Add(new(nameof(SingleCaseGenerator.DimensionWithLineType)));
Data.Add(new(nameof(SingleCaseGenerator.GeoData)));
Data.Add(new(nameof(SingleCaseGenerator.TextAlignment)));
Data.Add(new(nameof(SingleCaseGenerator.LineTypeInBlock)));
Data.Add(new(nameof(SingleCaseGenerator.XData)));
Data.Add(new(nameof(SingleCaseGenerator.XRef)));
Expand Down Expand Up @@ -834,6 +833,7 @@ public void EllipseSegments()
ellipse.RadiusRatio = 0.5d;
ellipse.StartParameter = 0.0d;
ellipse.EndParameter = Math.PI * 2;
ellipse.MajorAxisEndPoint *= 4;
ellipse.Center = center;

var pline = new Polyline3D(ellipse.PolygonalVertexes(4));
Expand Down
3 changes: 0 additions & 3 deletions src/ACadSharp/CadObject.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using ACadSharp.Attributes;
using ACadSharp.Extensions;
using ACadSharp.Objects;
using ACadSharp.Objects.Collections;
using ACadSharp.Tables;
using ACadSharp.Tables.Collections;
using ACadSharp.XData;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down
3 changes: 2 additions & 1 deletion src/ACadSharp/DxfFileToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public static class DxfFileToken
public const string ObjectsSection = "OBJECTS";
public const string ObjectDictionary = "DICTIONARY";
public const string ObjectDictionaryWithDefault = "ACDBDICTIONARYWDFLT";
public const string ObjectDimensionAssociation = "DIMASSOC";
public const string ObjectProxyObject = "ACAD_PROXY_OBJECT";
public const string ObjectDictionaryVar = "DICTIONARYVAR";
public const string ObjectDBColor = "DBCOLOR";
Expand Down Expand Up @@ -139,7 +140,7 @@ public static class DxfFileToken
public const string ObjectTableStyle = "TABLESTYLE";
public const string ObjectCellStyleMap = "CELLSTYLEMAP";
public const string ObjectSpatialFilter = "SPATIAL_FILTER";

//Table tokens
public const string ObjectTableColumn = "COLUMN";
public const string ObjectTableColumnBegin = "TABLECOLUMN_BEGIN";
Expand Down
2 changes: 2 additions & 0 deletions src/ACadSharp/DxfSubclassMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public static class DxfSubclassMarker

public const string DimensionStyleTable = "AcDbDimStyleTable";

public const string DimensionAssociation = "AcDbDimAssoc";

public const string Ellipse = "AcDbEllipse";

public const string Entity = "AcDbEntity";
Expand Down
83 changes: 71 additions & 12 deletions src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,9 @@ private CadTemplate readUnlistedType(short classNumber)
case "ACAD_TABLE":
template = this.readTableEntity();
break;
case DxfFileToken.ObjectDimensionAssociation:
template = this.readDimensionAssociation();
break;
case "DBCOLOR":
template = this.readDbColor();
break;
Expand Down Expand Up @@ -3701,11 +3704,11 @@ private CadTemplate readObjectContextData(CadTemplate template)
ObjectContextData contextData = (ObjectContextData)template.CadObject;

//BS 70 Version (default value is 3).
contextData.Version = _objectReader.ReadBitShort();
contextData.Version = this._objectReader.ReadBitShort();
//B - Has file to extension dictionary (default value is true).
contextData.HasFileToExtensionDictionary = _objectReader.ReadBit();
contextData.HasFileToExtensionDictionary = this._objectReader.ReadBit();
//B 290 Default flag (default value is false).
contextData.Default = _objectReader.ReadBit();
contextData.Default = this._objectReader.ReadBit();

return template;
}
Expand Down Expand Up @@ -3737,13 +3740,13 @@ private MultiLeaderObjectContextData readMultiLeaderAnnotContext(MultiLeaderObje
int leaderRootCount = this._objectReader.ReadBitLong();
if (leaderRootCount == 0)
{
bool b0 = _objectReader.ReadBit();
bool b1 = _objectReader.ReadBit();
bool b2 = _objectReader.ReadBit();
bool b3 = _objectReader.ReadBit();
bool b4 = _objectReader.ReadBit();
bool b5 = _objectReader.ReadBit();
bool b6 = _objectReader.ReadBit();
bool b0 = this._objectReader.ReadBit();
bool b1 = this._objectReader.ReadBit();
bool b2 = this._objectReader.ReadBit();
bool b3 = this._objectReader.ReadBit();
bool b4 = this._objectReader.ReadBit();
bool b5 = this._objectReader.ReadBit();
bool b6 = this._objectReader.ReadBit();

leaderRootCount = b5 ? 2 : 1;
}
Expand Down Expand Up @@ -6402,9 +6405,9 @@ private CadTemplate readVisualStyle()
visualStyle.Type = this._objectReader.ReadBitLong();

//177
var value177 = _objectReader.ReadBitShort();
var value177 = this._objectReader.ReadBitShort();
//291 Internal use only flag
var value291 = _objectReader.ReadBit();
var value291 = this._objectReader.ReadBit();

//70 Count then repeat 90 and 176
int count = this._objectReader.ReadBitLong();
Expand Down Expand Up @@ -7214,6 +7217,62 @@ private static bool looksLikeUtf16Le(byte[] buffer, int offset)

#endregion Object readers

private CadTemplate readDimensionAssociation()
{
DimensionAssociation association = new DimensionAssociation();
CadDimensionAssociationTemplate template = new CadDimensionAssociationTemplate(association);

this.readCommonNonEntityData(template);

//Following the order of dxf:
//330
template.DimensionHandle = this.handleReference();

//90
association.AssociativityFlags = (AssociativityFlags)this._mergedReaders.ReadBitLong();
//70
association.IsTransSpace = this._mergedReaders.ReadBit();
//71
association.RotatedDimensionType = (RotatedDimensionType)this._mergedReaders.ReadByte();

if (association.AssociativityFlags.HasFlag(AssociativityFlags.FirstPointReference))
{
this.readOsnapPointRef();
}

if (association.AssociativityFlags.HasFlag(AssociativityFlags.SecondPointReference))
{
this.readOsnapPointRef();
}

if (association.AssociativityFlags.HasFlag(AssociativityFlags.ThirdPointReference))
{
this.readOsnapPointRef();
}

if (association.AssociativityFlags.HasFlag(AssociativityFlags.FourthPointReference))
{
this.readOsnapPointRef();
}

return template;
}

private DimensionAssociation.OsnapPointRef readOsnapPointRef()
{
var osnap = new DimensionAssociation.OsnapPointRef();

//1
osnap.ClassName = this._mergedReaders.ReadVariableText();
//72
osnap.ObjectOsnapType = (ObjectOsnapType)this._mergedReaders.ReadByte();

//331
ulong h1 = this.handleReference();

return osnap;
}

private CadTemplate readDbColor()
{
BookColor bookColor = new();
Expand Down
36 changes: 35 additions & 1 deletion src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ private CadTemplate readObject()
return this.readObjectCodes<AcdbPlaceHolder>(new CadNonGraphicalObjectTemplate(new AcdbPlaceHolder()), this.readObjectSubclassMap);
case DxfFileToken.ObjectDBColor:
return this.readObjectCodes<BookColor>(new CadNonGraphicalObjectTemplate(new BookColor()), this.readBookColor);
case DxfFileToken.ObjectDimensionAssociation:
return this.readObjectCodes<DimensionAssociation>(new CadDimensionAssociationTemplate(), this.readDimensionAssociation);
case DxfFileToken.ObjectDictionary:
return this.readObjectCodes<CadDictionary>(new CadDictionaryTemplate(), this.readDictionary);
case DxfFileToken.ObjectDictionaryWithDefault:
Expand Down Expand Up @@ -307,7 +309,14 @@ private bool readLayout(CadTemplate template, DxfMap map)
switch (this._reader.Code)
{
case 330:
tmp.PaperSpaceBlockHandle = this._reader.ValueAsHandle;
if (template.OwnerHandle.HasValue)
{
tmp.PaperSpaceBlockHandle = this._reader.ValueAsHandle;
}
else
{
tmp.OwnerHandle = this._reader.ValueAsHandle;
}
return true;
case 331:
tmp.LasActiveViewportHandle = (this._reader.ValueAsHandle);
Expand Down Expand Up @@ -1889,6 +1898,31 @@ private bool readBookColor(CadTemplate template, DxfMap map)
}
}

private bool readDimensionAssociation(CadTemplate template, DxfMap map)
{
CadDimensionAssociationTemplate tmp = template as CadDimensionAssociationTemplate;
DimensionAssociation dimassoc = tmp.CadObject;

switch (this._reader.Code)
{
case 330:
if (template.OwnerHandle.HasValue)
{
tmp.DimensionHandle = this._reader.ValueAsHandle;
}
else
{
tmp.OwnerHandle = this._reader.ValueAsHandle;
}
return true;
case 331:
tmp.GeometryHandle = this._reader.ValueAsHandle;
return true;
default:
return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
}
}

private bool readDictionary(CadTemplate template, DxfMap map)
{
CadDictionaryTemplate tmp = template as CadDictionaryTemplate;
Expand Down
33 changes: 33 additions & 0 deletions src/ACadSharp/IO/Templates/CadDimensionAssociationTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using ACadSharp.Entities;
using ACadSharp.Objects;

namespace ACadSharp.IO.Templates
{
internal class CadDimensionAssociationTemplate : CadTemplate<DimensionAssociation>
{
public ulong? DimensionHandle { get; set; }

public ulong? GeometryHandle { get; set; }

public CadDimensionAssociationTemplate() : base(new())
{
}

public CadDimensionAssociationTemplate(DimensionAssociation obj) : base(obj)
{
}

protected override void build(CadDocumentBuilder builder)
{
base.build(builder);

if (builder.TryGetCadObject<Dimension>(this.DimensionHandle, out var dimension))
{
}

if (builder.TryGetCadObject<CadObject>(this.GeometryHandle, out var geom))
{
}
}
}
}
16 changes: 16 additions & 0 deletions src/ACadSharp/Objects/AssociativityFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace ACadSharp.Objects
{
[System.Flags]
public enum AssociativityFlags : short
{
None = 0,

FirstPointReference = 1,

SecondPointReference = 2,

ThirdPointReference = 4,

FourthPointReference = 8
}
}
Loading
Loading