Пример #1
0
        public void setProjectScenario(ArcSWAT.Project project, ArcSWAT.ScenarioResult scenario, ArcSWAT.SWATUnitType type)
        {
            _project  = project;
            _scenario = scenario;
            _type     = type;
            _date     = new DateTime(scenario.StartYear, 1, 1);
            if (onMapTimeChanged != null)
            {
                onMapTimeChanged(this, new EventArgs());
            }

            if (type == ArcSWAT.SWATUnitType.SUB)
            {
                _unitList = _scenario.Subbasins;
            }
            else if (type == ArcSWAT.SWATUnitType.RCH)
            {
                _unitList = _scenario.Reaches;
            }
            else if (type == ArcSWAT.SWATUnitType.HRU)
            {
                _unitList = _scenario.HRUs;
            }
            else if (type == ArcSWAT.SWATUnitType.RES)
            {
                _unitList = _scenario.Reservoirs;
            }

            this.Resize += (ss, ee) => { splitContainer3.SplitterDistance = 72; };

            //swat input files extension list
            swatFileList1.SWATUnitType = _type;
            swatFileList1.onSWATInputFileExtensionChanged += (s, e) =>
            {
                if (_unit == null)
                {
                    return;
                }
                string fileName = _unit.getInputFileName(swatFileList1.Extension);
                if (!System.IO.File.Exists(fileName))
                {
                    SWAT_SQLite.showInformationWindow(fileName + " doesn't exist!");
                    return;
                }

                string notePad = System.Environment.SystemDirectory + @"\notepad.exe";
                if (System.IO.File.Exists(notePad))
                {
                    System.Diagnostics.Process.Start(notePad, fileName);
                }
            };

            //id list
            if (type == ArcSWAT.SWATUnitType.HRU)
            {
                idList1.IDs = scenario.getSWATUnitIDs(ArcSWAT.SWATUnitType.SUB);
            }
            else
            {
                idList1.IDs = scenario.getSWATUnitIDs(type);
            }

            idList1.onIDChanged += (s, e) => { onIDChanged(idList1.ID); subbasinMap1.ID = idList1.ID; };

            //season control
            seasonCtrl1.onSeasonTypeChanged += (s, e) => { tableView1.Season = seasonCtrl1.Season; outputDisplayChart1.Season = seasonCtrl1.Season; updateTableAndChart(); };

            //year control
            yearCtrl1.Scenario       = scenario;
            yearCtrl1.onYearChanged += (s, e) => { updateTableAndChart(); };

            //only for subbasin to show hru list
            hruList1.Visible            = (type == ArcSWAT.SWATUnitType.SUB || type == ArcSWAT.SWATUnitType.HRU);
            hruList1.IsChangeWhenSelect = (type == ArcSWAT.SWATUnitType.HRU);
            hruList1.onSwitch2HRU      += (hru) =>
            {
                if (_type == ArcSWAT.SWATUnitType.HRU)
                {
                    if (_unit != null && _unit.ID == hruList1.HRU.ID)
                    {
                        return;
                    }

                    _unit = hruList1.HRU;

                    //show basic information
                    if (onMapSelectionChanged != null)
                    {
                        onMapSelectionChanged(this, new EventArgs());
                    }

                    //update table and chart
                    updateTableAndChart();
                }
                if (_type == ArcSWAT.SWATUnitType.SUB)
                {
                    if (onSwitch2HRU != null)
                    {
                        onSwitch2HRU(hru);
                    }
                }
            };

            //columns
            resultColumnTree1.onResultTypeAndColumnChanged += (resultType, col) =>
            {
                _resultType = resultType;
                _col        = col;

                //only for daily and monthly
                this.yearCtrl1.Visible = _scenario.Structure.getInterval(_resultType) == ArcSWAT.SWATResultIntervalType.DAILY ||
                                         _scenario.Structure.getInterval(_resultType) == ArcSWAT.SWATResultIntervalType.MONTHLY;

                updateMap();
                updateTableAndChart();
            };
            resultColumnTree1.setScenarioAndUnit(scenario, type);

            //map
            subbasinMap1.onLayerSelectionChanged += (unitType, id) => { onIDChanged(id); idList1.ID = id; };
            subbasinMap1.setProjectScenario(project, scenario, type);

            //chart export
            outputDisplayChart1.onExport += (s, e) =>
            {
            };

            //table view
            tableView1.onDateChanged += (d) =>
            {
                if (_type == ArcSWAT.SWATUnitType.HRU)
                {
                    return;
                }
                _date = d;
                if (onMapTimeChanged != null)
                {
                    onMapTimeChanged(this, new EventArgs());
                }
                updateMap();
            };

            //compare control
            compareCtrl1.ScenarioResult          = scenario;
            compareCtrl1.onCompareResultChanged += (ss, ee) =>
            {
                updateTableAndChart();
            };


            //update
            updateMap();
            updateTableAndChart();
        }
Пример #2
0
        public void setProjectScenario(ArcSWAT.Project project, ArcSWAT.ScenarioResult scenario, ArcSWAT.SWATUnitType type)
        {
            _project  = project;
            _scenario = scenario;
            _type     = type;
            _date     = new DateTime(scenario.StartYear, 1, 1);
            if (onMapTimeChanged != null)
            {
                onMapTimeChanged(this, new EventArgs());
            }

            if (type == ArcSWAT.SWATUnitType.SUB)
            {
                _unitList = _scenario.Subbasins;
            }
            else if (type == ArcSWAT.SWATUnitType.RCH)
            {
                _unitList = _scenario.Reaches;
            }
            else if (type == ArcSWAT.SWATUnitType.HRU)
            {
                _unitList = _scenario.HRUs;
            }
            else if (type == ArcSWAT.SWATUnitType.RES)
            {
                _unitList = _scenario.Reservoirs;
            }

            this.Resize += (ss, ee) => { splitContainer3.SplitterDistance = 72; };

            //swat input files extension list
            swatFileList1.SWATUnitType = _type;
            swatFileList1.onSWATInputFileExtensionChanged += (s, e) =>
            {
                if (_unit == null)
                {
                    return;
                }
                string fileName = _unit.getInputFileName(swatFileList1.Extension);
                if (!System.IO.File.Exists(fileName))
                {
                    SWAT_SQLite.showInformationWindow(fileName + " doesn't exist!");
                    return;
                }

                string notePad = System.Environment.SystemDirectory + @"\notepad.exe";
                if (System.IO.File.Exists(notePad))
                {
                    System.Diagnostics.Process.Start(notePad, fileName);
                }
            };

            //id list
            if (type == ArcSWAT.SWATUnitType.HRU)
            {
                idList1.IDs = scenario.getSWATUnitIDs(ArcSWAT.SWATUnitType.SUB);
            }
            else
            {
                idList1.IDs = scenario.getSWATUnitIDs(type);
            }

            idList1.onIDChanged += (s, e) => { onIDChanged(idList1.ID); subbasinMap1.ID = idList1.ID; setMapTalbeIDSelection(idList1.ID); };

            //season control
            seasonCtrl1.onSeasonTypeChanged += (s, e) => { tableView1.Season = seasonCtrl1.Season; outputDisplayChart1.Season = seasonCtrl1.Season; updateTableAndChart(); };

            //year control
            yearCtrl1.Scenario       = scenario;
            yearCtrl1.onYearChanged += (s, e) =>
            {
                //update the summary type control
                summaryTypeCtrl1.CurrentYear = yearCtrl1.Year;

                //update the time step map view and summary control
                if (yearCtrl1.Year != -1)
                {
                    _date = new DateTime(yearCtrl1.Year, 1, 1);
                    summaryTypeCtrl1.TimeForTimeStep = _date;

                    //update the status bar
                    if (onMapTimeChanged != null)
                    {
                        onMapTimeChanged(this, new EventArgs());
                    }
                }

                //update map
                if (_summaryType != ArcSWAT.ResultSummaryType.AVERAGE_ANNUAL) //only update map when it's not average annual
                {
                    this.updateMap();
                }

                updateTableAndChart();
            };

            //summary type control for map
            summaryTypeCtrl1.ScenarioResult        = scenario;
            summaryTypeCtrl1.onSummaryTypeChanged += (s, e) =>
            {
                _summaryType = summaryTypeCtrl1.SummaryType;
                this.updateMap();                     //update the status bar
                if (onMapTimeChanged != null)
                {
                    onMapTimeChanged(this, new EventArgs());
                }
            };

            //only for subbasin to show hru list
            hruList1.Visible            = (type == ArcSWAT.SWATUnitType.SUB || type == ArcSWAT.SWATUnitType.HRU);
            hruList1.IsChangeWhenSelect = (type == ArcSWAT.SWATUnitType.HRU);
            hruList1.onSwitch2HRU      += (hru) =>
            {
                if (_type == ArcSWAT.SWATUnitType.HRU)
                {
                    if (_unit != null && _unit.ID == hruList1.HRU.ID)
                    {
                        return;
                    }

                    _unit = hruList1.HRU;

                    //show basic information
                    if (onMapSelectionChanged != null)
                    {
                        onMapSelectionChanged(this, new EventArgs());
                    }

                    //update table and chart
                    updateTableAndChart();
                }
                if (_type == ArcSWAT.SWATUnitType.SUB)
                {
                    if (onSwitch2HRU != null)
                    {
                        onSwitch2HRU(hru);
                    }
                }
            };

            //columns
            resultColumnTree1.onResultTypeAndColumnChanged += (resultType, col) =>
            {
                _resultType = resultType;
                _col        = col;

                //only for daily and monthly
                this.yearCtrl1.Visible = _scenario.Structure.getInterval(_resultType) == ArcSWAT.SWATResultIntervalType.DAILY ||
                                         _scenario.Structure.getInterval(_resultType) == ArcSWAT.SWATResultIntervalType.MONTHLY;

                updateMap();
                updateTableAndChart();
            };
            resultColumnTree1.setScenarioAndUnit(scenario, type);

            //the id selection changed
            tblMapData.RowHeadersVisible = false;
            tblMapData.ReadOnly          = true;
            tblMapData.Sorted           += (s, e) =>
            {
                //System.Diagnostics.Debug.WriteLine("--------");
                //foreach (DataGridViewRow r in tblMapData.Rows)
                //{
                //    if (r.Cells[0].Value == null) continue;
                //    System.Diagnostics.Debug.WriteLine(r.Cells[0].Value);
                //}
            };
            tblMapData.RowEnter += onMapTableIDChanged;

            //map
            subbasinMap1.onLayerSelectionChanged += (unitType, id) => { onIDChanged(id); idList1.ID = id; setMapTalbeIDSelection(id); };
            subbasinMap1.setProjectScenario(project, scenario, type);
            subbasinMap1.onMapUpdated += (s, e) =>
            {
                //get current selected id on map
                //if none is selected, will be -1
                //will keep the current the selection when the datasource of map data table view is changed
                int id = subbasinMap1.ID;
                if (id > 0)
                {
                    this.tblMapData.RowEnter -= onMapTableIDChanged;            //remove the handler, don't need to do this when none is selected
                }
                this.tblMapData.DataSource = subbasinMap1.DataTable;            //set data
                if (id > 0)
                {
                    setMapTalbeIDSelection(id);                                 //use current selected id, don't change to a new one
                    this.tblMapData.RowEnter += onMapTableIDChanged;            //resume the handler
                }

                tblMapData.Columns[SubbasinMap.ID_COLUMN_NAME].HeaderText             = _resultType.ToString().ToLower();
                tblMapData.Columns[SubbasinMap.RESULT_COLUMN].HeaderText              = _col;
                tblMapData.Columns[SubbasinMap.RESULT_COLUMN].DefaultCellStyle.Format = "F4";
            };

            //chart export
            outputDisplayChart1.onExport += (s, e) =>
            {
            };

            //table view
            tableView1.onDateChanged += (d) =>
            {
                if (_type == ArcSWAT.SWATUnitType.HRU)
                {
                    return;
                }
                _date = d;
                summaryTypeCtrl1.TimeForTimeStep = d;

                if (onMapTimeChanged != null)
                {
                    onMapTimeChanged(this, new EventArgs());
                }
                if (_summaryType == ArcSWAT.ResultSummaryType.TIMESTEP)
                {
                    updateMap();
                }
            };

            //compare control
            compareCtrl1.ScenarioResult          = scenario;
            compareCtrl1.onCompareResultChanged += (ss, ee) =>
            {
                updateTableAndChart();
            };


            //update
            updateMap();
            updateTableAndChart();

            //update the status bar
            if (onMapTimeChanged != null)
            {
                onMapTimeChanged(this, new EventArgs());
            }
        }