Free cookie consent management tool by TermsFeed Policy Generator

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/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4
Files:
10 added
6 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}
Note: See TracChangeset for help on using the changeset viewer.