Exemplo n.º 1
0
    public void LoadFromFile()
    {
        List<AnnotationText> textAnnotationList = new List<AnnotationText> ();
        List<AnnotationMark> markAnnotationList = new List<AnnotationMark> ();
        List<AnnotationInk> inkAnnotationList = new List<AnnotationInk> ();
        List<AnnotationLink> linkAnnotationList = new List<AnnotationLink>();

        if (annotationXmlPath == null) {
            Debug.Log ("ERROR - XML path null");
            return;
        }

        TextAsset textAsset = new TextAsset();
        textAsset = (TextAsset)Resources.Load(annotationXmlPath, typeof(TextAsset));

        if (textAsset == null) {
            if(annotationXmlPath.Contains(".xml")) {
               Debug.Log ("ERROR - the filename can't have extension. Delete .xml from the filename");
            }
            else {
                Debug.Log ("ERROR - There was a problem loading xml file");
            }
            return;
        }

        XmlDocument xml = new XmlDocument ();
        xml.LoadXml (textAsset.text);

        // Load Take
        XmlNodeList xmlTakeList = xml.SelectNodes ("/annotation_document/session/take");
        for (int j = 0; j < xmlTakeList.Count; j++) {

            XmlNodeList xmlAnnotationSetList = xmlTakeList.Item(j).SelectNodes("annotations/annotation_set");
            if(xmlAnnotationSetList.Count == 0)
                continue;

            take =  CreateTake(xmlTakeList.Item(j));
            if(take == null) {
                Debug.Log("ERROR creating class Take");
                return;
            }

            // Load Annotations
            //XmlNodeList xmlAnnotationSetList = xml.SelectNodes ("/annotation_document/session/take/annotations/annotation_set");
            int nNodes = xmlAnnotationSetList.Count;
            //Debug.Log ("annotation set count: " + nNodes);
            for (int i = 0; i < nNodes; i++) {
                    //Debug.Log("annotation set name: " + xmlAnnotationSetList.Item(i).Name);
                    XmlNodeList tmpList = xmlAnnotationSetList.Item (i).SelectNodes ("annotation");
                    //Debug.Log("annotation count: " + tmpList.Count);
                    for (int w = 0; w < tmpList.Count; w++) {
                            XmlNode xmlAnnotation = tmpList.Item (w);

                            //	Debug.Log("type = " + xmlAnnotation.Attributes[0].InnerText);
                            switch (xmlAnnotation.Attributes [0].InnerText) {

                            case "text":
                                    AnnotationText annotation = CreateAnnotationText (xmlAnnotation);
                                    if(annotation == null)
                                        continue;

                                    annotation.Type = "text";
                                    textAnnotationList.Add (annotation);
                                    Debug.Log ("TEXT annotation");
                                    continue;
                            case "mark":
                                    AnnotationMark annotationMark = new AnnotationMark ();
                                    annotationMark.Type = "mark";
                                    annotationMark = (AnnotationMark)AddAnnotationCommonFields (xmlAnnotation, annotationMark);
                                    markAnnotationList.Add (annotationMark);
                                    Debug.Log ("MARK annotation");
                                    continue;
                            case "ink":
                                    AnnotationInk annotationInk = new AnnotationInk ();
                                    annotationInk.Type = "ink";
                                    annotationInk = CreateAnnotationInk (xmlAnnotation);
                                    inkAnnotationList.Add (annotationInk);
                                    Debug.Log ("INK annotation");
                                    continue;
                            case "link":
                                    AnnotationLink annotationLink = new AnnotationLink ();
                                    annotationLink.Type = "link";
                                    annotationLink = CreateAnnotationLink (xmlAnnotation);
                                    linkAnnotationList.Add (annotationLink);
                                    Debug.Log ("LINK annotation");
                                    continue;
                            case "audio":
                                    Debug.Log ("Audio annotation");
                                    continue;
                            default:
                                    continue;
                            }
                    }
            }

            take.TextAnnotationList = textAnnotationList;
            take.InkAnnotationList = inkAnnotationList;
            take.MarkAnnotationList = markAnnotationList;
            take.LinkAnnotationList = linkAnnotationList;
            Debug.Log ("Number of Text Annotation: " + take.TextAnnotationList.Count);
            Debug.Log ("Number of Mark Annotation: " + take.MarkAnnotationList.Count);
            Debug.Log ("Number of Ink Annotation: " + take.InkAnnotationList.Count);
            Debug.Log ("Number of Link Annotation: " + take.LinkAnnotationList.Count);
        }
    }
Exemplo n.º 2
0
    public void LoadFromFile()
    {
        List <AnnotationText> textAnnotationList = new List <AnnotationText> ();
        List <AnnotationMark> markAnnotationList = new List <AnnotationMark> ();
        List <AnnotationInk>  inkAnnotationList  = new List <AnnotationInk> ();
        List <AnnotationLink> linkAnnotationList = new List <AnnotationLink>();

        if (annotationXmlPath == null)
        {
            Debug.Log("ERROR - XML path null");
            return;
        }

        TextAsset textAsset = new TextAsset();

        textAsset = (TextAsset)Resources.Load(annotationXmlPath, typeof(TextAsset));

        if (textAsset == null)
        {
            if (annotationXmlPath.Contains(".xml"))
            {
                Debug.Log("ERROR - the filename can't have extension. Delete .xml from the filename");
            }
            else
            {
                Debug.Log("ERROR - There was a problem loading xml file");
            }
            return;
        }

        XmlDocument xml = new XmlDocument();

        xml.LoadXml(textAsset.text);



        // Load Take
        XmlNodeList xmlTakeList = xml.SelectNodes("/annotation_document/session/take");

        for (int j = 0; j < xmlTakeList.Count; j++)
        {
            XmlNodeList xmlAnnotationSetList = xmlTakeList.Item(j).SelectNodes("annotations/annotation_set");
            if (xmlAnnotationSetList.Count == 0)
            {
                continue;
            }

            take = CreateTake(xmlTakeList.Item(j));
            if (take == null)
            {
                Debug.Log("ERROR creating class Take");
                return;
            }

            // Load Annotations
            //XmlNodeList xmlAnnotationSetList = xml.SelectNodes ("/annotation_document/session/take/annotations/annotation_set");
            int nNodes = xmlAnnotationSetList.Count;
            //Debug.Log ("annotation set count: " + nNodes);
            for (int i = 0; i < nNodes; i++)
            {
                //Debug.Log("annotation set name: " + xmlAnnotationSetList.Item(i).Name);
                XmlNodeList tmpList = xmlAnnotationSetList.Item(i).SelectNodes("annotation");
                //Debug.Log("annotation count: " + tmpList.Count);
                for (int w = 0; w < tmpList.Count; w++)
                {
                    XmlNode xmlAnnotation = tmpList.Item(w);

                    //	Debug.Log("type = " + xmlAnnotation.Attributes[0].InnerText);
                    switch (xmlAnnotation.Attributes [0].InnerText)
                    {
                    case "text":
                        AnnotationText annotation = CreateAnnotationText(xmlAnnotation);
                        if (annotation == null)
                        {
                            continue;
                        }

                        annotation.Type = "text";
                        textAnnotationList.Add(annotation);
                        Debug.Log("TEXT annotation");
                        continue;

                    case "mark":
                        AnnotationMark annotationMark = new AnnotationMark();
                        annotationMark.Type = "mark";
                        annotationMark      = (AnnotationMark)AddAnnotationCommonFields(xmlAnnotation, annotationMark);
                        markAnnotationList.Add(annotationMark);
                        Debug.Log("MARK annotation");
                        continue;

                    case "ink":
                        AnnotationInk annotationInk = new AnnotationInk();
                        annotationInk.Type = "ink";
                        annotationInk      = CreateAnnotationInk(xmlAnnotation);
                        inkAnnotationList.Add(annotationInk);
                        Debug.Log("INK annotation");
                        continue;

                    case "link":
                        AnnotationLink annotationLink = new AnnotationLink();
                        annotationLink.Type = "link";
                        annotationLink      = CreateAnnotationLink(xmlAnnotation);
                        linkAnnotationList.Add(annotationLink);
                        Debug.Log("LINK annotation");
                        continue;

                    case "audio":
                        Debug.Log("Audio annotation");
                        continue;

                    default:
                        continue;
                    }
                }
            }

            take.TextAnnotationList = textAnnotationList;
            take.InkAnnotationList  = inkAnnotationList;
            take.MarkAnnotationList = markAnnotationList;
            take.LinkAnnotationList = linkAnnotationList;
            Debug.Log("Number of Text Annotation: " + take.TextAnnotationList.Count);
            Debug.Log("Number of Mark Annotation: " + take.MarkAnnotationList.Count);
            Debug.Log("Number of Ink Annotation: " + take.InkAnnotationList.Count);
            Debug.Log("Number of Link Annotation: " + take.LinkAnnotationList.Count);
        }
    }