Skip to content

Commit c548ff6

Browse files
authored
Merge pull request #949 from DomCR/issue-948_dynamic-blocks-refactor
issue-948 dynamic properties
2 parents 5dfe7c4 + 8516db0 commit c548ff6

31 files changed

+18040
-326
lines changed
37.7 KB
Binary file not shown.

samples/dynamic-blocks/BLOCKVISIBILITYPARAMETER.dxf

Lines changed: 17330 additions & 0 deletions
Large diffs are not rendered by default.

src/ACadSharp.Tests/IO/DynamicBlockTests.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
using ACadSharp.Entities;
22
using ACadSharp.IO;
3+
using ACadSharp.Objects;
34
using ACadSharp.Objects.Evaluations;
45
using ACadSharp.Tables;
56
using ACadSharp.Tests.TestModels;
7+
using System.Linq;
68
using Xunit;
79
using Xunit.Abstractions;
810

911
namespace ACadSharp.Tests.IO
1012
{
1113
public class DynamicBlockTests : IOTestsBase
1214
{
13-
public static TheoryData<FileModel> DwgDynamicBlocksPaths { get; } = new();
15+
public static TheoryData<FileModel> GenericDynamicBlocksPaths { get; } = new();
16+
17+
public static TheoryData<FileModel> IsolatedDynamicBlocksPaths { get; } = new();
1418

1519
static DynamicBlockTests()
1620
{
17-
loadSamples("./", "dxf", DwgDynamicBlocksPaths);
18-
loadSamples("./", "dwg", DwgDynamicBlocksPaths);
21+
loadSamples("./", "dxf", GenericDynamicBlocksPaths);
22+
loadSamples("./", "dwg", GenericDynamicBlocksPaths);
23+
24+
loadSamples("./dynamic-blocks", "*dwg", IsolatedDynamicBlocksPaths);
25+
loadSamples("./dynamic-blocks", "*dxf", IsolatedDynamicBlocksPaths);
1926
}
2027

2128
public DynamicBlockTests(ITestOutputHelper output) : base(output)
2229
{
2330
}
2431

2532
[Theory]
26-
[MemberData(nameof(DwgDynamicBlocksPaths))]
33+
[MemberData(nameof(GenericDynamicBlocksPaths))]
2734
public void DynamicBlocksTest(FileModel test)
2835
{
2936
CadDocument doc;
@@ -70,5 +77,28 @@ public void DynamicBlocksTest(FileModel test)
7077
Assert.NotNull(modified.Block.Source);
7178
Assert.Equal(dynamicName, modified.Block.Source.Name);
7279
}
80+
81+
[Theory]
82+
[MemberData(nameof(IsolatedDynamicBlocksPaths))]
83+
public void IsolatedTest(FileModel test)
84+
{
85+
var config = getConfiguration(test);
86+
var doc = this.readDocument(test, config);
87+
88+
var original = doc.BlockRecords["block_visibility_parameter"];
89+
foreach (BlockRecord record in doc.BlockRecords.Where(b => b.IsAnonymous))
90+
{
91+
Assert.Equal(original, record.Source);
92+
}
93+
94+
foreach (Insert insert in doc.Entities.OfType<Insert>())
95+
{
96+
var dict = insert.XDictionary.GetEntry<CadDictionary>("AcDbBlockRepresentation");
97+
var representation = dict.GetEntry<BlockRepresentationData>("AcDbRepData");
98+
99+
Assert.NotNull(representation);
100+
Assert.Equal(original, representation.Block);
101+
}
102+
}
73103
}
74104
}

src/ACadSharp.Tests/IO/IOTestsBase.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public abstract class IOTestsBase
2828
{
2929
};
3030

31+
protected readonly ITestOutputHelper _output;
32+
3133
protected readonly SvgConfiguration _svgConfiguration = new SvgConfiguration
3234
{
3335
DefaultLineWeight = 0.15,
3436
LineWeightRatio = 50,
3537
};
3638

37-
protected readonly ITestOutputHelper _output;
38-
3939
static IOTestsBase()
4040
{
4141
loadSamples("", "dwg", DwgFilePaths);
@@ -98,6 +98,18 @@ protected static void loadSamples(string folder, string prefix, string ext, Theo
9898
}
9999
}
100100

101+
protected CadReaderConfiguration getConfiguration(FileModel test)
102+
{
103+
if (test.IsDxf)
104+
{
105+
return new DxfReaderConfiguration();
106+
}
107+
else
108+
{
109+
return new DwgReaderConfiguration();
110+
}
111+
}
112+
101113
protected bool isSupportedVersion(ACadVersion version)
102114
{
103115
switch (version)

src/ACadSharp/ACadSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PropertyGroup>
1818
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1919
<PackageReadmeFile>README.md</PackageReadmeFile>
20-
<Version>3.3.29</Version>
20+
<Version>3.3.30</Version>
2121
<PackageOutputPath>../nupkg</PackageOutputPath>
2222
<SignAssembly>True</SignAssembly>
2323
<AssemblyOriginatorKeyFile>../ACadSharp.snk</AssemblyOriginatorKeyFile>

src/ACadSharp/DxfFileToken.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,13 @@ public static class DxfFileToken
127127
public const string ObjectSortEntsTable = "SORTENTSTABLE";
128128
public const string ObjectXRecord = "XRECORD";
129129
public const string ObjectMLeaderContextData = "ACDB_MLEADEROBJECTCONTEXTDATA_CLASS";
130+
public const string ObjectBlockRepresentationData = "ACDB_BLOCKREPRESENTATION_DATA";
130131
public const string ObjectEvalGraph = "ACAD_EVALUATION_GRAPH";
131132
public const string ObjectBlockLinearParameter = "BLOCKLINEARPARAMETER";
132133
public const string ObjectBlockVisibilityParameter = "BLOCKVISIBILITYPARAMETER";
134+
public const string ObjectBlockVisibilityGrip = "BLOCKVISIBILITYGRIP";
133135
public const string ObjectBlockBasePointParameter = "BLOCKBASEPOINTPARAMETER";
136+
public const string ObjectBlockGripLocationComponent = "BLOCKGRIPLOCATIONCOMPONENT";
134137
public const string ObjectBlockFlipParameter = "BLOCKFLIPPARAMETER";
135138
public const string ObjectBlockFlipAction = "BLOCKFLIPACTION";
136139
public const string ObjectTableContent = "TABLECONTENT";

src/ACadSharp/DxfSubclassMarker.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ public static class DxfSubclassMarker
4242

4343
public const string BlockGrip = "AcDbBlockGrip";
4444

45-
public const string BlockGripExpression = "AcDbBlockGripExpression";
46-
47-
public const string BlockGripLocationComponent = "AcDbBlockGripLocationComponent";
45+
public const string BlockGripExpression = "AcDbBlockGripExpr";
4846

4947
public const string BlockLinearParameter = "AcDbBlockLinearParameter";
5048

5149
public const string BlockParameter = "AcDbBlockParameter";
5250

5351
public const string BlockRecord = "AcDbBlockTableRecord";
5452

53+
public const string BlockRepresentationData = "AcDbBlockRepresentationData";
54+
5555
public const string BlockVisibilityGrip = "AcDbBlockVisibilityGrip";
5656

5757
public const string BlockVisibilityParameter = "AcDbBlockVisibilityParameter";
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
using ACadSharp.IO.Templates;
2+
using ACadSharp.Objects;
3+
using ACadSharp.Objects.Evaluations;
4+
5+
namespace ACadSharp.IO.DWG
6+
{
7+
internal partial class DwgObjectReader : DwgSectionIO
8+
{
9+
private void readBlock1PtParameter(CadBlock1PtParameterTemplate template)
10+
{
11+
this.readBlockParameter(template);
12+
13+
//1010 1020 1030
14+
template.Block1PtParameter.Location = this._mergedReaders.Read3BitDouble();
15+
//170
16+
template.Block1PtParameter.Value170 = this._mergedReaders.ReadBitShort();
17+
//171
18+
template.Block1PtParameter.Value171 = this._mergedReaders.ReadBitShort();
19+
//93
20+
template.Block1PtParameter.Value93 = this._mergedReaders.ReadBitLong();
21+
}
22+
23+
private void readBlockElement(CadBlockElementTemplate template)
24+
{
25+
this.readEvaluationExpression(template);
26+
27+
//300 name
28+
template.BlockElement.ElementName = this._mergedReaders.ReadVariableText();
29+
//98
30+
template.BlockElement.Value98 = this._mergedReaders.ReadBitLong();
31+
//99
32+
template.BlockElement.Value99 = this._mergedReaders.ReadBitLong();
33+
//1071
34+
template.BlockElement.Value1071 = this._mergedReaders.ReadBitLong();
35+
}
36+
37+
private CadTemplate readBlockGripLocationComponent()
38+
{
39+
BlockGripExpression gripExpression = new BlockGripExpression();
40+
CadBlockGripExpressionTemplate template = new CadBlockGripExpressionTemplate(gripExpression);
41+
42+
this.readEvaluationExpression(template);
43+
44+
return template;
45+
}
46+
47+
private void readBlockParameter(CadBlockParameterTemplate template)
48+
{
49+
this.readBlockElement(template);
50+
51+
//280
52+
template.BlockParameter.Value280 = this._mergedReaders.ReadBit();
53+
//281
54+
template.BlockParameter.Value281 = this._mergedReaders.ReadBit();
55+
}
56+
57+
private CadTemplate readBlockRepresentationData()
58+
{
59+
BlockRepresentationData representation = new BlockRepresentationData();
60+
CadBlockRepresentationDataTemplate template = new CadBlockRepresentationDataTemplate(representation);
61+
62+
this.readCommonNonEntityData(template);
63+
64+
representation.Value70 = this._mergedReaders.ReadBitShort();
65+
template.BlockHandle = this.handleReference();
66+
67+
return template;
68+
}
69+
70+
private CadTemplate readBlockVisibilityParameter()
71+
{
72+
BlockVisibilityParameter blockVisibilityParameter = new BlockVisibilityParameter();
73+
CadBlockVisibilityParameterTemplate template = new CadBlockVisibilityParameterTemplate(blockVisibilityParameter);
74+
75+
this.readBlock1PtParameter(template);
76+
77+
//281
78+
blockVisibilityParameter.Value281 = this._mergedReaders.ReadBit();
79+
//301
80+
blockVisibilityParameter.Name = this._mergedReaders.ReadVariableText();
81+
//302
82+
blockVisibilityParameter.Description = this._mergedReaders.ReadVariableText();
83+
//missing bit?? 91 should be an int
84+
blockVisibilityParameter.Value91 = this._mergedReaders.ReadBit();
85+
86+
//DXF 93 Total entities count
87+
var totalEntitiesCount = this._objectReader.ReadBitLong();
88+
for (int i = 0; i < totalEntitiesCount; i++)
89+
{
90+
//331
91+
template.EntityHandles.Add(this.handleReference());
92+
}
93+
94+
//DXF 92 states count
95+
var nstates = this._objectReader.ReadBitLong();
96+
for (int j = 0; j < nstates; j++)
97+
{
98+
template.StateTemplates.Add(this.readState());
99+
}
100+
101+
return template;
102+
}
103+
104+
private void readEvaluationExpression(CadEvaluationExpressionTemplate template)
105+
{
106+
this.readCommonNonEntityData(template);
107+
108+
//AcDbEvalExpr
109+
var unknown = this._objectReader.ReadBitLong();
110+
111+
//98
112+
template.CadObject.Value98 = this._objectReader.ReadBitLong();
113+
//99
114+
template.CadObject.Value99 = this._objectReader.ReadBitLong();
115+
116+
//Code value
117+
short code = this._mergedReaders.ReadBitShort();
118+
if (code > 0)
119+
{
120+
var groupValue = GroupCodeValue.TransformValue(code);
121+
switch (groupValue)
122+
{
123+
case GroupCodeValueType.Double:
124+
case GroupCodeValueType.ExtendedDataDouble:
125+
this._mergedReaders.ReadBitDouble();
126+
break;
127+
default:
128+
throw new System.NotImplementedException($"[EvaluationExpression] Code not implemented {groupValue}");
129+
}
130+
}
131+
132+
//90
133+
template.CadObject.Id = this._objectReader.ReadBitLong();
134+
}
135+
136+
private CadBlockVisibilityParameterTemplate.StateTemplate readState()
137+
{
138+
CadBlockVisibilityParameterTemplate.StateTemplate template = new CadBlockVisibilityParameterTemplate.StateTemplate();
139+
140+
template.State.Name = this._textReader.ReadVariableText();
141+
142+
//DXF 94 subset count 1
143+
int n1 = this._objectReader.ReadBitLong();
144+
for (int i = 0; i < n1; i++)
145+
{
146+
//332
147+
template.EntityHandles.Add(this.handleReference());
148+
}
149+
150+
//DXF 95 subset count 2
151+
var n2 = this._objectReader.ReadBitLong();
152+
for (int i = 0; i < n2; i++)
153+
{
154+
//333
155+
template.ExpressionHandles.Add(this.handleReference());
156+
}
157+
158+
return template;
159+
}
160+
}
161+
}

0 commit comments

Comments
 (0)