public SpeciesRichnessProcessor(DistributionModel model, IEnumerable <SpeciesRichnessPointSetViewModel> pointSets, IEnumerable <string> layerFiles, double cutOff, bool retainLayers)
 {
     this.Model        = model;
     this.MapPointSets = pointSets;
     this.LayerFiles   = layerFiles;
     this.CutOff       = cutOff;
     this.RetainLayers = retainLayers;
 }
        private void StartSingleModel()
        {
            var points = pointSets.PointSets;

            if (points == null || points.Count() == 0)
            {
                ErrorMessage.Show("There are no training points to model from!");
                return;
            }

            int totalPoints = 0;

            points.ForEach((set) => {
                totalPoints += set.Count();
            });

            if (totalPoints == 0)
            {
                ErrorMessage.Show("There are no training points to model from!");
                return;
            }

            if (_layerFilenames.Count == 0)
            {
                ErrorMessage.Show("There are no environmental grid layers specified!");
                return;
            }

            _currentModel = _singleModelOptions.cmbModelType.SelectedItem as DistributionModel;
            if (_currentModel != null)
            {
                _currentModel.ProgressObserver = this;

                btnStart.IsEnabled = false;
                btnStop.IsEnabled  = true;

                JobExecutor.QueueJob(() => {
                    try {
                        var layers = _layerFilenames.Select((mm) => {
                            ProgressMessage(string.Format("Loading grid layer {0}", mm.Name));
                            return(new GridLayer(mm.Name));
                        }).ToList();

                        ProgressMessage("Running model...");

                        var result = _currentModel.RunModel(layers, points);

                        if (_currentModel.IsCancelled)
                        {
                            MessageBox.Show("Model cancelled", "Model cancelled", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }

                        this.InvokeIfRequired(() => {
                            ProgressMessage("Saving file...");
                            result.SaveToGRDFile(_singleModelOptions.txtFilename.Text);

                            if (_singleModelOptions.chkGenerateImage.IsChecked == true)
                            {
                                ProgressMessage("Preparing map...");
                                string imageFilename = SystemUtils.ChangeExtension(_singleModelOptions.txtFilename.Text, "bmp");
                                TempFileManager.Attach(imageFilename);
                                double cutoff = _singleModelOptions.CutOff;
                                int intervals = _singleModelOptions.Intervals;
                                ShowGridLayerInMap(result, intervals, cutoff, _singleModelOptions, imageFilename);
                            }
                        });
                        ProgressMessage("Model complete.");
                    } catch (Exception ex) {
                        MessageBox.Show(ex.ToString());
                    } finally {
                        this.InvokeIfRequired(() => {
                            btnStart.IsEnabled = true;
                            btnStop.IsEnabled  = false;
                        });
                        _currentModel = null;
                    }
                });
            }
        }