Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3044_variableScaling/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/ShrinkDataAnalysisRunsMenuItem.cs @ 18242

Last change on this file since 18242 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 3.0 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
24using System;
25using System.Collections.Generic;
26using System.Linq;
27using HeuristicLab.MainForm;
28using HeuristicLab.Optimization;
29using HeuristicLab.Optimizer;
30
31using MenuItem = HeuristicLab.MainForm.WindowsForms.MenuItem;
32
33namespace 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 {
39      get { return new string[] { "&Edit", "&Data Analysis" }; }
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;
74      var content = activeView.Content;
75      Progress.Show(content, "Removing duplicate datasets.", ProgressMode.Indeterminate);
76
77      Action<IContentView> action = (view) => DatasetUtil.RemoveDuplicateDatasets(view.Content);
78
79      action.BeginInvoke(activeView, delegate (IAsyncResult result) {
80        action.EndInvoke(result);
81        Progress.Hide(content);
82      }, null);
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.