Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Problems.Scheduling.Views/3.3/ScheduleView.cs @ 6260

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

#1329: Implemented PermutationWithRepetition Encoding. Implemented new operators for JSM Encoding.

File size: 3.9 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;
33
34namespace 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}
Note: See TracBrowser for help on using the repository browser.