Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization.Views/3.3/LinearProgrammingProblemView.cs @ 16405

Last change on this file since 16405 was 16405, checked in by ddorfmei, 6 years ago

#2931:

  • moved views to separate plugin HeuristicLab.MathematicalOptimization.Views
  • added button in LinearProgrammingProblemView to select the problem definition type
  • added views for problem definitions
  • added ExportFile parameter to LinearProgrammingAlgorithm
  • extended FileValue and FileValueView by the option to save a file
  • code cleanup
File size: 4.0 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;
26using HeuristicLab.MainForm.WindowsForms;
27using HeuristicLab.MathematicalOptimization.LinearProgramming;
28using HeuristicLab.PluginInfrastructure;
29
30namespace HeuristicLab.MathematicalOptimization.Views {
31
32  [View(nameof(LinearProgrammingProblemView))]
33  [Content(typeof(LinearProgrammingProblem), true)]
34  public partial class LinearProgrammingProblemView : ItemView {
35    protected ViewHost definitionView;
36
37    private TypeSelectorDialog problemTypeSelectorDialog;
38
39    public LinearProgrammingProblemView() {
40      InitializeComponent();
41      definitionView = ViewHost;
42    }
43
44    public new LinearProgrammingProblem Content {
45      get => (LinearProgrammingProblem)base.Content;
46      set => base.Content = value;
47    }
48
49    protected override void DeregisterContentEvents() {
50      base.DeregisterContentEvents();
51      Content.ProblemDefinitionChanged -= ContentOnProblemDefinitionChanged;
52      Content.NameChanged -= ContentOnNameChanged;
53    }
54
55    protected override void OnContentChanged() {
56      base.OnContentChanged();
57      if (Content == null) {
58        definitionView.Content = null;
59      } else {
60        Caption = Content.Name;
61        ContentOnProblemDefinitionChanged(Content, EventArgs.Empty);
62      }
63    }
64
65    protected override void RegisterContentEvents() {
66      Content.ProblemDefinitionChanged += ContentOnProblemDefinitionChanged;
67      Content.NameChanged += ContentOnNameChanged;
68      base.RegisterContentEvents();
69    }
70
71    private void changeModelTypeButton_Click(object sender, EventArgs e) {
72      if (problemTypeSelectorDialog == null) {
73        problemTypeSelectorDialog = new TypeSelectorDialog { Caption = "Select Model Type" };
74        problemTypeSelectorDialog.TypeSelector.Caption = "Available Model Types";
75        problemTypeSelectorDialog.TypeSelector.Configure(typeof(ILinearProgrammingProblemDefinition), false, true);
76      }
77      if (problemTypeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
78        try {
79          Content.ProblemDefinition =
80            (ILinearProgrammingProblemDefinition)problemTypeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
81        } catch (Exception ex) {
82          ErrorHandling.ShowErrorDialog(this, ex);
83        }
84      }
85    }
86
87    private void ContentOnNameChanged(object sender, EventArgs eventArgs) {
88      Caption = Content.Name;
89    }
90
91    private void ContentOnProblemDefinitionChanged(object sender, EventArgs eventArgs) {
92      var problemDefinition = ((LinearProgrammingProblem)sender).ProblemDefinition;
93      definitionView.Content = problemDefinition;
94
95      switch (problemDefinition) {
96        case null:
97          modelTypeNameLabel.Text = "none";
98          break;
99
100        case ProgrammableLinearProgrammingProblemDefinition _:
101          modelTypeNameLabel.Text = "Script";
102          break;
103
104        case FileBasedLinearProgrammingProblemDefinition _:
105          modelTypeNameLabel.Text = "File";
106          break;
107
108        default:
109          throw new NotImplementedException("Unknown problem definition type.");
110      }
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.