Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17181 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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      var view = problemInstanceView.ActiveView as VRPProblemInstanceView;
52      if (view != null) view.Solution = null;
53
54      problemInstanceView.Content = Content.ProblemInstance;
55
56      view = problemInstanceView.ActiveView as VRPProblemInstanceView;
57      if (view != null) view.Solution = Content.Solution;
58
59      UpdateTourView();
60    }
61
62    protected override void OnContentChanged() {
63      base.OnContentChanged();
64      if (Content == null) {
65        problemInstanceView.Content = null;
66      } else {
67        UpdateContent();
68      }
69    }
70
71    private void Content_SolutionChanged(object sender, EventArgs e) {
72      if (InvokeRequired)
73        Invoke(new EventHandler(Content_SolutionChanged), sender, e);
74      else {
75        UpdateContent();
76      }
77    }
78
79    protected override void OnReadOnlyChanged() {
80      base.OnReadOnlyChanged();
81      SetEnabledStateOfControls();
82    }
83
84    protected override void SetEnabledStateOfControls() {
85      base.SetEnabledStateOfControls();
86      tabControl1.Enabled = Content != null;
87      problemInstanceView.Enabled = Content != null;
88    }
89
90    private void UpdateTourView() {
91      StringBuilder sb = new StringBuilder();
92
93      if (Content != null && Content.Solution != null) {
94        foreach (Tour tour in Content.Solution.GetTours()) {
95          foreach (int city in tour.Stops) {
96            sb.Append(city);
97            sb.Append(" ");
98          }
99          sb.AppendLine();
100        }
101      }
102
103      valueTextBox.Text = sb.ToString();
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.