예제 #1
0
        public static PointMatrixPick CreatePickFromIC(InitialConditions IC, PointMatrixPick _pick)
        {
            PointMatrixPick Condition = new PointMatrixPick();

            Condition.Matrices = _pick.Matrices.ToList();
            Condition.Indices  = new int[IC.Grid.CellGrid.GetLength(0), IC.Grid.CellGrid.GetLength(1)];
            for (int i = 0; i < IC.Grid.CellGrid.GetLength(0); i++)
            {
                for (int j = 0; j < IC.Grid.CellGrid.GetLength(1); j++)
                {
                    Condition.Indices[i, j] = IC.Grid.CellGrid[i, j].Value >= Condition.Matrices.Count ? Condition.Matrices.Count - 1 : IC.Grid.CellGrid[i, j].Value;
                }
            }
            return(Condition);
        }
예제 #2
0
        public static InitialConditions CreateICFromPick(PointMatrixPick Condition)
        {
            var IC = new InitialConditions();
            var IG = new InitialConditionsGrid();

            IG.CellGrid = new InitialConditionCell[Condition.Indices.GetLength(0), Condition.Indices.GetLength(1)];
            for (int i = 0; i < Condition.Indices.GetLength(0); i++)
            {
                for (int j = 0; j < Condition.Indices.GetLength(1); j++)
                {
                    IG.CellGrid[i, j] = new InitialConditionCell(i, j, Condition.Indices[i, j], Condition.Indices[i, j]);
                }
            }
            IC.Grid = IG;
            return(IC);
        }
예제 #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);
 }
예제 #4
0
        /// <summary>
        /// Metoda factory generująca koło
        /// </summary>
        /// <param name="reversed">Czy wartości mają być odwrócone</param>
        /// <param name="size">Rozmiar</param>
        /// <param name="stateCount">Ilość możliwych wartości komórek</param>
        /// <returns>Układ początkowy z kołem</returns>
        internal static InitialConditions CircleFactory(bool reversed = false, int size = 30, int stateCount = SPDAssets.MAX, bool twoState = false)
        {
            InitialConditionsGrid ig = InitialConditionsGrid.CircleFactory(size, twoState ? 2 : stateCount);

            ig.Transform(GetTransformation(twoState ? 2 : stateCount, reversed), twoState ? 2 : stateCount);
            if (twoState)
            {
                ig.Transform((x) => (x == 0 ? 0 : stateCount - 1), 2);
            }
            var ic = new InitialConditions
            {
                Name = "Koło " + (reversed ? "- odwrócone kolory" : ""),
                Grid = ig
            };

            return(ic);
        }
예제 #5
0
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var ic = new InitialCondition(2 + GetNeighboursCount((Neighbourhoods)NeighbourBox.SelectedItem, (int)Slider1.Value), _ic);
            var b  = ic.ShowDialog();

            if (!b.HasValue || !b.Value)
            {
                return;
            }
            if (pointMatrix != null && ic.Condition.Grid.CellGrid.GetLength(0) != pointMatrix.Size)
            {
                AdvancedMatrixAccepted = false;
            }
            _ic = ic.Condition;
            NotifyPropertyChanged("NoError");
            NotifyPropertyChanged("NoAdvancedError");
        }
예제 #6
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;
        }
예제 #7
0
        public MainWindow()
        {
            SPDAssets.CreateBrushes();
            SPDAssets.ChangeFont("Arial");
            SPDAssets.InitialiseDescriptions();
            _colorPicking = ColorPicking.RegularPickingFactory(10);
            InitializeComponent();

            InitialConditions.Initialise();
            ShapeBox.ItemsSource      = Enum.GetValues(typeof(Shape));
            NeighbourBox.ItemsSource  = Enum.GetValues(typeof(Neighbourhoods));
            ShapeBox.SelectedItem     = Shape.Płaski;
            NeighbourBox.SelectedItem = Neighbourhoods.Moore;

            DataContext  = this;
            Error        = ValidationErrors.None;
            _canvalidate = true;
        }
예제 #8
0
        /// <summary>
        /// Metoda generująca losowy układ
        /// </summary>
        /// <param name="size">Rozmiar układu</param>
        /// <param name="stateCount">Ilość możliwych wartości komórek</param>
        /// <returns>Układ początkowy</returns>
        internal static InitialConditions GenerateRandom(int size = 100, int stateCount = SPDAssets.MAX, bool twoState = false)
        {
            Random r    = new Random();
            var    Grid = InitialConditionsGrid.GenerateRandom(r, size, twoState?2:stateCount);

            Grid.Transform(GetTransformation(twoState ? 2 : stateCount), twoState ? 2 : stateCount);
            if (twoState)
            {
                Grid.Transform((x) => (x == 0 ? 0 : stateCount - 1), 2);
            }

            var ic = new InitialConditions
            {
                Name = "Losowy" + r.Next(),
                Grid = Grid
            };

            return(ic);
        }
예제 #9
0
        private void CicSave_OnClick(object sender, RoutedEventArgs e)
        {
            var sfd = new SaveFileDialog {
                Filter = "Initial Condition (*.cic)|*.cic"
            };
            var v = sfd.ShowDialog();

            if (!v.HasValue || !v.Value)
            {
                return;
            }
            var c   = GetStateByIteration(_iter);
            var ifc = InitialConditions.FromCellArray(c, Path.GetFileName(sfd.FileName));
            var bf  = new BinaryFormatter();
            var fs  = new FileStream(sfd.FileName, FileMode.Create);

            bf.Serialize(fs, ifc);
            fs.Close();
        }
예제 #10
0
 private void Slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     _ic = null;
     NotifyPropertyChanged("NoError");
     UpdateColors();
 }
예제 #11
0
 private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     _ic = null;
     NotifyPropertyChanged("NoError");
     UpdateColors();
 }
예제 #12
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     ResetScale();
     Condition = InitialConditions.GenerateRandom((int)RandomSize.Value, Mode, IsTwoState);
     ComboBoxCopy.SelectedIndex = -1;
 }
예제 #13
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     ResetScale();
     Condition = PointMatrixPick.CreatePickFromIC(InitialConditions.GenerateRandom(Size, (int)MatrixCount), Condition);
     ComboBoxCopy.SelectedIndex = -1;
 }