[1241] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.ComponentModel;
|
---|
| 4 | using System.Drawing;
|
---|
| 5 | using System.Data;
|
---|
| 6 | using System.Text;
|
---|
| 7 | using System.Windows.Forms;
|
---|
| 8 | using HeuristicLab.Core;
|
---|
| 9 | using HeuristicLab.Data;
|
---|
| 10 |
|
---|
| 11 | namespace HeuristicLab.Assignment.QAP {
|
---|
| 12 | public partial class QAPInjectorView : ViewBase {
|
---|
| 13 |
|
---|
| 14 | public QAPInjectorView() {
|
---|
| 15 | InitializeComponent();
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | public QAPInjector injector {
|
---|
| 19 | get { return (QAPInjector)Item; }
|
---|
| 20 | set { base.Item = value; }
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | public QAPInjectorView(QAPInjector injector) : this() {
|
---|
| 24 | this.injector = injector;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | protected override void UpdateControls() {
|
---|
| 28 | base.UpdateControls();
|
---|
| 29 | if (injector == null) {
|
---|
| 30 | facilitiesTextBox.Text = "-";
|
---|
| 31 | facilitiesTextBox.Enabled = false;
|
---|
| 32 | knownQualCheckBox.Checked = false;
|
---|
| 33 | knownQualCheckBox.Enabled = false;
|
---|
| 34 | qualTextBox.Visible = false;
|
---|
| 35 | qualTextBox.Enabled = false;
|
---|
| 36 | } else {
|
---|
| 37 | facilitiesTextBox.Text = injector.GetVariable("Facilities").Value.ToString();
|
---|
| 38 | knownQualCheckBox.Checked = injector.GetVariable("InjectBestKnownQuality").GetValue<BoolData>().Data;
|
---|
| 39 | knownQualCheckBox.Enabled = true;
|
---|
| 40 | if (knownQualCheckBox.Checked) {
|
---|
| 41 | qualTextBox.Text = injector.GetVariable("BestKnownQuality").Value.ToString();
|
---|
| 42 | qualTextBox.Enabled = true;
|
---|
| 43 | } else {
|
---|
| 44 | qualTextBox.Text = "-";
|
---|
| 45 | qualTextBox.Enabled = false;
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | private void loadButton_Click(object sender, EventArgs e) {
|
---|
| 51 | if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 52 | QAPParser parser = null;
|
---|
| 53 | bool success = false;
|
---|
| 54 | try {
|
---|
| 55 | parser = new QAPParser();
|
---|
| 56 | parser.Parse(openFileDialog.FileName);
|
---|
| 57 | success = true;
|
---|
| 58 | } catch (Exception ex) {
|
---|
| 59 | MessageBox.Show(this, ex.Message, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 60 | }
|
---|
| 61 | if (success) {
|
---|
| 62 | injector.GetVariable("Facilities").Value = new IntData(parser.facilities);
|
---|
| 63 | injector.GetVariable("Distances").Value = new DoubleMatrixData(parser.distances);
|
---|
| 64 | injector.GetVariable("Weights").Value = new DoubleMatrixData(parser.weights);
|
---|
| 65 | Refresh();
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | protected override void RemoveItemEvents() {
|
---|
| 71 | operatorBaseVariableInfosView.Operator = null;
|
---|
| 72 | operatorBaseDescriptionView.Operator = null;
|
---|
| 73 | base.RemoveItemEvents();
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | protected override void AddItemEvents() {
|
---|
| 77 | base.AddItemEvents();
|
---|
| 78 | operatorBaseVariableInfosView.Operator = injector;
|
---|
| 79 | operatorBaseDescriptionView.Operator = injector;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | private void knownQualCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 83 | injector.GetVariable("InjectBestKnownQuality").GetValue<BoolData>().Data = knownQualCheckBox.Checked;
|
---|
| 84 | if (knownQualCheckBox.Checked) {
|
---|
| 85 | qualTextBox.Text = injector.GetVariable("BestKnownQuality").Value.ToString();
|
---|
| 86 | qualTextBox.Enabled = true;
|
---|
| 87 | } else {
|
---|
| 88 | qualTextBox.Text = "-";
|
---|
| 89 | qualTextBox.Enabled = false;
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | private void qualTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
| 94 | e.Cancel = false;
|
---|
| 95 | try {
|
---|
| 96 | injector.GetVariable("BestKnownQuality").GetValue<DoubleData>().Data = double.Parse(qualTextBox.Text);
|
---|
| 97 | } catch (Exception) {
|
---|
| 98 | qualTextBox.SelectAll();
|
---|
| 99 | e.Cancel = true;
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | private void facilitiesTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 104 |
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | }
|
---|