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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Text;
|
---|
25 | using HeuristicLab.Scheduling.JSSP;
|
---|
26 | using HeuristicLab.Charting.Grid;
|
---|
27 | using System.Drawing;
|
---|
28 |
|
---|
29 | namespace 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 | }
|
---|