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 |
|
---|
22 | using System;
|
---|
23 | using System.Windows.Forms;
|
---|
24 | using HeuristicLab.Common.Resources;
|
---|
25 | using HeuristicLab.Core.Views;
|
---|
26 | using HeuristicLab.MainForm;
|
---|
27 | using HeuristicLab.MainForm.WindowsForms;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Problems.QuadraticAssignment.Views {
|
---|
30 | [View("Quadratic Assignment Problem View")]
|
---|
31 | [Content(typeof(QuadraticAssignmentProblem), IsDefaultView = true)]
|
---|
32 | public sealed partial class QuadraticAssignmentProblemView : ParameterizedNamedItemView {
|
---|
33 | public new QuadraticAssignmentProblem Content {
|
---|
34 | get { return (QuadraticAssignmentProblem)base.Content; }
|
---|
35 | set { base.Content = value; }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public QuadraticAssignmentProblemView() {
|
---|
39 | InitializeComponent();
|
---|
40 | importInstanceButton.Image = VSImageLibrary.Open;
|
---|
41 | Controls.Remove(parameterCollectionView);
|
---|
42 | parameterCollectionView.Dock = DockStyle.Fill;
|
---|
43 | problemTabPage.Controls.Add(parameterCollectionView);
|
---|
44 | }
|
---|
45 |
|
---|
46 | protected override void RegisterContentEvents() {
|
---|
47 | base.RegisterContentEvents();
|
---|
48 | Content.DistanceMatrixParameter.ValueChanged += new EventHandler(DistanceMatrixParameter_ValueChanged);
|
---|
49 | Content.WeightsParameter.ValueChanged += new EventHandler(WeightsParameter_ValueChanged);
|
---|
50 | Content.BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected override void DeregisterContentEvents() {
|
---|
54 | Content.DistanceMatrixParameter.ValueChanged -= new EventHandler(DistanceMatrixParameter_ValueChanged);
|
---|
55 | Content.WeightsParameter.ValueChanged -= new EventHandler(WeightsParameter_ValueChanged);
|
---|
56 | Content.BestKnownSolutionParameter.ValueChanged -= new EventHandler(BestKnownSolutionParameter_ValueChanged);
|
---|
57 | base.DeregisterContentEvents();
|
---|
58 | }
|
---|
59 |
|
---|
60 | private void DistanceMatrixParameter_ValueChanged(object sender, System.EventArgs e) {
|
---|
61 | qapView.Distances = Content.DistanceMatrix;
|
---|
62 | }
|
---|
63 |
|
---|
64 | private void WeightsParameter_ValueChanged(object sender, System.EventArgs e) {
|
---|
65 | qapView.Weights = Content.Weights;
|
---|
66 | }
|
---|
67 |
|
---|
68 | private void BestKnownSolutionParameter_ValueChanged(object sender, System.EventArgs e) {
|
---|
69 | qapView.Assignment = Content.BestKnownSolution;
|
---|
70 | }
|
---|
71 |
|
---|
72 | protected override void OnContentChanged() {
|
---|
73 | base.OnContentChanged();
|
---|
74 | instancesComboBox.Items.Clear();
|
---|
75 | if (Content != null) {
|
---|
76 | foreach (string instance in Content.EmbeddedInstances) {
|
---|
77 | instancesComboBox.Items.Add(instance);
|
---|
78 | }
|
---|
79 | qapView.Distances = Content.DistanceMatrix;
|
---|
80 | qapView.Weights = Content.Weights;
|
---|
81 | qapView.Assignment = Content.BestKnownSolution;
|
---|
82 | } else {
|
---|
83 | qapView.Distances = null;
|
---|
84 | qapView.Weights = null;
|
---|
85 | qapView.Assignment = null;
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | protected override void SetEnabledStateOfControls() {
|
---|
90 | base.SetEnabledStateOfControls();
|
---|
91 | instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null;
|
---|
92 | loadInstanceButton.Enabled = !ReadOnly && !Locked && Content != null && instancesComboBox.SelectedItem != null;
|
---|
93 | importInstanceButton.Enabled = !ReadOnly && !Locked && Content != null;
|
---|
94 | }
|
---|
95 |
|
---|
96 | private void instancesComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
|
---|
97 | loadInstanceButton.Enabled = instancesComboBox.SelectedItem != null;
|
---|
98 | }
|
---|
99 |
|
---|
100 | private void loadInstanceButton_Click(object sender, System.EventArgs e) {
|
---|
101 | string instance = instancesComboBox.SelectedItem as string;
|
---|
102 | try {
|
---|
103 | Content.LoadEmbeddedInstance(instance);
|
---|
104 | } catch (Exception ex) {
|
---|
105 | PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | private void importInstanceButton_Click(object sender, System.EventArgs e) {
|
---|
110 | if (openFileDialog.ShowDialog() == DialogResult.OK) {
|
---|
111 | try {
|
---|
112 | Content.ImportFileInstance(openFileDialog.FileName);
|
---|
113 | } catch (Exception ex) {
|
---|
114 | PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
|
---|
115 | }
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | private void QAPLIBInstancesLabel_Click(object sender, System.EventArgs e) {
|
---|
120 | System.Diagnostics.Process.Start("http://www.seas.upenn.edu/qaplib/");
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|