Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Encodings.ScheduleEncoding.Views/3.3/ScheduleView.cs @ 16225

Last change on this file since 16225 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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.AddData("Resource" + r.Index,
82            categoryNr,
83            t.TaskNr,
84            t.StartTime,
85            t.EndTime,
86            toolTip);
87        }
88        resCount++;
89      }
90    }
91
92    private void RefreshChartInformations(Schedule content) {
93
94    }
95
96    protected override void SetEnabledStateOfControls() {
97      base.SetEnabledStateOfControls();
98      ganttChart.Enabled = Content != null;
99    }
100
101
102    private void Content_QualityChanged(object sender, EventArgs e) {
103      if (InvokeRequired)
104        Invoke(new EventHandler(Content_QualityChanged), sender, e);
105      else {
106        if (Content == null) {
107          ResetGanttChart();
108        } else {
109          RedrawGanttChart(Content);
110        }
111      }
112    }
113
114    private void Content_ResourcesChanged(object sender, EventArgs e) {
115      if (InvokeRequired)
116        Invoke(new EventHandler(Content_ResourcesChanged), sender, e);
117      else {
118        if (Content == null) {
119          ResetGanttChart();
120        } else {
121          RedrawGanttChart(Content);
122        }
123      }
124    }
125  }
126}
Note: See TracBrowser for help on using the repository browser.