public static IEnumerable<ISymbolicExpressionTreeNode> FindMatches(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode subtree, SymbolicExpressionTreeNodeEqualityComparer comp) {
      var fragmentLength = subtree.GetLength();
      // below, we use ">=" for Match(n, subtree, comp) >= fragmentLength because in case of relaxed conditions, 
      // we can have multiple matches of the same node

      return root.IterateNodesBreadth().Where(n => n.GetLength() >= fragmentLength && Match(n, subtree, comp) == fragmentLength);
    }
Exemple #2
0
 public IEnumerable <ISymbolicExpressionTreeNode> IterateNodesBreadth()
 {
     if (root == null)
     {
         return(Enumerable.Empty <SymbolicExpressionTreeNode>());
     }
     return(root.IterateNodesBreadth());
 }
        public static IEnumerable <ISymbolicExpressionTreeNode> FindMatches(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode subtree, SymbolicExpressionTreeNodeEqualityComparer comp)
        {
            var fragmentLength = subtree.GetLength();

            // below, we use ">=" for Match(n, subtree, comp) >= fragmentLength because in case of relaxed conditions,
            // we can have multiple matches of the same node

            return(root.IterateNodesBreadth().Where(n => n.GetLength() >= fragmentLength && Match(n, subtree, comp) == fragmentLength));
        }
        private void contextMenuStrip_Opened(object sender, EventArgs e)
        {
            var menuStrip  = (ContextMenuStrip)sender;
            var point      = menuStrip.SourceControl.PointToClient(Cursor.Position);
            var ea         = new MouseEventArgs(MouseButtons.Left, 1, point.X, point.Y, 0);
            var visualNode = FindVisualSymbolicExpressionTreeNodeAt(ea.X, ea.Y);

            if (visualNode != null)
            {
                OnSymbolicExpressionTreeNodeClicked(visualNode, ea);
            }
            else
            {
                currSelected = null;
            }

            if (currSelected == null)
            {
                insertNodeToolStripMenuItem.Visible = false;
                changeNodeToolStripMenuItem.Visible = false;
                copyToolStripMenuItem.Visible       = false;
                cutToolStripMenuItem.Visible        = false;
                removeToolStripMenuItem.Visible     = false;
                pasteToolStripMenuItem.Visible      = false;
            }
            else
            {
                var node = currSelected.Content;
                insertNodeToolStripMenuItem.Visible = true;
                changeNodeToolStripMenuItem.Visible = true;
                changeNodeToolStripMenuItem.Enabled = (node is SymbolicExpressionTreeTerminalNode);
                insertNodeToolStripMenuItem.Enabled = !changeNodeToolStripMenuItem.Enabled;
                copyToolStripMenuItem.Visible       = true;
                cutToolStripMenuItem.Visible        = true;
                removeToolStripMenuItem.Visible     = true;

                pasteToolStripMenuItem.Visible = true;
                pasteToolStripMenuItem.Enabled = tempNode != null && insertNodeToolStripMenuItem.Enabled &&
                                                 !(lastOp == EditOp.CutSubtree && tempNode.IterateNodesBreadth().Contains(node)) &&
                                                 node.SubtreeCount < node.Symbol.MaximumArity;
            }
        }