Skip to content

Commit

Permalink
BlockLinearParameter tree
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Nov 7, 2024
1 parent 1e7ec41 commit 908f9a0
Show file tree
Hide file tree
Showing 21 changed files with 15,194 additions and 148 deletions.
Binary file modified samples/dynamic-blocks/dynamic-block-circle.dwg
Binary file not shown.
14,858 changes: 14,858 additions & 0 deletions samples/dynamic-blocks/dynamic-block-circle.dxf

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions src/ACadSharp.Tests/IO/DynamicBlockTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using ACadSharp.IO;
using ACadSharp.Entities;
using ACadSharp.IO;
using ACadSharp.Objects.Evaluations;
using ACadSharp.Tables;
using ACadSharp.Tests.TestModels;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -24,7 +27,24 @@ public void DynamicBlocksTest(FileModel test)
{
//"my-dynamic-block" handle = 570

CadDocument doc = DwgReader.Read(test.Path, this.onNotification);
DwgReaderConfiguration configuration = new DwgReaderConfiguration();
configuration.KeepUnknownEntities = true;
configuration.KeepUnknownNonGraphicalObjects = true;

CadDocument doc = DwgReader.Read(test.Path, configuration, this.onNotification);

BlockRecord blk = doc.BlockRecords["my-dynamic-block"];

//Dictionary entry
EvaluationGraph eval = blk.XDictionary.GetEntry<EvaluationGraph>("ACAD_ENHANCEDBLOCK");

//Extended data related to the dynamic block
var a = blk.ExtendedData.Get(doc.AppIds["AcDbBlockRepETag"]);
var b = blk.ExtendedData.Get(doc.AppIds["AcDbDynamicBlockTrueName"]);
var c = blk.ExtendedData.Get(doc.AppIds["AcDbDynamicBlockGUID"]);

Insert basic = doc.GetCadObject<Insert>(788);
Insert modified = doc.GetCadObject<Insert>(889);
}
}
}
1 change: 1 addition & 0 deletions src/ACadSharp/CadObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ACadSharp.Objects.Collections;
using ACadSharp.Tables;
using ACadSharp.Tables.Collections;
using ACadSharp.XData;
using System.Collections.Generic;

namespace ACadSharp
Expand Down
1 change: 1 addition & 0 deletions src/ACadSharp/DxfFileToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public static class DxfFileToken
public const string ObjectXRecord = "XRECORD";
public const string ObjectMLeaderContextData = "CONTEXT_DATA";
public const string ObjectEvalGraph = "ACAD_EVALUATION_GRAPH";
public const string ObjectBlockLinearParameter = "BLOCKLINEARPARAMETER";
public const string ObjectBlockVisibilityParameter = "BLOCKVISIBILITYPARAMETER";

#endregion
Expand Down
8 changes: 8 additions & 0 deletions src/ACadSharp/DxfSubclassMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ public static class DxfSubclassMarker
public const string PlotSettings = "AcDbPlotSettings";
public const string DictionaryVariables = "DictionaryVariables";
public const string Scale = "AcDbScale";

//Dynamic block constants
public const string EvalGraph = "AcDbEvalGraph";
public const string EvalGraphExpr = "AcDbEvalExpr";
public const string BlockElement = "AcDbBlockElement";
public const string BlockParameter = "AcDbBlockParameter";
public const string Block2PtParameter = "AcDbBlock2PtParameter";
public const string BlockLinearParameter = "AcDbBlockLinearParameter";

public const string BlockVisibilityParameter = "AcDbBlockVisibilityParameter";
}
}
79 changes: 0 additions & 79 deletions src/ACadSharp/ExtendedDataCollection.cs

This file was deleted.

41 changes: 29 additions & 12 deletions src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
using System.Net;
using CSUtilities.Converters;
using CSUtilities.Extensions;
using ACadSharp.Objects.Evaluations;
using ACadSharp.XData;

namespace ACadSharp.IO.DWG
{
Expand Down Expand Up @@ -1070,34 +1072,45 @@ private CadTemplate readUnlistedType(short classNumber)

#region Evaluation Graph, Enhanced Block etc.

private CadTemplate readEvaluationGraph() {
private CadTemplate readEvaluationGraph()
{
EvaluationGraph evaluationGraph = new EvaluationGraph();
EvaluationGraphTemplate template = new EvaluationGraphTemplate(evaluationGraph);

this.readCommonNonEntityData(template);

// DXF fields 96, 97 contain the value 5, here are three fields returning the same value 5
var val1 = _objectReader.ReadBitLong();
var val2 = _objectReader.ReadBitLong();
var val3 = _objectReader.ReadBitLong();
int nodeCount = val3;
evaluationGraph.Value96 = _objectReader.ReadBitLong();
evaluationGraph.Value97 = _objectReader.ReadBitLong();

for (int i = 0; i < nodeCount; i++) {
int nodeCount = _objectReader.ReadBitLong();
for (int i = 0; i < nodeCount; i++)
{
var node = new EvaluationGraph.GraphNode();
evaluationGraph.Nodes.Add(node);

//Code 91
node.Index = _objectReader.ReadBitLong();
//Code 93
node.Flags = _objectReader.ReadBitLong();
//Code 95
node.NextNodeIndex = _objectReader.ReadBitLong();

//Code 360
template.NodeHandles.Add(node, this.handleReference());

//Codes 92
node.Data1 = _objectReader.ReadBitLong();
node.Data2 = _objectReader.ReadBitLong();
node.Data3 = _objectReader.ReadBitLong();
node.Data4 = _objectReader.ReadBitLong();
}

foreach (EvaluationGraph.GraphNode node in evaluationGraph.Nodes) {
foreach (EvaluationGraph.GraphNode node in evaluationGraph.Nodes)
{
int nextNodeIndex = node.NextNodeIndex;
if (nextNodeIndex >= 0 && nextNodeIndex < nodeCount) {
if (nextNodeIndex >= 0 && nextNodeIndex < nodeCount)
{
node.Next = evaluationGraph.Nodes[nextNodeIndex];
}
}
Expand All @@ -1108,7 +1121,8 @@ private CadTemplate readEvaluationGraph() {
}


private CadTemplate readBlockVisibilityParameter() {
private CadTemplate readBlockVisibilityParameter()
{
BlockVisibilityParameter blockVisibilityParameter = new BlockVisibilityParameter();
BlockVisibilityParameterTemplate template = new BlockVisibilityParameterTemplate(blockVisibilityParameter);

Expand Down Expand Up @@ -1160,14 +1174,16 @@ private CadTemplate readBlockVisibilityParameter() {
//DwgAnalyseTools.resetPosition(214293, 0);
// DXF 93 Total entities count (no property)
var totalEntitiesCount = _objectReader.ReadBitLong();
for (int i = 0; i < totalEntitiesCount; i++) {
for (int i = 0; i < totalEntitiesCount; i++)
{
var handle = this.handleReference();
template.TotalEntityHandles.Add(handle, null);
}

// DXF 92 Sub blocks count (no property)
var subBlocksCount = _objectReader.ReadBitLong();
for (int sbi = 0; sbi < subBlocksCount; sbi++) {
for (int sbi = 0; sbi < subBlocksCount; sbi++)
{
BlockVisibilityParameter.SubBlock subBlock = new BlockVisibilityParameter.SubBlock();
subBlock.Name = _textReader.ReadVariableText();
blockVisibilityParameter.SubBlocks.Add(subBlock);
Expand All @@ -1176,7 +1192,8 @@ private CadTemplate readBlockVisibilityParameter() {
template.SubBlockHandles.Add(subBlock, subBlockHandles);
// DXF 94 Subblock entities count (no property)
int entitiesCount = _objectReader.ReadBitLong();
for (int i = 0; i < entitiesCount; i++) {
for (int i = 0; i < entitiesCount; i++)
{
var handle = this.handleReference();
subBlockHandles.Add(handle);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ACadSharp.Classes;
using ACadSharp.Entities;
using ACadSharp.Tables;
using ACadSharp.XData;
using CSUtilities.Converters;
using System.IO;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ACadSharp.Entities;
using ACadSharp.IO.Templates;
using ACadSharp.XData;
using CSMath;
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ACadSharp.Tables;
using ACadSharp.Tables.Collections;
using ACadSharp.Types.Units;
using ACadSharp.XData;
using CSMath;
using CSUtilities.Extensions;
using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Collections.Generic;

using ACadSharp.Entities;
using ACadSharp.Objects;
using ACadSharp.Objects.Evaluations;

namespace ACadSharp.IO.Templates {
namespace ACadSharp.IO.Templates
{

internal class BlockVisibilityParameterTemplate : CadTemplate<BlockVisibilityParameter> {

Expand Down
1 change: 1 addition & 0 deletions src/ACadSharp/IO/Templates/CadTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ACadSharp.Entities;
using ACadSharp.Objects;
using ACadSharp.Tables;
using ACadSharp.XData;
using System.Collections.Generic;

namespace ACadSharp.IO.Templates
Expand Down
3 changes: 1 addition & 2 deletions src/ACadSharp/IO/Templates/EvaluationGraphTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;

using ACadSharp.Objects;
using ACadSharp.Objects.Evaluations;

namespace ACadSharp.IO.Templates
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;

using ACadSharp.Attributes;
using ACadSharp.Entities;

using CSMath;


namespace ACadSharp.Objects
namespace ACadSharp.Objects.Evaluations
{

/// <summary>
/// Represents a BLOCKVISIBILITYPARAMETER object, in AutoCAD used to
/// control the visibility state of entities in a dynamic block.
Expand Down Expand Up @@ -47,7 +43,7 @@ public class BlockVisibilityParameter : CadObject
/// </summary>
[DxfCodeValue(1010, 1020, 1030)]
public XYZ BasePosition { get; internal set; }

/// <summary>
/// Gets a text presumably describing the purpose of this <see cref="BlockVisibilityParameter"/>.
/// </summary>
Expand Down Expand Up @@ -107,7 +103,6 @@ public object Clone()
}
}


/// <inheritdoc/>
public override CadObject Clone()
{
Expand Down
Loading

0 comments on commit 908f9a0

Please sign in to comment.