Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.Scheduling.Views/3.3/JobShopSchedulingProblemView.cs @ 12440

Last change on this file since 12440 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 4.4 KB
RevLine 
[6121]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6121]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
[10433]22using System;
[6121]23using System.Windows.Forms;
[10433]24using HeuristicLab.Collections;
25using HeuristicLab.Encodings.ScheduleEncoding;
[6121]26using HeuristicLab.MainForm;
[8882]27using HeuristicLab.Optimization.Views;
[6121]28
29namespace HeuristicLab.Problems.Scheduling.Views {
30  [View("JobShop Scheduling Problem View")]
31  [Content(typeof(JobShopSchedulingProblem), true)]
[8882]32  public partial class JobShopSchedulingProblemView : ProblemView {
[6121]33
34    public new JobShopSchedulingProblem Content {
35      get { return (JobShopSchedulingProblem)base.Content; }
36      set { base.Content = value; }
37    }
38
[8882]39    public JobShopSchedulingProblemView() {
40      InitializeComponent();
41      Controls.Remove(parameterCollectionView);
42      parameterCollectionView.Dock = DockStyle.Fill;
43      problemTabPage.Controls.Add(parameterCollectionView);
44    }
45
[6121]46    protected override void OnContentChanged() {
47      base.OnContentChanged();
[10433]48      FillGanttChart();
[6121]49    }
50
[10213]51    protected override void DeregisterContentEvents() {
[10433]52      Content.JobDataParameter.ValueChanged -= JobDataParameterOnValueChanged;
53      Content.JobData.ItemsAdded -= JobsOnChanged;
[11346]54      Content.JobData.ItemsRemoved -= JobsOnRemoved;
[10433]55      Content.JobData.ItemsReplaced -= JobsOnChanged;
56      Content.JobData.CollectionReset -= JobsOnChanged;
57      foreach (var job in Content.JobData) {
58        job.TasksChanged -= JobOnTasksChanged;
59      }
[10213]60      base.DeregisterContentEvents();
61    }
62    protected override void RegisterContentEvents() {
63      base.RegisterContentEvents();
[10433]64      Content.JobDataParameter.ValueChanged += JobDataParameterOnValueChanged;
65      Content.JobData.ItemsAdded += JobsOnChanged;
[11346]66      Content.JobData.ItemsRemoved += JobsOnRemoved;
[10433]67      Content.JobData.ItemsReplaced += JobsOnChanged;
68      Content.JobData.CollectionReset += JobsOnChanged;
69      foreach (var job in Content.JobData) {
70        job.TasksChanged += JobOnTasksChanged;
71      }
[10213]72    }
73
[10433]74    private void JobsOnChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<Job>> e) {
75      foreach (var job in e.OldItems)
76        job.Value.TasksChanged -= JobOnTasksChanged;
77      foreach (var job in e.Items)
78        job.Value.TasksChanged += JobOnTasksChanged;
79      FillGanttChart();
80    }
81
[11346]82    private void JobsOnRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<Job>> e) {
83      foreach (var job in e.Items)
84        job.Value.TasksChanged -= JobOnTasksChanged;
85      FillGanttChart();
86    }
87
[10433]88    private void JobDataParameterOnValueChanged(object sender, EventArgs e) {
89      Content.JobData.ItemsAdded += JobsOnChanged;
[11346]90      Content.JobData.ItemsRemoved += JobsOnRemoved;
[10433]91      Content.JobData.ItemsReplaced += JobsOnChanged;
92      Content.JobData.CollectionReset += JobsOnChanged;
93      foreach (var job in Content.JobData) {
94        job.TasksChanged += JobOnTasksChanged;
[10213]95      }
[10433]96      FillGanttChart();
[10213]97    }
98
[10433]99    private void JobOnTasksChanged(object sender, EventArgs e) {
100      FillGanttChart();
101    }
102
103    private void FillGanttChart() {
[6260]104      ganttChart.Reset();
[10433]105      if (Content == null) return;
[6177]106      int jobCount = 0;
[10433]107      foreach (var j in Content.JobData) {
[6294]108        double lastEndTime = 0;
[10433]109        foreach (var t in Content.JobData[jobCount].Tasks) {
[6412]110          int categoryNr = t.JobNr;
[6260]111          string categoryName = "Job" + categoryNr;
[6177]112          ganttChart.AddData(categoryName,
[6260]113            categoryNr,
[6482]114            t.TaskNr,
[6294]115            lastEndTime + 1,
[6412]116            lastEndTime + t.Duration,
[10433]117            "Job" + t.JobNr + " - " + "Task#" + t.TaskNr);
[6412]118          lastEndTime += t.Duration;
[6177]119        }
120        jobCount++;
121      }
122    }
[6121]123  }
124}
Note: See TracBrowser for help on using the repository browser.