/// <summary>Calculates the grid frontend name.</summary> /// <param name="grid">The grid.</param> /// <param name="col">The col.</param> /// <param name="row">The row.</param> /// <param name="settings">The settings.</param> /// <returns></returns> public static string Name_Frontend(IGridBlock_Base grid, int col, int row, GridControl_Settings settings) { var parentRow = grid.Name_ParentRow; // + "/"; string prefix = GridPrefix(grid, settings); return(parentRow + prefix + $"{row}_{col}"); }
private static bool GridSync_DisplayMode(IGridBlock_Base grid, IGridControl gridControl, enGrid_BlockDisplayType displayMode) { var result = false; switch (displayMode) { case enGrid_BlockDisplayType.Address: gridControl.Text = grid.Name_Caption; break; case enGrid_BlockDisplayType.Name: gridControl.Text = grid.Name_Control; break; case enGrid_BlockDisplayType.Value: { var state = grid as IGridBlock_State; if (state == null) { return(false); } if (Double.IsNaN(state.State_ValueDouble)) { gridControl.Text = "?"; } else { gridControl.Text = state.State_ValueDouble.zObject().AsStr(); } break; } } return(result); }
public static string GridPrefix(IGridBlock_Base grid, GridControl_Settings settings) { if (grid == null) { throw new ArgumentNullException(nameof(grid)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } string prefix = ""; if (grid is GridBlock_1Micro) { prefix = settings.GridBlock_Name1Micro; } else if (grid is GridBlock_2Sub) { prefix = settings.GridBlock_Name2Sub; } else if (grid is GridBlock_3Macro) { prefix = settings.GridBlock_Name3Macro; } else if (grid is GridBlock_4Cuboid) { prefix = settings.GridBlock_Name4Cuboid; } else { throw new ArgumentException($"Error! '{nameof(grid)}' is not a defined type."); } return(prefix); }
/// <summary>Initializes a new instance of the <see cref="GridBlock_4Cuboid" /> class.</summary> /// <param name="parent">The parent.</param> /// <param name="onGridCreate">The on grid create.</param> /// <param name="onGridRowCreate">The on grid row create.</param> /// <param name="settings">The settings.</param> /// <param name="macroRows">The macro rows.</param> /// <param name="macroCols">The child rows.</param> /// <param name="subRows">The sub rows.</param> /// <param name="subCols">The sub cols.</param> /// <param name="microRows">The micro rows.</param> /// <param name="microCols">The micro cols.</param> public GridBlock_4Cuboid(IGridBlock_Base parent, onGrid_CreateItem onGridCreate, onGrid_CreateItem onGridRowCreate, GridControl_Settings settings, int macroRows = 1, int macroCols = 1, int subRows = 5, int subCols = 5, int microRows = 5, int microCols = 5) : base(parent, 1, 1, settings) { Child_BlockType = enGrid_BlockType.MacroBlock; Child_DisplayType = enGrid_BlockDisplayType.Address; Child_Cols = macroCols; Child_Rows = macroRows; onGridCreate?.Invoke(this, enGrid_BlockType.CuboidGrid); // Create the child objects int ii = 0; for (int row1 = 1; row1 <= macroRows; row1++) { Name_ChildRow = GridBlock_zMethods.Name_ChildRow(this, row1); onGridRowCreate?.Invoke(this, Child_BlockType); for (int col = 1; col <= macroCols; col++) { ii++; var grid = new GridBlock_3Macro(this, onGridCreate, onGridRowCreate, settings, ii, row1, col, subRows, subCols, microRows, microCols); _GridBlocksDictionary.Add(grid.Name_Address, grid); } } Child_Count = macroRows * macroCols * subRows * subCols * microRows * microCols; }
private void onGridClick(IGridControl sender) { // Fired when mouse click on a grid IGridBlock_Base gridData = sender.GridState; var caption = gridData.Name_Caption; if (radioClick.Checked) { // Click event message if (gridData._Parent != null) { caption = gridData._Parent.Name_Caption + " x " + caption; if (gridData._Parent._Parent != null) { caption = gridData._Parent._Parent.Name_Caption + " x " + caption; } } MessageBox.Show(caption, "Grid Feedback"); } if (radioSelect.Checked) { // Do selection of grids if (ModifierKeys.HasFlag(Keys.Control) == false && ModifierKeys.HasFlag(Keys.Shift) == false) { RefreshGrid(); // Remove previous selections } _SelectedControls.Add(sender); var gridState = gridData as IGridBlock_State; sender.BackColor = Color.CadetBlue; } }
/// <summary>Initializes a new instance of the <see cref="GridBlock_1Micro" /> class.</summary> /// <param name="parent">The parent.</param> /// <param name="index">The index.</param> /// <param name="row">The row.</param> /// <param name="col">The col.</param> /// <param name="settings">The settings.</param> public GridBlock_0BaseState(IGridBlock_Base parent, int index, int row, int col, GridControl_Settings settings) : base(parent, row, col, settings) { State_Index = index; State_Col = col; State_Row = row; State_Setup(Double.NaN, 0, Color.Black); State_EditState = enGrid_BlockEditState.Undefined; }
public static void ReadGridDataFromFile(winForms_GridControlsSetup grid, string fileName) { using (var sr = new StreamReader(fileName)) { while (sr.Peek() >= 0) { string sLine; string[] sArrData; sLine = sr.ReadLine(); sArrData = sLine.Split(','); string sMacroX = sArrData[0]; string sMacroY = sArrData[1]; string sMacro = AddressConcat(sMacroX, sMacroY); string sSubX = sArrData[2]; string sSubY = sArrData[3]; string sSub = AddressConcat(sSubX, sSubY); string sMicroX = sArrData[4]; string sMicroY = sArrData[5]; string sMicro = AddressConcat(sMicroX, sMicroY); string sFloatValue = sArrData[6]; double dFloatData; if (sFloatValue == "") { dFloatData = 0; } else { dFloatData = Double.Parse(sFloatValue); } string sState = sArrData[7]; switch (sState) { case "Scheduled": sState = "1"; break; case "In Progress": sState = "2"; break; case "Complete": sState = "3"; break; case "Cancelled": sState = "4"; break; case "Inspected": sState = "5"; break; } IGridBlock_Base micro = grid.Cuboid.GetChild_MicroGridBlock(sMacro, sSub, sMicro); micro.State_Setup(dFloatData, Int32.Parse(sState)); } } }
/// <summary>Setups the sub grids.</summary> /// <param name="macroAddress">The macro address.</param> /// <param name="subAddress">The sub address.</param> /// <param name="settings">The settings.</param> /// <param name="microRows">The micro rows.</param> /// <param name="microCols">The micro cols.</param> /// <exception cref="System.InvalidOperationException">Error! Macro grid was not found.</exception> /// <exception cref="InvalidOperationException">Error! Macro grid was not found.</exception> public void Setup_MicroGrids(string macroAddress, string subAddress, GridControl_Settings settings, int microRows, int microCols) { IGridBlock_Base grid = GetChild_SubGridBlock(macroAddress, subAddress); var gridMicro = grid as GridBlock_2Sub; if (gridMicro == null) { throw new InvalidOperationException("Error! Macro grid was not found."); } gridMicro.CreateMicroGrids(OnGridCreate, OnGridRowCreate, settings, microRows, microCols); }
/// <summary>Calculate the current row name for the frontend.</summary> /// <param name="grid">The grid.</param> /// <param name="row">The row.</param> /// <returns></returns> public static string Name_ParentRow(IGridBlock_Base grid, int row) { string name = ""; if (grid._Parent != null) { name = grid._Parent.Name_Control; } //if (name != "") name += "/"; return(name + "R" + row); }
/// <summary>Initializes a new instance of the <see cref="GridBlock_1Micro" /> class.</summary> /// <param name="parent">The parent.</param> /// <param name="onGridCreate">The on grid create.</param> /// <param name="onGridRowCreate">The on grid row create.</param> /// <param name="settings">The settings.</param> /// <param name="index">The index.</param> /// <param name="row">The row.</param> /// <param name="col">The col.</param> /// <param name="microRows">The micro rows.</param> /// <param name="microCols">The micro cols.</param> public GridBlock_2Sub(IGridBlock_Base parent, onGrid_CreateItem onGridCreate, onGrid_CreateItem onGridRowCreate, GridControl_Settings settings, int index, int row, int col, int microRows = 5, int microCols = 5) : base(parent, index, row, col, settings) { Child_BlockType = enGrid_BlockType.MicroBlock; Child_DisplayType = enGrid_BlockDisplayType.Address; Child_Cols = microCols; Child_Rows = microRows; Child_Count = 0; onGridCreate?.Invoke(this, enGrid_BlockType.SubBlock); CreateMicroGrids(onGridCreate, onGridRowCreate, settings, microRows, microCols); }
public void GridPrefix_Test() { // null, null var ex = Assert.Throws <ArgumentNullException>(() => GridBlock_zMethods.GridPrefix(null, null)); Assert.Equal("Value cannot be null.".NL() + "Parameter name: grid", ex.Message); // macro, null var settings = GridControl_Settings.Setup(1, 1, 1, 1, 1, 1); var gridCuboid = new GridBlock_5Setup(OnCreateGridControl1, settings); IGridBlock_Base grid = gridCuboid.GetChild_MacroGridBlock("1_1"); ex = Assert.Throws <ArgumentNullException>(() => GridBlock_zMethods.GridPrefix(grid, null)); Assert.Equal("Value cannot be null.".NL() + "Parameter name: settings", ex.Message); }
/// <summary>Initializes a new instance of the <see cref="GridBlock_1Micro" /> class.</summary> /// <param name="parent">The parent.</param> /// <param name="onGridCreate">The on grid create.</param> /// <param name="onGridRowCreate">The on grid row create.</param> /// <param name="settings">The settings.</param> /// <param name="index">The index.</param> /// <param name="row">The row.</param> /// <param name="col">The col.</param> /// <param name="subRows">The sub rows.</param> /// <param name="subCols">The sub cols.</param> /// <param name="microRows">The micro rows.</param> /// <param name="microCols">The micro cols.</param> public GridBlock_3Macro(IGridBlock_Base parent, onGrid_CreateItem onGridCreate, onGrid_CreateItem onGridRowCreate, GridControl_Settings settings, int index, int row, int col, int subRows = 5, int subCols = 5, int microRows = 5, int microCols = 5) : base(parent, index, row, col, settings) { Child_BlockType = enGrid_BlockType.SubBlock; Child_DisplayType = enGrid_BlockDisplayType.Address; Child_Cols = subCols; Child_Rows = subRows; onGridCreate?.Invoke(this, enGrid_BlockType.MacroBlock); // Create the child objects CreateSubGrids(onGridCreate, onGridRowCreate, settings, subRows, subCols, microRows, microCols); }
private void OnGridRowCreate(IGridBlock_Base sender, enGrid_BlockType blockType) { var parentGrid = sender.Name_Control; var rowName = sender.Name_ChildRow; IGridControl gridRowControl = new object() as IGridControl; // Create dummy control if (_onCreateGridControl != null) { _onCreateGridControl(sender, enGrid_ControlType.Row, parentGrid, rowName, blockType, ref gridRowControl); // Ask frontend to create the control } //sender.zGridControl = gridRowControl; // We do not want to save the row. We can get it through the parent property. We already have the grid _treeControls.zDictionary_AddSafe(rowName, gridRowControl); // Save testing information _treeDebugInfo.zDictionary_AddSafe(GridControl_2Str(enGrid_ControlType.Row, parentGrid, rowName, blockType), null); }
private void OnGridCreate(IGridBlock_Base sender, enGrid_BlockType blockType) { var gridName = sender.Name_Control; var gridRow = sender.Name_ParentRow; IGridControl gridControl = new object() as IGridControl; // Create dummy control if (_onCreateGridControl != null) { _onCreateGridControl(sender, enGrid_ControlType.Grid, gridRow, gridName, blockType, ref gridControl); // Ask frontend to create the control } sender.zGridControl = gridControl; // Save tree for quick references _treeControls.zDictionary_AddSafe(gridName, gridControl); // Save testing information _treeDebugInfo.zDictionary_AddSafe(GridControl_2Str(enGrid_ControlType.Grid, gridRow, gridName, blockType), null); }
private static bool GridSync_StateColor(IGridBlock_Base grid, IGridControl gridFrontend, GridControl_Settings settings) { var state = grid as IGridBlock_State; if (state == null) { return(false); } var result = false; Color color; if (settings.Color_ID.TryGetValue(state.State_Id, out color)) { if (gridFrontend.BackColor != color) { gridFrontend.BackColor = color; result = true; } } return(result); }
private static void GridSync_CalcSize(IGridBlock_Base grid, ref int width, ref int height) { IGridControl gridControl = grid.zGridControl; var child = grid as IGridBlock_State; if (child != null) { // Recalc sizes if (child.State_Row != rowMax) { // reset the row width = 0; rowMax = child.State_Row; } width += gridControl.Width; // Only increase width on first row if (child.State_Col == 1) { height += gridControl._Parent.Height; // Only increase height on first col } } }
public static void ReadGridDataFromFile(winForms_GridControlsSetup grid, DataTable gridData) { foreach (DataRow dr in gridData.Rows) { double dValue; string sMacro = dr["Macro Block Name (Grid One)"].ToString().Replace(',', '_'); string sSub = dr["Sub Block Name (Grid Two)"].ToString().Replace(',', '_'); string sMicro = dr["Micro Block Name (Grid Three)"].ToString().Replace(',', '_'); string sValue = dr["Value"].ToString(); string sProgressState = dr["FKProgressState"].ToString(); if (sValue == "") { dValue = 0; } else { dValue = Double.Parse(sValue); } IGridBlock_Base micro = grid.Cuboid.GetChild_MicroGridBlock(sMacro, sSub, sMicro); micro.State_Setup(dValue, Int32.Parse(sProgressState)); } }
private void OnCreateGridControl1(IGridBlock_Base sender, enGrid_ControlType gridcontroltype, string parentname, string childname, enGrid_BlockType blocktype, ref IGridControl gridcontrol) { //gridcontrol = new object() as IGridControl; _ListTest1.Add(ControlToStr(gridcontroltype, parentname, childname, blocktype)); }
/// <summary>Initializes a new instance of the <see cref="GridBlock_1Micro" /> class.</summary> /// <param name="parent">The parent.</param> /// <param name="onGridCreate">The on grid create.</param> /// <param name="settings">The settings.</param> /// <param name="index">The index.</param> /// <param name="col">The col.</param> /// <param name="row">The row.</param> public GridBlock_1Micro(IGridBlock_Base parent, onGrid_CreateItem onGridCreate, GridControl_Settings settings, int index, int col, int row) : base(parent, index, row, col, settings) { onGridCreate?.Invoke(this, enGrid_BlockType.MicroBlock); }
private void onCreateGridControl(IGridBlock_Base sender, enGrid_ControlType gridcontroltype, string parentname, string childname, enGrid_BlockType blocktype, ref IGridControl gridcontrol) { if (gridcontrol != null) { throw new ArgumentException(nameof(gridcontrol), "Error!. Grid control must be null in order to be created."); } #region Sample of a simple 1x1,1x1,1x1 grid // R1 // R1cub1_1 // R1cub1_1R1 // R1cub1_1R1mac1_1 // R1cub1_1R1mac1_1R1 // R1cub1_1R1mac1_1R1sub1_1 // R1cub1_1R1mac1_1R1sub1_1R1 // R1cub1_1R1mac1_1R1sub1_1R1mic1_1 // Row//?//R1//CuboidGrid // Grid//R1//R1cub1_1//CuboidGrid // Row//R1cub1_1//R1cub1_1R1//MacroBlock // Grid//R1cub1_1R1//R1cub1_1R1mac1_1//MacroBlock // Row//R1cub1_1R1mac1_1//R1cub1_1R1mac1_1R1//SubBlock // Grid//R1cub1_1R1mac1_1R1//R1cub1_1R1mac1_1R1sub1_1//SubBlock // Row//R1cub1_1R1mac1_1R1sub1_1//R1cub1_1R1mac1_1R1sub1_1R1//MicroBlock // Grid//R1cub1_1R1mac1_1R1sub1_1R1//R1cub1_1R1mac1_1R1sub1_1R1mic1_1//MicroBlock #endregion // Find the grid control bool created; gridcontrol = GridControl_Get(gridcontroltype, childname, blocktype, out created); if (created == false) { return; // The control exists, we do not need to do anything. } // Find the parent IGridControl parent; if (GridControl_Get(parentname, out parent) == false) { throw new InvalidOperationException($"Error! Parent '{parentname}' does not exist."); } // Setup the row / grid properties gridcontrol.GridState = sender; gridcontrol.Text = sender.Name_Caption; // Set the caption of the control if (gridcontroltype == enGrid_ControlType.Row) { #region Row setup // ================== int height = 100; if (blocktype == enGrid_BlockType.CuboidGrid) { height = _Settings.Size_CuboidHeight; // These settings need to be calculated } else if (blocktype == enGrid_BlockType.MacroBlock) { height = _Settings.Size_MacroHeight; // These settings need to be calculated } else if (blocktype == enGrid_BlockType.SubBlock) { height = _Settings.Size_SubHeight; } else if (blocktype == enGrid_BlockType.MicroBlock) { height = _Settings.Size_MicroHeight; } GridControl_SetupRow(parent, gridcontrol, height); #endregion } else { #region Grid setup // =================== var color = Color.Gray; int width = 30; if (blocktype == enGrid_BlockType.CuboidGrid) { color = _Settings.ColorDefault_CuboidGrid; width = _Settings.Size_CuboidWidth; // These settings need to be calculated } else if (blocktype == enGrid_BlockType.MacroBlock) { width = _Settings.Size_MacroWidth; // These settings need to be calculated color = _Settings.ColorDefault_MacroGrid; } else if (blocktype == enGrid_BlockType.SubBlock) { width = _Settings.Size_SubWidth; color = _Settings.ColorDefault_SubGrid; } else if (blocktype == enGrid_BlockType.MicroBlock) { var display = _Settings.DisplayMode_MicroGrids; if (display == enGrid_BlockDisplayType.Address) { gridcontrol.Text = sender.Name_Caption; // Set the caption of the control } if (display == enGrid_BlockDisplayType.Name) { gridcontrol.Text = sender.Name_Control; // Set the caption of the control } if (display == enGrid_BlockDisplayType.Value) { gridcontrol.Text = "?"; //There is no value yet } width = _Settings.Size_MicroWidth; color = _Settings.ColorDefault_MicroGrid; } GridControl_SetupBlock(parent, gridcontrol, width, color); #endregion } }
/// <summary>Calculates the front-ends child row.</summary> /// <param name="gridBlock">The grid block.</param> /// <param name="row">The row.</param> /// <returns></returns> public static string Name_ChildRow(IGridBlock_Base gridBlock, int row) { return(gridBlock.Name_Control + "R" + row); }
private static void GridSync(IGridBlock_Base grid, GridControl_Settings settings, bool resetColors, onGrid_ChangeEvent onGridChangeEvent) { IGridControl gridControl = grid.zGridControl; if (gridControl == null) { return; // Testing code } var parent = grid._Parent as IGridBlock_ChildState; var child = grid as IGridBlock_State; if (parent == null) { // Cuboid if (GridSync_Size(child, gridControl, settings.Size_CuboidWidth, settings.Size_CuboidHeight)) { onGridChangeEvent(gridControl, enGrid_ChangeType.Size); // Check size } if (resetColors && GridSync_Color(child, gridControl, settings.ColorDefault_CuboidGrid)) { onGridChangeEvent(gridControl, enGrid_ChangeType.Color); // Check size } //if (GridSync_Visible(gridControl, Visible_CuboidGrids)) onGridChange?.Invoke(gridControl, enGridChangeType.Visible); // Check size //if (GridSync_DisplayMode(grid, gridControl, DisplayMode_CuboidGrids)) onGridChange?.Invoke(gridControl, enGridChangeType.DisplayMode); // Check size } else if (parent.Child_BlockType == enGrid_BlockType.MacroBlock) { // Macro if (GridSync_Size(child, gridControl, settings.Size_MacroWidth, settings.Size_MacroHeight)) { onGridChangeEvent(gridControl, enGrid_ChangeType.Size); // Check size } if (resetColors && GridSync_Color(child, gridControl, settings.ColorDefault_MacroGrid)) { onGridChangeEvent(gridControl, enGrid_ChangeType.Color); // Check size } if (GridSync_Visible(gridControl, settings.Visible_MacroGrids)) { onGridChangeEvent(gridControl, enGrid_ChangeType.Visible); // Check size } //if (GridSync_DisplayMode(grid, gridControl, DisplayMode_MacroGrids)) onGridChange?.Invoke(gridControl, enGridChangeType.DisplayMode); // Check size } else if (parent.Child_BlockType == enGrid_BlockType.SubBlock) { // Sub if (GridSync_Size(child, gridControl, settings.Size_SubWidth, settings.Size_SubHeight)) { onGridChangeEvent(gridControl, enGrid_ChangeType.Size); // Check size } if (resetColors && GridSync_Color(child, gridControl, settings.ColorDefault_SubGrid)) { onGridChangeEvent(gridControl, enGrid_ChangeType.Color); // Check size } if (GridSync_Visible(gridControl, settings.Visible_SubGrids)) { onGridChangeEvent(gridControl, enGrid_ChangeType.Visible); // Check size } //if (GridSync_DisplayMode(grid, gridControl, DisplayMode_SubGrids)) onGridChange?.Invoke(gridControl, enGridChangeType.DisplayMode); // Check size } else if (parent.Child_BlockType == enGrid_BlockType.MicroBlock) { // Micro if (GridSync_Size(child, gridControl, settings.Size_MicroWidth, settings.Size_MicroHeight)) { onGridChangeEvent(gridControl, enGrid_ChangeType.Size); // Check size } if (resetColors && GridSync_Color(child, gridControl, settings.ColorDefault_MicroGrid)) { onGridChangeEvent(gridControl, enGrid_ChangeType.Color); // Check size } if (GridSync_Visible(gridControl, settings.Visible_MicroGrids)) { onGridChangeEvent(gridControl, enGrid_ChangeType.Visible); // Check size } if (GridSync_DisplayMode(grid, gridControl, settings.DisplayMode_MicroGrids)) { onGridChangeEvent(gridControl, enGrid_ChangeType.DisplayMode); // Check size } } // Color ID is always the same for all grids if (settings.Color_ID.Count != 0 && GridSync_StateColor(grid, gridControl, settings)) { onGridChangeEvent(gridControl, enGrid_ChangeType.StateColor); // Check size } }