using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Xml; using System.IO; using System.Runtime.InteropServices; using PVOID = System.IntPtr; using DWORD = System.UIntPtr; using Microsoft.Win32; using Microsoft.DirectX; using Microsoft.DirectX.Direct3D; using System.Speech; using System.Speech.Recognition; using System.Speech.Synthesis; using System.Threading; using LibUsbDotNet; using LibUsbDotNet.Usb; namespace Fusion_Control_Centre_UberMDX { public partial class MainMDX : Form { #region Vote Opinion /// /// Vote Opinion of yes, no, or indifferent /// public enum Vote_Opinion { OUI, NON, MEH } #endregion #region Vote Priority /// /// Vote Priority of either high, medium, or low /// public enum Vote_Priority { HIGH_PRIORITY, MEDIUM_PRIORITY, LOW_PRIORITY } #endregion #region Window Handle Class public class wndArrayClass { public IntPtr hWnd = IntPtr.Zero; public string title = ""; public wndArrayClass(IntPtr inputHwd, string inputTitle) { hWnd = inputHwd; title = inputTitle; } } #endregion #region Logical Vote /// /// Logical Vote contains both an Opinion and a Priority /// Opinion: What it thinks it should do in the form of yes/no/indifferent /// Priority: How important its opinion is by rank of high/medium/low /// public struct LogicalVote { public Vote_Opinion MyLogicalOpinion; public Vote_Priority MyLogicalPriority; public object toWhat; } #endregion #region Functions /// /// Usually external "macros" of a sort that have input parameters and return a value /// public struct Functions { public XmlNode rawFunction; public string functionName; } #endregion #region Logic public class Logic_Struct { public XmlNode _logicNode = null; public DateTime _logicLastVoteTime = DateTime.MinValue; public int _logicMinimumTimeBetweenVotes = 20; public Logic_Struct(XmlNode _Node, int _TimeBetween) { _logicNode = _Node; _logicMinimumTimeBetweenVotes = _TimeBetween; } } #endregion #region Variable /// /// Has the name by which functions and if/then statements call it by as well as the value. /// Can be either a double or boolean value /// public class Variable { public object variableValue; public string variableReferenceName; public List WhatShouldMyValueBe = new List(); public Variable(string input_referenceName, object input_value) { variableValue = input_value; variableReferenceName = input_referenceName; } } #endregion #region Log /// /// Each item to monitor to a log file /// public class LogClass { public string logReferenceName; public string toMonitorName; public string toMonitorType; public string fireOnString = "logic"; public string saveToFile = "Fusion Control Centre Log File"; public bool monitorState = false; public int NumberToLogBeforeDumping = 100; public bool HoldingAStreamOpen = false; public int StreamIndex = -1; public string dataName = "Logged Value"; public string dataFrom = "value"; public List ShouldIBeLogging = new List(); public List MyDataPoints = new List(); public LogClass(string input_name, string input_monitorname, string input_monitortype, string input_fireOn) { logReferenceName = input_name; toMonitorName = input_monitorname; toMonitorType = input_monitortype; fireOnString = input_fireOn; } } #endregion #region Log Streams public class LogFileStream { public System.IO.FileStream MyFileStream; public System.IO.StreamWriter MyStreamWriter; public System.IO.StreamReader MyStreamReader; public string CurrentData = ""; public LogFileStream(string input_stream_path) { MyFileStream = new System.IO.FileStream(input_stream_path + ".xml", System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite); MyStreamReader = new System.IO.StreamReader(MyFileStream); MyStreamWriter = new System.IO.StreamWriter(MyFileStream); CurrentData = MyStreamReader.ReadToEnd(); MyStreamReader.Close(); } } #endregion #region Log Data Point public class LogDataPoint { public DateTime StoredDate = DateTime.Now; public object StoredData = null; public string StoredName = ""; public LogDataPoint(object newData, string newName) { StoredData = newData; StoredName = newName; } public string GenerateXMLNode() { string newLogNode_String = " \r\n"; newLogNode_String += " " + StoredDate.ToLongDateString() + "\r\n"; newLogNode_String += " \r\n"; newLogNode_String += " " + StoredName + "\r\n"; newLogNode_String += " " + StoredData.ToString() + "\r\n"; newLogNode_String += " \r\n"; return newLogNode_String; } } #endregion #region COM Command public class COM_Command { public string id = ""; public DateTime last_vote = DateTime.MinValue; public int minimum_delta_vote_time = 0; public List do_statements = new List(); public COM_Command(string input_id) { id = input_id; } } #endregion #region Other Voting Options public static List CanDo_ShouldIChangePage = new List(); public static List CanDo_ShouldIChangeGUITimer = new List(); public static List CanDo_ShouldIChangeLogicTimer = new List(); //List CanDo_ShouldIChangeOutputTimer = new List(); //List CanDo_ShouldIChangeInputTimer = new List(); public static List CanDo_ShouldIChangeIOTimer = new List(); public static List CanDo_ShouldIChangeLogging = new List(); public static List CanDo_ShouldIPressAKey = new List(); public static List CanDo_ShouldIPlayASound = new List(); public static List CanDo_ShouldIGiveAWarning = new List(); public static List CanDo_ShouldISendAnEmail = new List(); #endregion #region BrainVersion public enum BrainVersion { Version_03, Version_04 } #endregion #region BrainID /// /// Each Fusion Brain connected to the PC has a hardware instance ID /// as well as a human name that can be referenced in functions and /// if/then statements /// public class BrainID { public string instanceID; public string humanName; public UsbDevice Device; public UsbEndpointWriter Stream_Writer; public UsbEndpointReader Stream_Reader; public BrainVersion version; //public string version_string_supposed_to_be = ""; public string Accurate_AnalogueScalingInput_Index_ReferenceID = ""; public int Accurate_AnalogueScalingInput_Index = -1; private int[] AnalogueInputIndexArray_03 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; private int[] DigitalOutputIndexArray_03 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; private int[] DigitalInputIndexArray_03 = { -1, -1, -1, -1 }; private int[] AnalogueInputIndexArray_04 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; private int[] DigitalOutputIndexArray_04 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; private int[] DigitalInputIndexArray_04 = { }; public int[] AnalogueInputIndexArray_EX; public int[] DigitalOutputIndexArray_EX; public int[] DigitalInputIndexArray_EX; public bool InitializeVersion(BrainVersion input_BrainVersion) { version = input_BrainVersion; switch (input_BrainVersion) { case BrainVersion.Version_03: AnalogueInputIndexArray_EX = AnalogueInputIndexArray_03; DigitalOutputIndexArray_EX = DigitalOutputIndexArray_03; DigitalInputIndexArray_EX = DigitalInputIndexArray_03; return true; case BrainVersion.Version_04: AnalogueInputIndexArray_EX = AnalogueInputIndexArray_04; DigitalOutputIndexArray_EX = DigitalOutputIndexArray_04; DigitalInputIndexArray_EX = DigitalInputIndexArray_04; return true; default: return false; } } } #endregion #region Physical Relations public const int FUSIONBRAIN_NUMBEROF_DIGITAL_OUTPUTS_VERSION_03 = 12; public const int FUSIONBRAIN_NUMBEROF_ANALOGUE_INPUTS_VERSION_03 = 10; public const int FUSIONBRAIN_NUMBEROF_DIGITAL_INPUTS_VERSION_03 = 4; public const int FUSIONBRAIN_NUMBEROF_DIGITAL_OUTPUTS_VERSION_04 = 16; public const int FUSIONBRAIN_NUMBEROF_ANALOGUE_INPUTS_VERSION_04 = 13; public const int FUSIONBRAIN_NUMBEROF_DIGITAL_INPUTS_VERSION_04 = 0; public static int FUSIONBRAIN_NUMBER_OF_DIGITAL_OUTPUTS(BrainVersion version) { switch (version) { case BrainVersion.Version_03: return FUSIONBRAIN_NUMBEROF_DIGITAL_OUTPUTS_VERSION_03; case BrainVersion.Version_04: return FUSIONBRAIN_NUMBEROF_DIGITAL_OUTPUTS_VERSION_04; default: return 0; } } public static int FUSIONBRAIN_NUMBER_OF_ANALOGUE_INPUTS(BrainVersion version) { switch (version) { case BrainVersion.Version_03: return FUSIONBRAIN_NUMBEROF_ANALOGUE_INPUTS_VERSION_03; case BrainVersion.Version_04: return FUSIONBRAIN_NUMBEROF_ANALOGUE_INPUTS_VERSION_04; default: return 0; } } public static int FUSIONBRAIN_NUMBER_OF_DIGITAL_INPUTS(BrainVersion version) { switch (version) { case BrainVersion.Version_03: return FUSIONBRAIN_NUMBEROF_DIGITAL_INPUTS_VERSION_03; case BrainVersion.Version_04: return FUSIONBRAIN_NUMBEROF_DIGITAL_INPUTS_VERSION_04; default: return 0; } } #endregion #region MDX Image DirectX or GDI+ public bool MDX_use_GDI_not_DX = false; public Graphics MDX_GDI_Graphics; public Bitmap MDX_GDI_DisplayBitmap; public class FusionImage_BitmapOrTexture { public Texture MDX_FusionTexture; public Image MDX_FusionBitmap; } #endregion #region MDX Image Generic public class FusionImage { public FusionImage_BitmapOrTexture MDX_Image = new FusionImage_BitmapOrTexture(); //public Texture MDX_FusionTexture; public ImageInformation MDX_FusionTextureInformation; public Sprite MDX_InternalSprite = null; //public Graphics MDX_InternalGraphics_GDI = null; public Point MDX_Position = new Point(0, 0); public Vector2 MDX_Scale = new Vector2(1.0f, 1.0f); public float MDX_Rotation = 0.0f; public Point MDX_Origin = new Point(0, 0); public bool doesNotRequireTexture = false; #region Draw 2D Texture to 3D Universe... public void Draw(bool GDI_not_DX, Vector2 _AppScaling, Graphics _GraphicLayer) { if (GDI_not_DX) { if (_GraphicLayer == null || MDX_Image.MDX_FusionBitmap == null) { return; } else { Image _2use = MDX_Image.MDX_FusionBitmap; if (MDX_Rotation != 0.0f) { _2use = RotateImage(MDX_Image.MDX_FusionBitmap, MDX_Rotation); } int x = 0, y = 0, w = 0, h = 0; x = (int)((float)MDX_Position.X * ((float)_AppScaling.X)); y = (int)((float)MDX_Position.Y * ((float)_AppScaling.Y)); w = (int)((float)MDX_Image.MDX_FusionBitmap.Width * (float)_AppScaling.X * (float)MDX_Scale.X); h = (int)((float)MDX_Image.MDX_FusionBitmap.Height * (float)_AppScaling.Y * (float)MDX_Scale.Y); _GraphicLayer.DrawImage(_2use, new Rectangle(x, y, w, h)); //_GraphicLayer.DrawRectangle(Color.FromArgb(new Random().Next()), new Rectangle(x, y, w, h)); } } else { if (MDX_Image.MDX_FusionTexture == null) { return; } else { Matrix _MatrixScaleSprite = new Matrix(); MDX_InternalSprite.Transform = Matrix.Translation(-MDX_Position.X - MDX_FusionTextureInformation.Width / 2, -MDX_Position.Y - MDX_FusionTextureInformation.Height / 2, 0f) * Matrix.Scaling(MDX_Scale.X, MDX_Scale.Y, 1.0f) * Matrix.RotationZ(MDX_Rotation) * Matrix.Translation(MDX_Position.X + MDX_Scale.X * MDX_FusionTextureInformation.Width / 2, MDX_Position.Y + MDX_Scale.Y * MDX_FusionTextureInformation.Height / 2, 0f) * Matrix.Scaling(_AppScaling.X, _AppScaling.Y, 1.0f); MDX_InternalSprite.Begin(SpriteFlags.AlphaBlend); Vector3 _tempDrawPoint = new Vector3((float)(MDX_Position.X), (float)(MDX_Position.Y), 0.0f); MDX_InternalSprite.Draw(MDX_Image.MDX_FusionTexture, Rectangle.Empty, new Vector3((float)MDX_Origin.X, (float)MDX_Origin.Y, 0.0f), _tempDrawPoint, Color.White); MDX_InternalSprite.End(); return; } } } public void DrawGraph(bool GDI_not_DX, Vector2 _AppScaling, Vector2 ShowSize, CustomVertex.PositionColored[] DataPoints, Color LineColour, int LineWidth, Graphics GraphicsLayer) { if (!doesNotRequireTexture) { return; } if (GDI_not_DX) { List _tempListPoints = new List(); for (int i = 0; i < DataPoints.Length; i++) { _tempListPoints.Add(new PointF(DataPoints[i].X, DataPoints[i].Y)); } GraphicsLayer.DrawLines(new Pen(LineColour, (float)LineWidth), _tempListPoints.ToArray()); } else { Matrix _MatrixScaleSprite = new Matrix(); MDX_InternalSprite.Transform = Matrix.Translation(-MDX_Position.X - ShowSize.X / 2, -MDX_Position.Y - ShowSize.Y / 2, 0f) * Matrix.Scaling(MDX_Scale.X, MDX_Scale.Y, 1.0f) * Matrix.RotationZ(MDX_Rotation) * Matrix.Translation(MDX_Position.X + MDX_Scale.X * ShowSize.X / 2, MDX_Position.Y + MDX_Scale.Y * ShowSize.Y / 2, 0f) * Matrix.Scaling(_AppScaling.X, _AppScaling.Y, 1.0f); MDX_InternalSprite.Begin(SpriteFlags.AlphaBlend); Vector3 _tempDrawPoint = new Vector3((float)(MDX_Position.X), (float)(MDX_Position.Y), 0.0f); MDX_InternalSprite.Device.VertexFormat = CustomVertex.PositionColored.Format; MDX_InternalSprite.Device.DrawUserPrimitives(PrimitiveType.LineStrip, DataPoints.Length - 1, DataPoints); MDX_InternalSprite.End(); } } public void DrawPortionAndOrAsFont(bool GDI_not_DX, Vector2 Font_Scaling, Point input_position, Rectangle input_Rectangle, Color input_Colour, Vector2 _AppScaling, Graphics GraphicsLayer) { if (!GDI_not_DX) { if (MDX_Image.MDX_FusionTexture == null) { return; } if (input_Rectangle == Rectangle.Empty) { } Matrix _MatrixScaleSprite = new Matrix(); MDX_InternalSprite.Transform = Matrix.Translation(-input_position.X - input_Rectangle.Width / 2, -input_position.Y - input_Rectangle.Height / 2, 0f) * Matrix.RotationZ(MDX_Rotation) * Matrix.Scaling(Font_Scaling.X, Font_Scaling.Y, 1.0f) * Matrix.Translation(input_position.X + Font_Scaling.X * input_Rectangle.Width / 2, input_position.Y + Font_Scaling.Y * input_Rectangle.Height / 2, 0f) * Matrix.Scaling(_AppScaling.X, _AppScaling.Y, 1.0f); MDX_InternalSprite.Begin(SpriteFlags.AlphaBlend); Vector3 _tempDrawPoint = new Vector3((float)(input_position.X), (float)(input_position.Y), 0.0f); MDX_InternalSprite.Draw(MDX_Image.MDX_FusionTexture, input_Rectangle, new Vector3((float)MDX_Origin.X, (float)MDX_Origin.Y, 0.0f), _tempDrawPoint, input_Colour); MDX_InternalSprite.End(); } else { Rectangle _size = new Rectangle((int)((float)input_position.X * _AppScaling.X), (int)((float)input_position.Y * _AppScaling.Y), (int)((float)input_Rectangle.Width * _AppScaling.X * Font_Scaling.X), (int)((float)input_Rectangle.Height * _AppScaling.Y * Font_Scaling.Y)); GraphicsLayer.DrawImage(MDX_Image.MDX_FusionBitmap, _size, input_Rectangle, GraphicsUnit.Pixel); } } #endregion #region Constructor & Overloads public FusionImage(Device input_Device, bool noTextureNeeded) { MDX_InternalSprite = new Sprite(input_Device); doesNotRequireTexture = noTextureNeeded; } public FusionImage(MDX_TextureLoadingReturnClass input_MDXRC, Device input_Device) { MDX_Image.MDX_FusionTexture = input_MDXRC._Texture; MDX_Image.MDX_FusionBitmap = input_MDXRC._Bitmap; MDX_FusionTextureInformation = input_MDXRC._Info; MDX_InternalSprite = new Sprite(input_Device); } public FusionImage(MDX_TextureLoadingReturnClass input_MDXRC, float input_Rotation, Device input_Device) { MDX_Image.MDX_FusionTexture = input_MDXRC._Texture; MDX_Image.MDX_FusionBitmap = input_MDXRC._Bitmap; MDX_FusionTextureInformation = input_MDXRC._Info; MDX_Rotation = input_Rotation; MDX_InternalSprite = new Sprite(input_Device); } #endregion #region Reset Sprites with New Device public void SetNewSpriteDevice(Device newDevice) { MDX_InternalSprite = new Sprite(newDevice); } #endregion #region RotateGDI [DIRECT IMPORT FROM FCC VERSION 2] public static Bitmap RotateImage(Image image, float angle) { if (image == null) throw new ArgumentNullException("image"); const double pi2 = Math.PI / 2.0; double oldWidth = (double)image.Width; double oldHeight = (double)image.Height; double theta = ((double)angle) * Math.PI / 180.0; double locked_theta = theta; while (locked_theta < 0.0) locked_theta += 2 * Math.PI; double newWidth, newHeight; int nWidth, nHeight; double adjacentTop, oppositeTop; double adjacentBottom, oppositeBottom; if ((locked_theta >= 0.0 && locked_theta < pi2) || (locked_theta >= Math.PI && locked_theta < (Math.PI + pi2))) { adjacentTop = Math.Abs(Math.Cos(locked_theta)) * oldWidth; oppositeTop = Math.Abs(Math.Sin(locked_theta)) * oldWidth; adjacentBottom = Math.Abs(Math.Cos(locked_theta)) * oldHeight; oppositeBottom = Math.Abs(Math.Sin(locked_theta)) * oldHeight; } else { adjacentTop = Math.Abs(Math.Sin(locked_theta)) * oldHeight; oppositeTop = Math.Abs(Math.Cos(locked_theta)) * oldHeight; adjacentBottom = Math.Abs(Math.Sin(locked_theta)) * oldWidth; oppositeBottom = Math.Abs(Math.Cos(locked_theta)) * oldWidth; } newWidth = adjacentTop + oppositeBottom; newHeight = adjacentBottom + oppositeTop; nWidth = (int)Math.Ceiling(newWidth); nHeight = (int)Math.Ceiling(newHeight); Bitmap rotatedBmp = new Bitmap(nWidth, nHeight); using (Graphics g = Graphics.FromImage(rotatedBmp)) { Point[] points; if (locked_theta >= 0.0 && locked_theta < pi2) { points = new Point[] { new Point( (int) oppositeBottom, 0 ), new Point( nWidth, (int) oppositeTop ), new Point( 0, (int) adjacentBottom ) }; } else if (locked_theta >= pi2 && locked_theta < Math.PI) { points = new Point[] { new Point( nWidth, (int) oppositeTop ), new Point( (int) adjacentTop, nHeight ), new Point( (int) oppositeBottom, 0 ) }; } else if (locked_theta >= Math.PI && locked_theta < (Math.PI + pi2)) { points = new Point[] { new Point( (int) adjacentTop, nHeight ), new Point( 0, (int) adjacentBottom ), new Point( nWidth, (int) oppositeTop ) }; } else { points = new Point[] { new Point( 0, (int) adjacentBottom ), new Point( (int) oppositeBottom, 0 ), new Point( (int) adjacentTop, nHeight ) }; } g.DrawImage(image, points); } return rotatedBmp; } #endregion } #endregion #region MDX Texture Loading Return Class public struct MDX_TextureLoadingReturnClass { public Texture _Texture; public ImageInformation _Info; public Image _Bitmap; public MDX_TextureLoadingReturnClass(Texture input_Texture, ImageInformation input_Info, Image input_Bitmap) { _Texture = input_Texture; _Info = input_Info; _Bitmap = input_Bitmap; } } #endregion #region MDX Texture Loading Time Saver Lookup Table public struct MDX_TextureLoadLookupStruct { public string _path; public Texture loadedTexture; public Image loadedBitmap; public ImageInformation loadedInfo; public MDX_TextureLoadLookupStruct(string input_path, Texture input_Texture, ImageInformation input_Info, Image input_Bitmap) { _path = input_path; loadedTexture = input_Texture; loadedInfo = input_Info; loadedBitmap = input_Bitmap; } } #endregion #region Background Images /// /// Each background image has a set page to display on, an image to display, /// and a style as to how to display the image (tile/strech/centre) /// public struct BackgroundImageForDisplay { public FusionImage theImage; public int thePage; public ImageLayout theImageLayout; } #endregion #region Display Button Generic public class DisplayButton { public List DisplayPage = new List(); public bool isPressed = false; public bool isBeingClicked = false; public bool isEnabled = true; public FusionImage MDX_Primary = null; public FusionImage MDX_Secondary = null; public FusionImage MDX_Disabled = null; public FusionImage MDX_Pushed = null; public int MDX_x_left = -1; public int MDX_x_right = -1; public int MDX_y_top = -1; public int MDX_y_bottom = -1; public Vector2 toScale_ApplicationBy = new Vector2(1.0f, 1.0f); public float MDX_DisplayDepth = 0.0f; public Size DisplaySize = new Size(50, 50); public Point DeButtonLocation = new Point(0, 0); //public ImageLayout DeButtonsImageLayout = ImageLayout.None; public string id; public DateTime Time_lastDownVote = DateTime.MinValue; public DateTime Time_lastUpVote = DateTime.MinValue; public int Time_MinDeltaDownVote = 20; public int Time_MinDeltaUpVote = 20; public string functionString; public string functionTarget; public string toMonitor = ""; public string toMonitorType = ""; public string voteOpinion; public string voteType; public bool upClick_Enable = false; public string upClick_Function; public string upClick_FunctionTargetID; public string upClick_VoteOpinion; public string upClick_VoteType; public Vote_Priority upClick_VotePriority = Vote_Priority.MEDIUM_PRIORITY; public DisplayTextLabel TextPrimary = new DisplayTextLabel(); public DisplayTextLabel TextSecondary = new DisplayTextLabel(); public DisplayTextLabel TextDisabled = new DisplayTextLabel(); public double threshold_Low = -1; public double threshold_High = -1; public Vote_Priority votePriority = Vote_Priority.MEDIUM_PRIORITY; public List ShouldIBeEnabled = new List(); public DisplayButton() { } public void UpdateBounds(FusionImage CurrentImage, bool GDI_not_DX) { int _w = 0, _h = 0; if (GDI_not_DX) { if (CurrentImage.MDX_Image.MDX_FusionBitmap != null) { _w = CurrentImage.MDX_Image.MDX_FusionBitmap.Width; _h = CurrentImage.MDX_Image.MDX_FusionBitmap.Height; } } else { if (CurrentImage.MDX_Image.MDX_FusionTexture != null) { _w = CurrentImage.MDX_FusionTextureInformation.Width; _h = CurrentImage.MDX_FusionTextureInformation.Height; } } int c_width = (int)(_w * CurrentImage.MDX_Scale.X * toScale_ApplicationBy.X); int c_height = (int)(_h * CurrentImage.MDX_Scale.Y * toScale_ApplicationBy.Y); MDX_x_left = (int)(DeButtonLocation.X * toScale_ApplicationBy.X); MDX_x_right = (int)(DeButtonLocation.X * toScale_ApplicationBy.X) + c_width; MDX_y_top = (int)(DeButtonLocation.Y * toScale_ApplicationBy.Y); MDX_y_bottom = (int)(DeButtonLocation.Y * toScale_ApplicationBy.Y) + c_height; } } #endregion #region Multi Image (DisplayButton) public class DisplayMultiImage : DisplayButton { public List MultipleImageList = new List(); public DisplayMultiImage(string input_id, string input_monitor, string input_toMonitor) { id = input_id; toMonitor = input_monitor; toMonitorType = input_toMonitor; } } #endregion #region Rotating Image (Display Button) public class DisplayRotateImageCentre : DisplayButton { public struct DisplayRotateImageValues { public double value_minimum; public double value_maximum; public double angle_minimum; public double angle_maximum; } public bool streakImage = false; public double maximumAngleStride = 0.5f; public bool smoothRotating = false; public double currentAngle = -1f; public List MultipleAngleList = new List(); public DisplayRotateImageCentre(string input_id, string input_monitor, string input_toMonitor) { id = input_id; toMonitor = input_monitor; toMonitorType = input_toMonitor; //DeButton.AutoSize = false; } } #endregion #region Static Image public class DisplayStaticImage { public FusionImage MDX_StaticImage = null; public List DisplayPages = new List(); public Point DisplayLocation = new Point(0, 0); public Vector2 DisplayScaling = new Vector2(1.0f, 1.0f); public Size DisplaySize = new Size(0, 0); public float MDX_DisplayDepth = 0.0f; } #endregion #region Display Text Label public class DisplayTextLabel { public Color FontColour = Color.White; public string FontText = ""; public float FontSize = 12.0f; public string FontName = ""; public Point LabelLocation = new Point(0, 0); public Vector4 LabelBounds; public bool isCompletelySetup() { if (FontName == "") { return false; } return true; } } #endregion #region Auto Display Text Label public class DisplayTextLabelAuto : DisplayTextLabel { public string id = ""; public string monitor_type = ""; public string monitor_id = ""; public List pageList = new List(); public int LabelDecimalPrecision = 1; public Point LabelMaxSize = new Point(1, 1); public string FontText_Original = ""; public DisplayTextLabelAuto(string input_id, string input_type, string input_monitorid, string input_text) { id = input_id; monitor_type = input_type; monitor_id = input_monitorid; FontText = input_text; FontText_Original = input_text; } } #endregion #region DisplayFusionFont public class FusionFont { public class FusionFont_Character { public Rectangle CroppingLocation = new Rectangle(); public int CharacterIntCode = -1; public Vector4 CharacterOffsetVector = new Vector4(0.0f, 0.0f, 0.0f, 0.0f); public FusionFont_Character(Rectangle input_rectangle, int input_IntCode, Vector4 input_Offset) { CroppingLocation = input_rectangle; CharacterIntCode = input_IntCode; CharacterOffsetVector = input_Offset; } } public string FusionFontName = ""; public FusionImage FusionFontMainImage = null; public float FusionFontOriginalSize = 100.0f; public List FusionFont_CharDefinitions = new List(); } public struct FontDisplayReturnValue { public Vector4 _Offset; public Rectangle _Rectangle; public FontDisplayReturnValue(Rectangle _iRect, Vector4 _iVect4) { _Offset = _iVect4; _Rectangle = _iRect; } } #endregion #region Fusion Graph public class DisplayFusionGraph : DisplayStaticImage { //public enum DATA_POINT {X,Y}; public string id = ""; public string timer = "logic timer"; public float value_minimum; public float value_maximum; //public int time_minimum; public float time_maximum; public Axis graphingAxis = Axis.HORIZONTAL; public string target = ""; public string targetID = ""; public int lineThickness = 2; public Color lineColour = Color.Black; //public List DataPoints = new List(); public List DataPoints = new List(); public bool smooth = false; public bool forwardBiasNotReverseBias = false; public int smoothNumbers = 10; } #endregion #region Axis Enumeration public enum Axis { HORIZONTAL, VERTICAL } #endregion #region Variable Location Image (Static Image) public class DisplayVariableLocationImage : DisplayStaticImage { 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 = ""; } #endregion #region All GUI Z-Ordering public struct 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_VARAIBLELOCATION, ENUM_GRAPH } #endregion #region Input/Output Channel Generic public class Channel { public string BrainID; public int Port; public string id; } #endregion #region Digital Output Channel (Channel) public class DigitalOutputChannel : Channel { public enum DigitalOutputChannel_Mode { STANDARD = 0, PULSE_WIDTH_MODULATION, OPTION_1, // Not decided yet OPTION_2 // Not decided yet } public bool CurrentState = false; public bool PreviousState = false; public List ShouldIChangeState = new List(); public int TimerValue = 0; public int PWM_Value = 127; public DigitalOutputChannel_Mode Mode = DigitalOutputChannel_Mode.STANDARD; public DigitalOutputChannel(string input_BrainID, string input_ID, int input_Port) { BrainID = input_BrainID; id = input_ID; Port = input_Port; } } #endregion #region Analogue Input Channel (Channel) public class AnalogueInputChannel : Channel { public double CurrentValue = 0.0f; public int maximumHistory = 200; public List HistoryValues = new List(); public bool autoAverage = false; public AnalogueInputChannel(string input_BrainID, string input_ID, int input_Port) { BrainID = input_BrainID; id = input_ID; Port = input_Port; } } #endregion #region Digital Input Channel (Channel) public class DigitalInputChannel : Channel { public bool CurrentState; public bool PreviousState; public DigitalInputChannel(string input_BrainID, string input_ID, int input_Port) { BrainID = input_BrainID; id = input_ID; Port = input_Port; } } #endregion #region GUI Lists public static List AllZOrder_QuelleListe = new List(); public static List AllMDXTexturePathOptimization = new List(); public static List AllDisplayButtons = new List(); public static List AllDisplayMultiImages = new List(); public static List AllDisplayRotateImage = new List(); public static List AllBackgroundImages = new List(); public static List AllStaticImages = new List(); public static List AllStaticVariableLocationImages = new List(); public static List AllTextLabels = new List(); public static List AllGraphs = new List(); public static List AllFusionFonts = new List(); #endregion #region Logic Lists public static List AllLogicXMlNodes = new List(); public static List AllFunctions = new List(); public static List AllVariables = new List(); public static List AllLogClasses = new List(); public static List AllLogFileStreams = new List(); public static List wndArrayComplete = new List(); public static List AllCOMCommands = new List(); #endregion #region Input/Output Lists public static List AllBrains = new List(); public static List AllDigitalOutputs = new List(); public static List AllAnalogueInputs = new List(); public static List AllDigitalInputs = new List(); #endregion #region Virtual Brain public class VirtualBrainClass { public string _human; public DEBUG_VirtualBrain _Form_03 = null; public DEBUG_VirtualBrain_Version04 _Form_04 = null; public BrainVersion _version; public VirtualBrainClass(string id) { _human = id; } public static bool isAVirtualBrain(string _id) { foreach (VirtualBrainClass _vb in DEBUG_VirtualBrainList) { if(_vb._human.ToLower() == _id.ToLower()) { return true; } } return false; } public bool Initialize(BrainVersion myVersion, MainMDX mYmomma) { _version = myVersion; switch(_version) { case BrainVersion.Version_03: { DEBUG_VirtualBrain _tempDVB = new DEBUG_VirtualBrain(mYmomma, _human); DEBUG_FormsToShow.Add((Form)_tempDVB); return true; } case BrainVersion.Version_04: { DEBUG_VirtualBrain_Version04 _tempDVB = new DEBUG_VirtualBrain_Version04(_human, mYmomma); DEBUG_FormsToShow.Add((Form)_tempDVB); return true; } } return false; } } public static List DEBUG_VirtualBrainList = new List(); #endregion #region Timers private static System.Windows.Forms.Timer LogicTimer = new System.Windows.Forms.Timer(); private static System.Windows.Forms.Timer IO_Timer = new System.Windows.Forms.Timer(); private static System.Windows.Forms.Timer GUI_Timer = new System.Windows.Forms.Timer(); //System.Windows.Forms.Timer OutputTimer = new System.Windows.Forms.Timer(); //System.Windows.Forms.Timer InputTimer = new System.Windows.Forms.Timer(); #endregion #region Threads Thread THREAD_Logic; Thread THREAD_IO; //Thread THREAD_GUI; //Thread THREAD_INPUT; //Thread THREAD_OUTPUT; #endregion #region Misc. Globals public static List
DEBUG_FormsToShow = new List(); public static int THREAD_IO_SLEEP_INTERVAL = 75; public static int THREAD_LOGIC_SLEEP_INTERVAL = 75; public static int CurrentPage = 0; public int PreviousPage = -1; public int Application_Width = -1; public int Application_Height = -1; public int Application_Original_Width = -1; public int Application_Original_Height = -1; public bool Debug_EnableDebugWindow = false; public Vector2 Application_isBeingScaledBy = new Vector2(1.0f, 1.0f); public Sprite MDX_Sprite_BackgroundImages; public Sprite MDX_Sprite_NormalLayer; public Device MDX_Device; public PresentParameters MDX_PresentParameters = null; public Color MDX_ClearColour = Color.White; SplashScreenForm _SCF = null; public int Splash_LoadedTextures = 0; public bool RunProgramInSystemTray = false; public bool MinimizeToSystemTray = true; public static Random MDX_Random = new Random(42); public bool useThreading = true; public int MAX_PAGE = -1; public bool COM_checkCommunication = true; #endregion #region Speech public static SpeechSynthesizer Speech_MainSynthesizer = new SpeechSynthesizer(); public static SpeechRecognitionEngine Speech_MainRecognizer = new SpeechRecognitionEngine(); public static bool Speech_MasterEnable = false; public static bool Speech_CurrentlyEnabled = false; public static bool Speech_EnableGlobalPolite = true; public static List AllSpeechCommands = new List(); public List DEBUG_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 Misc. DLL Declarations [DllImport("User32.dll")] public static extern Int32 FindWindow(String lpClassName, String lpWindowName); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int SendMessage(int hWnd, int msg, int wParam, IntPtr lParam); [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle); [DllImport("winmm.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] public static extern bool PlaySound(string pszSound, IntPtr hMod, SoundFlags sf); [DllImport("user32.dll")] private static extern int GetWindowText(int hWnd, StringBuilder title, int size); [DllImport("user32.dll")] private static extern int GetWindowModuleFileName(int hWnd, StringBuilder title, int size); [DllImport("user32.dll")] private static extern int EnumWindows(EnumWindowsProc ewp, int lParam); [DllImport("user32.dll")] private static extern bool IsWindowVisible(int hWnd); [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern void keybd_event(byte bVk, byte bScan, long dwFlags, long dwExtraInfo); //delegate used for EnumWindows() callback function public delegate bool EnumWindowsProc(int hWnd, int lParam); #endregion #region Sound Flags Enumeration for "PlaySound" through WinMM.dll public enum SoundFlags : int { SND_SYNC = 0x0000, // play synchronously (default) SND_ASYNC = 0x0001, // play asynchronously SND_NODEFAULT = 0x0002, // silence (!default) if sound not found SND_MEMORY = 0x0004, // pszSound points to a memory file SND_LOOP = 0x0008, // loop the sound until next sndPlaySound SND_NOSTOP = 0x0010, // don't stop any currently playing sound SND_NOWAIT = 0x00002000, // don't wait if the driver is busy SND_ALIAS = 0x00010000, // name is a registry alias SND_ALIAS_ID = 0x00110000, // alias is a predefined ID SND_FILENAME = 0x00020000, // name is file name SND_RESOURCE = 0x00040004 // name is resource name or atom } #endregion #region SendMessage Constants public const int KEYEVENTF_EXTENDEDKEY = 0x01; public const int KEYEVENTF_KEYUP = 0x02; public const int WM_KEYDOWN = 0x100; public const int WM_KEYUP = 0x101; public const int WM_CHAR = 0x102; public const int BN_CLICKED = 245; public const int VK_0 = 0x30; public const int VK_1 = 0x31; public const int VK_2 = 0x32; public const int VK_3 = 0x33; public const int VK_4 = 0x34; public const int VK_5 = 0x35; public const int VK_6 = 0x36; public const int VK_7 = 0x37; public const int VK_8 = 0x38; public const int VK_9 = 0x39; public const int VK_A = 0x41; public const int VK_B = 0x42; public const int VK_C = 0x43; public const int VK_D = 0x44; public const int VK_E = 0x45; public const int VK_F = 0x46; public const int VK_G = 0x47; public const int VK_H = 0x48; public const int VK_I = 0x49; public const int VK_J = 0x4A; public const int VK_K = 0x4B; public const int VK_L = 0x4C; public const int VK_M = 0x4D; public const int VK_N = 0x4E; public const int VK_O = 0x4F; public const int VK_P = 0x50; public const int VK_Q = 0x51; public const int VK_R = 0x52; public const int VK_S = 0x53; public const int VK_T = 0x54; public const int VK_U = 0x55; public const int VK_V = 0x56; public const int VK_W = 0x57; public const int VK_X = 0x58; public const int VK_Y = 0x59; public const int VK_Z = 0x5A; public const int VK_BACK = 0x08; public const int VK_TAB = 0x09; public const int VK_CLEAR = 0x0C; public const int VK_RETURN = 0x0D; public const int VK_SHIFT = 0x10; public const int VK_CONTROL = 0x11; public const int VK_ALT = 0x12; public const int VK_MENU = 0x12; public const int VK_PAUSE = 0x13; public const int VK_CAPITAL = 0x14; public const int VK_KANA = 0x15; public const int VK_HANGEUL = 0x15; public const int VK_HANGUL = 0x15; public const int VK_JUNJA = 0x17; public const int VK_FINAL = 0x18; public const int VK_HANJA = 0x19; public const int VK_KANJI = 0x19; public const int VK_ESCAPE = 0x1B; public const int VK_CONVERT = 0x1C; public const int VK_NONCONVERT = 0x1D; public const int VK_ACCEPT = 0x1E; public const int VK_MODECHANGE = 0x1F; public const int VK_SPACE = 0x20; public const int VK_PRIOR = 0x21; public const int VK_NEXT = 0x22; public const int VK_END = 0x23; public const int VK_HOME = 0x24; public const int VK_LEFT = 0x25; public const int VK_UP = 0x26; public const int VK_RIGHT = 0x27; public const int VK_DOWN = 0x28; public const int VK_SELECT = 0x29; public const int VK_PRINT = 0x2A; public const int VK_EXECUTE = 0x2B; public const int VK_SNAPSHOT = 0x2C; public const int VK_INSERT = 0x2D; public const int VK_DELETE = 0x2E; public const int VK_HELP = 0x2F; public const int VK_LWIN = 0x5B; public const int VK_RWIN = 0x5C; public const int VK_APPS = 0x5D; public const int VK_SLEEP = 0x5F; public const int VK_NUMPAD0 = 0x60; public const int VK_NUMPAD1 = 0x61; public const int VK_NUMPAD2 = 0x62; public const int VK_NUMPAD3 = 0x63; public const int VK_NUMPAD4 = 0x64; public const int VK_NUMPAD5 = 0x65; public const int VK_NUMPAD6 = 0x66; public const int VK_NUMPAD7 = 0x67; public const int VK_NUMPAD8 = 0x68; public const int VK_NUMPAD9 = 0x69; public const int VK_MULTIPLY = 0x6A; public const int VK_ADD = 0x6B; public const int VK_SEPARATOR = 0x6C; public const int VK_SUBTRACT = 0x6D; public const int VK_DECIMAL = 0x6E; public const int VK_DIVIDE = 0x6F; public const int VK_F1 = 0x70; public const int VK_F2 = 0x71; public const int VK_F3 = 0x72; public const int VK_F4 = 0x73; public const int VK_F5 = 0x74; public const int VK_F6 = 0x75; public const int VK_F7 = 0x76; public const int VK_F8 = 0x77; public const int VK_F9 = 0x78; public const int VK_F10 = 0x79; public const int VK_F11 = 0x7A; public const int VK_F12 = 0x7B; public const int VK_F13 = 0x7C; public const int VK_F14 = 0x7D; public const int VK_F15 = 0x7E; public const int VK_F16 = 0x7F; public const int VK_F17 = 0x80; public const int VK_F18 = 0x81; public const int VK_F19 = 0x82; public const int VK_F20 = 0x83; public const int VK_F21 = 0x84; public const int VK_F22 = 0x85; public const int VK_F23 = 0x86; public const int VK_F24 = 0x87; public const int VK_NUMLOCK = 0x90; public const int VK_SCROLL = 0x91; public static int SendKey_StringToVK(string inputKey) { if (inputKey.Length == 1) { if (char.IsLetter(inputKey, 0)) { return (int)inputKey.ToUpper().ToCharArray()[0]; } else if (char.IsDigit(inputKey, 0)) { return (int)inputKey.ToUpper().ToCharArray()[0]; } } else if (inputKey.Length == 2 && inputKey.StartsWith("*")) { if (char.IsLetter(inputKey, 0)) { return (int)inputKey.ToLower().ToCharArray()[0]; } } if (inputKey.StartsWith("F")) { int _tempF = -1; if (int.TryParse(inputKey.Substring(1), out _tempF)) { if (_tempF > 0 && _tempF <= 24) { _tempF += VK_F1 - 1; return _tempF; } } } switch (inputKey.ToUpper()) { case "SHIFT": return VK_SHIFT; case "CTRL": return VK_CONTROL; case "ALT": return VK_ALT; case "NUM0": return VK_NUMPAD0; case "NUM1": return VK_NUMPAD1; case "NUM2": return VK_NUMPAD2; case "NUM3": return VK_NUMPAD3; case "NUM4": return VK_NUMPAD4; case "NUM5": return VK_NUMPAD5; case "NUM6": return VK_NUMPAD6; case "NUM7": return VK_NUMPAD7; case "NUM8": return VK_NUMPAD8; case "NUM9": return VK_NUMPAD9; case "DOWN": return VK_DOWN; case "UP": return VK_UP; case "LEFT": return VK_LEFT; case "RIGHT": return VK_RIGHT; case "SPACE": return VK_SPACE; case "TAB": return VK_TAB; default: return 0; } } #endregion #region Delegates and Events public delegate void Debug_Delegate_VerboseLogging(string LoggingString); public static event Debug_Delegate_VerboseLogging Debug_VerboseLoggingEvent; public delegate void Debug_Delegate_Debug_Variables(List AllToUpdateList); public event Debug_Delegate_Debug_Variables Debug_VariableList; public delegate void Debug_Delegate_VirtualBrain_03(string theUpdatedBrain); public event Debug_Delegate_VirtualBrain_03 Debug_VirtualBrain_03; public delegate void Debug_Delegate_VirtualBrain_04(BrainID theUpdatedBrain); public event Debug_Delegate_VirtualBrain_04 Debug_VirtualBrain_04; public delegate void Debug_Delegate_DebugIfThens(List AllIfThenSuccess); public event Debug_Delegate_DebugIfThens Debug_IfThenList; public delegate void Debug_Delegate_DebugSpeechCommands(string I_Heard_String); public event Debug_Delegate_DebugSpeechCommands Debug_SpeechCommands_Hypothesized; public event Debug_Delegate_DebugSpeechCommands Debug_SpeechCommands_Recognized; public event Debug_Delegate_DebugSpeechCommands Debug_Speech_CommandsRejected; public delegate void Debug_Delegate_Byte_Stream(string brainID, byte[] theArray); //public event Debug_Delegate_Byte_Stream Debug_Byte_Stream; public delegate void Delegate_DoneChangingOutputState(); public static event Delegate_DoneChangingOutputState DoneChangingOutputState; //public delegate void Debug_Delegate_DebugSpeechCommandsAllAvailable(List newAllPossibleList); //public event Debug_Delegate_DebugSpeechCommandsAllAvailable Debug_SpeechReloadAllPossible; #endregion } }