Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP-MoveOperators/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPProblemInstanceView.cs @ 10145

Last change on this file since 10145 was 8053, checked in by ascheibe, 12 years ago

#1722 fixed more licensing information and source formatting

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