다음을 통해 공유


ContextNode 클래스

업데이트: 2007년 11월

잉크 분석 도중 만들어진 개체 트리의 노드를 나타냅니다.

네임스페이스:  Microsoft.Ink
어셈블리:  Microsoft.Ink.Analysis(Microsoft.Ink.Analysis.dll)

구문

‘선언
Public Class ContextNode
‘사용 방법
Dim instance As ContextNode
public class ContextNode
public ref class ContextNode
public class ContextNode
public class ContextNode

설명

InkAnalyzer에서는 잉크에 대한 분석을 수행한 후 결과를 ContextNode 개체 트리로 나타냅니다. 이러한 노드는 맨 위쪽의 RootNode부터 시작하여 트리의 아래쪽으로 내려갈수록 점점 더 작은 스트로크 컬렉션을 나타냅니다. 이러한 노드는 단락이나 줄 등의 단어 그룹, 단어나 그리기 등의 분석된 잉크 또는 다양한 기타 형식일 수 있습니다. 전체 목록을 보려면 ContextNodeType 클래스를 참조하십시오.

사용자는 AnalysisHintNode, TextWordNode, ImageNode 등의 다른 노드를 InkAnalyzer에 추가할 수 있습니다.

예제

이 예제에서는 InkAnalyzer인 theInkAnalyzer를 받아 해당 ContextNode 트리를 사용하여 System.Windows.Forms.TreeView인 theTreeView를 채웁니다. 트리 뷰에서 노드를 선택하면 해당 스트로크가 빨간색으로 나타나도록 설정됩니다. Tag 속성은 트리 노드와 해당 노드가 나타내는 컨텍스트 노드를 서로 매핑하는 데 사용됩니다.

Private Sub BuildTree()
    Me.theTreeView.Nodes.Clear()
    Dim rootNode As New TreeNode(Me.theInkAnalyzer.RootNode.ToString())
    Me.theTreeView.Nodes.Add(rootNode)
    rootNode.Tag = Me.theInkAnalyzer.RootNode

    WalkTree(Me.theInkAnalyzer.RootNode, rootNode)

End Sub 'BuildTree


Private Sub WalkTree(ByVal parentContextNode As Microsoft.Ink.ContextNode, _
                     ByVal parentTreeNode As TreeNode)

    Dim cNode As ContextNode
    For Each cNode In parentContextNode.SubNodes
        Dim newTNode As New TreeNode(cNode.ToString())
        If TypeOf cNode Is Microsoft.Ink.InkWordNode Then
            newTNode.Text = newTNode.Text + _
                ": " + CType(cNode, InkWordNode).GetRecognizedString()
        ElseIf TypeOf cNode Is Microsoft.Ink.InkDrawingNode Then
            Dim shapeName As String = CType(cNode, InkDrawingNode).GetShapeName()
            If shapeName <> "" Then
                newTNode.Text = newTNode.Text + ": " + shapeName
            End If
        End If
        WalkTree(cNode, newTNode)
        parentTreeNode.Nodes.Add(newTNode)

        ' Add the context node as a tag of the tree node
        newTNode.Tag = cNode
    Next cNode

End Sub 'WalkTree

Private Sub theTreeView_AfterSelect(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.TreeViewEventArgs) _
            Handles theTreeView.AfterSelect
    ' Get the context node
    Dim selectedNode As ContextNode = CType(e.Node.Tag, ContextNode)

    MarkNodeAsRed(selectedNode)

    timeStampLabel.Text = ""

    ' Show selected results
    If Not (selectedNode Is Nothing) Then
        Select Case selectedNode.Type
            Case Microsoft.Ink.ContextNodeType.WritingRegion
                Dim writingRegion As WritingRegionNode = _
                    CType(selectedNode, WritingRegionNode)
                selectedResultsTextBox.Text = writingRegion.GetRecognizedString()
            Case Microsoft.Ink.ContextNodeType.Paragraph
                Dim paragraph As ParagraphNode = _
                    CType(selectedNode, ParagraphNode)
                selectedResultsTextBox.Text = paragraph.GetRecognizedString()
            Case Microsoft.Ink.ContextNodeType.Line
                Dim line As LineNode = _
                    CType(selectedNode, LineNode)
                selectedResultsTextBox.Text = line.GetRecognizedString()
            Case Microsoft.Ink.ContextNodeType.InkWord
                Dim inkWord As InkWordNode = _
                    CType(selectedNode, InkWordNode)
                Dim parentNode As ContextNode = inkWord.ParentNode
                If TypeOf parentNode Is LineNode Then
                    Dim parentLine As LineNode = CType(parentNode, LineNode)
                    ' Put parent line's recognized string into the text box
                    selectedResultsTextBox.Text = parentLine.GetRecognizedString()

                    ' Select the text that corresponds to the ink word
                    Dim subNodes As New ContextNodeCollection(theInkAnalyzer)
                    subNodes.Add(inkWord)
                    Dim start As Integer
                    Dim length As Integer
                    parentLine.GetTextRangeFromNodes(subNodes, start, length)
                    If start >= 0 AndAlso length > 0 Then
                        selectedResultsTextBox.Select(start, length)
                    End If
                End If
                ' Show the time stamp
                If inkWord.ContainsPropertyData(Me.timeStampGuid) Then
                    Dim timeStamp As DateTime = _
                        CType(inkWord.GetPropertyData(Me.timeStampGuid), DateTime)
                    timeStampLabel.Text = timeStamp.ToShortTimeString()
                End If

                ' Snippet to demonstrate GetPropertyDataIds
                Dim propertyDataIds() As Guid = inkWord.GetPropertyDataIds()

                ' Snippets to demonstrate loading and saving
                Dim data As Byte() = inkWord.SavePropertiesData()
                If (Not inkWord.LoadPropertiesData(data)) Then
                    MessageBox.Show("Cannot load property data")
                End If
            Case Microsoft.Ink.ContextNodeType.InkDrawing
                Dim drawingNode As InkDrawingNode = CType(selectedNode, InkDrawingNode)
                selectedResultsTextBox.Text = drawingNode.GetShapeName()
            Case Microsoft.Ink.ContextNodeType.InkBullet
                Dim bulletNode As InkBulletNode = CType(selectedNode, InkBulletNode)
                selectedResultsTextBox.Text = bulletNode.GetRecognizedString()
            Case Microsoft.Ink.ContextNodeType.Object
                Dim selectedObject As ObjectNode = selectedNode
                selectedResultsTextBox.Text = selectedObject.GetRecognizedString()
            Case Microsoft.Ink.ContextNodeType.CustomRecognizer
                Dim customRecognizer As CustomRecognizerNode = selectedNode
                selectedResultsTextBox.Text = customRecognizer.GetRecognizedString()
            Case Else
                selectedResultsTextBox.Text = String.Empty
        End Select
    End If
    Me.currentNode = selectedNode

End Sub 'theTreeView_AfterSelect


Private Sub MarkNodeAsRed(ByVal selectedNode As ContextNode)
    ' Set all node strokes to black, but this one to red
    Dim inkStroke As Stroke
    For Each inkStroke In Me.theInkCollector.Ink.Strokes
        If Not (selectedNode Is Nothing) AndAlso _
           selectedNode.Strokes.Contains(inkStroke) Then
            inkStroke.DrawingAttributes = New DrawingAttributes(Color.Red)
        Else
            inkStroke.DrawingAttributes = Me.theInkCollector.DefaultDrawingAttributes
        End If
    Next inkStroke
    theNotesPanel.Refresh()

End Sub 'MarkNodeAsRed

        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();
        }

상속 계층 구조

System.Object
  Microsoft.Ink.ContextNode
    Microsoft.Ink.AnalysisHintNode
    Microsoft.Ink.CustomRecognizerNode
    Microsoft.Ink.ImageNode
    Microsoft.Ink.InkBulletNode
    Microsoft.Ink.InkDrawingNode
    Microsoft.Ink.InkWordNode
    Microsoft.Ink.LineNode
    Microsoft.Ink.ObjectNode
    Microsoft.Ink.ParagraphNode
    Microsoft.Ink.RootNode
    Microsoft.Ink.TextWordNode
    Microsoft.Ink.UnclassifiedInkNode
    Microsoft.Ink.WritingRegionNode

스레드로부터의 안전성

이 형식의 모든 공용 static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows Vista

.NET Framework 및 .NET Compact Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

3.0에서 지원

참고 항목

참조

ContextNode 멤버

Microsoft.Ink 네임스페이스

InkAnalyzer.Analyze

InkAnalyzer.RootNode

Microsoft.Ink.ContextNodeType