refactor(demos): own UserConfig/UserService copy for Hi.Sample
UserService moved out of the HiNc core package; Hi.Sample keeps its own copy under Sample.Common so the DemoSessionMessage #ShowStepPresent region (a live docfx code snippet referenced by two app-anatomy pages) still compiles. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
using Hi.Cbtr;
|
||||
using Hi.Common;
|
||||
using Hi.Common.XmlUtils;
|
||||
using Hi.MachiningSteps;
|
||||
using Hi.NcMech.Fixtures;
|
||||
using Hi.NcMech.Workpieces;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Sample.Common;
|
||||
|
||||
/// <summary>
|
||||
/// User Configuration.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Sample-owned copy of the per-GUI user configuration, kept so the
|
||||
/// <see cref="DemoSessionMessage"/> step-present demo still compiles. Each
|
||||
/// GUI/APP keeps its own version; the core engine package (HiNc) no longer
|
||||
/// carries any GUI configuration type.
|
||||
/// </remarks>
|
||||
public class UserConfig : IMakeXmlSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers this type's deserializer with the given <see cref="XFactory"/>
|
||||
/// (or <see cref="XFactory.Default"/> when <paramref name="factory"/> is
|
||||
/// <c>null</c>). Idempotent.
|
||||
/// </summary>
|
||||
public static void Reg(XFactory factory = null)
|
||||
{
|
||||
factory ??= XFactory.Default;
|
||||
factory.Generators.TryAdd(XName, (xml, baseDirectory, relFile, progress, res)
|
||||
=> new UserConfig(xml, baseDirectory));
|
||||
}
|
||||
#region XML IO
|
||||
/// <summary>
|
||||
/// Name for XML IO.
|
||||
/// </summary>
|
||||
public static string XName => nameof(UserConfig);
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserConfig"/> class from XML data.
|
||||
/// </summary>
|
||||
/// <param name="src">XML element containing configuration data</param>
|
||||
/// <param name="baseDirectory">Base directory for resolving relative paths</param>
|
||||
public UserConfig(XElement src, string baseDirectory)
|
||||
{
|
||||
if (src == null) return;
|
||||
|
||||
src.Element(nameof(ShowPhysicsOptions))?.Value?.SelfInvoke(
|
||||
v => ShowPhysicsOptions = XmlConvert.ToBoolean(v));
|
||||
src.Element(nameof(LanguageCode))?.Value?.SelfInvoke(v => LanguageCode = v);
|
||||
src.Element(nameof(EnableFullControl))?.Value?.SelfInvoke(
|
||||
v => EnableFullControl = XmlConvert.ToBoolean(v));
|
||||
|
||||
src.Element(nameof(GraphicCacheLowerLimitMb))?.Value?.SelfInvoke(
|
||||
v => GraphicCacheLowerLimitMb = XmlConvert.ToDouble(v));
|
||||
src.Element(nameof(GraphicCacheUpperLimitMb))?.Value?.SelfInvoke(
|
||||
v => GraphicCacheUpperLimitMb = XmlConvert.ToDouble(v));
|
||||
src.Element(nameof(GraphicCacheMb))?.Value?.SelfInvoke(
|
||||
v => GraphicCacheMb = XmlConvert.ToInt64(v));
|
||||
|
||||
src.Element(nameof(DisplayedStepPresentKeyList))?.SelfInvoke(ee =>
|
||||
{
|
||||
DisplayedStepPresentKeyList = ee.Elements("Item").Select(e => e.Value).ToList();
|
||||
});
|
||||
|
||||
// Load FixtureSetupDisplayeeConfig
|
||||
src.Element(nameof(FixtureSetupDisplayeeConfig))?.SelfInvoke(e =>
|
||||
{
|
||||
FixtureSetupDisplayeeConfig = new FixtureEditorDisplayeeConfig(e);
|
||||
});
|
||||
|
||||
// Load EquipmentWorkpieceSetupDisplayeeConfig
|
||||
src.Element(nameof(EquipmentWorkpieceSetupDisplayeeConfig))?.SelfInvoke(e =>
|
||||
{
|
||||
EquipmentWorkpieceSetupDisplayeeConfig = new WorkpieceEditorDisplayeeConfig(e);
|
||||
});
|
||||
|
||||
// Load PlayerDivConfig
|
||||
src.Element(nameof(PlayerDivConfig))?.SelfInvoke(e =>
|
||||
{
|
||||
PlayerDivConfig = new PlayerDivConfig(e);
|
||||
});
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public XElement MakeXmlSource(string baseDirectory, string relFile, bool exhibitionOnly)
|
||||
{
|
||||
XElement dst = new XElement(XName,
|
||||
new XElement(nameof(ShowPhysicsOptions), ShowPhysicsOptions),
|
||||
new XElement(nameof(LanguageCode), LanguageCode),
|
||||
new XElement(nameof(EnableFullControl), EnableFullControl),
|
||||
new XElement(nameof(GraphicCacheLowerLimitMb), GraphicCacheLowerLimitMb),
|
||||
new XElement(nameof(GraphicCacheUpperLimitMb), GraphicCacheUpperLimitMb),
|
||||
new XElement(nameof(GraphicCacheMb), GraphicCacheMb),
|
||||
new XElement(nameof(DisplayedStepPresentKeyList),
|
||||
DisplayedStepPresentKeyList.Select(v => new XElement("Item", v))),
|
||||
new XElement(nameof(FixtureSetupDisplayeeConfig),
|
||||
FixtureSetupDisplayeeConfig?.MakeXmlSource(baseDirectory, relFile, exhibitionOnly)),
|
||||
new XElement(nameof(EquipmentWorkpieceSetupDisplayeeConfig),
|
||||
EquipmentWorkpieceSetupDisplayeeConfig?.MakeXmlSource(baseDirectory, relFile, exhibitionOnly)),
|
||||
PlayerDivConfig?.MakeXmlSource(baseDirectory, relFile, exhibitionOnly)
|
||||
);
|
||||
return dst;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether to show physics options in the UI.
|
||||
/// </summary>
|
||||
public bool ShowPhysicsOptions { get; set; } = false;
|
||||
/// <summary>
|
||||
/// Gets or sets the language code for the application UI.
|
||||
/// </summary>
|
||||
public string LanguageCode { get; set; } = "en";
|
||||
/// <summary>
|
||||
/// Enable Full control of the application.
|
||||
/// Eanble System.Diagnostics.Process in GUI Script Command.
|
||||
/// Not used yet.
|
||||
/// </summary>
|
||||
public bool EnableFullControl { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the lower limit of graphic cache in megabytes.
|
||||
/// </summary>
|
||||
public double GraphicCacheLowerLimitMb { get; set; } = 10;
|
||||
/// <summary>
|
||||
/// Gets or sets the upper limit of graphic cache in megabytes.
|
||||
/// </summary>
|
||||
public double GraphicCacheUpperLimitMb { get; set; } = 1200;
|
||||
/// <summary>
|
||||
/// Gets or sets the graphic cache size in megabytes.
|
||||
/// </summary>
|
||||
public long GraphicCacheMb
|
||||
{
|
||||
get => CubeTree.DispCacheMb;
|
||||
set => CubeTree.DispCacheMb = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Step infomation key list to show.
|
||||
/// </summary>
|
||||
public List<string> DisplayedStepPresentKeyList { get; set; } = new List<string>([
|
||||
nameof(MachiningStep.StepIndex),
|
||||
nameof(MachiningStep.FileNo), nameof(MachiningStep.LineNo),
|
||||
nameof(MachiningStep.FilePath),nameof(MachiningStep.AccumulatedTime),
|
||||
nameof(MachiningStep.LineText),nameof(MachiningStep.FlagsText),
|
||||
nameof(MachiningStep.ToolId),
|
||||
nameof(MachiningStep.SpindleSpeed_rpm),nameof(MachiningStep.Feedrate_mmdmin),
|
||||
nameof(MachiningStep.Mrr_mm3ds),
|
||||
nameof(MachiningStep.AvgAbsTorque_Nm),
|
||||
]);
|
||||
|
||||
/// <summary>
|
||||
/// Configuration for FixtureSetupDisplayee
|
||||
/// </summary>
|
||||
public FixtureEditorDisplayeeConfig FixtureSetupDisplayeeConfig { get; set; } = new FixtureEditorDisplayeeConfig();
|
||||
|
||||
/// <summary>
|
||||
/// Configuration for EquipmentWorkpieceSetupDisplayee
|
||||
/// </summary>
|
||||
public WorkpieceEditorDisplayeeConfig EquipmentWorkpieceSetupDisplayeeConfig { get; set; } = new WorkpieceEditorDisplayeeConfig();
|
||||
|
||||
/// <summary>
|
||||
/// Per-user visibility flags for the Player page's divisions (charts and info panels).
|
||||
/// Persisted alongside the rest of this <see cref="UserConfig"/>.
|
||||
/// </summary>
|
||||
public PlayerDivConfig PlayerDivConfig { get; set; } = new PlayerDivConfig();
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
public UserConfig() { }
|
||||
}
|
||||
Reference in New Issue
Block a user