using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.IO; using System.Xml; using System.Drawing; namespace FCC_Uber_MDX_Configurator { public static class GlobalStaticClass { #region List View Up-A-Level Root public static ListViewItem ListViewItem_GoUpALevel = new ListViewItem("Go Up", "UpListIcon.png"); #endregion #region Function Directory public static string FUNCTION_DIRECTORY = Application.StartupPath + "\\functions"; public static string FONT_DIRECTORY = Application.StartupPath + "\\fonts"; #endregion #region String Formatting public static string FormatAllCapsString(string input_string) { string return_string = ""; if (input_string == null) { return return_string; } string[] splitArray = input_string.Split(new char[] { ' ', '_' }); foreach (string _s in splitArray) { string _tempS = _s.Substring(0, 1).ToUpper() + _s.Substring(1).ToLower(); return_string += _tempS + " "; } return_string = return_string.Trim(); return return_string; } #endregion #region Help Area public static List AllHelpTopics = new List(); public static List AllHelpForms = new List(); public struct HelpTopicLinkStruct { public string FormID; public string TopicID; public HelpTopicLinkStruct(string input_form, string input_topic) { FormID = input_form; TopicID = input_topic; } } public class HelpTopicClass { public string FormID; public string TopicID; public string HelpTitle; public string HelpDescription; public List HelpLinkIndexes = new List(); public HelpTopicClass(string input_formID, string input_topicD, string input_title, string input_description) { FormID = input_formID; TopicID = input_topicD; HelpTitle = input_title; HelpDescription = input_description; GlobalStaticClass.AllHelpTopics.Add(this); } public void DisplayHelp() { if (HelpTitle == "" || HelpDescription == "") { return; } HelpForm _tempHelp = (new HelpForm(AllHelpTopics.IndexOf(this))); AllHelpForms.Add(_tempHelp); if (AllHelpForms.Count > 5) { AllHelpForms[0].Close(); AllHelpForms.RemoveAt(0); } _tempHelp.Show(); } public void AddLinkIndex(HelpTopicLinkStruct input_HelpTopicLinkStruct) { HelpLinkIndexes.Add(input_HelpTopicLinkStruct); } public object[] ToListArray() { List _tempStringArray = new List(); foreach (HelpTopicLinkStruct _HTLS in HelpLinkIndexes) { _tempStringArray.Add(_HTLS.FormID + ": " + _HTLS.TopicID); } return (object[])_tempStringArray.ToArray(); } } public static void FireHelpEvent(string input_EventFired_Form, string input_EventFired_Topic) { for (int i = 0; i < AllHelpTopics.Count; i++) { if (AllHelpTopics[i].FormID == input_EventFired_Form && AllHelpTopics[i].TopicID == input_EventFired_Topic) { AllHelpTopics[i].DisplayHelp(); return; } } (new ErrorForm("No Help Topic Available", "There is currently no available help for this topic.\r\n[" + input_EventFired_Form + ": " + input_EventFired_Topic + "]", true)).ShowDialog(); return; } #endregion #region Global Properties public static class _GlobalPropertiesClass { public static string _author = "Me"; public static string _versionRequired = "3.0.0.0"; public static DateTime _LastModifiedDate = DateTime.Now; public static DateTime _CreatedDate = DateTime.Now; } #endregion #region Global Graphics Properties public static class _GlobalGraphicsPropertiesClass { public static int _MadeForWidth = 800; public static int _MadeForHeight = 600; public static int _ShowAtWidth = 800; public static int _ShowAtHeight = 600; public static FormBorderStyle _ApplicationFormStyle = FormBorderStyle.Sizable; public static bool _MinimizeToSystemTray = true; public static bool _StartInSystemTray = false; public static string _ApplicationFormStyleToString() { switch (_ApplicationFormStyle) { case FormBorderStyle.FixedSingle: return "Fixed"; case FormBorderStyle.Sizable: return "Sizeable"; default: return "Hidden"; } } public static string _MinimizeToTrayToString() { if (_MinimizeToSystemTray) { return "True"; } else { return "False"; } } public static string _StartInTrayToString() { if (_StartInSystemTray) { return "True"; } else { return "False"; } } } #endregion #region Timer Properties public static class _GlobalTimerClass { public static int _timer_Output = 100; public static int _timer_Input = 75; public static int _timer_Logic = 50; public static int _timer_GUI = 50; } #endregion #region Brain Class and List public static List<_GlobalBrainClass> _Global_List_Brains = new List<_GlobalBrainClass>(); public static List _Global_List_Brains_ListItems = new List(); public class _GlobalBrainClass { public string _humanName = "MyFusionBrain0"; public string _VIDPID = null; public int _Version = 4; public _GlobalBrainClass(string Input_HumanName, string Input_VIDPID, int Input_Version) { _humanName = Input_HumanName; _VIDPID = Input_VIDPID; _Version = Input_Version; _Global_List_Brains.Add(this); } } #endregion #region I/O Classes and Lists public class _GlobalChannel { public string BrainID; public int Port; public string id; } public static List<_GlobalDigitalOutputClass> _Global_List_DigitalOutputs = new List<_GlobalDigitalOutputClass>(); public static List _Global_List_DigitalOutputs_ListItems = new List(); public class _GlobalDigitalOutputClass : _GlobalChannel { public bool _defaultState = false; public _GlobalDigitalOutputClass(string input_BrainID, int input_Port, string input_ID, string input_DefaultState) { BrainID = input_BrainID; Port = input_Port; id = input_ID; _defaultState = DefaultStateAsBool(input_DefaultState); _Global_List_DigitalOutputs.Add(this); } public string DefaultStateAsString() { if (_defaultState) { return "on"; } else { return "off"; } } public bool DefaultStateAsBool(string _state) { if (_state == "on") { return true; } else { return false; } } } public static List<_GlobalAnalogueInputClass> _Global_List_AnalogueInputs = new List<_GlobalAnalogueInputClass>(); public static List _Global_List_AnalogueInputs_ListItems = new List(); public class _GlobalAnalogueInputClass : _GlobalChannel { public bool _autoAverage = false; public int _historyKeeping = 15; public _GlobalAnalogueInputClass(string input_BrainID, int input_Port, string input_ID, string input_AutoAverage, int input_History) { BrainID = input_BrainID; Port = input_Port; id = input_ID; _autoAverage = AutoAverageFromStringToBool(input_AutoAverage); _historyKeeping = input_History; _Global_List_AnalogueInputs.Add(this); } public string AutoAverageAsString() { if (_autoAverage) { return "true"; } else { return "false"; } } public bool AutoAverageFromStringToBool(string i_autoAverage) { if (i_autoAverage.ToLower() == "true") { return true; } else { return false; } } } #endregion #region Physical Relations public const int FUSIONBRAIN_NUMBEROF_DIGITAL_OUTPUTS = 12; public const int FUSIONBRAIN_NUMBEROF_ANALOGUE_INPUTS = 10; #endregion #region Compare 2 Files public static bool FileCompare(string file1, string file2) { int file1byte; int file2byte; FileStream fs1; FileStream fs2; if (file1 == file2) { return true; } fs1 = new FileStream(file1, FileMode.Open); fs2 = new FileStream(file2, FileMode.Open); if (fs1.Length != fs2.Length) { fs1.Close(); fs2.Close(); return false; } do { file1byte = fs1.ReadByte(); file2byte = fs2.ReadByte(); } while ((file1byte == file2byte) && (file1byte != -1)); fs1.Close(); fs2.Close(); return ((file1byte - file2byte) == 0); } #endregion #region Variables public static List<_GlobalVariableClass> _Global_List_Variables = new List<_GlobalVariableClass>(); public static List _Global_List_Variables_ListItems = new List(); public class _GlobalVariableClass { public string _id; public object _value; public _GlobalVariableClass(string input_id, object input_value) { _id = input_id; _value = input_value; _Global_List_Variables.Add(this); } } #endregion #region Functions public static List<_GlobalFunctionsClass> _Global_List_Functions = new List<_GlobalFunctionsClass>(); public static List _Global_List_Functions_ListItems = new List(); public static List _Global_List_Functions_TSMenuItems = new List(); public class _GlobalFunctionsClass { public LogicModules.FunctionMDX _function; public TabPage _MyTabPage; public System.Drawing.Bitmap _image; public ListBox _thenList_ListBox = new ListBox(); public PictureBox _function_PictureBox = new PictureBox(); public _GlobalFunctionsClass(LogicModules.FunctionMDX input_function, System.Drawing.Bitmap input_image) { _function = input_function; _image = input_image; _MyTabPage = new TabPage(input_function._FunctionID); _MyTabPage.Name = input_function._FunctionID; _function_PictureBox.BackgroundImage = _image; _MyTabPage.BackColor = System.Drawing.Color.White; this._thenList_ListBox.Font = new System.Drawing.Font("Arial", 14.25F); this._thenList_ListBox.FormattingEnabled = true; this._thenList_ListBox.ItemHeight = 22; this._thenList_ListBox.Location = new System.Drawing.Point(12, 285); this._thenList_ListBox.Name = "ListBox: " + input_function._FunctionID; this._thenList_ListBox.Size = new System.Drawing.Size(542, 136); this._thenList_ListBox.TabIndex = 0; this._function_PictureBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this._function_PictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this._function_PictureBox.Location = new System.Drawing.Point(12, 12); this._function_PictureBox.Name = "PictureBox: " + input_function._FunctionID; this._function_PictureBox.Size = new System.Drawing.Size(100, 100); this._function_PictureBox.TabIndex = 1; this._function_PictureBox.TabStop = false; this._MyTabPage.Controls.Add(this._function_PictureBox); this._MyTabPage.Controls.Add(this._thenList_ListBox); _Global_List_Functions.Add(this); } public void PopulateThenDoList() { _thenList_ListBox.Items.Clear(); foreach (GlobalStaticClass.Vote_VoteClass _vvc in _function._ThenList) { _thenList_ListBox.Items.Add(_vvc.FormatAsStringForListBox()); } _thenList_ListBox.Update(); } public static string GetUniqueName() { return GetUniqueName("Root Function #"); } public static string GetUniqueName(string input_baseName) { int i = 1; string possibleName = input_baseName; while (true) { bool isUnique = true; foreach (_GlobalFunctionsClass _mi in _Global_List_Functions) { if (_mi._function._FunctionID.ToLower() == possibleName.ToLower()) { isUnique = false; break; } } if (isUnique) { return possibleName; } else { i++; } possibleName = input_baseName + i.ToString(); } } } public static void Functions_InitializeNonDesignerModulesLocation(LogicModules.FunctionMDX input_function) { LogicModules.Module _root = null; List> SortedModules = new List>(); foreach (LogicModules.Module _mod in input_function._Modules) { if (_mod.id == "OUTPUT") { _root = _mod; break; } } if (_root == null) { return; } if (_root.Input_Nodes.Count == 0) { return; } if (!_root.Input_Nodes[0].isConnected()) { return; } SortedModules.Add(new List()); SortedModules[0].Add(_root); Functions_InitializeNonDesignerModulesLocation_SetupLevels(1, _root.Input_Nodes[0].LinkTo.Link_Module, SortedModules); int ConstrainWidth = 800, ConstrainHeight = 600; for (int x = 0; x < SortedModules.Count; x++) { for (int y = 0; y < SortedModules[x].Count; y++) { SortedModules[x][y].ModuleLocation = new System.Drawing.Point(ConstrainWidth - ((ConstrainWidth / (SortedModules.Count + 2)) * (x + 1)), ((ConstrainHeight / (SortedModules[x].Count + 2)) * (y + 1))); } } } private static void Functions_InitializeNonDesignerModulesLocation_SetupLevels(int _level, LogicModules.Module _addModule, List> _sortList) { #region Idea 1 Switches /* switch (_allModules[_allIndex].id) { case "AND": { } break; case "OR": { } break; case "NOT": { } break; case "NAND": { } break; case "NOR": { } break; case "XOR": { } break; case "LESS THAN": { } break; case "LESS THAN OR EQUAL TO": { } break; case "GREATER THAN": { } break; case "GREATER THAN OR EQUAL TO": { } break; case "EQUAL TO": { } break; case "NOT EQUAL TO": { } break; case "ADD": { } break; case "SUBTRACT": { } break; case "MULTIPLY": { } break; case "DIVIDE": { } break; case "INPUT": { } break; case "NUMBER": { } break; case "VARIABLE": { } break; case "ANALOGUEINPUT": { } break; case "DIGITALOUTPUT": { } break; default: //Custom Function { } break; } */ #endregion if (_sortList.Count <= _level) { _sortList.Add(new List()); } _sortList[_level].Add(_addModule); for (int i = 0; i < _addModule.Input_Nodes.Count; i++) { if (_addModule.Input_Nodes[i].isConnected()) { Functions_InitializeNonDesignerModulesLocation_SetupLevels(_level + 1, _addModule.Input_Nodes[i].LinkTo.Link_Module, _sortList); } } return; } public static List Function_ParseThenAndAntiThenNodesToVoteClassList(XmlNode _thenNode, ref List inputErrors) { List _r = new List(); if (_thenNode != null) { foreach (XmlNode _thenChild in _thenNode.ChildNodes) { if (_thenChild.Name.ToLower() == "do") { string s_priority = ""; string s_function = ""; string s_functionTargetID = ""; string s_opinion = ""; Vote_VoteClass _thenVote = new Vote_VoteClass(); foreach (XmlAttribute _thenA in _thenChild.Attributes) { #region Read In Values switch (_thenA.Name.ToLower()) { case "function": s_function = _thenA.Value; break; case "functiontargetid": s_functionTargetID = _thenA.Value; break; case "vote_opinion": s_opinion = _thenA.Value; break; case "vote_priority": s_priority = _thenA.Value; break; default: inputErrors.Add("Property of a Then statement is invalid: \"" + _thenA.Name + "\""); break; } #endregion } if (s_function != "" && s_functionTargetID != "" && s_opinion != "" && s_priority != "") { #region Set Priority { switch (s_priority.ToLower()) { case "low": _thenVote._Priority = GlobalStaticClass.Vote_Priority.LOW; break; case "medium": _thenVote._Priority = GlobalStaticClass.Vote_Priority.MEDIUM; break; case "high": _thenVote._Priority = GlobalStaticClass.Vote_Priority.HIGH; break; case "absolute": _thenVote._Priority = GlobalStaticClass.Vote_Priority.ABSOLUTE; break; default: inputErrors.Add("Then Statement: Prioirty Invalid of \"" + s_priority + "\""); _thenVote._Priority = Vote_Priority.MEDIUM; break; } } #endregion #region What to Do { switch (s_function.ToLower()) { case "trigger output": { _thenVote._WhatToDo = GlobalStaticClass.Vote_PossibleThingsToDo.TRIGGER_OUTPUT; } break; case "enable or disable": { _thenVote._WhatToDo = GlobalStaticClass.Vote_PossibleThingsToDo.ENABLE_OR_DISABLE; } break; case "change variable": { _thenVote._WhatToDo = GlobalStaticClass.Vote_PossibleThingsToDo.CHANGE_VARIABLE; } break; case "change page": { _thenVote._WhatToDo = GlobalStaticClass.Vote_PossibleThingsToDo.CHANGE_PAGE; } break; case "change timer": { _thenVote._WhatToDo = GlobalStaticClass.Vote_PossibleThingsToDo.CHANGE_TIMER; } break; case "change logging": { _thenVote._WhatToDo = GlobalStaticClass.Vote_PossibleThingsToDo.CHANGE_VARIABLE; } break; case "send key": { _thenVote._WhatToDo = GlobalStaticClass.Vote_PossibleThingsToDo.SEND_KEY; } break; case "send key to foreground": { _thenVote._WhatToDo = GlobalStaticClass.Vote_PossibleThingsToDo.SEND_KEY_TO_FOREGROUND; } break; case "play sound": { _thenVote._WhatToDo = GlobalStaticClass.Vote_PossibleThingsToDo.PLAY_SOUND; } break; default: inputErrors.Add("Then Statement: What to do Invalid of \"" + s_function + "\""); _thenVote._WhatToDo = Vote_PossibleThingsToDo.TRIGGER_OUTPUT; break; } } #endregion _thenVote._TargetID = s_functionTargetID; _thenVote._VoteOpinion = s_opinion; _r.Add(_thenVote); } } } } return _r; } public static bool Functions_ParseXMLLogicToDesigner(XmlNode _root, MainMDXConfigForm mom, List inputErrors, BusyDoingCrapForm _BUSYFORM) { XmlNodeList _nl = _root.SelectNodes("if"); foreach (XmlNode _ifNode in _nl) { _BUSYFORM.UpdateBar(); LogicModules.FunctionMDX _func = new LogicModules.FunctionMDX(); _func._FunctionID = GlobalStaticClass._GlobalFunctionsClass.GetUniqueName(); List _list_Mod = new List(); foreach (XmlAttribute _ifAttribute in _ifNode.Attributes) { switch (_ifAttribute.Name.ToLower()) { case "fire_on": string _fireOnString = "logic"; if (_ifAttribute.Value.Length > 0) { switch (_ifAttribute.Value.ToLower().ToCharArray()[0]) { case 'o': _fireOnString = "output"; break; case 'i': _fireOnString = "input"; break; case 'g': _fireOnString = "gui"; break; default: _fireOnString = "logic"; break; } } _func._timerID = _fireOnString; break; case "minimum_delta_vote_time": int.TryParse(_ifAttribute.Value, out _func._TimeInbetween); break; case "id": _func._FunctionID = _ifAttribute.Value; break; default: break; } } LogicModules.LogicModule_OUTPUT _rootOutput = new LogicModules.LogicModule_OUTPUT(); LogicModules.Module _modReturn = Functions_XMLToModule(_ifNode, _rootOutput, _list_Mod); if (_modReturn == null) { inputErrors.Add("Function is unreadable. Must have a 2nd tier node of \"boolean_operation\" or \"operation\". Other possibilities include missing external function file."); continue; } XmlNode _thenNode = _ifNode.SelectSingleNode("then"); XmlNode _antiThenNode = _ifNode.SelectSingleNode("anti-then"); _func._ThenList = Function_ParseThenAndAntiThenNodesToVoteClassList(_thenNode, ref inputErrors); _func._AntiThenList = Function_ParseThenAndAntiThenNodesToVoteClassList(_antiThenNode, ref inputErrors); _list_Mod.Add(_rootOutput); _rootOutput.Input_Nodes[0].LinkTo = new LogicModules.Node.ConnectLink(_modReturn, LogicModules.Node.LinkDirection.INPUT, _modReturn.Output_Nodes[0]); _modReturn.Output_Nodes[0].LinkTo = new LogicModules.Node.ConnectLink(_rootOutput, LogicModules.Node.LinkDirection.OUTPUT, _rootOutput.Input_Nodes[0]); _func._Modules = new List(_list_Mod.ToArray()); Functions_InitializeNonDesignerModulesLocation(_func); System.Drawing.Bitmap _myBitmap = new System.Drawing.Bitmap(800, 600); System.Drawing.Graphics _myBitmap_G = System.Drawing.Graphics.FromImage(_myBitmap); List _myBitmap_RECT = new List(); foreach (LogicModules.Module _mod in _func._Modules) { _BUSYFORM.UpdateBar(); CustomFunctionForm.DrawNode(_myBitmap_G, _mod, _myBitmap_RECT, null, true); } _myBitmap_G.Dispose(); mom.Logic_SetupNewRootNode(_func, _myBitmap, false); } return true; } private static LogicModules.Module Functions_XMLToModule(XmlNode _node, LogicModules.Module _mod, List _myList) { LogicModules.Module _newMod = null; switch (_node.Name.ToLower()) { case "if": { XmlNode _firstLogicNode = null; _firstLogicNode = _node.SelectSingleNode("boolean_operation"); if (_firstLogicNode == null) { _firstLogicNode = _node.SelectSingleNode("operation"); if (_firstLogicNode == null) { _firstLogicNode = _node.SelectSingleNode("evaluate"); if (_firstLogicNode == null) { _firstLogicNode = _node.SelectSingleNode("variable"); if (_firstLogicNode == null) { //Not in correct format return null; } else { XmlNode _doNode = _firstLogicNode.Attributes.GetNamedItem("do"); if (_doNode == null) { //No Do Node return null; } else { if (_doNode.Value.ToLower() != "set") { return null; } } } } } } _newMod = Functions_XMLToModule(_firstLogicNode, _mod, _myList); //_myList.Add(_newMod); return _newMod; } break; case "boolean_operation": case "operation": { List pNodes = new List(); int p_i = 1; while (true) { XmlNode p = _node.SelectSingleNode("parameter" + p_i.ToString()); if (p == null) { break; } else { pNodes.Add(p); } p_i++; } //mlNode p1 = _node.SelectSingleNode("parameter1"); //XmlNode p2 = _node.SelectSingleNode("parameter2"); //XmlNode p3 = _node.SelectSingleNode("parameter3"); if (pNodes.Count == 0) { break; } for(int p_ii = 0; p_ii < pNodes.Count; p_ii++) { if (!pNodes[p_ii].HasChildNodes) { pNodes[p_ii] = null; p_ii--; } } string op_type = (_node.Attributes.GetNamedItem("type")).Value.ToLower(); switch (op_type) { case "divide": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Division(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_Division_Icon, null)); break; case "multiply": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Multiplication(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_Multiplication_Icon, null)); break; case "add": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Add(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_Addition_Icon, null)); break; case "subtract": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Subtraction(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_Subtraction_Icon, null)); break; case "greater than": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_GreaterThan(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_GreaterThan_Icon, null)); break; case "less than": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_LessThan(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_LessThan_icon, null)); break; case "greater than or equal to": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_GreaterThanOrEqualTo(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_GreaterThanOrEqualTo_Icon, null)); break; case "less than or equal to": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_LessThanOrEqualTo(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_LessThanOrEqualTo_icon, null)); break; case "between ee": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_BetweenEE(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_Between_Exclusive_Exclusive, null)); break; case "between ei": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_BetweenEI(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_Between_Exclusive_Inclusive, null)); break; case "between ie": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_BetweenIE(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_Between_Inclusive_Exclusive, null)); break; case "between ii": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_BetweenII(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_Between_Inclusive_Inclusive, null)); break; case "equal to": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Equals(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_Equals_Icon, null)); break; case "not equal to": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_NotEquals(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.Text_NotEqual_Icon, null)); break; case "and": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_And2(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.AND_Icon, null)); break; case "or": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Or2(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.OR_Icon, null)); break; case "not": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Not2(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.NOT_Icon, null)); break; case "nand": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Nand2(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.NAND_Icon, null)); break; case "nor": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Nor2(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.NOR_Icon, null)); break; case "xor": _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Xor2(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.XOR_Icon, null)); break; default: break; } if (_newMod == null) { break; } foreach (XmlNode pNode in pNodes) { if (pNode == null) { continue; } LogicModules.Module m = Functions_XMLToModule(pNode.FirstChild, _newMod, _myList); if (m == null) { return null; }; //LogicModules.Module m2 = Functions_XMLToModule(p2.FirstChild, _newMod, _myList); //if (m2 == null) { return null; }; m.Output_Nodes[0].LinkTo = new LogicModules.Node.ConnectLink(_newMod, LogicModules.Node.LinkDirection.OUTPUT, _newMod.Input_Nodes[pNodes.IndexOf(pNode)]); _newMod.Input_Nodes[pNodes.IndexOf(pNode)].LinkTo = new LogicModules.Node.ConnectLink(m, LogicModules.Node.LinkDirection.INPUT, m.Output_Nodes[0]); //m2.Output_Nodes[0].LinkTo = new LogicModules.Node.ConnectLink(_newMod, LogicModules.Node.LinkDirection.OUTPUT, _newMod.Input_Nodes[1]); //_newMod.Input_Nodes[1].LinkTo = new LogicModules.Node.ConnectLink(m2, LogicModules.Node.LinkDirection.INPUT, m2.Output_Nodes[0]); } break; } case "number": { double returnValuezDouble = 0.00; double.TryParse(_node.FirstChild.Value, out returnValuezDouble); _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Number(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.NumberIconTransparent, null, returnValuezDouble)); } break; #region DEPRECIATED case "boolean": { _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Number(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.NumberIconTransparent, null, 0.0)); } break; #endregion case "output": { string _id = _node.Attributes.GetNamedItem("id").Value; _newMod = (LogicModules.Module)(new LogicModules.LogicModule_DIGITALOUTPUT(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.OutputIcon, null, _id)); } break; case "input": { } break; case "analogue": { string _id = _node.Attributes.GetNamedItem("id").Value; _newMod = (LogicModules.Module)(new LogicModules.LogicModule_ANALOGUEINPUT(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.InputIcon, null, _id)); } break; #region DEPRECIATED case "digital_input": { _newMod = (LogicModules.Module)(new LogicModules.LogicModule_Number(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.NumberIconTransparent, null, 0.0)); } break; #endregion case "variable": { string _ref = null; if (_node.HasChildNodes) { _ref = _node.FirstChild.Value; } if (_ref == null || _ref == "") { _ref = _node.Attributes.GetNamedItem("name").Value; } if (_ref == null || _ref == "") { } string _gOs = _node.Attributes.GetNamedItem("do").Value; if (_gOs.ToLower() == "set") { LogicModules.Module m1 = Functions_XMLToModule(_node.FirstChild, _mod, _myList); if (m1 == null) { return null; }; _newMod = (LogicModules.Module)(new LogicModules.LogicModule_VARIABLE(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.VariableIcon, null, _ref, _gOs)); int _newMod_index_var = -1; for (int i = 0; i < _newMod.Input_Nodes.Count; i++) { if (!_newMod.Input_Nodes[i].isConnected()) { _newMod_index_var = i; break; } } if (_newMod_index_var >= 0) { m1.Output_Nodes[0].LinkTo = new LogicModules.Node.ConnectLink(_newMod, LogicModules.Node.LinkDirection.OUTPUT, _newMod.Input_Nodes[_newMod_index_var]); _newMod.Input_Nodes[_newMod_index_var].LinkTo = new LogicModules.Node.ConnectLink(m1, LogicModules.Node.LinkDirection.INPUT, m1.Output_Nodes[0]); } //_myList.Add(m1); } else { _newMod = (LogicModules.Module)(new LogicModules.LogicModule_VARIABLE(new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.VariableIcon, null, _ref, _gOs)); } } break; case "evaluate": { XmlNode testNode = _node.Attributes.GetNamedItem("function"); if (testNode == null) { return null; } string test_id = testNode.Value.ToLower(); bool function_is_found = false; foreach (LogicModules.PsuedoFunctionMDX _psuedo in LogicModules._Global_FunctionsList) { if (_psuedo._id.ToLower() == test_id) { _newMod = (LogicModules.Module)(new LogicModules.Module_FunctionMDX(_psuedo, new System.Drawing.Point(0, 0), global::FCC_Uber_MDX_Configurator.Properties.Resources.FunctionIcon)); function_is_found = true; break; } } if (!function_is_found) { return null; } foreach (XmlNode _nodanoda in _node.SelectNodes("input")) { LogicModules.Module m1 = Functions_XMLToModule(_nodanoda.FirstChild, _mod, _myList); if (m1 == null) { return null; }; XmlNode _temp_order_node = _nodanoda.Attributes.GetNamedItem("order"); string temp_order_string = ""; if (_temp_order_node != null) { temp_order_string = _temp_order_node.Value; } int temp_order = 0; int.TryParse(temp_order_string, out temp_order); temp_order--; if (_newMod.Input_Nodes.Count > temp_order && !_newMod.Input_Nodes[temp_order].isConnected()) { m1.Output_Nodes[0].LinkTo = new LogicModules.Node.ConnectLink(_newMod, LogicModules.Node.LinkDirection.OUTPUT, _newMod.Input_Nodes[temp_order]); _newMod.Input_Nodes[temp_order].LinkTo = new LogicModules.Node.ConnectLink(m1, LogicModules.Node.LinkDirection.INPUT, m1.Output_Nodes[0]); } else { int _newMod_index_func = -1; for (int i = 0; i < _newMod.Input_Nodes.Count; i++) { if (!_newMod.Input_Nodes[i].isConnected()) { _newMod_index_func = i; break; } } if (_newMod_index_func >= 0) { m1.Output_Nodes[0].LinkTo = new LogicModules.Node.ConnectLink(_newMod, LogicModules.Node.LinkDirection.OUTPUT, _newMod.Input_Nodes[_newMod_index_func]); _newMod.Input_Nodes[_newMod_index_func].LinkTo = new LogicModules.Node.ConnectLink(m1, LogicModules.Node.LinkDirection.INPUT, m1.Output_Nodes[0]); } } } } break; default: //Error break; } if (_newMod == null) { return null; } _myList.Add(_newMod); return _newMod; } #endregion #region Email public const string MatchEmailPattern = @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@" + @"((([0-1]?[0-9]{1,2}|2{1}[0-5]{2})\.([0-1]?[0-9]{1,2}|2{1}[0-5]{2})\." + @"([0-1]?[0-9]{1,2}|2{1}[0-5]{2})\.([0-1]?[0-9]{1,2}|2{1}[0-5]{2})){1}|" + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$"; #endregion #region COM -- Globals and Lists public static List COM_List_of_Commands = new List(); public static List COM_List_of_Executable_Commands = new List(); public static bool COM_Master_Enable = false; public static bool COM_Enable_Only_COM_Mode = false; #endregion #region COM Command to Interpret public class COM_Command_Class { public string id = ""; public int minimum_delta_vote_time = 100; public List do_statements = new List(); public COM_Command_Class(string input_id) { id = input_id; } public void Copy(COM_Command_Class _toCopy) { id = _toCopy.id; minimum_delta_vote_time = _toCopy.minimum_delta_vote_time; do_statements = new List(_toCopy.do_statements.ToArray()); } } #endregion #region COM Command to Execute public class COM_Execution_Object_Class { public class COM_Execution_Object_Command_IDs_Class { public string external_Command; public string internal_Command; public List external_Command_Parameters; public COM_Execution_Object_Command_IDs_Class(string input_external_command, string input_internal_command, List input_external_command_parameters) { external_Command = input_external_command; internal_Command = input_internal_command; external_Command_Parameters = input_external_command_parameters; } } public class COM_External_Executable_Parameter_Class : IComparable { public int _order; public string _param; public COM_External_Executable_Parameter_Class() { } public COM_External_Executable_Parameter_Class(int input_order, string input_parameter) { _order = input_order; _param = input_parameter; } #region IComparable Members public int CompareTo(COM_External_Executable_Parameter_Class other) { return this._order.CompareTo(other._order); } #endregion } public string id = ""; public List COM_Commands = new List(); public void Copy(COM_Execution_Object_Class toCopy) { id = toCopy.id; COM_Commands = new List(toCopy.COM_Commands.ToArray()); } } #endregion #region Voting Options public enum Vote_PossibleThingsToDo { TRIGGER_OUTPUT, ENABLE_OR_DISABLE, CHANGE_VARIABLE, CHANGE_PAGE, CHANGE_TIMER, CHANGE_LOGGING, SEND_KEY, SEND_KEY_TO_FOREGROUND, PLAY_SOUND, SEND_EMAIL, DISPLAY_WARNING } public enum Vote_Priority { LOW, MEDIUM, HIGH, ABSOLUTE } public class Vote_VoteClass { public Vote_PossibleThingsToDo _WhatToDo; public string _TargetID; public string _VoteOpinion; public Vote_Priority _Priority; public Vote_VoteClass() { } public Vote_VoteClass(Vote_PossibleThingsToDo input_do, string input_targetid, string input_opinion, Vote_Priority input_priority) { _WhatToDo = input_do; _TargetID = input_targetid; _VoteOpinion = input_opinion; _Priority = input_priority; } public string FormatAsStringForListBox() { return GlobalStaticClass.FormatAllCapsString(this._WhatToDo.ToString()) + " [" + GlobalStaticClass.FormatAllCapsString(this._Priority.ToString()) + "]" + " -- " + this._TargetID + " -- " + this._VoteOpinion; } } #endregion #region Logs public static List<_GlobalLogClass> _Global_List_Logs = new List<_GlobalLogClass>(); public static List _Global_List_Logs_ListItems = new List(); public class _GlobalLogClass { public string _id, _monitor_type, _monitor_id, _record_timer, _record_object, _data_name, _file_name; public bool _hold_stream_open, _default_state; public int _store_before_dump = 100; public _GlobalLogClass(string input_id, string input_monitor_type, string input_monitor_id, string input_record_timer, string input_record_object, string input_default_state, string input_hold_stream_open, int input_store_before_dump, string input_data_name, string input_log_file_name) { _id = input_id; _monitor_type = input_monitor_type; _monitor_id = input_monitor_id; _record_timer = input_record_timer; _record_object = input_record_object; _default_state = DefaultStateFromStringToBool(input_default_state); _hold_stream_open = HoldOpenFromStringToBool(input_hold_stream_open); _store_before_dump = input_store_before_dump; _data_name = input_data_name; _file_name = input_log_file_name; _Global_List_Logs.Add(this); } public _GlobalLogClass(string input_id, string input_monitor_type, string input_monitor_id, string input_record_timer, string input_record_object, bool input_default_state, bool input_hold_stream_open, int input_store_before_dump, string input_data_name, string input_log_file_name) { _id = input_id; _monitor_type = input_monitor_type; _monitor_id = input_monitor_id; _record_timer = input_record_timer; _record_object = input_record_object; _default_state = input_default_state; _hold_stream_open = input_hold_stream_open; _store_before_dump = input_store_before_dump; _data_name = input_data_name; _file_name = input_log_file_name; _Global_List_Logs.Add(this); } public bool DefaultStateFromStringToBool(string input) { if (input.ToLower() == "on") { return true; } else { return false; } } public string DefaultStateFromBoolToString() { if (_default_state) { return "On"; } else { return "Off"; } } public bool HoldOpenFromStringToBool(string input) { if (input.ToLower() == "true") { return true; } else { return false; } } public string HoldOpenFromBoolToString() { if (_hold_stream_open) { return "True"; } else { return "False"; } } } #endregion #region Graphics public static List _Global_List_Graphics_PageList = new List(); public static List _Global_List_Graphics_Generic_Sorted_Images = new List(); public static List _Global_List_AllModuleBounds = new List(); public static List _Global_List_Graphics_BackgroundImage = new List(); public static List _Global_List_Graphics_StaticImage = new List(); public static List _Global_List_Graphics_DisplayButton = new List(); public static List _Global_List_Graphics_MultiImage = new List(); public static List _Global_List_Graphics_VariableLocationImage = new List(); public static List _Global_List_Graphics_Graphs = new List(); public static List _Global_List_Graphics_BackgroundImage_ListItems = new List(); public static List _Global_List_Graphics_StaticImage_ListItems = new List(); public static List _Global_List_Graphics_DisplayButton_ListItems = new List(); public static List _Global_List_Graphics_MultiImage_ListItems = new List(); public static List _Global_List_Graphics_VariableLocationImage_ListItems = new List(); public static List _Global_List_Graphics_Graph_ListItems = new List(); #region All GUI Z-Ordering public class ZOrder_QuelleListeLookupItem { public ZOrderListIndexMatrix _ListReferenceType; public int _IndexInList; public float _ZOrder; public ZOrder_QuelleListeLookupItem(ZOrderListIndexMatrix input_ListENUM, int input_Index, float input_Order) { _ListReferenceType = input_ListENUM; _IndexInList = input_Index; _ZOrder = input_Order; } public ZOrder_QuelleListeLookupItem(ZOrder_QuelleListeLookupItem toCloneItem) { _ListReferenceType = toCloneItem._ListReferenceType; _IndexInList = toCloneItem._IndexInList; _ZOrder = toCloneItem._ZOrder; } public void Replace(ZOrder_QuelleListeLookupItem toReplaceItem) { _ListReferenceType = toReplaceItem._ListReferenceType; _IndexInList = toReplaceItem._IndexInList; _ZOrder = toReplaceItem._ZOrder; } } public enum ZOrderListIndexMatrix { ENUM_DISPLAYBUTTONS, ENUM_MULTIIMAGES, ENUM_ROTATEIMAGES, ENUM_STATICIMAGES, ENUM_BACKGROUND, ENUM_VARIABLELOCATION, ENUM_GRAPH } #endregion #region Sort Graphics public static void GraphicsSort() { GraphicsUpdateAllModuleBounds(); _Global_List_Graphics_Generic_Sorted_Images.Clear(); for (int i = 0; i < _Global_List_Graphics_StaticImage.Count; i++) { _Global_List_Graphics_Generic_Sorted_Images.Add(new ZOrder_QuelleListeLookupItem(ZOrderListIndexMatrix.ENUM_STATICIMAGES, i, _Global_List_Graphics_StaticImage[i]._z_order)); } for (int i = 0; i < _Global_List_Graphics_DisplayButton.Count; i++) { _Global_List_Graphics_Generic_Sorted_Images.Add(new ZOrder_QuelleListeLookupItem(ZOrderListIndexMatrix.ENUM_DISPLAYBUTTONS, i, _Global_List_Graphics_DisplayButton[i]._z_order)); } for (int i = 0; i < _Global_List_Graphics_MultiImage.Count; i++) { _Global_List_Graphics_Generic_Sorted_Images.Add(new ZOrder_QuelleListeLookupItem(ZOrderListIndexMatrix.ENUM_MULTIIMAGES, i, _Global_List_Graphics_MultiImage[i]._z_order)); } for(int i = 0; i < _Global_List_Graphics_VariableLocationImage.Count; i++) { _Global_List_Graphics_Generic_Sorted_Images.Add(new ZOrder_QuelleListeLookupItem(ZOrderListIndexMatrix.ENUM_VARIABLELOCATION, i, _Global_List_Graphics_VariableLocationImage[i]._z_order)); } for (int i = 0; i < _Global_List_Graphics_Graphs.Count; i++) { _Global_List_Graphics_Generic_Sorted_Images.Add(new ZOrder_QuelleListeLookupItem(ZOrderListIndexMatrix.ENUM_GRAPH, i, _Global_List_Graphics_Graphs[i]._z_order)); } if (_Global_List_Graphics_Generic_Sorted_Images.Count > 0) { MDX_BubbleSortAlgorithm(); _Global_List_Graphics_Generic_Sorted_Images.Reverse(); } } #endregion #region Bubble Sort Algorithm (For MDX_DisplayDepth) public static void MDX_BubbleSortAlgorithm() { GlobalStaticClass.ZOrder_QuelleListeLookupItem temp = null; for (int i = (GlobalStaticClass._Global_List_Graphics_Generic_Sorted_Images.Count - 1); i >= 0; i--) { for (int j = 1; j <= i; j++) { if (GlobalStaticClass._Global_List_Graphics_Generic_Sorted_Images[j - 1]._ZOrder > GlobalStaticClass._Global_List_Graphics_Generic_Sorted_Images[j]._ZOrder) { temp = GlobalStaticClass._Global_List_Graphics_Generic_Sorted_Images[j - 1]; GlobalStaticClass._Global_List_Graphics_Generic_Sorted_Images[j - 1] = GlobalStaticClass._Global_List_Graphics_Generic_Sorted_Images[j]; GlobalStaticClass._Global_List_Graphics_Generic_Sorted_Images[j] = temp; } } } } #endregion #region Update Module Bounds public static void GraphicsUpdateAllModuleBounds() { _Global_List_AllModuleBounds.Clear(); foreach (FusionImage_StaticImage static_image in _Global_List_Graphics_StaticImage) { _Global_List_AllModuleBounds.Add(new System.Drawing.Rectangle(static_image._x, static_image._y, static_image._width, static_image._height)); } } #endregion #region Localization private static List Graphics_AlreadySavedLocally = new List(); public static List Functions_ToSaveLocally_Names = new List(); public static void Functions_LocalizeAllFunctions_PopulateList() { Functions_ToSaveLocally_Names.Clear(); foreach (GlobalStaticClass._GlobalFunctionsClass _globalFunction in GlobalStaticClass._Global_List_Functions) { foreach (LogicModules.Module _mod in _globalFunction._function._Modules) { if (LogicModules.Module_is_a_Function(_mod)) { if (!Functions_ToSaveLocally_Names.Contains(_mod.id.ToLower())) { Functions_ToSaveLocally_Names.Add(_mod.id.ToLower()); } } } } } public static bool Functions_LocalizeAllFunctions(string savePath) { bool allGood = true; Functions_LocalizeAllFunctions_PopulateList(); if (Functions_ToSaveLocally_Names.Count == 0) { return allGood; } if (!Directory.Exists(savePath + "\\content\\functions")) { Directory.CreateDirectory(savePath + "\\content\\functions"); } foreach (string _s in Functions_ToSaveLocally_Names) { if (File.Exists(FUNCTION_DIRECTORY + "\\" + _s + ".xml")) { File.Copy(FUNCTION_DIRECTORY + "\\" + _s + ".xml", savePath + "\\content\\functions\\" + _s + ".xml", true); if (File.Exists(FUNCTION_DIRECTORY + "\\" + _s + ".designer")) { File.Copy(FUNCTION_DIRECTORY + "\\" + _s + ".designer", savePath + "\\content\\functions\\" + _s + ".designer", true); } } else { allGood = false; } } return allGood; } public static bool Function_isNotARootNode(GlobalStaticClass._GlobalFunctionsClass _inputFunc) { return true; } public static string Graphics_LocalizeImage(string input_path, ZOrderListIndexMatrix input_type) { return Graphics_LocalizeImage(input_path, input_type, ""); } public static string Graphics_LocalizeImage(string input_path, ZOrderListIndexMatrix input_type, string optionalSubDirectory) { string image_only = input_path; string[] image_path_array = image_only.Split(new char[] { '\\' }); image_only = image_path_array[image_path_array.Length - 1]; image_only = "content\\images\\" + Graphics_LocalizeImage_TypeToFolder(input_type) + "\\" + optionalSubDirectory + image_only; return image_only; } public static bool Graphics_LocalizeAllImages(string savePath) { bool allGood = true; Graphics_AlreadySavedLocally.Clear(); if (_Global_List_Graphics_BackgroundImage.Count > 0) { if (!Directory.Exists(savePath + "\\content\\images\\" + Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix.ENUM_BACKGROUND))) { Directory.CreateDirectory(savePath + "\\content\\images\\" + Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix.ENUM_BACKGROUND)); } } if (_Global_List_Graphics_StaticImage.Count > 0) { if (!Directory.Exists(savePath + "\\content\\images\\" + Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix.ENUM_STATICIMAGES))) { Directory.CreateDirectory(savePath + "\\content\\images\\" + Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix.ENUM_STATICIMAGES)); } } if (_Global_List_Graphics_DisplayButton.Count > 0) { if (!Directory.Exists(savePath + "\\content\\images\\" + Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix.ENUM_DISPLAYBUTTONS))) { Directory.CreateDirectory(savePath + "\\content\\images\\" + Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix.ENUM_DISPLAYBUTTONS)); } } if (_Global_List_Graphics_MultiImage.Count > 0) { if (!Directory.Exists(savePath + "\\content\\images\\" + Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix.ENUM_MULTIIMAGES))) { Directory.CreateDirectory(savePath + "\\content\\images\\" + Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix.ENUM_MULTIIMAGES)); } } if (_Global_List_Graphics_VariableLocationImage.Count > 0) { if (!Directory.Exists(savePath + "\\content\\images\\" + Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix.ENUM_VARIABLELOCATION))) { Directory.CreateDirectory(savePath + "\\content\\images\\" + Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix.ENUM_VARIABLELOCATION)); } } /* if (_Global_List_Graphics_MultiImage.Count > 0) { if (!Directory.Exists(savePath + "\\content\\images\\" + Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix.ENUM_GRAPH))) { Directory.CreateDirectory(savePath + "\\content\\images\\" + Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix.ENUM_GRAPH)); } } */ foreach (FusionImage_BackgroundImage _back in _Global_List_Graphics_BackgroundImage) { if (!Graphics_LocalizeImageForSave(savePath, _back._path, ZOrderListIndexMatrix.ENUM_BACKGROUND)) { allGood = false; } } foreach (FusionImage_StaticImage _static in _Global_List_Graphics_StaticImage) { if (!Graphics_LocalizeImageForSave(savePath, _static._path, ZOrderListIndexMatrix.ENUM_STATICIMAGES)) { allGood = false; } } foreach (FusionImage_VariableLocationImage _varLOC in _Global_List_Graphics_VariableLocationImage) { if (!Graphics_LocalizeImageForSave(savePath, _varLOC._path, ZOrderListIndexMatrix.ENUM_VARIABLELOCATION)) { allGood = false; } } foreach (FusionImage_DisplayButton _disp in _Global_List_Graphics_DisplayButton) { if (!Graphics_LocalizeImageForSave(savePath, _disp._path_Primary, ZOrderListIndexMatrix.ENUM_DISPLAYBUTTONS) || !Graphics_LocalizeImageForSave(savePath, _disp._path_Secondary, ZOrderListIndexMatrix.ENUM_DISPLAYBUTTONS) || !Graphics_LocalizeImageForSave(savePath, _disp._path_Disabled, ZOrderListIndexMatrix.ENUM_DISPLAYBUTTONS) || !Graphics_LocalizeImageForSave(savePath, _disp._path_Pushed, ZOrderListIndexMatrix.ENUM_DISPLAYBUTTONS)) { allGood = false; } } foreach (FusionImage_MultiImage _multi in _Global_List_Graphics_MultiImage) { foreach (FusionImage_MultiImage.MultiImageProperties _multi_property in _multi._ImageList) { if (!Graphics_LocalizeImageForSave(savePath, _multi_property._path, ZOrderListIndexMatrix.ENUM_MULTIIMAGES)) { allGood = false; } } } return allGood; } private static bool Graphics_LocalizeImageForSave(string savePath, string input_path, ZOrderListIndexMatrix input_type) { string image_only = Graphics_LocalizeImage(input_path, input_type); if (!Graphics_AlreadySavedLocally.Contains(input_path)) { if (File.Exists(input_path)) { Graphics_AlreadySavedLocally.Add(input_path); if (!File.Exists(savePath + "\\" + image_only)) { File.Copy(input_path, savePath + "\\" + image_only, true); } return true; } else { return false; } } else { return true; } } private static string Graphics_LocalizeImage_TypeToFolder(ZOrderListIndexMatrix input_type) { switch (input_type) { case ZOrderListIndexMatrix.ENUM_BACKGROUND: return "background_images"; case ZOrderListIndexMatrix.ENUM_DISPLAYBUTTONS: return "button_images"; case ZOrderListIndexMatrix.ENUM_MULTIIMAGES: return "multi_images"; case ZOrderListIndexMatrix.ENUM_ROTATEIMAGES: return "rotate_images"; case ZOrderListIndexMatrix.ENUM_STATICIMAGES: return "static_images"; case ZOrderListIndexMatrix.ENUM_VARIABLELOCATION: return "variable_location_images"; default: return ""; } } #endregion #region Generic Graphics Page public class GraphicsPage { public System.Drawing.Bitmap PreviewImage; public int Page; public GraphicsPage(System.Drawing.Bitmap input_image, int input_page) { Page = input_page; PreviewImage = input_image; } } #endregion #region Generic Fusion Image public class FusionImage { public string _name; public string _path; public System.Drawing.Bitmap _image; public List _pages = new List(); public int _x, _y; public int _width, _height; public float _z_order = 0.0f; public float _rotation = 0.0f; //Not done yet... } #endregion #region Background Image public class FusionImage_BackgroundImage { public string _path; public System.Drawing.Bitmap _image; public string _imageLayout = "centre"; public int _page = 0; public FusionImage_BackgroundImage(string input_path, System.Drawing.Bitmap input_image, string input_layout, int input_page) { _path = input_path; _image = input_image; _imageLayout = input_layout; _page = input_page; } } #endregion #region Static Image public class FusionImage_StaticImage : FusionImage { public FusionImage_StaticImage(string input_path, System.Drawing.Bitmap input_image) { _path = input_path; _image = input_image; _name = GetUniqueName(); } public static string GetUniqueName() { int i = 1; while (true) { string possibleName = "Static Image #" + i.ToString(); bool isUnique = true; foreach (FusionImage_StaticImage _static in _Global_List_Graphics_StaticImage) { if (_static._name.ToLower() == possibleName.ToLower()) { isUnique = false; break; } } if (isUnique) { return possibleName; } else { i++; } } } } #endregion #region Axis Enumeration public enum Axis { HORIZONTAL, VERTICAL } #endregion #region Graph public class FusionImage_Graph : FusionImage { public float _value_minimum; public float _value_maximum; //public float _time_minimum; public int _time_maximum; public Axis _graphingAxis = Axis.HORIZONTAL; public string _target = ""; public string _targetID = ""; public int _lineThickness = 2; public Color _lineColour = Color.Black; public string _timer = "logic"; public bool _smooth = false; public bool _forwardBiasNotReverseBias = false; public int _smoothNumbers = 10; public static string GetUniqueName() { int i = 1; while (true) { string possibleName = "My Graph #" + i.ToString(); bool isUnique = true; foreach (FusionImage_Graph _graph in _Global_List_Graphics_Graphs) { if (_graph._name.ToLower() == possibleName.ToLower()) { isUnique = false; break; } } if (isUnique) { return possibleName; } else { i++; } } } } #endregion #region Variable Location Image public class FusionImage_VariableLocationImage : FusionImage { public float _value_minimum; public float _value_maximum; public int _location_minimum; public int _location_maximum; public Axis _translateAround = Axis.HORIZONTAL; public string _target = ""; public string _targetID = ""; public static string GetUniqueName() { int i = 1; while (true) { string possibleName = "Variable Location Image #" + i.ToString(); bool isUnique = true; foreach (FusionImage_VariableLocationImage _varLoc in _Global_List_Graphics_VariableLocationImage) { if (_varLoc._name.ToLower() == possibleName.ToLower()) { isUnique = false; break; } } if (isUnique) { return possibleName; } else { i++; } } } } #endregion #region Multi Image public class FusionImage_MultiImage : FusionImage { public class MultiImageProperties { public float _low = 0.0f; public float _high = 5.0f; public System.Drawing.Bitmap _image; public string _path; } public List _ImageList = new List(); public string _monitor_type = ""; public string _monitor_id = ""; public FusionImage_MultiImage() { } public static string GetUniqueName() { int i = 1; while (true) { string possibleName = "My Multi Image " + i.ToString(); bool isUnique = true; foreach (FusionImage_MultiImage _mi in _Global_List_Graphics_MultiImage) { if (_mi._name.ToLower() == possibleName.ToLower()) { isUnique = false; break; } } if (isUnique) { return possibleName; } else { i++; } } } public void AddImageToList(string input_path, System.Drawing.Bitmap input_image) { MultiImageProperties _tempM = new MultiImageProperties(); _tempM._image = input_image; _tempM._path = input_path; _ImageList.Add(_tempM); } public void AddImageToList(string input_path, System.Drawing.Bitmap input_image, float input_low, float input_high) { MultiImageProperties _tempM = new MultiImageProperties(); _tempM._image = input_image; _tempM._path = input_path; _tempM._low = input_low; _tempM._high = input_high; _ImageList.Add(_tempM); } } #endregion #region Display Button public class FusionImage_DisplayButton : FusionImage { public Vote_VoteClass _MyVote; public string _MyVote_Type = "attached"; public Vote_VoteClass _MyVote_UPCLICK; public string _MyVote_Type_UPCLICK; public string default_state; public int _Time_down = 20; public int _Time_up = 20; public string _path_Primary; public System.Drawing.Bitmap _image_Primary; public string _path_Secondary; public System.Drawing.Bitmap _image_Secondary; public string _path_Pushed; public System.Drawing.Bitmap _image_Pushed; public string _path_Disabled; public System.Drawing.Bitmap _image_Disabled; public string _font_name = ""; public string _font_size = ""; public string _textPrimary = ""; public string _textSecondary = ""; public string _textDisabled = ""; public Color _textPrimaryColour = Color.Black; public Color _textSecondaryColour = Color.Black; public Color _textDisabledColour = Color.Black; public FusionImage_DisplayButton() { } public static string GetUniqueName() { int i = 1; while (true) { string possibleName = "My Display Button " + i.ToString(); bool isUnique = true; foreach (FusionImage_DisplayButton _db in _Global_List_Graphics_DisplayButton) { if (_db._name.ToLower() == possibleName.ToLower()) { isUnique = false; break; } } if (isUnique) { return possibleName; } else { i++; } } } } #endregion #region Fonts public static List _Global_List_Graphics_Fonts = new List(); public static List _Global_List_Graphics_Fonts_ListItems = new List(); public static List Fonts_ToSaveLocally_Names = new List(); public static List _Global_List_Graphics_TextLabels = new List(); public static List _Global_List_Graphics_TextLabels_ListItems = new List(); public struct Font_ToSaveStruct { public string _image; public string _xml; public Font_ToSaveStruct(string input_xml, string input_image) { _xml = input_xml; _image = input_image; } } private static bool Font_ToSaveStruct_Contains(string _compareTo) { foreach (Font_ToSaveStruct _f in Fonts_ToSaveLocally_Names) { if (_f._xml.ToLower() == _compareTo.ToLower()) { return true; } } return false; } public class PseudoFusionFont { public string font_path_XML = ""; public string font_path_Image = ""; public string font_name = ""; public float font_size = 1.0f; public List _uniqueSkinIDs = new List(); public PseudoFusionFont(string xml, string image, float size) { string _name = xml; if (xml.Contains("\\")) { _name = _name.Substring(_name.LastIndexOf('\\') + 1); _name = _name.Split(new char[] { '.' })[0]; } font_path_XML = xml; font_path_Image = image; font_name = _name; font_size = size; } public PseudoFusionFont(string xml, string image, string name, float size) { font_path_XML = xml; font_path_Image = image; font_name = name; font_size = size; } public static string PasPrefix(string inza) { string returnString = inza; if (inza.Contains("\\")) { returnString = returnString.Substring(returnString.LastIndexOf('\\') + 1); } return returnString; } } public struct PsuedoFontBindings { public string _UID; public string _filenameID; public PsuedoFontBindings(string inputUID, string inputFILEID) { _UID = inputUID; _filenameID = inputFILEID; if (_filenameID.Contains(".")) { _filenameID = _filenameID.Split(new char[] { '.' })[0]; } } } public static bool PseudoFont_BindRelations(List input_List) { bool allGood = true; foreach (PsuedoFontBindings _b in input_List) { foreach (FusionFont_TextLabel _t in _Global_List_Graphics_TextLabels) { if (_t._fontName.ToLower() == _b._UID.ToLower()) { _t._fontName = _b._filenameID; } } foreach (FusionImage_DisplayButton _d in _Global_List_Graphics_DisplayButton) { if (_d._font_name.ToLower() == _b._UID.ToLower()) { _d._font_name = _b._filenameID; } } } foreach (FusionFont_TextLabel _t in _Global_List_Graphics_TextLabels) { allGood = (allGood && PseudoFont_BindRelationsCheckThatBounded(_t._fontName, input_List)); } foreach (FusionImage_DisplayButton _d in _Global_List_Graphics_DisplayButton) { allGood = (allGood && PseudoFont_BindRelationsCheckThatBounded(_d._font_name, input_List)); } return allGood; } private static bool PseudoFont_BindRelationsCheckThatBounded(string input_FontName, List input_List) { if (input_FontName == "") { return true; } foreach (PsuedoFontBindings _p in input_List) { if (_p._UID.ToLower() == input_FontName.ToLower()) { return true; } } return false; } public static void Fonts_LocalizeAllFonts_PopulateList() { Fonts_ToSaveLocally_Names.Clear(); foreach (GlobalStaticClass.PseudoFusionFont _globalFont in GlobalStaticClass._Global_List_Graphics_Fonts) { // Check each Display Button foreach (FusionImage_DisplayButton _d in _Global_List_Graphics_DisplayButton) { if (_d._font_name.ToLower() == _globalFont.font_name.ToLower()) { if (!Font_ToSaveStruct_Contains(_globalFont.font_path_XML)) { Fonts_ToSaveLocally_Names.Add(new Font_ToSaveStruct(_globalFont.font_path_XML.ToLower(), _globalFont.font_path_Image)); } } } // Check each Text Label foreach (FusionFont_TextLabel _t in _Global_List_Graphics_TextLabels) { if (_t._fontName.ToLower() == _globalFont.font_name.ToLower()) { if (!Font_ToSaveStruct_Contains(_globalFont.font_path_XML)) { Fonts_ToSaveLocally_Names.Add(new Font_ToSaveStruct(_globalFont.font_path_XML.ToLower(), _globalFont.font_path_Image)); } } } } } public static bool Fonts_LocalizeAllFonts(string savePath) { bool allGood = true; Fonts_LocalizeAllFonts_PopulateList(); if (Fonts_ToSaveLocally_Names.Count == 0) { return allGood; } if (!Directory.Exists(savePath + "\\content\\fonts")) { Directory.CreateDirectory(savePath + "\\content\\fonts"); } foreach (Font_ToSaveStruct _s in Fonts_ToSaveLocally_Names) { if (File.Exists(_s._xml)) { File.Copy(_s._xml, savePath + "\\content\\fonts\\" + PseudoFusionFont.PasPrefix(_s._xml), true); } else { allGood = false; } if (File.Exists(_s._image)) { File.Copy(_s._image, savePath + "\\content\\fonts\\" + PseudoFusionFont.PasPrefix(_s._image), true); } else { allGood = false; } } return allGood; } public static void Fonts_LoadAllFontFiles() { string[] _fonts = Directory.GetFiles(FONT_DIRECTORY, "*.xml"); _Global_List_Graphics_Fonts.Clear(); foreach (string _f in _fonts) { try { FileStream _fs = new FileStream(_f, FileMode.Open, FileAccess.Read); StreamReader _sr = new StreamReader(_fs); string _all = _sr.ReadToEnd(); _sr.Close(); _fs.Close(); XmlDocument _doc = new XmlDocument(); _doc.LoadXml(_all); XmlNode _root = _doc.SelectSingleNode("font"); if (_root != null) { string _xmlPath = _f, _imagePath = ""; float _size = 0.0f; string _imagePathRoot = FONT_DIRECTORY; XmlNode _imagePathFiles = _root.Attributes.GetNamedItem("fontImage"); if (_imagePathFiles != null) { _imagePath = _imagePathRoot + "\\" + _imagePathFiles.Value; } else { continue; } XmlNodeList _fontCharacters = _root.SelectNodes("char"); int totalHeight = 0; foreach (XmlNode _n in _fontCharacters) { XmlNode _n1 = _n.Attributes.GetNamedItem("location_topleft"); XmlNode _n2 = _n.Attributes.GetNamedItem("location_bottomright"); if (_n1 != null && _n2 != null) { int _tempHeight1 = 0, _tempHeight2 = 0, _tempHeight = 0; int.TryParse(((_n1.Value).Split(new char[] { ',' }))[1], out _tempHeight1); int.TryParse(((_n2.Value).Split(new char[] { ',' }))[1], out _tempHeight2); _tempHeight = _tempHeight2 - _tempHeight1; totalHeight += _tempHeight; } } _size = totalHeight / _fontCharacters.Count; _Global_List_Graphics_Fonts.Add(new PseudoFusionFont(_xmlPath, _imagePath, _size)); } } catch (Exception) { } } } #endregion #region Text Labels public class FusionFont_TextLabel : FusionImage { //public string _id = ""; public string _text = ""; public string _fontName = ""; public float _fontSize = 12.0f; //public int _x = 0, _y = 0; //public float _z = 0.0f; //public List _pages = new List(); public Color _colour = Color.Black; public string _autoMonitor = ""; public string _autoMonitorTargetID = ""; public int _maxDecimals = 1; //public int _maxWidth = 100, _maxHeight = 20; } #endregion #endregion #region Speech public static bool Speech_MasterEnable = false; public static bool Speech_EnableGlobalPolite = true; public static List AllPossibleSpeechStrings = new List(); public class Speech_Response { public string beginnning = "", ending = ""; public Speech_Response(string input_beginning, string input_ending) { beginnning = input_beginning; ending = input_ending; } } public static class Speech_StaticSetupClass { public class customQuery { public List possible_responses = new List(); public string monitor_type = ""; public string monitor_id = ""; public List builder_beginnings = new List(); public List builder_middles = new List(); public List builder_endings = new List(); } public class customDefinition { public string systemName = ""; public string spokenName = ""; } public static List generic_system = new List(); public static List generic_digital_output_turn_on = new List(); public static List generic_digital_output_turn_off = new List(); public static List generic_digital_output = new List(); public static List generic_analogue_input_read = new List(); public static List generic_analogue_input = new List(); public static List custom_query_list = new List(); public static List custom_definition_digital_outputs = new List(); public static List custom_definition_variables = new List(); } public enum SpeechDirection { QUERY, RESPONSE, GLOBAL } public class SpeechPossibility { public string monitor_type = ""; public string monitor_id = ""; public string vote_opinion = ""; public SpeechDirection response_or_query; public List possible_responses = new List(); public List possible_queries = new List(); public SpeechPossibility() { } public SpeechPossibility(List input_responses, List input_queries) { response_or_query = SpeechDirection.GLOBAL; possible_responses = new List(input_responses.ToArray()); possible_queries = new List(input_queries.ToArray()); } } #endregion #region Debugging public static bool Debug_MasterEnable = false; public static bool Debug_IfThenWindow = false; public static bool Debug_VariableWindow = false; public static bool Debug_SpeechWindow = false; public static List Debug_VirtualBrainList = new List(); #endregion #region Remote Control public static class RemoteControlProperties { public static string userName = "default"; public static int port = 4242; public static bool enabled = false; } #endregion } }