Skip to content

Commit

Permalink
add support for AcDb2LineAngularDimension
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo committed May 6, 2020
1 parent 7352bae commit 378d5d2
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/IxMilia.Dxf.Generator/EntityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private void OutputSingleDxfEntity(XElement entity)
AppendXData(entity);
AppendDefaultConstructor(entity);
AppendParameterizedConstructors(entity);
AppendCopyConstructor(entity, "DxfEntity");
AppendCopyConstructor(entity);
AppendInitializeMethod(entity, BaseClass(entity, "") == "DxfDimensionBase" ? $"this.DimensionType = DxfDimensionType.{Tag(entity)};" : null);
AppendAddValuePairsMethod(entity);
AppendTrySetPairMethod(entity);
Expand Down
3 changes: 2 additions & 1 deletion src/IxMilia.Dxf.Generator/GeneratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void AppendAddValuePairsMethod(XElement item)
}
}

public void AppendCopyConstructor(XElement item, string baseClass)
public void AppendCopyConstructor(XElement item)
{
var copyConstructorAccessibility = CopyConstructor(item);
if (copyConstructorAccessibility != null)
Expand All @@ -87,6 +87,7 @@ public void AppendCopyConstructor(XElement item, string baseClass)
AppendLine(" : base(other)");
AppendLine("{");
IncreaseIndent();
AppendLine("CopyManualValues(other);");
AppendLine("((IDxfHasXDataHidden)this).XDataHidden = ((IDxfHasXDataHidden)other).XDataHidden;");
foreach (var property in GetPropertiesAndPointers(item))
{
Expand Down
2 changes: 1 addition & 1 deletion src/IxMilia.Dxf.Generator/ObjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private void OutputSingleDxfObject(XElement obj)
AppendXData(obj);
AppendDefaultConstructor(obj);
AppendParameterizedConstructors(obj);
AppendCopyConstructor(obj, "DxfObject");
AppendCopyConstructor(obj);
AppendInitializeMethod(obj);
AppendAddValuePairsMethod(obj);

Expand Down
17 changes: 17 additions & 0 deletions src/IxMilia.Dxf.Generator/Specs/EntitiesSpec.xml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,23 @@
<Value>DefinitionPoint3</Value>
</Extents>
</Entity>
<!-- angular, 2 line -->
<Entity Name="DxfAngularTwoLineDimension" EntityType="Dimension" SubclassMarker="AcDb2LineAngularDimension" TypeString="" BaseClass="DxfDimensionBase" CopyConstructor="Inherited" HasXData="true" Tag="Angular">
<Property Name="FirstExtensionLineP1" Code="13" Type="DxfPoint" DefaultValue="DxfPoint.Origin" CodeOverrides="13,23,33" />
<Property Name="FirstExtensionLineP2" Code="14" Type="DxfPoint" DefaultValue="DxfPoint.Origin" CodeOverrides="14,24,34" />
<Property Name="SecondExtensionLineP2" Code="15" Type="DxfPoint" DefaultValue="DxfPoint.Origin" CodeOverrides="15,25,35" />
<Property Name="DimensionLineArcLocation" Code="16" Type="DxfPoint" DefaultValue="DxfPoint.Origin" CodeOverrides="16,26,36" />
<Extents>
<!-- from DxfDimensionBase -->
<Value>TextMidPoint</Value>
<!-- from this entity -->
<Value>FirstExtensionLineP1</Value>
<Value>FirstExtensionLineP2</Value>
<Value>SecondExtensionLineP1</Value>
<Value>SecondExtensionLineP2</Value>
<Value>DimensionLineArcLocation</Value>
</Extents>
</Entity>
<!--
ELLIPSE
Expand Down
56 changes: 56 additions & 0 deletions src/IxMilia.Dxf.Test/DxfEntityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,62 @@ public void WriteDimensionTest()
");
}

[Fact]
public void ReadAngularTwoLineDimensionTest()
{
var dim = (DxfAngularTwoLineDimension)Entity("DIMENSION", @"
100
AcDbDimension
10
1.0
20
2.0
30
3.0
11
4.0
21
5.0
31
6.0
70
130
100
AcDb2LineAngularDimension
13
7.0
23
8.0
33
9.0
14
10.0
24
11.0
34
12.0
15
13.0
25
14.0
35
15.0
16
16.0
26
17.0
36
18.0
");
Assert.True(dim.IsAtUserDefinedLocation);
Assert.Equal(new DxfPoint(1.0, 2.0, 3.0), dim.SecondExtensionLineP1);
Assert.Equal(new DxfPoint(4.0, 5.0, 6.0), dim.TextMidPoint);
Assert.Equal(new DxfPoint(7.0, 8.0, 9.0), dim.FirstExtensionLineP1);
Assert.Equal(new DxfPoint(10.0, 11.0, 12.0), dim.FirstExtensionLineP2);
Assert.Equal(new DxfPoint(13.0, 14.0, 15.0), dim.SecondExtensionLineP2);
Assert.Equal(new DxfPoint(16.0, 17.0, 18.0), dim.DimensionLineArcLocation);
}

[Fact]
public void WriteDimensionWithTrailingXDataTest()
{
Expand Down
13 changes: 13 additions & 0 deletions src/IxMilia.Dxf/Entities/DxfAngularTwoLineDimension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) IxMilia. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace IxMilia.Dxf.Entities
{
public partial class DxfAngularTwoLineDimension
{
public DxfPoint SecondExtensionLineP1
{
get => DefinitionPoint1;
set => DefinitionPoint1 = value;
}
}
}
10 changes: 10 additions & 0 deletions src/IxMilia.Dxf/Entities/DxfDimensionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ public partial class DxfDimensionBase : DxfEntity

public bool IsAtUserDefinedLocation { get; set; } = false;

protected override void CopyManualValues(DxfEntity other)
{
if (other is DxfDimensionBase otherDim)
{
IsBlockReferenceReferencedByThisBlockOnly = otherDim.IsBlockReferenceReferencedByThisBlockOnly;
IsOrdinateXType = otherDim.IsOrdinateXType;
IsAtUserDefinedLocation = otherDim.IsAtUserDefinedLocation;
}
}

private DxfDimensionType HandleDimensionType(short value)
{
// reader
Expand Down
4 changes: 4 additions & 0 deletions src/IxMilia.Dxf/Entities/DxfEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ internal virtual void AddObjectsToOutput(List<DxfObject> objects)
{
}

protected virtual void CopyManualValues(DxfEntity other)
{
}

protected virtual DxfEntity PostParse()
{
return this;
Expand Down

0 comments on commit 378d5d2

Please sign in to comment.