Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Problems.Scheduling.Views/3.3/JobShopSchedulingProblemView.cs @ 6514

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

#1329: Applied some changes to the ScheduleView. Added TaskNr properties to ScheduledTask to make specific selection of tasks in the view possible.

File size: 3.6 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.Windows.Forms;
24using HeuristicLab.Core;
25using HeuristicLab.Core.Views;
26using HeuristicLab.Encodings.ScheduleEncoding;
27using HeuristicLab.MainForm;
28using HeuristicLab.PluginInfrastructure;
29
30namespace HeuristicLab.Problems.Scheduling.Views {
31  [View("JobShop Scheduling Problem View")]
32  [Content(typeof(JobShopSchedulingProblem), true)]
33  public partial class JobShopSchedulingProblemView : NamedItemView {
34    public JobShopSchedulingProblemView() {
35      InitializeComponent();
36    }
37    private SchedulingProblemImportDialog spImportDialog;
38
39    public new JobShopSchedulingProblem Content {
40      get { return (JobShopSchedulingProblem)base.Content; }
41      set { base.Content = value; }
42    }
43
44    protected override void OnContentChanged() {
45      base.OnContentChanged();
46      if (Content == null) {
47        parameterCollectionView.Content = null;
48        ganttChart.Reset();
49      } else {
50        parameterCollectionView.Content = ((IParameterizedNamedItem)Content).Parameters;
51        FillGanttChart(Content);
52      }
53    }
54
55    private void FillGanttChart(JobShopSchedulingProblem content) {
56      //Add Jobs as Categories
57      ganttChart.Reset();
58      int jobCount = 0;
59      Random random = new Random(1);
60      foreach (Job j in content.JobData) {
61        double lastEndTime = 0;
62        foreach (Task t in content.JobData[jobCount].Tasks) {
63          int categoryNr = t.JobNr;
64          string categoryName = "Job" + categoryNr;
65          ganttChart.AddData(categoryName,
66            categoryNr,
67            t.TaskNr,
68            lastEndTime + 1,
69            lastEndTime + t.Duration,
70            "Job" + t.JobNr + " - " + "Task#" + t.TaskNr.ToString());
71          lastEndTime += t.Duration;
72        }
73        jobCount++;
74      }
75    }
76
77    protected override void SetEnabledStateOfControls() {
78      base.SetEnabledStateOfControls();
79      parameterCollectionView.Enabled = Content != null;
80      importButton.Enabled = Content != null && !ReadOnly;
81    }
82
83    private void importButton_Click(object sender, EventArgs e) {
84      if (spImportDialog == null) spImportDialog = new SchedulingProblemImportDialog();
85
86      if (spImportDialog.ShowDialog(this) == DialogResult.OK) {
87        try {
88          switch (spImportDialog.Format) {
89            case SPFormat.ORLib:
90              Content.ImportFromORLibrary(spImportDialog.SPFileName);
91              break;
92          }
93
94
95          if (!string.IsNullOrEmpty(spImportDialog.OptimalScheduleFileName))
96            Content.ImportJSMSolution(spImportDialog.OptimalScheduleFileName);
97          OnContentChanged();
98        }
99        catch (Exception ex) {
100          ErrorHandling.ShowErrorDialog(this, ex);
101        }
102      }
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.