private async void AddParticles_Click(object sender, RoutedEventArgs e) { MainWindow Window = (MainWindow)Application.Current.MainWindow; Species S = Species; CustomDialog NewDialog = new CustomDialog(); NewDialog.HorizontalContentAlignment = HorizontalAlignment.Center; DialogSpeciesParticleSets NewDialogContent = new DialogSpeciesParticleSets(Window.ActivePopulation, S); NewDialogContent.Close += async() => await Window.HideMetroDialogAsync(NewDialog); NewDialogContent.Add += async() => { await Window.HideMetroDialogAsync(NewDialog); var NewSpeciesProgress = await Window.ShowProgressAsync("Please wait while particle statistics are updated...", ""); NewSpeciesProgress.SetIndeterminate(); await Task.Run(() => { S.AddParticles(NewDialogContent.ParticlesFinal); S.CalculateParticleStats(); S.Commit(); S.Save(); }); await NewSpeciesProgress.CloseAsync(); }; NewDialog.Content = NewDialogContent; await Window.ShowMetroDialogAsync(NewDialog); }
private async void ButtonPopulationAddSpecies_OnClick(object sender, RoutedEventArgs e) { if (ActivePopulation == null) { return; } CustomDialog AddDialog = new CustomDialog(); AddDialog.HorizontalContentAlignment = HorizontalAlignment.Center; DialogAddSpecies AddDialogContent = new DialogAddSpecies(); AddDialogContent.Close += async() => await this.HideMetroDialogAsync(AddDialog); AddDialogContent.Add += async() => { await this.HideMetroDialogAsync(AddDialog); if ((bool)AddDialogContent.RadioLocal.IsChecked) { await this.ShowMessageAsync("Oopsie", "This feature is not implemented yet."); } else if ((bool)AddDialogContent.RadioRemote.IsChecked) { await this.ShowMessageAsync("Oopsie", "This feature is not implemented yet."); } else if ((bool)AddDialogContent.RadioScratch.IsChecked) { CustomDialog NewDialog = new CustomDialog(); NewDialog.HorizontalContentAlignment = HorizontalAlignment.Center; DialogCreateNewSpecies NewDialogContent = new DialogCreateNewSpecies(ActivePopulation); NewDialogContent.Close += async() => await this.HideMetroDialogAsync(NewDialog); NewDialogContent.Finish += async() => { await this.HideMetroDialogAsync(NewDialog); string DefaultProgressMessage = "Please wait while various metrics are calculated for the new map. This will take at least a few minutes.\n"; var NewSpeciesProgress = await this.ShowProgressAsync("Creating new species...", DefaultProgressMessage); NewSpeciesProgress.SetIndeterminate(); Species NewSpecies = new Species(NewDialogContent.Halfmap1Final, NewDialogContent.Halfmap2Final, NewDialogContent.MaskFinal) { Name = NewDialogContent.SpeciesName, PixelSize = NewDialogContent.HalfmapPixelSize, Symmetry = NewDialogContent.SpeciesSymmetry, DiameterAngstrom = NewDialogContent.SpeciesDiameter, MolecularWeightkDa = NewDialogContent.SpeciesWeight, TemporalResolutionMovement = NewDialogContent.TemporalResMov, TemporalResolutionRotation = NewDialogContent.TemporalResMov, Particles = NewDialogContent.ParticlesFinal }; await Task.Run(() => { NewSpecies.Path = ActivePopulation.SpeciesDir + NewSpecies.GUID.ToString().Substring(0, 8) + "\\" + NewSpecies.NameSafe + ".species"; Directory.CreateDirectory(NewSpecies.FolderPath); NewSpecies.CalculateResolutionAndFilter(-1, (message) => Dispatcher.Invoke(() => NewSpeciesProgress.SetMessage(DefaultProgressMessage + "\n" + message))); Dispatcher.Invoke(() => NewSpeciesProgress.SetMessage(DefaultProgressMessage + "\n" + "Calculating particle statistics")); NewSpecies.CalculateParticleStats(); Dispatcher.Invoke(() => NewSpeciesProgress.SetMessage(DefaultProgressMessage + "\n" + "Committing results")); NewSpecies.Commit(); NewSpecies.Save(); }); ActivePopulation.Species.Add(NewSpecies); await NewSpeciesProgress.CloseAsync(); }; NewDialog.Content = NewDialogContent; await this.ShowMetroDialogAsync(NewDialog); } }; AddDialog.Content = AddDialogContent; await this.ShowMetroDialogAsync(AddDialog); }