Ejemplo n.º 1
0
        private void Canvas_OnMouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (Condition == null)
            {
                return;
            }
            var ic = PointMatrixPick.CreateICFromPick(Condition);
            var p  = e.GetPosition(Canvas);
            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;
            }
            _scale += Math.Sign(-e.Delta) * 0.1;
            if (_scale < 0.1)
            {
                _scale = 0.1;
            }
            if (_scale > 1)
            {
                _scale = 1;
            }

            var width   = ic.Grid.CellGrid.GetLength(0);
            var height  = ic.Grid.CellGrid.GetLength(1);
            var nwidth  = (int)(width * _scale);
            var nheight = (int)(height * _scale);
            var x       = (int)X - (nwidth / 2);
            var y       = (int)Y
                          - (nheight / 2);
            var xx = (int)X + (nwidth / 2);
            var yy = (int)Y + (nheight / 2);

            if (xx >= width)
            {
                x -= (xx - width) + 1;
            }
            if (yy >= height)
            {
                y -= (yy - height) + 1;
            }
            if (x < 0)
            {
                x = 0;
            }
            if (y < 0)
            {
                y = 0;
            }
            _x        = x;
            _y        = y;
            Condition = PointMatrixPick.CreatePickFromIC(ic, Condition);
        }
Ejemplo n.º 2
0
 public void ReCreateCondition()
 {
     ResetScale();
     if (ComboBoxCopy.SelectedIndex < 0)
     {
         return;
     }
     Condition = PointMatrixPick.CreatePickFromIC(
         _conditions[_conditionNames[ComboBoxCopy.SelectedIndex].Item2](
             _conditionNames[ComboBoxCopy.SelectedIndex].Item2.Item2, Size, (int)MatrixCount, false), Condition);
 }
Ejemplo n.º 3
0
 private void RandomSize_DragCompleted(object sender, DragCompletedEventArgs e)
 {
     ResetScale();
     if (Condition == null)
     {
         return;
     }
     if (ComboBoxCopy.SelectedIndex < 0)
     {
         Condition = PointMatrixPick.CreatePickFromIC(InitialConditions.GenerateRandom(Size, (int)MatrixCount), Condition);
         return;
     }
     Condition = PointMatrixPick.CreatePickFromIC(
         _conditions[_conditionNames[ComboBoxCopy.SelectedIndex].Item2](
             _conditionNames[ComboBoxCopy.SelectedIndex].Item2.Item2, Size, (int)MatrixCount, false), Condition);
 }
Ejemplo n.º 4
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 = PointMatrixPick.CreateICFromPick(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((int)MatrixCount)(_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((int)MatrixCount)(_comboBox.SelectedIndex);
                        }
                    }
                }
            }
            Condition = PointMatrixPick.CreatePickFromIC(ic, Condition);
        }
Ejemplo n.º 5
0
        private void ButtonBase_OnClick1(object sender, RoutedEventArgs e)
        {
            var bf  = new BinaryFormatter();
            var ofd = new OpenFileDialog
            {
                Filter      = "Initial Condition File (*.cic)|*.cic",
                Multiselect = false
            };

            var result = ofd.ShowDialog();

            if (result.HasValue && result.Value)
            {
                var fs  = new FileStream(ofd.FileName, FileMode.Open);
                var obj = bf.Deserialize(fs);
                Condition = PointMatrixPick.CreatePickFromIC(obj as InitialConditions, Condition);
                fs.Close();
            }
        }
Ejemplo n.º 6
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     ResetScale();
     Condition = PointMatrixPick.CreatePickFromIC(InitialConditions.GenerateRandom(Size, (int)MatrixCount), Condition);
     ComboBoxCopy.SelectedIndex = -1;
 }