using Hi.Common;
using Hi.Common.XmlUtils;
using System.Xml;
using System.Xml.Linq;
namespace Sample.Common;
///
/// Per-user visibility flags for the Player page's divisions (charts and
/// info panels), flattened into a single all-boolean config persisted through
/// .
///
///
/// Defaults are tuned for a first-time user: the two info panels
/// ( and ) are ON
/// so the Player page looks populated without having to open the
/// Division Visibility dropdown; every chart toggle starts OFF.
///
public class PlayerDivConfig : IMakeXmlSource
{
#region XML IO
///
/// Registers this type's deserializer with the given
/// (or when is
/// null). Idempotent.
///
public static void Reg(XFactory factory = null)
{
factory ??= XFactory.Default;
factory.Generators.TryAdd(XName, (xml, baseDirectory, relFile, progress, res)
=> new PlayerDivConfig(xml));
}
///
/// Name for XML IO.
///
public static string XName => nameof(PlayerDivConfig);
///
/// Default constructor.
///
public PlayerDivConfig() { }
///
/// Initializes a new instance of the class from XML data.
///
/// XML element containing player-div data.
public PlayerDivConfig(XElement src)
{
if (src == null) return;
src.Element(nameof(EnableStripAvailabilityChart))?.Value?.SelfInvoke(
v => EnableStripAvailabilityChart = XmlConvert.ToBoolean(v));
src.Element(nameof(EnableStripRoughnessChart))?.Value?.SelfInvoke(
v => EnableStripRoughnessChart = XmlConvert.ToBoolean(v));
src.Element(nameof(ColorIndexTimeChart))?.Value?.SelfInvoke(
v => ColorIndexTimeChart = XmlConvert.ToBoolean(v));
src.Element(nameof(ForceCycleLineDiv))?.Value?.SelfInvoke(
v => ForceCycleLineDiv = XmlConvert.ToBoolean(v));
src.Element(nameof(SimSpindleMomentCycleLineDiv))?.Value?.SelfInvoke(
v => SimSpindleMomentCycleLineDiv = XmlConvert.ToBoolean(v));
src.Element(nameof(SensorSpindleMomentCycleLineDiv))?.Value?.SelfInvoke(
v => SensorSpindleMomentCycleLineDiv = XmlConvert.ToBoolean(v));
src.Element(nameof(DynamometerForceCycleLineDiv))?.Value?.SelfInvoke(
v => DynamometerForceCycleLineDiv = XmlConvert.ToBoolean(v));
src.Element(nameof(EnableStepDiv))?.Value?.SelfInvoke(
v => EnableStepDiv = XmlConvert.ToBoolean(v));
src.Element(nameof(MessageTable))?.Value?.SelfInvoke(
v => MessageTable = XmlConvert.ToBoolean(v));
src.Element(nameof(EnableDetailDiv0))?.Value?.SelfInvoke(
v => EnableDetailDiv0 = XmlConvert.ToBoolean(v));
}
///
public XElement MakeXmlSource(string baseDirectory, string relFile, bool exhibitionOnly)
{
return new XElement(XName,
new XElement(nameof(EnableStripAvailabilityChart), EnableStripAvailabilityChart),
new XElement(nameof(EnableStripRoughnessChart), EnableStripRoughnessChart),
new XElement(nameof(ColorIndexTimeChart), ColorIndexTimeChart),
new XElement(nameof(ForceCycleLineDiv), ForceCycleLineDiv),
new XElement(nameof(SimSpindleMomentCycleLineDiv), SimSpindleMomentCycleLineDiv),
new XElement(nameof(SensorSpindleMomentCycleLineDiv), SensorSpindleMomentCycleLineDiv),
new XElement(nameof(DynamometerForceCycleLineDiv), DynamometerForceCycleLineDiv),
new XElement(nameof(EnableStepDiv), EnableStepDiv),
new XElement(nameof(MessageTable), MessageTable),
new XElement(nameof(EnableDetailDiv0), EnableDetailDiv0)
);
}
#endregion
///
/// Availability strip chart (per-step timeline coloured by availability aspect).
///
public bool EnableStripAvailabilityChart { get; set; } = false;
///
/// Surface-roughness strip chart (per-step timeline coloured by surface-roughness aspect).
///
public bool EnableStripRoughnessChart { get; set; } = false;
///
/// Color-index strip chart (single-strip timeline coloured by arbitrary numeric/bool aspect).
///
public bool ColorIndexTimeChart { get; set; } = false;
///
/// Cycle-line chart of cutting force along the step's rotation cycle.
///
public bool ForceCycleLineDiv { get; set; } = false;
///
/// Cycle-line chart of simulation-derived spindle moment on spindle-rotation coordinate.
///
public bool SimSpindleMomentCycleLineDiv { get; set; } = false;
///
/// Cycle-line chart of sensor-measured spindle moment (overlay on sim moment).
///
public bool SensorSpindleMomentCycleLineDiv { get; set; } = false;
///
/// Cycle-line chart of sensor-measured force from an external dynamometer.
///
public bool DynamometerForceCycleLineDiv { get; set; } = false;
///
/// Full / condensed step information panel (Selected Step Info).
///
public bool EnableStepDiv { get; set; } = true;
///
/// Session messages panel.
///
public bool MessageTable { get; set; } = true;
///
/// Developer-only raw step-property dump panel.
///
public bool EnableDetailDiv0 { get; set; } = false;
}