private void onMapTimeChanged(UserControl view) { if (view != null && view is SubbasinView) { ArcSWAT.ResultSummaryType type = (view as SubbasinView).SummaryType; if (type == ArcSWAT.ResultSummaryType.AVERAGE_ANNUAL) { lblMapTime.Text = "Map Display: Average Annual"; } else if (type == ArcSWAT.ResultSummaryType.ANNUAL) { lblMapTime.Text = "Map Display: Annual " + (view as SubbasinView).MapTime.Year.ToString(); } else { if ((view as SubbasinView).ScenarioResult.Interval == ArcSWAT.SWATResultIntervalType.DAILY) { lblMapTime.Text = string.Format("Map Display: {0:yyyy-MM-dd}", (view as SubbasinView).MapTime); } else if ((view as SubbasinView).ScenarioResult.Interval == ArcSWAT.SWATResultIntervalType.MONTHLY) { lblMapTime.Text = string.Format("Map Display: {0:yyyy-MM-dd}", (view as SubbasinView).MapTime); } } } else { lblMapTime.Text = "Map Display:"; } }
private void updateMap() { if (_type == ArcSWAT.SWATUnitType.HRU) { return; } if (_resultType == null || _col == null) { return; } //consider the result summary type in map int year = yearCtrl1.Year; _summaryType = summaryTypeCtrl1.SummaryType; if (year == -1 && _summaryType == ArcSWAT.ResultSummaryType.ANNUAL) { _summaryType = ArcSWAT.ResultSummaryType.AVERAGE_ANNUAL; } if (_summaryType == ArcSWAT.ResultSummaryType.ANNUAL) { subbasinMap1.drawLayer(_resultType, _col, new DateTime(year, 1, 1), _summaryType); } else { subbasinMap1.drawLayer(_resultType, _col, _date, _summaryType); } }
public SummaryTypeCtrl() { InitializeComponent(); //default is annual for the map display this.rdbAnnual.Checked = true; this._summaryType = ArcSWAT.ResultSummaryType.ANNUAL; this.rdbAnnual.CheckedChanged += (ss, e) => { whenClickHappens(); }; this.rdbAverageAnnual.CheckedChanged += (ss, e) => { whenClickHappens(); }; this.rdbTimeStep.CheckedChanged += (ss, e) => { whenClickHappens(); }; }
/// <summary> /// update corresponding layer /// </summary> /// <param name="type"></param> public void drawLayer(string resultType, string col, DateTime date, ArcSWAT.ResultSummaryType summaryType) { if (_type != ArcSWAT.SWATUnitType.SUB && _type != ArcSWAT.SWATUnitType.RCH) { return; } if (_workingLayer == null) { return; } if (_unitList == null && _scenario != null) { if (_type == ArcSWAT.SWATUnitType.SUB) { _unitList = _scenario.Subbasins; } if (_type == ArcSWAT.SWATUnitType.RCH) { _unitList = _scenario.Reaches; } } if (_unitList == null) { return; } _resultColumn = col; _summaryType = summaryType; _resultDate = date; Debug.WriteLine("Draw Layer, " + _workingLayer.LegendText); Debug.WriteLine("Getting results..."); DateTime d = DateTime.Now; DataTable dt = _workingLayer.DataSet.DataTable; int resultIndex = dt.Columns.IndexOf(RESULT_COLUMN); int idIndex = dt.Columns.IndexOf(ID_COLUMN_NAME); if (summaryType == ArcSWAT.ResultSummaryType.AVERAGE_ANNUAL || summaryType == ArcSWAT.ResultSummaryType.ANNUAL) { int year = -1; if (summaryType == ArcSWAT.ResultSummaryType.ANNUAL) { year = date.Year; } Dictionary <int, double> ave_annual = _scenario.getAverageAnnualResults(_type, col, year); foreach (DataRow r in dt.Rows) { r[resultIndex] = ArcSWAT.ScenarioResultStructure.EMPTY_VALUE; int id = int.Parse(r[idIndex].ToString()); r[resultIndex] = ave_annual[id]; } } else { foreach (DataRow r in dt.Rows) { r[resultIndex] = ArcSWAT.ScenarioResultStructure.EMPTY_VALUE; int id = int.Parse(r[idIndex].ToString()); if (!_unitList.ContainsKey(id)) { continue; } ArcSWAT.SWATUnit unit = _unitList[id]; if (!unit.Results.ContainsKey(resultType)) { continue; } ArcSWAT.SWATUnitResult result = unit.Results[resultType]; if (!result.Columns.Contains(col)) { continue; } if (summaryType == ArcSWAT.ResultSummaryType.TIMESTEP) { r[resultIndex] = result.getData(col, date); } else if (summaryType == ArcSWAT.ResultSummaryType.ANNUAL) //annual { r[resultIndex] = result.getData(col, date.Year); } } } Debug.WriteLine(DateTime.Now.Subtract(d).TotalMilliseconds); Debug.WriteLine("setLayerSchema"); d = DateTime.Now; //update symbol setLayerSchema(_workingLayer); Debug.WriteLine(DateTime.Now.Subtract(d).TotalMilliseconds); ////update chart //onLayerSelectionChanged(type); if (onMapUpdated != null) { onMapUpdated(this, new EventArgs()); } }
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()); } }
/// <summary> /// Handler for change /// </summary> /// <remarks>Use variable to avoid duplicated response</remarks> private void whenClickHappens() { if (_summaryType != SummaryType) { _summaryType = SummaryType; if (onSummaryTypeChanged != null) onSummaryTypeChanged(this, new EventArgs()); } }