Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/25/14 14:59:50 (10 years ago)
Author:
jkarder
Message:

#2195:

  • redesigned start page
  • added scripting samples
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimizer/3.3/StartPage.cs

    r10488 r11048  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.IO;
    2425using System.Linq;
     
    3435  [View("Start Page")]
    3536  public partial class StartPage : HeuristicLab.MainForm.WindowsForms.View {
     37    private const string StandardProblemsGroupName = "Standard Problems";
     38    private const string DataAnalysisGroupName = "Data Analysis";
     39    private const string ScriptsGroupName = "Scripts";
     40    private const string UncategorizedGroupName = "Uncategorized";
     41    private const string SampleNamePrefix = "HeuristicLab.Optimizer.Documents.";
     42    private const string SampleNameSuffix = ".hl";
     43
     44    private readonly Dictionary<ListViewGroup, List<string>> GroupLookup = new Dictionary<ListViewGroup, List<string>>();
     45    private readonly ListViewGroup StandardProblemsGroup = new ListViewGroup(StandardProblemsGroupName);
     46    private readonly ListViewGroup DataAnalysisGroup = new ListViewGroup(DataAnalysisGroupName);
     47    private readonly ListViewGroup ScriptsGroup = new ListViewGroup(ScriptsGroupName);
     48    private readonly ListViewGroup UncategorizedGroup = new ListViewGroup(UncategorizedGroupName);
     49
    3650    private IProgress progress;
    3751
     
    5569
    5670      samplesListView.Enabled = false;
     71      samplesListView.Groups.Add(StandardProblemsGroup);
     72      samplesListView.Groups.Add(DataAnalysisGroup);
     73      samplesListView.Groups.Add(ScriptsGroup);
     74      samplesListView.Groups.Add(UncategorizedGroup);
     75      FillGroupLookup();
     76
    5777      showStartPageCheckBox.Checked = Properties.Settings.Default.ShowStartPage;
    5878
     
    7191      progress = MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(samplesListView, "Loading...");
    7292      try {
    73         Assembly assembly = Assembly.GetExecutingAssembly();
    74         var samples = assembly.GetManifestResourceNames().Where(x => x.EndsWith(".hl"));
     93        var assembly = Assembly.GetExecutingAssembly();
     94        var samples = assembly.GetManifestResourceNames().Where(x => x.EndsWith(SampleNameSuffix));
    7595        int count = samples.Count();
    7696        string path = Path.GetTempFileName();
    7797
    78         foreach (string name in samples) {
    79           try {
    80             using (Stream stream = assembly.GetManifestResourceStream(name)) {
    81               WriteStreamToTempFile(stream, path);
    82               INamedItem item = XmlParser.Deserialize<INamedItem>(path);
    83               OnSampleLoaded(item, 1.0 / count);
    84             }
     98        foreach (var entry in GroupLookup) {
     99          var group = entry.Key;
     100          var sampleList = entry.Value;
     101          foreach (var sampleName in sampleList) {
     102            string resourceName = SampleNamePrefix + sampleName + SampleNameSuffix;
     103            LoadSample(resourceName, assembly, path, group, count);
    85104          }
    86           catch (Exception) {
    87           }
    88         }
     105        }
     106
     107        var categorizedSamples = GroupLookup.Select(x => x.Value).SelectMany(x => x).Select(x => SampleNamePrefix + x + SampleNameSuffix);
     108        var uncategorizedSamples = samples.Except(categorizedSamples);
     109
     110        foreach (var resourceName in uncategorizedSamples) {
     111          LoadSample(resourceName, assembly, path, UncategorizedGroup, count);
     112        }
     113
    89114        OnAllSamplesLoaded();
    90115      }
     
    93118      }
    94119    }
    95     private void OnSampleLoaded(INamedItem sample, double progress) {
     120
     121    private void LoadSample(string name, Assembly assembly, string path, ListViewGroup group, int count) {
     122      try {
     123        using (var stream = assembly.GetManifestResourceStream(name)) {
     124          WriteStreamToTempFile(stream, path);
     125          var item = XmlParser.Deserialize<INamedItem>(path);
     126          OnSampleLoaded(item, group, 1.0 / count);
     127        }
     128      }
     129      catch (Exception) { }
     130    }
     131
     132    private void FillGroupLookup() {
     133      var standardProblems = new List<string>(
     134        new[] { "ES_Griewank", "GA_TSP", "GA_VRP", "GE_ArtificialAnt",
     135                "IslandGA_TSP", "LS_Knapsack", "PSO_Schwefel", "RAPGA_JSSP",
     136                "SA_Rastrigin", "SGP_SantaFe", "SS_VRP", "TS_TSP", "TS_VRP", "VNS_TSP"
     137        });
     138      GroupLookup[StandardProblemsGroup] = standardProblems;
     139      var dataAnalysisProblems = new List<string>(new[] { "GE_SymbReg", "GPR", "SGP_SymbClass", "SGP_SymbReg" });
     140      GroupLookup[DataAnalysisGroup] = dataAnalysisProblems;
     141      var scripts = new List<string>(new[] { "GA_QAP_Script", "GUI_Automation_Script", "OSGA_Rastrigin_Script" });
     142      GroupLookup[ScriptsGroup] = scripts;
     143    }
     144
     145    private void OnSampleLoaded(INamedItem sample, ListViewGroup group, double progress) {
    96146      if (InvokeRequired)
    97         Invoke(new Action<INamedItem, double>(OnSampleLoaded), sample, progress);
     147        Invoke(new Action<INamedItem, ListViewGroup, double>(OnSampleLoaded), sample, group, progress);
    98148      else {
    99         ListViewItem item = new ListViewItem(new string[] { sample.Name, sample.Description });
     149        ListViewItem item = new ListViewItem(new string[] { sample.Name, sample.Description }, group);
    100150        item.ToolTipText = sample.ItemName + ": " + sample.ItemDescription;
    101151        samplesListView.SmallImageList.Images.Add(sample.ItemImage);
Note: See TracChangeset for help on using the changeset viewer.