[9859] | 1 | #region License Information
|
---|
| 2 |
|
---|
| 3 | /* HeuristicLab
|
---|
[15583] | 4 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[9859] | 5 | *
|
---|
| 6 | * This file is part of HeuristicLab.
|
---|
| 7 | *
|
---|
| 8 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 9 | * it under the terms of the GNU General Public License as published by
|
---|
| 10 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 11 | * (at your option) any later version.
|
---|
| 12 | *
|
---|
| 13 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | * GNU General Public License for more details.
|
---|
| 17 | *
|
---|
| 18 | * You should have received a copy of the GNU General Public License
|
---|
| 19 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #endregion
|
---|
| 23 |
|
---|
| 24 | using System;
|
---|
| 25 | using System.Collections.Generic;
|
---|
| 26 | using System.Linq;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Optimizer;
|
---|
| 30 |
|
---|
| 31 | using MenuItem = HeuristicLab.MainForm.WindowsForms.MenuItem;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
| 34 | internal sealed class ShrinkDataAnalysisRunsMenuItem : MenuItem, IOptimizerUserInterfaceItemProvider {
|
---|
| 35 | public override string Name {
|
---|
| 36 | get { return "Remove Duplicate Datasets"; }
|
---|
| 37 | }
|
---|
| 38 | public override IEnumerable<string> Structure {
|
---|
[9973] | 39 | get { return new string[] { "&Edit", "&Data Analysis" }; }
|
---|
[9859] | 40 | }
|
---|
| 41 | public override int Position {
|
---|
| 42 | get { return 5300; }
|
---|
| 43 | }
|
---|
| 44 | public override string ToolTipText {
|
---|
| 45 | get { return "This command shrinks the memory usage of data analysis optimizers by checking and unifying duplicate datasets."; }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | protected override void OnToolStripItemSet(EventArgs e) {
|
---|
| 49 | ToolStripItem.Enabled = false;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | protected override void OnActiveViewChanged(object sender, EventArgs e) {
|
---|
| 53 | IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
|
---|
| 54 | if (activeView == null) {
|
---|
| 55 | ToolStripItem.Enabled = false;
|
---|
| 56 | return;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | var content = activeView.Content;
|
---|
| 60 | RunCollection runCollection = content as RunCollection;
|
---|
| 61 | if (runCollection == null && content is IOptimizer)
|
---|
| 62 | runCollection = ((IOptimizer)content).Runs;
|
---|
| 63 |
|
---|
| 64 | if (runCollection == null) {
|
---|
| 65 | ToolStripItem.Enabled = false;
|
---|
| 66 | return;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | ToolStripItem.Enabled = runCollection.Any(run => run.Parameters.Any(p => p.Value is IDataAnalysisProblemData));
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | public override void Execute() {
|
---|
| 73 | IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
|
---|
[16430] | 74 | var content = activeView.Content;
|
---|
| 75 | Progress.Show(content, "Removing duplicate datasets.", ProgressMode.Indeterminate);
|
---|
[9859] | 76 |
|
---|
[15427] | 77 | Action<IContentView> action = (view) => DatasetUtil.RemoveDuplicateDatasets(view.Content);
|
---|
[9859] | 78 |
|
---|
[15427] | 79 | action.BeginInvoke(activeView, delegate (IAsyncResult result) {
|
---|
[9859] | 80 | action.EndInvoke(result);
|
---|
[16430] | 81 | Progress.Hide(content);
|
---|
[9859] | 82 | }, null);
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | }
|
---|