Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7784


Ignore:
Timestamp:
05/08/12 10:10:14 (12 years ago)
Author:
bburlacu
Message:

#1832: Moved replacement and impact values calculation code from view to separate files. Implemented simplifier actions: copy, cut, delete, insert node/subtree.

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  
    159159  </ItemGroup>
    160160  <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>
    161167    <Compile Include="Plugin.cs" />
    162168    <Compile Include="SymbolicExpressionGrammarAllowedChildSymbolsControl.cs">
     
    183189    <Compile Include="SymbolicExpressionGrammarView.Designer.cs">
    184190      <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>
    185203    </Compile>
    186204    <Compile Include="SymbolView.cs">
     
    233251      <Install>true</Install>
    234252    </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>
    235267  </ItemGroup>
    236268  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolView.cs

    r7259 r7784  
    2929namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
    3030  [View("Symbol View")]
    31   [Content(typeof(ISymbol), false)]
     31  [Content(typeof(ISymbol), true)]
    3232  public partial class SymbolView : NamedItemView {
    3333    public new ISymbol Content {
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.Designer.cs

    r7148 r7784  
    170170      this.symbolsTreeView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.symbolsTreeView_KeyDown);
    171171      this.symbolsTreeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.symbolsTreeView_MouseDown);
     172      this.symbolsTreeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(symbolsTreeView_NodeMouseDoubleClick);
    172173      //
    173174      // imageList
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.cs

    r7259 r7784  
    6262        copyButton.Enabled = false;
    6363        treeViewBackColor = symbolsTreeView.BackColor;
    64         symbolsTreeView.BackColor = Color.FromArgb(255,240,240,240);
     64        symbolsTreeView.BackColor = Color.FromArgb(255, 240, 240, 240);
    6565      } else {
    6666        addButton.Enabled = true;
     
    125125    #endregion
    126126
    127     private bool internalTreeViewUpdateInProgress = false;
    128127    private void UpdateSymbolsTreeView() {
    129       internalTreeViewUpdateInProgress = true;
    130128      var symbols = Content.Symbols.ToList();
    131129      foreach (var treeNode in IterateTreeNodes().ToList()) {
     
    140138
    141139      RebuildImageList();
    142       internalTreeViewUpdateInProgress = false;
    143140    }
    144141
     
    181178
    182179    private void symbolsTreeView_BeforeCheck(object sender, TreeViewCancelEventArgs e) {
    183       if (internalTreeViewUpdateInProgress) return;     
    184180      if (Content == null || Content.ReadOnly) e.Cancel = true;
    185181      if (ReadOnly || Locked) e.Cancel = true;
     
    187183
    188184    #region drag & drop operations
    189     private GroupSymbol parentOfDraggedSymbol;
    190185    private void symbolsTreeView_ItemDrag(object sender, ItemDragEventArgs e) {
    191186      if (!Locked) {
    192187        var treeNode = e.Item as TreeNode;
    193         if (treeNode.Parent != null) parentOfDraggedSymbol = treeNode.Parent.Tag as GroupSymbol;
    194188        var data = new DataObject();
    195189        data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, treeNode.Tag);
     
    257251    }
    258252
     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
    259262    private void symbolsTreeView_KeyDown(object sender, KeyEventArgs e) {
    260263      if (Content == null || Content.ReadOnly || ReadOnly || Locked) return;
     
    424427
    425428  //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
    426430  internal class CheckBoxTreeView : TreeView {
    427431    protected override void WndProc(ref Message m) {
    428432      // 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));
    430449    }
    431450  }
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.Designer.cs

    r7372 r7784  
    2020#endregion
    2121
    22 using System;
    23 using System.Windows.Forms;
    24 using HeuristicLab.Common;
    2522
    2623namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
     
    5350      this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
    5451      this.saveImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    55       this.changeValueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5652      this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
    5753      this.contextMenuStrip.SuspendLayout();
     
    6157      //
    6258      this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    63             this.saveImageToolStripMenuItem,
    64             this.changeValueToolStripMenuItem});
     59            this.saveImageToolStripMenuItem});
    6560      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);
    6862      //
    6963      // saveImageToolStripMenuItem
     
    7367      this.saveImageToolStripMenuItem.Text = "Save Image";
    7468      this.saveImageToolStripMenuItem.Click += new System.EventHandler(this.saveImageToolStripMenuItem_Click);
    75       //
    76       // changeValueToolStripMenuItem
    77       //
    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);
    8369      //
    8470      // saveFileDialog
     
    10591
    10692    private System.Windows.Forms.ToolTip toolTip;
    107     private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
    10893    private System.Windows.Forms.ToolStripMenuItem saveImageToolStripMenuItem;
    10994    private System.Windows.Forms.SaveFileDialog saveFileDialog;
    110     private System.Windows.Forms.ToolStripMenuItem changeValueToolStripMenuItem;
     95    internal System.Windows.Forms.ContextMenuStrip contextMenuStrip;
    11196  }
    11297}
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r7411 r7784  
    2727
    2828namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
    29   public sealed partial class SymbolicExpressionTreeChart : UserControl {
     29  public partial class SymbolicExpressionTreeChart : UserControl {
    3030    private Image image;
    3131    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;
    3534
    3635    public SymbolicExpressionTreeChart() {
     
    4443      this.backgroundColor = Color.White;
    4544      this.textFont = new Font("Times New Roman", 8);
    46       selectedNode = null;
    4745    }
    4846
     
    158156
    159157    #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 
    168158    public event MouseEventHandler SymbolicExpressionTreeNodeClicked;
    169     private void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
     159    protected void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
    170160      var clicked = SymbolicExpressionTreeNodeClicked;
    171161      if (clicked != null)
     
    173163    }
    174164
    175     private void SymbolicExpressionTreeChart_MouseClick(object sender, MouseEventArgs e) {
     165    protected virtual void SymbolicExpressionTreeChart_MouseClick(object sender, MouseEventArgs e) {
    176166      VisualSymbolicExpressionTreeNode visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
    177       if (visualTreeNode != null)
     167      if (visualTreeNode != null) {
    178168        OnSymbolicExpressionTreeNodeClicked(visualTreeNode, e);
     169      }
    179170    }
    180171
    181172    public event MouseEventHandler SymbolicExpressionTreeNodeDoubleClicked;
    182     private void OnSymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) {
     173    protected void OnSymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) {
    183174      var doubleClicked = SymbolicExpressionTreeNodeDoubleClicked;
    184175      if (doubleClicked != null)
     
    193184
    194185    public event ItemDragEventHandler SymbolicExpressionTreeNodeDrag;
    195     private void OnSymbolicExpressionTreeNodeDragDrag(object sender, ItemDragEventArgs e) {
     186    protected void OnSymbolicExpressionTreeNodeDragDrag(object sender, ItemDragEventArgs e) {
    196187      var dragged = SymbolicExpressionTreeNodeDrag;
    197188      if (dragged != null)
     
    244235    ///
    245236    /// </summary>
    246     /// <param name="functionTree"> functiontree to draw</param>
     237    /// <param name="functionTree"> function tree to draw</param>
    247238    /// <param name="graphics">graphics object to draw on</param>
    248239    /// <param name="x">x coordinate of drawing area</param>
     
    357348    }
    358349    #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 anyway
    372         OnSymbolicExpressionTreeNodeChanged(selectedNode, e);
    373     }
    374350  }
    375351}
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.sln

    r7365 r7784  
    1111EndProject
    1212Project("{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}"
     13EndProject
     14Project("{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}"
     15EndProject
     16Project("{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}"
     17EndProject
     18Project("{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}"
    1319EndProject
    1420Global
     
    4652    {423BD94F-963A-438E-BA45-3BB3D61CD03B}.Release|x86.ActiveCfg = Release|x86
    4753    {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
    4890  EndGlobalSection
    4991  GlobalSection(SolutionProperties) = preSolution
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj

    r7422 r7784  
    135135  <ItemGroup>
    136136    <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>
    143137    <Compile Include="TextualSymbolicDataAnalysisModelView.cs">
    144138      <SubType>UserControl</SubType>
     
    216210      <Install>true</Install>
    217211    </BootstrapperPackage>
     212  </ItemGroup>
     213  <ItemGroup>
     214    <EmbeddedResource Include="InteractiveSymbolicDataAnalysisSolutionSimplifierView.resx">
     215      <DependentUpon>InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs</DependentUpon>
     216    </EmbeddedResource>
    218217  </ItemGroup>
    219218  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.Designer.cs

    r7411 r7784  
    5050      this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
    5151      this.btnSimplify = new System.Windows.Forms.Button();
     52      this.btnPrune = new System.Windows.Forms.Button();
    5253      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();
    5455      this.grpViewHost = new System.Windows.Forms.GroupBox();
    55       this.btnPrune = new System.Windows.Forms.Button();
    5656      this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
    5757      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
     
    133133      this.btnSimplify.Click += new System.EventHandler(this.btnSimplify_Click);
    134134      //
     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      //
    135145      // btnOptimizeConstants
    136146      //
     
    160170      this.treeChart.TextFont = new System.Drawing.Font("Times New Roman", 8F);
    161171      this.treeChart.Tree = null;
     172      this.treeChart.SymbolicExpressionTreeChanged += new System.EventHandler(this.treeChart_SymbolicExpressionTreeChanged);
    162173      this.treeChart.SymbolicExpressionTreeNodeChanged += new System.EventHandler(this.treeChart_SymbolicExpressionTreeNodeChanged);
     174      this.treeChart.SymbolicExpressionTreeNodeInserted += new System.EventHandler(this.treeChart_SymbolicExpressionTreeNodeInserted);
    163175      this.treeChart.SymbolicExpressionTreeNodeClicked += new System.Windows.Forms.MouseEventHandler(this.treeChart_SymbolicExpressionTreeNodeClicked);
    164176      this.treeChart.SymbolicExpressionTreeNodeDoubleClicked += new System.Windows.Forms.MouseEventHandler(this.treeChart_SymbolicExpressionTreeNodeDoubleClicked);
     
    174186      this.grpViewHost.TabStop = false;
    175187      this.grpViewHost.Text = "Details";
    176       //
    177       // btnPrune
    178       //
    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);
    186188      //
    187189      // backgroundWorker1
     
    212214    #endregion
    213215
    214     private HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart treeChart;
     216    private HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.InteractiveSymbolicExpressionTreeChart treeChart;
    215217    private System.Windows.Forms.SplitContainer splitContainer;
    216218    private HeuristicLab.MainForm.WindowsForms.ViewHost viewHost;
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r7422 r7784  
    2727using System.Windows.Forms;
    2828using HeuristicLab.Common;
     29using HeuristicLab.Data;
    2930using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    3031using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
     
    3637    private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts;
    3738    private Dictionary<ISymbolicExpressionTreeNode, double> originalValues;
     39    private Dictionary<ISymbolicExpressionTreeNode, string> originalVariableNames;
    3840    private bool updateInProgress = false;
    39     private VisualSymbolicExpressionTreeNode visualTreeNode; // for correctly handling events when changing node values
    4041    private ISymbolicExpressionTree model;
    4142
     
    4546      this.nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>();
    4647      this.originalValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
     48      this.originalVariableNames = new Dictionary<ISymbolicExpressionTreeNode, string>();
    4749      this.Caption = "Interactive Solution Simplifier";
    4850    }
     
    9698    private void CalculateReplacementNodesAndNodeImpacts() {
    9799      if (Content == null || Content.Model == null || Content.ProblemData == null) return;
    98       //var tree = Content.Model.SymbolicExpressionTree;
    99100      var tree = model;
    100101      var replacementValues = CalculateReplacementValues(tree);
     
    161162
    162163    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;
    164167      var tree = model;
    165168      // 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
    167170      // 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);
    176175        updateInProgress = true;
    177176        UpdateModel(tree);
     
    179178        return;
    180179      }
    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      }
    182192      foreach (SymbolicExpressionTreeNode treeNode in tree.IterateNodesPostfix()) {
    183193        for (int i = 0; i < treeNode.SubtreeCount; i++) {
    184194          ISymbolicExpressionTreeNode subTree = treeNode.GetSubtree(i);
    185195          // 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)) {
    187197            SwitchNodeWithReplacementNode(treeNode, i);
    188 
    189198            // 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));
    195200            updateInProgress = true;
    196201            UpdateModel(tree);
     
    203208
    204209    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();
    220221    }
    221222
    222223    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) {
    258257    }
    259258
     
    282281        if (flag2) // constant or variable node was changed
    283282          visualTree.ToolTip += Environment.NewLine + "Original value: " + originalValues[treeNode];
    284         else if (flag1 && flag3) // node was folded to a constant
     283        else if (flag1 && flag3) // symbol node was folded to a constant
    285284          visualTree.ToolTip += Environment.NewLine + "Original node: " + replacementNodes[treeNode];
    286285
     
    324323
    325324    private void btnSimplify_Click(object sender, EventArgs e) {
    326       SymbolicDataAnalysisExpressionTreeSimplifier simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
     325      var simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
    327326      var simplifiedExpressionTree = simplifier.Simplify(model);
    328327      UpdateModel(simplifiedExpressionTree);
     
    343342    private void PruneTree(BackgroundWorker worker) {
    344343      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))) {
    347346        if (worker.CancellationPending)
    348347          break; // pruning cancelled
     
    369368
    370369    #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;
    390377    }
    391378    #endregion
Note: See TracChangeset for help on using the changeset viewer.