Пример #1
0
        static Stroke UndoStroke(Queue<SupportedString> lines, Stack<Stroke> undoStack, StrokeCreation strokeType)
        {
            Stroke toCopy = undoStack.Pop();
            Stroke newOne = new Stroke();
            newOne.LineNumber = lines.Peek().LineNumber;
            newOne.PenType = UndoOf(toCopy.PenType);
            newOne.Recorded = false;
            newOne.SimultaneousMaxTemplatesUsed = 0;
            newOne.Viewbox = toCopy.Viewbox;
            newOne.Templates = new List<TemplateInfo>();
            newOne.InputMouse = toCopy.InputMouse;
            newOne.OutputStroke = toCopy.OutputStroke;
            newOne.StrokeType = strokeType;

            return newOne;
        }
Пример #2
0
        static Stroke ExtractStroke(Queue<SupportedString> lines, AppState p)
        {
            Stroke s = new Stroke();

            // assign a view box to this stroke
            if (p.ViewBox.Length > 0)
            {
                string [] parts = p.ViewBox.Split(new char[] {'{','=',',','}'});
                s.Viewbox = new System.Windows.Rect(
                    Double.Parse( parts[2]),
                    Double.Parse(parts[4]),
                    Double.Parse(parts[6]),
                    Double.Parse(parts[8]));
            }

            {
                SupportedString line = lines.Dequeue();
                s.LineNumber = line.LineNumber;
                string dateTimeSpecial = line.Line.Split(new char[] { '/' })[2];
                dateTimeSpecial = dateTimeSpecial.Substring(0, dateTimeSpecial.IndexOf(',') - 1);
                s.Timestamp = DateTime.Parse(dateTimeSpecial);
            }

            s.PenType = p.PenType;
            if (p.PenType == PenType.Ink || p.PenType == PenType.UndoInk)
                s.StrokeWidth = 2;
            else
                s.StrokeWidth = p.EraserSize;
            s.StrokeType = StrokeCreation.New;

            string[] split = lines.Peek().Line.Split('/');
            while (!"stroke_ended".Equals(split[ACTION]))
            {
                if ("_input_stroke".Equals(split[ACTION]))
                {
                    s.InputMouse =  ShiftPoints( GetPointsFromString(split[OTHER]), new System.Windows.Vector(-s.Viewbox.Left,-s.Viewbox.Top));
                }
                else if ("_template_used".Equals(split[ACTION]))
                {
                    // get some template info
                    string templateKey = split[ITEM] + "[" + split[ITEM_ID] + "]";
                    if (!p.Templates.ContainsKey(templateKey))
                    {
                        // force extraction of template if it didn't exist before
                        Console.WriteLine("template " + templateKey + " used without being defined");
                        ExtractTemplate(split, p);
                    }
                    TemplateLog tl =  p.Templates[templateKey];
                    string strength = "default";
                    if (tl.ContainsKey("change_template_strength"))
                        strength = tl["change_template_strength"];

                    s.Templates.Add(new TemplateInfo()
                        {
                            TemplateName = split[ITEM].Replace("TemplateFilter",""),
                            TimesEntered = int.Parse( split[OTHER]),
                            UID = int.Parse(split[ITEM_ID]),
                            TemplateStrength = strength
                        });

                }
                else if ("_simultaneous_templates_max_used".Equals(split[ACTION]))
                {
                    s.SimultaneousMaxTemplatesUsed = int.Parse(split[OTHER]);
                }
                else if ("_output_stroke".Equals(split[ACTION]))
                {
                    s.OutputStroke = ShiftPoints(GetPointsFromString(split[OTHER]), new System.Windows.Vector(-s.Viewbox.Left,-s.Viewbox.Top));
                }
                else if ("_stroke_path".Equals(split[ACTION]))
                {
                    if (s.OutputStroke.Count == 0)
                    {
                        s.OutputStroke = ShiftPoints(GetPointsFromString(split[OTHER]), new System.Windows.Vector(-s.Viewbox.Left,-s.Viewbox.Top));
                        if (s.OutputStroke.Count > 0)
                            System.Console.WriteLine("_stroke_path used because _output_stroke missing");
                    }

                }
                else if ("replay_recorded_movement".Equals(split[ACTION]))
                {
                    s.Recorded = true;
                }
                else
                {
                    System.Console.WriteLine("Could not understand {0}", split[ACTION]);
                }

                lines.Dequeue();
                split = lines.Peek().Line.Split('/');
            }

            return s;
        }