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