[7966] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[7966] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Drawing;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Common;
|
---|
| 27 | using HeuristicLab.Common.Resources;
|
---|
| 28 | using HeuristicLab.Core;
|
---|
| 29 | using HeuristicLab.MainForm;
|
---|
| 30 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.DebugEngine {
|
---|
| 33 |
|
---|
| 34 | [View("Operation Content View")]
|
---|
| 35 | [Content(typeof(OperationContent), IsDefaultView = true)]
|
---|
| 36 | public partial class OperationContentView : AsynchronousContentView {
|
---|
| 37 | public new OperationContent Content {
|
---|
| 38 | get { return (OperationContent)base.Content; }
|
---|
| 39 | set { base.Content = value; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public OperationContentView() {
|
---|
| 43 | InitializeComponent();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | protected override void OnContentChanged() {
|
---|
| 47 | base.OnContentChanged();
|
---|
| 48 | if (Content == null) {
|
---|
| 49 | nameTextBox.Text = "";
|
---|
| 50 | scopeTreeView.Nodes.Clear();
|
---|
| 51 | executionContextTreeView.Nodes.Clear();
|
---|
| 52 | iconBox.Image = null;
|
---|
| 53 | } else {
|
---|
| 54 | nameTextBox.Text = Content.Name;
|
---|
| 55 | UpdateScopeTree();
|
---|
| 56 | UpdateExecutionContext();
|
---|
| 57 | iconBox.Image = Content.Icon;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | private object GetParameterValue(IParameter param, IExecutionContext context, out string actualName) {
|
---|
| 62 | param = (IParameter)param.Clone();
|
---|
[9195] | 63 | ILookupParameter lookupParam = param as ILookupParameter;
|
---|
| 64 | if (lookupParam != null) {
|
---|
| 65 | actualName = lookupParam.ActualName;
|
---|
| 66 | lookupParam.ExecutionContext = context;
|
---|
| 67 | } else
|
---|
| 68 | actualName = null;
|
---|
| 69 |
|
---|
[7966] | 70 | object value = null;
|
---|
| 71 | try {
|
---|
| 72 | value = param.ActualValue;
|
---|
[9195] | 73 | }
|
---|
| 74 | catch (Exception x) {
|
---|
[7966] | 75 | value = x.Message;
|
---|
| 76 | }
|
---|
| 77 | return value;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | private void UpdateScopeTree() {
|
---|
| 81 | scopeTreeView.BeginUpdate();
|
---|
| 82 | scopeTreeView.Nodes.Clear();
|
---|
| 83 | scopeTreeView.ImageList.Images.Clear();
|
---|
| 84 | scopeTreeView.ImageList.Images.Add(VSImageLibrary.Namespace);
|
---|
| 85 | scopeTreeView.ImageList.Images.Add(VSImageLibrary.Field);
|
---|
| 86 | if (Content.IsContext) {
|
---|
| 87 | var scope = Content.ExecutionContext.Scope;
|
---|
| 88 | while (scope != null && scope.Parent != null)
|
---|
| 89 | scope = scope.Parent;
|
---|
| 90 | if (scope != null)
|
---|
| 91 | AddScope(scopeTreeView.Nodes, scope);
|
---|
| 92 | }
|
---|
| 93 | scopeTreeView.EndUpdate();
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | private void AddScope(TreeNodeCollection nodes, IScope scope) {
|
---|
| 97 | TreeNode node = nodes.Add(string.Format("{0} ({1}+{2})",
|
---|
| 98 | scope.Name, scope.Variables.Count, scope.SubScopes.Count));
|
---|
| 99 | node.Tag = scope;
|
---|
| 100 | node.ImageIndex = 0;
|
---|
| 101 | node.SelectedImageIndex = 0;
|
---|
| 102 | foreach (var var in scope.Variables) {
|
---|
| 103 | TreeNode varNode = node.Nodes.Add(string.Format("{0} = {1}", var.Name, var.Value));
|
---|
| 104 | varNode.Tag = var.Value;
|
---|
| 105 | varNode.ToolTipText = string.Format("{0}{1}{1}{2}",
|
---|
| 106 | Utils.TypeName(var.Value), Environment.NewLine,
|
---|
| 107 | Utils.Wrap(var.Description ?? var.ItemDescription, 60));
|
---|
| 108 | varNode.ImageIndex = 1;
|
---|
| 109 | varNode.SelectedImageIndex = 1;
|
---|
| 110 | }
|
---|
| 111 | foreach (var subScope in scope.SubScopes)
|
---|
| 112 | AddScope(node.Nodes, subScope);
|
---|
| 113 | if (Content.IsAtomic && Content.AtomicOperation.Scope == scope) {
|
---|
| 114 | node.NodeFont = new Font(DefaultFont, FontStyle.Bold);
|
---|
| 115 | node.ForeColor = Color.White;
|
---|
| 116 | node.BackColor = Color.Crimson;
|
---|
| 117 | node.Expand();
|
---|
| 118 | scopeTreeView.TopNode = node;
|
---|
| 119 | node.ToolTipText = "Current scope of active operation";
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 | private void UpdateExecutionContext() {
|
---|
| 125 | executionContextTreeView.BeginUpdate();
|
---|
| 126 | executionContextTreeView.Nodes.Clear();
|
---|
| 127 | executionContextTreeView.ImageList.Images.Clear();
|
---|
| 128 | executionContextTreeView.ImageList.Images.Add(VSImageLibrary.Namespace);
|
---|
| 129 | if (Content.IsContext) {
|
---|
| 130 | AddExecutionContext(Content.ExecutionContext, executionContextTreeView.Nodes);
|
---|
| 131 | }
|
---|
| 132 | executionContextTreeView.ExpandAll();
|
---|
| 133 | if (executionContextTreeView.Nodes.Count > 0)
|
---|
| 134 | executionContextTreeView.TopNode = executionContextTreeView.Nodes[0];
|
---|
| 135 | executionContextTreeView.EndUpdate();
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | private void AddExecutionContext(IExecutionContext executionContext, TreeNodeCollection nodes) {
|
---|
| 139 | ExecutionContext context = executionContext as ExecutionContext;
|
---|
| 140 | StringBuilder name = new StringBuilder();
|
---|
| 141 | if (context != null && context.Operator != null)
|
---|
| 142 | name.Append(context.Operator.Name);
|
---|
| 143 | else
|
---|
| 144 | name.Append("<Context>");
|
---|
| 145 | name.Append("@").Append(executionContext.Scope.Name);
|
---|
| 146 | TreeNode node = nodes.Add(name.ToString());
|
---|
| 147 | node.Tag = executionContext;
|
---|
| 148 | node.ImageIndex = 0;
|
---|
| 149 | node.SelectedImageIndex = 0;
|
---|
| 150 | foreach (var param in executionContext.Parameters) {
|
---|
| 151 | string actualName = null;
|
---|
| 152 | object value = GetParameterValue(param, executionContext, out actualName);
|
---|
| 153 | if (value == null)
|
---|
| 154 | value = "null";
|
---|
| 155 | string label = actualName != null && actualName != param.Name ?
|
---|
| 156 | string.Format("{0} ({1}) = {2}", param.Name, actualName, value) :
|
---|
| 157 | string.Format("{0} = {1}", param.Name, value);
|
---|
| 158 | TreeNode paramNode = node.Nodes.Add(label);
|
---|
| 159 | paramNode.Tag = param;
|
---|
| 160 | executionContextTreeView.ImageList.Images.Add(param.ItemImage ?? VSImageLibrary.Nothing);
|
---|
| 161 | paramNode.ImageIndex = executionContextTreeView.ImageList.Images.Count - 1;
|
---|
| 162 | paramNode.SelectedImageIndex = paramNode.ImageIndex;
|
---|
| 163 | paramNode.ToolTipText = string.Format("{0}{1}{1}{2}",
|
---|
| 164 | Utils.TypeName(param), Environment.NewLine,
|
---|
| 165 | Utils.Wrap(param.Description ?? param.ItemDescription, 60));
|
---|
| 166 | }
|
---|
| 167 | if (executionContext.Parent != null)
|
---|
| 168 | AddExecutionContext(executionContext.Parent, node.Nodes);
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | #region Event Handlers (child controls)
|
---|
| 172 |
|
---|
| 173 | private void executionContextTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
|
---|
| 174 | if (e.Node != null) {
|
---|
| 175 | IParameter param = e.Node.Tag as IParameter;
|
---|
| 176 | if (param != null)
|
---|
| 177 | MainFormManager.MainForm.ShowContent(param);
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | private void scopeTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
|
---|
| 182 | if (e.Node != null) {
|
---|
| 183 | IItem item = e.Node.Tag as IItem;
|
---|
| 184 | if (item != null)
|
---|
| 185 | MainFormManager.MainForm.ShowContent(item);
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | private TreeNode selectedScopeNode = null;
|
---|
| 190 | private void executionContextTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
|
---|
| 191 | scopeTreeView.BeginUpdate();
|
---|
| 192 | if (selectedScopeNode != null) {
|
---|
| 193 | if (Content.IsAtomic && Content.AtomicOperation.Scope == selectedScopeNode.Tag) {
|
---|
| 194 | selectedScopeNode.BackColor = Color.Crimson;
|
---|
| 195 | selectedScopeNode.ForeColor = Color.White;
|
---|
| 196 | selectedScopeNode.NodeFont = new Font(DefaultFont, FontStyle.Bold);
|
---|
| 197 | } else {
|
---|
| 198 | selectedScopeNode.BackColor = Color.White;
|
---|
| 199 | selectedScopeNode.ForeColor = Color.Black;
|
---|
| 200 | selectedScopeNode.NodeFont = DefaultFont;
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 | if (e.Node != null) {
|
---|
| 204 | IExecutionContext context = e.Node.Tag as IExecutionContext;
|
---|
| 205 | if (context != null && context.Scope != null) {
|
---|
| 206 | TreeNode scopeNode = FindScopeNode(context.Scope, scopeTreeView.Nodes);
|
---|
| 207 | if (scopeNode != null) {
|
---|
| 208 | if (Content.IsAtomic && Content.AtomicOperation.Scope == scopeNode.Tag) {
|
---|
| 209 | scopeNode.BackColor = Color.DarkViolet;
|
---|
| 210 | scopeNode.ForeColor = Color.White;
|
---|
| 211 | scopeNode.NodeFont = new Font(DefaultFont, FontStyle.Bold);
|
---|
| 212 | } else {
|
---|
| 213 | scopeNode.BackColor = Color.Blue;
|
---|
| 214 | scopeNode.ForeColor = Color.White;
|
---|
| 215 | scopeNode.NodeFont = new Font(DefaultFont, FontStyle.Bold);
|
---|
| 216 | }
|
---|
| 217 | selectedScopeNode = scopeNode;
|
---|
| 218 | scopeTreeView.TopNode = scopeNode;
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 | }
|
---|
| 222 | scopeTreeView.EndUpdate();
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | private TreeNode FindScopeNode(IScope scope, TreeNodeCollection nodes) {
|
---|
| 226 | foreach (TreeNode node in nodes) {
|
---|
| 227 | if (node.Tag == scope) {
|
---|
| 228 | return node;
|
---|
| 229 | } else {
|
---|
| 230 | TreeNode childNode = FindScopeNode(scope, node.Nodes);
|
---|
| 231 | if (childNode != null)
|
---|
| 232 | return childNode;
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
| 235 | return null;
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | private void nameTextBox_DoubleClick(object sender, EventArgs e) {
|
---|
| 239 | if (Content != null && Content.IsAtomic && Content.AtomicOperation.Operator != null)
|
---|
| 240 | MainFormManager.MainForm.ShowContent(Content.AtomicOperation.Operator);
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | private void ShowValue_Click(object sender, EventArgs e) {
|
---|
| 244 | if (executionContextTreeView.SelectedNode == null)
|
---|
| 245 | return;
|
---|
| 246 | IParameter param = executionContextTreeView.SelectedNode.Tag as IParameter;
|
---|
| 247 | if (param != null) {
|
---|
| 248 | string actualName = null;
|
---|
| 249 | IExecutionContext context = executionContextTreeView.SelectedNode.Parent.Tag as IExecutionContext ?? Content.ExecutionContext;
|
---|
| 250 | MainFormManager.MainForm.ShowContent(GetParameterValue(param, context, out actualName) as IContent);
|
---|
| 251 | }
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | private void executionContextConextMenu_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
| 255 | IParameter param = executionContextTreeView.SelectedNode.Tag as IParameter;
|
---|
| 256 | if (param != null) {
|
---|
| 257 | string actualName = null;
|
---|
| 258 | IExecutionContext context = executionContextTreeView.SelectedNode.Parent.Tag as IExecutionContext ?? Content.ExecutionContext;
|
---|
| 259 | showValueToolStripMenuItem.Enabled = GetParameterValue(param, context, out actualName) is IContent;
|
---|
| 260 | } else
|
---|
| 261 | e.Cancel = true;
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | private void executionContextTreeView_MouseDown(object sender, MouseEventArgs e) {
|
---|
| 265 | if (e.Button == System.Windows.Forms.MouseButtons.Right)
|
---|
| 266 | executionContextTreeView.SelectedNode = executionContextTreeView.GetNodeAt(e.Location);
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | #endregion
|
---|
| 270 |
|
---|
| 271 | }
|
---|
| 272 | }
|
---|