tbf/TBF/Rig/BridgeComponents/GciBridge/GciBridgeCfgCtrl.cs

183 lines
5.8 KiB
C#

///
/// Copyright (c) 2015-2021 Sensus Slovensko a.s.
///
using Common;
using System;
using System.Windows.Forms;
using TBF.Rig.Generic;
using TBF.UI.Bench.Components;
namespace TBF.Rig.BridgeComponents.GciBridge
{
/// <summary>
/// Configuration control for GCI bridge component.
/// </summary>
public partial class GciBridgeCfgCtrl : UserControl, IComponentCfgCtrl
{
ComponentParametersDlg parent;
public bool ShowMore { get { return true; } }
GciBridgeCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as GciBridgeCfg;
Redraw();
}
}
public GciBridgeCfgCtrl()
{
InitializeComponent();
}
private void GciBridgeCfgCtrl_Load(object sender, EventArgs e)
{
parent = ParentForm as ComponentParametersDlg;
if (parent == null) return;
if (parent.CmpntEntities != null)
{
readerNameComboBox.Items.Add("---");
writerNameComboBox.Items.Add("---");
foreach (var cmpnt in parent.CmpntEntities)
{
object factory = TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName);
if (factory is TBF.Rig.Input.DataStorage.UniDataStorageReader.Factory)
{
readerNameComboBox.Items.Add(cmpnt.Name);
}
if (factory is TBF.Rig.Output.DataStorage.UniDataStorageWriter.Factory)
{
writerNameComboBox.Items.Add(cmpnt.Name);
}
}
}
Redraw();
}
public void Closing()
{
}
void Redraw()
{
if (config == null) return;
classNameLabel.Text = config.Factory.ClassName;
nameTextBox.Text = config.Name;
readerNameComboBox.Text = string.IsNullOrEmpty(config.ReaderName) ? "---" : config.ReaderName;
writerNameComboBox.Text = string.IsNullOrEmpty(config.WriterName) ? "---" : config.WriterName;
enableGuiCheckBox.Checked = config.EnableGuiAccess;
enableExternalCheckBox.Checked = config.EnableExternalAccess;
showGuiOnInitializeCheckBox.Checked = config.ShowGuiOnInitialize;
externalTypeNameTextBox.Text = config.ExternalInterfaceTypeName;
}
public void Unlock()
{
nameTextBox.Enabled = true;
readerNameComboBox.Enabled = true;
writerNameComboBox.Enabled = true;
enableGuiCheckBox.Enabled = true;
enableExternalCheckBox.Enabled = true;
showGuiOnInitializeCheckBox.Enabled = true;
externalTypeNameTextBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
if (string.IsNullOrWhiteSpace(nameTextBox.Text))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "Invalid 'Name'";
}
if (!readerNameComboBox.Items.Contains(readerNameComboBox.Text))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "Invalid 'Reader Name'";
}
if (!writerNameComboBox.Items.Contains(writerNameComboBox.Text))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "Invalid 'Writer Name'";
}
return flags;
}
public CfgUpdateFlags UpdateCfg()
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
if (config == null) return CfgUpdateFlags.Error;
if (!config.Name.Equals(nameTextBox.Text))
{
config.Name = nameTextBox.Text;
flags |= CfgUpdateFlags.RestartRqrd;
}
string readerName = readerNameComboBox.Text.Equals("---") ? string.Empty : readerNameComboBox.Text;
if (!config.ReaderName.Equals(readerName))
{
config.ReaderName = readerName;
flags |= CfgUpdateFlags.RestartRqrd;
}
string writerName = writerNameComboBox.Text.Equals("---") ? string.Empty : writerNameComboBox.Text;
if (!config.WriterName.Equals(writerName))
{
config.WriterName = writerName;
flags |= CfgUpdateFlags.RestartRqrd;
}
if (config.EnableGuiAccess != enableGuiCheckBox.Checked)
{
config.EnableGuiAccess = enableGuiCheckBox.Checked;
flags |= CfgUpdateFlags.RestartRqrd;
}
if (config.EnableExternalAccess != enableExternalCheckBox.Checked)
{
config.EnableExternalAccess = enableExternalCheckBox.Checked;
flags |= CfgUpdateFlags.RestartRqrd;
}
if (config.ShowGuiOnInitialize != showGuiOnInitializeCheckBox.Checked)
{
config.ShowGuiOnInitialize = showGuiOnInitializeCheckBox.Checked;
flags |= CfgUpdateFlags.RestartRqrd;
}
if (config.ExternalInterfaceTypeName != externalTypeNameTextBox.Text)
{
config.ExternalInterfaceTypeName = externalTypeNameTextBox.Text;
flags |= CfgUpdateFlags.RestartRqrd;
}
return flags;
}
private void connectExternalButton_Click(object sender, EventArgs e)
{
/// TODO
}
private void showGuiButton_Click(object sender, EventArgs e)
{
/// TODO
}
}
}