/// <summary>
        /// Populate the grid
        /// </summary>
        /// <param name="model">The model to examine for properties</param>
        public void PopulateGrid(Model model)
        {
            IGridCell selectedCell = this.grid.GetCurrentCell;

            this.model = model;
            DataTable table = new DataTable();

            table.Columns.Add("Description", typeof(string));

            if (this.childrenWithSameType != null)
            {
                foreach (IModel child in this.childrenWithSameType)
                {
                    //child names become the column names
                    table.Columns.Add(child.Name, typeof(object));
                }
            }
            else
            {
                //if there are no children
                table.Columns.Add("Value", typeof(string));
            }

            this.FillTable(table);
            this.FormatGrid();
            if (selectedCell != null)
            {
                this.grid.GetCurrentCell = selectedCell;
            }
        }
Example #2
0
        /// <summary>Get a list of database fieldnames.
        /// Returns the names associated with the first table name in the property list
        /// </summary>
        /// <returns>A list of fieldnames.</returns>
        private List <string> GetFieldNames()
        {
            List <string> fieldNames = null;

            for (int i = 0; i < properties.Count; i++)
            {
                if (properties[i].Display != null && properties[i].Display.Type == DisplayType.TableName)
                {
                    IGridCell cell = grid.GetCell(1, i);
                    if (cell.Value != null && cell.Value.ToString() != string.Empty)
                    {
                        string    tableName = cell.Value.ToString();
                        DataTable data      = null;
                        if (storage.Reader.TableNames.Contains(tableName))
                        {
                            data = storage.Reader.GetDataUsingSql("SELECT * FROM " + tableName + " LIMIT 1");
                        }
                        if (data != null)
                        {
                            fieldNames = DataTableUtilities.GetColumnNames(data).ToList();
                            if (fieldNames.Contains("SimulationID"))
                            {
                                fieldNames.Add("SimulationName");
                            }
                        }
                    }
                }
            }
            return(fieldNames);
        }
Example #3
0
        /// <summary>
        /// Called when user clicks on a file name.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void OnFileBrowseClick(object sender, GridCellChangedArgs e)
        {
            // todo - add file extension paramter to display attribute?
            IFileDialog fileChooser = new FileDialog()
            {
                Action           = FileDialog.FileActionType.Open,
                Prompt           = "Select file path",
                InitialDirectory = e.OldValue
            };

            if (properties[e.RowIndex].Display.Type == DisplayType.DirectoryName)
            {
                fileChooser.Action = FileDialog.FileActionType.SelectFolder;
                fileChooser.Prompt = "Select a folder";
            }

            IGridCell cell     = grid.GetCell(e.ColIndex, e.RowIndex);
            string    fileName = properties[e.RowIndex].Display.Type == DisplayType.FileNames ? string.Join(", ", fileChooser.GetFiles()) : fileChooser.GetFile();

            if (!string.IsNullOrWhiteSpace(fileName) && fileName != e.OldValue)
            {
                e.NewValue = fileName;
                OnCellsChanged(sender, new GridCellsChangedArgs(e));
                PopulateGrid(model);
            }
        }
Example #4
0
        /// <summary>
        /// Gets the direction to a neighbouring cell in matrix deltas.
        /// </summary>
        /// <param name="other">The other cell.</param>
        /// <returns>
        /// A vector representing the matrix deltas to apply to reach the other cell in the matrix.
        /// </returns>
        public VectorXZ GetDirectionTo(IGridCell other)
        {
            var dx = Mathf.Clamp(other.matrixPosX - this.matrixPosX, -1, 1) + 1;
            var dz = Mathf.Clamp(other.matrixPosZ - this.matrixPosZ, -1, 1) + 1;

            return(MatrixDirection.Directions[(dz * 3) + dx]);
        }
Example #5
0
        /// <summary>
        /// Set the value of the specified property
        /// </summary>
        /// <param name="property">The property to set the value of</param>
        /// <param name="value">The value to set the property to</param>
        private void SetPropertyValue(IVariable property, object value)
        {
            presenter.CommandHistory.ModelChanged -= OnModelChanged;
            try
            {
                ChangeProperty cmd = new ChangeProperty(property.Object, property.Name, value);
                presenter.CommandHistory.Add(cmd);
            }
            catch (Exception err)
            {
                presenter.MainPresenter.ShowError(err);
            }
            presenter.CommandHistory.ModelChanged += OnModelChanged;

            for (int i = 0; i < properties.Count; i++)
            {
                IGridCell cell = grid.GetCell(1, i);
                cell.IsRowReadonly = !IsPropertyEnabled(i);
            }

            // Model has been modified - need to refresh the grid.
            // Note: Refresh() interrogates the model. grid.Refresh()
            // updates the UI.
            Refresh();
            grid.Refresh();
        }
Example #6
0
        public static IGridCell Span(this IGridCell cell, int rowSpan, int colSpan)
        {
            cell.RowSpan = rowSpan;
            cell.ColSpan = colSpan;

            return(cell);
        }
        /// <summary>
        /// Updates the model (Just one column)
        /// Updates the lists of Cultivar and Field names in the model.
        /// This is used when the model has been changed. For example, when a
        /// new crop has been selecled.
        /// </summary>
        /// <param name="model">The new model</param>
        private void UpdateModel(int propListIndex)
        {
            IGridCell curCell = this.grid.GetCurrentCell;

            for (int i = 0; i < this.properties[propListIndex].Count; i++)
            {
                IGridCell cell = this.grid.GetCell(propListIndex + 1, i); //add 1 because of Description column
                if (curCell != null && cell.RowIndex == curCell.RowIndex && cell.ColumnIndex == curCell.ColumnIndex)
                {
                    continue;
                }

                if (this.properties[propListIndex][i].Display.Type == DisplayType.CultivarName)
                {
                    IPlant crop = this.GetCrop(this.properties[propListIndex]);
                    if (crop != null)
                    {
                        cell.DropDownStrings = this.GetCultivarNames(crop);
                    }
                }
                else if (this.properties[propListIndex][i].Display.Type == DisplayType.FieldName)
                {
                    string[] fieldNames = this.GetFieldNames(propListIndex);
                    if (fieldNames != null)
                    {
                        cell.DropDownStrings = fieldNames;
                    }
                }
            }
        }
Example #8
0
        /// <summary>
        /// Delete a column in the dataGrid model and then in the View model.
        /// </summary>
        /// <param name="columnToRemove"></param>
        /// <returns></returns>
        public bool DelColumn(IGridColumn columnToRemove)
        {
            // get the VM
            IGridColumnVM colVM = _collColumnGrid.Where(c => c.GridColumn == columnToRemove).FirstOrDefault();

            // remove the VM
            _collColumnGrid.Remove(colVM);

            // remove the coll
            _dynDataGrid.RemoveColumn(columnToRemove);

            // no more col: remove all rows
            if (_dynDataGrid.ListColumn.Count() == 0)
            {
                // remove all rows
                _dynDataGrid.RemoveAllRow();

                // remove all rows VM
                _collDataRow.Clear();
                RaisePropertyChanged("CollDataRow");
                return(true);
            }

            // remove the cells! in each row
            foreach (IGridRow gridRow in _dynDataGrid.ListRow)
            {
                // find the cellVM matching the col
                IGridCell cell = gridRow.FindCellByColumn(columnToRemove);
                gridRow.RemoveCell(cell);
            }

            RaisePropertyChanged("CollDataRow");
            return(true);
        }
Example #9
0
        /// <summary>
        /// Gets the neighbour of the specified cell.
        /// </summary>
        /// <param name="cell">The reference cell.</param>
        /// <param name="dx">The delta x position in the matrix.</param>
        /// <param name="dz">The delta z position in the matrix.</param>
        /// <returns>
        /// The neighbour or null if none is found.
        /// </returns>
        public Cell GetNeighbour(IGridCell cell, int dx, int dz)
        {
            var x = cell.matrixPosX + dx;
            var z = cell.matrixPosZ + dz;

            return(_cellMatrix[x, z]);
        }
Example #10
0
        public IHtmlContent Render(IGridColumn column, IGridCell cell)
        {
            string cssStyles = GetCssStylesString();
            string cssClass  = GetCssClassesString();

            var builder = new TagBuilder("td");

            if (!string.IsNullOrWhiteSpace(cssClass))
            {
                builder.AddCssClass(cssClass);
            }
            if (!string.IsNullOrWhiteSpace(cssStyles))
            {
                builder.MergeAttribute("style", cssStyles);
            }
            builder.MergeAttribute("data-name", column.Name);

            builder.InnerHtml.SetHtmlContent(cell.ToString());

            using (var sw = new StringWriter())
            {
                builder.WriteTo(sw, HtmlEncoder.Default);
                return(new HtmlString(sw.ToString()));
            }
        }
Example #11
0
        /// <summary>
        /// create a column in the dataGird model and also in the corresponding VM, depending on the type.
        /// (the UI wil be updated automatically).
        /// Create all empty cells (model and view model).
        /// </summary>
        /// <param name="typeCol"></param>
        /// <param name="newColName"></param>
        /// <param name="colObj"></param>
        /// <param name="gridColumnVM"></param>
        /// <returns></returns>
        public DynDataGridErrCode CreateColumnWithCells(GridColumnType typeCol, string newColName, object colObj, out IGridColumnVM gridColumnVM)
        {
            gridColumnVM = null;

            // create the col in the data model, depending on the type
            IGridColumn        column;
            DynDataGridErrCode errCode = _gridFactory.CreateColumn(_dynDataGrid, typeCol, newColName, colObj, out column);

            if (errCode != DynDataGridErrCode.Ok)
            {
                return(errCode);
            }

            // create a empty cell for each row in the dataGrid model
            foreach (IGridRow gridRow in _dynDataGrid.ListRow)
            {
                // depending on the type of the new column
                IGridCell cell = _gridFactory.CreateCell(_dynDataGrid, column, gridRow);

                gridRow.AddCell(cell);
            }

            // update the UI, add the colVM
            gridColumnVM = AddColumnVM(column);
            RaisePropertyChanged("CollColumnGrid");
            return(DynDataGridErrCode.Ok);
        }
Example #12
0
 public void SetNeighbors(int gridWidth, int gridHeight, GridCell[,] cells)
 {
     LeftNeighbor  = X > 0 ? cells[X - 1, Y] : OffGridCell.Instance;
     RightNeighbor = X < gridWidth - 1 ? cells[X + 1, Y] : OffGridCell.Instance;
     DownNeighbor  = Y > 0 ? cells[X, Y - 1] : OffGridCell.Instance;
     UpNeighbor    = Y < gridHeight - 1 ? cells[X, Y + 1] : OffGridCell.Instance;
 }
Example #13
0
        /// <summary>
        /// Constructs a grid row from a model and a list of properties.
        /// </summary>
        /// <typeparam name="TItem">The type of business model found in the search result.</typeparam>
        /// <param name="item">Business model from search result.</param>
        /// <param name="properties">List of properties that will be used to construct grid row.</param>
        /// <param name="urlHelper">URL helper.</param>
        /// <param name="urlParameters">URL parameters.</param>
        /// <param name="routePropertyPairs">Holds the names of route values and the corresponding names of object properties that are used to populate route values.</param>
        /// <returns>GridRow.</returns>
        private GridRow GetGridRow <TItem>(TItem item, List <string> properties, UrlHelper urlHelper, UrlParameters urlParameters, List <RoutePropertyPair> routePropertyPairs)
        {
            GridRow gridRow = new GridRow {
                Cells = new List <IGridCell>()
            };

            for (int index = 0; index < properties.Count; index++)
            {
                string       property     = properties[index];
                IGridCell    gridCell     = null;
                PropertyInfo propertyInfo = item.GetType().GetProperty(property);
                object       value        = propertyInfo.GetValue(item);
                if (propertyInfo.PropertyType == typeof(string))
                {
                    gridCell = new TextCell {
                        Value = (string)value
                    }
                }
                ;
                if (index == 0 && urlParameters != null)
                {
                    gridCell.Url = "#"; // TODO: urlHelper.GetUrl(urlParameters, GetRouteValues<TItem>(item, routePropertyPairs));
                }
                gridRow.Cells.Add(gridCell);
            }
            return(gridRow);
        }
Example #14
0
        /// <summary>Get a list of database fieldnames.
        /// Returns the names associated with the first table name in the property list
        /// </summary>
        /// <returns>A list of fieldnames.</returns>
        private List <string> GetFieldNames()
        {
            List <string> fieldNames = null;

            for (int i = 0; i < properties.Count; i++)
            {
                if (properties[i].Display != null && properties[i].Display.Type == DisplayType.TableName)
                {
                    IGridCell cell = grid.GetCell(1, i);
                    if (cell.Value != null && cell.Value.ToString() != string.Empty)
                    {
                        string tableName = cell.Value.ToString();
                        if (storage.Reader.TableNames.Contains(tableName))
                        {
                            fieldNames = storage.Reader.ColumnNames(tableName).ToList();
                            if (fieldNames.Contains("SimulationID"))
                            {
                                fieldNames.Add("SimulationName");
                            }
                        }
                    }
                }
            }
            return(fieldNames);
        }
Example #15
0
 /// <summary>
 /// Updates the lists of Cultivar and Field names in the model.
 /// This is used when the model has been changed. For example, when a
 /// new crop has been selecled.
 /// </summary>
 /// <param name="model">The new model</param>
 public void UpdateModel(Model model)
 {
     this.model = model;
     if (this.model != null)
     {
         IGridCell curCell = this.grid.GetCurrentCell;
         for (int i = 0; i < this.properties.Count; i++)
         {
             IGridCell cell = this.grid.GetCell(1, i);
             if (cell.RowIndex == curCell.RowIndex && cell.ColumnIndex == curCell.ColumnIndex)
             {
                 continue;
             }
             if (this.properties[i].DisplayType == DisplayAttribute.DisplayTypeEnum.CultivarName)
             {
                 ICrop crop = GetCrop(properties);
                 if (crop != null)
                 {
                     cell.DropDownStrings = GetCultivarNames(crop);
                 }
             }
             else if (this.properties[i].DisplayType == DisplayAttribute.DisplayTypeEnum.FieldName)
             {
                 string[] fieldNames = GetFieldNames();
                 if (fieldNames != null)
                 {
                     cell.DropDownStrings = fieldNames;
                 }
             }
         }
     }
 }
Example #16
0
        /// <summary>Get a list of database fieldnames.
        /// Returns the names associated with the first table name in the property list
        /// </summary>
        /// <returns>A list of fieldnames.</returns>
        private string[] GetFieldNames()
        {
            string[] fieldNames = null;
            for (int i = 0; i < this.properties.Count; i++)
            {
                if (this.properties[i].Display.Type == DisplayType.TableName)
                {
                    IGridCell cell = this.grid.GetCell(1, i);
                    if (cell.Value != null && cell.Value.ToString() != string.Empty)
                    {
                        string    tableName = cell.Value.ToString();
                        DataTable data      = null;
                        if (storage.TableNames.Contains(tableName))
                        {
                            data = this.storage.RunQuery("SELECT * FROM " + tableName + " LIMIT 1");
                        }
                        if (data != null)
                        {
                            fieldNames = DataTableUtilities.GetColumnNames(data);
                        }
                    }
                }
            }

            return(fieldNames);
        }
Example #17
0
        public void Update(IGridCell[,] currentGrid, IGridCell newCell)
        {
            var neighbours = GetNeighbours(currentGrid);
            var rule1      = Alive && (neighbours == 2 || neighbours == 3);
            var rule2      = !Alive && neighbours == 3;

            newCell.Alive = rule1 || rule2;
        }
Example #18
0
        /// <summary>
        /// Add a new cell to the parent grid, you can specify row and columns using dedicated extension methods
        /// </summary>
        /// <example>
        /// <code>
        /// .Cell(GridCellExtensions.Create()
        ///   .Row(1).Column(2).Span(2, 1)
        ///   .Contains( ...))
        /// </code>
        /// </example>
        public static IFluentItem <Grid> Cell(this IFluentItem <Grid> fluentItem, IGridCell cell)
        {
            (fluentItem as GridFluentItem)?.SetupCell(cell);
            cell.HostInGrid(fluentItem.Element);
            fluentItem.AddChild(cell.Content);

            return(fluentItem);
        }
Example #19
0
        /// <summary>
        /// Refresh the values of all calculated columns in the profile grid.
        /// </summary>
        private void RefreshCalculatedColumns()
        {
            // Loop through all calculated properties, get an array of values from the property
            // a give to profile grid.
            for (int i = 0; i < this.propertiesInGrid.Count; i++)
            {
                if (this.propertiesInGrid[i].IsReadOnly && i > 0)
                {
                    try
                    {
                        VariableProperty property = this.propertiesInGrid[i];
                        int col = i;
                        int row = 0;
                        foreach (object value in property.Value as IEnumerable <double> )
                        {
                            object valueForCell = value;
                            bool   missingValue = (double)value == MathUtilities.MissingValue || double.IsNaN((double)value);

                            if (missingValue)
                            {
                                valueForCell = null;
                            }

                            IGridCell cell = this.view.ProfileGrid.GetCell(col, row);
                            cell.Value = valueForCell;

                            row++;
                        }

                        // add a total to the column header if necessary.
                        double total = property.Total;
                        if (!double.IsNaN(total))
                        {
                            string columnName = property.Description;
                            if (property.UnitsLabel != null)
                            {
                                columnName += "\r\n" + property.UnitsLabel;
                            }

                            columnName = columnName + "\r\n" + total.ToString("N1") + " mm";

                            IGridColumn column = this.view.ProfileGrid.GetColumn(col);
                            column.HeaderText = columnName;
                        }
                    }
                    catch (Exception e)
                    {
                        if (e is System.Reflection.TargetInvocationException)
                        {
                            e = (e as System.Reflection.TargetInvocationException).InnerException;
                        }

                        this.explorerPresenter.MainPresenter.ShowError(e);
                    }
                }
            }
        }
Example #20
0
 public bool AddPlayer(IGridCell caller, Vector2 position)
 {
     if (Grid.ContainsKey(position) && Grid[position] == null)
     {
         Grid[position] = caller;
         return(true);
     }
     return(false);
 }
Example #21
0
        public static IGridCell Column(this IFluentItem <Grid> item, GridLength width)
        {
            IGridCell cell = GridCellExtensions.Create();

            cell.Width  = width;
            cell.Column = item.Element.ColumnDefinitions.Count;

            return(cell);
        }
Example #22
0
        //Debugging purposes only
        internal HeightData GetHeightData(IGridCell neighbour)
        {
            var dx = Mathf.Clamp(neighbour.matrixPosX - this.matrixPosX, -1, 1);
            var dz = Mathf.Clamp(neighbour.matrixPosZ - this.matrixPosZ, -1, 1);

            var idx = (dx + (3 * dz) + 4);

            return(_heightData[idx]);
        }
Example #23
0
        public static IGridCell Row(this IFluentItem <Grid> item, GridLength height)
        {
            IGridCell cell = GridCellExtensions.Create();

            cell.Height = height;
            cell.Row    = item.Element.RowDefinitions.Count;

            return(cell);
        }
Example #24
0
        public void Update(IGridCell[,] currentGrid, IGridCell newCell)
        {
            var currCell = (SSCell)currentGrid.At(Location);

            // regular regrowth
            var distanceToCenter = new Vector2(Location.X - currentGrid.GetLength(1) / 2f, Location.Y - currentGrid.GetLength(0) / 2f).Length();
            var scale            = 1f / (distanceToCenter + 1);

            scale *= 2f;
            //scale = 1f;
            var extra = sugarRegrowthRate * scale;

            ((SSCell)newCell).sugarLevel = Math.Min(currCell.sugarLevel + extra, sugarCapacity);

            // bonus
            var sumOfSurroundingCells = 0f;

            sumOfSurroundingCells += ((SSCell)currentGrid.At(Location)).sugarLevel;
            sumOfSurroundingCells += ((SSCell)currentGrid.At(Location - new Point(0, 1))).sugarLevel;
            sumOfSurroundingCells += ((SSCell)currentGrid.At(Location - new Point(1, 0))).sugarLevel;
            sumOfSurroundingCells += ((SSCell)currentGrid.At(Location - new Point(0, -1))).sugarLevel;
            sumOfSurroundingCells += ((SSCell)currentGrid.At(Location - new Point(-1, 0))).sugarLevel;
            sumOfSurroundingCells += ((SSCell)currentGrid.At(Location - new Point(1, 1))).sugarLevel;
            sumOfSurroundingCells += ((SSCell)currentGrid.At(Location - new Point(1, -1))).sugarLevel;
            sumOfSurroundingCells += ((SSCell)currentGrid.At(Location - new Point(-1, 1))).sugarLevel;
            sumOfSurroundingCells += ((SSCell)currentGrid.At(Location - new Point(-1, -1))).sugarLevel;

            if (sumOfSurroundingCells > 4500)
            {
                //dying from overcrowding
                ((SSCell)newCell).sugarLevel *= 0.95f;
            }
            else if (sumOfSurroundingCells < 500)
            {
                // thriving from no competition
                ((SSCell)newCell).sugarLevel *= 1.05f;
            }
            //else
            {
                //average out neighbours
                var avg  = sumOfSurroundingCells / 9f;
                var diff = avg - currCell.sugarLevel;
                //((SSCell)newCell).sugarLevel += (Math.Abs(diff) / 100f);
                ((SSCell)newCell).sugarLevel += diff / 100f;
            }

            // cell 'death'
            if (rnd.NextDouble() > 0.999 * (scale * 8f))
            {
                ((SSCell)newCell).sugarLevel = 0;
            }
            if (rnd.NextDouble() < 0.001)            // * (scale * 6f))
            {
                ((SSCell)newCell).sugarLevel = ((SSCell)newCell).sugarCapacity;
            }
        }
Example #25
0
 public bool Move(IGridCell caller, Vector2 position, Vector2 direction)
 {
     if (Grid.ContainsKey(position + direction) && Grid[position + direction] == null)
     {
         Grid[position + direction] = caller;
         Grid[position]             = null;
         return(true);
     }
     return(false);
 }
Example #26
0
        public int GetCellCost(IGridCell cell, object unitProperties)
        {
            //First cast the properties to the type we expect to see. The commented line is for using the alternative Unit type from UnitPartialExtension.cs.
            var concreteProperties = unitProperties as UnitDerivedExtension;
            /* var concreteProperties = unitProperties as UnitComponent; */

            var mask = cell.cost & (int)concreteProperties.affectedByCosts;

            return(CellCostManager.instance.GetCost(mask));
        }
Example #27
0
        public bool RemoveCell(IGridCell cell)
        {
            if (cell == null)
            {
                return(false);
            }

            _listCell.Remove(cell);
            return(true);
        }
Example #28
0
        public Rover(IGrid grid, IGridCell origin, IDirection direction)
        {
            _cell      = origin;
            _direction = direction;
            _grid      = grid;

            _turn.Add('L', _direction.Left);
            _turn.Add('R', _direction.Right);
            _move.Add('F', Forward);
            _move.Add('B', Backward);
        }
Example #29
0
 /// <summary>
 /// Resets the invocation list of all events within the class.
 /// </summary>
 /// <param name="cell">The cell object.</param>
 /// <param name="includeChildren">Whether or not to also nullify the events of any child elements.</param>
 public static void NullifyEvents(this IGridCell cell, bool includeChildren)
 {
     cell.NullifyEvents();
     if (includeChildren)
     {
         foreach (var control in cell.Children.OfType <IControl>())
         {
             control.NullifyEvents();
         }
     }
 }
Example #30
0
        /// <summary>
        /// Pastes tab-delimited data from the clipboard into a range of cells.
        /// </summary>
        private void PasteCells(object sender, GridCellPasteArgs args)
        {
            List <IGridCell>           cellsChanged = new List <IGridCell>();
            List <GridCellChangedArgs> changedArgs  = new List <GridCellChangedArgs>();

            string[] lines = args.Text.Split(Environment.NewLine.ToCharArray()).Where(line => !string.IsNullOrEmpty(line)).ToArray();
            for (int i = 0; i < lines.Length; i++)
            {
                // Add new rows, if necessary.
                while (args.Grid.RowCount < args.StartCell.RowIndex + i + 1)
                {
                    args.Grid.RowCount++;
                }
                string[] words = lines[i].Split('\t');
                int      numReadOnlyColumns = 0;
                for (int j = 0; j < words.Length; j++)
                {
                    // Skip over any read-only columns.
                    IGridColumn column = args.Grid.GetColumn(args.StartCell.ColumnIndex + j + numReadOnlyColumns);
                    while (column != null && column.ReadOnly)
                    {
                        numReadOnlyColumns++;
                        column = args.Grid.GetColumn(args.StartCell.ColumnIndex + j + numReadOnlyColumns);
                    }
                    if (column == null)
                    {
                        throw new Exception("Error pasting into grid - not enough columns.");
                    }

                    int row = args.StartCell.RowIndex + i;
                    int col = args.StartCell.ColumnIndex + j + numReadOnlyColumns;

                    IGridCell cell = args.Grid.GetCell(col, row);

                    string oldValue = null;
                    if (args.Grid.DataSource.Rows.Count > row)
                    {
                        oldValue = args.Grid.DataSource.Rows[row][col]?.ToString();
                    }

                    string newValue = words[j];

                    changedArgs.Add(new GridCellChangedArgs(row, col, oldValue, newValue));

                    // fixme - this should not be set here. What if the item is an array?
                    //cell.Value = Convert.ChangeType(words[j], args.Grid.DataSource.Columns[args.StartCell.ColumnIndex + j + numReadOnlyColumns].DataType);

                    cellsChanged.Add(cell);
                }
            }
            // If some cells were changed then send out an event.
            args.Grid.SelectCells(cellsChanged);
            args.Grid.Refresh(new GridCellsChangedArgs(changedArgs.ToArray()));
        }
Example #31
0
        /// <summary>
        /// Determines whether the cell is walkable from the specified neighbour.
        /// </summary>
        /// <param name="neighbour">The neighbour.</param>
        /// <param name="unitProps">The unit properties.</param>
        /// <returns><c>true</c> if the cell is walkable, otherwise <c>false</c></returns>
        public override bool isWalkableFrom(IGridCell neighbour, IUnitProperties unitProps)
        {
            if (!isWalkable(unitProps.attributes))
            {
                return false;
            }

            var pos = neighbour.GetRelativePositionTo(this);

            return (_heightBlockedFrom & pos) == 0;
        }
Example #32
0
        public IHtmlString Render(IGridColumn column, IGridCell cell)
        {
            string cssStyles = GetCssStylesString();
            string cssClass = GetCssClassesString();

            var builder = new TagBuilder("td");
            if (!string.IsNullOrWhiteSpace(cssClass))
                builder.AddCssClass(cssClass);
            if (!string.IsNullOrWhiteSpace(cssStyles))
                builder.MergeAttribute("style", cssStyles);
            builder.MergeAttribute("data-name", column.Name);

            builder.InnerHtml = cell.ToString();

            return MvcHtmlString.Create(builder.ToString());
        }
Example #33
0
        /// <summary>
        /// Determines whether the cell is walkable from the specified neighbour.
        /// </summary>
        /// <param name="neighbour">The neighbour.</param>
        /// <param name="mask">The attribute mask used to determine walk-ability.</param>
        /// <returns><c>true</c> if the cell is walkable, otherwise <c>false</c></returns>
        public override bool isWalkableFrom(IGridCell neighbour, IUnitProperties unitProps)
        {
            if (!isWalkable(unitProps.attributes))
            {
                return false;
            }

            var dx = Mathf.Clamp(neighbour.matrixPosX - this.matrixPosX, -1, 1);
            var dz = Mathf.Clamp(neighbour.matrixPosZ - this.matrixPosZ, -1, 1);

            var idx = (dx + (3 * dz) + 4);

            var uc = unitProps.heightNavigationCapability;
            var d = _heightData[idx];

            //We compare to opposites since this is from the neighbour's point of view
            return ((uc.maxClimbHeight >= d.dropHeight && uc.maxDropHeight >= d.climbHeight) || uc.maxSlopeAngle >= d.slope);
        }
 /// <summary>
 /// Gets the vector field cell at a cell center position.
 /// Note the value passed as position MUST be a grid cell center.
 /// </summary>
 /// <param name="cell">The grid cell.</param>
 /// <returns>
 /// The vector field cell at the specified position.
 /// </returns>
 public VectorFieldCell GetFieldCellAtPos(IGridCell cell)
 {
     Ensure.ArgumentNotNull(cell, "cell");
     return _cellDirs[cell.matrixPosX, cell.matrixPosZ];
 }
Example #35
0
        /// <summary>
        /// Gets the walkable neighbours.
        /// </summary>
        /// <param name="grid">The grid</param>
        /// <param name="c">The cell whose walkable neighbours to return.</param>
        /// <param name="unitProps">The unit properties</param>
        /// <param name="excludeCornerCutting">if set to <c>true</c> otherwise walkable neighbours on the diagonal that would cause a move from it to the current cell to cut a corner are excluded (deemed not walkable).</param>
        /// <returns>The walkable neighbours to the referenced cell.</returns>
        public static IEnumerable<Cell> GetWalkableNeighbours(this IGrid grid, IGridCell c, IUnitProperties unitProps, bool excludeCornerCutting)
        {
            Cell n;

            //Straight move neighbours
            bool uw = grid.TryGetWalkableNeighbour(c, 0, 1, unitProps, out n);
            if (uw)
            {
                yield return n;
            }

            bool dw = grid.TryGetWalkableNeighbour(c, 0, -1, unitProps, out n);
            if (dw)
            {
                yield return n;
            }

            bool rw = grid.TryGetWalkableNeighbour(c, 1, 0, unitProps, out n);
            if (rw)
            {
                yield return n;
            }

            bool lw = grid.TryGetWalkableNeighbour(c, -1, 0, unitProps, out n);
            if (lw)
            {
                yield return n;
            }

            //Diagonal neighbours. First determine if they are unwalkable as a consequence of their straight neighbours
            bool urw, drw, dlw, ulw;
            if (excludeCornerCutting)
            {
                urw = uw && rw;
                drw = dw && rw;
                dlw = dw && lw;
                ulw = uw && lw;
            }
            else
            {
                urw = uw || rw;
                drw = dw || rw;
                dlw = dw || lw;
                ulw = uw || lw;
            }

            urw = urw && grid.TryGetWalkableNeighbour(c, 1, 1, unitProps, out n);
            if (urw)
            {
                yield return n;
            }

            drw = drw && grid.TryGetWalkableNeighbour(c, 1, -1, unitProps, out n);
            if (drw)
            {
                yield return n;
            }

            dlw = dlw && grid.TryGetWalkableNeighbour(c, -1, -1, unitProps, out n);
            if (dlw)
            {
                yield return n;
            }

            ulw = ulw && grid.TryGetWalkableNeighbour(c, -1, 1, unitProps, out n);
            if (ulw)
            {
                yield return n;
            }
        }
        /// <summary>
        /// Gets the vector field cell at a cell center position.
        /// Note the value passed as position MUST be a grid cell center.
        /// </summary>
        /// <param name="cell">The grid cell.</param>
        /// <returns>
        /// The vector field cell at the specified position.
        /// </returns>
        public VectorFieldCell GetFieldCellAtPos(IGridCell cell)
        {
            Ensure.ArgumentNotNull(cell, "cell");

            if (_cellDirsSet == null)
            {
                // if we have no dictionary yet, then return default value of vector field cell
                return default(VectorFieldCell);
            }

            // otherwise, return the vector field cell at the specified position
            VectorFieldCell value;
            _cellDirsSet.TryGetValue(cell.position, out value);
            return value;
        }
Example #37
0
        //Debugging purposes only
        internal HeightData GetHeightData(IGridCell neighbour)
        {
            var dx = Mathf.Clamp(neighbour.matrixPosX - this.matrixPosX, -1, 1);
            var dz = Mathf.Clamp(neighbour.matrixPosZ - this.matrixPosZ, -1, 1);

            var idx = (dx + (3 * dz) + 4);

            return _heightData[idx];
        }
Example #38
0
 public PerimeterCell(Perimeter p)
 {
     perimeter = p;
     cell = null;
 }
Example #39
0
        private static IPathRequest UpdateRequest(IPathRequest req, IGridCell to, params Vector3[] waypoints)
        {
            req.to = to.position;
            req.pendingWaypoints = waypoints;

            return req;
        }
Example #40
0
 NeighbourPosition IGridCell.GetRelativePositionTo(IGridCell other)
 {
     return NeighbourPosition.None;
 }
Example #41
0
 bool IGridCell.isWalkableFrom(IGridCell neighbour, AttributeMask mask)
 {
     return _parentPortal.IsUsableBy(mask);
 }
 bool IGridCell.isWalkableFrom(IGridCell neighbour, IUnitProperties unitProps)
 {
     return _parentPortal.IsUsableBy(unitProps.attributes);
 }
Example #43
0
 VectorXZ IGridCell.GetDirectionTo(IGridCell other)
 {
     return MatrixDirection.None;
 }
 /// <summary>
 /// Determines whether the cell is walkable from the specified neighbour.
 /// </summary>
 /// <param name="neighbour">The neighbour.</param>
 /// <param name="unitProps">The unit properties.</param>
 /// <returns><c>true</c> if the cell is walkable, otherwise <c>false</c></returns>
 public override bool isWalkableFrom(IGridCell neighbour, IUnitProperties unitProps)
 {
     return isWalkable(unitProps.attributes);
 }
        public ICollection<IGridCell> GetNeighbourCells(IGridCell iGridCell)
        {
            List<IGridCell> cells = new List<IGridCell>();

            HexPoint cellPoint = new HexPoint(iGridCell.X,iGridCell.Y);
            foreach (HexPoint pt in cellPoint.Neighbors)
            {
                if (IsValid(pt))
                    cells.Add(this[pt]);
            }

            return cells;
        }
Example #46
0
        /// <summary>
        /// Gets the direction to a neighbouring cell in matrix deltas.
        /// </summary>
        /// <param name="other">The other cell.</param>
        /// <returns>
        /// A vector representing the matrix deltas to apply to reach the other cell in the matrix.
        /// </returns>
        public VectorXZ GetDirectionTo(IGridCell other)
        {
            var dx = Mathf.Clamp(other.matrixPosX - this.matrixPosX, -1, 1) + 1;
            var dz = Mathf.Clamp(other.matrixPosZ - this.matrixPosZ, -1, 1) + 1;

            return MatrixDirection.Directions[(dz * 3) + dx];
        }
Example #47
0
        /// <summary>
        /// Gets this cell's relative position to the other cell.
        /// </summary>
        /// <param name="other">The other cell.</param>
        /// <returns>
        /// The relative position
        /// </returns>
        public NeighbourPosition GetRelativePositionTo(IGridCell other)
        {
            var dx = Mathf.Clamp(this.matrixPosX - other.matrixPosX, -1, 1);
            var dz = Mathf.Clamp(this.matrixPosZ - other.matrixPosZ, -1, 1);

            //____________
            //|_6_|_7_|_8_| 1
            //|_3_|_4_|_5_| 0
            //|_0_|_1_|_2_|-1
            // -1   0   1
            return (NeighbourPosition)(1 << (dx + (3 * dz) + 4));
        }
Example #48
0
 /// <summary>
 /// Determines whether the cell is walkable from the specified neighbour.
 /// </summary>
 /// <param name="neighbour">The neighbour.</param>
 /// <param name="mask">The attribute mask used to determine walk-ability.</param>
 /// <returns><c>true</c> if the cell is walkable, otherwise <c>false</c></returns>
 public abstract bool isWalkableFrom(IGridCell neighbour, IUnitProperties unitProps);
 /// <summary>
 /// Gets the cell cost.
 /// </summary>
 /// <param name="cell">The cell.</param>
 /// <param name="unitProperties">The unit properties.</param>
 /// <returns>
 /// The cost
 /// </returns>
 public int GetCellCost(IGridCell cell, object unitProperties)
 {
     return cell.cost;
 }
Example #50
0
        public void AddHeader(DateTime startDate, string requestText, string logoPath)
        {
            // Add a repeating band header to the main band
            IBandHeader bandHeader = this.currentBand.Header;

            // Header settings
            bandHeader.Repeat = true;
            bandHeader.Height = new FixedHeight(80);
            bandHeader.Alignment = new ContentAlignment(Alignment.Left, Alignment.Middle);
            var logo = new Image(logoPath);
            logo.Preferences.Compressor = ImageCompressors.Flate;

            //' Add a grid to header
            IGrid grid = bandHeader.AddGrid();

            // Arrays for columns and cells
            IGridColumn[] headerColumn = new IGridColumn[5];
            IGridCell[] headerGridCell = new IGridCell[4];

            // Add two columns to the grid
            headerColumn[0] = grid.AddColumn();
            //headerColumn[0].Width = new FixedWidth(270);
            headerColumn[1] = grid.AddColumn();
            headerColumn[1].Width = new FixedWidth(20);
            headerColumn[2] = grid.AddColumn();
            headerColumn[2].Width = new FixedWidth(270);

            // Add one row to the grid
            IGridRow gridRow = grid.AddRow();

            
            headerGridCell[1] = gridRow.AddCell();
            IGrid dataGrid = headerGridCell[1].AddGrid();
            var dataGridheaderColumn = dataGrid.AddColumn();
            dataGridheaderColumn.Width = new FixedWidth(150);
            dataGrid.AddColumn();

            GridCellPattern dataCellPattern = new GridCellPattern();
            dataCellPattern.Alignment = new ContentAlignment(Alignment.Center, Alignment.Middle);
            dataCellPattern.Paddings.Left = 5;
            dataCellPattern.Paddings.Bottom = 10;

            var dataGridRow = dataGrid.AddRow();

            IText text ;
            headerGridCell[0] = dataGridRow.AddCell();
            dataCellPattern.Apply(headerGridCell[0]);
            text = headerGridCell[0].AddText();
            text.Style.Font = this.pdfFonts[PdfFont.DefaultNormalReg];
            text.AddContent("Ende Abrechnungszeitraum (Stichtag)");

            headerGridCell[1] = dataGridRow.AddCell();
            dataCellPattern.Apply(headerGridCell[1]);
            text = headerGridCell[1].AddText();
            text.Style.Font = this.pdfFonts[PdfFont.DefaultNormalReg];
            text.AddContent(startDate.ToShortDateString());

            dataGridRow = dataGrid.AddRow();

            headerGridCell[0] = dataGridRow.AddCell();
            dataCellPattern.Apply(headerGridCell[0]);
            text = headerGridCell[0].AddText();
            text.Style.Font = this.pdfFonts[PdfFont.DefaultNormalReg];
            text.AddContent("Region");

            headerGridCell[1] = dataGridRow.AddCell();
            dataCellPattern.Apply(headerGridCell[1]);
            text = headerGridCell[1].AddText();
            text.Style.Font = this.pdfFonts[PdfFont.DefaultNormalReg];
            text.AddContent(requestText);

            // Add grid cell for logo
            gridRow.AddCell();

            headerGridCell[0] = gridRow.AddCell();
            //cellPattern.Apply(headerGridCell(0))
            headerGridCell[0].Alignment = ContentAlignment.Right;
            headerGridCell[0].AddImage(logo);
            //gridRow.AddCell();


            //'cellPattern.Apply(headerGridCell(1))
            //'headerGridCell(1).ColSpan = 1
            //Dim headingText As IText = headerGridCell(1).AddText()
            //headingText.Style.Font = pdfFonts(PdfFont.DefaultSmallReg)
            //headingText.AddContent(requestText)

        }