private void setProject(ArcSWAT.Project p) { if (p == null && p.Folder.Equals(_prj.Folder)) { return; } this.Nodes.Clear(); TreeNode prjNode = this.Nodes.Add("Project"); prjNode.Tag = p; foreach (ArcSWAT.Scenario s in p.Scenarios.Values) { addNodes(prjNode, s); } prjNode.ExpandAll(); //select project node //if(prjNode.Nodes.Count > 0) // this.OnNodeMouseClick( // new TreeNodeMouseClickEventArgs(prjNode, System.Windows.Forms.MouseButtons.Left,-1,-1,-1)); }
private void Form2_Load(object sender, EventArgs e) { //ArcSWAT.Project p = new ArcSWAT.Project(@"C:\Swat\ArcSWAT\Databases\Example1_model"); //University ArcSWAT.Project p = new ArcSWAT.Project(@"C:\Users\zyu\Downloads\LaSalleArcswat2013-05-01\Lasalle-new"); //University La Salle //ArcSWAT.Project p = new ArcSWAT.Project(@"C:\Users\yuz\Downloads\Example1_model"); //AAFC //subbasinView1.setProjectScenario(p, p.Scenarios["Default"].getModelResult(ArcSWAT.SWATModelType.SWAT_488), // ArcSWAT.SWATUnitType.RCH); }
/// <summary> /// For project view /// </summary> /// <param name="project"></param> public void setProject(ArcSWAT.Project project) { _project = project; this.MapFrame.ProjectionModeDefine = DotSpatial.Controls.ActionMode.Always; this.MapFrame.ProjectionModeReproject = DotSpatial.Controls.ActionMode.Never; this.Resized += (ss, ee) => { this.ZoomToMaxExtent(); }; //add layers drawObservationLayers(); this.FunctionMode = DotSpatial.Controls.FunctionMode.Select; }
private void Form1_Load(object sender, EventArgs e) { ArcSWAT.Project p = new ArcSWAT.Project(@"C:\Swat\ArcSWAT\Databases\Example1_model"); //University //ArcSWAT.Project p = new ArcSWAT.Project(@"C:\Users\yuz\Downloads\Example1_model"); //AAFC //richTextBox1.Text = p.ToString(); //System.Diagnostics.Debug.WriteLine(richTextBox1.Text); //projectTree1.Project = p; //DataTable dt = ArcSWAT.Query.GetDataTable("select date(printf('%d-%02d-%02d',yr,mo,da)) from sub where sub=1", // @"C:\Swat\ArcSWAT\Databases\Example1_model\Scenarios\Default\TxtInOut\result.db3"); //foreach (DataRow r in dt.Rows) // System.Diagnostics.Debug.WriteLine(r[0]); //tableResultsCtrl1.SWATUnits = p.Scenarios["Default"].getModelResult(ArcSWAT.SWATModelType.SWAT_488).Subbasins; p.Scenarios["Default"].modifyOutputInterval(ArcSWAT.SWATResultIntervalType.MONTHLY); }
public void setProjectScenario(ArcSWAT.Project project, ArcSWAT.ScenarioResult scenario) { this.Resize += (ss, ee) => { this.splitContainer2.SplitterDistance = 72; }; _project = project; _scenario = scenario; _date = new DateTime(scenario.StartYear, 1, 1); //year control yearCtrl1.Scenario = scenario; yearCtrl1.onYearChanged += (s, e) => { updateTableAndChart(); }; //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; updateTableAndChart(); }; resultColumnTree1.setScenarioAndUnit(scenario, ArcSWAT.SWATUnitType.WSHD); //chart export outputDisplayChart1.onExport += (s, e) => { }; //compare control compareCtrl1.ScenarioResult = scenario; compareCtrl1.onCompareResultChanged += (ss, ee) => { _compareResult = compareCtrl1.CompareResult; updateTableAndChart(); }; //update updateTableAndChart(); this.tableView2.DataTable = this._scenario.Watershed.AverageAnnualBasinTable; }
/// <summary> /// For result display view /// </summary> /// <param name="project"></param> /// <param name="scenario"></param> /// <param name="type"></param> public void setProjectScenario(ArcSWAT.Project project, ArcSWAT.ScenarioResult scenario, ArcSWAT.SWATUnitType type) { if (type != ArcSWAT.SWATUnitType.SUB && type != ArcSWAT.SWATUnitType.RCH && type != ArcSWAT.SWATUnitType.HRU && type != ArcSWAT.SWATUnitType.RES) { return; } _project = project; _scenario = scenario; _type = type; this.MapFrame.ProjectionModeDefine = DotSpatial.Controls.ActionMode.Always; this.MapFrame.ProjectionModeReproject = DotSpatial.Controls.ActionMode.Never; this.Resized += (ss, ee) => { this.ZoomToMaxExtent(); }; this.Layers.Clear(); if (type == ArcSWAT.SWATUnitType.SUB) { _workingLayer = addLayer(project.Spatial.SubbasinShapefile, "Subbasin", false, true); addLayer(project.Spatial.ReachShapefile, "Reach", false, false); } else if (type == ArcSWAT.SWATUnitType.RCH) { addLayer(project.Spatial.SubbasinShapefile, "Subbasin", false, false); _workingLayer = addLayer(project.Spatial.ReachShapefile, "Reach", false, true); } else if (type == ArcSWAT.SWATUnitType.HRU) { _workingLayer = addLayer(project.Spatial.SubbasinShapefile, "Subbasin", false, true); addLayer(project.Spatial.ReachShapefile, "Reach", false, false); } else if (type == ArcSWAT.SWATUnitType.RES) { addLayer(project.Spatial.SubbasinShapefile, "Subbasin", false, false); addLayer(project.Spatial.ReachShapefile, "Reach", false, false); _workingLayer = addLayer(project.Spatial.MonitoringShapefile, "Reservoir", false, true); } this.FunctionMode = DotSpatial.Controls.FunctionMode.Select; }
private void openProject(string prjPath) { if (_prj != null && prjPath.Equals(_prj.Folder)) { return; } try { _prj = new ArcSWAT.Project(prjPath); } catch (Exception e) { SWAT_SQLite.showInformationWindow(e.Message); return; } if (!_prj.IsValid) { _prj = null; //remove the path if it's not there anymore if (Properties.Settings.Default.Projects.Contains(prjPath)) { Properties.Settings.Default.Projects.Remove(prjPath); Properties.Settings.Default.Save(); cmbProjects.Items.Remove(prjPath); } System.Windows.Forms.MessageBox.Show(prjPath + " is not a valid ArcSWAT project folder."); return; } projectTree1.Project = _prj; //clear views _views.Clear(); _projectView = null; //see what view is currently used if (splitContainer1.Panel2.Controls.Count > 0) { Control currentView = splitContainer1.Panel2.Controls[0]; if (currentView is ProjectView) { updateProjectView(); } else if (currentView is ScenarioView) { if (_prj.Scenarios.Count > 0) { updateScenarioView(_prj.Scenarios.First().Value); } else { updateScenarioView(null); } } else { splitContainer1.Panel2.Controls.Clear(); } } //save current path Properties.Settings.Default.PreviousProjectFolder = prjPath; if (!Properties.Settings.Default.Projects.Contains(prjPath)) { Properties.Settings.Default.Projects.Add(prjPath); cmbProjects.Items.Add(prjPath); cmbProjects.SelectedIndex = cmbProjects.Items.Count - 1; } Properties.Settings.Default.Save(); }
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(); }
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()); } }