Ejemplo n.º 1
0
        /// <summary>
        /// Konstruktor okna warunków początkowych
        /// </summary>
        internal InitialCondition(int _mode = SPDAssets.MAX, InitialConditions condition = null)
        {
            _tooltip = -1;
            InitializeComponent();

            Mode = _mode;
            _selectedOperation     = Operation.None;
            ComboBox.ItemsSource   = SPDAssets.GetBrushRectangles(Mode, InitialConditions.GetTransformation(Mode));
            ComboBox.SelectedIndex = 0;
            DataContext            = this;
            _conditionNames        = new List <Tuple <string, Tuple <string, bool> > >();
            _conditions            = new Dictionary <Tuple <string, bool>, Func <bool, int, int, bool, InitialConditions> >();
            foreach (var T in new[] { false, true })
            {
                _conditions.Add(new Tuple <string, bool>("Donut", T), InitialConditions.DonutFactory);
                _conditions.Add(new Tuple <string, bool>("Circle", T), InitialConditions.CircleFactory);
                _conditions.Add(new Tuple <string, bool>("Diagonal", T), InitialConditions.DiagonalFactory);
                _conditions.Add(new Tuple <string, bool>("NowakMay", T), InitialConditions.NowakMayFactory);
            }
            _conditionNames.AddRange(
                _conditions.Select(
                    k =>
                    new Tuple <string, Tuple <string, bool> >(k.Value(k.Key.Item2, 1, 10, false).Name,
                                                              new Tuple <string, bool>(k.Key.Item1, k.Key.Item2))));
            ComboBoxCopy.ItemsSource = _conditionNames.Select(s => s.Item1);
            var D = SPDAssets.GenerateLegend(Legend.Height, Mode, InitialConditions.GetTransformation(Mode));

            D.Stretch = Stretch.Fill;

            Legend.Children.Add(D);
            if (condition != null)
            {
                Condition = condition;
            }
        }
Ejemplo n.º 2
0
        private void Canvas_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (Operation.None == _selectedOperation)
            {
                return;
            }

            if (ComboBox.SelectedIndex < 0)
            {
                return;
            }
            var p  = e.GetPosition(Canvas);
            var ic = Condition;
            var x  = _x + _scale * p.X / (Canvas.Width / (ic.Grid.CellGrid.GetLength(0)));

            if (x >= ic.Grid.CellGrid.GetLength(0))
            {
                return;
            }
            var y = _y + _scale * p.Y / (Canvas.Height / (ic.Grid.CellGrid.GetLength(1)));

            if (y >= ic.Grid.CellGrid.GetLength(1))
            {
                return;
            }
            if (Operation.Check == _selectedOperation)
            {
                ic.Grid.CellGrid[(int)x, (int)y].Value = InitialConditions.GetTransformation(Mode)(ComboBox.SelectedIndex);
            }
            else
            {
                var k = ic.Grid.CellGrid[(int)x, (int)y].Value;
                for (var i = 0; i < ic.Grid.CellGrid.GetLength(0); i++)
                {
                    for (var j = 0; j < ic.Grid.CellGrid.GetLength(1); j++)
                    {
                        if (ic.Grid.CellGrid[i, j].Value == k)
                        {
                            ic.Grid.CellGrid[i, j].Value = InitialConditions.GetTransformation(Mode)(ComboBox.SelectedIndex);
                        }
                    }
                }
            }
            Condition = ic;
        }