Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Assignment.QAP/3.2/QAPInjectorView.cs @ 3397

Last change on this file since 3397 was 1529, checked in by gkronber, 16 years ago

Moved source files of plugins AdvancedOptimizationFrontEnd ... Grid into version-specific sub-folders. #576

File size: 3.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Text;
7using System.Windows.Forms;
8using HeuristicLab.Core;
9using HeuristicLab.Data;
10
11namespace 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}
Note: See TracBrowser for help on using the repository browser.