Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 5060 was 4513, checked in by swinkler, 14 years ago

Corrected comments and descriptions (#1182); formatted code.

File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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;
24using HeuristicLab.Core;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27using HeuristicLab.PluginInfrastructure;
28
29namespace HeuristicLab.Problems.TravelingSalesman.Views {
30  /// <summary>
31  /// A view for a Traveling Salesman Problem instance.
32  /// </summary>
33  [View("Traveling Salesman Problem View")]
34  [Content(typeof(TravelingSalesmanProblem), true)]
35  public sealed partial class TravelingSalesmanProblemView : NamedItemView {
36    private TSPLIBImportDialog tsplibImportDialog;
37
38    public new TravelingSalesmanProblem Content {
39      get { return (TravelingSalesmanProblem)base.Content; }
40      set { base.Content = value; }
41    }
42
43    /// <summary>
44    /// Initializes a new instance of <see cref="TravelingSalesmanProblemView"/>.
45    /// </summary>
46    public TravelingSalesmanProblemView() {
47      InitializeComponent();
48    }
49
50    protected override void DeregisterContentEvents() {
51      Content.CoordinatesParameter.ValueChanged -= new EventHandler(CoordinatesParameter_ValueChanged);
52      Content.BestKnownQualityParameter.ValueChanged -= new EventHandler(BestKnownQualityParameter_ValueChanged);
53      Content.BestKnownSolutionParameter.ValueChanged -= new EventHandler(BestKnownSolutionParameter_ValueChanged);
54      base.DeregisterContentEvents();
55    }
56    protected override void RegisterContentEvents() {
57      base.RegisterContentEvents();
58      Content.CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
59      Content.BestKnownQualityParameter.ValueChanged += new EventHandler(BestKnownQualityParameter_ValueChanged);
60      Content.BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
61    }
62
63    protected override void OnContentChanged() {
64      base.OnContentChanged();
65      if (Content == null) {
66        parameterCollectionView.Content = null;
67        pathTSPTourView.Content = null;
68      } else {
69        parameterCollectionView.Content = ((IParameterizedNamedItem)Content).Parameters;
70        pathTSPTourView.Content = new PathTSPTour(Content.Coordinates, Content.BestKnownSolution, Content.BestKnownQuality);
71      }
72    }
73
74    protected override void SetEnabledStateOfControls() {
75      base.SetEnabledStateOfControls();
76      parameterCollectionView.Enabled = Content != null;
77      pathTSPTourView.Enabled = Content != null;
78      importButton.Enabled = Content != null && !ReadOnly;
79    }
80
81    private void importButton_Click(object sender, System.EventArgs e) {
82      if (tsplibImportDialog == null) tsplibImportDialog = new TSPLIBImportDialog();
83
84      if (tsplibImportDialog.ShowDialog(this) == DialogResult.OK) {
85        try {
86          if (tsplibImportDialog.Quality == null)
87            Content.ImportFromTSPLIB(tsplibImportDialog.TSPFileName, tsplibImportDialog.TourFileName);
88          else
89            Content.ImportFromTSPLIB(tsplibImportDialog.TSPFileName, tsplibImportDialog.TourFileName, (double)tsplibImportDialog.Quality);
90        }
91        catch (Exception ex) {
92          ErrorHandling.ShowErrorDialog(this, ex);
93        }
94      }
95    }
96
97    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
98      pathTSPTourView.Content.Coordinates = Content.Coordinates;
99    }
100    private void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {
101      pathTSPTourView.Content.Quality = Content.BestKnownQuality;
102    }
103    private void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
104      pathTSPTourView.Content.Permutation = Content.BestKnownSolution;
105    }
106  }
107}
Note: See TracBrowser for help on using the repository browser.