Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPProblemInstanceView.cs @ 15990

Last change on this file since 15990 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Drawing;
25using System.Windows.Forms;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28using HeuristicLab.Problems.VehicleRouting.Interfaces;
29using HeuristicLab.Optimization.Views;
30
31namespace HeuristicLab.Problems.VehicleRouting.Views {
32  [View("VRPProblemInstance View")]
33  [Content(typeof(IVRPProblemInstance), true)]
34  public abstract partial class VRPProblemInstanceView : ParameterizedNamedItemView {
35    public new IVRPProblemInstance Content {
36      get { return (IVRPProblemInstance)base.Content; }
37      set { base.Content = value; }
38    }
39
40    private IVRPEncoding solution;
41    public IVRPEncoding Solution {
42      get {
43        return solution;
44      }
45      set {
46        solution = value;
47        GenerateImage();
48      }
49    }
50
51    public VRPProblemInstanceView() {
52      InitializeComponent();
53      Solution = null;
54    }
55
56    protected override void OnContentChanged() {
57      base.OnContentChanged();
58      if (Content == null) {
59        pictureBox.Image = null;
60      } else {
61        GenerateImage();
62      }
63    }
64
65    private void pictureBox_SizeChanged(object sender, EventArgs e) {
66      GenerateImage();
67    }
68
69    protected virtual void pictureBox_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) {
70    }
71
72    protected abstract void DrawVisualization(Bitmap bitmap);
73
74    protected List<Pen> GetColors(int count) {
75      List<Pen> result = new List<Pen>();
76
77      int i = 0;
78
79      int r = 255;
80      int g = 255;
81      int b = 255;
82
83      int step = Math.Max(1, 200 * 6 / count);
84
85      while (result.Count != count) {
86        switch (i) {
87          case 0: result.Add(new Pen(Color.FromArgb(0, 0, b)));
88            break;
89          case 1: result.Add(new Pen(Color.FromArgb(0, g, 0)));
90            break;
91          case 2: result.Add(new Pen(Color.FromArgb(r, 0, 0)));
92            break;
93          case 3: result.Add(new Pen(Color.FromArgb(0, g, b)));
94            break;
95          case 4: result.Add(new Pen(Color.FromArgb(r, 0, b)));
96            break;
97          case 5: result.Add(new Pen(Color.FromArgb(r, g, 0)));
98            break;
99        }
100
101        i++;
102        if (i == 6) {
103          i = 0;
104
105          if (r >= step)
106            r -= step;
107
108          if (g >= step)
109            g -= step;
110
111          if (b >= step)
112            b -= step;
113        }
114      }
115
116      return result;
117    }
118
119    protected void GenerateImage() {
120      if ((pictureBox.Width > 0) && (pictureBox.Height > 0)) {
121        if (Content == null) {
122          pictureBox.Image = null;
123        } else {
124          Bitmap bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
125
126          DrawVisualization(bitmap);
127
128          pictureBox.Image = bitmap;
129        }
130      }
131    }
132  }
133}
Note: See TracBrowser for help on using the repository browser.