Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.TravelingSalesman.Views/3.3/TravelingSalesmanProblemView.cs @ 5717

Last change on this file since 5717 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 4.7 KB
RevLine 
[2805]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2805]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Windows.Forms;
[3153]24using HeuristicLab.Core;
[2805]25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
[3758]27using HeuristicLab.PluginInfrastructure;
[2805]28
[3158]29namespace HeuristicLab.Problems.TravelingSalesman.Views {
[2805]30  /// <summary>
[4513]31  /// A view for a Traveling Salesman Problem instance.
[2805]32  /// </summary>
[3159]33  [View("Traveling Salesman Problem View")]
34  [Content(typeof(TravelingSalesmanProblem), true)]
35  public sealed partial class TravelingSalesmanProblemView : NamedItemView {
[3151]36    private TSPLIBImportDialog tsplibImportDialog;
37
[3159]38    public new TravelingSalesmanProblem Content {
39      get { return (TravelingSalesmanProblem)base.Content; }
[2805]40      set { base.Content = value; }
41    }
42
43    /// <summary>
[4513]44    /// Initializes a new instance of <see cref="TravelingSalesmanProblemView"/>.
[2805]45    /// </summary>
[3159]46    public TravelingSalesmanProblemView() {
[2805]47      InitializeComponent();
48    }
49
[5237]50    protected override void Dispose(bool disposing) {
51      if (disposing) {
52        if (tsplibImportDialog != null) tsplibImportDialog.Dispose();
53        if (components != null) components.Dispose();
54      }
55      base.Dispose(disposing);
56    }
57
[3153]58    protected override void DeregisterContentEvents() {
59      Content.CoordinatesParameter.ValueChanged -= new EventHandler(CoordinatesParameter_ValueChanged);
[3712]60      Content.BestKnownQualityParameter.ValueChanged -= new EventHandler(BestKnownQualityParameter_ValueChanged);
[3153]61      Content.BestKnownSolutionParameter.ValueChanged -= new EventHandler(BestKnownSolutionParameter_ValueChanged);
62      base.DeregisterContentEvents();
63    }
64    protected override void RegisterContentEvents() {
65      base.RegisterContentEvents();
66      Content.CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
[3712]67      Content.BestKnownQualityParameter.ValueChanged += new EventHandler(BestKnownQualityParameter_ValueChanged);
[3153]68      Content.BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
69    }
70
[2998]71    protected override void OnContentChanged() {
72      base.OnContentChanged();
73      if (Content == null) {
[3153]74        parameterCollectionView.Content = null;
75        pathTSPTourView.Content = null;
[2998]76      } else {
[3153]77        parameterCollectionView.Content = ((IParameterizedNamedItem)Content).Parameters;
[3616]78        pathTSPTourView.Content = new PathTSPTour(Content.Coordinates, Content.BestKnownSolution, Content.BestKnownQuality);
[2998]79      }
80    }
81
[3904]82    protected override void SetEnabledStateOfControls() {
83      base.SetEnabledStateOfControls();
[3454]84      parameterCollectionView.Enabled = Content != null;
85      pathTSPTourView.Enabled = Content != null;
86      importButton.Enabled = Content != null && !ReadOnly;
87    }
88
[2805]89    private void importButton_Click(object sender, System.EventArgs e) {
[3151]90      if (tsplibImportDialog == null) tsplibImportDialog = new TSPLIBImportDialog();
91
92      if (tsplibImportDialog.ShowDialog(this) == DialogResult.OK) {
[2805]93        try {
[3151]94          if (tsplibImportDialog.Quality == null)
95            Content.ImportFromTSPLIB(tsplibImportDialog.TSPFileName, tsplibImportDialog.TourFileName);
96          else
97            Content.ImportFromTSPLIB(tsplibImportDialog.TSPFileName, tsplibImportDialog.TourFileName, (double)tsplibImportDialog.Quality);
[2805]98        }
99        catch (Exception ex) {
[3758]100          ErrorHandling.ShowErrorDialog(this, ex);
[2805]101        }
102      }
103    }
[3153]104
105    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
106      pathTSPTourView.Content.Coordinates = Content.Coordinates;
107    }
[3712]108    private void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {
109      pathTSPTourView.Content.Quality = Content.BestKnownQuality;
110    }
[3153]111    private void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
112      pathTSPTourView.Content.Permutation = Content.BestKnownSolution;
113    }
[2805]114  }
115}
Note: See TracBrowser for help on using the repository browser.