[2805] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Windows.Forms;
|
---|
[3376] | 24 | using HeuristicLab.Common;
|
---|
[3153] | 25 | using HeuristicLab.Core;
|
---|
[2805] | 26 | using HeuristicLab.Core.Views;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 |
|
---|
[3158] | 29 | namespace HeuristicLab.Problems.TravelingSalesman.Views {
|
---|
[2805] | 30 | /// <summary>
|
---|
| 31 | /// The base class for visual representations of items.
|
---|
| 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>
|
---|
| 44 | /// Initializes a new instance of <see cref="ItemBaseView"/>.
|
---|
| 45 | /// </summary>
|
---|
[3159] | 46 | public TravelingSalesmanProblemView() {
|
---|
[2805] | 47 | InitializeComponent();
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[3153] | 50 | protected override void DeregisterContentEvents() {
|
---|
| 51 | Content.CoordinatesParameter.ValueChanged -= new EventHandler(CoordinatesParameter_ValueChanged);
|
---|
| 52 | Content.BestKnownSolutionParameter.ValueChanged -= new EventHandler(BestKnownSolutionParameter_ValueChanged);
|
---|
| 53 | base.DeregisterContentEvents();
|
---|
| 54 | }
|
---|
| 55 | protected override void RegisterContentEvents() {
|
---|
| 56 | base.RegisterContentEvents();
|
---|
| 57 | Content.CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
|
---|
| 58 | Content.BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[2998] | 61 | protected override void OnContentChanged() {
|
---|
| 62 | base.OnContentChanged();
|
---|
| 63 | if (Content == null) {
|
---|
[3153] | 64 | parameterCollectionView.Content = null;
|
---|
| 65 | pathTSPTourView.Content = null;
|
---|
[2998] | 66 | } else {
|
---|
[3153] | 67 | parameterCollectionView.Content = ((IParameterizedNamedItem)Content).Parameters;
|
---|
| 68 | pathTSPTourView.Content = new PathTSPTour(Content.Coordinates, Content.BestKnownSolution);
|
---|
[2998] | 69 | }
|
---|
[3454] | 70 | SetEnabledStateOfControls();
|
---|
[2998] | 71 | }
|
---|
| 72 |
|
---|
[3454] | 73 | protected override void OnReadOnlyChanged() {
|
---|
| 74 | base.OnReadOnlyChanged();
|
---|
| 75 | SetEnabledStateOfControls();
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | private void SetEnabledStateOfControls() {
|
---|
| 79 | parameterCollectionView.Enabled = Content != null;
|
---|
| 80 | pathTSPTourView.Enabled = Content != null;
|
---|
| 81 | importButton.Enabled = Content != null && !ReadOnly;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[2805] | 84 | private void importButton_Click(object sender, System.EventArgs e) {
|
---|
[3151] | 85 | if (tsplibImportDialog == null) tsplibImportDialog = new TSPLIBImportDialog();
|
---|
| 86 |
|
---|
| 87 | if (tsplibImportDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
[2805] | 88 | try {
|
---|
[3151] | 89 | if (tsplibImportDialog.Quality == null)
|
---|
| 90 | Content.ImportFromTSPLIB(tsplibImportDialog.TSPFileName, tsplibImportDialog.TourFileName);
|
---|
| 91 | else
|
---|
| 92 | Content.ImportFromTSPLIB(tsplibImportDialog.TSPFileName, tsplibImportDialog.TourFileName, (double)tsplibImportDialog.Quality);
|
---|
[2805] | 93 | }
|
---|
| 94 | catch (Exception ex) {
|
---|
| 95 | Auxiliary.ShowErrorMessageBox(ex);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
[3153] | 99 |
|
---|
| 100 | private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 101 | pathTSPTourView.Content.Coordinates = Content.Coordinates;
|
---|
| 102 | }
|
---|
| 103 | private void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 104 | pathTSPTourView.Content.Permutation = Content.BestKnownSolution;
|
---|
| 105 | }
|
---|
[2805] | 106 | }
|
---|
| 107 | }
|
---|