예제 #1
0
        private void ApplyData(ScanResult[] scans)
        {
            var minYValue = scans.Min(s => s.Y.Min());
            var maxYValue = scans.Max(s => s.Y.Max());
            var minXValue = scans.Min(s => s.X.Min());
            var maxXValue = scans.Max(s => s.X.Max());
            var yLength   = maxYValue - minYValue + 1;
            var xLength   = maxXValue - minXValue + 1;
            var grid      =
                Enumerable
                .Range(0, yLength)
                .Select(y =>
            {
                var offsettedY = y + minYValue;
                return
                (new[] { new GridEntryViewModel()
                         {
                             Type = GridEntryType.Sand, X = 0, Y = y
                         } }                                                                               //Allow overflow on left side
                 .Concat(
                     Enumerable.Range(0, xLength)
                     .Select(x =>
                {
                    var offsettedX = x + minXValue;
                    var isClay = scans.Any(s => s.X.Contains(offsettedX) && s.Y.Contains(offsettedY));
                    return new GridEntryViewModel()
                    {
                        Type = isClay ? GridEntryType.Clay : GridEntryType.Sand,
                        X = x + 1,                 // +1 to compensate for allowing overflowing on left side
                        Y = y
                    };
                })
                     )
                 .Concat(
                     new[] { new GridEntryViewModel()
                             {
                                 Type = GridEntryType.Sand, X = xLength + 1, Y = y
                             } }                                                                                         //Allow overflow on right side
                     )
                 .ToArray());
            })
                .ToArray();

            var wellLocation = 500 - minXValue + 1; // +1 to compensate for allowing overflowing on left side
            var vm           = new GridDataViewModel(wellLocation, grid);

            SetDataContext(vm);
        }
예제 #2
0
        private void LoadSandbox_Click(object sender, RoutedEventArgs e)
        {
            var grid = new GridDataViewModel(50,
                                             Enumerable.Range(0, 100).Select(y =>
                                                                             Enumerable.Range(0, 100).Select(x =>
                                                                                                             new GridEntryViewModel()
            {
                Type = GridEntryType.Sand,
                X    = x,
                Y    = y
            }
                                                                                                             ).ToArray()
                                                                             ).ToArray()
                                             );

            SetDataContext(grid);
        }
예제 #3
0
        private void SetDataContext(GridDataViewModel vm)
        {
            SetDataLoadButtonsEnabledTo(false);
            SetFlowButtonsEnabledTo(true);

            ItemsPanel.RowDefinitions.Clear();
            for (var y = 0; y < vm.ViewBoxYSize; y++)
            {
                ItemsPanel.RowDefinitions.Add(new System.Windows.Controls.RowDefinition()
                {
                    Height = new GridLength(1, GridUnitType.Star)
                });
            }
            ItemsPanel.ColumnDefinitions.Clear();
            for (var x = 0; x < vm.ViewBoxXSize; x++)
            {
                ItemsPanel.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition()
                {
                    Width = new GridLength(1, GridUnitType.Star)
                });
            }

            this.DataContext = vm;
        }