Пример #1
0
        public string getResultStatus(SWATModelType modelType)
        {
            StringBuilder status = new StringBuilder();

            for (int j = Convert.ToInt32(SWATResultIntervalType.MONTHLY); j <= Convert.ToInt32(SWATResultIntervalType.YEARLY); j++)
            {
                SWATResultIntervalType interval = (SWATResultIntervalType)j;
                ScenarioResult         result   = getModelResult(modelType, interval);
                if (result == null)
                {
                    continue;
                }

                if (status.Length > 0)
                {
                    status.Append(";");
                }
                status.Append(interval);
                status.Append(":");
                if (result.Status != ScenarioResultStatus.NORMAL)
                {
                    status.Append(result.Status);
                }
                else
                {
                    status.Append(string.Format("{0:yyyy-MM-dd hh:mm:ss}", result.SimulationTime));
                }
            }
            return(status.ToString());
        }
Пример #2
0
        private ArcSWAT.SWATUnitColumnYearResult getResult(ArcSWAT.ScenarioResult result)
        {
            if (_unitType == ArcSWAT.SWATUnitType.UNKNOWN)
            {
                return(null);
            }

            //get the unit
            ArcSWAT.SWATUnit unit = result.getSWATUnit(_unitType, _id);
            if (unit == null)
            {
                return(null);
            }

            //get unit results
            foreach (ArcSWAT.SWATUnitResult unitResult in unit.Results.Values)
            {
                ArcSWAT.SWATUnitColumnYearResult r = unitResult.getResult(_col, -1);
                if (r != null)
                {
                    return(r);
                }
            }
            return(null);
        }
        public ScenarioComparasionReportView()
        {
            InitializeComponent();

            cmbHRU.CheckedChanged += (s, e) => { updateUnitType(); };
            cmbReach.CheckedChanged += (s, e) => { updateUnitType(); };
            cmbSubbasin.CheckedChanged += (s, e) => { updateUnitType(); };

            resultColumnTree1.onResultTypeAndColumnChanged += (resultType, col) => { _resultType = resultType; _col = col; this.backgroundWorker1.RunWorkerAsync(); };
            cmbCompareResults.SelectedIndexChanged += (s, e) => { _compareResult = CompareResult; this.backgroundWorker1.RunWorkerAsync(); };

            backgroundWorker1.DoWork += (s, e) => { updateTableAndChart(); };
            backgroundWorker1.ProgressChanged += (s, e) => { richTextBox1.AppendText(e.UserState.ToString() + "\n"); richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.ScrollToCaret(); };
            backgroundWorker1.RunWorkerCompleted += (s, e) =>
            {
                tableView1.DataTable = _differentTable;
                chart1.DataSource = _differentTable;
                chart1.Invalidate();

                if (_differentTable == null) return;
                richTextBox1.AppendText("Finished.\n");
            };

            //default select reach
            cmbReach.Checked = true;
        }
Пример #4
0
        public Reservoir(DataRow resInfoRow, ScenarioResult scenario)
            : base(resInfoRow, scenario)
        {
            RowItem item = new RowItem(resInfoRow);

            _id = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_RES);
        }
Пример #5
0
        public Subbasin(DataRow subInfoRow, ScenarioResult scenario)
            : base(subInfoRow, scenario)
        {
            RowItem item = new RowItem(subInfoRow);

            _id           = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_SUB);
            _area         = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_KM2);
            _area_fr_wshd = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_FR_WSHD);
        }
Пример #6
0
        public Reach(DataRow rchInfoRow, ScenarioResult scenario)
            : base(rchInfoRow, scenario)
        {
            RowItem item = new RowItem(rchInfoRow);
            _id = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_RCH);
            _area = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_KM2);

            if (scenario.Subbasins.ContainsKey(_id))
                _sub = scenario.Subbasins[_id] as Subbasin;
        }
Пример #7
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();
            }
        }
Пример #8
0
        /// <summary>
        /// Re-read results when it's simulated again.
        /// </summary>
        /// <param name="modelType"></param>
        public void reReadResults(SWATModelType modelType, SWATResultIntervalType interval)
        {
            ScenarioResult result = getModelResult(modelType, interval);

            if (result != null)
            {
                _results[getResultID(modelType, interval)] =
                    new ScenarioResult(
                        _modelfolder + @"\" + ScenarioResultStructure.getDatabaseName(modelType, interval), this, modelType, interval);
            }
        }
Пример #9
0
        public ProjectTree()
        {
            NodeMouseClick += (s, e) =>
            {
                if(onResultLevelChanged == null) return;
                _scenarioResult = null;

                if (e.Node == null) return;

                ArcSWAT.SWATUnitType type = ArcSWAT.SWATUnitType.UNKNOWN;
                if (e.Node.Text.Equals("Watershed"))
                    type = ArcSWAT.SWATUnitType.WSHD;
                else if (e.Node.Text.Equals("HRU"))
                    type = ArcSWAT.SWATUnitType.HRU;
                else if (e.Node.Text.Equals("Subbasin"))
                    type = ArcSWAT.SWATUnitType.SUB;
                else if (e.Node.Text.Equals("Reach"))
                    type = ArcSWAT.SWATUnitType.RCH;
                else if (e.Node.Text.Equals("Reservoir"))
                    type = ArcSWAT.SWATUnitType.RES;

                if (type != ArcSWAT.SWATUnitType.UNKNOWN)
                    onResultLevelChanged(e.Node.Tag as ArcSWAT.ScenarioResult, (ArcSWAT.SWATModelType)e.Node.Parent.Tag, type);

                //click on scenario node
                if (e.Node.Tag != null && e.Node.Tag is ArcSWAT.Scenario && onScenarioSelectionChanged != null)
                    onScenarioSelectionChanged(e.Node.Tag as ArcSWAT.Scenario);

                //click on model node
                if (e.Node.Tag != null && e.Node.Tag is ArcSWAT.SWATModelType && e.Node.Nodes.Count > 0 && e.Node.Nodes[0].Tag != null && e.Node.Nodes[0].Tag is ArcSWAT.ScenarioResult)
                    onResultLevelChanged(e.Node.Nodes[0].Tag as ArcSWAT.ScenarioResult, (ArcSWAT.SWATModelType)e.Node.Tag, ArcSWAT.SWATUnitType.WSHD);

                //click on project node
                if (e.Node.Tag != null && e.Node.Tag is ArcSWAT.Project && onProjectNodeSelected != null)
                    onProjectNodeSelected(this, new EventArgs());

                //click on difference node
                if (e.Node.Text.Equals("Difference") && e.Node.Tag != null && e.Node.Tag is ArcSWAT.ScenarioResult && onDifferenceNodeSelected != null)
                {
                    _scenarioResult = e.Node.Tag as ArcSWAT.ScenarioResult;
                    onDifferenceNodeSelected(this, new EventArgs());
                }

                //click on difference node
                if (e.Node.Text.Equals("Performance") && e.Node.Tag != null && e.Node.Tag is ArcSWAT.ScenarioResult && onPerformanceNodeSelected != null)
                {
                    _scenarioResult = e.Node.Tag as ArcSWAT.ScenarioResult;
                    onPerformanceNodeSelected(this, new EventArgs());
                }
            };
        }
Пример #10
0
        public Reach(DataRow rchInfoRow, ScenarioResult scenario)
            : base(rchInfoRow, scenario)

        {
            RowItem item = new RowItem(rchInfoRow);

            _id   = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_RCH);
            _area = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_KM2);

            if (scenario.Subbasins.ContainsKey(_id))
            {
                _sub = scenario.Subbasins[_id] as Subbasin;
            }
        }
Пример #11
0
        public HRU(DataRow hruInfoRow, ScenarioResult scenario)
            : base(hruInfoRow,scenario)
        {
            RowItem item = new RowItem(hruInfoRow);
            _id = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_HRU);
            _seqIdInSubbasin = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_HRU_SEQ);
            _area = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_KM2);
            _area_fr_sub = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_FR_SUB);
            _area_fr_wshd = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_FR_WSHD);

            //connect hru and subbasin
            int subid = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_SUB);
            if (scenario.Subbasins.ContainsKey(subid))
            {
                _sub = scenario.Subbasins[subid] as Subbasin;
                if (_sub != null) _sub.addHRU(this);
            }
        }
Пример #12
0
        /// <summary>
        /// get compare table for given scenario and model type
        /// </summary>
        /// <param name="scenario"></param>
        /// <param name="modelType"></param>
        /// <returns></returns>
        private SWATUnitColumnYearResult getCompareResult(Scenario scenario, SWATModelType modelType)
        {
            //get scenario result
            ScenarioResult compareResult = scenario.getModelResult(modelType, _result.Interval);

            if (compareResult == null)
            {
                throw new Exception("Can't find model " + modelType.ToString() + " in scenario " + scenario.Name);
            }
            if (compareResult.Status == ScenarioResultStatus.UNKNOWN)
            {
                throw new Exception("The status of model " + modelType.ToString() + " in scenario " + scenario.Name + " is unknown.");
            }
            if (compareResult.Status == ScenarioResultStatus.UNSUCCESS)
            {
                throw new Exception("The simulation of " + modelType.ToString() + " in scenario " + scenario.Name + " is not successful. Please check the model first.");
            }
            if (compareResult.Status == ScenarioResultStatus.NO_EXIST)
            {
                throw new Exception("The simulation result of " + modelType.ToString() + " in scenario " + scenario.Name + " doesn't exist. Please run the model first.");
            }


            //get unit
            SWATUnit unit = compareResult.getSWATUnit(_result.Unit.Type, _result.Unit.ID);

            if (unit == null)
            {
                throw new Exception("Can't find " + _result.Unit.Type + " " + _result.Unit.ID.ToString() + " in scenario " + scenario.Name + ",model " + modelType.ToString());
            }

            SWATUnitResult unitResult = unit.getResult(_result.Name);

            if (unitResult == null)
            {
                throw new Exception("Can't find result  " + _result.Name + " for " + _result.Unit.Type + " " + _result.Unit.ID.ToString() + " in scenario " + scenario.Name + ",model " + modelType.ToString());
            }
            if (unitResult.Interval != _result.Interval)
            {
                throw new Exception("The interval for " + _result.Name + " for " + _result.Unit.Type + " " + _result.Unit.ID.ToString() + " in scenario " + scenario.Name + ",model " + modelType.ToString() + " is different from current result.");
            }

            return(unitResult.getResult(_col, _year));
        }
Пример #13
0
        /// <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;
        }
Пример #14
0
        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;
        }
Пример #15
0
        public HRU(DataRow hruInfoRow, ScenarioResult scenario) : base(hruInfoRow, scenario)
        {
            RowItem item = new RowItem(hruInfoRow);

            _id = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_HRU);
            _seqIdInSubbasin = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_HRU_SEQ);
            _area            = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_KM2);
            _area_fr_sub     = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_FR_SUB);
            _area_fr_wshd    = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_FR_WSHD);

            //connect hru and subbasin
            int subid = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_SUB);

            if (scenario.Subbasins.ContainsKey(subid))
            {
                _sub = scenario.Subbasins[subid] as Subbasin;
                if (_sub != null)
                {
                    _sub.addHRU(this);
                }
            }
        }
Пример #16
0
        public void setScenarioAndUnit(ArcSWAT.ScenarioResult scenario, ArcSWAT.SWATUnitType type)
        {
            this.Nodes.Clear();

            if (scenario == null)
            {
                return;
            }
            if (type == ArcSWAT.SWATUnitType.UNKNOWN)
            {
                return;
            }

            StringCollection tbls = scenario.Structure.getResultTablesWithData(type);

            if (tbls.Count == 0)
            {
                return;
            }

            foreach (string tbl in tbls)
            {
                TreeNode tblNode = Nodes.Add(tbl);

                StringCollection cols = scenario.Structure.getDataColumns(tbl);
                foreach (string col in cols)
                {
                    tblNode.Nodes.Add(col);
                }

                tblNode.ExpandAll();
            }
            //if (Nodes.Count > 0 && Nodes[0].Nodes.Count > 0)
            //    OnNodeMouseClick(new TreeNodeMouseClickEventArgs(
            //        Nodes[0].Nodes[0], System.Windows.Forms.MouseButtons.Left, -1, -1, -1));
        }
Пример #17
0
        public Scenario(string f, Project prj)
            : base(f)
        {
            if (IsValid)
            {
                _prj         = prj;
                _modelfolder = Folder + DEFAULT_TXTINOUT_NAME;
                if (!Directory.Exists(_modelfolder))
                {
                    _modelfolder = null;
                    _isValid     = false;
                    _error       = _modelfolder + " doesn't exist!";
                    return;
                }
                _name = (new DirectoryInfo(Folder)).Name;

                //Regular SWAT and CanSWAT could run one a same model
                _hasResults = false;
                for (int i = Convert.ToInt32(ArcSWAT.SWATModelType.SWAT_488); i <= Convert.ToInt32(ArcSWAT.SWATModelType.CanSWAT); i++)
                {
                    SWATModelType modelType = (SWATModelType)i;
                    for (int j = Convert.ToInt32(SWATResultIntervalType.MONTHLY); j <= Convert.ToInt32(SWATResultIntervalType.YEARLY); j++)
                    {
                        SWATResultIntervalType interval = (SWATResultIntervalType)j;
                        ScenarioResult         result   = new ScenarioResult(
                            _modelfolder + @"\" + ScenarioResultStructure.getDatabaseName(modelType, interval),
                            this, modelType, interval);
                        if (result.Status == ScenarioResultStatus.NORMAL)
                        {
                            _hasResults = true;
                        }
                        _results.Add(getResultID(modelType, interval), result);
                    }
                }
            }
        }
Пример #18
0
 public Watershed(ScenarioResult scenario)
     : base(null, scenario)
 {
 }
 public SWATUnitColumnYearCompareResult Compare(ScenarioResult result)
 {
     return Compare(result.Scenario, result.ModelType);
 }
Пример #20
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);

            //close the connection with the databse
            //or the file can't be deleted
            //error severe (46): Inconsistent OPEN/CLOSE parameters will be given
            ArcSWAT.ScenarioResult r = _scenario.getModelResult(modelType, interval);
            if (r != null)
            {
                r.close();
            }

            //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.BeginErrorReadLine();
                //myProcess.WaitForExit();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Пример #21
0
 public SWATUnit(DataRow unitInfoRow, ScenarioResult scenario)
 {
     _scenario = scenario;
 }
Пример #22
0
 public SWATUnit(DataRow unitInfoRow, ScenarioResult scenario)
 {
     _scenario = scenario;
 }
Пример #23
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());
            }
        }
Пример #24
0
 public SWATUnitColumnYearCompareResult Compare(ScenarioResult result)
 {
     return(Compare(result.Scenario, result.ModelType));
 }
Пример #25
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();
        }
Пример #26
0
 public Watershed(ScenarioResult scenario)
     : base(null, scenario)
 {
 }
Пример #27
0
 public ScenarioResultStructure(ScenarioResult scenario)
 {
     _scenario = scenario;
 }