Esempio n. 1
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            var p = RiverSimulationProfile.profile;
            var selectedCellCount = dataGv.GetCellCount(DataGridViewElementStates.Selected);

            if (selectedCellCount <= 0)
            {
                return;
            }

            int index = selCombo.SelectedIndex;
            int type = 0, count = 0;

            GetTypeAndCount(index, ref type, ref count);

            List <Point> pl = new List <Point>();     //表格內被選取的格網點

            for (int i = 0; i < selectedCellCount; ++i)
            {
                pl.Add(new Point(dataGv.SelectedCells[i].RowIndex, dataGv.SelectedCells[i].ColumnIndex));
            }

            List <Point> pts        = (type == 0) ? sideOutObjects[count].sideFlowPoints : sideInObjects[count].sideFlowPoints;
            List <Point> plSelected = (pts == null) ? null : new List <Point>(pts);

            if (null != plSelected)
            {   //正在編輯的結構物不為空則合併被選取的格網點到正在編輯的結構物中
                SideFlowtUtility.MergePoints(ref plSelected, pl);
                SideFlowtUtility.TrimToEdge(ref plSelected, p.inputGrid.GetI, p.inputGrid.GetJ);
            }
            else
            {   //正在編輯的結構物還沒有任何格網點
                if (!SideFlowtUtility.TrimToEdge(ref pl, p.inputGrid.GetI, p.inputGrid.GetJ))
                {
                    MessageBox.Show("請圈選邊界!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                plSelected = new List <Point>(pl);
            }

            if (!SideFlowtUtility.IsContinuous(plSelected))
            {   //檢查是否連續
                FillDataGrid(plSelected, true);
                MessageBox.Show("新增後不是連續區域,請重新選取!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                FillDataGrid();
                return;
            }

            if (type == 0)
            {
                sideOutObjects[count].sideFlowPoints = plSelected;
            }
            else
            {
                sideInObjects[count].sideFlowPoints = plSelected;
            }

            FillDataGrid();
            dataGv.ClearSelection();
        }