Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 538 image reactor #544

Merged
merged 2 commits into from
Jan 27, 2025
Merged
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
3 changes: 2 additions & 1 deletion src/ACadSharp.Tests/Common/DocumentIntegrity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public void AssertBlockRecords(CadDocument doc)
Assert.NotNull(br.BlockEntity.Document);
this.documentObjectNotNull(doc, br.BlockEntity);

Assert.True(br.Handle == br.BlockEntity.Owner.Handle, "Block entity owner doesn't mach");
Assert.True(br.Handle == br.BlockEntity.Owner.Handle, "Block entity owner doesn't match");
Assert.NotNull(br.BlockEntity.Document);

Assert.NotNull(br.BlockEnd.Document);
this.documentObjectNotNull(doc, br.BlockEnd);
Expand Down
2 changes: 1 addition & 1 deletion src/ACadSharp.Tests/IO/CadReaderTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public virtual void AssertDocumentDefaults(FileModel test)
this._docIntegrity.AssertDocumentDefaults(doc);
}

public virtual void AssertTableHirearchy(FileModel test)
public virtual void AssertTableHierarchy(FileModel test)
{
CadDocument doc = this.getDocument(test);

Expand Down
4 changes: 2 additions & 2 deletions src/ACadSharp.Tests/IO/DWG/DwgReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public override void AssertDocumentDefaults(FileModel test)

[Theory]
[MemberData(nameof(DwgFilePaths))]
public override void AssertTableHirearchy(FileModel test)
public override void AssertTableHierarchy(FileModel test)
{
base.AssertTableHirearchy(test);
base.AssertTableHierarchy(test);
}

[Theory]
Expand Down
4 changes: 2 additions & 2 deletions src/ACadSharp.Tests/IO/DXF/DxfReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public override void AssertDocumentDefaults(FileModel test)
[Theory]
[MemberData(nameof(DxfAsciiFiles))]
[MemberData(nameof(DxfBinaryFiles))]
public override void AssertTableHirearchy(FileModel test)
public override void AssertTableHierarchy(FileModel test)
{
base.AssertTableHirearchy(test);
base.AssertTableHierarchy(test);
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
using System;
using ACadSharp.Objects;
using System.Linq;
using CSUtilities.Extensions;

namespace ACadSharp.Entities
{
/// <summary>
/// Common base class for <see cref="RasterImage" /> and <see cref="Wipeout" />.
/// </summary>
[DxfSubClass(null, true)]
public abstract class CadImageBase : Entity
public abstract class CadWipeoutBase : Entity
{
/// <summary>
/// Class version
Expand All @@ -38,20 +39,39 @@ public abstract class CadImageBase : Entity
public XYZ VVector { get; set; } = XYZ.AxisY;

/// <summary>
/// Image size in pixels
/// Image size in pixels.
/// </summary>
/// <remarks>
/// 2D point(U and V values)
/// 2D point(U and V values).
/// </remarks>
[DxfCodeValue(13, 23)]
public XY Size { get; set; }

/// <summary>
/// Image display properties
/// Image display properties.
/// </summary>
[DxfCodeValue(70)]
public ImageDisplayFlags Flags { get; set; }

/// <summary>
/// Add the ShowImage flag to the display flags property.
/// </summary>
public bool ShowImage
{
get { return this.Flags.HasFlag(ImageDisplayFlags.ShowImage); }
set
{
if (value)
{
this.Flags = this.Flags.AddFlag(ImageDisplayFlags.ShowImage);
}
else
{
this.Flags = this.Flags.RemoveFlag(ImageDisplayFlags.ShowImage);
}
}
}

/// <summary>
/// Clipping state
/// </summary>
Expand Down Expand Up @@ -169,7 +189,7 @@ public ImageDefinition Definition
}

/// <summary>
/// Reference to image definition reactor
/// Reference to image definition reactor.
/// </summary>
//It seems that is not necessecary, keep it hidden for now
[DxfCodeValue(DxfReferenceType.Handle, 360)]
Expand All @@ -179,6 +199,7 @@ internal ImageDefinitionReactor DefinitionReactor
set
{
this._definitionReactor = value;
this._definitionReactor.Owner = this;
}
}

Expand Down Expand Up @@ -213,7 +234,7 @@ public override BoundingBox GetBoundingBox()
/// <inheritdoc/>
public override CadObject Clone()
{
CadImageBase clone = (CadImageBase)base.Clone();
CadWipeoutBase clone = (CadWipeoutBase)base.Clone();

clone.Definition = (ImageDefinition)this.Definition?.Clone();

Expand Down
2 changes: 1 addition & 1 deletion src/ACadSharp/Entities/RasterImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ACadSharp.Entities
/// </remarks>
[DxfName(DxfFileToken.EntityImage)]
[DxfSubClass(DxfSubclassMarker.RasterImage)]
public class RasterImage : CadImageBase
public class RasterImage : CadWipeoutBase
{
/// <inheritdoc/>
public override ObjectType ObjectType => ObjectType.UNLISTED;
Expand Down
2 changes: 1 addition & 1 deletion src/ACadSharp/Entities/Wipeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ACadSharp.Entities
/// </remarks>
[DxfName(DxfFileToken.EntityWipeout)]
[DxfSubClass(DxfSubclassMarker.Wipeout)]
public class Wipeout : CadImageBase
public class Wipeout : CadWipeoutBase
{
/// <inheritdoc/>
public override ObjectType ObjectType => ObjectType.UNLISTED;
Expand Down
2 changes: 1 addition & 1 deletion src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5418,7 +5418,7 @@ private CadTemplate readVisualStyle()
return null;
}

private CadTemplate readCadImage(CadImageBase image)
private CadTemplate readCadImage(CadWipeoutBase image)
{
CadImageTemplate template = new CadImageTemplate(image);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private void writeEntity(Entity entity)
case Spline spline:
this.writeSpline(spline);
break;
case CadImageBase image:
case CadWipeoutBase image:
this.writeCadImage(image);
break;
case TextEntity text:
Expand Down Expand Up @@ -1752,7 +1752,7 @@ private void writeSolid3D(Solid3D solid)
{
}

private void writeCadImage(CadImageBase image)
private void writeCadImage(CadWipeoutBase image)
{
this._writer.WriteBitLong(image.ClassVersion);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ private void writeViewport(Viewport vp)
}

private void writeCadImage<T>(T image)
where T : CadImageBase
where T : CadWipeoutBase
{
DxfClassMap map = DxfClassMap.Create<T>();

Expand Down
4 changes: 2 additions & 2 deletions src/ACadSharp/IO/Templates/CadImageTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ internal class CadImageTemplate : CadEntityTemplate

public ulong? ImgReactorHandle { get; set; }

public CadImageTemplate(CadImageBase image) : base(image) { }
public CadImageTemplate(CadWipeoutBase image) : base(image) { }

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

CadImageBase image = this.CadObject as CadImageBase;
CadWipeoutBase image = this.CadObject as CadWipeoutBase;

if (builder.TryGetCadObject(this.ImgDefHandle, out ImageDefinition imgDef))
{
Expand Down
4 changes: 2 additions & 2 deletions src/ACadSharp/Objects/ImageDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ImageDefinition : NonGraphicalObject
/// Class version
/// </summary>
[DxfCodeValue(90)]
public int ClassVersion { get; set; }
public int ClassVersion { get; internal set; }

/// <summary>
/// File name of image
Expand All @@ -51,7 +51,7 @@ public class ImageDefinition : NonGraphicalObject
/// Image-is-loaded flag.
/// </summary>
[DxfCodeValue(280)]
public bool IsLoaded { get; set; } = false;
public bool IsLoaded { get; set; } = true;

/// <summary>
/// Resolution units.
Expand Down
9 changes: 9 additions & 0 deletions src/ACadSharp/Objects/ImageDefinitionReactor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ACadSharp.Attributes;
using System;

namespace ACadSharp.Objects
{
Expand All @@ -11,6 +12,7 @@ namespace ACadSharp.Objects
/// </remarks>
[DxfName(DxfFileToken.ObjectImageDefinitionReactor)]
[DxfSubClass(DxfSubclassMarker.RasterImageDefReactor)]
[Obsolete("This object doesn't seem to be needed for any kind of app.")]
public class ImageDefinitionReactor : NonGraphicalObject
{
/// <inheritdoc/>
Expand All @@ -33,5 +35,12 @@ public class ImageDefinitionReactor : NonGraphicalObject
/// </summary>
[DxfCodeValue(DxfReferenceType.Handle, 330)]
public ImageDefinition Definition { get; set; }

internal ImageDefinitionReactor() { }

internal ImageDefinitionReactor(ImageDefinition definition)
{
this.Definition = definition;
}
}
}