Export (0) Print
Expand All

RootNode Class

Represents the top ContextNode for the tree of nodes that describes the results of ink analysis.

Namespace:  Microsoft.Ink
Assembly:  Microsoft.Ink.Analysis (in Microsoft.Ink.Analysis.dll)

public sealed class RootNode : ContextNode

The RootNode is accessed by the InkAnalyzer.RootNode property.

A RootNode object can contain the following types of children:

The following example takes an InkAnalyzer, theInkAnalyzer, and uses its ContextNode tree to fill a TreeView, theTreeView, starting with the RootNode. When a node in the tree view is selected, the strokes are set to display in red. The Tag property is used to map between tree nodes and the context nodes that they represent.

		private void BuildTree()
		{
			this.theTreeView.Nodes.Clear();
			TreeNode rootNode =
				new TreeNode(this.theInkAnalyzer.RootNode.ToString());
			this.theTreeView.Nodes.Add(rootNode);
			rootNode.Tag = this.theInkAnalyzer.RootNode;

			WalkTree(this.theInkAnalyzer.RootNode, rootNode);
		}

		private void WalkTree(ContextNode parentContextNode, TreeNode parentTreeNode)
		{
			foreach (ContextNode cNode in parentContextNode.SubNodes)
			{
				TreeNode newTNode = new TreeNode(cNode.ToString());
				if (cNode is Microsoft.Ink.InkWordNode)
				{
					newTNode.Text +=
						": " + ((InkWordNode)cNode).GetRecognizedString();
				}
				else if (cNode is Microsoft.Ink.InkDrawingNode)
				{
                    String shapeName = ((InkDrawingNode)cNode).GetShapeName();
                    if (shapeName != "")
					    newTNode.Text += ": " + shapeName;
                }
				WalkTree(cNode, newTNode);
				parentTreeNode.Nodes.Add(newTNode);

				// Add the context node as a tag of the tree node
				newTNode.Tag = cNode;
			}
		}

		private void theTreeView_AfterSelect(object sender, TreeViewEventArgs e)
		{
			// Get the context node
			ContextNode selectedNode = (ContextNode)e.Node.Tag;

			MarkNodeAsRed(selectedNode);

			timeStampLabel.Text = "";

			// Show selected results 
			if (selectedNode != null)
			{
				if (selectedNode.Type == Microsoft.Ink.ContextNodeType.WritingRegion)
                {
					WritingRegionNode writingRegion = (WritingRegionNode)selectedNode;
					selectedResultsTextBox.Text = writingRegion.GetRecognizedString();
                }
				else if (selectedNode.Type == Microsoft.Ink.ContextNodeType.Paragraph)
                {
					ParagraphNode paragraph = (ParagraphNode)selectedNode;
					selectedResultsTextBox.Text = paragraph.GetRecognizedString();
                }
				else if (selectedNode.Type == Microsoft.Ink.ContextNodeType.Line)
                {
					LineNode line = (LineNode)selectedNode;
					selectedResultsTextBox.Text = line.GetRecognizedString();
                }
				else if (selectedNode.Type == Microsoft.Ink.ContextNodeType.InkWord)
                {
					InkWordNode inkWord = (InkWordNode)selectedNode;
					ContextNode parentNode = inkWord.ParentNode;
					if (parentNode is LineNode)
					{
						LineNode parentLine = (LineNode)parentNode;
						// Put parent line's recognized string into the text box
						selectedResultsTextBox.Text = parentLine.GetRecognizedString();

						// Select the text that corresponds to the ink word
                        ContextNodeCollection subNodes = new ContextNodeCollection(theInkAnalyzer);
                        subNodes.Add(inkWord);
                        int start = 0;
                        int length = 0;
                        parentLine.GetTextRangeFromNodes(subNodes, out start, out length);
						if (start >= 0 && length > 0)
						{
							selectedResultsTextBox.Select(start, length);
						}
					}
                }
				else if (selectedNode.Type == Microsoft.Ink.ContextNodeType.InkDrawing)
                {
					InkDrawingNode drawingNode = (InkDrawingNode)selectedNode;
					selectedResultsTextBox.Text = drawingNode.GetShapeName();
                }
            	else if (selectedNode.Type == Microsoft.Ink.ContextNodeType.InkBullet)
                {
					InkBulletNode bulletNode = (InkBulletNode)selectedNode;
                    selectedResultsTextBox.Text = bulletNode.GetRecognizedString();
                }
                else if (selectedNode.Type == Microsoft.Ink.ContextNodeType.CustomRecognizer)
                {
                    CustomRecognizerNode customRecognizer = (CustomRecognizerNode)selectedNode;
                    selectedResultsTextBox.Text = customRecognizer.GetRecognizedString();
                }
                else if (selectedNode.Type == Microsoft.Ink.ContextNodeType.Object)
                {
                    ObjectNode selectedObject = (ObjectNode)selectedNode;
                    selectedResultsTextBox.Text = selectedObject.GetRecognizedString();
                }
                else
                {
					selectedResultsTextBox.Text = String.Empty;
				}

				if (selectedNode is InkWordNode)
				{
					InkWordNode inkWord = (InkWordNode)selectedNode;

					// Show the time stamp 
					if (inkWord.ContainsPropertyData(this.timeStampGuid))
					{
						DateTime timeStamp =
							(DateTime)inkWord.GetPropertyData(this.timeStampGuid);
						timeStampLabel.Text = timeStamp.ToShortTimeString();
					}

					// Snippet to demonstrate GetPropertyDataIds
					Guid[] propertyDataIds = inkWord.GetPropertyDataIds();
					// Snippets to demonstrate loading and saving
					byte[] data = inkWord.SavePropertiesData();
                    if (!inkWord.LoadPropertiesData(data))
                        MessageBox.Show("Cannot load property data");
				}

			}
			this.currentNode = selectedNode;
		}

		private void MarkNodeAsRed(ContextNode selectedNode)
		{
			// Set all node strokes to black, but this one to red 
			foreach (Stroke stroke in this.theInkCollector.Ink.Strokes)
			{
				if (selectedNode != null && 
					selectedNode.Strokes.Contains(stroke))
					stroke.DrawingAttributes = new DrawingAttributes(Color.Red);
				else
					stroke.DrawingAttributes = this.theInkCollector.DefaultDrawingAttributes;
			}

			theNotesPanel.Refresh();
		}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2015 Microsoft