Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding.Views/3.3/ScheduleView.cs @ 17226

Last change on this file since 17226 was 17226, checked in by mkommend, 5 years ago

#2521: Merged trunk changes into problem refactoring branch.

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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      foreach (Resource resource in content.Resources) {
70        foreach (ScheduledTask task in resource.Tasks) {
71          int categoryNr = task.JobNr;
72          string categoryName = "Job" + categoryNr;
73          string toolTip = categoryName + " - " + "Task#" + task.TaskNr;
74
75          ganttChart.AddData("Resource" + resource.Index,
76            categoryNr,
77            task.TaskNr,
78            task.StartTime,
79            task.EndTime,
80            toolTip);
81        }
82      }
83    }
84
85    protected override void SetEnabledStateOfControls() {
86      base.SetEnabledStateOfControls();
87      ganttChart.Enabled = Content != null;
88    }
89
90
91    private void Content_QualityChanged(object sender, EventArgs e) {
92      if (InvokeRequired)
93        Invoke(new EventHandler(Content_QualityChanged), sender, e);
94      else {
95        if (Content == null) {
96          ResetGanttChart();
97        } else {
98          RedrawGanttChart(Content);
99        }
100      }
101    }
102
103    private void Content_ResourcesChanged(object sender, EventArgs e) {
104      if (InvokeRequired)
105        Invoke(new EventHandler(Content_ResourcesChanged), sender, e);
106      else {
107        if (Content == null) {
108          ResetGanttChart();
109        } else {
110          RedrawGanttChart(Content);
111        }
112      }
113    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.