/// <summary>Initializes a new instance of the <see cref="GridBlock_1Micro" /> class.</summary> /// <param name="parent">The parent.</param> /// <param name="col">The col.</param> /// <param name="row">The row.</param> /// <param name="microCols">The micro cols.</param> /// <param name="microRows">The micro rows.</param> public GridBlock_2Sub(IGridBlock parent, OnGridCreate onGridCreate, OnGridRowCreate onGridRowCreate, int col, int row, int microCols = 5, int microRows = 5) { _Parent = parent; _Frontend_Caption = $"{row}.{col}"; Reference_Col = col; Reference_Row = row; State_Value = double.NaN; State_Block = enBlockState.Unknown; ChildBlockType = enBlockType.MicroBlock; ChildDisplayType = enBlockDisplayType.Name; ChildDecimalPlaces = 1; _Frontend_Name = parent._Frontend_Name + $"sub{row}_{col}"; _Frontend_CurrentRow = GridBlock_Methods.FrontendCurrentRow(parent, row); onGridCreate?.Invoke(this, enBlockType.SubBlock); // Create the child objects // This can be optimised by only creating a child the momemnt it is neaded in Child_GridBlockGet for (int row1 = 1; row1 <= microRows; row1++) { onGridRowCreate?.Invoke(this, row); for (int col1 = 1; col1 <= microCols; col1++) { var grid = new GridBlock_1Micro(this, onGridCreate, col1, row1); _gridBlockDictionary.Add(grid._Frontend_Caption, grid); } } ChildCount = microRows * microCols; }
/// <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="col">The col.</param> /// <param name="row">The row.</param> /// <param name="subCols">The sub cols.</param> /// <param name="subRows">The sub rows.</param> /// <param name="microCols">The micro cols.</param> /// <param name="microRows">The micro rows.</param> public GridBlock_3Macro(IGridblock_Frontend parent, OnGridCreate onGridCreate, OnGridRowCreate onGridRowCreate, int col, int row, int subCols = 5, int subRows = 5, int microCols = 5, int microRows = 5) { _Parent = parent; _Frontend_Caption = $"{row}.{col}"; Reference_Col = col; Reference_Row = row; State_Value = double.NaN; State_Block = enBlockState.Unknown; ChildBlockType = enBlockType.SubBlock; ChildDisplayType = enBlockDisplayType.Name; ChildDecimalPlaces = 1; _Frontend_Name = parent._Frontend_Name + $"mac{row}_{col}"; _Frontend_CurrentRow = GridBlock_Methods.FrontendCurrentRow(parent, row); onGridCreate?.Invoke(this, enBlockType.MacroBlock); // Create the child objects for (int row1 = 1; row1 <= subRows; row1++) { onGridRowCreate?.Invoke(this, row); for (int col1 = 1; col1 <= subCols; col1++) { var grid = new GridBlock_2Sub(this, onGridCreate, onGridRowCreate, col1, row1, microCols: microCols, microRows: microRows); _gridBlockDictionary.Add(grid._Frontend_Caption, grid); } } ChildCount = subRows * subCols * microCols * microRows; }
public void Address_ToXY_Test() { int y, x; GridBlock_Methods.Address_ToXY("1.1", out y, out x); Assert.Equal(1, y); Assert.Equal(1, x); GridBlock_Methods.Address_ToXY("1.3", out y, out x); Assert.Equal(1, y); Assert.Equal(3, x); GridBlock_Methods.Address_ToXY("7.3", out y, out x); Assert.Equal(7, y); Assert.Equal(3, x); }
public void GridBlock_4MacroSetup_Test(string addressMacro, string addressSub, string addressMicro) { int macroY, macroX; GridBlock_Methods.Address_ToXY(addressMacro, out macroY, out macroX); int subY, subX; GridBlock_Methods.Address_ToXY(addressSub, out subY, out subX); int microY, microX; GridBlock_Methods.Address_ToXY(addressMicro, out microY, out microX); var gridCuboid = new GridBlock_4MacroSetup(this, null, null, macroCols: 1, macroRows: 5, subCols: 6, subRows: 5, microCols: 6, microRows: 6); #region Cuboid Assert.Equal(5 * 6 * 5 * 6 * 6, gridCuboid.ChildCount); Assert.Equal(this, gridCuboid._Parent); Assert.Equal(enBlockType.MacroBlock, gridCuboid.ChildBlockType); Assert.Equal(1, gridCuboid.ChildDecimalPlaces); Assert.Equal(enBlockDisplayType.Name, gridCuboid.ChildDisplayType); #endregion #region Macro block var gridMacro = gridCuboid.Child_GridBlockGet(addressMacro) as GridBlock_3Macro; Assert.NotEqual(null, gridMacro); Assert.Equal(addressMacro, gridMacro._Frontend_Caption); Assert.Equal(6 * 5 * 6 * 6, gridMacro.ChildCount); Assert.Equal(gridCuboid, gridMacro._Parent); Assert.Equal(enBlockType.SubBlock, gridMacro.ChildBlockType); Assert.Equal(1, gridMacro.ChildDecimalPlaces); Assert.Equal(enBlockDisplayType.Name, gridMacro.ChildDisplayType); Assert.Equal(macroY, gridMacro.Reference_Row); Assert.Equal(macroX, gridMacro.Reference_Col); Assert.Equal(enBlockState.Unknown, gridMacro.State_Block); Assert.Equal(double.NaN, gridMacro.State_Value); #endregion #region Sub block var gridSub = gridMacro.Child_GridBlockGet(addressSub) as GridBlock_2Sub; Assert.NotEqual(null, gridSub); Assert.Equal(addressSub, gridSub._Frontend_Caption); Assert.Equal(6 * 6, gridSub.ChildCount); Assert.Equal(gridMacro, gridSub._Parent); Assert.Equal(enBlockType.MicroBlock, gridSub.ChildBlockType); Assert.Equal(1, gridSub.ChildDecimalPlaces); Assert.Equal(enBlockDisplayType.Name, gridSub.ChildDisplayType); Assert.Equal(subY, gridSub.Reference_Row); Assert.Equal(subX, gridSub.Reference_Col); Assert.Equal(enBlockState.Unknown, gridSub.State_Block); Assert.Equal(double.NaN, gridSub.State_Value); // Child_GridBlockSub var gridSub2 = gridCuboid.Child_GridBlockSub(addressMacro, addressSub); Assert.Equal(gridSub, gridSub2); #endregion #region Micro block var gridMicro = gridSub.Child_GridBlockGet(addressMicro) as GridBlock_1Micro; Assert.NotEqual(null, gridMicro); Assert.Equal(addressMicro, gridMicro._Frontend_Caption); Assert.Equal(gridSub, gridMicro._Parent); Assert.Equal(microY, gridMicro.Reference_Row); Assert.Equal(microX, gridMicro.Reference_Col); Assert.Equal(enBlockState.Unknown, gridMicro.State_Block); Assert.Equal(double.NaN, gridMicro.State_Value); // Child_GridBlockMicro var gridMicro2 = gridCuboid.Child_GridBlockMicro(addressMacro, addressSub, addressMicro); Assert.Equal(gridMicro, gridMicro2); #endregion }