Changeset 7415 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentView.cs
- Timestamp:
- 01/26/12 14:50:56 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentView.cs
r7412 r7415 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Linq; 25 26 using System.Windows.Forms; … … 44 45 #region Register Content Events 45 46 protected override void DeregisterContentEvents() { 46 // TODO: Deregister your event handlers on the Content here47 Content.PropertyChanged -= new PropertyChangedEventHandler(Content_PropertyChanged); 47 48 base.DeregisterContentEvents(); 48 49 } 49 50 protected override void RegisterContentEvents() { 50 51 base.RegisterContentEvents(); 51 // TODO: Register your event handlers on the Content here52 Content.PropertyChanged += new PropertyChangedEventHandler(Content_PropertyChanged); 52 53 } 53 54 #endregion … … 55 56 protected override void OnContentChanged() { 56 57 base.OnContentChanged(); 57 assignmentTreeView.Nodes.Clear(); 58 if (Content == null) { 59 qualityTextBox.Text = String.Empty; 60 } else { 61 qualityTextBox.Text = Content.Quality.Value.ToString(); 62 BuildAssignmentTree(); 63 } 58 UpdateQuality(); 59 UpdateAssignment(); 64 60 } 65 61 66 62 protected override void SetEnabledStateOfControls() { 67 63 base.SetEnabledStateOfControls(); 68 qualityTextBox.Enabled = false;69 assignmentTreeView.Enabled = true;70 64 } 71 65 72 66 #region Event Handlers 73 // TODO: Put event handlers here 67 private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) { 68 switch (e.PropertyName) { 69 case "Quality": UpdateQuality(); break; 70 case "FlowDistanceQuality": UpdateFlowDistanceQuality(); break; 71 case "InstallationQuality": UpdateInstallationQuality(); break; 72 case "OverbookedCapacity": UpdateOverbookedCapacity(); break; 73 case "Assignment": UpdateAssignment(); break; 74 case "EquipmentNames": UpdateAssignment(); break; 75 case "LocationNames": UpdateAssignment(); break; 76 default: break; 77 } 78 } 74 79 #endregion 75 80 76 private void BuildAssignmentTree() { 77 IntegerVector assignment = Content.Assignment; 78 Dictionary<int, TreeNode> locationNodes = new Dictionary<int, TreeNode>(); 79 for (int i = 0; i < assignment.Length; i++) { 80 if (!locationNodes.ContainsKey(assignment[i])) { 81 string locationName = assignment[i].ToString(); 82 if (Content.LocationNames != null && Content.LocationNames.Length > 0) 83 locationName = Content.LocationNames[assignment[i] % Content.LocationNames.Length]; 84 locationNodes.Add(assignment[i], new TreeNode(locationName)); 81 private void UpdateQuality() { 82 if (InvokeRequired) Invoke((Action)UpdateQuality); 83 else { 84 if (Content == null) { 85 qualityLabel.Text = "-"; 86 } else { 87 qualityLabel.Text = Content.Quality.ToString(); 85 88 } 86 string equipmentName = i.ToString();87 if (Content.EquipmentNames != null && Content.EquipmentNames.Length > 0)88 equipmentName = Content.EquipmentNames[i % Content.EquipmentNames.Length];89 locationNodes[assignment[i]].Nodes.Add(equipmentName);90 89 } 90 } 91 91 92 assignmentTreeView.BeginUpdate(); 93 try { 94 foreach (var node in locationNodes.OrderBy(x => x.Key).Select(x => x.Value)) { 95 assignmentTreeView.Nodes.Add(node); 96 node.Expand(); 92 private void UpdateFlowDistanceQuality() { 93 if (InvokeRequired) Invoke((Action)UpdateFlowDistanceQuality); 94 else { 95 if (Content == null || Content.FlowDistanceQuality == null) { 96 flowDistanceQualityLabel.Text = "-"; 97 } else { 98 flowDistanceQualityLabel.Text = Content.FlowDistanceQuality.ToString(); 97 99 } 98 } finally { assignmentTreeView.EndUpdate(); } 100 } 101 } 102 103 private void UpdateInstallationQuality() { 104 if (InvokeRequired) Invoke((Action)UpdateInstallationQuality); 105 else { 106 if (Content == null || Content.InstallationQuality == null) { 107 installationQualityLabel.Text = "-"; 108 } else { 109 installationQualityLabel.Text = Content.InstallationQuality.ToString(); 110 } 111 } 112 } 113 114 private void UpdateOverbookedCapacity() { 115 if (InvokeRequired) Invoke((Action)UpdateOverbookedCapacity); 116 else { 117 if (Content == null || Content.OverbookedCapacity == null) { 118 overbookedCapacityLabel.Text = "-"; 119 } else { 120 overbookedCapacityLabel.Text = Content.OverbookedCapacity.ToString(); 121 } 122 } 123 } 124 125 private void UpdateAssignment() { 126 if (InvokeRequired) Invoke((Action)UpdateAssignment); 127 else { 128 assignmentTreeView.Nodes.Clear(); 129 if (Content != null) { 130 IntegerVector assignment = Content.Assignment; 131 Dictionary<int, TreeNode> locationNodes = new Dictionary<int, TreeNode>(); 132 for (int i = 0; i < assignment.Length; i++) { 133 if (!locationNodes.ContainsKey(assignment[i])) { 134 string locationName = assignment[i].ToString(); 135 if (Content.LocationNames != null && Content.LocationNames.Length > assignment[i]) 136 locationName = Content.LocationNames[assignment[i]]; 137 locationNodes.Add(assignment[i], new TreeNode(locationName)); 138 } 139 string equipmentName = i.ToString(); 140 if (Content.EquipmentNames != null && Content.EquipmentNames.Length > i) 141 equipmentName = Content.EquipmentNames[i]; 142 locationNodes[assignment[i]].Nodes.Add(equipmentName); 143 } 144 145 assignmentTreeView.BeginUpdate(); 146 try { 147 foreach (var node in locationNodes.OrderBy(x => x.Key).Select(x => x.Value)) { 148 assignmentTreeView.Nodes.Add(node); 149 node.Expand(); 150 } 151 } finally { assignmentTreeView.EndUpdate(); } 152 } 153 } 99 154 } 100 155 }
Note: See TracChangeset
for help on using the changeset viewer.