示例#1
0
        public ProjectView()
        {
            InitializeComponent();

            _interval = intervalCtrl1.Interval;
            subbasinMap1.Interval = _interval;
        }
示例#2
0
        /// <summary>
        /// This method may be called in another thread.
        /// </summary>
        /// <param name="scenNode"></param>
        /// <param name="scenario"></param>
        /// <param name="modelType"></param>
        private void AddScenarioResult(TreeNode scenNode, ArcSWAT.Scenario scenario, ArcSWAT.SWATModelType modelType)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new addScenarioResultDelegate(AddScenarioResult), scenNode, scenario, modelType);
            }
            else
            {
                foreach (TreeNode n in scenNode.Nodes)
                {
                    if (n.Text.Equals(modelType.ToString()))
                    {
                        scenNode.Nodes.Remove(n); //remove the existing one and then add to update its status.
                        break;
                    }
                }

                TreeNode modelTypeNode = null;
                for (int j = Convert.ToInt32(ArcSWAT.SWATResultIntervalType.MONTHLY); j <= Convert.ToInt32(ArcSWAT.SWATResultIntervalType.YEARLY); j++)
                {
                    ArcSWAT.SWATResultIntervalType interval = (ArcSWAT.SWATResultIntervalType)j;

                    ArcSWAT.ScenarioResult result = scenario.getModelResult(modelType, interval);
                    if (result == null)
                    {
                        continue;
                    }
                    if (result.Status != ArcSWAT.ScenarioResultStatus.NORMAL)
                    {
                        continue;
                    }

                    if (modelTypeNode == null)
                    {
                        modelTypeNode     = scenNode.Nodes.Add(modelType.ToString());
                        modelTypeNode.Tag = modelType;
                    }

                    TreeNode resultNode = modelTypeNode.Nodes.Add(interval.ToString());
                    resultNode.Tag = modelType;
                    resultNode.Nodes.Add("Watershed").Tag = result;
                    resultNode.Nodes.Add("HRU").Tag       = result;
                    resultNode.Nodes.Add("Subbasin").Tag  = result;
                    resultNode.Nodes.Add("Reach").Tag     = result;
                    if (result.Reservoirs.Count > 0)
                    {
                        resultNode.Nodes.Add("Reservoir").Tag = result;
                    }
                    resultNode.Nodes.Add("Difference").Tag  = result;
                    resultNode.Nodes.Add("Performance").Tag = result;
                }

                scenNode.ExpandAll();
            }
        }
        private void setChartArea(DataTable dt, ArcSWAT.SWATResultIntervalType interval)
        {
            if (interval == ArcSWAT.SWATResultIntervalType.MONTHLY) //monthly
            {
                _chartArea.AxisX.Title = "Time (monthly)";
                if (dt.Rows.Count == 12) //for one year
                {
                    _chartArea.AxisX.LabelStyle.Format = "yyyy/MM";
                    _chartArea.AxisX.LabelStyle.Angle  = 0;

                    _chartArea.AxisX.MajorTickMark.Interval     = 1;
                    _chartArea.AxisX.MajorTickMark.IntervalType = DateTimeIntervalType.Months;
                }
                else
                {
                    _chartArea.AxisX.LabelStyle.Format = "yyyy";
                    _chartArea.AxisX.LabelStyle.Angle  = 0;

                    _chartArea.AxisX.MajorTickMark.Interval     = 1; //half a year
                    _chartArea.AxisX.MajorTickMark.IntervalType = DateTimeIntervalType.Years;
                }
            }
            else if (interval == ArcSWAT.SWATResultIntervalType.DAILY) //daily
            {
                _chartArea.AxisX.Title             = "Time (daily)";
                _chartArea.AxisX.LabelStyle.Format = "yyyy-MM-dd";
                //_chartArea.AxisX.LabelStyle.Angle = -45;

                if (dt.Rows.Count == 365 || dt.Rows.Count == 366) //for one year
                {
                    _chartArea.AxisX.MajorTickMark.Interval     = 1;
                    _chartArea.AxisX.MajorTickMark.IntervalType = DateTimeIntervalType.Months;
                }
                else//all year
                {
                    _chartArea.AxisX.MajorTickMark.Interval     = 1; //half a year
                    _chartArea.AxisX.MajorTickMark.IntervalType = DateTimeIntervalType.Years;
                }
            }
            else //yearly
            {
                _chartArea.AxisX.Title             = "Year";
                _chartArea.AxisX.LabelStyle.Format = "yyyy";
                _chartArea.AxisX.LabelStyle.Angle  = 0;

                _chartArea.AxisX.MajorTickMark.Interval     = 1; //half a year
                _chartArea.AxisX.MajorTickMark.IntervalType = DateTimeIntervalType.Years;
            }
        }
示例#4
0
        private void ProjectView_Load(object sender, EventArgs e)
        {
            this.Resize += (ss, ee) => { this.splitContainer1.SplitterDistance = this.Width - 200; };

            cmbObservedColumns.SelectedIndexChanged += (ss, ee) =>
            {
                if (cmbObservedColumns.SelectedIndex == -1)
                {
                    _col = null;
                }
                else
                {
                    _col = ArcSWAT.ObservationData.getObservationSWATColumn(cmbObservedColumns.SelectedItem.ToString());
                }
                updateTableAndChart();
            };

            subbasinMap1.onLayerSelectionChanged += (unitType, id) =>
            {
                cmbObservedColumns.DataSource = null;
                updateTableAndChart();

                if (id <= 0)
                {
                    return;
                }

                _id       = id;
                _unitType = unitType;
                cmbObservedColumns.DataSource =
                    ArcSWAT.ObservationData.getObservationDataColumns(_unitType);
                cmbObservedColumns.SelectedIndex = 0;
                if (onMapSelectionChanged != null)
                {
                    onMapSelectionChanged(this, new EventArgs());
                }
            };

            yearCtrl1.onYearChanged += (ss, ee) => { _year = yearCtrl1.Year; updateTableAndChart(); };

            intervalCtrl1.onIntervalChanged += (ss, ee) =>
            {
                _interval                     = intervalCtrl1.Interval;
                subbasinMap1.Interval         = _interval;
                cmbObservedColumns.DataSource = null;
                updateTableAndChart();
            };
        }
示例#5
0
        private void RunSWAT(ArcSWAT.SWATModelType modelType, ArcSWAT.SWATResultIntervalType interval)
        {
            if (_scenario == null)
            {
                return;
            }
            if (modelType == ArcSWAT.SWATModelType.UNKNOWN)
            {
                return;
            }
            if (interval == ArcSWAT.SWATResultIntervalType.UNKNOWN)
            {
                return;
            }
            if (_scenario.getModelResult(modelType, interval).Status == ArcSWAT.ScenarioResultStatus.NORMAL)
            {
                if (MessageBox.Show("There is a pre-generated model result. Do you want to overwrite?", SWAT_SQLite.NAME, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                {
                    return;
                }
            }

            //find the corresponding executables
            string swatexe = SWAT_SQLite.InstallationFolder + @"swat_exes\" + ArcSWAT.ScenarioResultStructure.getSWATExecutableName(modelType);

            if (!System.IO.File.Exists(swatexe))
            {
                SWAT_SQLite.showInformationWindow("Can't find " + swatexe);
                return;
            }

            //change output interval
            _scenario.modifyOutputInterval(interval);

            //start to run the model
            Process myProcess = new Process();

            try
            {
                myProcess.EnableRaisingEvents              = true;
                myProcess.StartInfo.UseShellExecute        = false;
                myProcess.StartInfo.FileName               = swatexe;
                myProcess.StartInfo.CreateNoWindow         = true;
                myProcess.StartInfo.RedirectStandardError  = true;
                myProcess.StartInfo.RedirectStandardOutput = true;
                myProcess.StartInfo.WorkingDirectory       = _scenario.ModelFolder;
                myProcess.OutputDataReceived              += (sender, agrs) =>
                {
                    if (agrs.Data != null)
                    {
                        updateMessage(agrs.Data);
                    }
                };
                myProcess.ErrorDataReceived += (sender, agrs) =>
                {
                    if (agrs.Data != null)
                    {
                        updateMessage(agrs.Data);
                    }
                };
                myProcess.Exited += (send, agrs) =>
                {
                    //update the results
                    if (onSimulationFinished != null)
                    {
                        onSimulationFinished(modelType, interval);
                    }

                    //update the date time of the result
                    //must be called after onSimulationFinished as the result status is updated in onSimulationFinished
                    updateSimulationTime();
                };
                updateMessage("Runing " + ModelType.ToString() + " in " + _scenario.ModelFolder);
                myProcess.Start();
                myProcess.BeginOutputReadLine();
                //myProcess.WaitForExit();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
        private void DrawGraph(DataTable dt, string xColName, StringCollection yColNames, ArcSWAT.SWATResultIntervalType interval)
        {
            if (_chartArea == null)
            {
                this.ChartAreas.Clear();
                this.Series.Clear();
                this.Titles.Clear();

                _chartArea                                   = this.ChartAreas.Add("chart_area");
                _chartArea.AxisY.Title                       = "y";
                _chartArea.AxisX.MajorGrid.Enabled           = false;
                _chartArea.AxisY.MajorGrid.Enabled           = false;
                _chartArea.AxisX.MajorTickMark.TickMarkStyle = TickMarkStyle.AcrossAxis;

                //context menu
                System.Windows.Forms.ToolStripMenuItem exportMenu =
                    new System.Windows.Forms.ToolStripMenuItem("Export current results to CSV");
                exportMenu.Click += (ss, _e) => { export(); };


                this.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip();
                this.ContextMenuStrip.Items.Add(exportMenu);
            }

            clear();

            if (dt.Rows == null || dt.Rows.Count == 0)
            {
                return;
            }
            if (yColNames == null || yColNames.Count == 0)
            {
                return;
            }
            if (interval == ArcSWAT.SWATResultIntervalType.UNKNOWN)
            {
                return;
            }

            this.DataSource = dt.Rows;
            if (yColNames.Count == 1)
            {
                _chartArea.AxisY.Title = yColNames[0];
            }

            int index = 0;

            foreach (string yColName in yColNames)
            {
                Series line = getLine(index);
                line.XValueMember  = xColName;
                line.YValueMembers = yColName;
                line.LegendText    = yColName;

                if (interval == ArcSWAT.SWATResultIntervalType.MONTHLY) //monthly
                {
                    line.ToolTip = "#VALY{F4}(#VALX{yyyy/MM})";
                    //if (rows.Length == 12) //for one year
                    //    line.IsValueShownAsLabel = true;
                    //else
                    //     line.IsValueShownAsLabel = false;
                }
                else if (interval == ArcSWAT.SWATResultIntervalType.DAILY) //daily
                {
                    line.ToolTip = "#VALY{F4}(#VALX{yyyy-MM-dd})";
                    //line.IsValueShownAsLabel = false;
                }
                else //yearly
                {
                    line.ToolTip = "#VALY{F4}(#VALX{yyyy})";
                }
                if (yColNames.Count > 1)
                {
                    line.ToolTip = yColName + ":" + line.ToolTip;
                }

                if (index == 0)
                {
                    line.Color = System.Drawing.Color.Red;
                }
                else if (yColName.ToLower().Contains("observed")) //the observed data is always green
                {
                    line.Color = System.Drawing.Color.Green;
                }
                else
                {
                    line.Color = System.Drawing.Color.Blue;
                }

                index++;
            }
            setChartArea(dt, interval);

            _dt        = dt;
            _xColName  = xColName;
            _yColNames = yColNames;

            this.DataBind();
        }
示例#7
0
        private UserControl getView(ArcSWAT.Scenario scenario, ArcSWAT.SWATModelType modelType, ArcSWAT.SWATResultIntervalType interval, ArcSWAT.SWATUnitType unitType)
        {
            string key = getViewName(scenario, modelType, interval, unitType);

            if (!_views.ContainsKey(key))
            {
                if (unitType == ArcSWAT.SWATUnitType.WSHD)
                {
                    WatershedView view = new WatershedView();
                    view.Dock = DockStyle.Fill;
                    view.setProjectScenario(_prj, scenario.getModelResult(modelType, interval));
                    view.onDataStatisticsChanged += (ss, ee) => { onDataStatisticsChanged(view); };

                    _views.Add(key, view);
                }
                else
                {
                    SubbasinView view = new SubbasinView();
                    view.Dock = DockStyle.Fill;

                    view.onMapTimeChanged        += (ss, ee) => { onMapTimeChanged(view); };
                    view.onMapSelectionChanged   += (ss, ee) => { onMapSelectionChanged(view); };
                    view.onDataStatisticsChanged += (ss, ee) => { onDataStatisticsChanged(view); };

                    view.setProjectScenario(_prj, scenario.getModelResult(modelType, interval), unitType);

                    if (unitType == ArcSWAT.SWATUnitType.SUB)
                    {
                        view.onSwitch2HRU += (hru) =>
                        {
                            SubbasinView hruview = switchView(_scenario, _modelType, interval, ArcSWAT.SWATUnitType.HRU) as SubbasinView;
                            hruview.HRU = hru;
                        }
                    }
                    ;
                    _views.Add(key, view);
                }
            }
            return(_views[key]);
        }
示例#8
0
 private string getViewName(ArcSWAT.Scenario scenario, ArcSWAT.SWATModelType modelType, ArcSWAT.SWATResultIntervalType interval, ArcSWAT.SWATUnitType unitType)
 {
     return(string.Format("{0}_{1}_{2}_{3}",
                          scenario.Name, modelType, interval, unitType));
 }
示例#9
0
        private void removeView(ArcSWAT.Scenario scenario, ArcSWAT.SWATModelType modelType, ArcSWAT.SWATResultIntervalType interval, ArcSWAT.SWATUnitType unitType)
        {
            string key = getViewName(scenario, modelType, interval, unitType);

            if (_views.ContainsKey(key))
            {
                _views.Remove(key);
            }
        }
示例#10
0
        private void removeView(ArcSWAT.Scenario scenario, ArcSWAT.SWATModelType modelType, ArcSWAT.SWATResultIntervalType interval)
        {
            removeView(scenario, modelType, interval, ArcSWAT.SWATUnitType.WSHD);
            removeView(scenario, modelType, interval, ArcSWAT.SWATUnitType.HRU);
            removeView(scenario, modelType, interval, ArcSWAT.SWATUnitType.SUB);
            removeView(scenario, modelType, interval, ArcSWAT.SWATUnitType.RCH);
            removeView(scenario, modelType, interval, ArcSWAT.SWATUnitType.RES);

            _performanceViews.Clear();
        }
示例#11
0
        private PerformanceView getPerformanceView(ArcSWAT.Scenario scenario, ArcSWAT.SWATModelType modelType, ArcSWAT.SWATResultIntervalType interval)
        {
            string key = string.Format("{0}_{1}_{2}", scenario.Name, modelType, interval);

            if (!_performanceViews.ContainsKey(key))
            {
                PerformanceView performanceView = new PerformanceView();
                performanceView.Result = scenario.getModelResult(modelType, interval);
                performanceView.Dock   = DockStyle.Fill;
                _performanceViews.Add(key, performanceView);
            }
            return(_performanceViews[key]);
        }
示例#12
0
        private UserControl switchView(ArcSWAT.Scenario scenario, ArcSWAT.SWATModelType modelType, ArcSWAT.SWATResultIntervalType interval, ArcSWAT.SWATUnitType unitType)
        {
            UserControl view = getView(scenario, modelType, interval, unitType);

            splitContainer1.Panel2.Controls.Clear();
            splitContainer1.Panel2.Controls.Add(view);

            if (view is SubbasinView)
            {
                Map = (view as SubbasinView).Map;
            }
            else
            {
                Map = null;
            }

            _scenario  = scenario;
            _modelType = modelType;
            _unitType  = unitType;

            //change status
            updateStatus(view);

            return(view);
        }