Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added samples/dynamic-blocks/BLOCKROTATIONPARAMETER.dwg
Binary file not shown.
15,172 changes: 15,172 additions & 0 deletions samples/dynamic-blocks/BLOCKROTATIONPARAMETER.dxf

Large diffs are not rendered by default.

32 changes: 31 additions & 1 deletion src/ACadSharp.Tests/IO/DynamicBlockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ public void IsolatedTest(FileModel test)
var config = getConfiguration(test);
var doc = this.readDocument(test, config);

switch (test.NoExtensionName)
{
case DxfFileToken.ObjectBlockVisibilityParameter:
this.assertVisibilityParameter(doc);
break;
case DxfFileToken.ObjectBlockRotationParameter:
this.assertRotationParameter(doc);
break;
default:
throw new System.NotImplementedException();
}
}

private void assertRotationParameter(CadDocument doc)
{
}

private void assertVisibilityParameter(CadDocument doc)
{
var original = doc.BlockRecords["block_visibility_parameter"];
foreach (BlockRecord record in doc.BlockRecords.Where(b => b.IsAnonymous))
{
Expand All @@ -96,9 +115,20 @@ public void IsolatedTest(FileModel test)
var dict = insert.XDictionary.GetEntry<CadDictionary>("AcDbBlockRepresentation");
var representation = dict.GetEntry<BlockRepresentationData>("AcDbRepData");

Assert.NotEmpty(insert.Block.Source.EvaluationGraph.Nodes.Select(n => n.Expression).OfType<BlockVisibilityParameter>());

Assert.NotNull(representation);
Assert.Equal(original, representation.Block);

XRecord record = insert.XDictionary
.GetEntry<CadDictionary>("AcDbBlockRepresentation")
.GetEntry<CadDictionary>("AppDataCache")
.GetEntry<CadDictionary>("ACAD_ENHANCEDBLOCKDATA")
.OfType<XRecord>().First();

var name = record.Entries.FirstOrDefault(e => e.Code == 1).Value as string;
Assert.False(string.IsNullOrEmpty(name));
}
}
}
}
}
3 changes: 2 additions & 1 deletion src/ACadSharp/DxfFileToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public static class DxfFileToken
public const string ObjectBlockVisibilityParameter = "BLOCKVISIBILITYPARAMETER";
public const string ObjectBlockVisibilityGrip = "BLOCKVISIBILITYGRIP";
public const string ObjectBlockBasePointParameter = "BLOCKBASEPOINTPARAMETER";
public const string ObjectBlockRotationParameter = "BLOCKROTATIONPARAMETER";
public const string ObjectBlockGripLocationComponent = "BLOCKGRIPLOCATIONCOMPONENT";
public const string ObjectBlockFlipParameter = "BLOCKFLIPPARAMETER";
public const string ObjectBlockFlipAction = "BLOCKFLIPACTION";
Expand All @@ -142,7 +143,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";
Expand Down
2 changes: 2 additions & 0 deletions src/ACadSharp/DxfSubclassMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public static class DxfSubclassMarker

public const string BlockRepresentationData = "AcDbBlockRepresentationData";

public const string BlockRotationParameter = "AcDbBlockRotationParameter";

public const string BlockVisibilityGrip = "AcDbBlockVisibilityGrip";

public const string BlockVisibilityParameter = "AcDbBlockVisibilityParameter";
Expand Down
36 changes: 36 additions & 0 deletions src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public override void Read()

private CadTemplate readObject()
{
this.currentSubclass = string.Empty;
switch (this._reader.ValueAsString)
{
case DxfFileToken.ObjectPlaceholder:
Expand Down Expand Up @@ -118,6 +119,8 @@ private CadTemplate readObject()
return this.readObjectCodes<BlockVisibilityGrip>(new CadBlockVisibilityGripTemplate(), this.readBlockVisibilityGrip);
case DxfFileToken.ObjectBlockVisibilityParameter:
return this.readObjectCodes<BlockVisibilityParameter>(new CadBlockVisibilityParameterTemplate(), this.readBlockVisibilityParameter);
case DxfFileToken.ObjectBlockRotationParameter:
return this.readObjectCodes<BlockRotationParameter>(new CadBlockRotationParameterTemplate(), this.readBlockRotationParameter);
default:
DxfMap map = DxfMap.Create<CadObject>();
CadUnknownNonGraphicalObjectTemplate unknownEntityTemplate = null;
Expand Down Expand Up @@ -1898,6 +1901,24 @@ private bool readBlock1PtParameter(CadTemplate template, DxfMap map)
}
}

private bool readBlock2PtParameter(CadTemplate template, DxfMap map)
{
var tmp = template as CadBlock2PtParameterTemplate;

switch (this._reader.Code)
{
//Stores always 4 entries using this code
case 91:
return true;
default:
if (!this.tryAssignCurrentValue(template.CadObject, map))
{
return this.readBlockParameter(template, map);
}
return true;
}
}

private bool readBlockVisibilityParameter(CadTemplate template, DxfMap map)
{
CadBlockVisibilityParameterTemplate tmp = template as CadBlockVisibilityParameterTemplate;
Expand Down Expand Up @@ -1929,6 +1950,21 @@ private bool readBlockVisibilityParameter(CadTemplate template, DxfMap map)
}
}

private bool readBlockRotationParameter(CadTemplate template, DxfMap map)
{
var tmp = template as CadBlockRotationParameterTemplate;

switch (this._reader.Code)
{
default:
if (!this.tryAssignCurrentValue(template.CadObject, map))
{
return this.readBlock2PtParameter(template, map);
}
return true;
}
}

private CadBlockVisibilityParameterTemplate.StateTemplate readState()
{
var state = new BlockVisibilityParameter.State();
Expand Down
17 changes: 17 additions & 0 deletions src/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,23 @@ private HashSet<ulong> readReactors()
return reactors;
}

protected bool tryAssignCurrentValue(object cadObject, DxfMap map)
{
if (string.IsNullOrEmpty(this.currentSubclass))
{
return false;
}

if (map.SubClasses.TryGetValue(this.currentSubclass, out var subClass))
{
return this.tryAssignCurrentValue(cadObject, subClass);
}
else
{
return false;
}
}

protected bool tryAssignCurrentValue(object cadObject, DxfClassMap map)
{
try
Expand Down
16 changes: 16 additions & 0 deletions src/ACadSharp/IO/Templates/CadBlockRotationParameterTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ACadSharp.Objects.Evaluations;

namespace ACadSharp.IO.Templates
{
internal partial class CadBlockRotationParameterTemplate : CadBlock2PtParameterTemplate
{
public CadBlockRotationParameterTemplate() : base(new BlockRotationParameter())
{
}

public CadBlockRotationParameterTemplate(BlockRotationParameter cadObject)
: base(cadObject)
{
}
}
}
47 changes: 32 additions & 15 deletions src/ACadSharp/Objects/Evaluations/Block2PtParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,43 @@ namespace ACadSharp.Objects.Evaluations
[DxfSubClass(DxfSubclassMarker.Block2PtParameter)]
public abstract class Block2PtParameter : BlockParameter
{
/// <inheritdoc/>
public override string SubclassMarker => DxfSubclassMarker.Block2PtParameter;

[DxfCodeValue(1010, 1020, 1030)]
public XYZ FirstPoint { get; set; }

[DxfCodeValue(1011, 1021, 1031)]
public XYZ SecondPoint { get; set; }

// Appears on DXF
//170 BS 4
//91 BL 31
//91 BL 0
//91 BL 0
//91 BL 0

//171 BS 0
//172 BS 0
//173 BS 0
//174 BS 0
//177 BS 0
/// <inheritdoc/>
public override string SubclassMarker => DxfSubclassMarker.Block2PtParameter;

[DxfCodeValue(170)]
public short Value170 { get; set; }

[DxfCodeValue(171)]
public short Value171 { get; set; }

[DxfCodeValue(172)]
public short Value172 { get; set; }

[DxfCodeValue(173)]
public short Value173 { get; set; }

[DxfCodeValue(174)]
public short Value174 { get; set; }

[DxfCodeValue(177)]
public short Value177 { get; set; }

[DxfCodeValue(303)]
public string Value303 { get; set; }

[DxfCodeValue(304)]
public string Value304 { get; set; }

[DxfCodeValue(94)]
public int Value94 { get; set; }

[DxfCodeValue(95)]
public int Value95 { get; set; }
}
}
35 changes: 35 additions & 0 deletions src/ACadSharp/Objects/Evaluations/BlockRotationParameter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using ACadSharp.Attributes;
using CSMath;

namespace ACadSharp.Objects.Evaluations
{
/// <summary>
/// Represents a BLOCKROTATIONPARAMETER object.
/// </summary>
/// <remarks>
/// Object name <see cref="DxfFileToken.ObjectBlockRotationParameter"/> <br/>
/// Dxf class name <see cref="DxfSubclassMarker.BlockRotationParameter"/>
/// </remarks>
[DxfName(DxfFileToken.ObjectBlockRotationParameter)]
[DxfSubClass(DxfSubclassMarker.BlockRotationParameter)]
public class BlockRotationParameter : Block2PtParameter
{
[DxfCodeValue(306)]
public string Description { get; set; }

[DxfCodeValue(305)]
public string Name { get; set; }

[DxfCodeValue(140)]
public double NameOffset { get; set; }

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

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

[DxfCodeValue(1011, 1021, 1031)]
public XYZ Point { get; set; }
}
}