Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Encodings.SchedulingEncoding.Views/3.3/ScheduleView.cs @ 6368

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

#1329: Did some minor refactoring.

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