using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Xml; using Microsoft.DirectX; using Microsoft.DirectX.Direct3D; namespace Fusion_Control_Centre_UberMDX { public partial class MainMDX : Form { public bool ReadInConfigurationFile() { #region ClearAllGlobals AllDisplayButtons.Clear(); AllFunctions.Clear(); AllBrains.Clear(); AllDigitalOutputs.Clear(); AllAnalogueInputs.Clear(); AllDigitalInputs.Clear(); AllVariables.Clear(); //AllLogic = null; AllLogicXMlNodes.Clear(); MDX_DebugLogging("Reading Config File"); #endregion #region Check if Configuration File Exists if (!File.Exists(Application.StartupPath + "\\FusionConfiguration.xml")) { //The file does not exist DisplayMessageBox("Configuration file not found"); return false; } #endregion #region Create XML Instances XmlDocument ConfigXML = new XmlDocument(); String XMLString = ""; #endregion #region Read in the Configuration File try { FileStream ConfigFileStream = new FileStream(Application.StartupPath + "\\FusionConfiguration.xml", FileMode.Open, FileAccess.Read); StreamReader ConfigReader = new StreamReader(ConfigFileStream); XMLString = ConfigReader.ReadToEnd(); ConfigReader.Close(); ConfigFileStream.Close(); } catch (Exception) { //Error Opening File DisplayMessageBox("Error Opening Configuration File"); return false; } if (XMLString == "") { DisplayMessageBox("Error Opening Configuration File"); return false; } #endregion try { #region Find and Select Main Node ConfigXML.LoadXml(XMLString); XmlNodeList AllConfigNodes = ConfigXML.ChildNodes; XmlNode MainNode = ConfigXML.SelectSingleNode("FusionControlCentreConfiguration"); XmlAttributeCollection MainNodeAttributes = MainNode.Attributes; #endregion #region Find Values of Main Node and Check Version foreach (XmlAttribute configattribute in MainNodeAttributes) { if (configattribute.Name.ToLower() == "version") { System.Reflection.Assembly CurrentAssembly = System.Reflection.Assembly.GetExecutingAssembly(); char[] splitparams = { ',' }; string[] assinfo = CurrentAssembly.FullName.Split(splitparams); foreach (string ass in assinfo) { if (ass.Replace(" ", "").StartsWith("Version=")) { string versionID = ass.Replace(" ", "").Substring("Version=".Length); splitparams[0] = '.'; string[] versioninfo = versionID.Split(splitparams); string[] neededversioninfo = configattribute.Value.Split(splitparams); for (int i = 0; i < neededversioninfo.Length; i++) { if (neededversioninfo.Length > versioninfo.Length && int.Parse(neededversioninfo[i]) > 0) { //Requires a newer version of software to run. DisplayMessageBox("This configuration file needs a newer version of the program than you have in order to run.\r\n" + "The file requires at least version " + configattribute.Value + " and you are currently running version " + versionID); return false; } if (int.Parse(versioninfo[i]) > int.Parse(neededversioninfo[i])) { break; } else if(int.Parse(versioninfo[i]) < int.Parse(neededversioninfo[i])) { //Requires a newer version of software to run. DisplayMessageBox("This configuration file needs a newer version of the program than you have in order to run.\r\n" + "The file requires at least version " + configattribute.Value + " and you are currently running version " + versionID, true); return false; } } } } } } #endregion #region Read in and Evaluate Configuration Nodes foreach (XmlNode confignode in AllConfigNodes) { if (confignode.Name.ToLower() == "FusionControlCentreConfiguration".ToLower()) { XmlNodeList SecondLevelNodes = confignode.ChildNodes; foreach (XmlNode subTopConfigNode in SecondLevelNodes) { #region Required Other Files if (subTopConfigNode.Name.ToLower() == "require") { //Other files to read in XmlNodeList RequiredFunctionsNode = subTopConfigNode.ChildNodes; foreach (XmlNode isRequiredNode in RequiredFunctionsNode) { #region External Function if (isRequiredNode.Name.ToLower() == "function") { //External Function XmlAttributeCollection extFunctionAttributes = isRequiredNode.Attributes; string readInFunction = ""; string readInFunctionName = ""; for (int func_i = 0; func_i < extFunctionAttributes.Count; func_i++) { if (extFunctionAttributes[func_i].Name.ToLower() == "file") { string file2read = extFunctionAttributes[func_i].Value; if (File.Exists(Application.StartupPath + "\\" + file2read + ".xml")) { FileStream TempFunctionReadFileStream = new FileStream(Application.StartupPath + "\\" + file2read + ".xml", FileMode.Open, FileAccess.Read); StreamReader TempFunctionReadStream = new StreamReader(TempFunctionReadFileStream); readInFunction = TempFunctionReadStream.ReadToEnd(); TempFunctionReadStream.Close(); TempFunctionReadFileStream.Close(); } else { DisplayMessageBox("An External Function referenced in the configuration file cannot be found.\r\n" + "Needed File: \\" + file2read + ".xml", true); return false; } } else if (extFunctionAttributes[func_i].Name.ToLower() == "id") { readInFunctionName = extFunctionAttributes[func_i].Value.ToLower(); } } XmlDocument newFunctionDocument = new XmlDocument(); newFunctionDocument.LoadXml(readInFunction); Functions newFunc = new Functions(); newFunc.functionName = readInFunctionName; foreach (XmlNode NewFunctionNode in newFunctionDocument.ChildNodes) { if (NewFunctionNode.Name.ToLower() == "function") { newFunc.rawFunction = newFunctionDocument; } } bool isUnique = true; for (int allfunc_i = 0; allfunc_i < AllFunctions.Count; allfunc_i++) { if (AllFunctions[allfunc_i].functionName == newFunc.functionName) { isUnique = false; break; } } if (isUnique) { AllFunctions.Add(newFunc); } } #endregion #region Fusion Font else if (isRequiredNode.Name.ToLower() == "font") { string temp_name = ""; float temp_size = -1.0f; string temp_configpath = ""; foreach (XmlAttribute FontAttribute in isRequiredNode.Attributes) { if (FontAttribute.Name.ToLower() == "name") { temp_name = FontAttribute.Value.ToLower(); } else if (FontAttribute.Name.ToLower() == "originalsize") { float.TryParse(FontAttribute.Value.ToLower(), out temp_size); } else if (FontAttribute.Name.ToLower() == "font_config") { temp_configpath = FontAttribute.Value.ToLower(); } } string readFont = ""; if (!File.Exists(temp_configpath)) { DisplayMessageBox("Font File is missing required parameter or not in the specified location...", true); return false; } else { FileStream tFS = new FileStream(temp_configpath, FileMode.Open, FileAccess.Read); StreamReader tSR = new StreamReader(tFS); readFont = tSR.ReadToEnd(); tSR.Close(); tFS.Close(); } XmlDocument newFontDocument = new XmlDocument(); newFontDocument.LoadXml(readFont); FusionFont temp_NewFusionFont = new FusionFont(); temp_NewFusionFont.FusionFontName = temp_name; temp_NewFusionFont.FusionFontOriginalSize = temp_size; foreach (XmlNode topFontNode in newFontDocument) { if (topFontNode.Name.ToLower() == "font") { foreach (XmlAttribute topFontAttribute in topFontNode.Attributes) { if (topFontAttribute.Name.ToLower() == "fontimage") { if (File.Exists(topFontAttribute.Value)) { FusionImage temp_FontFusionImage = new FusionImage(LoadMyTexture(MDX_Device, topFontAttribute.Value), MDX_Device); temp_NewFusionFont.FusionFontMainImage = temp_FontFusionImage; } else { //string[] _splitFontImageArray = temp_configpath.Split(new char[] { '\\', '/' }); if (temp_configpath.Contains("\\")) { string next_try = temp_configpath.Substring(0, temp_configpath.LastIndexOf('\\')); next_try += "\\" + topFontAttribute.Value; if (File.Exists(next_try)) { FusionImage temp_FontFusionImage = new FusionImage(LoadMyTexture(MDX_Device, next_try), MDX_Device); temp_NewFusionFont.FusionFontMainImage = temp_FontFusionImage; } } if (temp_NewFusionFont.FusionFontMainImage == null) { DisplayMessageBox("Font Image referenced in External Font file is missing or not in the correct location", true); return false; } } } } foreach (XmlNode FontCharNode in topFontNode.ChildNodes) { if (FontCharNode.Name.ToLower() == "char") { int x1 = -1, x2 = -1, y1 = -1, y2 = -1; int FF_value = -1; Vector4 FF_Offset = new Vector4(0.0f, 0.0f, 0.0f, 0.0f); foreach (XmlAttribute FF_CharAttribute in FontCharNode.Attributes) { switch (FF_CharAttribute.Name.ToLower()) { case "location_topleft": { char[] rect_splitter = { ',' }; string[] rect_parse = FF_CharAttribute.Value.Split(rect_splitter); int.TryParse(rect_parse[0], out x1); int.TryParse(rect_parse[1], out y1); } break; case "location_bottomright": { char[] rect_splitter = { ',' }; string[] rect_parse = FF_CharAttribute.Value.Split(rect_splitter); int.TryParse(rect_parse[0], out x2); int.TryParse(rect_parse[1], out y2); } break; case "value": { int.TryParse(FF_CharAttribute.Value, out FF_value); } break; case "offsets": { char[] rect_splitter = { ',' }; string[] rect_parse = FF_CharAttribute.Value.Split(rect_splitter); float FFx1 = 0.0f, FFx2 = 0.0f, FFy1 = 0.0f, FFy2 = 0.0f; float.TryParse(rect_parse[0], out FFx1); float.TryParse(rect_parse[1], out FFx2); float.TryParse(rect_parse[2], out FFy1); float.TryParse(rect_parse[3], out FFy2); FF_Offset = new Vector4(FFx1, FFy1, FFx2, FFy2); } break; default: //Error Or Unknown break; } } if (x1 >= 0 && y1 >= 0 && x2 - x1 > 0 && y2 - y1 > 0 && FF_value > 0) { temp_NewFusionFont.FusionFont_CharDefinitions.Add(new FusionFont.FusionFont_Character(new Rectangle(x1, y1, x2 - x1, y2 - y1), FF_value, FF_Offset)); } } } } } AllFusionFonts.Add(temp_NewFusionFont); } #endregion } } #endregion #region General Configuration else if (subTopConfigNode.Name.ToLower() == "general") { //General Part of the skin file foreach (XmlNode GeneralSubNode in subTopConfigNode.ChildNodes) { switch (GeneralSubNode.Name.ToLower()) { #region Remote Control case "remote": { foreach (XmlAttribute GeneralSubAttribute in GeneralSubNode.Attributes) { if (GeneralSubAttribute.Name.ToLower() == "status") { if (GeneralSubAttribute.Value.ToLower() == "enabled") { RemoteControlClass.Remote_MasterEnable = true; } } else if (GeneralSubAttribute.Name.ToLower() == "user_name") { RemoteControlClass._userName = GeneralSubAttribute.Value; } else if (GeneralSubAttribute.Name.ToLower() == "port") { int.TryParse(GeneralSubAttribute.Value, out RemoteControlClass._port); } } } break; #endregion #region COM Commands case "com": { foreach (XmlAttribute GeneralSubAttribute in GeneralSubNode.Attributes) { if (GeneralSubAttribute.Name.ToLower() == "status") { if (GeneralSubAttribute.Value.ToLower() == "enabled") { COM_checkCommunication = true; } else { COM_checkCommunication = false; } } } foreach (XmlNode COM_CommandsRootNode in GeneralSubNode.ChildNodes) { if (COM_CommandsRootNode.Name.ToLower() == "commands") { foreach (XmlNode COM_CommandNodes in COM_CommandsRootNode.ChildNodes) { if (COM_CommandNodes.Name.ToLower() == "command") { string com_command_id = ""; int com_command_minDVT = 0; foreach (XmlAttribute COM_CommandAttribute in COM_CommandNodes.Attributes) { if (COM_CommandAttribute.Name.ToLower() == "id") { com_command_id = COM_CommandAttribute.Value.ToLower(); } else if (COM_CommandAttribute.Name.ToLower() == "minimum_delta_vote_time") { int.TryParse(COM_CommandAttribute.Value, out com_command_minDVT); } } COM_Command _command = new COM_Command(com_command_id); _command.minimum_delta_vote_time = com_command_minDVT; foreach (XmlNode COM_CommandDo_Node in COM_CommandNodes.ChildNodes) { if (COM_CommandDo_Node.Name.ToLower() == "do") { _command.do_statements.Add(COM_CommandDo_Node); } } AllCOMCommands.Add(_command); } } } else if (COM_CommandsRootNode.Name.ToLower() == "executable_commands") { foreach (XmlNode COM_ProgramNodes in COM_CommandsRootNode.ChildNodes) { if (COM_ProgramNodes.Name.ToLower() == "external_COM_id".ToLower()) { string COM_Program_ID = ""; foreach (XmlAttribute COM_ProgramNodesAttribute in COM_ProgramNodes.Attributes) { if (COM_ProgramNodesAttribute.Name.ToLower() == "id") { COM_Program_ID = COM_ProgramNodesAttribute.Value; break; } } COM_Execution_Object_Class newCOMExecutionObject = new COM_Execution_Object_Class(COM_Program_ID); foreach (XmlNode COM_CommandNodes in COM_ProgramNodes.ChildNodes) { if (COM_CommandNodes.Name.ToLower() == "command") { string com_command_external = ""; string com_command_internal = ""; List com_command_external_parameters = new List(); foreach (XmlAttribute COM_CommandAttribute in COM_CommandNodes.Attributes) { if (COM_CommandAttribute.Name.ToLower() == "internal_id") { com_command_internal = COM_CommandAttribute.Value.ToLower(); } else if (COM_CommandAttribute.Name.ToLower() == "external_command") { com_command_external = COM_CommandAttribute.Value; } } List _parametersForSort = new List(); foreach (XmlNode COM_CommandNode_EX_Params in COM_CommandNodes.ChildNodes) { COM_Execution_Object_Class.COM_External_Executable_Parameter_Class _param = new COM_Execution_Object_Class.COM_External_Executable_Parameter_Class(); foreach (XmlAttribute COM_CommandNode_EX_Params_Attribute in COM_CommandNode_EX_Params.Attributes) { if (COM_CommandNode_EX_Params_Attribute.Name.ToLower() == "order") { int.TryParse(COM_CommandNode_EX_Params_Attribute.Value, out _param._order); } else if (COM_CommandNode_EX_Params_Attribute.Name.ToLower() == "external_command_parameter") { _param._param = COM_CommandNode_EX_Params_Attribute.Value; } } if (_param._order >= 0) { _parametersForSort.Add(_param); } } _parametersForSort.Sort(); foreach (COM_Execution_Object_Class.COM_External_Executable_Parameter_Class _pClass in _parametersForSort) { com_command_external_parameters.Add(_pClass._param); } newCOMExecutionObject.Add_Command(com_command_external, com_command_internal, com_command_external_parameters); } } COM_Execution_Commands_List.Add(newCOMExecutionObject); } } } } } break; #endregion #region Debugging case "debug": { foreach (XmlAttribute GeneralSubAttribute in GeneralSubNode.Attributes) { if (GeneralSubAttribute.Name.ToLower() == "status") { if (GeneralSubAttribute.Value.ToLower() == "on") { Debug_EnableDebugWindow = true; } } } if (Debug_EnableDebugWindow) { foreach (XmlNode _debugNode in GeneralSubNode.ChildNodes) { switch(_debugNode.Name.ToLower()) { case "window": { foreach (XmlAttribute _debug_attribute in _debugNode.Attributes) { switch (_debug_attribute.Value.ToLower()) { case "variables": { DEBUG_VariablesForm _debug = new DEBUG_VariablesForm(this); DEBUG_FormsToShow.Add((Form)_debug); } break; case "ifthen": { DEBUG_IfThenNodeForm _debug = new DEBUG_IfThenNodeForm(this); DEBUG_FormsToShow.Add((Form)_debug); } break; case "speech": { DEBUG_SpeechForm _debug = new DEBUG_SpeechForm(this); DEBUG_FormsToShow.Add((Form)_debug); } break; case "logic": { } break; default: break; } } } break; case "virtual_brain": { foreach (XmlAttribute _debug_attribute in _debugNode.Attributes) { switch (_debug_attribute.Name.ToLower()) { case "id": { DEBUG_VirtualBrainList.Add(new VirtualBrainClass(_debug_attribute.Value.ToLower())); } break; default: break; } } } break; case "byte_stream": { foreach (XmlAttribute _debug_attribute in _debugNode.Attributes) { switch (_debug_attribute.Name.ToLower()) { case "id": { DEBUG_FormsToShow.Add((Form)(new DEBUG_Byte_Stream(_debug_attribute.Value.ToLower()))); } break; default: break; } } } break; default: break; } } } } break; #endregion default: //Error or Unknown break; } } } #endregion #region Speech else if (subTopConfigNode.Name.ToLower() == "speech") { //Setup of Logic area foreach (XmlAttribute _speechRootEnableAttribute in subTopConfigNode.Attributes) { if (_speechRootEnableAttribute.Name.ToLower() == "enabled") { if (!bool.TryParse(_speechRootEnableAttribute.Value, out Speech_MasterEnable)) { } } else if (_speechRootEnableAttribute.Name.ToLower() == "global_politeness") { if (!bool.TryParse(_speechRootEnableAttribute.Value, out Speech_EnableGlobalPolite)) { } } } foreach (XmlNode speechTopNode in subTopConfigNode.ChildNodes) { switch (speechTopNode.Name.ToLower()) { case "system_name": { string new_system_name = speechTopNode.InnerText; if (new_system_name != null && new_system_name != "") { Speech_StaticSetupClass.generic_system.Add(new_system_name); } } break; case "system_definitions": { foreach (XmlNode _system_definition_nodes in speechTopNode.ChildNodes) { switch (_system_definition_nodes.Name.ToLower()) { case "digital_output_turn_on": { Speech_StaticSetupClass.generic_digital_output_turn_on.Add(_system_definition_nodes.InnerText); } break; case "digital_output_turn_off": { Speech_StaticSetupClass.generic_digital_output_turn_off.Add(_system_definition_nodes.InnerText); } break; case "digital_output_id_generic": { Speech_StaticSetupClass.generic_digital_output.Add(_system_definition_nodes.InnerText); } break; case "analogue_input_query": { Speech_StaticSetupClass.generic_analogue_input_read.Add(_system_definition_nodes.InnerText); } break; case "analogue_input_id_generic": { Speech_StaticSetupClass.generic_analogue_input.Add(_system_definition_nodes.InnerText); } break; default: //Error or Unknown break; } } } break; case "custom_definitions": { foreach (XmlNode _custom_definition_nodes in speechTopNode.ChildNodes) { switch (_custom_definition_nodes.Name.ToLower()) { case "digital_output": { Speech_StaticSetupClass.customDefinition _cD = new Speech_StaticSetupClass.customDefinition(); foreach (XmlAttribute _customDefAttribute in _custom_definition_nodes.Attributes) { if (_customDefAttribute.Name.ToLower() == "id") { _cD.systemName = _customDefAttribute.Value; break; } } _cD.spokenName = _custom_definition_nodes.InnerText; if (_cD.spokenName != "" && _cD.systemName != "") { Speech_StaticSetupClass.custom_definition_digital_outputs.Add(_cD); } } break; case "variable": { Speech_StaticSetupClass.customDefinition _cD = new Speech_StaticSetupClass.customDefinition(); foreach (XmlAttribute _customDefAttribute in _custom_definition_nodes.Attributes) { if (_customDefAttribute.Name.ToLower() == "id") { _cD.systemName = _customDefAttribute.Value; break; } } _cD.spokenName = _custom_definition_nodes.InnerText; if (_cD.spokenName != "" && _cD.systemName != "") { Speech_StaticSetupClass.custom_definition_variables.Add(_cD); } } break; default: //Error or Unknown break; } } } break; case "custom_queries": { foreach (XmlNode _queryNode in speechTopNode.ChildNodes) { if (_queryNode.Name.ToLower() == "query") { Speech_StaticSetupClass.customQuery _cQ = new Speech_StaticSetupClass.customQuery(); foreach (XmlAttribute _cQAttribute in _queryNode.Attributes) { if (_cQAttribute.Name.ToLower() == "monitor_type") { _cQ.monitor_type = _cQAttribute.Value.ToLower(); } else if (_cQAttribute.Name.ToLower() == "monitor_id") { _cQ.monitor_id = _cQAttribute.Value.ToLower(); } } foreach (XmlNode _queryBuildNodes in _queryNode.ChildNodes) { if (_queryBuildNodes.Name.ToLower() == "build_question") { foreach (XmlNode _queryBuildSubNodes in _queryBuildNodes.ChildNodes) { switch (_queryBuildSubNodes.Name.ToLower()) { case "beginning": { foreach (XmlNode _queryBuildOption in _queryBuildSubNodes.ChildNodes) { if (_queryBuildOption.Name.ToLower() == "option") { _cQ.builder_beginnings.Add(_queryBuildOption.InnerText); } } } break; case "middle": { foreach (XmlNode _queryBuildOption in _queryBuildSubNodes.ChildNodes) { if (_queryBuildOption.Name.ToLower() == "option") { _cQ.builder_middles.Add(_queryBuildOption.InnerText); } } } break; case "ending": { foreach (XmlNode _queryBuildOption in _queryBuildSubNodes.ChildNodes) { if (_queryBuildOption.Name.ToLower() == "option") { _cQ.builder_endings.Add(_queryBuildOption.InnerText); } } } break; } } } else if (_queryBuildNodes.Name.ToLower() == "responses") { foreach (XmlNode _queryBuildResponse in _queryBuildNodes.ChildNodes) { if (_queryBuildResponse.Name.ToLower() == "response") { string _response_b = "", _response_e = ""; foreach (XmlAttribute _responseAttributes in _queryBuildResponse.Attributes) { if (_responseAttributes.Name.ToLower() == "beginning") { _response_b = _responseAttributes.InnerText; } else if (_responseAttributes.Name.ToLower() == "ending") { _response_e = _responseAttributes.InnerText; } } _cQ.possible_responses.Add(new Speech_Response(_response_b, _response_e)); } } } } Speech_StaticSetupClass.custom_query_list.Add(_cQ); } } } break; default: //Error or Unknown break; } } } #endregion #region Graphics Configuration else if (subTopConfigNode.Name.ToLower() == "graphics") { //Graphic Part of the skin file foreach (XmlNode GraphicSubNode in subTopConfigNode.ChildNodes) { switch (GraphicSubNode.Name.ToLower()) { #region Main Program Global Values case "main_display": int original_size_x = -1; int original_size_y = -1; foreach (XmlAttribute MainDisplayAttribute in GraphicSubNode.Attributes) { switch (MainDisplayAttribute.Name.ToLower()) { #region Size of Program in Pixels (Designed for and Actual) case "designed_for_size": { int Size_x = 1; int Size_y = 1; if (!int.TryParse(MainDisplayAttribute.Value.Substring(0, MainDisplayAttribute.Value.IndexOf(',')), out Size_x) || !int.TryParse(MainDisplayAttribute.Value.Substring(MainDisplayAttribute.Value.IndexOf(',') + 1), out Size_y)) { //Error parsing DisplayMessageBox("Syntax error parsing the size command of the \"main_display\" item", true); } original_size_x = Size_x; original_size_y = Size_y; Application_Original_Width = Size_x; Application_Original_Height = Size_y; } break; case "show_at_size": { int Size_x = 1; int Size_y = 1; if (!int.TryParse(MainDisplayAttribute.Value.Substring(0, MainDisplayAttribute.Value.IndexOf(',')), out Size_x) || !int.TryParse(MainDisplayAttribute.Value.Substring(MainDisplayAttribute.Value.IndexOf(',') + 1), out Size_y)) { //Error parsing DisplayMessageBox("Syntax error parsing the size command of the \"main_display\" item", true); } Application_Width = Size_x; Application_Height = Size_y; this.Size = new Size(Application_Width, Application_Height); this.Update(); } break; #endregion #region Show or Hide the Menu bar with Min/Max/Close case "menubar": FormBorderStyle FBS = new FormBorderStyle(); switch (MainDisplayAttribute.Value.ToLower()) { case "none": case "hidden": FBS = FormBorderStyle.None; break; case "fixed": FBS = FormBorderStyle.FixedSingle; break; case "sizeable": FBS = FormBorderStyle.Sizable; break; default: //Not recognized type... break; } this.FormBorderStyle = FBS; break; #endregion #region Run in System Tray case "runinsystemtray": { if (MainDisplayAttribute.Value.ToLower() == "true") { RunProgramInSystemTray = true; } else { RunProgramInSystemTray = false; } } break; #endregion #region Minimize to System Tray case "minimizetosystemtray": { if (MainDisplayAttribute.Value.ToLower() == "true") { MinimizeToSystemTray = true; } else { MinimizeToSystemTray = false; } } break; #endregion #region Error or Undefined default: //Not recognized type... break; #endregion } } if (original_size_x < 0 || original_size_y < 0 || Application_Width < 0 || Application_Height < 0) { DisplayMessageBox("The Display Size or Actual Size has an error.", true); return false; } else { float scale_by_x = (float)((float)Application_Width / (float)original_size_x); float scale_by_y = (float)((float)Application_Height / (float)original_size_y); Application_isBeingScaledBy = new Vector2(scale_by_x, scale_by_y); } break; #endregion #region Background Images case "background_image": BackgroundImageForDisplay newBackImage = new BackgroundImageForDisplay(); foreach (XmlAttribute BackgroundAttribute in GraphicSubNode.Attributes) { switch (BackgroundAttribute.Name.ToLower()) { #region Page to Display Background Image on case "page": int.TryParse(BackgroundAttribute.Value, out newBackImage.thePage); MaxPage(newBackImage.thePage); break; #endregion #region ImageLayout of the Background Image case "style": ImageLayout newLayout = new ImageLayout(); switch (BackgroundAttribute.Value.ToLower()) { case "tile": newLayout = ImageLayout.Tile; break; case "centre": newLayout = ImageLayout.Center; break; case "zoom": newLayout = ImageLayout.Zoom; break; case "stretch": newLayout = ImageLayout.Stretch; break; default: //Unrecognized DisplayMessageBox("Syntax error in Background Image Style definition"); break; } newBackImage.theImageLayout = newLayout; break; #endregion #region Actual Image of the Background Image case "imagefilepath": try { newBackImage.theImage = new FusionImage(LoadMyTexture(MDX_Device, BackgroundAttribute.Value), MDX_Device); } catch (Exception) { DisplayMessageBox("Background Image not found. The page in error will not have a background."); } break; #endregion #region Error or Unknown default: //Undefined... break; #endregion } } #region If the new background image Mmeets requirements, add it to the global list... if (newBackImage.theImage != null && newBackImage.theImageLayout != ImageLayout.None && newBackImage.thePage >= 0) { AllBackgroundImages.Add(newBackImage); } break; #endregion #endregion #region Display Buttons case "button": { DisplayButton newDisplayButton = new DisplayButton(); foreach (XmlAttribute DisplayButtonAttribute in GraphicSubNode.Attributes) { switch (DisplayButtonAttribute.Name.ToLower()) { #region Unique ID of button case "id": string newID = DisplayButtonAttribute.Value.ToLower(); bool isUnique = true; foreach (DisplayButton testDispButton in AllDisplayButtons) { if (testDispButton.id == newID) { isUnique = false; break; } } if (isUnique) { newDisplayButton.id = newID; } break; #endregion #region The default Enabled/Disabled State of the Button on Program Start case "enabled": if (DisplayButtonAttribute.Value.ToLower() == "yes") { newDisplayButton.isEnabled = true; } else if (DisplayButtonAttribute.Value.ToLower() == "no") { newDisplayButton.isEnabled = false; } break; #endregion #region The function of the button (What it does) case "function": newDisplayButton.functionString = DisplayButtonAttribute.Value.ToLower(); break; #endregion #region The Target ID of whatever the function is case "functiontargetid": newDisplayButton.functionTarget = DisplayButtonAttribute.Value.ToLower(); break; #endregion #region Vote Type case "vote": newDisplayButton.voteType = DisplayButtonAttribute.Value.ToLower(); break; #endregion #region Vote Opinion case "vote_opinion": newDisplayButton.voteOpinion = DisplayButtonAttribute.Value.ToLower(); break; #endregion #region Vote Priority case "vote_priority": switch (DisplayButtonAttribute.Value.ToLower()) { case "low": newDisplayButton.votePriority = Vote_Priority.LOW_PRIORITY; break; case "medium": newDisplayButton.votePriority = Vote_Priority.MEDIUM_PRIORITY; break; case "high": newDisplayButton.votePriority = Vote_Priority.HIGH_PRIORITY; break; default: break; } break; #endregion #region Error or Undefined default: break; #endregion } } foreach (XmlNode DeZildrenOfDeButton in GraphicSubNode.ChildNodes) { foreach (XmlAttribute DeZildrenAttributes in DeZildrenOfDeButton.Attributes) { switch (DeZildrenAttributes.Name.ToLower()) { #region Primary Image case "imageprimary": if (File.Exists(DeZildrenAttributes.Value)) { newDisplayButton.MDX_Primary = new FusionImage(LoadMyTexture(MDX_Device, DeZildrenAttributes.Value), MDX_Device); } else { DisplayMessageBox("A Dispay Button's primary image does not exist where specified.", true); } break; #endregion #region Secondary Image case "imagesecondary": try { newDisplayButton.MDX_Secondary = new FusionImage(LoadMyTexture(MDX_Device, DeZildrenAttributes.Value), MDX_Device); } catch (FileNotFoundException) { DisplayMessageBox("A Dispay Button's secondary image does not exist where specified.", true); } break; #endregion #region Disabled Image case "imagedisabled": try { newDisplayButton.MDX_Disabled = new FusionImage(LoadMyTexture(MDX_Device, DeZildrenAttributes.Value), MDX_Device); } catch (FileNotFoundException) { DisplayMessageBox("A Dispay Button's disabled image does not exist where specified.", true); } break; #endregion #region Pushed Image case "imagepushed": try { newDisplayButton.MDX_Pushed = new FusionImage(LoadMyTexture(MDX_Device, DeZildrenAttributes.Value), MDX_Device); } catch (FileNotFoundException) { DisplayMessageBox("A Dispay Button's pushed image does not exist where specified.", true); } break; #endregion #region Size of Button case "size": int Size_x = 1; int Size_y = 1; if (!int.TryParse(DeZildrenAttributes.Value.Substring(0, DeZildrenAttributes.Value.IndexOf(',')), out Size_x) || !int.TryParse(DeZildrenAttributes.Value.Substring(DeZildrenAttributes.Value.IndexOf(',') + 1), out Size_y)) { //Error parsing DisplayMessageBox("Syntax error parsing the size of a button item"); } else { newDisplayButton.DisplaySize = new Size(Size_x, Size_y); } break; #endregion #region Location of Button case "location": float Loc_x = 1; float Loc_y = 1; if (!float.TryParse(DeZildrenAttributes.Value.Substring(0, DeZildrenAttributes.Value.IndexOf(',')), out Loc_x) || !float.TryParse(DeZildrenAttributes.Value.Substring(DeZildrenAttributes.Value.IndexOf(',') + 1), out Loc_y)) { //Error parsing DisplayMessageBox("Syntax error parsing the location of a button item"); } else { newDisplayButton.DeButtonLocation = new Point((int)Loc_x, (int)Loc_y); } break; #endregion #region Page of Button case "page": int newPage = -1; if (!int.TryParse(DeZildrenAttributes.Value, out newPage)) { DisplayMessageBox("Syntax error parsing the page of a button item"); } else { bool isUniquePage = true; foreach (int Pagita in newDisplayButton.DisplayPage) { if (Pagita == newPage) { isUniquePage = false; break; } } if (isUniquePage) { newDisplayButton.DisplayPage.Add(newPage); MaxPage(newPage); } } break; #endregion #region Text Style case "textprimary": newDisplayButton.TextPrimary.FontText = DeZildrenAttributes.Value; break; case "textsecondary": newDisplayButton.TextSecondary.FontText = DeZildrenAttributes.Value; break; case "textdisabled": newDisplayButton.TextDisabled.FontText = DeZildrenAttributes.Value; break; #endregion #region Text Colour case "colourprimaryargb": { char[] argb_split = { ',' }; string[] argb_string = DeZildrenAttributes.Value.Split(argb_split); int[] argb_int = new int[4]; for (int argb_i = 0; argb_i < 4; argb_i++) { int.TryParse(argb_string[argb_i], out argb_int[argb_i]); } newDisplayButton.TextPrimary.FontColour = Color.FromArgb(argb_int[0], argb_int[1], argb_int[2], argb_int[3]); } break; case "coloursecondaryargb": { char[] argb_split = { ',' }; string[] argb_string = DeZildrenAttributes.Value.Split(argb_split); int[] argb_int = new int[4]; for (int argb_i = 0; argb_i < 4; argb_i++) { int.TryParse(argb_string[argb_i], out argb_int[argb_i]); } newDisplayButton.TextSecondary.FontColour = Color.FromArgb(argb_int[0], argb_int[1], argb_int[2], argb_int[3]); } break; case "colourdisabledargb": { char[] argb_split = { ',' }; string[] argb_string = DeZildrenAttributes.Value.Split(argb_split); int[] argb_int = new int[4]; for (int argb_i = 0; argb_i < 4; argb_i++) { int.TryParse(argb_string[argb_i], out argb_int[argb_i]); } newDisplayButton.TextDisabled.FontColour = Color.FromArgb(argb_int[0], argb_int[1], argb_int[2], argb_int[3]); } break; #endregion #region Font Family and Size case "font": newDisplayButton.TextPrimary.FontName = DeZildrenAttributes.Value.ToLower(); newDisplayButton.TextSecondary.FontName = DeZildrenAttributes.Value.ToLower(); newDisplayButton.TextDisabled.FontName = DeZildrenAttributes.Value.ToLower(); break; case "font_size": { float temp_FontSize = 0.0f; if (float.TryParse(DeZildrenAttributes.Value, out temp_FontSize)) { newDisplayButton.TextPrimary.FontSize = temp_FontSize; newDisplayButton.TextSecondary.FontSize = temp_FontSize; newDisplayButton.TextDisabled.FontSize = temp_FontSize; } } break; #endregion #region Image Scaling - DEPRECIATED /* case "imageScaling": switch (DeZildrenAttributes.Value.ToLower()) { case "stretch": newDisplayButton.DeButtonsImageLayout = ImageLayout.Stretch; break; case "centre": newDisplayButton.DeButtonsImageLayout = ImageLayout.Center; break; case "zoom": newDisplayButton.DeButtonsImageLayout = ImageLayout.Zoom; break; case "tile": newDisplayButton.DeButtonsImageLayout = ImageLayout.Tile; break; default: newDisplayButton.DeButtonsImageLayout = ImageLayout.None; break; } break; */ #endregion #region Z-Order case "z_order": { if (!float.TryParse(DeZildrenAttributes.Value, out newDisplayButton.MDX_DisplayDepth)) { DisplayMessageBox("Syntax error parsing the depth of a display button item"); } } break; #endregion #region Up Click Options case "up_click_function": { newDisplayButton.upClick_Function = DeZildrenAttributes.Value.ToLower(); } break; case "up_click_functiontargetid": { newDisplayButton.upClick_FunctionTargetID = DeZildrenAttributes.Value.ToLower(); } break; case "up_click_vote_opinion": { newDisplayButton.upClick_VoteOpinion = DeZildrenAttributes.Value.ToLower(); ; } break; case "up_click_vote": { newDisplayButton.upClick_VoteType = DeZildrenAttributes.Value.ToLower(); } break; case "up_click_vote_priority": { switch (DeZildrenAttributes.Value.ToLower()) { case "low": newDisplayButton.upClick_VotePriority = Vote_Priority.LOW_PRIORITY; break; case "medium": newDisplayButton.upClick_VotePriority = Vote_Priority.MEDIUM_PRIORITY; break; case "high": newDisplayButton.upClick_VotePriority = Vote_Priority.HIGH_PRIORITY; break; default: break; } } break; #endregion #region Minimum Time Between Votes (Down) case "minimum_delta_vote_time_down": { if (!int.TryParse(DeZildrenAttributes.Value, out newDisplayButton.Time_MinDeltaDownVote)) { DisplayMessageBox("Syntax error parsing the minimum delta time vote (down) of a display button item"); } } break; #endregion #region Minimum Time Between Votes (Up) case "minimum_delta_vote_time_up": { if (!int.TryParse(DeZildrenAttributes.Value, out newDisplayButton.Time_MinDeltaUpVote)) { DisplayMessageBox("Syntax error parsing the minimum delta time vote (up) of a display button item"); } } break; #endregion #region Undefined or Error default: break; #endregion } } } if (newDisplayButton.id != null && newDisplayButton.functionString != null && newDisplayButton.functionTarget != null) { if (!newDisplayButton.TextPrimary.isCompletelySetup()) { newDisplayButton.TextPrimary = null; } if (!newDisplayButton.TextSecondary.isCompletelySetup()) { newDisplayButton.TextSecondary = null; } if (!newDisplayButton.TextDisabled.isCompletelySetup()) { newDisplayButton.TextDisabled = null; } if (newDisplayButton.upClick_Function == null || newDisplayButton.upClick_Function == "" || newDisplayButton.upClick_FunctionTargetID == null || newDisplayButton.upClick_FunctionTargetID == "" || newDisplayButton.upClick_VoteOpinion == null || newDisplayButton.upClick_VoteOpinion == "" || newDisplayButton.upClick_VoteType == null || newDisplayButton.upClick_VoteType == "") { newDisplayButton.upClick_Enable = false; } else { newDisplayButton.upClick_Enable = true; } AllDisplayButtons.Add(newDisplayButton); } else { DisplayMessageBox("There is a Display Button that does not meet the reqirements to be displayed", true); } } break; #endregion #region Multi Image Setup case "multiimage": { string MultiImage_id = ""; string MultiImage_monitor = ""; string MultiImage_monitorType = ""; foreach (XmlAttribute MultiImageMainAttributes in GraphicSubNode.Attributes) { switch (MultiImageMainAttributes.Name.ToLower()) { case "id": MultiImage_id = MultiImageMainAttributes.Value.ToLower(); break; case "monitorid": MultiImage_monitor = MultiImageMainAttributes.Value.ToLower(); break; case "monitortype": MultiImage_monitorType = MultiImageMainAttributes.Value.ToLower(); break; default: //Error or Unknown break; } } if (MultiImage_id != "" && MultiImage_monitor != "" && MultiImage_monitorType != "") { DisplayMultiImage newDisplayMultiImage = new DisplayMultiImage(MultiImage_id, MultiImage_monitor, MultiImage_monitorType); float multi_rotation = 0.0f; foreach (XmlNode MultiChildNode in GraphicSubNode.ChildNodes) { switch (MultiChildNode.Name.ToLower()) { #region Display Options case "display": foreach (XmlAttribute MultiChildAttribute in MultiChildNode.Attributes) { switch (MultiChildAttribute.Name.ToLower()) { #region Size of MultiImage case "size": int Size_x = 1; int Size_y = 1; if (!int.TryParse(MultiChildAttribute.Value.Substring(0, MultiChildAttribute.Value.IndexOf(',')), out Size_x) || !int.TryParse(MultiChildAttribute.Value.Substring(MultiChildAttribute.Value.IndexOf(',') + 1), out Size_y)) { //Error parsing DisplayMessageBox("Syntax error parsing the size of a multi image item"); } else { newDisplayMultiImage.DisplaySize = new Size(Size_x, Size_y); } break; #endregion #region Location of MultiImage case "location": float Loc_x = 1; float Loc_y = 1; if (!float.TryParse(MultiChildAttribute.Value.Substring(0, MultiChildAttribute.Value.IndexOf(',')), out Loc_x) || !float.TryParse(MultiChildAttribute.Value.Substring(MultiChildAttribute.Value.IndexOf(',') + 1), out Loc_y)) { //Error parsing DisplayMessageBox("Syntax error parsing the location of a multi image item"); } else { newDisplayMultiImage.DeButtonLocation = new Point((int)Loc_x, (int)Loc_y); } break; #endregion #region Page of MultiImage case "page": int newPage = -1; if (!int.TryParse(MultiChildAttribute.Value, out newPage)) { DisplayMessageBox("Syntax error parsing the page of a multi image item"); } else { bool isUniquePage = true; foreach (int Pagita in newDisplayMultiImage.DisplayPage) { if (Pagita == newPage) { isUniquePage = false; break; } } if (isUniquePage) { newDisplayMultiImage.DisplayPage.Add(newPage); MaxPage(newPage); } } break; #endregion #region Z-Order case "z_order": { if (!float.TryParse(MultiChildAttribute.Value, out newDisplayMultiImage.MDX_DisplayDepth)) { DisplayMessageBox("Syntax error parsing the depth of a Multi Image item"); } } break; #endregion #region Z-Order case "rotate": { if (!float.TryParse(MultiChildAttribute.Value, out multi_rotation)) { DisplayMessageBox("Syntax error parsing the depth of a Multi Image item"); } } break; #endregion #region Error Or Unknown default: //Error or Unknown break; #endregion } } break; #endregion #region Image Node case "image": DisplayButton newMultiImageButtonTemp = new DisplayButton(); foreach (XmlAttribute MultiChildAttribute in MultiChildNode.Attributes) { if (MultiChildAttribute.Name.ToLower() == "path") { try { newMultiImageButtonTemp.MDX_Primary = new FusionImage(LoadMyTexture(MDX_Device, MultiChildAttribute.Value), MDX_Device); } catch (FileNotFoundException) { DisplayMessageBox("A Multi Image's image does not exist where specified.", true); } } } foreach (XmlNode MultiChildNodeSubNode in MultiChildNode.ChildNodes) { if (MultiChildNodeSubNode.Name.ToLower() == "values") { foreach (XmlAttribute MultiImageSubSubAttribute in MultiChildNodeSubNode.Attributes) { switch (MultiImageSubSubAttribute.Name.ToLower()) { case "atleastorequalto": double.TryParse(MultiImageSubSubAttribute.Value, out newMultiImageButtonTemp.threshold_Low); break; case "atmost": double.TryParse(MultiImageSubSubAttribute.Value, out newMultiImageButtonTemp.threshold_High); break; case "rotate": float newMultiImageRotateAngle = 0.0f; float.TryParse(MultiImageSubSubAttribute.Value, out newMultiImageRotateAngle); newMultiImageButtonTemp.MDX_Primary.MDX_Rotation = float.Parse(DegreesToRadians(newMultiImageRotateAngle).ToString()); break; default: //Error or Unknown break; } } } } if (newMultiImageButtonTemp.threshold_Low <= newMultiImageButtonTemp.threshold_High && newMultiImageButtonTemp.threshold_High >= newMultiImageButtonTemp.threshold_Low && newMultiImageButtonTemp.MDX_Primary != null) { /* * TEMPORARILY DISABLED * * * newMultiImageButtonTemp.MDX_Primary.XNA_DepthToDraw = newDisplayMultiImage.XNA_Depth; */ newDisplayMultiImage.MultipleImageList.Add(newMultiImageButtonTemp); } break; #endregion #region Auto Image case "imageauto": string MultiImageAUTO_directoryname = ""; string MultiImageAUTO_filenamebase = ""; string MultiImageAUTO_filenameextension = ""; int MultiImageAUTO_filenamestart = 0; int MultiImageAUTO_filenameend = 0; double MultiImageAUTO_valuestart = 0.0; double MultiImageAUTO_valueend = 5.0; float MultiImageAUTO_rotateangle = 0.0f; foreach (XmlAttribute MultiImageAttributeAUTO in MultiChildNode.Attributes) { if (MultiImageAttributeAUTO.Name.ToLower() == "directory_path") { MultiImageAUTO_directoryname = MultiImageAttributeAUTO.Value; } } foreach (XmlNode MultiImageSubNodeAUTO in MultiChildNode.ChildNodes) { foreach (XmlAttribute MultiImageSubNodeAttributeAUTO in MultiImageSubNodeAUTO.Attributes) { switch (MultiImageSubNodeAttributeAUTO.Name.ToLower()) { case "filename_base": MultiImageAUTO_filenamebase = MultiImageSubNodeAttributeAUTO.Value; break; case "filename_start": int.TryParse(MultiImageSubNodeAttributeAUTO.Value, out MultiImageAUTO_filenamestart); break; case "filename_end": int.TryParse(MultiImageSubNodeAttributeAUTO.Value, out MultiImageAUTO_filenameend); break; case "filename_extension": MultiImageAUTO_filenameextension = MultiImageSubNodeAttributeAUTO.Value; break; case "value_start": double.TryParse(MultiImageSubNodeAttributeAUTO.Value, out MultiImageAUTO_valuestart); break; case "value_end": double.TryParse(MultiImageSubNodeAttributeAUTO.Value, out MultiImageAUTO_valueend); break; case "rotate": float.TryParse(MultiImageSubNodeAttributeAUTO.Value, out MultiImageAUTO_rotateangle); break; default: //Error or Unknown break; } } } if (Directory.Exists(MultiImageAUTO_directoryname)) { int temp_totalSteps = MultiImageAUTO_filenameend - MultiImageAUTO_filenamestart; double temp_totalDeltaValue = MultiImageAUTO_valueend - MultiImageAUTO_valuestart; for (int MultiImageAUTO_i = MultiImageAUTO_filenamestart; MultiImageAUTO_i <= MultiImageAUTO_filenameend; MultiImageAUTO_i++) { double temp_startValue = MultiImageAUTO_valuestart + ((MultiImageAUTO_i / (double)temp_totalSteps) * temp_totalDeltaValue); double temp_endValue = MultiImageAUTO_valuestart + (((MultiImageAUTO_i + 1) / (double)temp_totalSteps) * temp_totalDeltaValue); string MultiImageAUTO_tryImagePath = MultiImageAUTO_directoryname + "\\" + MultiImageAUTO_filenamebase + MultiImageAUTO_i.ToString() + "." + MultiImageAUTO_filenameextension; if (File.Exists(MultiImageAUTO_tryImagePath)) { DisplayButton newMultiDisplayButtonAUTO = new DisplayButton(); newMultiDisplayButtonAUTO.MDX_Primary = new FusionImage(LoadMyTexture(MDX_Device, MultiImageAUTO_tryImagePath), float.Parse(DegreesToRadians(MultiImageAUTO_rotateangle).ToString()), MDX_Device); newMultiDisplayButtonAUTO.threshold_Low = temp_startValue; newMultiDisplayButtonAUTO.threshold_High = temp_endValue; /* * TEMPORARILY DISABLED * * * newMultiDisplayButtonAUTO.MDX_Primary.XNA_DepthToDraw = newDisplayMultiImage.XNA_Depth; */ newDisplayMultiImage.MultipleImageList.Add(newMultiDisplayButtonAUTO); } else { DisplayMessageBox("File \"" + MultiImageAUTO_tryImagePath + "\" does not exist in directory \"" + MultiImageAUTO_directoryname + "\" as it is defined in a multiimage", true); return false; } } } else { DisplayMessageBox("Directory \"" + MultiImageAUTO_directoryname + "\" not found in application root and is needed as defined by a multiimage.", true); return false; } break; #endregion #region Options case "options": foreach (XmlAttribute OptionAttribute in MultiChildNode.Attributes) { switch (OptionAttribute.Name.ToLower()) { #region Image Scaling - DEPRECIATED /* case "imagescaling": switch (OptionAttribute.Value.ToLower()) { case "stretch": newDisplayMultiImage.DeButtonsImageLayout = ImageLayout.Stretch; break; case "centre": newDisplayMultiImage.DeButtonsImageLayout = ImageLayout.Center; break; case "zoom": newDisplayMultiImage.DeButtonsImageLayout = ImageLayout.Zoom; break; case "tile": newDisplayMultiImage.DeButtonsImageLayout = ImageLayout.Tile; break; default: newDisplayMultiImage.DeButtonsImageLayout = ImageLayout.None; break; } break; */ #endregion default: break; } } break; #endregion #region Error or Unknown default: break; #endregion } } if (newDisplayMultiImage.MDX_Primary != null) { newDisplayMultiImage.MDX_Primary.MDX_Rotation = multi_rotation; } AllDisplayMultiImages.Add(newDisplayMultiImage); } } break; #endregion #region Rotating Image Setup case "rotateimage": { string RotateImage_id = ""; string RotateImage_monitor = ""; string RotateImage_monitorType = ""; foreach (XmlAttribute RotateImageMainAttributes in GraphicSubNode.Attributes) { switch (RotateImageMainAttributes.Name.ToLower()) { case "id": RotateImage_id = RotateImageMainAttributes.Value.ToLower(); break; case "monitorid": RotateImage_monitor = RotateImageMainAttributes.Value.ToLower(); break; case "monitortype": RotateImage_monitorType = RotateImageMainAttributes.Value.ToLower(); break; default: //Error or Unknown break; } } if (RotateImage_id != "" && RotateImage_monitor != "" && RotateImage_monitorType != "") { DisplayRotateImageCentre newDisplayRotateImage = new DisplayRotateImageCentre(RotateImage_id, RotateImage_monitor, RotateImage_monitorType); foreach (XmlNode RotateChildNode in GraphicSubNode.ChildNodes) { switch (RotateChildNode.Name.ToLower()) { #region Display case "display": foreach (XmlAttribute RotateChildAttribute in RotateChildNode.Attributes) { switch (RotateChildAttribute.Name.ToLower()) { #region Size of Rotate Image case "size": int Size_x = 1; int Size_y = 1; if (!int.TryParse(RotateChildAttribute.Value.Substring(0, RotateChildAttribute.Value.IndexOf(',')), out Size_x) || !int.TryParse(RotateChildAttribute.Value.Substring(RotateChildAttribute.Value.IndexOf(',') + 1), out Size_y)) { //Error parsing DisplayMessageBox("Syntax error parsing the size of a multi image item"); } else { newDisplayRotateImage.DisplaySize = new Size(Size_x, Size_y); } break; #endregion #region Location of Rotate Image case "location": int Loc_x = 1; int Loc_y = 1; if (!int.TryParse(RotateChildAttribute.Value.Substring(0, RotateChildAttribute.Value.IndexOf(',')), out Loc_x) || !int.TryParse(RotateChildAttribute.Value.Substring(RotateChildAttribute.Value.IndexOf(',') + 1), out Loc_y)) { //Error parsing DisplayMessageBox("Syntax error parsing the location of a multi image item"); } else { newDisplayRotateImage.DeButtonLocation = new Point((int)Loc_x, (int)Loc_y); } break; #endregion #region Page of Rotate Image case "page": int newPage = -1; if (!int.TryParse(RotateChildAttribute.Value, out newPage)) { DisplayMessageBox("Syntax error parsing the page of a multi image item"); } else { bool isUniquePage = true; foreach (int Pagita in newDisplayRotateImage.DisplayPage) { if (Pagita == newPage) { isUniquePage = false; break; } } if (isUniquePage) { newDisplayRotateImage.DisplayPage.Add(newPage); MaxPage(newPage); } } break; #endregion #region Z-Order case "z_order": { if (!float.TryParse(RotateChildAttribute.Value, out newDisplayRotateImage.MDX_DisplayDepth)) { DisplayMessageBox("Syntax error parsing the depth of a Static Image item, will be set to 0.0f"); } } break; #endregion #region Error Or Unknown default: //Error or Unknown break; #endregion } } break; #endregion #region Option Settings case "options": foreach (XmlAttribute RotateChildAttribute in RotateChildNode.Attributes) { switch (RotateChildAttribute.Name.ToLower()) { #region Streak the Image case "streakimage": if (RotateChildAttribute.Value.ToLower() == "true") { newDisplayRotateImage.streakImage = true; } else if (RotateChildAttribute.Value.ToLower() == "false") { newDisplayRotateImage.streakImage = false; } break; #endregion #region Smooth the Image Rotation case "smoothimage": if (RotateChildAttribute.Value.ToLower() == "true") { newDisplayRotateImage.smoothRotating = true; } else if (RotateChildAttribute.Value.ToLower() == "false") { newDisplayRotateImage.smoothRotating = false; } break; #endregion #region Smooth the Image Rotation case "smoothmaximumangledifference": if (!double.TryParse(RotateChildAttribute.Value, out newDisplayRotateImage.maximumAngleStride)) { DisplayMessageBox("Rotating Image Maximum Smoothing Image Parse Error", true); } break; #endregion #region Image Scaling - DEPRECIATED /* case "imageScaling": switch (RotateChildAttribute.Value.ToLower()) { case "stretch": newDisplayRotateImage.DeButtonsImageLayout = ImageLayout.Stretch; break; case "centre": newDisplayRotateImage.DeButtonsImageLayout = ImageLayout.Center; break; case "zoom": newDisplayRotateImage.DeButtonsImageLayout = ImageLayout.Zoom; break; case "tile": newDisplayRotateImage.DeButtonsImageLayout = ImageLayout.Tile; break; default: newDisplayRotateImage.DeButtonsImageLayout = ImageLayout.None; break; } break; */ #endregion #region Error Or Unknown default: //Error or Unknown break; #endregion } } break; #endregion #region Image case "image": foreach (XmlAttribute RotateChildAttribute in RotateChildNode.Attributes) { #region Rotate Image Path if (RotateChildAttribute.Name.ToLower() == "path") { try { newDisplayRotateImage.MDX_Primary = new FusionImage(LoadMyTexture(MDX_Device, RotateChildAttribute.Value), MDX_Device); } catch (FileNotFoundException) { DisplayMessageBox("A Rotate Image's image does not exist where specified.", true); return false; } } #endregion } break; #endregion #region Values case "values": DisplayRotateImageCentre.DisplayRotateImageValues newRotateValues = new DisplayRotateImageCentre.DisplayRotateImageValues(); foreach (XmlAttribute RotateChildAttribute in RotateChildNode.Attributes) { switch (RotateChildAttribute.Name.ToLower()) { #region Minimum Angle for New Setting case "angleminimum": if (!double.TryParse(RotateChildAttribute.Value, out newRotateValues.angle_minimum)) { DisplayMessageBox("Error Reading Minimum Angle for a Rotate Image", true); } break; #endregion #region Maximum Angle for New Setting case "anglemaximum": if (!double.TryParse(RotateChildAttribute.Value, out newRotateValues.angle_maximum)) { DisplayMessageBox("Error Reading Maximum Angle for a Rotate Image", true); } break; #endregion #region Minimum Value for New Setting case "valueminimum": if (!double.TryParse(RotateChildAttribute.Value, out newRotateValues.value_minimum)) { DisplayMessageBox("Error Reading Minimum Value for a Rotate Image", true); } break; #endregion #region Maximum Value for New Setting case "valuemaximum": if (!double.TryParse(RotateChildAttribute.Value, out newRotateValues.value_maximum)) { DisplayMessageBox("Error Reading Maximum Value for a Rotate Image", true); } break; #endregion #region Error or Unknown in New Setting default: //Error Or Unknown break; #endregion } } if (newRotateValues.value_minimum <= newRotateValues.value_maximum && newRotateValues.angle_minimum <= newRotateValues.angle_maximum) { newDisplayRotateImage.MultipleAngleList.Add(newRotateValues); } break; #endregion #region Unknown or Error default: break; #endregion } } /* * TEMPORARILY DISABLED... * * newDisplayRotateImage.MDX_Primary.XNA_DepthToDraw = newDisplayRotateImage.XNA_Depth; */ AllDisplayRotateImage.Add(newDisplayRotateImage); } } break; #endregion #region Static Image case "staticimage": { DisplayStaticImage newStaticImage = new DisplayStaticImage(); foreach (XmlNode DeZildrenOfDeStatic in GraphicSubNode.ChildNodes) { foreach (XmlAttribute DeZildrenAttributes in DeZildrenOfDeStatic.Attributes) { switch (DeZildrenAttributes.Name.ToLower()) { #region Static Image case "path": try { newStaticImage.MDX_StaticImage = new FusionImage(LoadMyTexture(MDX_Device, DeZildrenAttributes.Value), MDX_Device); } catch (FileNotFoundException) { DisplayMessageBox("A Static Image's image does not exist where specified.", true); } break; #endregion #region Size of Button case "size": int Size_x = 1; int Size_y = 1; if (!int.TryParse(DeZildrenAttributes.Value.Substring(0, DeZildrenAttributes.Value.IndexOf(',')), out Size_x) || !int.TryParse(DeZildrenAttributes.Value.Substring(DeZildrenAttributes.Value.IndexOf(',') + 1), out Size_y)) { //Error parsing DisplayMessageBox("Syntax error parsing the size of a Static Image item"); } else { newStaticImage.DisplaySize = new Size(Size_x, Size_y); } break; #endregion #region Location of Button case "location": float Loc_x = 1.0f; float Loc_y = 1.0f; if (!float.TryParse(DeZildrenAttributes.Value.Substring(0, DeZildrenAttributes.Value.IndexOf(',')), out Loc_x) || !float.TryParse(DeZildrenAttributes.Value.Substring(DeZildrenAttributes.Value.IndexOf(',') + 1), out Loc_y)) { //Error parsing DisplayMessageBox("Syntax error parsing the location of a button item"); } else { newStaticImage.DisplayLocation = new Point((int)Loc_x, (int)Loc_y); } break; #endregion #region Page of Button case "page": int newPage = -1; if (!int.TryParse(DeZildrenAttributes.Value, out newPage)) { DisplayMessageBox("Syntax error parsing the page of a Static Image item"); } else { bool isUniquePage = true; foreach (int Pagita in newStaticImage.DisplayPages) { if (Pagita == newPage) { isUniquePage = false; break; } } if (isUniquePage) { newStaticImage.DisplayPages.Add(newPage); MaxPage(newPage); } } break; #endregion #region Z-Order case "z_order": { if (!float.TryParse(DeZildrenAttributes.Value, out newStaticImage.MDX_DisplayDepth)) { DisplayMessageBox("Syntax error parsing the depth of a Static Image item"); } } break; #endregion #region Undefined or Error default: break; #endregion } } } if (newStaticImage.MDX_StaticImage != null && newStaticImage.DisplayPages.Count > 0) { AllStaticImages.Add(newStaticImage); } } break; #endregion #region Fusion Graph case "graph": { string name = ""; string timer = "logic timer"; int width = -1, height = -1, x = -1, y = -1; List pages = new List(); float z_order = 0.0f; float value_min = 0, value_max = 0; int time_min = 0, time_max = 0; int lineWidth = 1; Color colour = Color.Black; Axis axis = Axis.HORIZONTAL; string targetType = "", targetID = ""; bool smooth = false, fwdBias = false; int smoothNumbers = 10; foreach (XmlAttribute _at in GraphicSubNode.Attributes) { if (_at.Name.ToLower() == "id") { name = _at.Value; } } foreach (XmlNode DeZildrenOfDeVariableLocation in GraphicSubNode.ChildNodes) { foreach (XmlAttribute DeZildrenAttributes in DeZildrenOfDeVariableLocation.Attributes) { switch (DeZildrenAttributes.Name.ToLower()) { #region Size of Variable Location Image case "size": if (!int.TryParse(DeZildrenAttributes.Value.Substring(0, DeZildrenAttributes.Value.IndexOf(',')), out width) || !int.TryParse(DeZildrenAttributes.Value.Substring(DeZildrenAttributes.Value.IndexOf(',') + 1), out height)) { //Error parsing DisplayMessageBox("Syntax error parsing the size of a Variable Location Image item"); } break; #endregion #region Location of Variable Location Image case "location": float Loc_x = 1.0f; float Loc_y = 1.0f; if (!float.TryParse(DeZildrenAttributes.Value.Substring(0, DeZildrenAttributes.Value.IndexOf(',')), out Loc_x) || !float.TryParse(DeZildrenAttributes.Value.Substring(DeZildrenAttributes.Value.IndexOf(',') + 1), out Loc_y)) { //Error parsing DisplayMessageBox("Syntax error parsing the location of a Variable Location image item"); } else { x = (int)Loc_x; y = (int)Loc_y; } break; #endregion #region Page of Graph case "page": int newPage = -1; if (!int.TryParse(DeZildrenAttributes.Value, out newPage)) { DisplayMessageBox("Syntax error parsing the page of a Variable Location Image item"); } else { bool isUniquePage = true; foreach (int Pagita in pages) { if (Pagita == newPage) { isUniquePage = false; break; } } if (isUniquePage) { pages.Add(newPage); MaxPage(newPage); } } break; #endregion #region Z-Order case "z_order": { if (!float.TryParse(DeZildrenAttributes.Value, out z_order)) { DisplayMessageBox("Syntax error parsing the depth of a Variable Location Image item"); } } break; #endregion #region Line Width case "line_width": { if (!int.TryParse(DeZildrenAttributes.Value, out lineWidth)) { DisplayMessageBox("Syntax error parsing the depth of a Variable Location Image item"); } } break; #endregion #region Line Colour case "line_colour": { char[] argb_split = { ',' }; string[] argb_string = DeZildrenAttributes.Value.Split(argb_split); int[] argb_int = new int[4]; for (int argb_i = 0; argb_i < 4; argb_i++) { int.TryParse(argb_string[argb_i], out argb_int[argb_i]); } colour = Color.FromArgb(argb_int[0], argb_int[1], argb_int[2], argb_int[3]); } break; #endregion #region Timer case "timer": { switch (DeZildrenAttributes.Value.ToLower().ToCharArray()[0]) { case 'l': timer = "Logic Timer"; break; case 'i': timer = "Input Timer"; break; case 'o': timer = "Output Timer"; break; case 'g': timer = "Gui Timer"; break; } } break; #endregion #region Variable Location Image Value Range case "value_minimum": { if (!float.TryParse(DeZildrenAttributes.Value, out value_min)) { DisplayMessageBox("Syntax error parsing the minimum value of a Variable Location Image item"); } } break; case "value_maximum": { if (!float.TryParse(DeZildrenAttributes.Value, out value_max)) { DisplayMessageBox("Syntax error parsing the maximum value of a Variable Location Image item"); } } break; #endregion #region Variable Location Image Location Range case "time_minimum": { if (!int.TryParse(DeZildrenAttributes.Value, out time_min)) { DisplayMessageBox("Syntax error parsing the minimum location of a Variable Location Image item"); } } break; case "time_maximum": { if (!int.TryParse(DeZildrenAttributes.Value, out time_max)) { DisplayMessageBox("Syntax error parsing the maximum location of a Variable Location Image item"); } } break; #endregion #region Variable Location Image Translate Axis case "axis": { switch (DeZildrenAttributes.Value.ToLower()) { case "horizontal": axis = Axis.HORIZONTAL; break; case "vertical": axis = Axis.VERTICAL; break; default: DisplayMessageBox("Syntax error parsing the translate axis of a Variable Location Image item"); break; } } break; #endregion #region Variable Location Target Type case "target_type": { targetType = DeZildrenAttributes.Value; } break; #endregion #region Variable Location Target ID case "target_id": { targetID = DeZildrenAttributes.Value; } break; #endregion #region Smoothing case "smooth_enabled": { smooth = (DeZildrenAttributes.Value.ToLower() == "true"); } break; case "smooth_forwardbias": { fwdBias = (DeZildrenAttributes.Value.ToLower() == "true"); } break; case "smooth_number": { int.TryParse(DeZildrenAttributes.Value, out smoothNumbers); } break; #endregion #region Undefined or Error default: break; #endregion } } } if (pages.Count > 0 && width > 0 && height > 0 && x >= 0 && y >= 0 && name != "" && targetID != "" && targetType != "" && value_min < value_max && time_min < time_max) { DisplayFusionGraph tempGPH = new DisplayFusionGraph(); tempGPH.MDX_StaticImage = new FusionImage(MDX_Device, true); tempGPH.id = name; tempGPH.DisplaySize = new Size(width, height); tempGPH.DisplayPages = new List(pages.ToArray()); tempGPH.DisplayLocation = new Point(x, y); tempGPH.MDX_DisplayDepth = z_order; // tempGPH.time_minimum = time_min; tempGPH.time_maximum = time_max; tempGPH.value_minimum = value_min; tempGPH.value_maximum = value_max; tempGPH.target = targetType; tempGPH.targetID = targetID; tempGPH.graphingAxis = axis; tempGPH.lineThickness = lineWidth; tempGPH.lineColour = colour; tempGPH.timer = timer; tempGPH.smooth = smooth; tempGPH.smoothNumbers = smoothNumbers; tempGPH.forwardBiasNotReverseBias = fwdBias; AllGraphs.Add(tempGPH); } else { DisplayMessageBox("A graph instance does not meet requirements to be displayed, it will be skipped"); } } break; #endregion #region Variable Location Image case "variable_location_image": { //string path = ""; //Bitmap image = null; int width = -1, height = -1, x = -1, y = -1; List pages = new List(); float z_order = 0.0f; float value_min = 0, value_max = 0; int location_min = 0, location_max = 0; Axis axis = Axis.HORIZONTAL; string targetType = "", targetID = ""; DisplayVariableLocationImage newVariableLocationImage = new DisplayVariableLocationImage(); foreach (XmlNode DeZildrenOfDeVariableLocation in GraphicSubNode.ChildNodes) { foreach (XmlAttribute DeZildrenAttributes in DeZildrenOfDeVariableLocation.Attributes) { switch (DeZildrenAttributes.Name.ToLower()) { #region Variable Location Image case "path": try { newVariableLocationImage.MDX_StaticImage = new FusionImage(LoadMyTexture(MDX_Device, DeZildrenAttributes.Value), MDX_Device); } catch (FileNotFoundException) { DisplayMessageBox("A Variable Location Image's image does not exist where specified.", true); } break; #endregion #region Size of Variable Location Image case "size": if (!int.TryParse(DeZildrenAttributes.Value.Substring(0, DeZildrenAttributes.Value.IndexOf(',')), out width) || !int.TryParse(DeZildrenAttributes.Value.Substring(DeZildrenAttributes.Value.IndexOf(',') + 1), out height)) { //Error parsing DisplayMessageBox("Syntax error parsing the size of a Variable Location Image item"); } break; #endregion #region Location of Variable Location Image case "location": float Loc_x = 1.0f; float Loc_y = 1.0f; if (!float.TryParse(DeZildrenAttributes.Value.Substring(0, DeZildrenAttributes.Value.IndexOf(',')), out Loc_x) || !float.TryParse(DeZildrenAttributes.Value.Substring(DeZildrenAttributes.Value.IndexOf(',') + 1), out Loc_y)) { //Error parsing DisplayMessageBox("Syntax error parsing the location of a Variable Location image item"); } else { x = (int)Loc_x; y = (int)Loc_y; } break; #endregion #region Page of Button case "page": int newPage = -1; if (!int.TryParse(DeZildrenAttributes.Value, out newPage)) { DisplayMessageBox("Syntax error parsing the page of a Variable Location Image item"); } else { bool isUniquePage = true; foreach (int Pagita in pages) { if (Pagita == newPage) { isUniquePage = false; break; } } if (isUniquePage) { pages.Add(newPage); MaxPage(newPage); } } break; #endregion #region Z-Order case "z_order": { if (!float.TryParse(DeZildrenAttributes.Value, out z_order)) { DisplayMessageBox("Syntax error parsing the depth of a Variable Location Image item"); } } break; #endregion #region Variable Location Image Value Range case "value_minimum": { if (!float.TryParse(DeZildrenAttributes.Value, out value_min)) { DisplayMessageBox("Syntax error parsing the minimum value of a Variable Location Image item"); } } break; case "value_maximum": { if (!float.TryParse(DeZildrenAttributes.Value, out value_max)) { DisplayMessageBox("Syntax error parsing the maximum value of a Variable Location Image item"); } } break; #endregion #region Variable Location Image Location Range case "location_minimum": { if (!int.TryParse(DeZildrenAttributes.Value, out location_min)) { DisplayMessageBox("Syntax error parsing the minimum location of a Variable Location Image item"); } } break; case "location_maximum": { if (!int.TryParse(DeZildrenAttributes.Value, out location_max)) { DisplayMessageBox("Syntax error parsing the maximum location of a Variable Location Image item"); } } break; #endregion #region Variable Location Image Translate Axis case "axis": { switch (DeZildrenAttributes.Value.ToLower()) { case "horizontal": axis = Axis.HORIZONTAL; break; case "vertical": axis = Axis.VERTICAL; break; default: DisplayMessageBox("Syntax error parsing the translate axis of a Variable Location Image item"); break; } } break; #endregion #region Variable Location Target Type case "target_type": { targetType = DeZildrenAttributes.Value; } break; #endregion #region Variable Location Target ID case "target_id": { targetID = DeZildrenAttributes.Value; } break; #endregion #region Undefined or Error default: break; #endregion } } } if (newVariableLocationImage.MDX_StaticImage != null && pages.Count > 0 && width > 0 && height > 0 && x >= 0 && y >= 0 && targetID != "" && targetType != "" && value_min < value_max && location_min < location_max) { newVariableLocationImage.DisplaySize = new Size(width, height); newVariableLocationImage.DisplayPages = new List(pages.ToArray()); newVariableLocationImage.DisplayLocation = new Point(x, y); newVariableLocationImage.MDX_DisplayDepth = z_order; newVariableLocationImage.location_minimum = location_min; newVariableLocationImage.location_maximum = location_max; newVariableLocationImage.value_minimum = value_min; newVariableLocationImage.value_maximum = value_max; newVariableLocationImage.target = targetType; newVariableLocationImage.targetID = targetID; newVariableLocationImage.translateAround = axis; AllStaticVariableLocationImages.Add(newVariableLocationImage); } else { DisplayMessageBox("A variable location image does not meet requirements to be displayed, it will be skipped"); } } break; #endregion #region Text Label case "text_label": { string _textLabel_ID = ""; string _textLabel_AutoMonitorType = ""; string _textLabel_AutoMonitorID = ""; string _textLabel_Text = ""; foreach (XmlAttribute _txtAttribute in GraphicSubNode.Attributes) { switch (_txtAttribute.Name.ToLower()) { case "id": _textLabel_ID = _txtAttribute.Value.ToLower(); break; case "auto_monitor": _textLabel_AutoMonitorType = _txtAttribute.Value.ToLower(); break; case "auto_monitortarget": _textLabel_AutoMonitorID = _txtAttribute.Value.ToLower(); break; case "text": _textLabel_Text = _txtAttribute.Value; break; default: break; } } DisplayTextLabelAuto _tempDisplayTextLabelAuto = new DisplayTextLabelAuto(_textLabel_ID, _textLabel_AutoMonitorType, _textLabel_AutoMonitorID, _textLabel_Text); if (_tempDisplayTextLabelAuto.id == "" || _tempDisplayTextLabelAuto.monitor_id == "" || _tempDisplayTextLabelAuto.monitor_type == "") { //continue; } foreach (XmlNode _nodeAutoText in GraphicSubNode.ChildNodes) { foreach (XmlAttribute _nodeAutoTextAttribute in _nodeAutoText.Attributes) { switch (_nodeAutoTextAttribute.Name.ToLower()) { case "font_id": _tempDisplayTextLabelAuto.FontName = _nodeAutoTextAttribute.Value.ToLower(); break; case "font_size": float.TryParse(_nodeAutoTextAttribute.Value.ToLower(), out _tempDisplayTextLabelAuto.FontSize); break; case "colour": { char[] argb_split = { ',' }; string[] argb_string = _nodeAutoTextAttribute.Value.Split(argb_split); int[] argb_int = new int[4]; for (int argb_i = 0; argb_i < 4; argb_i++) { int.TryParse(argb_string[argb_i], out argb_int[argb_i]); } _tempDisplayTextLabelAuto.FontColour = Color.FromArgb(argb_int[0], argb_int[1], argb_int[2], argb_int[3]); } break; case "location": { string[] _locSArray = _nodeAutoTextAttribute.Value.ToLower().Split(new char[] { ',' }); if (_locSArray.Length == 2) { int _tempX = 0, _tempY = 0; if (int.TryParse(_locSArray[0], out _tempX) && int.TryParse(_locSArray[1], out _tempY)) { _tempDisplayTextLabelAuto.LabelLocation = new Point(_tempX, _tempY); } } } break; case "page": { int _tempPageInt = 0; int.TryParse(_nodeAutoTextAttribute.Value, out _tempPageInt); bool _tempPage_isUnique = true; foreach (int _tempPageCheck in _tempDisplayTextLabelAuto.pageList) { if (_tempPageInt == _tempPageCheck) { _tempPage_isUnique = false; break; } } if (_tempPage_isUnique) { _tempDisplayTextLabelAuto.pageList.Add(_tempPageInt); MaxPage(_tempPageInt); } } break; case "decimals": { int _tempDecInt = 1; int.TryParse(_nodeAutoTextAttribute.Value, out _tempDecInt); _tempDisplayTextLabelAuto.LabelDecimalPrecision = _tempDecInt; } break; case "max_size": { string[] _maxSArray = _nodeAutoTextAttribute.Value.ToLower().Split(new char[] { ',' }); if (_maxSArray.Length == 2) { int _tempX = 0, _tempY = 0; if (int.TryParse(_maxSArray[0], out _tempX) && int.TryParse(_maxSArray[1], out _tempY)) { _tempDisplayTextLabelAuto.LabelMaxSize = new Point(_tempX, _tempY); } } } break; default: break; } } } _tempDisplayTextLabelAuto.LabelBounds = new Vector4(_tempDisplayTextLabelAuto.LabelLocation.X, _tempDisplayTextLabelAuto.LabelLocation.Y, _tempDisplayTextLabelAuto.LabelLocation.X + _tempDisplayTextLabelAuto.LabelMaxSize.X, _tempDisplayTextLabelAuto.LabelLocation.Y + _tempDisplayTextLabelAuto.LabelMaxSize.Y); AllTextLabels.Add(_tempDisplayTextLabelAuto); } break; #endregion #region Error or Undefined Value default: //Not recognized as a type... break; #endregion } } } #endregion #region I/O Setup else if (subTopConfigNode.Name.ToLower() == "io") { //Setup of Brain Instances and I/O Channels XmlNodeList IONodes = subTopConfigNode.ChildNodes; foreach (XmlNode ioConfigNode in IONodes) { #region Configure Attached Brains if (ioConfigNode.Name.ToLower() == "brain") { string instanceread = ""; string humanNameread = ""; string analogue_input_accuracy_index_reference_name = ""; string version_to_be = ""; foreach (XmlAttribute idNode in ioConfigNode.Attributes) { if (idNode.Name.ToLower() == "id") { humanNameread = idNode.Value.ToLower(); } else if (idNode.Name.ToLower() == "version") { version_to_be = idNode.Value.ToLower(); } else if (idNode.Name.ToLower() == "analogue_reference") { analogue_input_accuracy_index_reference_name = idNode.Value.ToLower(); } } if (humanNameread == "") { DisplayMessageBox("Error in Brain ID specified in configuration file"); return false; } if (ioConfigNode.FirstChild == null) { DisplayMessageBox("Error in USB Instance ID declaration of Fusion Brain \"" + humanNameread + "\" in configuration file"); return false; } instanceread = ioConfigNode.FirstChild.Value.ToLower(); BrainID newBrain = new BrainID(); newBrain.humanName = humanNameread; newBrain.instanceID = instanceread; //newBrain.version_string_supposed_to_be = version_to_be; if (version_to_be == "4") { newBrain.InitializeVersion(BrainVersion.Version_04); } else { newBrain.InitializeVersion(BrainVersion.Version_03); } newBrain.Accurate_AnalogueScalingInput_Index_ReferenceID = analogue_input_accuracy_index_reference_name; bool isUnique = true; for (int brain_i = 0; brain_i < AllBrains.Count; brain_i++) { if (AllBrains[brain_i].humanName == newBrain.humanName) { isUnique = false; break; } } if (isUnique) { AllBrains.Add(newBrain); } } #endregion #region Configure Timers else if (ioConfigNode.Name.ToLower() == "timer") { int newInterval = -1; foreach (XmlAttribute timerIntervalAttribute in ioConfigNode.Attributes) { if (timerIntervalAttribute.Name.ToLower() == "interval") { int.TryParse(timerIntervalAttribute.Value, out newInterval); break; } } if (newInterval == -1) { DisplayMessageBox("A timer declaration has no interval value, it will be skipped and set to defaults"); continue; } foreach (XmlAttribute timerAttribute in ioConfigNode.Attributes) { if (timerAttribute.Name.ToLower() == "id") { switch (timerAttribute.Value.ToLower()) { case "logic": LogicTimer.Interval = newInterval; THREAD_LOGIC_SLEEP_INTERVAL = newInterval; break; case "gui": GUI_Timer.Interval = newInterval; break; case "output": //OutputTimer.Interval = newInterval; //break; case "input": //InputTimer.Interval = newInterval; //break; case "io": IO_Timer.Interval = newInterval; THREAD_IO_SLEEP_INTERVAL = newInterval; break; default: break; } } } } #endregion #region Configure I/O Channels else if (ioConfigNode.Name.ToLower() == "iochannel") { string read_string_port = ""; string read_string_brain = ""; string read_string_id = ""; string read_string_type = ""; int read_int_port; #region Read In and Verify Required Settings foreach (XmlAttribute newChannelAttribute in ioConfigNode.Attributes) { if (newChannelAttribute.Name.ToLower() == "id") { read_string_id = newChannelAttribute.Value.ToLower(); } else if (newChannelAttribute.Name.ToLower() == "port") { read_string_port = newChannelAttribute.Value.ToLower(); } else if (newChannelAttribute.Name.ToLower() == "brain") { read_string_brain = newChannelAttribute.Value.ToLower(); } else if (newChannelAttribute.Name.ToLower() == "type") { read_string_type = newChannelAttribute.Value.ToLower(); } } if (read_string_brain == "" || read_string_id == "" || read_string_port == "" || read_string_type == "") { //Minimum channel requirements not met... DisplayMessageBox("There is an error in a I/O Channel declaration.\r\n" + "Every I/O Channel must have a Brain, ID, Port, and Type"); continue; } if (!int.TryParse(read_string_port, out read_int_port)) { DisplayMessageBox("Invalid Port in a I/O Channel in the configuration channel\r\n" + "I/O Channel ID: " + read_string_id); continue; } #endregion switch (read_string_type) { #region Digital Output Configuration case "digital_output": DigitalOutputChannel Temp_DOC = new DigitalOutputChannel(read_string_brain, read_string_id, read_int_port); /* * Extra Digital Output Only Options */ foreach (XmlNode doChildren in ioConfigNode.ChildNodes) { foreach (XmlAttribute ioAttributes in doChildren.Attributes) { switch (ioAttributes.Name.ToLower()) { #region The On/Off State of the Output on Program Start case "defaultstate": if (ioAttributes.Value.ToLower() == "on") { Temp_DOC.CurrentState = true; } else if (ioAttributes.Value.ToLower() == "off") { Temp_DOC.CurrentState = false; } break; #endregion #region Errors or Unknown default: break; #endregion } } } AllDigitalOutputs.Add(Temp_DOC); break; #endregion #region Analogue Input Configuration case "analogue_input": AnalogueInputChannel Temp_AIC = new AnalogueInputChannel(read_string_brain, read_string_id, read_int_port); /* * Extra Analogue Input Only Options */ foreach (XmlNode doChildren in ioConfigNode.ChildNodes) { foreach (XmlAttribute ioAttributes in doChildren.Attributes) { switch (ioAttributes.Name.ToLower()) { #region Maximum History Points To Store case "history": int newHistory = 200; if (!int.TryParse(ioAttributes.Value, out newHistory)) { DisplayMessageBox("Error Parsing Analogue History Value"); } Temp_AIC.maximumHistory = newHistory; break; #endregion #region Current Value is Actual or Averaged case "auto_average": if (ioAttributes.Value.ToLower() == "true") { Temp_AIC.autoAverage = true; } else if (ioAttributes.Value.ToLower() == "false") { Temp_AIC.autoAverage = false; } break; #endregion #region Errors or Unknown default: break; #endregion } } } AllAnalogueInputs.Add(Temp_AIC); break; #endregion #region Digital Input Configuration case "digital_input": DigitalInputChannel Temp_DIC = new DigitalInputChannel(read_string_brain, read_string_id, read_int_port); /* * Extra Digital Input Only Options */ AllDigitalInputs.Add(Temp_DIC); break; #endregion #region Error in Type default: DisplayMessageBox("I/O Channel is of an invalid type.\r\n" + "I/O Channel ID: " + read_string_id); return false; #endregion } } #endregion } } #endregion #region Logic else if (subTopConfigNode.Name.ToLower() == "logic") { //Setup of Logic area foreach (XmlNode logicTopNode in subTopConfigNode.ChildNodes) { #region Variables if (logicTopNode.Name.ToLower() == "all_variables") { foreach (XmlNode variableNode in logicTopNode) { if (variableNode.Name.ToLower() == "variable") { if (variableNode.FirstChild == null) { DisplayMessageBox("Error in a variable declaration in the configuration file.\r\n" + "Variables here must have an intial value. To make a variable with no startup" + "value, just include it in the logic area", true); return false; } else { object read_initial_value = null; double read_initial_value_double = 0.0; bool read_initial_value_bool = false; string read_name = ""; if (double.TryParse(variableNode.FirstChild.Value, out read_initial_value_double)) { read_initial_value = read_initial_value_double; } else if (bool.TryParse(variableNode.FirstChild.Value, out read_initial_value_bool)) { read_initial_value = read_initial_value_bool; } else { DisplayMessageBox("Error in a variable declaration in the configuration file.\r\n" + "Variable must have an intial value."); return false; } foreach (XmlAttribute variableAttribute in variableNode.Attributes) { if (variableAttribute.Name.ToLower() == "name") { read_name = variableAttribute.Value.ToLower(); } } if (read_name == "") { DisplayMessageBox("Error in a variable declaration in the configuration file.\r\n" + "Variable must have an name to reference it by."); return false; } bool isUnique = true; for (int variable_i = 0; variable_i < AllVariables.Count; variable_i++) { if (AllVariables[variable_i].variableReferenceName == read_name) { isUnique = false; break; } } if (isUnique) { AllVariables.Add(new Variable(read_name, read_initial_value)); } } } } } #endregion #region Logs else if (logicTopNode.Name.ToLower() == "all_logging") { foreach (XmlNode logNode in logicTopNode) { if (logNode.Name.ToLower() == "log") { string temp_logID = ""; string temp_logMonitorType = ""; string temp_logMonitorID = ""; string temp_logFireOn = "logic"; foreach (XmlAttribute logAttribute in logNode.Attributes) { if (logAttribute.Name.ToLower() == "logid") { temp_logID = logAttribute.Value.ToLower(); foreach (LogClass test_LogClass in AllLogClasses) { if (temp_logID == test_LogClass.logReferenceName) { DisplayMessageBox("Another Log has the same ID", true); } } } else if (logAttribute.Name.ToLower() == "monitortype") { temp_logMonitorType = logAttribute.Value.ToLower(); } else if (logAttribute.Name.ToLower() == "targetid") { temp_logMonitorID = logAttribute.Value.ToLower(); } else if (logAttribute.Name.ToLower() == "fire_on") { temp_logFireOn = logAttribute.Value.ToLower(); } } if (temp_logID != "" && temp_logMonitorID != "" && temp_logMonitorType != "") { LogClass temp_LogClass = new LogClass(temp_logID, temp_logMonitorID, temp_logMonitorType, temp_logFireOn); foreach (XmlNode logChildNode in logNode.ChildNodes) { foreach (XmlAttribute logChildAttribute in logChildNode.Attributes) { switch (logChildAttribute.Name.ToLower()) { case "defaultmonitorstate": if (logChildAttribute.Value.ToLower() == "on") { temp_LogClass.monitorState = true; } break; case "filename": temp_LogClass.saveToFile = logChildAttribute.Value; break; case "dataname": temp_LogClass.dataName = logChildAttribute.Value; break; case "datafrom": temp_LogClass.dataFrom = logChildAttribute.Value.ToLower(); break; case "holdstreamopen": if (logChildAttribute.Value.ToLower() == "true") { temp_LogClass.HoldingAStreamOpen = true; } break; case "storebeforedumping": int.TryParse(logChildAttribute.Value, out temp_LogClass.NumberToLogBeforeDumping); break; default: //Error or Unknown break; } } } if (temp_LogClass.HoldingAStreamOpen) { try { bool makeMeAFile = !File.Exists(temp_LogClass.saveToFile + ".xml"); if (!makeMeAFile) { LogFileStream temp_LogFileStream = new LogFileStream(temp_LogClass.saveToFile); string testReadInString = temp_LogFileStream.CurrentData; if (!testReadInString.StartsWith("\r\n")) { if (MessageBox.Show("The file at \"" + temp_LogClass.saveToFile + ".xml\" is set to be used as a log dumping file.\r\n" + "The program has determined the file is invalid as it is currently to append to because it does not" + "start with the correct XML encoding rule and/or root node. The file will be overwritten and all" + "previous data will be lost. Click \"OK\" to continue, cancel to exit the application", "WARNING", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Cancel) { //Cancel the operation, Close the Program CloseAllOpenLogStreams(); DisplayMessageBox("Press OK, to terminate the program", true); } else { File.Delete(temp_LogClass.saveToFile + ".xml"); makeMeAFile = true; } } else { AllLogFileStreams.Add(temp_LogFileStream); temp_LogClass.StreamIndex = AllLogFileStreams.Count - 1; } } if (makeMeAFile) { string temp_LogXMLString = "\r\n\r\n"; if (temp_LogClass.saveToFile.Contains("\\")) { string temp_Directory = temp_LogClass.saveToFile.Substring(0, temp_LogClass.saveToFile.LastIndexOf('\\')); Directory.CreateDirectory(temp_Directory); } File.Create(temp_LogClass.saveToFile + ".xml").Close(); LogFileStream temp_LogFileStream = new LogFileStream(temp_LogClass.saveToFile); AllLogFileStreams.Add(temp_LogFileStream); temp_LogClass.StreamIndex = AllLogFileStreams.Count - 1; temp_LogFileStream.CurrentData = temp_LogXMLString; } } catch (Exception) { } } AllLogClasses.Add(temp_LogClass); } else { //Not enough Log info DisplayMessageBox("Error in Log section. Every Log must contain and ID, a monitor type, and taget ID at a minimum"); } } else { //Error or Unknown } } } #endregion #region Statements else if (logicTopNode.Name.ToLower() == "all_statements") { XmlNode temp_AllLogic = logicTopNode; foreach (XmlNode temp_AllLogic_SubNode in temp_AllLogic.ChildNodes) { int tempTimeInbetween = LogicTimer.Interval; foreach (XmlAttribute _abcdefg in temp_AllLogic_SubNode.Attributes) { if (_abcdefg.Name.ToLower() == "minimum_delta_vote_time") { int.TryParse(_abcdefg.Value, out tempTimeInbetween); break; } } AllLogicXMlNodes.Add(new Logic_Struct(temp_AllLogic_SubNode, tempTimeInbetween)); } } #endregion } } #endregion } } } Console.WriteLine("Done Reading XML File"); #endregion } #region Error Catching catch (FileNotFoundException e) { Console.WriteLine(e.ToString()); DisplayMessageBox("Unkown Error in Configuration File", true); this.Close(); return false; } #endregion return true; } #region Load Texture into Device public MDX_TextureLoadingReturnClass LoadMyTexture(Device device, string path) { try { Splash_LoadedTextures++; MDX_DebugLogging("Loading Texture #" + Splash_LoadedTextures.ToString()); foreach (MDX_TextureLoadLookupStruct _MDX_LUS in AllMDXTexturePathOptimization) { if (_MDX_LUS._path.ToLower() == path.ToLower()) { return new MDX_TextureLoadingReturnClass(_MDX_LUS.loadedTexture, _MDX_LUS.loadedInfo, _MDX_LUS.loadedBitmap); } } if (!File.Exists(path)) { return new MDX_TextureLoadingReturnClass(); } ImageInformation _ImageInfo = new ImageInformation(); Texture _Texture = null; Image _Bitmap = null; if (MDX_use_GDI_not_DX) { _Bitmap = Image.FromFile(path); } else { _ImageInfo = TextureLoader.ImageInformationFromFile(path); _Texture = TextureLoader.FromFile(device, path, _ImageInfo.Width, _ImageInfo.Height, _ImageInfo.MipLevels, Usage.None, _ImageInfo.Format, Pool.Managed, Filter.None, Filter.None, 0); } AllMDXTexturePathOptimization.Add(new MDX_TextureLoadLookupStruct(path, _Texture, _ImageInfo, _Bitmap)); return new MDX_TextureLoadingReturnClass(_Texture, _ImageInfo, _Bitmap); } catch (Exception e) { Console.WriteLine(e.ToString()); return new MDX_TextureLoadingReturnClass(); } } #endregion #region Store Maximum Page public void MaxPage(int i) { if (i > MAX_PAGE) { MAX_PAGE = i; } } #endregion } }