Ejemplo n.º 1
0
        //This method manage the down button click
        private void DownButton_Click(object sender, RoutedEventArgs e)
        {
            Button   caller         = sender as Button;
            int      otherBoard_id  = boardId + 1;
            int      thisBoard_id   = boardId;
            BoardRow other_boardRow = this.parent.Boards[otherBoard_id - 1];

            caller.IsEnabled = false;

            //Doing the swap in the collections of the setup window
            BoardSwap(otherBoard_id);

            //Updating the board ids
            this.boardId           = otherBoard_id;
            other_boardRow.boardId = thisBoard_id;

            //Updating the enabled buttons
            for (int i = 0; i < this.parent.Boards.Count; i++)
            {
                this.parent.UpdateEnableUpDown(i);
            }

            this.parent.save_data_button.IsEnabled = true;
            this.parent.start_button.IsEnabled     = false;

            return;
        }
Ejemplo n.º 2
0
        //This method is called when 2 boards have to be place swapped
        private void BoardSwap(int otherBoard_ID)
        {
            int        row_indexThis   = 2 * (boardId - 1);
            int        row_indexOther  = 2 * (otherBoard_ID - 1);
            int        list_indexThis  = boardId - 1;
            int        list_indexOther = otherBoard_ID - 1;
            BoardRow   other_boardRow  = this.parent.Boards[list_indexOther];
            Board      this_board      = this.parent.Inserted_boards[list_indexThis];
            Board      other_board     = this.parent.Inserted_boards[list_indexOther];
            ChartPoint thisPoint       = this.parent.polygon.Values.GetPoints(this.parent.polygon).ElementAt(list_indexThis);
            ChartPoint otherPoint      = this.parent.polygon.Values.GetPoints(this.parent.polygon).ElementAt(list_indexOther);

            //Change the row of the elements in the grid
            Grid.SetRow(this, row_indexOther);
            Grid.SetRow(other_boardRow, row_indexThis);

            //Change the position of the elements in the boards list
            this.parent.Boards[list_indexThis]  = other_boardRow;
            this.parent.Boards[list_indexOther] = this;

            //Change the positions in the coordinateGrid.children list
            this.parent.coordinatesGrid.Children.Clear();
            for (int i = 0; i < this.parent.Boards.Count; i++)
            {
                this.parent.coordinatesGrid.Children.Add(this.parent.Boards[i]);
            }

            //Change the position of the elements in the inserted boards list
            this.parent.Inserted_boards[list_indexThis]  = other_board;
            this.parent.Inserted_boards[list_indexOther] = this_board;

            //Swapping the point representation
            this.parent.polygon.Values[list_indexThis]  = new ObservablePoint(otherPoint.X, otherPoint.Y);
            this.parent.polygon.Values[list_indexOther] = new ObservablePoint(thisPoint.X, thisPoint.Y);

            if ((boardId == 1 || otherBoard_ID == 1) && this.parent.CountBoards > 2)
            {
                double x = this.parent.Inserted_boards[0].X;
                double y = this.parent.Inserted_boards[0].Y;
                this.parent.polygon.Values[this.parent.polygon.Values.Count - 1] = new ObservablePoint(x, y);
            }

            return;
        }
        //Method used to initialize all the textboxes in the grid
        public void Initialize_created_Textboxs()
        {
            Coordinates point_to_insert   = null;
            string      mac_board         = string.Empty;
            BoardRow    lastBoardInserted = boards[boards.Count - 1];

            //Define the indexs and generate the new coordinates
            int last_board = inserted_boards.Count - 1;
            int last_point = polygon.Values.Count - 1;

            point_to_insert = Coordinates.PointsInTheMiddle(inserted_boards[last_board].Coordinates, inserted_boards[0].Coordinates, 1)[0];

            //Check how many board I have inserted yet
            if (this.countBoards - 1 > Features.leastBoardNumber)
            {
                polygon.Values.RemoveAt(last_point);
            }

            //Here I update the text attribute of the texboxes' row
            call_event = false;
            lastBoardInserted.x.Text = point_to_insert.X.ToString("N2");
            lastBoardInserted.y.Text = point_to_insert.Y.ToString("N2");
            do
            {
                mac_board = Features.Generate_Random_MAC().ToLower();
            }while (inserted_boards.Select(b => b.BoardID).Contains(mac_board));
            lastBoardInserted.MAC.Text = mac_board;
            call_event = true;

            //Updating the map and the list of boards
            polygon.Values.Add(new ObservablePoint(point_to_insert.X, point_to_insert.Y));
            inserted_boards.Add(new Board(mac_board, point_to_insert.X, point_to_insert.Y));

            //Close the figure in the map
            if (this.countBoards > Features.leastBoardNumber)
            {
                polygon.Values.Add(new ObservablePoint(inserted_boards[0].X, inserted_boards[0].Y));
            }

            return;
        }
        //----------------- INTERNAL METHODS --------------------------------------------------------------------------------------
        //Method used to add a specified number of rows of textboxes, meaning we want to add some board to the configuration
        public void Add_some_TextBox_rows(int to_add)
        {
            for (int i = 0; i < to_add; i++)
            {
                //The first board has not to have a space row before
                if (this.countBoards != 0)
                {
                    RowDefinition newSpace = new RowDefinition()
                    {
                        Height = new GridLength(25, GridUnitType.Pixel)
                    };
                    this.coordinatesGrid.RowDefinitions.Add(newSpace);
                }

                //Define the row for the new board
                RowDefinition newRow = new RowDefinition()
                {
                    Height = new GridLength(30, GridUnitType.Pixel)
                };
                this.coordinatesGrid.RowDefinitions.Add(newRow);
                this.countBoards++;

                //Initialize the new board
                BoardRow newBoard = new BoardRow(this, this.countBoards, blinking);

                //Adding the control to the Grid of the window and to the list of boards
                boards.Add(newBoard);
                this.coordinatesGrid.Children.Add(newBoard);

                //Setting the row of the board
                Grid.SetRow(newBoard, this.coordinatesGrid.RowDefinitions.Count - 1);
            }

            //Deciding what row have to have the buttons enabled and what not
            for (int i = 0; i < this.countBoards; i++)
            {
                UpdateEnableUpDown(i);
            }
        }