Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Charting.Gantt/Ganttchart.cs @ 2

Last change on this file since 2 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Text;
25using HeuristicLab.Scheduling.JSSP;
26using HeuristicLab.Charting.Grid;
27using System.Drawing;
28
29namespace HeuristicLab.Charting.Gantt {
30  public class Ganttchart : Gridchart {
31    private Schedule schedule;
32    public Schedule Schedule {
33      get { return schedule; }
34      set { schedule = value; DisplaySchedule(); }
35    }
36
37    private List<Color> colors;
38
39    public Ganttchart(Schedule s, PointD lowerLeft, PointD upperRight)
40      : base(lowerLeft, upperRight) {
41      schedule = s;
42      colors = new List<Color>();
43      DisplaySchedule();
44    }
45
46    public Ganttchart(Schedule s, double x1, double y1, double x2, double y2)
47      : base(x1, y1, x2, y2) {
48      schedule = s;
49      colors = new List<Color>();
50      DisplaySchedule();   
51    }
52
53    private void DisplaySchedule() {
54      Random rand = new Random();
55      if((schedule != null) && (schedule.Machines > 0)) {
56        // delete all primitives except the grid
57        Grid.Grid grid = (Grid.Grid) Group.Primitives[Group.Primitives.Count - 1];
58        Group.Clear();
59        Group.Add(grid);
60
61        this.Redim(schedule.Machines, schedule.GetMachineSchedule(0).Timespan);
62        for(int i = 0; i < schedule.Machines; i++) {
63          ScheduleTree tree = schedule.GetMachineSchedule(i);
64          foreach(ScheduleTreeNode node in tree.InOrder) {
65            if(tree.IsLeaf(node) && (node.Data.job != -1)) {
66              OperationCell s = new OperationCell(this);
67              s.Value = node.Data.job;
68              s.SetSpan(1, node.Data.end - node.Data.start);
69              while(node.Data.job >= colors.Count) {
70                colors.Add(Color.Empty);
71              }
72              if(colors[node.Data.job].IsEmpty) {
73                colors[node.Data.job] = Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255));
74              }
75              s.Brush = new SolidBrush(colors[node.Data.job]);
76              this[i, node.Data.start] = s;
77            }
78          }
79        }
80      }
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.