Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.cs @ 17710

Last change on this file since 17710 was 17710, checked in by abeham, 4 years ago

#2521: working on VRP

File size: 3.4 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      evaluationViewHost.Content = Content.Evaluation;
62    }
63
64    protected override void OnContentChanged() {
65      base.OnContentChanged();
66      if (Content == null) {
67        problemInstanceView.Content = null;
68        evaluationViewHost.Content = null;
69        valueTextBox.Text = string.Empty;
70      } else {
71        UpdateContent();
72      }
73    }
74
75    private void Content_SolutionChanged(object sender, EventArgs e) {
76      if (InvokeRequired)
77        Invoke(new EventHandler(Content_SolutionChanged), sender, e);
78      else {
79        UpdateContent();
80      }
81    }
82
83    protected override void OnReadOnlyChanged() {
84      base.OnReadOnlyChanged();
85      SetEnabledStateOfControls();
86    }
87
88    protected override void SetEnabledStateOfControls() {
89      base.SetEnabledStateOfControls();
90      tabControl1.Enabled = Content != null;
91      problemInstanceView.Enabled = Content != null;
92    }
93
94    private void UpdateTourView() {
95      StringBuilder sb = new StringBuilder();
96
97      if (Content != null && Content.Solution != null) {
98        foreach (Tour tour in Content.Solution.GetTours()) {
99          foreach (int city in tour.Stops) {
100            sb.Append(city);
101            sb.Append(" ");
102          }
103          sb.AppendLine();
104        }
105      }
106
107      valueTextBox.Text = sb.ToString();
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.