Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPProblemInstanceView.cs @ 15589

Last change on this file since 15589 was 15584, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers on stable

File size: 3.7 KB
RevLine 
[4374]1#region License Information
2/* HeuristicLab
[15584]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[4374]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;
[8651]29using HeuristicLab.Optimization.Views;
[4374]30
31namespace HeuristicLab.Problems.VehicleRouting.Views {
32  [View("VRPProblemInstance View")]
33  [Content(typeof(IVRPProblemInstance), true)]
[8651]34  public abstract partial class VRPProblemInstanceView : ParameterizedNamedItemView {
[4374]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
[6715]69    protected virtual void pictureBox_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) {
70    }
71
[4374]72    protected abstract void DrawVisualization(Bitmap bitmap);
73
[7858]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        }
[8053]100
[7858]101        i++;
102        if (i == 6) {
103          i = 0;
104
[8053]105          if (r >= step)
[7858]106            r -= step;
107
[8053]108          if (g >= step)
109            g -= step;
[7858]110
[8053]111          if (b >= step)
112            b -= step;
113        }
[7858]114      }
115
116      return result;
117    }
118
[6715]119    protected void GenerateImage() {
[4374]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.