Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QuadraticAssignmentProblemView.cs @ 7000

Last change on this file since 7000 was 6952, checked in by abeham, 13 years ago

#1619

  • reverted changes to trunk
  • readded instances as embedded resources
File size: 5.8 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.Drawing;
24using System.IO;
25using System.Windows.Forms;
26using HeuristicLab.Common.Resources;
27using HeuristicLab.Core.Views;
28using HeuristicLab.MainForm;
29using HeuristicLab.MainForm.WindowsForms;
30
31namespace 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;
43      Controls.Remove(parameterCollectionView);
44      parameterCollectionView.Dock = DockStyle.Fill;
45      problemTabPage.Controls.Add(parameterCollectionView);
46    }
47
48    protected override void RegisterContentEvents() {
49      base.RegisterContentEvents();
50      Content.DistancesParameter.ValueChanged += new EventHandler(DistanceMatrixParameter_ValueChanged);
51      Content.WeightsParameter.ValueChanged += new EventHandler(WeightsParameter_ValueChanged);
52      Content.BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
53    }
54
55    protected override void DeregisterContentEvents() {
56      Content.DistancesParameter.ValueChanged -= new EventHandler(DistanceMatrixParameter_ValueChanged);
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) {
63      qapView.Distances = Content.Distances;
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
74    protected override void OnContentChanged() {
75      base.OnContentChanged();
76      instancesComboBox.Items.Clear();
77      if (Content != null) {
78        foreach (string instance in Content.Instances) {
79          instancesComboBox.Items.Add(instance);
80        }
81        qapView.Distances = Content.Distances;
82        qapView.Weights = Content.Weights;
83        qapView.Assignment = Content.BestKnownSolution;
84      } else {
85        qapView.Distances = null;
86        qapView.Weights = null;
87        qapView.Assignment = null;
88      }
89    }
90
91    protected override void SetEnabledStateOfControls() {
92      base.SetEnabledStateOfControls();
93      instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null;
94      loadInstanceButton.Enabled = !ReadOnly && !Locked && Content != null && instancesComboBox.SelectedItem != null;
95      importInstanceButton.Enabled = !ReadOnly && !Locked && Content != null;
96    }
97
98    private void instancesComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
99      loadInstanceButton.Enabled = instancesComboBox.SelectedItem != null;
100    }
101
102    private void loadInstanceButton_Click(object sender, System.EventArgs e) {
103      string instance = instancesComboBox.SelectedItem as string;
104      try {
105        Content.LoadInstanceFromEmbeddedResource(instance);
106      } catch (Exception ex) {
107        PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
108      }
109    }
110
111    private void importInstanceButton_Click(object sender, System.EventArgs e) {
112      if (openFileDialog.ShowDialog() == DialogResult.OK) {
113        try {
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          }
122        } catch (Exception ex) {
123          PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
124        }
125      }
126    }
127
128    private void QAPLIBInstancesLabel_Click(object sender, System.EventArgs e) {
129      System.Diagnostics.Process.Start("http://www.seas.upenn.edu/qaplib/");
130    }
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    }
143  }
144}
Note: See TracBrowser for help on using the repository browser.