Files
SabreTools/SabreTools.DatItems/Display.cs

492 lines
16 KiB
C#
Raw Normal View History

2020-09-04 10:28:25 -07:00
using System;
using System.Collections.Generic;
2020-09-02 21:36:14 -07:00
using System.Linq;
2020-09-07 22:00:02 -07:00
using System.Xml.Serialization;
2020-09-03 13:20:56 -07:00
2020-12-08 13:23:59 -08:00
using SabreTools.Core;
using SabreTools.Core.Tools;
2020-12-08 13:48:57 -08:00
using SabreTools.Filtering;
2020-09-03 13:20:56 -07:00
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
2020-09-02 21:36:14 -07:00
2020-12-08 15:15:41 -08:00
namespace SabreTools.DatItems
2020-09-02 21:36:14 -07:00
{
/// <summary>
/// Represents one machine display
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("display"), XmlRoot("display")]
2020-09-02 21:36:14 -07:00
public class Display : DatItem
{
#region Fields
/// <summary>
/// Display tag
/// </summary>
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("tag")]
2020-09-02 21:36:14 -07:00
public string Tag { get; set; }
/// <summary>
/// Display type
/// </summary>
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
2020-09-07 22:00:02 -07:00
[XmlElement("type")]
public DisplayType DisplayType { get; set; }
2020-09-02 21:36:14 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool DisplayTypeSpecified { get { return DisplayType != DisplayType.NULL; } }
2020-09-02 21:36:14 -07:00
/// <summary>
/// Display rotation
/// </summary>
[JsonProperty("rotate", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("rotate")]
2020-09-04 10:28:25 -07:00
public long? Rotate { get; set; }
2020-09-02 21:36:14 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool RotateSpecified { get { return Rotate != null; } }
2020-09-02 21:36:14 -07:00
/// <summary>
/// Determines if display is flipped in the X-coordinates
/// </summary>
[JsonProperty("flipx", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("flipx")]
2020-09-02 21:36:14 -07:00
public bool? FlipX { get; set; }
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool FlipXSpecified { get { return FlipX != null; } }
2020-09-02 21:36:14 -07:00
/// <summary>
/// Display width
/// </summary>
[JsonProperty("width", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("width")]
2020-09-04 10:39:37 -07:00
public long? Width { get; set; }
2020-09-02 21:36:14 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool WidthSpecified { get { return Width != null; } }
2020-09-02 21:36:14 -07:00
/// <summary>
/// Display height
/// </summary>
[JsonProperty("height", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("height")]
2020-09-04 10:39:37 -07:00
public long? Height { get; set; }
2020-09-02 21:36:14 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool HeightSpecified { get { return Height != null; } }
2020-09-02 21:36:14 -07:00
/// <summary>
/// Refresh rate
/// </summary>
[JsonProperty("refresh", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("refresh")]
2020-09-04 11:04:58 -07:00
public double? Refresh { get; set; }
2020-09-02 21:36:14 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool RefreshSpecified { get { return Refresh != null; } }
2020-09-02 21:36:14 -07:00
/// <summary>
/// Pixel clock timer
/// </summary>
[JsonProperty("pixclock", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("pixclock")]
2020-09-04 10:50:08 -07:00
public long? PixClock { get; set; }
2020-09-02 21:36:14 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool PixClockSpecified { get { return PixClock != null; } }
2020-09-02 21:36:14 -07:00
/// <summary>
/// Total horizontal lines
/// </summary>
[JsonProperty("htotal", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("htotal")]
2020-09-04 10:57:30 -07:00
public long? HTotal { get; set; }
2020-09-02 21:36:14 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool HTotalSpecified { get { return HTotal != null; } }
2020-09-02 21:36:14 -07:00
/// <summary>
/// Horizontal blank end
/// </summary>
[JsonProperty("hbend", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("hbend")]
2020-09-04 10:57:30 -07:00
public long? HBEnd { get; set; }
2020-09-02 21:36:14 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool HBEndSpecified { get { return HBEnd != null; } }
2020-09-02 21:36:14 -07:00
/// <summary>
/// Horizontal blank start
/// </summary>
[JsonProperty("hbstart", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("hbstart")]
2020-09-04 10:57:30 -07:00
public long? HBStart { get; set; }
2020-09-02 21:36:14 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool HBStartSpecified { get { return HBStart != null; } }
2020-09-02 21:36:14 -07:00
/// <summary>
/// Total vertical lines
/// </summary>
[JsonProperty("vtotal", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("vtotal")]
2020-09-04 10:57:30 -07:00
public long? VTotal { get; set; }
2020-09-02 21:36:14 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool VTotalSpecified { get { return VTotal != null; } }
2020-09-02 21:36:14 -07:00
/// <summary>
/// Vertical blank end
/// </summary>
[JsonProperty("vbend", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("vbend")]
2020-09-04 10:57:30 -07:00
public long? VBEnd { get; set; }
2020-09-02 21:36:14 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool VBEndSpecified { get { return VBEnd != null; } }
2020-09-02 21:36:14 -07:00
/// <summary>
/// Vertical blank start
/// </summary>
[JsonProperty("vbstart", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("vbstart")]
2020-09-04 10:57:30 -07:00
public long? VBStart { get; set; }
2020-09-02 21:36:14 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool VBStartSpecified { get { return VBStart != null; } }
2020-09-02 21:36:14 -07:00
#endregion
#region Accessors
/// <summary>
/// Set fields with given values
/// </summary>
/// <param name="mappings">Mappings dictionary</param>
public override void SetFields(Dictionary<Field, string> mappings)
{
// Set base fields
base.SetFields(mappings);
// Handle Display-specific fields
if (mappings.Keys.Contains(Field.DatItem_Tag))
Tag = mappings[Field.DatItem_Tag];
if (mappings.Keys.Contains(Field.DatItem_DisplayType))
DisplayType = mappings[Field.DatItem_DisplayType].AsDisplayType();
2020-09-02 21:36:14 -07:00
if (mappings.Keys.Contains(Field.DatItem_Rotate))
Rotate = Utilities.CleanLong(mappings[Field.DatItem_Rotate]);
2020-09-02 21:36:14 -07:00
if (mappings.Keys.Contains(Field.DatItem_FlipX))
FlipX = mappings[Field.DatItem_FlipX].AsYesNo();
if (mappings.Keys.Contains(Field.DatItem_Width))
Width = Utilities.CleanLong(mappings[Field.DatItem_Width]);
2020-09-02 21:36:14 -07:00
if (mappings.Keys.Contains(Field.DatItem_Height))
Height = Utilities.CleanLong(mappings[Field.DatItem_Height]);
2020-09-02 21:36:14 -07:00
if (mappings.Keys.Contains(Field.DatItem_Refresh))
2020-09-04 11:04:58 -07:00
{
if (Double.TryParse(mappings[Field.DatItem_Refresh], out double refresh))
Refresh = refresh;
}
2020-09-02 21:36:14 -07:00
if (mappings.Keys.Contains(Field.DatItem_PixClock))
PixClock = Utilities.CleanLong(mappings[Field.DatItem_PixClock]);
2020-09-02 21:36:14 -07:00
if (mappings.Keys.Contains(Field.DatItem_HTotal))
HTotal = Utilities.CleanLong(mappings[Field.DatItem_HTotal]);
2020-09-02 21:36:14 -07:00
if (mappings.Keys.Contains(Field.DatItem_HBEnd))
HBEnd = Utilities.CleanLong(mappings[Field.DatItem_HBEnd]);
2020-09-02 21:36:14 -07:00
if (mappings.Keys.Contains(Field.DatItem_HBStart))
HBStart = Utilities.CleanLong(mappings[Field.DatItem_HBStart]);
2020-09-02 21:36:14 -07:00
if (mappings.Keys.Contains(Field.DatItem_VTotal))
VTotal = Utilities.CleanLong(mappings[Field.DatItem_VTotal]);
2020-09-02 21:36:14 -07:00
if (mappings.Keys.Contains(Field.DatItem_VBEnd))
VBEnd = Utilities.CleanLong(mappings[Field.DatItem_VBEnd]);
2020-09-02 21:36:14 -07:00
if (mappings.Keys.Contains(Field.DatItem_VBStart))
VBStart = Utilities.CleanLong(mappings[Field.DatItem_VBStart]);
2020-09-02 21:36:14 -07:00
}
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Display object
/// </summary>
public Display()
{
ItemType = ItemType.Display;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Display()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Tag = this.Tag,
DisplayType = this.DisplayType,
Rotate = this.Rotate,
FlipX = this.FlipX,
Width = this.Width,
Height = this.Height,
Refresh = this.Refresh,
PixClock = this.PixClock,
HTotal = this.HTotal,
HBEnd = this.HBEnd,
HBStart = this.HBStart,
VTotal = this.VTotal,
VBEnd = this.VBEnd,
VBStart = this.VBStart,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Display, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Display
Display newOther = other as Display;
// If the Display information matches
return (Tag == newOther.Tag
&& DisplayType == newOther.DisplayType
&& Rotate == newOther.Rotate
&& FlipX == newOther.FlipX
&& Width == newOther.Width
&& Height == newOther.Height
&& Refresh == newOther.Refresh
&& PixClock == newOther.PixClock
&& HTotal == newOther.HTotal
&& HBEnd == newOther.HBEnd
&& HBStart == newOther.HBStart
&& VTotal == newOther.VTotal
&& VBEnd == newOther.VBEnd
&& VBStart == newOther.VBStart);
}
#endregion
#region Filtering
/// <summary>
/// Check to see if a DatItem passes the filter
/// </summary>
/// <param name="filter">Filter to check against</param>
/// <param name="sub">True if this is a subitem, false otherwise</param>
2020-09-02 21:36:14 -07:00
/// <returns>True if the item passed the filter, false otherwise</returns>
public override bool PassesFilter(Filter filter, bool sub = false)
2020-09-02 21:36:14 -07:00
{
// Check common fields first
if (!base.PassesFilter(filter, sub))
2020-09-02 21:36:14 -07:00
return false;
// Filter on tag
if (!filter.PassStringFilter(filter.DatItem_Tag, Tag))
2020-09-02 21:36:14 -07:00
return false;
// Filter on display type
if (filter.DatItem_DisplayType.MatchesPositive(DisplayType.NULL, DisplayType) == false)
2020-09-02 21:36:14 -07:00
return false;
if (filter.DatItem_DisplayType.MatchesNegative(DisplayType.NULL, DisplayType) == true)
2020-09-02 21:36:14 -07:00
return false;
// Filter on rotation
if (!filter.PassLongFilter(filter.DatItem_Rotate, Rotate))
2020-09-02 21:36:14 -07:00
return false;
// Filter on flipx
if (!filter.PassBoolFilter(filter.DatItem_FlipX, FlipX))
2020-09-02 21:36:14 -07:00
return false;
// Filter on width
if (!filter.PassLongFilter(filter.DatItem_Width, Width))
2020-09-02 21:36:14 -07:00
return false;
// Filter on height
if (!filter.PassLongFilter(filter.DatItem_Height, Height))
2020-09-02 21:36:14 -07:00
return false;
// Filter on refresh
if (!filter.PassDoubleFilter(filter.DatItem_Refresh, Refresh))
2020-09-02 21:36:14 -07:00
return false;
// Filter on pixclock
if (!filter.PassLongFilter(filter.DatItem_PixClock, PixClock))
2020-09-02 21:36:14 -07:00
return false;
// Filter on htotal
if (!filter.PassLongFilter(filter.DatItem_HTotal, HTotal))
2020-09-02 21:36:14 -07:00
return false;
// Filter on hbend
if (!filter.PassLongFilter(filter.DatItem_HBEnd, HBEnd))
2020-09-02 21:36:14 -07:00
return false;
// Filter on hbstart
if (!filter.PassLongFilter(filter.DatItem_HBStart, HBStart))
2020-09-02 21:36:14 -07:00
return false;
// Filter on vtotal
if (!filter.PassLongFilter(filter.DatItem_VTotal, VTotal))
2020-09-02 21:36:14 -07:00
return false;
// Filter on vbend
if (!filter.PassLongFilter(filter.DatItem_VBEnd, VBEnd))
2020-09-02 21:36:14 -07:00
return false;
// Filter on vbstart
if (!filter.PassLongFilter(filter.DatItem_VBStart, VBStart))
2020-09-02 21:36:14 -07:00
return false;
return true;
}
/// <summary>
/// Remove fields from the DatItem
/// </summary>
/// <param name="fields">List of Fields to remove</param>
public override void RemoveFields(List<Field> fields)
{
// Remove common fields first
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Tag))
Tag = null;
if (fields.Contains(Field.DatItem_DisplayType))
DisplayType = DisplayType.NULL;
2020-09-02 21:36:14 -07:00
if (fields.Contains(Field.DatItem_Rotate))
Rotate = null;
if (fields.Contains(Field.DatItem_FlipX))
FlipX = null;
if (fields.Contains(Field.DatItem_Width))
Width = null;
if (fields.Contains(Field.DatItem_Height))
Height = null;
if (fields.Contains(Field.DatItem_Refresh))
Refresh = null;
if (fields.Contains(Field.DatItem_PixClock))
PixClock = null;
if (fields.Contains(Field.DatItem_HTotal))
HTotal = null;
if (fields.Contains(Field.DatItem_HBEnd))
HBEnd = null;
if (fields.Contains(Field.DatItem_HBStart))
HBStart = null;
if (fields.Contains(Field.DatItem_VTotal))
VTotal = null;
if (fields.Contains(Field.DatItem_VBEnd))
VBEnd = null;
if (fields.Contains(Field.DatItem_VBStart))
VBStart = null;
}
#endregion
#region Sorting and Merging
/// <summary>
/// Replace fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="fields">List of Fields representing what should be updated</param>
public override void ReplaceFields(DatItem item, List<Field> fields)
{
// Replace common fields first
base.ReplaceFields(item, fields);
// If we don't have a Display to replace from, ignore specific fields
if (item.ItemType != ItemType.Display)
return;
// Cast for easier access
Display newItem = item as Display;
// Replace the fields
if (fields.Contains(Field.DatItem_Tag))
Tag = newItem.Tag;
if (fields.Contains(Field.DatItem_DisplayType))
DisplayType = newItem.DisplayType;
if (fields.Contains(Field.DatItem_Rotate))
Rotate = newItem.Rotate;
if (fields.Contains(Field.DatItem_FlipX))
FlipX = newItem.FlipX;
if (fields.Contains(Field.DatItem_Width))
Width = newItem.Width;
if (fields.Contains(Field.DatItem_Height))
Height = newItem.Height;
if (fields.Contains(Field.DatItem_Refresh))
Refresh = newItem.Refresh;
if (fields.Contains(Field.DatItem_PixClock))
PixClock = newItem.PixClock;
if (fields.Contains(Field.DatItem_HTotal))
HTotal = newItem.HTotal;
if (fields.Contains(Field.DatItem_HBEnd))
HBEnd = newItem.HBEnd;
if (fields.Contains(Field.DatItem_HBStart))
HBStart = newItem.HBStart;
if (fields.Contains(Field.DatItem_VTotal))
VTotal = newItem.VTotal;
if (fields.Contains(Field.DatItem_VBEnd))
VBEnd = newItem.VBEnd;
if (fields.Contains(Field.DatItem_VBStart))
VBStart = newItem.VBStart;
}
#endregion
}
}