Changeset 7784
- Timestamp:
- 05/08/12 10:10:14 (13 years ago)
- Location:
- branches/HeuristicLab.TreeSimplifierView
- Files:
-
- 218 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4.csproj
r7388 r7784 159 159 </ItemGroup> 160 160 <ItemGroup> 161 <Compile Include="InteractiveSymbolicExpressionTreeChart.cs"> 162 <SubType>UserControl</SubType> 163 </Compile> 164 <Compile Include="InteractiveSymbolicExpressionTreeChart.Designer.cs"> 165 <DependentUpon>InteractiveSymbolicExpressionTreeChart.cs</DependentUpon> 166 </Compile> 161 167 <Compile Include="Plugin.cs" /> 162 168 <Compile Include="SymbolicExpressionGrammarAllowedChildSymbolsControl.cs"> … … 183 189 <Compile Include="SymbolicExpressionGrammarView.Designer.cs"> 184 190 <DependentUpon>SymbolicExpressionGrammarView.cs</DependentUpon> 191 </Compile> 192 <Compile Include="SymbolicExpressionTreeNodeChangeValueDialog.cs"> 193 <SubType>Form</SubType> 194 </Compile> 195 <Compile Include="SymbolicExpressionTreeNodeChangeValueDialog.Designer.cs"> 196 <DependentUpon>SymbolicExpressionTreeNodeChangeValueDialog.cs</DependentUpon> 197 </Compile> 198 <Compile Include="SymbolicExpressionTreeNodeInsertDialog.cs"> 199 <SubType>Form</SubType> 200 </Compile> 201 <Compile Include="SymbolicExpressionTreeNodeInsertDialog.Designer.cs"> 202 <DependentUpon>SymbolicExpressionTreeNodeInsertDialog.cs</DependentUpon> 185 203 </Compile> 186 204 <Compile Include="SymbolView.cs"> … … 233 251 <Install>true</Install> 234 252 </BootstrapperPackage> 253 </ItemGroup> 254 <ItemGroup> 255 <EmbeddedResource Include="InteractiveSymbolicExpressionTreeChart.resx"> 256 <DependentUpon>InteractiveSymbolicExpressionTreeChart.cs</DependentUpon> 257 </EmbeddedResource> 258 <EmbeddedResource Include="SymbolicExpressionTreeChart.resx"> 259 <DependentUpon>SymbolicExpressionTreeChart.cs</DependentUpon> 260 </EmbeddedResource> 261 <EmbeddedResource Include="SymbolicExpressionTreeNodeChangeValueDialog.resx"> 262 <DependentUpon>SymbolicExpressionTreeNodeChangeValueDialog.cs</DependentUpon> 263 </EmbeddedResource> 264 <EmbeddedResource Include="SymbolicExpressionTreeNodeInsertDialog.resx"> 265 <DependentUpon>SymbolicExpressionTreeNodeInsertDialog.cs</DependentUpon> 266 </EmbeddedResource> 235 267 </ItemGroup> 236 268 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolView.cs
r7259 r7784 29 29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views { 30 30 [View("Symbol View")] 31 [Content(typeof(ISymbol), false)]31 [Content(typeof(ISymbol), true)] 32 32 public partial class SymbolView : NamedItemView { 33 33 public new ISymbol Content { -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.Designer.cs
r7148 r7784 170 170 this.symbolsTreeView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.symbolsTreeView_KeyDown); 171 171 this.symbolsTreeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.symbolsTreeView_MouseDown); 172 this.symbolsTreeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(symbolsTreeView_NodeMouseDoubleClick); 172 173 // 173 174 // imageList -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.cs
r7259 r7784 62 62 copyButton.Enabled = false; 63 63 treeViewBackColor = symbolsTreeView.BackColor; 64 symbolsTreeView.BackColor = Color.FromArgb(255, 240,240,240);64 symbolsTreeView.BackColor = Color.FromArgb(255, 240, 240, 240); 65 65 } else { 66 66 addButton.Enabled = true; … … 125 125 #endregion 126 126 127 private bool internalTreeViewUpdateInProgress = false;128 127 private void UpdateSymbolsTreeView() { 129 internalTreeViewUpdateInProgress = true;130 128 var symbols = Content.Symbols.ToList(); 131 129 foreach (var treeNode in IterateTreeNodes().ToList()) { … … 140 138 141 139 RebuildImageList(); 142 internalTreeViewUpdateInProgress = false;143 140 } 144 141 … … 181 178 182 179 private void symbolsTreeView_BeforeCheck(object sender, TreeViewCancelEventArgs e) { 183 if (internalTreeViewUpdateInProgress) return;184 180 if (Content == null || Content.ReadOnly) e.Cancel = true; 185 181 if (ReadOnly || Locked) e.Cancel = true; … … 187 183 188 184 #region drag & drop operations 189 private GroupSymbol parentOfDraggedSymbol;190 185 private void symbolsTreeView_ItemDrag(object sender, ItemDragEventArgs e) { 191 186 if (!Locked) { 192 187 var treeNode = e.Item as TreeNode; 193 if (treeNode.Parent != null) parentOfDraggedSymbol = treeNode.Parent.Tag as GroupSymbol;194 188 var data = new DataObject(); 195 189 data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, treeNode.Tag); … … 257 251 } 258 252 253 private void symbolsTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { 254 var symbol = e.Node.Tag as ISymbol; 255 if (symbol == null) return; 256 if (e.Button != MouseButtons.Left) return; 257 if (e.X < e.Node.Bounds.Left - symbolsTreeView.ImageList.Images[e.Node.ImageIndex].Width || e.X > e.Node.Bounds.Right) return; 258 MainFormManager.MainForm.ShowContent(symbol); 259 e.Node.Toggle(); 260 } 261 259 262 private void symbolsTreeView_KeyDown(object sender, KeyEventArgs e) { 260 263 if (Content == null || Content.ReadOnly || ReadOnly || Locked) return; … … 424 427 425 428 //this class is necessary to prevent double clicks which do not fire the checkbox checked event 429 //workaround taken from http://connect.microsoft.com/VisualStudio/feedback/details/374516/treeview-control-does-not-fire-events-reliably-when-double-clicking-on-checkbox 426 430 internal class CheckBoxTreeView : TreeView { 427 431 protected override void WndProc(ref Message m) { 428 432 // Suppress WM_LBUTTONDBLCLK 429 if (m.Msg == 0x203) { m.Result = IntPtr.Zero; } else base.WndProc(ref m); 433 if (m.Msg == 0x203 && IsOnCheckBox(m)) { m.Result = IntPtr.Zero; } else base.WndProc(ref m); 434 } 435 436 private int GetXLParam(IntPtr lParam) { 437 return lParam.ToInt32() & 0xffff; 438 } 439 440 private int GetYLParam(IntPtr lParam) { 441 return lParam.ToInt32() >> 16; 442 } 443 444 private bool IsOnCheckBox(Message m) { 445 int x = GetXLParam(m.LParam); 446 int y = GetYLParam(m.LParam); 447 TreeNode node = this.GetNodeAt(x, y); 448 return ((x <= node.Bounds.Left - 20) && (x >= node.Bounds.Left - 32)); 430 449 } 431 450 } -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.Designer.cs
r7372 r7784 20 20 #endregion 21 21 22 using System;23 using System.Windows.Forms;24 using HeuristicLab.Common;25 22 26 23 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views { … … 53 50 this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); 54 51 this.saveImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 55 this.changeValueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();56 52 this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); 57 53 this.contextMenuStrip.SuspendLayout(); … … 61 57 // 62 58 this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 63 this.saveImageToolStripMenuItem, 64 this.changeValueToolStripMenuItem}); 59 this.saveImageToolStripMenuItem}); 65 60 this.contextMenuStrip.Name = "contextMenuStrip"; 66 this.contextMenuStrip.Size = new System.Drawing.Size(153, 70); 67 this.contextMenuStrip.Opened += new System.EventHandler(this.contextMenuStrip_Opened); 61 this.contextMenuStrip.Size = new System.Drawing.Size(153, 48); 68 62 // 69 63 // saveImageToolStripMenuItem … … 73 67 this.saveImageToolStripMenuItem.Text = "Save Image"; 74 68 this.saveImageToolStripMenuItem.Click += new System.EventHandler(this.saveImageToolStripMenuItem_Click); 75 //76 // changeValueToolStripMenuItem77 //78 this.changeValueToolStripMenuItem.Enabled = false;79 this.changeValueToolStripMenuItem.Name = "changeValueToolStripMenuItem";80 this.changeValueToolStripMenuItem.Size = new System.Drawing.Size(152, 22);81 this.changeValueToolStripMenuItem.Text = "Change Value";82 this.changeValueToolStripMenuItem.Click += new System.EventHandler(this.changeValueToolStripMenuItem_Click);83 69 // 84 70 // saveFileDialog … … 105 91 106 92 private System.Windows.Forms.ToolTip toolTip; 107 private System.Windows.Forms.ContextMenuStrip contextMenuStrip;108 93 private System.Windows.Forms.ToolStripMenuItem saveImageToolStripMenuItem; 109 94 private System.Windows.Forms.SaveFileDialog saveFileDialog; 110 private System.Windows.Forms.ToolStripMenuItem changeValueToolStripMenuItem;95 internal System.Windows.Forms.ContextMenuStrip contextMenuStrip; 111 96 } 112 97 } -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r7411 r7784 27 27 28 28 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views { 29 public sealedpartial class SymbolicExpressionTreeChart : UserControl {29 public partial class SymbolicExpressionTreeChart : UserControl { 30 30 private Image image; 31 31 private StringFormat stringFormat; 32 private Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes; 33 private Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection> visualLines; 34 private VisualSymbolicExpressionTreeNode selectedNode; 32 protected Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes; 33 protected Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection> visualLines; 35 34 36 35 public SymbolicExpressionTreeChart() { … … 44 43 this.backgroundColor = Color.White; 45 44 this.textFont = new Font("Times New Roman", 8); 46 selectedNode = null;47 45 } 48 46 … … 158 156 159 157 #region events 160 public event EventHandler SymbolicExpressionTreeNodeChanged;161 private void OnSymbolicExpressionTreeNodeChanged(object sender, EventArgs e) {162 var changed = SymbolicExpressionTreeNodeChanged;163 if (changed != null) {164 changed(sender, e);165 }166 }167 168 158 public event MouseEventHandler SymbolicExpressionTreeNodeClicked; 169 pr ivatevoid OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {159 protected void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) { 170 160 var clicked = SymbolicExpressionTreeNodeClicked; 171 161 if (clicked != null) … … 173 163 } 174 164 175 pr ivatevoid SymbolicExpressionTreeChart_MouseClick(object sender, MouseEventArgs e) {165 protected virtual void SymbolicExpressionTreeChart_MouseClick(object sender, MouseEventArgs e) { 176 166 VisualSymbolicExpressionTreeNode visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y); 177 if (visualTreeNode != null) 167 if (visualTreeNode != null) { 178 168 OnSymbolicExpressionTreeNodeClicked(visualTreeNode, e); 169 } 179 170 } 180 171 181 172 public event MouseEventHandler SymbolicExpressionTreeNodeDoubleClicked; 182 pr ivatevoid OnSymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) {173 protected void OnSymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) { 183 174 var doubleClicked = SymbolicExpressionTreeNodeDoubleClicked; 184 175 if (doubleClicked != null) … … 193 184 194 185 public event ItemDragEventHandler SymbolicExpressionTreeNodeDrag; 195 pr ivatevoid OnSymbolicExpressionTreeNodeDragDrag(object sender, ItemDragEventArgs e) {186 protected void OnSymbolicExpressionTreeNodeDragDrag(object sender, ItemDragEventArgs e) { 196 187 var dragged = SymbolicExpressionTreeNodeDrag; 197 188 if (dragged != null) … … 244 235 /// 245 236 /// </summary> 246 /// <param name="functionTree"> function tree to draw</param>237 /// <param name="functionTree"> function tree to draw</param> 247 238 /// <param name="graphics">graphics object to draw on</param> 248 239 /// <param name="x">x coordinate of drawing area</param> … … 357 348 } 358 349 #endregion 359 360 private void contextMenuStrip_Opened(object sender, EventArgs e) {361 var menu = sender as ContextMenuStrip;362 if (menu == null) return;363 var point = menu.SourceControl.PointToClient(Cursor.Position);364 selectedNode = FindVisualSymbolicExpressionTreeNodeAt(point.X, point.Y);365 if (selectedNode != null) {366 OnSymbolicExpressionTreeNodeClicked(selectedNode, new MouseEventArgs(MouseButtons.Right, 1, point.X, point.Y, 0));367 }368 }369 370 private void changeValueToolStripMenuItem_Click(object sender, EventArgs e) {371 if (selectedNode != null) // this should never be null anyway372 OnSymbolicExpressionTreeNodeChanged(selectedNode, e);373 }374 350 } 375 351 } -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.sln
r7365 r7784 11 11 EndProject 12 12 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4", "HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4.csproj", "{423BD94F-963A-438E-BA45-3BB3D61CD03B}" 13 EndProject 14 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.DataAnalysis.Symbolic-3.4", "HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj", "{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}" 15 EndProject 16 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4", "HeuristicLab.Problems.DataAnalysis.Symbolic.Classification\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj", "{05BAE4E1-A9FA-4644-AA77-42558720159E}" 17 EndProject 18 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4", "HeuristicLab.Problems.DataAnalysis.Symbolic.Regression\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj", "{5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}" 13 19 EndProject 14 20 Global … … 46 52 {423BD94F-963A-438E-BA45-3BB3D61CD03B}.Release|x86.ActiveCfg = Release|x86 47 53 {423BD94F-963A-438E-BA45-3BB3D61CD03B}.Release|x86.Build.0 = Release|x86 54 {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Debug|x64.ActiveCfg = Debug|x64 57 {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Debug|x64.Build.0 = Debug|x64 58 {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Debug|x86.ActiveCfg = Debug|x86 59 {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Debug|x86.Build.0 = Debug|x86 60 {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Release|Any CPU.ActiveCfg = Release|Any CPU 61 {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Release|Any CPU.Build.0 = Release|Any CPU 62 {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Release|x64.ActiveCfg = Release|x64 63 {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Release|x64.Build.0 = Release|x64 64 {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Release|x86.ActiveCfg = Release|x86 65 {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Release|x86.Build.0 = Release|x86 66 {05BAE4E1-A9FA-4644-AA77-42558720159E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 67 {05BAE4E1-A9FA-4644-AA77-42558720159E}.Debug|Any CPU.Build.0 = Debug|Any CPU 68 {05BAE4E1-A9FA-4644-AA77-42558720159E}.Debug|x64.ActiveCfg = Debug|x64 69 {05BAE4E1-A9FA-4644-AA77-42558720159E}.Debug|x64.Build.0 = Debug|x64 70 {05BAE4E1-A9FA-4644-AA77-42558720159E}.Debug|x86.ActiveCfg = Debug|x86 71 {05BAE4E1-A9FA-4644-AA77-42558720159E}.Debug|x86.Build.0 = Debug|x86 72 {05BAE4E1-A9FA-4644-AA77-42558720159E}.Release|Any CPU.ActiveCfg = Release|Any CPU 73 {05BAE4E1-A9FA-4644-AA77-42558720159E}.Release|Any CPU.Build.0 = Release|Any CPU 74 {05BAE4E1-A9FA-4644-AA77-42558720159E}.Release|x64.ActiveCfg = Release|x64 75 {05BAE4E1-A9FA-4644-AA77-42558720159E}.Release|x64.Build.0 = Release|x64 76 {05BAE4E1-A9FA-4644-AA77-42558720159E}.Release|x86.ActiveCfg = Release|x86 77 {05BAE4E1-A9FA-4644-AA77-42558720159E}.Release|x86.Build.0 = Release|x86 78 {5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 79 {5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}.Debug|Any CPU.Build.0 = Debug|Any CPU 80 {5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}.Debug|x64.ActiveCfg = Debug|x64 81 {5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}.Debug|x64.Build.0 = Debug|x64 82 {5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}.Debug|x86.ActiveCfg = Debug|x86 83 {5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}.Debug|x86.Build.0 = Debug|x86 84 {5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}.Release|Any CPU.ActiveCfg = Release|Any CPU 85 {5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}.Release|Any CPU.Build.0 = Release|Any CPU 86 {5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}.Release|x64.ActiveCfg = Release|x64 87 {5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}.Release|x64.Build.0 = Release|x64 88 {5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}.Release|x86.ActiveCfg = Release|x86 89 {5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}.Release|x86.Build.0 = Release|x86 48 90 EndGlobalSection 49 91 GlobalSection(SolutionProperties) = preSolution -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj
r7422 r7784 135 135 <ItemGroup> 136 136 <Compile Include="Plugin.cs" /> 137 <Compile Include="SymbolicExpressionTreeNodeChangeValueDialog.cs">138 <SubType>Form</SubType>139 </Compile>140 <Compile Include="SymbolicExpressionTreeNodeChangeValueDialog.designer.cs">141 <DependentUpon>SymbolicExpressionTreeNodeChangeValueDialog.cs</DependentUpon>142 </Compile>143 137 <Compile Include="TextualSymbolicDataAnalysisModelView.cs"> 144 138 <SubType>UserControl</SubType> … … 216 210 <Install>true</Install> 217 211 </BootstrapperPackage> 212 </ItemGroup> 213 <ItemGroup> 214 <EmbeddedResource Include="InteractiveSymbolicDataAnalysisSolutionSimplifierView.resx"> 215 <DependentUpon>InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs</DependentUpon> 216 </EmbeddedResource> 218 217 </ItemGroup> 219 218 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.Designer.cs
r7411 r7784 50 50 this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); 51 51 this.btnSimplify = new System.Windows.Forms.Button(); 52 this.btnPrune = new System.Windows.Forms.Button(); 52 53 this.btnOptimizeConstants = new System.Windows.Forms.Button(); 53 this.treeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views. SymbolicExpressionTreeChart();54 this.treeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.InteractiveSymbolicExpressionTreeChart(); 54 55 this.grpViewHost = new System.Windows.Forms.GroupBox(); 55 this.btnPrune = new System.Windows.Forms.Button();56 56 this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); 57 57 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); … … 133 133 this.btnSimplify.Click += new System.EventHandler(this.btnSimplify_Click); 134 134 // 135 // btnPrune 136 // 137 this.btnPrune.Location = new System.Drawing.Point(104, 3); 138 this.btnPrune.Name = "btnPrune"; 139 this.btnPrune.Size = new System.Drawing.Size(95, 23); 140 this.btnPrune.TabIndex = 3; 141 this.btnPrune.Text = "Prune"; 142 this.btnPrune.UseVisualStyleBackColor = true; 143 this.btnPrune.Click += new System.EventHandler(this.btnPrune_Click); 144 // 135 145 // btnOptimizeConstants 136 146 // … … 160 170 this.treeChart.TextFont = new System.Drawing.Font("Times New Roman", 8F); 161 171 this.treeChart.Tree = null; 172 this.treeChart.SymbolicExpressionTreeChanged += new System.EventHandler(this.treeChart_SymbolicExpressionTreeChanged); 162 173 this.treeChart.SymbolicExpressionTreeNodeChanged += new System.EventHandler(this.treeChart_SymbolicExpressionTreeNodeChanged); 174 this.treeChart.SymbolicExpressionTreeNodeInserted += new System.EventHandler(this.treeChart_SymbolicExpressionTreeNodeInserted); 163 175 this.treeChart.SymbolicExpressionTreeNodeClicked += new System.Windows.Forms.MouseEventHandler(this.treeChart_SymbolicExpressionTreeNodeClicked); 164 176 this.treeChart.SymbolicExpressionTreeNodeDoubleClicked += new System.Windows.Forms.MouseEventHandler(this.treeChart_SymbolicExpressionTreeNodeDoubleClicked); … … 174 186 this.grpViewHost.TabStop = false; 175 187 this.grpViewHost.Text = "Details"; 176 //177 // btnPrune178 //179 this.btnPrune.Location = new System.Drawing.Point(104, 3);180 this.btnPrune.Name = "btnPrune";181 this.btnPrune.Size = new System.Drawing.Size(95, 23);182 this.btnPrune.TabIndex = 3;183 this.btnPrune.Text = "Prune";184 this.btnPrune.UseVisualStyleBackColor = true;185 this.btnPrune.Click += new System.EventHandler(this.btnPrune_Click);186 188 // 187 189 // backgroundWorker1 … … 212 214 #endregion 213 215 214 private HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views. SymbolicExpressionTreeChart treeChart;216 private HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.InteractiveSymbolicExpressionTreeChart treeChart; 215 217 private System.Windows.Forms.SplitContainer splitContainer; 216 218 private HeuristicLab.MainForm.WindowsForms.ViewHost viewHost; -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r7422 r7784 27 27 using System.Windows.Forms; 28 28 using HeuristicLab.Common; 29 using HeuristicLab.Data; 29 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views; … … 36 37 private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts; 37 38 private Dictionary<ISymbolicExpressionTreeNode, double> originalValues; 39 private Dictionary<ISymbolicExpressionTreeNode, string> originalVariableNames; 38 40 private bool updateInProgress = false; 39 private VisualSymbolicExpressionTreeNode visualTreeNode; // for correctly handling events when changing node values40 41 private ISymbolicExpressionTree model; 41 42 … … 45 46 this.nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>(); 46 47 this.originalValues = new Dictionary<ISymbolicExpressionTreeNode, double>(); 48 this.originalVariableNames = new Dictionary<ISymbolicExpressionTreeNode, string>(); 47 49 this.Caption = "Interactive Solution Simplifier"; 48 50 } … … 96 98 private void CalculateReplacementNodesAndNodeImpacts() { 97 99 if (Content == null || Content.Model == null || Content.ProblemData == null) return; 98 //var tree = Content.Model.SymbolicExpressionTree;99 100 var tree = model; 100 101 var replacementValues = CalculateReplacementValues(tree); … … 161 162 162 163 private void treeChart_SymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) { 163 visualTreeNode = (VisualSymbolicExpressionTreeNode)sender; 164 var visualNode = (VisualSymbolicExpressionTreeNode)sender; 165 var symbExprTreeNode = (SymbolicExpressionTreeNode)visualNode.SymbolicExpressionTreeNode; 166 if (symbExprTreeNode == null) return; 164 167 var tree = model; 165 168 // check if the node value/weight has been altered 166 // if so, the first double click will return the node to its original value/weight 169 // if so, the first double click will return the node to its original value/weight/variable name 167 170 // the next double click will replace the ConstantNode with the original SymbolicExpressionTreeNode 168 if (originalValues.ContainsKey(visualTreeNode.SymbolicExpressionTreeNode)) { 169 double value = originalValues[visualTreeNode.SymbolicExpressionTreeNode]; 170 var subTree = visualTreeNode.SymbolicExpressionTreeNode; 171 if (subTree.Symbol is Constant) 172 (subTree as ConstantTreeNode).Value = value; 173 else if (subTree.Symbol is Variable) 174 (subTree as VariableTreeNode).Weight = value; 175 originalValues.Remove(subTree); 171 if (originalVariableNames.ContainsKey(symbExprTreeNode)) { 172 var variable = (VariableTreeNode)symbExprTreeNode; 173 variable.VariableName = originalVariableNames[symbExprTreeNode]; 174 originalVariableNames.Remove(variable); 176 175 updateInProgress = true; 177 176 UpdateModel(tree); … … 179 178 return; 180 179 } 181 180 if (originalValues.ContainsKey(symbExprTreeNode)) { 181 double value = originalValues[symbExprTreeNode]; 182 if (symbExprTreeNode.Symbol is Constant) 183 ((ConstantTreeNode)symbExprTreeNode).Value = value; 184 else if (symbExprTreeNode.Symbol is Variable) 185 ((VariableTreeNode)symbExprTreeNode).Weight = value; 186 originalValues.Remove(symbExprTreeNode); 187 updateInProgress = true; 188 UpdateModel(tree); 189 updateInProgress = false; 190 return; 191 } 182 192 foreach (SymbolicExpressionTreeNode treeNode in tree.IterateNodesPostfix()) { 183 193 for (int i = 0; i < treeNode.SubtreeCount; i++) { 184 194 ISymbolicExpressionTreeNode subTree = treeNode.GetSubtree(i); 185 195 // only allow to replace nodes for which a replacement value is known (replacement value for ADF nodes are not available) 186 if (subTree == visualTreeNode.SymbolicExpressionTreeNode && replacementNodes.ContainsKey(subTree)) {196 if (subTree == symbExprTreeNode && replacementNodes.ContainsKey(subTree)) { 187 197 SwitchNodeWithReplacementNode(treeNode, i); 188 189 198 // show only interesting part of solution 190 if (tree.Root.SubtreeCount > 1) 191 this.treeChart.Tree = new SymbolicExpressionTree(tree.Root); // RPB + ADFs 192 else 193 this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); // 1st child of RPB 194 199 treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); 195 200 updateInProgress = true; 196 201 UpdateModel(tree); … … 203 208 204 209 private void treeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) { 205 if (e.Button == MouseButtons.Right) { 206 var node = (sender as VisualSymbolicExpressionTreeNode).SymbolicExpressionTreeNode; 207 var menu = treeChart.ContextMenuStrip; 208 209 bool flag = (node.Symbol is Constant || node.Symbol is Variable); 210 211 ToolStripItem[] items = menu.Items.Find("changeValueToolStripMenuItem", false); 212 ToolStripItem changeValueMenuItem = null; 213 if (items.Any()) 214 changeValueMenuItem = items[0]; 215 if (changeValueMenuItem != null) { 216 changeValueMenuItem.Enabled = flag; 217 changeValueMenuItem.Visible = flag; 218 } 219 } 210 // do stuff 211 treeChart.Repaint(); 212 } 213 214 private void treeChart_OnInsertNodeContextMenuItemClicked(object sender, EventArgs e) { 215 // display the insert node dialog 216 } 217 218 private void treeChart_SymbolicExpressionTreeChanged(object sender, EventArgs e) { 219 CalculateReplacementNodesAndNodeImpacts(treeChart.Tree); 220 PaintModel(); 220 221 } 221 222 222 223 private void treeChart_SymbolicExpressionTreeNodeChanged(object sender, EventArgs e) { 223 visualTreeNode = sender as VisualSymbolicExpressionTreeNode; 224 var subTree = visualTreeNode.SymbolicExpressionTreeNode; 225 string title = String.Empty; 226 double value = 0.0; 227 228 if (subTree.Symbol is Constant) { 229 title = "Change Constant Value"; 230 value = (subTree as ConstantTreeNode).Value; 231 } else if (subTree.Symbol is Variable) { 232 title = "Change Weight Value"; 233 value = (subTree as VariableTreeNode).Weight; 234 } 235 236 double originalValue = value; 237 238 if (!originalValues.ContainsKey(subTree)) 239 originalValues.Add(subTree, value); 240 else originalValue = originalValues[subTree]; 241 242 var dialog = new ValueChangeDialog(title, Math.Round(originalValue, 4).ToString(), Math.Round(value, 4).ToString()); 243 dialog.NewValueTextBox.Validated += OnNewValueValidated; 244 dialog.ShowDialog(this); 245 } 246 247 private void OnNewValueValidated(object sender, EventArgs e) { 248 var textBox = sender as TextBox; 249 var value = double.Parse(textBox.Text); 250 var subTree = visualTreeNode.SymbolicExpressionTreeNode; 251 252 if (subTree.Symbol is Constant) 253 (subTree as ConstantTreeNode).Value = value; 254 else if (subTree.Symbol is Variable) 255 (subTree as VariableTreeNode).Weight = value; 256 257 PaintModel(); 224 var dialog = (ValueChangeDialog)sender; 225 bool flag1 = false, flag2 = false; 226 if (dialog.Content is VariableTreeNode) { 227 var variable = (VariableTreeNode)dialog.Content; 228 var weight = double.Parse(dialog.NewValueTextBox.Text); 229 var name = (string)dialog.VariableNameComboBox.SelectedItem; 230 if (!variable.Weight.Equals(weight)) { 231 flag1 = true; 232 originalValues[variable] = variable.Weight; 233 variable.Weight = weight; 234 } 235 if (!variable.VariableName.Equals(name)) { 236 flag2 = true; 237 originalVariableNames[variable] = variable.VariableName; 238 variable.VariableName = name; 239 } 240 } else if (dialog.Content is ConstantTreeNode) { 241 var constant = (ConstantTreeNode)dialog.Content; 242 var value = double.Parse(dialog.NewValueTextBox.Text); 243 if (!constant.Value.Equals(value)) { 244 flag1 = true; 245 originalValues[constant] = constant.Value; 246 constant.Value = value; 247 248 } 249 } 250 if (flag1 || flag2) { 251 CalculateReplacementNodesAndNodeImpacts(); 252 PaintModel(); 253 } 254 } 255 256 private void treeChart_SymbolicExpressionTreeNodeInserted(object sender, EventArgs e) { 258 257 } 259 258 … … 282 281 if (flag2) // constant or variable node was changed 283 282 visualTree.ToolTip += Environment.NewLine + "Original value: " + originalValues[treeNode]; 284 else if (flag1 && flag3) // node was folded to a constant283 else if (flag1 && flag3) // symbol node was folded to a constant 285 284 visualTree.ToolTip += Environment.NewLine + "Original node: " + replacementNodes[treeNode]; 286 285 … … 324 323 325 324 private void btnSimplify_Click(object sender, EventArgs e) { 326 SymbolicDataAnalysisExpressionTreeSimplifier simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();325 var simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier(); 327 326 var simplifiedExpressionTree = simplifier.Simplify(model); 328 327 UpdateModel(simplifiedExpressionTree); … … 343 342 private void PruneTree(BackgroundWorker worker) { 344 343 var tree = model; 345 // get all tree nodes 346 foreach (var node in GetNodesAtDepth(tree .Root, new Data.IntRange(2, tree.Depth))) {344 // get all tree nodes starting from depth 2 (below the root and start nodes) 345 foreach (var node in GetNodesAtDepth(tree, new IntRange(2, tree.Depth))) { 347 346 if (worker.CancellationPending) 348 347 break; // pruning cancelled … … 369 368 370 369 #region helpers 371 private static IEnumerable<ISymbolicExpressionTreeNode> GetNodesAtDepth(ISymbolicExpressionTreeNode root, Data.IntRange range) { 372 var list = new List<Tuple<ISymbolicExpressionTreeNode, int>> { new Tuple<ISymbolicExpressionTreeNode, int>(root, 0) }; 373 int offset = 0; 374 int level = 0; 375 while (level < range.End) { 376 ++level; 377 int count = list.Count; 378 for (int i = offset; i != count; ++i) { 379 if (list[i].Item1.Subtrees.Any()) 380 list.AddRange(from s in list[i].Item1.Subtrees select new Tuple<ISymbolicExpressionTreeNode, int>(s, level)); 381 } 382 offset = count; 383 } 384 // taking advantage of the fact that the list is already sorted by level 385 for (int i = list.Count - 1; i >= 0; --i) { 386 if (list[i].Item2 >= range.Start) 387 yield return list[i].Item1; 388 else break; 389 } 370 private static IEnumerable<ISymbolicExpressionTreeNode> GetNodesAtDepth(ISymbolicExpressionTree tree, IntRange depthRange) { 371 var treeDepth = tree.Root.GetDepth(); 372 return from node in tree.Root.IterateNodesPostfix() 373 let depth = treeDepth - node.GetDepth() 374 where depthRange.Start <= depth 375 where depth <= depthRange.End 376 select node; 390 377 } 391 378 #endregion
Note: See TracChangeset
for help on using the changeset viewer.