Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.cs @ 4507

Last change on this file since 4507 was 4374, checked in by svonolfe, 14 years ago

Added analyzers and views (#1177)

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