Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Encodings.ScheduleEncoding.Views/3.3/ScheduleView.cs @ 6412

Last change on this file since 6412 was 6412, checked in by jhelm, 13 years ago

#1329: Did some minor changes affecting datatypes.

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