예제 #1
0
 public void addNodeCompletion(NodeCompletion n)
 {
     testCompletions.Add(n);
 }
예제 #2
0
        // Converts a string to a TestReplay object
        public void parseTestReplayFile(string testReplayString)
        {
            bool inActionSection = true;
            List<string> testStrings = 
                testReplayString.Split('\n').Cast<string>().ToList<string>();

            List<string> firstLineWords = testStrings[0].Split(' ').Cast<string>().ToList<string>();
            parsePatientInfo(firstLineWords);

            string startTimeString = testStrings[1];
            startTime = Convert.ToDateTime(startTimeString);

            int foundEndTestLine = 0;
            List<string> LEGACY_endTestCheckLine = testStrings[2].Split(' ').Cast<string>().ToList<string>();
            if (LEGACY_endTestCheckLine[0].Contains('/')) {
                string endTimeString = testStrings[2];
                endTime = Convert.ToDateTime(endTimeString);
                foundEndTestLine = 1;
            }

            for(int i = 2 + foundEndTestLine; i < testStrings.Count; i++)
            {
                if (inActionSection) {
                    List<string> lineWords = testStrings[i].Split(' ')
                        .Cast<string>().ToList<string>();
                    if (lineWords[0] == "line")
                        ((Stroke)testActions[testActions.Count - 1])
                            .addLineData(parseLineLineData(lineWords));
                    else if (lineWords[0] == "Stroke")
                        testActions.Add(parseLineStroke(lineWords));
                    else if (lineWords[0] == "DeleteStroke")
                        testActions.Add(parseLineDelPrevStroke(lineWords));
                    else if (lineWords[0] == "=====TIMES=====")
                    {
                        inActionSection = false;
                    }
                    else if (lineWords[0] == "=====ERRORS====")
                    {
                        inActionSection = false;
                    }     
                    else if (lineWords[0] == "=====NOTES=====") 
                    { 
                        inActionSection = false;
                    }     
                } else {
                    // Parse all the error objects. Each one should be three nodes plus a Date
                    List<string> lineWords = testStrings[i]
                        .Split('\t').Cast<string>().ToList<string>();

                    // This is a node completion object.
                    // Should be read as:
                    //begin   node '\t' point
                    //end     node '\t' point
                    //DateTime

                    if (lineWords.Count == 7)
                    {
                        NodeCompletion completion = new NodeCompletion();
                        // Get each of the node strings and points from the line
                        for (int j = 0; j < 6; j += 3)
                        {
                            string beginText = lineWords[j];
                            Point point;
                            point.X = Convert.ToDouble(lineWords[j + 1]);
                            point.Y = Convert.ToDouble(lineWords[j + 2]);
                            bool flip = true;
                            if (testType.ToString().Contains("_H"))
                                flip = false;
                            TrailNode node = new TrailNode(beginText, point, flip);

                            if (j == 0)
                                completion.setBegin(node);
                            if (j == 3)
                                completion.setEnd(node);
                        }

                        DateTime date = new DateTime();
                        date = Convert.ToDateTime(lineWords[6]);
                        completion.setTime(date);

                        testCompletions.Add(completion);
                    }

                    // This is an error object.
                    // Should be read as:
                    //begin   node '\t' point
                    //exp end node '\t' point
                    //act end node '\t' point
                    //DateTime

                    else if(lineWords.Count == 10)
                    {
                        TestError error = new TestError();
                        // Get each of the node strings and points from the line
                        for(int j = 0; j < 9; j += 3)
                        {
                            string beginText = lineWords[j];
                            Point point;
                            point.X = Convert.ToDouble(lineWords[j + 1]);
                            point.Y = Convert.ToDouble(lineWords[j + 2]);
                            bool flip = true;
                            if(testType.ToString().Contains("_H"))
                                flip = false;
                            TrailNode node = new TrailNode(beginText, point, flip);
                            
                            if(j == 0)
                                error.setBegin(node);
                            if (j == 3)
                                error.setExpected(node);
                            if (j == 6)
                                error.setActual(node);
                        }
                        
                        DateTime date = new DateTime();
                        date = Convert.ToDateTime(lineWords[9]);
                        error.setTime(date);

                        testErrors.Add(error);
                    }

                    else if (lineWords.Count >= 5)
                    {
                        DateTime date = new DateTime();
                        date = DateTime.Parse(lineWords[0] + " " + 
                            lineWords[1] + " " + lineWords[2]);
                        lineWords[3] = lineWords[3].Replace("[SPC]", "");
                        lineWords[4] = lineWords[4].Replace("[SPC]", "");
                        testNotes.Add(
                            new PatientNote(lineWords[3], lineWords[4], date));
                    }
                }
            }
        }
예제 #3
0
        private void MyCanvas_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            double x1, y1, x2, y2;
            int indexHit = -1;

            if (e.Pointer.PointerId == penId)
            {
                PointerPoint pt = e.GetCurrentPoint(MyCanvas);

                currentContactPt = pt.Position;
                x1 = previousContactPt.X;
                y1 = previousContactPt.Y;
                x2 = currentContactPt.X;
                y2 = currentContactPt.Y;

                //test whether the pointer has moved far enough to warrant drawing a new line
                if (Distance(x1, y1, x2, y2) > 2.0) 
                {
                    if (!pressed)
                    {
                        return;
                    }

                    //check if the stylus has collided with the "current" node to reset any error colors
                    indexHit = stylusHitTest(x2, y2);
                    if(indexHit == currentIndex)
                    {
                        nodes[currentIndex].setFillColor(new SolidColorBrush(Colors.Green));
                        resetIncorrectNodes(currentIndex + 1);
                    }

                    // The stylus has made contact with the correct next node.
                    if (indexHit == nextIndex)
                    {
                        // Start the timer keeping track of total time
                        if (!timer.IsRunning)
                        {
                            timer.Start();
                            testReplay.startTest();
                        }

                        NodeCompletion n = new NodeCompletion(nodes[currentIndex], nodes[nextIndex]);
                        testReplay.addNodeCompletion(n);

                        // Set the node completed value equal to true and change the color to Green
                        nodes[nextIndex].setFillColor(new SolidColorBrush(Colors.Green));
                        nodes[nextIndex].setComplete(true);

                        // Change the index of the next node to look for and the current index
                        currentIndex = nextIndex;
                        nextIndex++;

                        //reset the list of lines so that if an error is made, the lines just drawn do not get erased
                        currentEdge.Clear();


                        //if the test is done, this code is executed
                        if (nextIndex >= nodes.Count)
                        {
                            
                            timer.Stop();
                            MyCanvas.PointerPressed -= MyCanvas_PointerPressed;
                            MyCanvas.PointerMoved -= MyCanvas_PointerMoved;
                            MyCanvas.PointerReleased -= MyCanvas_PointerReleased;
                            MyCanvas.PointerExited -= MyCanvas_PointerReleased;

                            inkManager.ProcessPointerUp(pt);

                            testReplay.endStroke();
                            testReplay.endTest();

                            submitButton.IsEnabled = true;
                            submitButton.IsHitTestVisible = true;

                            saveButton.IsEnabled = true;
                            saveButton.IsHitTestVisible = true;
                            
                            allLines.Add(inkManager.GetStrokes()[inkManager.GetStrokes().Count - 1], currentLine);
                            currentLine = new List<Line>();
                            finished = true;
                            return;
                        }
                    }
                    // Stylus did not contact the next node in the correct order.
                    // Need to change the color of the corrected node to Yellow and the
                        // incorrect node hit to red to notify the user this is not correct.
                    else if ((indexHit >= 0) && indexHit > currentIndex)
                    {
                        //set error colors
                        if (incorrectNodes.Count < 1)
                        {
                            nodes[indexHit].setFillColor(new SolidColorBrush(Colors.Red));
                            testReplay.addError(new TestError(nodes[currentIndex], nodes[nextIndex],nodes[indexHit]));
                        }
                        nodes[currentIndex].setFillColor(new SolidColorBrush(Colors.Yellow));

                        //reset the index back 1
                        nextIndex = currentIndex;

                        if (!incorrectNodes.Contains(currentIndex))
                            incorrectNodes.Enqueue(currentIndex);

                        if (!incorrectNodes.Contains(indexHit))
                            incorrectNodes.Enqueue(indexHit);

                        //erase the line just drawn from previous node to the incorrect node
                        foreach (Line l in currentEdge)
                        {
                            MyCanvas.Children.Remove(l);
                        }
                        testReplay.endStroke();
                        testReplay.deleteStroke(testReplay.getTestActions().Count-1);
                    }
                    
                        Line line = new Line()
                        {
                            X1 = x1,
                            X2 = x2,
                            Y1 = y1,
                            Y2 = y2,
                            StrokeThickness = DRAW_WIDTH,
                            Stroke = new SolidColorBrush(DRAW_COLOR)
                        };
                        currentLine.Add(line);
                        currentEdge.Add(line);
                        MyCanvas.Children.Add(line);

                        testReplay.addLine(line);
                    
                    if(!finished)
                        inkManager.ProcessPointerUpdate(pt);
                    previousContactPt = currentContactPt;
                }
            }

            else if (e.Pointer.PointerId == touchId)
            {
                // Process touch input (finger input)
            }
            e.Handled = true;
        }