void SpeciesProperties(ScenarioSpecies species) { var vm = new SpeciesPropertiesViewModel(species) { WindowTitle = "Species Properties" }; var result = Globals.VisualizerService.ShowDialog("SpeciesPropertiesView", vm); if ((result.HasValue) && (result.Value)) { if (Math.Abs(vm.PopulationDensity - species.PopulationDensity) > 0.0001 || species.SpeciesDefinitionFilename != vm.SpeciesDefinitionFilename) { species.PopulationDensity = vm.PopulationDensity; species.SpeciesDefinitionFilename = vm.SpeciesDefinitionFilename; RepopulateSpeciesAsync(species); } if (vm.LatinName != species.LatinName) species.LatinName = vm.LatinName; } }
async void AddSpecies(Scenario scenario) { var vm = new SpeciesPropertiesViewModel(new ScenarioSpecies { LatinName = "Generic odontocete", PopulationDensity = 0.01f, SpeciesDefinitionFilename = "Generic odontocete.spe" }) { WindowTitle = "Add new species" }; var result = Globals.VisualizerService.ShowDialog("SpeciesPropertiesView", vm); if ((!result.HasValue) || (!result.Value)) return; var species = new ScenarioSpecies { Scenario = scenario, LatinName = vm.LatinName, PopulationDensity = vm.PopulationDensity, SpeciesDefinitionFilename = vm.SpeciesDefinitionFilename, }; try { scenario.ScenarioSpecies.Add(species); species.LayerSettings.LineOrSymbolSize = 3; var animats = await Animat.SeedAsync(species, scenario.Location.GeoRect, scenario.BathymetryData); animats.Save(species.PopulationFilePath); species.UpdateMapLayers(); } catch (Exception e) { scenario.ScenarioSpecies.Remove(species); Globals.MessageBoxService.ShowError(e.Message); } OnPropertyChanged("IsRunSimulationCommandEnabled"); OnPropertyChanged("IsSaveScenarioCommandEnabled"); }