1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 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.ComponentModel;
|
---|
25 | using System.Drawing;
|
---|
26 | using System.Data;
|
---|
27 | using System.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using HeuristicLab.Core.Views;
|
---|
31 | using HeuristicLab.MainForm;
|
---|
32 | using HeuristicLab.Core;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Problems.Scheduling.Views {
|
---|
35 | [View("Schedule View")]
|
---|
36 | [Content(typeof(Schedule), true)]
|
---|
37 | public partial class ScheduleView : NamedItemView {
|
---|
38 | public ScheduleView() {
|
---|
39 | InitializeComponent();
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
43 | protected override void DeregisterContentEvents() {
|
---|
44 | Content.QualityChanged -= new EventHandler(Content_QualityChanged);
|
---|
45 | Content.ResourcesChanged -= new EventHandler(Content_ResourcesChanged);
|
---|
46 |
|
---|
47 | base.DeregisterContentEvents();
|
---|
48 | }
|
---|
49 | protected override void RegisterContentEvents() {
|
---|
50 | base.RegisterContentEvents();
|
---|
51 | Content.QualityChanged += new EventHandler(Content_QualityChanged);
|
---|
52 | Content.ResourcesChanged += new EventHandler(Content_ResourcesChanged);
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | public new Schedule Content {
|
---|
57 | get { return (Schedule)base.Content; }
|
---|
58 | set { base.Content = value; }
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected override void OnContentChanged() {
|
---|
62 | base.OnContentChanged();
|
---|
63 | if (Content == null) {
|
---|
64 | ResetGanttChart();
|
---|
65 | } else {
|
---|
66 | FillGanttChart(Content);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | private void ResetGanttChart() {
|
---|
71 | ganttChart.Reset();
|
---|
72 | }
|
---|
73 |
|
---|
74 | private void FillGanttChart(Schedule content) {
|
---|
75 | ResetGanttChart();
|
---|
76 | int resCount = 0;
|
---|
77 | Random random = new Random (1);
|
---|
78 | foreach (Resource r in content.Resources) {
|
---|
79 | foreach (JSSPTask t in content.Resources[resCount].Tasks) {
|
---|
80 | int categoryNr = 0;
|
---|
81 | string toolTip = "Task#" + t.TaskNr;
|
---|
82 | string categoryName = "ScheduleTasks";
|
---|
83 | if (t is JSSPTask) {
|
---|
84 | categoryNr = ((JSSPTask)t).JobNr.Value;
|
---|
85 | categoryName = "Job" + categoryNr;
|
---|
86 | toolTip = categoryName + " - " + toolTip;
|
---|
87 | }
|
---|
88 | ganttChart.AddJobColor(categoryNr);
|
---|
89 | ganttChart.AddData("Resource" + r.Index,
|
---|
90 | categoryNr,
|
---|
91 | t.StartTime.Value,
|
---|
92 | t.EndTime.Value,
|
---|
93 | toolTip);
|
---|
94 | }
|
---|
95 | resCount++;
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | protected override void SetEnabledStateOfControls() {
|
---|
100 | base.SetEnabledStateOfControls();
|
---|
101 | ganttChart.Enabled = Content != null;
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | private void Content_QualityChanged(object sender, EventArgs e) {
|
---|
106 | if (InvokeRequired)
|
---|
107 | Invoke(new EventHandler(Content_QualityChanged), sender, e);
|
---|
108 | else {
|
---|
109 | if (Content == null) {
|
---|
110 | ResetGanttChart();
|
---|
111 | } else {
|
---|
112 | FillGanttChart(Content);
|
---|
113 | }
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | private void Content_ResourcesChanged(object sender, EventArgs e) {
|
---|
118 | if (InvokeRequired)
|
---|
119 | Invoke(new EventHandler(Content_ResourcesChanged), sender, e);
|
---|
120 | else {
|
---|
121 | if (Content == null) {
|
---|
122 | ResetGanttChart();
|
---|
123 | } else {
|
---|
124 | FillGanttChart(Content);
|
---|
125 | }
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 | }
|
---|