diff --git a/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs b/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs index a5419b272..7b4889079 100644 --- a/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs +++ b/src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs @@ -81,7 +81,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))); @@ -839,6 +838,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)); diff --git a/src/ACadSharp/CadObject.cs b/src/ACadSharp/CadObject.cs index 966e037ff..835ca16b3 100644 --- a/src/ACadSharp/CadObject.cs +++ b/src/ACadSharp/CadObject.cs @@ -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; diff --git a/src/ACadSharp/DxfFileToken.cs b/src/ACadSharp/DxfFileToken.cs index be83568c0..26462f28a 100644 --- a/src/ACadSharp/DxfFileToken.cs +++ b/src/ACadSharp/DxfFileToken.cs @@ -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"; @@ -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"; diff --git a/src/ACadSharp/DxfSubclassMarker.cs b/src/ACadSharp/DxfSubclassMarker.cs index 2dde47c43..381128222 100644 --- a/src/ACadSharp/DxfSubclassMarker.cs +++ b/src/ACadSharp/DxfSubclassMarker.cs @@ -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"; diff --git a/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs b/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs index 85fd82b70..c870ca78c 100644 --- a/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs +++ b/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs @@ -63,6 +63,8 @@ private CadTemplate readObject() return this.readObjectCodes(new CadNonGraphicalObjectTemplate(new AcdbPlaceHolder()), this.readObjectSubclassMap); case DxfFileToken.ObjectDBColor: return this.readObjectCodes(new CadNonGraphicalObjectTemplate(new BookColor()), this.readBookColor); + case DxfFileToken.ObjectDimensionAssociation: + return this.readObjectCodes(new CadDimensionAssociationTemplate(), this.readDimensionAssociation); case DxfFileToken.ObjectDictionary: return this.readObjectCodes(new CadDictionaryTemplate(), this.readDictionary); case DxfFileToken.ObjectDictionaryWithDefault: @@ -302,7 +304,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); @@ -1673,6 +1682,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; diff --git a/src/ACadSharp/IO/Templates/CadDimensionAssociationTemplate.cs b/src/ACadSharp/IO/Templates/CadDimensionAssociationTemplate.cs new file mode 100644 index 000000000..fa0bf4ffe --- /dev/null +++ b/src/ACadSharp/IO/Templates/CadDimensionAssociationTemplate.cs @@ -0,0 +1,33 @@ +using ACadSharp.Entities; +using ACadSharp.Objects; + +namespace ACadSharp.IO.Templates +{ + internal class CadDimensionAssociationTemplate : CadTemplate + { + 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(this.DimensionHandle, out var dimension)) + { + } + + if (builder.TryGetCadObject(this.GeometryHandle, out var geom)) + { + } + } + } +} \ No newline at end of file diff --git a/src/ACadSharp/Objects/DimensionAssociation.cs b/src/ACadSharp/Objects/DimensionAssociation.cs new file mode 100644 index 000000000..42148ea54 --- /dev/null +++ b/src/ACadSharp/Objects/DimensionAssociation.cs @@ -0,0 +1,176 @@ +using ACadSharp.Attributes; +using ACadSharp.Entities; +using CSMath; + +namespace ACadSharp.Objects +{ + [System.Flags] + public enum AssociativityFlags : short + { + None = 0, + + FirstPointReference = 1, + + SecondPointReference = 2, + + ThirdPointReference = 4, + + FourthPointReference = 8 + } + + public enum ObjectOsnapType : short + { + None = 0, + + Endpoint = 1, + + Midpoint = 2, + + Center = 3, + + Node = 4, + + Quadrant = 5, + + Intersection = 6, + + Insertion = 7, + + Perpendicular = 8, + + Tangent = 9, + + Nearest = 10, + + ApparentIntersection = 11, + + Parallel = 12, + + StartPoint = 13, + } + + public enum RotatedDimensionType : short + { + Unknown = 0, + + Parallel = 1, + + Perpendicular = 2 + } + + public enum SubentType : short + { + Unknown = 0, + + Edge = 1, + + Face = 2 + } + + /// + /// Represents a object. + /// + /// + /// Object name
+ /// Dxf class name + ///
+ [DxfName(DxfFileToken.ObjectDimensionAssociation)] + [DxfSubClass(DxfSubclassMarker.DimensionAssociation)] + public class DimensionAssociation : NonGraphicalObject + { + /// + /// Gets or sets the associativity flags that define the reference points for an entity. + /// + [DxfCodeValue(90)] + public AssociativityFlags AssociativityFlags { get; set; } + + /// + /// Gets the name of the class represented by this instance. + /// + [DxfCodeValue(1)] + public string ClassName { get; set; } = "AcDbOsnapPointRef"; + + /// + /// Gets or sets the associated dimension object. + /// + [DxfCodeValue(DxfReferenceType.Handle, 330)] + public Dimension Dimension { get; set; } + + /// + /// Gets or sets the geometry parameter used for the Near object snap (Osnap). + /// + [DxfCodeValue(40)] + public double GeometryParameter { get; set; } + + /// + /// Gets or sets a value indicating whether the entity is in trans-space. + /// + [DxfCodeValue(70)] + public bool IsTransSpace { get; set; } + + /// + public override string ObjectName => DxfFileToken.ObjectDimensionAssociation; + + /// + /// Gets or sets the object snap type associated with the entity. + /// + [DxfCodeValue(72)] + public ObjectOsnapType ObjectOsnapType { get; set; } + + /// + public override ObjectType ObjectType => ObjectType.UNLISTED; + + //301 + //Handle(string) of Xref object + /// + /// Gets or sets the object snap (Osnap) point in world coordinate system (WCS). + /// + /// The Osnap point is used to specify precise locations on geometry for object snapping + /// operations. + [DxfCodeValue(10, 20, 30)] + public XYZ OsnapPoint { get; set; } + + /// + /// Gets or sets the type of the rotated dimension, indicating whether it is parallel or perpendicular. + /// + [DxfCodeValue(71)] + public RotatedDimensionType RotatedDimensionType { get; set; } = RotatedDimensionType.Unknown; + + /// + public override string SubclassMarker => DxfSubclassMarker.DimensionAssociation; + + /// + /// Gets or sets the type of the rotated dimension, indicating whether it is parallel or perpendicular. + /// + [DxfCodeValue(73)] + public SubentType SubentType { get; set; } = SubentType.Unknown; + + //331 + //ID of main object (geometry) + + //73 + //SubentType of main object (edge, face) + + //91 + //GsMarker of main object (index) + //332 + //ID of intersection object (geometry) + + //74 + //SubentType of intersction object (edge/face) + + //92 + //GsMarker of intersection object (index) + + //302 + //Handle(string) of intersection Xref object + + //75 + //hasLastPointRef flag(true/false) + + /// + public DimensionAssociation() : base() + { + } + } +} \ No newline at end of file