Skip to content

Commit

Permalink
Merge pull request #370 from DomCR/issue-369_pdfdefinition
Browse files Browse the repository at this point in the history
Issue 369 pdfdefinition
  • Loading branch information
DomCR authored Aug 14, 2024
2 parents 44749f7 + 9275c24 commit 62f2865
Show file tree
Hide file tree
Showing 21 changed files with 402 additions and 52 deletions.
38 changes: 38 additions & 0 deletions ACadSharp.Tests/CadObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Xunit;
using ACadSharp.Tests.Common;
using ACadSharp.Tables.Collections;
using ACadSharp.Entities;

namespace ACadSharp.Tests
{
Expand All @@ -13,10 +14,47 @@ static CadObjectTests()
{
foreach (Type item in DataFactory.GetTypes<CadObject>())
{
if (item == typeof(UnknownEntity))
{
continue;
}

if (item.IsAbstract)
{
continue;
}

ACadTypes.Add(item);
}
}

[Theory]
[MemberData(nameof(ACadTypes))]
public void DefaultConstructor(Type t)
{
CadObject cadObject = Factory.CreateObject(t, false);

Assert.NotNull(cadObject);
Assert.True(0 == cadObject.Handle);

Assert.NotEqual(ObjectType.UNDEFINED, cadObject.ObjectType);

Assert.False(string.IsNullOrEmpty(cadObject.ObjectName));
Assert.False(string.IsNullOrEmpty(cadObject.SubclassMarker));

Assert.Null(cadObject.XDictionary);
}

[Fact]
public void CreateExtendedDictionaryTest()
{
CadObject obj = new Line();
obj.CreateExtendedDictionary();

Assert.NotNull(obj.XDictionary);
Assert.Empty(obj.XDictionary);
}

[Theory(Skip = "Factory refactor needed")]
[MemberData(nameof(ACadTypes))]
public void Clone(Type t)
Expand Down
24 changes: 11 additions & 13 deletions ACadSharp.Tests/Common/Factory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using ACadSharp.Entities;
using ACadSharp.Objects;
using ACadSharp.Tables;
using ACadSharp.Tables.Collections;
using CSUtilities.Extensions;
using System;
using System.Linq;

Expand Down Expand Up @@ -58,34 +60,30 @@ private static CadObject createObject(Type type, Type original, bool randomize)
return null;
}

if (type == typeof(XRecord)
|| type == typeof(PlotSettings)
|| type == typeof(Material)
|| type == typeof(MLineStyle)
|| type == typeof(Layout)
|| type == typeof(Group)
|| type == typeof(CadDictionary)
|| type == typeof(DictionaryVariable)
|| type == typeof(VisualStyle))
if (type.IsSubclassOf(typeof(NonGraphicalObject)))
{
object o = Activator.CreateInstance(type);
object o = Activator.CreateInstance(type, true);
if (!randomize)
return (CadObject)o;

return (CadObject)Factory.map(o);
}

if (type.BaseType == typeof(Entity))
if (type.IsSubclassOf(typeof(Entity)))
{
return EntityFactory.Create(original, randomize);
}
else if (type.BaseType == typeof(TableEntry))
else if (type.IsSubclassOf(typeof(TableEntry)))
{
return TableEntryFactory.Create(original, randomize: randomize);
}

if (type.HasInterface<ITable>())
{
return (CadObject)Activator.CreateInstance(type, true);
}

return createObject(type.BaseType, original, randomize);
}

}
}
5 changes: 0 additions & 5 deletions ACadSharp.Tests/IO/LocalSampleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public void ReadUserDxf(string test)
return;

CadDocument doc = DxfReader.Read(test, this.onNotification);

using (DxfReader reader = new DxfReader(test))
{
var e = reader.ReadEntities();
}
}

[Theory]
Expand Down
1 change: 0 additions & 1 deletion ACadSharp.Tests/Internal/DxfMapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public void CreateMapTest(Type t)
}

DxfMap map = DxfMap.Create(t);

}

[Fact]
Expand Down
3 changes: 3 additions & 0 deletions ACadSharp/DxfFileToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static class DxfFileToken
public const string EntityMText = "MTEXT";
public const string EntityOleFrame = "OLEFRAME";
public const string EntityOle2Frame = "OLE2FRAME";
public const string EntityPdfUnderlay = "PDFUNDERLAY";
public const string EntityPoint = "POINT";
public const string EntityPolyline = "POLYLINE";
public const string EntityPolyFaceMesh = "PFACE";
Expand Down Expand Up @@ -116,7 +117,9 @@ public static class DxfFileToken
public const string ObjectMLeaderStyle = "MLEADERSTYLE";
public const string ObjectImageDefinition = "IMAGEDEF";
public const string ObjectImageDefinitionReactor = "IMAGEDEF_REACTOR";
public const string ObjectMaterial = "MATERIAL";
public const string ObjectMLineStyle = "MLINESTYLE";
public const string ObjectPdfDefinition = "PDFDEFINITION";
public const string ObjectVisualStyle = "VISUALSTYLE";
public const string ObjectScale = "SCALE";
public const string ObjectSortEntsTable = "SORTENTSTABLE";
Expand Down
1 change: 1 addition & 0 deletions ACadSharp/DxfSubclassMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static class DxfSubclassMarker
public const string Vertex = "AcDbVertex";
public const string Polyline = "AcDb2dPolyline";
public const string Leader = "AcDbLeader";
public const string Material = "AcDbMaterial";
public const string MultiLeader = "AcDbMLeader";
public const string MLeaderStyle = "AcDbMLeaderStyle";
public const string MultiLeaderAnnotContext = "AcDbMultiLeaderAnnotContext";
Expand Down
22 changes: 22 additions & 0 deletions ACadSharp/Entities/PdfUnderlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using ACadSharp.Attributes;

namespace ACadSharp.Entities
{
/// <summary>
/// Represents a <see cref="PdfUnderlay"/> entity.
/// </summary>
/// <remarks>
/// Object name <see cref="DxfFileToken.EntityPdfUnderlay"/> <br/>
/// Dxf class name <see cref="DxfSubclassMarker.Underlay"/>
/// </remarks>
[DxfName(DxfFileToken.EntityPdfUnderlay)]
[DxfSubClass(DxfSubclassMarker.Underlay)]
public class PdfUnderlay : UnderlayEntity
{
/// <inheritdoc/>
public override ObjectType ObjectType => ObjectType.UNLISTED;

/// <inheritdoc/>
public override string ObjectName => DxfFileToken.EntityPdfUnderlay;
}
}
36 changes: 36 additions & 0 deletions ACadSharp/Entities/UnderlayDisplayFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;

namespace ACadSharp.Entities
{
/// <summary>
/// Underlay display options.
/// </summary>
[Flags]
public enum UnderlayDisplayFlags : byte
{
/// <summary>
/// Clipping is on.
/// </summary>
ClippingOn = 1,

/// <summary>
/// Underlay is on.
/// </summary>
ShowUnderlay = 2,

/// <summary>
/// Show as monochrome.
/// </summary>
Monochrome = 4,

/// <summary>
/// Adjust for background.
/// </summary>
AdjustForBackground = 8,

/// <summary>
/// Clip is inside mode.
/// </summary>
ClipInsideMode = 16
}
}
117 changes: 117 additions & 0 deletions ACadSharp/Entities/UnderlayEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using ACadSharp.Attributes;
using ACadSharp.Objects;
using CSMath;
using System;

namespace ACadSharp.Entities
{
/// <summary>
/// Common base class for all underlay entities, like <see cref="PdfUnderlay" />.
/// </summary>
[DxfSubClass(null, true)]
public abstract class UnderlayEntity : Entity
{
/// <inheritdoc/>
public override string SubclassMarker => DxfSubclassMarker.Underlay;

/// <summary>
/// Specifies the three-dimensional normal unit vector for the object.
/// </summary>
[DxfCodeValue(210, 220, 230)]
public XYZ Normal { get; set; } = XYZ.AxisZ;

/// <summary>
/// Insertion point(in WCS)
/// </summary>
[DxfCodeValue(10, 20, 30)]
public XYZ InsertPoint { get; set; }

/// <summary>
/// X scale factor
/// </summary>
[DxfCodeValue(41)]
public double XScale { get; set; } = 1;

/// <summary>
/// Y scale factor
/// </summary>
[DxfCodeValue(42)]
public double YScale { get; set; } = 1;

/// <summary>
/// Z scale factor
/// </summary>
[DxfCodeValue(43)]
public double ZScale { get; set; } = 1;

/// <summary>
/// Specifies the rotation angle for the object.
/// </summary>
/// <value>
/// The rotation angle in radians.
/// </value>
[DxfCodeValue(DxfReferenceType.IsAngle, 50)]
public double Rotation { get; set; } = 0.0;

/// <summary>
/// Underlay display options.
/// </summary>
[DxfCodeValue(280)]
public UnderlayDisplayFlags Flags { get; set; }

/// <summary>
/// Contrast
/// </summary>
/// <remarks>
/// 0-100; default = 50
/// </remarks>
[DxfCodeValue(281)]
public byte Contrast
{
get { return this._contrast; }
set
{
if (value < 0 || value > 100)
{
throw new ArgumentException($"Invalid Brightness value: {value}, must be in range 0-100");
}

this._contrast = value;
}
}

/// <summary>
/// Fade
/// </summary>
/// <value>
/// Range: 0 - 100 <br/>
/// Default: 0
/// </value>
[DxfCodeValue(282)]
public byte Fade
{
get { return this._fade; }
set
{
if (value < 0 || value > 100)
{
throw new ArgumentException($"Invalid Brightness value: {value}, must be in range 0-100");
}

this._fade = value;
}
}

[DxfCodeValue(DxfReferenceType.Handle, 340)]
public UnderlayDefinition Definition { get; set; }

private byte _contrast = 50;
private byte _fade = 0;

/// <inheritdoc/>
public override BoundingBox GetBoundingBox()
{
return BoundingBox.Null;
}
}
}
Loading

0 comments on commit 62f2865

Please sign in to comment.