Skip to content

Commit

Permalink
image reactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Jan 27, 2025
1 parent 48507de commit 518ae78
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 16 deletions.
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;
}
}
}

0 comments on commit 518ae78

Please sign in to comment.