Exemple #1
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);
        }
Exemple #2
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);
            }
        }
Exemple #3
0
 public void update(ArcSWAT.Scenario scenario, ArcSWAT.SWATModelType modelType)
 {
     foreach (TreeNode node in this.Nodes[0].Nodes)
     {
         if (node.Text.Equals(scenario.Name))
         {
             AddScenarioResult(node, scenario, modelType);
         }
     }
 }
Exemple #4
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();
        }
Exemple #5
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();
            }
        }
Exemple #6
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]);
        }
Exemple #7
0
        private void addNodes(TreeNode projectNode, ArcSWAT.Scenario s)
        {
            TreeNode scenNode = projectNode.Nodes.Add(s.Name);

            scenNode.Tag = s;

            if (s.hasResults)
            {
                for (int i = Convert.ToInt32(ArcSWAT.SWATModelType.SWAT_488); i <= Convert.ToInt32(ArcSWAT.SWATModelType.CanSWAT); i++)
                {
                    ArcSWAT.SWATModelType modelType = (ArcSWAT.SWATModelType)i;
                    AddScenarioResult(scenNode, s, modelType);
                }
            }
        }
Exemple #8
0
        private void ScenarioView_Load(object sender, EventArgs e)
        {
            cmbModelType.SelectedIndexChanged += (ss, ee) => { _modelType = ModelType; updateSimulationTime(); };

            //add models based on executables
            cmbModelType.Items.Clear();
            for (int i = Convert.ToInt32(ArcSWAT.SWATModelType.SWAT_488); i <= Convert.ToInt32(ArcSWAT.SWATModelType.CanSWAT); i++)
            {
                ArcSWAT.SWATModelType modelType = (ArcSWAT.SWATModelType)i;

                string swatexe = SWAT_SQLite.InstallationFolder + @"swat_exes\" + ArcSWAT.ScenarioResultStructure.getSWATExecutableName(modelType);
                if (System.IO.File.Exists(swatexe))
                {
                    cmbModelType.Items.Add(modelType);
                }
            }
            cmbModelType.SelectedIndex = 0;

            backgroundWorker1.DoWork          += (ss, ee) => { copyModel(ee.Argument.ToString()); };
            backgroundWorker1.ProgressChanged += (ss, ee) => { updateMessage(ee.UserState.ToString()); };
        }
Exemple #9
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]);
        }
Exemple #10
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);
            }
        }
Exemple #11
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));
 }