using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Fusion_Control_Centre_Uber_XNA_Edition { public partial class Debug : Form { List AllBrains = null; List AllDigitalOutputs = null; List AllAnalogueInputs = null; List AllDigitalInputs = null; List AllVariables = null; public int CurrentIndex = -1; public event Fusion_Control_Centre_Uber_XNA_Edition_Game.Debug_Delegate_RequestNewLists RequestNewInformation; public event Fusion_Control_Centre_Uber_XNA_Edition_Game.Debug_Delegate_SaveVariable SaveVariableList; public event Fusion_Control_Centre_Uber_XNA_Edition_Game.Debug_Delegate_SaveDigitalOut SaveDigitalOut; public event Fusion_Control_Centre_Uber_XNA_Edition_Game.Debug_Delegate_SaveAnalogueInput SaveAnalogueInput; public event Fusion_Control_Centre_Uber_XNA_Edition_Game.Debug_Delegate_SaveDigitalInput SaveDigitalInput; public Debug(Fusion_Control_Centre_Uber_XNA_Edition_Game myMomma) { InitializeComponent(); myMomma.Debug_Event_SendLists += new Fusion_Control_Centre_Uber_XNA_Edition_Game.Debug_Delegate_SendLists(myMomma_Debug_Event_SendLists); myMomma.Debug_VerboseLoggingEvent += new Fusion_Control_Centre_Uber_XNA_Edition_Game.Debug_Delegate_VerboseLogging(myMomma_Debug_VerboseLoggingEvent); this.Show(); } public void myMomma_Debug_VerboseLoggingEvent(string LoggingString) { //DEBUG_RICHTEXT.Text += LoggingString + "\r\n"; DEBUG_RICHTEXT.AppendText(LoggingString + "\r\n"); DEBUG_RICHTEXT.ScrollToCaret(); return; } public void myMomma_Debug_Event_SendLists(List Debug_Brains, List Debug_Outputs, List Debug_AInputs, List Debug_DInputs, List Debug_Variables) { AllBrains = new List(Debug_Brains); AllDigitalOutputs = new List(Debug_Outputs); AllAnalogueInputs = new List(Debug_AInputs); AllDigitalInputs = new List(Debug_DInputs); AllVariables = new List(Debug_Variables); UpdateTree(); return; } public void UpdateTree() { DebugTree.Nodes.Clear(); TreeNode TNode_Brains = new TreeNode("Fusion Brains"); TreeNode TNode_Variables = new TreeNode("Variables"); TNode_Variables.Name = "Variables"; foreach (Fusion_Control_Centre_Uber_XNA_Edition_Game.BrainID CurrentBrain in AllBrains) { TreeNode TNode_TopBrain = new TreeNode(CurrentBrain.humanName); TreeNode TNode_BrainSettings = new TreeNode("Settings"); TNode_BrainSettings.Nodes.Add(new TreeNode("VID/PID: " + CurrentBrain.instanceID)); TNode_TopBrain.Nodes.Insert(0, TNode_BrainSettings); TreeNode TNode_DigitalOutputs = new TreeNode("Digital Outputs"); TreeNode TNode_AnalogueInputs = new TreeNode("Analogue Inputs"); TreeNode TNode_DigitalInputs = new TreeNode("Digital Inputs"); TNode_DigitalOutputs.Name = "Digital Outputs"; TNode_AnalogueInputs.Name = "Analogue Inputs"; TNode_DigitalInputs.Name = "Digital Inputs"; foreach (Fusion_Control_Centre_Uber_XNA_Edition_Game.DigitalOutputChannel CurrentDO in AllDigitalOutputs) { TreeNode TNode_tempTopDO = new TreeNode(CurrentDO.id); TNode_tempTopDO.Nodes.Add(new TreeNode("Port: " + CurrentDO.Port.ToString())); TNode_tempTopDO.Nodes.Add(new TreeNode("Current State: " + CurrentDO.CurrentState.ToString())); TNode_DigitalOutputs.Nodes.Add(TNode_tempTopDO); } foreach (Fusion_Control_Centre_Uber_XNA_Edition_Game.AnalogueInputChannel CurrentAI in AllAnalogueInputs) { TreeNode TNode_tempTopAI = new TreeNode(CurrentAI.id); TNode_tempTopAI.Nodes.Add(new TreeNode("Port: " + CurrentAI.Port.ToString())); TNode_tempTopAI.Nodes.Add(new TreeNode("Value: " + CurrentAI.CurrentValue.ToString())); TNode_tempTopAI.Nodes.Add(new TreeNode("Auto Average: " + CurrentAI.autoAverage.ToString())); TNode_tempTopAI.Nodes.Add(new TreeNode("Maximum History: " + CurrentAI.maximumHistory.ToString())); TNode_AnalogueInputs.Nodes.Add(TNode_tempTopAI); } foreach (Fusion_Control_Centre_Uber_XNA_Edition_Game.DigitalInputChannel CurrentDI in AllDigitalInputs) { TreeNode TNode_tempTopDI = new TreeNode(CurrentDI.id); TNode_tempTopDI.Nodes.Add(new TreeNode("Port: " + CurrentDI.Port.ToString())); TNode_tempTopDI.Nodes.Add(new TreeNode("Current State: " + CurrentDI.CurrentState.ToString())); TNode_DigitalInputs.Nodes.Add(TNode_tempTopDI); } TNode_TopBrain.Nodes.Insert(1, TNode_DigitalOutputs); TNode_TopBrain.Nodes.Insert(2, TNode_AnalogueInputs); TNode_TopBrain.Nodes.Insert(3, TNode_DigitalInputs); TNode_Brains.Nodes.Add(TNode_TopBrain); } foreach (Fusion_Control_Centre_Uber_XNA_Edition_Game.Variable CurrentVariable in AllVariables) { TNode_Variables.Nodes.Add(new TreeNode(CurrentVariable.variableReferenceName + ": " + CurrentVariable.variableValue)); } DebugTree.Nodes.Insert(0, TNode_Brains); DebugTree.Nodes.Insert(1, TNode_Variables); } private void BTN_UPDATE_Click(object sender, EventArgs e) { RequestNewInformation(); } private void BTN_VAR_SAVE_Click(object sender, EventArgs e) { if (CurrentIndex < AllVariables.Count) { double _double; bool _bool; if (double.TryParse(TXT_VAR_VALUE.Text, out _double)) { SaveVariableList((object)_double, CurrentIndex); } else if (bool.TryParse(TXT_VAR_VALUE.Text, out _bool)) { SaveVariableList((object)_bool, CurrentIndex); } else { MessageBox.Show("Error parsing Variable value"); } } } private void BTN_DO_SAVE_Click(object sender, EventArgs e) { SaveDigitalOut(AllDigitalOutputs); } private void BTN_AI_SAVE_Click(object sender, EventArgs e) { SaveAnalogueInput(AllAnalogueInputs); } private void BTN_DI_SAVE_Click(object sender, EventArgs e) { SaveDigitalInput(AllDigitalInputs); } private void DebugTree_AfterSelect(object sender, TreeViewEventArgs e) { bool isIdentified = false; bool continueSearching = true; TreeNode identifyingNode = e.Node; TreeNode identifyingNodePrevious; if (identifyingNode.Parent != null) { identifyingNodePrevious = identifyingNode; identifyingNode = identifyingNode.Parent; while (continueSearching) { switch (identifyingNode.Text.ToLower()) { case "digital outputs": { for (int i = 0; i < AllDigitalOutputs.Count; i++) { if (identifyingNodePrevious.Text.ToLower() == AllDigitalOutputs[i].id.ToLower()) { CurrentIndex = i; TXT_DO_NAME.Text = AllDigitalOutputs[i].id; RADIO_DO_ON.Checked = AllDigitalOutputs[i].CurrentState; RADIO_DO_OFF.Checked = !AllDigitalOutputs[i].CurrentState; DEBUG_TABCONTROL.SelectedTab = DEBUG_TAB_DO; continueSearching = false; break; } } } break; case "analogue inputs": { for (int i = 0; i < AllAnalogueInputs.Count; i++) { if (identifyingNodePrevious.Text.ToLower() == AllAnalogueInputs[i].id.ToLower()) { CurrentIndex = i; TXT_AI_NAME.Text = AllAnalogueInputs[i].id; TXT_AI_VALUE.Text = AllAnalogueInputs[i].CurrentValue.ToString(); CHK_AI_AUTOAVERAGE.Checked = AllAnalogueInputs[i].autoAverage; DEBUG_TABCONTROL.SelectedTab = DEBUG_TAB_AI; continueSearching = false; break; } } } break; case "digital inputs": { for (int i = 0; i < AllDigitalInputs.Count; i++) { if (identifyingNodePrevious.Text.ToLower() == AllDigitalInputs[i].id.ToLower()) { CurrentIndex = i; TXT_DI_NAME.Text = AllDigitalInputs[i].id; RADIO_DI_ON.Checked = AllDigitalInputs[i].CurrentState; RADIO_DI_OFF.Checked = !AllDigitalInputs[i].CurrentState; DEBUG_TABCONTROL.SelectedTab = DEBUG_TAB_DI; continueSearching = false; break; } } } break; case "variables": { for (int i = 0; i < AllVariables.Count; i++) { if (identifyingNodePrevious.Text.ToLower() == AllVariables[i].variableReferenceName.ToLower() + ": " + AllVariables[i].variableValue.ToString()) { CurrentIndex = i; TXT_VAR_NAME.Text = AllVariables[i].variableReferenceName; TXT_VAR_VALUE.Text = AllVariables[i].variableValue.ToString(); DEBUG_TABCONTROL.SelectedTab = DEBUG_TAB_VARIABLE; continueSearching = false; break; } } } break; default: if (identifyingNode.Parent != null) { identifyingNodePrevious = identifyingNode; identifyingNode = identifyingNode.Parent; continue; } else { continueSearching = false; } break; } } } } private void DEBUG_TABCONTROL_SelectedIndexChanged(object sender, EventArgs e) { if (DEBUG_TABCONTROL.SelectedTab == DEBUG_TAB_VARIABLE) { DebugTree.SelectedNode = DebugTree.Nodes.Find("Variables", true)[0]; } else if (DEBUG_TABCONTROL.SelectedTab == DEBUG_TAB_DO) { DebugTree.SelectedNode = DebugTree.Nodes.Find("Digital Outputs", true)[0]; } else if (DEBUG_TABCONTROL.SelectedTab == DEBUG_TAB_AI) { DebugTree.SelectedNode = DebugTree.Nodes.Find("Analogue Inputs", true)[0]; } else if (DEBUG_TABCONTROL.SelectedTab == DEBUG_TAB_DI) { DebugTree.SelectedNode = DebugTree.Nodes.Find("Digital Inputs", true)[0]; } } } }