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