Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.VehicleRouting.Views/3.3/VehicleRoutingProblemView.cs @ 4851

Last change on this file since 4851 was 4851, checked in by svonolfe, 13 years ago

Implemented review comments (#1236)

File size: 4.2 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.Data;
27using HeuristicLab.MainForm;
28using HeuristicLab.Parameters;
29using HeuristicLab.PluginInfrastructure;
30
31namespace HeuristicLab.Problems.VehicleRouting.Views {
32  [View("VehicleRouting Problem View")]
33  [Content(typeof(VehicleRoutingProblem), true)]
34  public partial class VehicleRoutingProblemView : NamedItemView {
35    private VRPImportDialog vrpImportDialog;
36   
37    public new VehicleRoutingProblem Content {
38      get { return (VehicleRoutingProblem)base.Content; }
39      set { base.Content = value; }
40    }
41
42    public VehicleRoutingProblemView() {
43      InitializeComponent();
44    }
45
46    protected override void DeregisterContentEvents() {
47      Content.CoordinatesParameter.ValueChanged -= new EventHandler(CoordinatesParameter_ValueChanged);
48      Content.BestKnownQualityParameter.ValueChanged -= new EventHandler(BestKnownQualityParameter_ValueChanged);
49      base.DeregisterContentEvents();
50    }
51    protected override void RegisterContentEvents() {
52      base.RegisterContentEvents();
53      Content.CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
54      Content.BestKnownQualityParameter.ValueChanged += new EventHandler(BestKnownQualityParameter_ValueChanged);
55    }
56
57    protected override void OnContentChanged() {
58      base.OnContentChanged();
59      if (Content == null) {
60        parameterCollectionView.Content = null;
61        vrpSolutionView.Content = null;
62      } else {
63        parameterCollectionView.Content = ((IParameterizedNamedItem)Content).Parameters;
64        UpdateSolution();
65      }
66    }
67
68    protected override void SetEnabledStateOfControls() {
69      base.SetEnabledStateOfControls();
70      parameterCollectionView.Enabled = Content != null;
71      vrpSolutionView.Enabled = Content != null;
72      importButton.Enabled = Content != null && !ReadOnly;
73    }
74
75    private void importButton_Click(object sender, EventArgs e) {
76      if (vrpImportDialog == null) vrpImportDialog = new VRPImportDialog();
77
78      if (vrpImportDialog.ShowDialog(this) == DialogResult.OK) {
79        try {
80          switch (vrpImportDialog.Format) {
81            case VRPFormat.TSPLib:
82              Content.ImportFromTSPLib(vrpImportDialog.VRPFileName);
83              break;
84
85            case VRPFormat.Solomon:
86              Content.ImportFromSolomon(vrpImportDialog.VRPFileName);
87              break;
88
89            case VRPFormat.ORLib:
90              Content.ImportFromORLib(vrpImportDialog.VRPFileName);
91              break;
92          }
93
94          if(!string.IsNullOrEmpty(vrpImportDialog.TourFileName))
95            Content.ImportSolution(vrpImportDialog.TourFileName);
96         }
97        catch (Exception ex) {
98          ErrorHandling.ShowErrorDialog(this, ex);
99        }
100      }
101    }
102
103    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
104      vrpSolutionView.Content.Coordinates = Content.Coordinates;
105    }
106
107    private void UpdateSolution() {
108      if (Content.BestKnownSolution == null)
109        vrpSolutionView.Content = new VRPSolution(Content.Coordinates);
110      else {
111        vrpSolutionView.Content = Content.BestKnownSolution;
112      }
113    }
114
115   void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {
116      UpdateSolution();
117    }
118  }
119}
Note: See TracBrowser for help on using the repository browser.