Skip to content

Commit

Permalink
dwg following dxf structure
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Dec 17, 2024
1 parent 4996c53 commit 4752c81
Show file tree
Hide file tree
Showing 9 changed files with 3,837 additions and 1,094 deletions.
Binary file modified samples/dynamic-blocks/dynamic-block-circle.dwg
Binary file not shown.
4,628 changes: 3,639 additions & 989 deletions samples/dynamic-blocks/dynamic-block-circle.dxf

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/ACadSharp/DxfSubclassMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static class DxfSubclassMarker
public const string EvalGraphExpr = "AcDbEvalExpr";
public const string BlockElement = "AcDbBlockElement";
public const string BlockParameter = "AcDbBlockParameter";
public const string Block1PtParameter = "AcDbBlock1PtParameter";
public const string Block2PtParameter = "AcDbBlock2PtParameter";
public const string BlockLinearParameter = "AcDbBlockLinearParameter";

Expand Down
105 changes: 67 additions & 38 deletions src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Globalization;
using ACadSharp.Objects.Evaluations;
using ACadSharp.XData;
using System.Diagnostics;

namespace ACadSharp.IO.DWG
{
Expand Down Expand Up @@ -1121,52 +1122,80 @@ private CadTemplate readEvaluationGraph()
return template;
}

private void readEvaluationExpression(CadEvaluationExpressionTemplate template)
{
this.readCommonNonEntityData(template);

//AcDbEvalExpr
//90
template.CadObject.Value90 = _objectReader.ReadBitLong();
//98
template.CadObject.Value98 = _objectReader.ReadBitLong();
//99
template.CadObject.Value99 = _objectReader.ReadBitLong();

//-9999 always the same value
short n9999 = this._mergedReaders.ReadBitShort();
Debug.Assert(n9999 == -9999);
}

private void readBlockElement(CadBlockElementTemplate template)
{
this.readEvaluationExpression(template);

//300 name
template.BlockElement.ElementName = this._mergedReaders.ReadVariableText();
//98
template.BlockElement.Value98 = this._mergedReaders.ReadBitLong();
//99
template.BlockElement.Value99 = this._mergedReaders.ReadBitLong();
//1071
template.BlockElement.Value1071 = this._mergedReaders.ReadBitLong();
}

private void readBlockParameter(CadBlockParameterTemplate template)
{
this.readBlockElement(template);

//280
template.BlockParameter.Value280 = this._mergedReaders.ReadBit();
//281
template.BlockParameter.Value281 = this._mergedReaders.ReadBit();
}

private void readBlock1PtParameter(CadBlock1PtParameterTemplate template)
{
this.readBlockParameter(template);

//1010 1020 1030
template.Block1PtParameter.Location = this._mergedReaders.Read3BitDouble();

//170
template.Block1PtParameter.Value170 = this._mergedReaders.ReadBitShort();
//171
template.Block1PtParameter.Value171 = this._mergedReaders.ReadBitShort();
//93
template.Block1PtParameter.Value93 = this._mergedReaders.ReadBitLong();
}

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

this.readCommonNonEntityData(template);
this.readBlock1PtParameter(template);

var l1 = _objectReader.ReadBitLong();
var s2 = _objectReader.ReadBitShort(); // can also be L
var s3 = _objectReader.ReadBitShort(); // can also be L
var b4 = _objectReader.ReadBit();
var s5 = _objectReader.ReadBitShort(); // can also be L
var b6 = _objectReader.ReadBit();
var s7 = _objectReader.ReadBitShort(); // can also be L

var b_8 = _objectReader.ReadBit();
var b_9 = _objectReader.ReadBit();
var b_10 = _objectReader.ReadBit();
var b_11 = _objectReader.ReadBit();
var b_12 = _objectReader.ReadBit();
var b_13 = _objectReader.ReadBit();
var S_14 = _objectReader.ReadBitShort(); // can also be L

var s_15 = _objectReader.ReadBitShort();
var b_16 = _objectReader.ReadBit();
var b_17 = _objectReader.ReadBit();
var s_18 = _objectReader.ReadBitShort();

// 300 Parameter Type
blockVisibilityParameter.ParameterType = _textReader.ReadVariableText();

// 1010, 1020, 1030 Menu position
blockVisibilityParameter.BasePosition = _objectReader.Read3BitDouble();
// 2x0 <-
var s170 = _objectReader.ReadBitShort();
var s171 = _objectReader.ReadBitShort();
var l93 = _objectReader.ReadBitLong();

// 301
//281
blockVisibilityParameter.Name = _textReader.ReadVariableText();
// 302
//301
blockVisibilityParameter.Name = _textReader.ReadVariableText();
//302
blockVisibilityParameter.Description = _textReader.ReadVariableText();
// DXF 91
blockVisibilityParameter.L91 = _objectReader.ReadBitLong();
//DXF 91
blockVisibilityParameter.Value91 = _objectReader.ReadBitLong();

//DwgAnalyseTools.resetPosition(214293, 0);
// DXF 93 Total entities count (no property)
//DXF 93 Total entities count (no property)
var totalEntitiesCount = _objectReader.ReadBitLong();
for (int i = 0; i < totalEntitiesCount; i++)
{
Expand Down
43 changes: 0 additions & 43 deletions src/ACadSharp/IO/Templates/BlockVisibilityParameterTemplate.cs

This file was deleted.

92 changes: 92 additions & 0 deletions src/ACadSharp/IO/Templates/CadBlockVisibilityParameterTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.Collections.Generic;

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

namespace ACadSharp.IO.Templates
{

internal class CadEvaluationExpressionTemplate : CadTemplate<EvaluationExpression>
{
public CadEvaluationExpressionTemplate(EvaluationExpression cadObject)
: base(cadObject)
{
}
}

internal class CadBlockElementTemplate : CadEvaluationExpressionTemplate
{
public BlockElement BlockElement { get { return this.CadObject as BlockElement; } }

public CadBlockElementTemplate(BlockElement cadObject)
: base(cadObject)
{
}
}

internal class CadBlockParameterTemplate : CadBlockElementTemplate
{
public BlockParameter BlockParameter { get { return this.CadObject as BlockParameter; } }

public CadBlockParameterTemplate(BlockParameter cadObject)
: base(cadObject)
{
}
}

internal class CadBlock1PtParameterTemplate : CadBlockParameterTemplate
{
public Block1PtParameter Block1PtParameter { get { return this.CadObject as Block1PtParameter; } }

public CadBlock1PtParameterTemplate(Block1PtParameter cadObject)
: base(cadObject)
{
}
}

internal class CadBlockVisibilityParameterTemplate : CadBlock1PtParameterTemplate
{
public IDictionary<ulong, Entity> TotalEntityHandles { get; } = new Dictionary<ulong, Entity>();

public IDictionary<BlockVisibilityParameter.SubBlock, IList<ulong>> SubBlockHandles { get; } = new Dictionary<BlockVisibilityParameter.SubBlock, IList<ulong>>();

public CadBlockVisibilityParameterTemplate(BlockVisibilityParameter cadObject)
: base(cadObject)
{
}

public override void Build(CadDocumentBuilder builder)
{
base.Build(builder);

BlockVisibilityParameter bvp = this.CadObject as BlockVisibilityParameter;

foreach (var cadObjectHandle in this.TotalEntityHandles)
{
ulong handle = cadObjectHandle.Key;
if (builder.TryGetCadObject(handle, out Entity entity))
{
this.TotalEntityHandles[handle] = entity;
bvp.Entities.Add(entity);
}
}

foreach (var subGroup in bvp.SubBlocks)
{
if (this.SubBlockHandles.TryGetValue(subGroup, out IList<ulong> subBlockHandles))
{
foreach (ulong handle in subBlockHandles)
{
if (this.TotalEntityHandles.TryGetValue(handle, out Entity entity))
{
subGroup.Entities.Add(entity);
}
else if (builder.TryGetCadObject(handle, out Entity entityX))
{
}
}
}
}
}
}
}
19 changes: 10 additions & 9 deletions src/ACadSharp/Objects/Evaluations/BlockVisibilityParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@

namespace ACadSharp.Objects.Evaluations
{
//BLOCKVISIBILITYPARAMETER
//AcDbEvalExpr
//AcDbBlockElement
//AcDbBlock1PtParameter
//AcDbBlockVisibilityParameter

/// <summary>
/// Represents a BLOCKVISIBILITYPARAMETER object, in AutoCAD used to
/// control the visibility state of entities in a dynamic block.
/// </summary>
public class BlockVisibilityParameter : CadObject
public class BlockVisibilityParameter : Block1PtParameter
{

/// <inheritdoc/>
public override ObjectType ObjectType => ObjectType.UNLISTED;

/// <inheritdoc/>
public override string ObjectName => DxfFileToken.ObjectBlockVisibilityParameter;

/// <inheritdoc/>
public override string SubclassMarker => DxfSubclassMarker.BlockVisibilityParameter;


/// <summary>
/// Gets the list of all <see cref="Entity"/> objects of the dynamic block
/// this <see cref="BlockVisibilityParameter"/> is associated with.
Expand Down Expand Up @@ -54,19 +55,19 @@ public class BlockVisibilityParameter : CadObject
/// Gets a title for the dialog to select the subblock that is to be set visible.
/// </summary>
[DxfCodeValue(301)]
public string Name { get; internal set; }
public string Name { get; set; }

/// <summary>
/// Gets a description presumably for the dialog to select the subblock that is to be set visible.
/// </summary>
[DxfCodeValue(302)]
public string Description { get; internal set; }
public string Description { get; set; }

/// <summary>
/// Unknown
/// </summary>
[DxfCodeValue(91)]
public int L91 { get; internal set; }
internal int Value91 { get; set; }

/// <summary>
/// Represents a named subblock containing <see cref="Entity"/> objects.
Expand Down
Loading

0 comments on commit 4752c81

Please sign in to comment.