Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.cs @ 10037

Last change on this file since 10037 was 9456, checked in by swagner, 11 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.Text;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26
27namespace HeuristicLab.Problems.VehicleRouting.Views {
28  [View("VRPSolution View")]
29  [Content(typeof(VRPSolution), true)]
30  public partial class VRPSolutionView : HeuristicLab.Core.Views.ItemView {
31    public new VRPSolution Content {
32      get { return (VRPSolution)base.Content; }
33      set { base.Content = value; }
34    }
35
36    public VRPSolutionView() {
37      InitializeComponent();
38      problemInstanceView.ViewsLabelVisible = false;
39    }
40
41    protected override void DeregisterContentEvents() {
42      Content.SolutionChanged -= new EventHandler(Content_SolutionChanged);
43      base.DeregisterContentEvents();
44    }
45    protected override void RegisterContentEvents() {
46      base.RegisterContentEvents();
47      Content.SolutionChanged += new EventHandler(Content_SolutionChanged);
48    }
49
50    private void UpdateContent() {
51      problemInstanceView.Content = Content.ProblemInstance;
52      VRPProblemInstanceView view = problemInstanceView.ActiveView as VRPProblemInstanceView;
53      if (view != null) {
54        view.Solution = Content.Solution;
55      }
56
57      UpdateTourView();
58    }
59
60    protected override void OnContentChanged() {
61      base.OnContentChanged();
62      if (Content == null) {
63        problemInstanceView.Content = null;
64      } else {
65        UpdateContent();
66      }
67    }
68
69    private void Content_SolutionChanged(object sender, EventArgs e) {
70      if (InvokeRequired)
71        Invoke(new EventHandler(Content_SolutionChanged), sender, e);
72      else {
73        UpdateContent();
74      }
75    }
76
77    protected override void OnReadOnlyChanged() {
78      base.OnReadOnlyChanged();
79      SetEnabledStateOfControls();
80    }
81
82    protected override void SetEnabledStateOfControls() {
83      base.SetEnabledStateOfControls();
84      tabControl1.Enabled = Content != null;
85      problemInstanceView.Enabled = Content != null;
86    }
87
88    private void UpdateTourView() {
89      StringBuilder sb = new StringBuilder();
90
91      if (Content != null && Content.Solution != null) {
92        foreach (Tour tour in Content.Solution.GetTours()) {
93          foreach (int city in tour.Stops) {
94            sb.Append(city);
95            sb.Append(" ");
96          }
97          sb.AppendLine();
98        }
99      }
100
101      valueTextBox.Text = sb.ToString();
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.