Upgrade (develop) - GCI UI for TBF - change Forms to Views

This commit is contained in:
Marek Frniak 2026-04-26 11:39:35 +02:00
parent 992452052e
commit a4ece06b05
6 changed files with 523 additions and 477 deletions

View File

@ -11,20 +11,14 @@
private System.Windows.Forms.ToolStripMenuItem miClearLog;
private System.Windows.Forms.ToolStripMenuItem miHelp;
private System.Windows.Forms.ToolStripMenuItem miHelpAbout;
private System.Windows.Forms.Panel pnlLeftMenu;
private System.Windows.Forms.Panel pnlMain;
private System.Windows.Forms.RichTextBox rtbMainLog;
private System.Windows.Forms.Panel mainHostPanel;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel tslStatus;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
@ -38,54 +32,39 @@
this.miClearLog = new System.Windows.Forms.ToolStripMenuItem();
this.miHelp = new System.Windows.Forms.ToolStripMenuItem();
this.miHelpAbout = new System.Windows.Forms.ToolStripMenuItem();
this.pnlLeftMenu = new System.Windows.Forms.Panel();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.preadjustmentButton = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnPulseSetup = new System.Windows.Forms.Button();
this.btnSetup = new System.Windows.Forms.Button();
this.btnRegisterStore = new System.Windows.Forms.Button();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.pnlMain = new System.Windows.Forms.Panel();
this.rtbMainLog = new System.Windows.Forms.RichTextBox();
this.mainHostPanel = new System.Windows.Forms.Panel();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.tslStatus = new System.Windows.Forms.ToolStripStatusLabel();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout();
this.pnlLeftMenu.SuspendLayout();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.pnlMain.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.miFile,
this.miView,
this.miHelp});
this.miFile,
this.miView,
this.miHelp
});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2);
this.menuStrip1.Size = new System.Drawing.Size(1309, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// miFile
//
this.miFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.miExit});
this.miExit
});
this.miFile.Name = "miFile";
this.miFile.Size = new System.Drawing.Size(37, 20);
this.miFile.Text = "File";
//
// miExit
//
@ -93,14 +72,17 @@
this.miExit.Size = new System.Drawing.Size(92, 22);
this.miExit.Text = "Exit";
this.miExit.Click += new System.EventHandler(this.miExit_Click);
//
// miView
//
this.miView.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.miClearLog});
this.miClearLog
});
this.miView.Name = "miView";
this.miView.Size = new System.Drawing.Size(44, 20);
this.miView.Text = "View";
//
// miClearLog
//
@ -108,14 +90,17 @@
this.miClearLog.Size = new System.Drawing.Size(124, 22);
this.miClearLog.Text = "Clear Log";
this.miClearLog.Click += new System.EventHandler(this.miClearLog_Click);
//
// miHelp
//
this.miHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.miHelpAbout});
this.miHelpAbout
});
this.miHelp.Name = "miHelp";
this.miHelp.Size = new System.Drawing.Size(44, 20);
this.miHelp.Text = "Help";
//
// miHelpAbout
//
@ -123,177 +108,44 @@
this.miHelpAbout.Size = new System.Drawing.Size(107, 22);
this.miHelpAbout.Text = "About";
this.miHelpAbout.Click += new System.EventHandler(this.miHelpAbout_Click);
//
// pnlLeftMenu
// mainHostPanel
//
this.pnlLeftMenu.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pnlLeftMenu.Controls.Add(this.tabControl1);
this.pnlLeftMenu.Dock = System.Windows.Forms.DockStyle.Left;
this.pnlLeftMenu.Location = new System.Drawing.Point(0, 24);
this.pnlLeftMenu.Name = "pnlLeftMenu";
this.pnlLeftMenu.Size = new System.Drawing.Size(190, 474);
this.pnlLeftMenu.TabIndex = 1;
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(3, 5);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(186, 464);
this.tabControl1.TabIndex = 4;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.groupBox2);
this.tabPage1.Controls.Add(this.groupBox1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(178, 438);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Laatzen API";
this.tabPage1.UseVisualStyleBackColor = true;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.preadjustmentButton);
this.groupBox2.Location = new System.Drawing.Point(6, 190);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(166, 66);
this.groupBox2.TabIndex = 5;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "CordonelPreadjustmentUI";
//
// preadjustmentButton
//
this.preadjustmentButton.Location = new System.Drawing.Point(6, 19);
this.preadjustmentButton.Name = "preadjustmentButton";
this.preadjustmentButton.Size = new System.Drawing.Size(153, 35);
this.preadjustmentButton.TabIndex = 3;
this.preadjustmentButton.Text = "Preadjustment";
this.preadjustmentButton.UseVisualStyleBackColor = true;
this.preadjustmentButton.Click += new System.EventHandler(this.preadjustmentButton_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.btnPulseSetup);
this.groupBox1.Controls.Add(this.btnSetup);
this.groupBox1.Controls.Add(this.btnRegisterStore);
this.groupBox1.Location = new System.Drawing.Point(6, 17);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(166, 153);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "GenesisToolBox";
//
// btnPulseSetup
//
this.btnPulseSetup.Location = new System.Drawing.Point(7, 101);
this.btnPulseSetup.Name = "btnPulseSetup";
this.btnPulseSetup.Size = new System.Drawing.Size(153, 35);
this.btnPulseSetup.TabIndex = 2;
this.btnPulseSetup.Text = "Pulse Setup";
this.btnPulseSetup.UseVisualStyleBackColor = true;
this.btnPulseSetup.Click += new System.EventHandler(this.btnPulseSetup_Click);
//
// btnSetup
//
this.btnSetup.Location = new System.Drawing.Point(7, 19);
this.btnSetup.Name = "btnSetup";
this.btnSetup.Size = new System.Drawing.Size(153, 35);
this.btnSetup.TabIndex = 0;
this.btnSetup.Text = "Setup";
this.btnSetup.UseVisualStyleBackColor = true;
this.btnSetup.Click += new System.EventHandler(this.btnSetup_Click);
//
// btnRegisterStore
//
this.btnRegisterStore.Location = new System.Drawing.Point(7, 60);
this.btnRegisterStore.Name = "btnRegisterStore";
this.btnRegisterStore.Size = new System.Drawing.Size(153, 35);
this.btnRegisterStore.TabIndex = 1;
this.btnRegisterStore.Text = "Register Store";
this.btnRegisterStore.UseVisualStyleBackColor = true;
this.btnRegisterStore.Click += new System.EventHandler(this.btnRegisterStore_Click);
//
// tabPage2
//
this.tabPage2.Controls.Add(this.groupBox3);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(178, 438);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "GCI API";
this.tabPage2.UseVisualStyleBackColor = true;
//
// pnlMain
//
this.pnlMain.Controls.Add(this.rtbMainLog);
this.pnlMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.pnlMain.Location = new System.Drawing.Point(190, 24);
this.pnlMain.Name = "pnlMain";
this.pnlMain.Padding = new System.Windows.Forms.Padding(9);
this.pnlMain.Size = new System.Drawing.Size(1119, 474);
this.pnlMain.TabIndex = 2;
//
// rtbMainLog
//
this.rtbMainLog.Dock = System.Windows.Forms.DockStyle.Fill;
this.rtbMainLog.Font = new System.Drawing.Font("Consolas", 10F);
this.rtbMainLog.Location = new System.Drawing.Point(9, 9);
this.rtbMainLog.Name = "rtbMainLog";
this.rtbMainLog.ReadOnly = true;
this.rtbMainLog.Size = new System.Drawing.Size(1101, 456);
this.rtbMainLog.TabIndex = 0;
this.rtbMainLog.Text = "";
this.mainHostPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.mainHostPanel.Location = new System.Drawing.Point(0, 24);
this.mainHostPanel.Name = "mainHostPanel";
this.mainHostPanel.Padding = new System.Windows.Forms.Padding(0);
this.mainHostPanel.Size = new System.Drawing.Size(1309, 474);
this.mainHostPanel.TabIndex = 1;
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tslStatus});
this.tslStatus
});
this.statusStrip1.Location = new System.Drawing.Point(0, 498);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0);
this.statusStrip1.Size = new System.Drawing.Size(1309, 22);
this.statusStrip1.TabIndex = 3;
this.statusStrip1.TabIndex = 2;
this.statusStrip1.Text = "statusStrip1";
//
// tslStatus
//
this.tslStatus.Name = "tslStatus";
this.tslStatus.Size = new System.Drawing.Size(39, 17);
this.tslStatus.Text = "Ready";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.button1);
this.groupBox3.Location = new System.Drawing.Point(6, 15);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(166, 66);
this.groupBox3.TabIndex = 6;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "GenesisCordonelInterface";
//
// button1
//
this.button1.Location = new System.Drawing.Point(6, 19);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(153, 35);
this.button1.TabIndex = 3;
this.button1.Text = "API";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1309, 520);
this.Controls.Add(this.pnlMain);
this.Controls.Add(this.pnlLeftMenu);
this.Controls.Add(this.mainHostPanel);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
@ -301,33 +153,14 @@
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Genesis Cordonel Interface";
this.Load += new System.EventHandler(this.MainForm_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.pnlLeftMenu.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.pnlMain.ResumeLayout(false);
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.Button btnSetup;
private System.Windows.Forms.Button preadjustmentButton;
private System.Windows.Forms.Button btnRegisterStore;
private System.Windows.Forms.Button btnPulseSetup;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button button1;
}
}

View File

@ -1,173 +1,38 @@
using GenesisCordonelInterface.UI.LaatzenAPI_CordonelPreadjustmentUI;
using GenesisCordonelInterface.UI.StaraTuraAPI_GenesisCordonelInterface;
using System;
using System;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Xylem.Common.Ui.GenesisToolBox;
using Xylem.Common.Utils.Logging;
namespace GenesisCordonelInterface.UI
{
public partial class MainForm : Form
{
private static readonly NLog.ILogger Logger = NLog.LogManager.GetLogger("GenesisCordonelInterface");
private static readonly Regex LogLevelRegex = new Regex(@"\|\s*(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\s*\|", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private MainView mainView;
public MainForm()
{
InitializeComponent();
/*_logger = logger;
_logger.MessagePublished += OnLogMessagePublished;*/
UiLogBus.MessageReceived += UiLogBus_MessageReceived;
//TopRight position on screen
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, 0);
//black background
rtbMainLog.BackColor = Color.Black;
rtbMainLog.ForeColor = Color.Gainsboro;
rtbMainLog.Font = new Font("Consolas", 9f);
rtbMainLog.ReadOnly = true;
rtbMainLog.HideSelection = false;
StartPosition = FormStartPosition.Manual;
Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - Width, 0);
}
private void UiLogBus_MessageReceived(string msg)
private void MainForm_Load(object sender, EventArgs e)
{
if (InvokeRequired)
{
BeginInvoke(new Action<string>(UiLogBus_MessageReceived), msg);
return;
}
string[] lines = msg.Replace("\r\n", "\n").Split('\n');
foreach (string originalLine in lines)
{
if (string.IsNullOrWhiteSpace(originalLine))
continue;
string line = originalLine;
// Find header (timestamp|LEVEL|)
Match m = LogLevelRegex.Match(line);
string indent = "";
if (m.Success)
{
int indentLength = m.Index + m.Length;
indent = new string(' ', indentLength);
}
// Split long message manually if needed (optional)
string[] subLines = line.Split(new[] { " - " }, 2, StringSplitOptions.None);
string firstLine = line;
string rest = null;
if (subLines.Length == 2 && subLines[1].Length > 120) // heuristic
{
firstLine = subLines[0] + " - " + subLines[1].Substring(0, 120);
rest = subLines[1].Substring(120);
}
AppendStyledLine(firstLine);
if (!string.IsNullOrEmpty(rest))
{
AppendStyledLine(indent + rest);
}
}
}
private void AppendStyledLine(string line)
{
int start = rtbMainLog.TextLength;
rtbMainLog.SelectionStart = start;
rtbMainLog.SelectionLength = 0;
rtbMainLog.SelectionColor = Color.Gainsboro;
rtbMainLog.AppendText(line + Environment.NewLine);
Match m = LogLevelRegex.Match(line);
if (m.Success)
{
rtbMainLog.SelectionStart = start + m.Index;
rtbMainLog.SelectionLength = m.Length;
rtbMainLog.SelectionColor = GetLogLevelColor(m.Groups[1].Value);
}
HighlightKeywordsInLine(line, start);
}
private int MeasureTextWidthPx(string text)
{
if (string.IsNullOrEmpty(text))
return 0;
return TextRenderer.MeasureText(text, rtbMainLog.Font).Width;
}
protected override void OnFormClosed(FormClosedEventArgs e)
{
//_logger.MessagePublished -= OnLogMessagePublished;
UiLogBus.MessageReceived -= UiLogBus_MessageReceived;
base.OnFormClosed(e);
}
private void btnSetup_Click(object sender, EventArgs e)
{
Logger.Trace("FORM: ---------------------------------");
Logger.Trace("FORM: Setup open");
using (FrmSetup frm = new FrmSetup())
{
frm.ShowDialog(this);
}
Logger.Trace("FORM: Setup closed.");
}
private void btnRegisterStore_Click(object sender, EventArgs e)
{
Logger.Trace("FORM: ---------------------------------");
Logger.Trace("FORM: Register Store open.");
using (FrmRegisterStore frm = new FrmRegisterStore())
{
frm.ShowDialog(this);
}
Logger.Trace("FORM: Register Store closed.");
}
private void btnPulseSetup_Click(object sender, EventArgs e)
{
Logger.Trace("FORM: ---------------------------------");
Logger.Trace("FORM: Pulse Setup open.");
using (FrmConfigurations frm = new FrmConfigurations())
{
frm.ShowDialog(this);
}
Logger.Trace("FORM: Pulse Setup closed.");
mainView = new MainView();
mainView.Dock = DockStyle.Fill;
Controls.Add(mainView);
mainView.BringToFront();
}
private void miExit_Click(object sender, EventArgs e)
{
this.Close();
Close();
}
private void miClearLog_Click(object sender, EventArgs e)
{
rtbMainLog.Clear();
Logger.Trace("Log cleared.");
if (mainView != null)
mainView.ClearLog();
}
private void miHelpAbout_Click(object sender, EventArgs e)
@ -178,113 +43,5 @@ namespace GenesisCordonelInterface.UI
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
private Color GetLogLevelColor(string level)
{
switch (level.Trim().ToUpperInvariant())
{
case "TRACE": return Color.Gray;
case "DEBUG": return Color.DeepSkyBlue;
case "INFO": return Color.LimeGreen;
case "WARN": return Color.Orange;
case "ERROR": return Color.Red;
case "FATAL": return Color.Magenta;
default: return Color.Gainsboro;
}
}
private bool IsSeparatorLine(string text)
{
if (string.IsNullOrWhiteSpace(text))
return false;
string trimmed = text.Trim();
// Remove spaces and tab-like spacing
string compact = new string(trimmed.Where(c => !char.IsWhiteSpace(c)).ToArray());
if (compact.Length < 4)
return false;
// Count non-letter/non-digit characters
int nonAlnumCount = compact.Count(c => !char.IsLetterOrDigit(c));
// Consider it a separator if most characters are non-alphanumeric
// Examples:
// -----CommandToMeter()-----
// ==========================
// /////////
double ratio = (double)nonAlnumCount / compact.Length;
return ratio >= 0.6;
}
/// <summary>
/// special string highlighting
/// "TX FINAL" have to go before "TX"
/// else "TX" will highlighted in the middle of "TX FINAL"
/// </summary>
private static readonly (Color color, string[] keywords)[] KeywordGroups =
{
(Color.DeepSkyBlue, new[] { "REQUEST" }),
(Color.Lime, new[] { "RESPONSE" }),
//(Color.LightGreen, new[] { "START", "END" }),
//(Color.Cyan, new[] { "TX", "TX FINAL" }),
//(Color.DeepSkyBlue,new[] { "RX", "RX FINAL", "RX CHUNK" }),
(Color.Gold, new[] { "READ-REGISTER-SESSION", "UI-CLICK"}),
//(Color.Violet, new[] { "REGADDR" }),
//(Color.Khaki, new[] { "DEFAULT", "ALIGNED", "STRING" })
};
/// <summary>
/// special string highlighting
/// </summary>
/// <param name="line"></param>
/// <param name="lineStartIndex"></param>
private void HighlightKeywordsInLine(string line, int lineStartIndex)
{
foreach (var group in KeywordGroups)
{
foreach (var keyword in group.keywords)
{
int index = 0;
while ((index = line.IndexOf(keyword, index, StringComparison.Ordinal)) >= 0)
{
rtbMainLog.SelectionStart = lineStartIndex + index;
rtbMainLog.SelectionLength = keyword.Length;
rtbMainLog.SelectionColor = group.color;
index += keyword.Length;
}
}
}
}
private void preadjustmentButton_Click(object sender, EventArgs e)
{
Logger.Trace("FORM: ---------------------------------");
Logger.Trace("FORM: Preadjustment open.");
using (FrmCordonelPreadjustmentUI frm = new FrmCordonelPreadjustmentUI())
{
frm.ShowDialog(this);
}
Logger.Trace("FORM: Preadjustment closed.");
}
private void button1_Click(object sender, EventArgs e)
{
Logger.Trace("FORM: ---------------------------------");
Logger.Trace("FORM: GCI GUI interface open.");
using (FrmGCIAPI frm = new FrmGCIAPI())
{
frm.ShowDialog(this);
}
Logger.Trace("FORM: GCI GUI interface closed.");
}
}
}

View File

@ -0,0 +1,187 @@
namespace GenesisCordonelInterface.UI
{
partial class MainView
{
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.Panel pnlLeftMenu;
private System.Windows.Forms.Panel pnlMain;
private System.Windows.Forms.RichTextBox rtbMainLog;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button btnSetup;
private System.Windows.Forms.Button btnRegisterStore;
private System.Windows.Forms.Button btnPulseSetup;
private System.Windows.Forms.Button preadjustmentButton;
private System.Windows.Forms.Button button1;
private void InitializeComponent()
{
this.pnlLeftMenu = new System.Windows.Forms.Panel();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.preadjustmentButton = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnPulseSetup = new System.Windows.Forms.Button();
this.btnSetup = new System.Windows.Forms.Button();
this.btnRegisterStore = new System.Windows.Forms.Button();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.pnlMain = new System.Windows.Forms.Panel();
this.rtbMainLog = new System.Windows.Forms.RichTextBox();
this.pnlLeftMenu.SuspendLayout();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.pnlMain.SuspendLayout();
this.SuspendLayout();
//
// pnlLeftMenu
//
this.pnlLeftMenu.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pnlLeftMenu.Controls.Add(this.tabControl1);
this.pnlLeftMenu.Dock = System.Windows.Forms.DockStyle.Left;
this.pnlLeftMenu.Location = new System.Drawing.Point(0, 0);
this.pnlLeftMenu.Name = "pnlLeftMenu";
this.pnlLeftMenu.Size = new System.Drawing.Size(190, 500);
this.pnlLeftMenu.TabIndex = 0;
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(188, 498);
//
// tabPage1
//
this.tabPage1.Controls.Add(this.groupBox2);
this.tabPage1.Controls.Add(this.groupBox1);
this.tabPage1.Text = "Laatzen API";
this.tabPage1.UseVisualStyleBackColor = true;
//
// groupBox1 (GenesisToolBox)
//
this.groupBox1.Controls.Add(this.btnPulseSetup);
this.groupBox1.Controls.Add(this.btnSetup);
this.groupBox1.Controls.Add(this.btnRegisterStore);
this.groupBox1.Location = new System.Drawing.Point(6, 10);
this.groupBox1.Size = new System.Drawing.Size(166, 150);
this.groupBox1.Text = "GenesisToolBox";
//
// btnSetup
//
this.btnSetup.Location = new System.Drawing.Point(7, 20);
this.btnSetup.Size = new System.Drawing.Size(150, 30);
this.btnSetup.Text = "Setup";
this.btnSetup.Click += new System.EventHandler(this.btnSetup_Click);
//
// btnRegisterStore
//
this.btnRegisterStore.Location = new System.Drawing.Point(7, 55);
this.btnRegisterStore.Size = new System.Drawing.Size(150, 30);
this.btnRegisterStore.Text = "Register Store";
this.btnRegisterStore.Click += new System.EventHandler(this.btnRegisterStore_Click);
//
// btnPulseSetup
//
this.btnPulseSetup.Location = new System.Drawing.Point(7, 90);
this.btnPulseSetup.Size = new System.Drawing.Size(150, 30);
this.btnPulseSetup.Text = "Pulse Setup";
this.btnPulseSetup.Click += new System.EventHandler(this.btnPulseSetup_Click);
//
// groupBox2 (Preadjustment)
//
this.groupBox2.Controls.Add(this.preadjustmentButton);
this.groupBox2.Location = new System.Drawing.Point(6, 170);
this.groupBox2.Size = new System.Drawing.Size(166, 70);
this.groupBox2.Text = "CordonelPreadjustmentUI";
//
// preadjustmentButton
//
this.preadjustmentButton.Location = new System.Drawing.Point(6, 20);
this.preadjustmentButton.Size = new System.Drawing.Size(150, 30);
this.preadjustmentButton.Text = "Preadjustment";
this.preadjustmentButton.Click += new System.EventHandler(this.preadjustmentButton_Click);
//
// tabPage2
//
this.tabPage2.Controls.Add(this.groupBox3);
this.tabPage2.Text = "GCI API";
this.tabPage2.UseVisualStyleBackColor = true;
//
// groupBox3 (GCI API)
//
this.groupBox3.Controls.Add(this.button1);
this.groupBox3.Location = new System.Drawing.Point(6, 10);
this.groupBox3.Size = new System.Drawing.Size(166, 70);
this.groupBox3.Text = "GenesisCordonelInterface";
//
// button1
//
this.button1.Location = new System.Drawing.Point(6, 20);
this.button1.Size = new System.Drawing.Size(150, 30);
this.button1.Text = "API";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// pnlMain
//
this.pnlMain.Controls.Add(this.rtbMainLog);
this.pnlMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.pnlMain.Location = new System.Drawing.Point(190, 0);
this.pnlMain.Padding = new System.Windows.Forms.Padding(5);
//
// rtbMainLog
//
this.rtbMainLog.Dock = System.Windows.Forms.DockStyle.Fill;
this.rtbMainLog.Font = new System.Drawing.Font("Consolas", 10F);
this.rtbMainLog.ReadOnly = true;
//
// MainView
//
this.Controls.Add(this.pnlMain);
this.Controls.Add(this.pnlLeftMenu);
this.Name = "MainView";
this.Size = new System.Drawing.Size(900, 500);
this.pnlLeftMenu.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.pnlMain.ResumeLayout(false);
this.ResumeLayout(false);
}
}
}

View File

@ -0,0 +1,221 @@
using GenesisCordonelInterface.UI.LaatzenAPI_CordonelPreadjustmentUI;
using GenesisCordonelInterface.UI.StaraTuraAPI_GenesisCordonelInterface;
using System;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Xylem.Common.Ui.GenesisToolBox;
using Xylem.Common.Utils.Logging;
namespace GenesisCordonelInterface.UI
{
public partial class MainView : UserControl
{
private static readonly NLog.ILogger Logger = NLog.LogManager.GetLogger("GenesisCordonelInterface");
private static readonly Regex LogLevelRegex = new Regex(@"\|\s*(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\s*\|", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public MainView()
{
InitializeComponent();
UiLogBus.MessageReceived += UiLogBus_MessageReceived;
rtbMainLog.BackColor = Color.Black;
rtbMainLog.ForeColor = Color.Gainsboro;
rtbMainLog.Font = new Font("Consolas", 9f);
rtbMainLog.ReadOnly = true;
rtbMainLog.HideSelection = false;
}
protected override void Dispose(bool disposing)
{
UiLogBus.MessageReceived -= UiLogBus_MessageReceived;
base.Dispose(disposing);
}
private IWin32Window DialogOwner
{
get
{
Form owner = FindForm();
return owner ?? (IWin32Window)this;
}
}
private void btnSetup_Click(object sender, EventArgs e)
{
Logger.Trace("FORM: ---------------------------------");
Logger.Trace("FORM: Setup open");
using (FrmSetup frm = new FrmSetup())
{
frm.ShowDialog(DialogOwner);
}
Logger.Trace("FORM: Setup closed.");
}
private void btnRegisterStore_Click(object sender, EventArgs e)
{
Logger.Trace("FORM: ---------------------------------");
Logger.Trace("FORM: Register Store open.");
using (FrmRegisterStore frm = new FrmRegisterStore())
{
frm.ShowDialog(DialogOwner);
}
Logger.Trace("FORM: Register Store closed.");
}
private void btnPulseSetup_Click(object sender, EventArgs e)
{
Logger.Trace("FORM: ---------------------------------");
Logger.Trace("FORM: Pulse Setup open.");
using (FrmConfigurations frm = new FrmConfigurations())
{
frm.ShowDialog(DialogOwner);
}
Logger.Trace("FORM: Pulse Setup closed.");
}
private void preadjustmentButton_Click(object sender, EventArgs e)
{
Logger.Trace("FORM: ---------------------------------");
Logger.Trace("FORM: Preadjustment open.");
using (FrmCordonelPreadjustmentUI frm = new FrmCordonelPreadjustmentUI())
{
frm.ShowDialog(DialogOwner);
}
Logger.Trace("FORM: Preadjustment closed.");
}
private void button1_Click(object sender, EventArgs e)
{
Logger.Trace("FORM: ---------------------------------");
Logger.Trace("FORM: GCI GUI interface open.");
using (FrmGCIAPI frm = new FrmGCIAPI())
{
frm.ShowDialog(DialogOwner);
}
Logger.Trace("FORM: GCI GUI interface closed.");
}
public void ClearLog()
{
rtbMainLog.Clear();
Logger.Trace("Log cleared.");
}
private void UiLogBus_MessageReceived(string msg)
{
if (InvokeRequired)
{
BeginInvoke(new Action<string>(UiLogBus_MessageReceived), msg);
return;
}
string[] lines = msg.Replace("\r\n", "\n").Split('\n');
foreach (string originalLine in lines)
{
if (string.IsNullOrWhiteSpace(originalLine))
continue;
string line = originalLine;
Match m = LogLevelRegex.Match(line);
string indent = "";
if (m.Success)
{
int indentLength = m.Index + m.Length;
indent = new string(' ', indentLength);
}
string[] subLines = line.Split(new[] { " - " }, 2, StringSplitOptions.None);
string firstLine = line;
string rest = null;
if (subLines.Length == 2 && subLines[1].Length > 120)
{
firstLine = subLines[0] + " - " + subLines[1].Substring(0, 120);
rest = subLines[1].Substring(120);
}
AppendStyledLine(firstLine);
if (!string.IsNullOrEmpty(rest))
AppendStyledLine(indent + rest);
}
}
private void AppendStyledLine(string line)
{
int start = rtbMainLog.TextLength;
rtbMainLog.SelectionStart = start;
rtbMainLog.SelectionLength = 0;
rtbMainLog.SelectionColor = Color.Gainsboro;
rtbMainLog.AppendText(line + Environment.NewLine);
Match m = LogLevelRegex.Match(line);
if (m.Success)
{
rtbMainLog.SelectionStart = start + m.Index;
rtbMainLog.SelectionLength = m.Length;
rtbMainLog.SelectionColor = GetLogLevelColor(m.Groups[1].Value);
}
HighlightKeywordsInLine(line, start);
}
private Color GetLogLevelColor(string level)
{
switch (level.Trim().ToUpperInvariant())
{
case "TRACE": return Color.Gray;
case "DEBUG": return Color.DeepSkyBlue;
case "INFO": return Color.LimeGreen;
case "WARN": return Color.Orange;
case "ERROR": return Color.Red;
case "FATAL": return Color.Magenta;
default: return Color.Gainsboro;
}
}
private static readonly Tuple<Color, string[]>[] KeywordGroups =
{
Tuple.Create(Color.DeepSkyBlue, new[] { "REQUEST" }),
Tuple.Create(Color.Lime, new[] { "RESPONSE" }),
Tuple.Create(Color.Gold, new[] { "READ-REGISTER-SESSION", "UI-CLICK" })
};
private void HighlightKeywordsInLine(string line, int lineStartIndex)
{
foreach (var group in KeywordGroups)
{
foreach (var keyword in group.Item2)
{
int index = 0;
while ((index = line.IndexOf(keyword, index, StringComparison.Ordinal)) >= 0)
{
rtbMainLog.SelectionStart = lineStartIndex + index;
rtbMainLog.SelectionLength = keyword.Length;
rtbMainLog.SelectionColor = group.Item1;
index += keyword.Length;
}
}
}
}
}
}

View File

@ -1,14 +1,15 @@
///
using log4net;
///
/// Copyright (c) 2015-2021 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using log4net;
using System.Windows.Forms;
using TBF.Rig.Generic;
using ExternalInterfaceGUIType = GenesisCordonelInterface.UI.MainView;
using ExternalInterfaceType = GenesisCordonelInterface.API.InterfaceOutsideToGCI;
using UdsReaderType = TBF.Rig.Input.DataStorage.UniDataStorageReader.Reader;
using UdsWriterType = TBF.Rig.Output.DataStorage.UniDataStorageWriter.Writer;
using ExternalInterfaceType = GenesisCordonelInterface.API.InterfaceOutsideToGCI;
using ExternalInterfaceGUIType = GenesisCordonelInterface.UI.MainForm;
namespace TBF.Rig.BridgeComponents.GciBridge
{
@ -39,6 +40,11 @@ namespace TBF.Rig.BridgeComponents.GciBridge
/// </summary>
ExternalInterfaceGUIType gciGUI;
/// <summary>
///
/// </summary>
Form gciGuiHostForm;
/// <summary>
/// Placeholder for GCI external/public interface.
/// Replace object with real GCI interface type later.
@ -99,16 +105,25 @@ namespace TBF.Rig.BridgeComponents.GciBridge
{
try
{
using (gciGUI = new ExternalInterfaceGUIType())
{
gciGUI.ShowDialog(/*this*/);
}
if (gciGuiHostForm != null && !gciGuiHostForm.IsDisposed)
return;
log.InfoFormat("{0}: GCI GUI initialized.", Name);
gciGUI = new ExternalInterfaceGUIType();
gciGUI.Dock = DockStyle.Fill;
gciGuiHostForm = new Form();
gciGuiHostForm.Text = "Genesis Cordonel Interface";
gciGuiHostForm.Width = 1300;
gciGuiHostForm.Height = 600;
gciGuiHostForm.StartPosition = FormStartPosition.CenterScreen;
gciGuiHostForm.Controls.Add(gciGUI);
log.InfoFormat("{0}: GCI GUI view initialized.", Name);
}
catch (Exception ex)
{
log.Error("Failed to initialize GCI GUI.", ex);
log.Error("Failed to initialize GCI GUI view.", ex);
}
}
@ -137,11 +152,16 @@ namespace TBF.Rig.BridgeComponents.GciBridge
{
if (!gciBridgeCfg.EnableGuiAccess) return;
if (!IsGuiInitialized)
if (gciGuiHostForm == null || gciGuiHostForm.IsDisposed)
{
TryInitializeGui();
}
if (gciGuiHostForm == null) return;
gciGuiHostForm.Show();
gciGuiHostForm.BringToFront();
log.InfoFormat("{0}: ShowGui invoked.", Name);
}
@ -151,12 +171,10 @@ namespace TBF.Rig.BridgeComponents.GciBridge
public void HideGui()
{
if (!gciBridgeCfg.EnableGuiAccess) return;
if (!IsGuiInitialized) return;
if (gciGuiHostForm == null || gciGuiHostForm.IsDisposed) return;
gciGuiHostForm.Hide();
using (gciGUI)
{
gciGUI.Hide(/*this*/);
}
log.InfoFormat("{0}: HideGui invoked.", Name);
}

View File

@ -172,12 +172,42 @@ namespace TBF.Rig.BridgeComponents.GciBridge
private void connectExternalButton_Click(object sender, EventArgs e)
{
/// TODO
try
{
GciBridge bridge = TbfComponents.FindComponent(config.Name) as GciBridge;
if (bridge == null)
{
MessageBox.Show("GciBridge component was not found.", "GCI Bridge");
return;
}
bridge.ConnectExternal();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "GCI Bridge error");
}
}
private void showGuiButton_Click(object sender, EventArgs e)
{
/// TODO
try
{
GciBridge bridge = TbfComponents.FindComponent(config.Name) as GciBridge;
if (bridge == null)
{
MessageBox.Show("GciBridge component was not found.", "GCI Bridge");
return;
}
bridge.ShowGui();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "GCI Bridge error");
}
}
}
}