Example #1
0
        public virtual DrawingShape GetShape(CanvasEventArgs canvasEventArgs, TikzStyle style)
        {
            if (canvasEventArgs.MouseState == MouseState.DOWN)
            {
                dummy            = new DrawingShape(new TikzLine(new Shapes.ArrowLine(), null), ShapeState.START);
                previousMousePos = canvasEventArgs.Point;
            }
            else
            {
                Point  mousePos = canvasEventArgs.Point;
                Vector delta    = mousePos - previousMousePos;
                previousMousePos = mousePos;
                foreach (TikzShape s in shapes)
                {
                    Canvas.SetLeft(s.Shape, Canvas.GetLeft(s.Shape) + delta.X);
                    Canvas.SetTop(s.Shape, Canvas.GetTop(s.Shape) + delta.Y);
                }

                if (canvasEventArgs.MouseState == MouseState.UP)
                {
                    dummy.ShapeState = ShapeState.FINISHED;
                }
                else if (canvasEventArgs.MouseState == MouseState.MOVE)
                {
                    dummy.ShapeState = ShapeState.DRAWING;
                }
            }
            dummy.RemoveOnFinish = true;
            return(dummy);
        }
Example #2
0
        public static List <TikzShape> Parse(string data)
        {
            MatchCollection  matches = svgRegexes[0].Matches(data);
            List <TikzShape> result  = new List <TikzShape>();

            foreach (Match m in matches)
            {
                string line = m.Value;
                string d    = svgRegexes[1].Match(line).Groups[1].Value;
                System.Windows.Shapes.Path p = new System.Windows.Shapes.Path
                {
                    Data = Geometry.Parse(d)
                };
                //Parse style

                string rawStrokeColor     = GetSVGProperty(line, "stroke");
                string rawFillColor       = GetSVGProperty(line, "fill");
                string rawStrokeWidth     = GetSVGProperty(line, "stroke-width");
                string rawStrokeDasharray = GetSVGProperty(line, "stroke-dasharray");
                string rawStrokeOpacity   = GetSVGProperty(line, "stroke-opacity");
                string rawFillOpacity     = GetSVGProperty(line, "fill-opacity");

                double    strokeOpacity = double.TryParse(rawStrokeOpacity, out double o) ? o : 1.0;
                double    fillOpacity   = double.TryParse(rawFillOpacity, out double of) ? of : 1.0;
                TikzStyle s             = new TikzStyle(parseSVGColor(rawStrokeColor, strokeOpacity),
                                                        parseSVGColor(rawFillColor, fillOpacity), LineEnding.NONE, praseSVGStrokeWidth(rawStrokeWidth), parseSVGDashArray(rawStrokeDasharray));

                p.SetStyle(s);
                result.Add(new TikzPath(p, s, line));
            }

            return(result);
        }
Example #3
0
        public virtual DrawingShape GetShape(CanvasEventArgs canvasEventArgs, TikzStyle style)
        {
            if (canvasEventArgs.MouseState == MouseState.DOWN)
            {
                Rectangle rect = new Rectangle();
                rect.SetStyle(TikzStyle.SelectionStyle);
                current = new DrawingShape(new TikzRectangle(rect, null), ShapeState.START);
                current.RemoveOnFinish = true;
                firstPoint             = canvasEventArgs.Point;
            }
            else
            {
                current.TikzShape.Shape.Width  = Math.Abs(firstPoint.X - canvasEventArgs.Point.X);
                current.TikzShape.Shape.Height = Math.Abs(firstPoint.Y - canvasEventArgs.Point.Y);
                current.TikzShape.Shape.Margin = new Thickness(Math.Min(firstPoint.X, canvasEventArgs.Point.X), Math.Min(firstPoint.Y, canvasEventArgs.Point.Y), 0, 0);

                if (canvasEventArgs.MouseState == MouseState.UP)
                {
                    current.ShapeState = ShapeState.FINISHED;
                }
                else if (canvasEventArgs.MouseState == MouseState.MOVE)
                {
                    current.ShapeState = ShapeState.DRAWING;
                }
            }
            return(current);
        }
Example #4
0
 public TikzPath(Path path, TikzStyle style, string rawData) : base(path, style)
 {
     this.path    = path;
     this.rawData = rawData;
     pathData     = SVGParser.GetSVGProperty(rawData, "d");
     Canvas.SetLeft(this.path, 0);
     Canvas.SetTop(this.path, 0);
 }
Example #5
0
        public DrawingShape GetShape(CanvasEventArgs canvasEventArgs, TikzStyle style)
        {
            if (canvasEventArgs.MouseState == MouseState.DOWN)
            {
                Ellipse ellipse = new Ellipse
                {
                    StrokeThickness = style.LineWidth.GetLineWidth(),
                };

                ellipse.SetStyle(style);
                current    = new DrawingShape(new TikzEllipse(ellipse, style), ShapeState.START);
                firstPoint = canvasEventArgs.Point;
            }
            else
            {
                double x = Math.Min(canvasEventArgs.Point.X, firstPoint.X);
                double y = Math.Min(canvasEventArgs.Point.Y, firstPoint.Y);

                double w = Math.Max(canvasEventArgs.Point.X, firstPoint.X) - x;
                double h = Math.Max(canvasEventArgs.Point.Y, firstPoint.Y) - y;

                if (canvasEventArgs.ModKey)
                {
                    if (canvasEventArgs.Point.X > firstPoint.X)
                    {
                        w = h;
                    }
                    else if (canvasEventArgs.Point.Y > firstPoint.Y)
                    {
                        h = w;
                    }
                    else
                    {
                        double b = Math.Min(firstPoint.X - canvasEventArgs.Point.X, firstPoint.Y - canvasEventArgs.Point.Y);
                        w = b;
                        h = b;
                        x = firstPoint.X - b;
                        y = firstPoint.Y - b;
                    }
                }

                Canvas.SetLeft(current.TikzShape.Shape, x);
                Canvas.SetTop(current.TikzShape.Shape, y);

                current.TikzShape.Shape.Width  = w;
                current.TikzShape.Shape.Height = h;

                if (canvasEventArgs.MouseState == MouseState.UP)
                {
                    current.ShapeState = ShapeState.FINISHED;
                }
                else if (canvasEventArgs.MouseState == MouseState.MOVE)
                {
                    current.ShapeState = ShapeState.DRAWING;
                }
            }
            return(current);
        }
Example #6
0
 public static void SetStyle(this Shape s, TikzStyle style)
 {
     s.Stroke             = new SolidColorBrush(style.StrokeColor);
     s.Fill               = new SolidColorBrush(style.FillColor);
     s.StrokeThickness    = style.LineWidth.GetLineWidth();
     s.StrokeDashArray    = style.LineType.GetDashArray();
     s.StrokeStartLineCap = style.LineEnding.GetLineCaps()[0];
     s.StrokeEndLineCap   = style.LineEnding.GetLineCaps()[1];
     s.StrokeDashCap      = style.LineEnding.GetLineCaps()[2];
 }
Example #7
0
        public virtual DrawingShape GetShape(CanvasEventArgs canvasEventArgs, TikzStyle style)
        {
            if (canvasEventArgs.MouseState == MouseState.DOWN)
            {
                Rectangle rect = new Rectangle();
                rect.SetStyle(style);
                current = new DrawingShape(new TikzRectangle(rect, style), ShapeState.START);

                firstPoint = canvasEventArgs.Point;
            }
            else
            {
                double x = Math.Min(canvasEventArgs.Point.X, firstPoint.X);
                double y = Math.Min(canvasEventArgs.Point.Y, firstPoint.Y);

                double w = Math.Max(canvasEventArgs.Point.X, firstPoint.X) - x;
                double h = Math.Max(canvasEventArgs.Point.Y, firstPoint.Y) - y;

                if (canvasEventArgs.ModKey)
                {
                    if (canvasEventArgs.Point.X > firstPoint.X)
                    {
                        w = h;
                    }
                    else if (canvasEventArgs.Point.Y > firstPoint.Y)
                    {
                        h = w;
                    }
                    else
                    {
                        double b = Math.Min(firstPoint.X - canvasEventArgs.Point.X, firstPoint.Y - canvasEventArgs.Point.Y);
                        w = b;
                        h = b;
                        x = firstPoint.X - b;
                        y = firstPoint.Y - b;
                    }
                }

                Canvas.SetLeft(current.TikzShape.Shape, x);
                Canvas.SetTop(current.TikzShape.Shape, y);

                current.TikzShape.Shape.Width  = w;
                current.TikzShape.Shape.Height = h;

                if (canvasEventArgs.MouseState == MouseState.UP)
                {
                    current.ShapeState = ShapeState.FINISHED;
                }
                else if (canvasEventArgs.MouseState == MouseState.MOVE)
                {
                    current.ShapeState = ShapeState.DRAWING;
                }
            }
            return(current);
        }
Example #8
0
        public DrawingShape GetShape(CanvasEventArgs canvasEventArgs, TikzStyle style)
        {
            if (canvasEventArgs.MouseState == MouseState.DOWN)
            {
                firstPoint = canvasEventArgs.Point;
                ArrowLine line = new ArrowLine
                {
                    X1 = firstPoint.X,
                    X2 = firstPoint.X,
                    Y1 = firstPoint.Y,
                    Y2 = firstPoint.Y,
                };

                line.SetStyle(style);
                current = new DrawingShape(new TikzLine(line, style), ShapeState.START);
            }
            else
            {
                if (current.TikzShape.Shape is not ArrowLine l)
                {
                    throw new Exception("Shape-Tool type mismatch, tool type: LineTool, expected shape type Line");
                }

                l.X2 = canvasEventArgs.Point.X;
                l.Y2 = canvasEventArgs.Point.Y;

                if (canvasEventArgs.ModKey)
                {
                    //Snap mode, from start to one of axis contraints
                    //Axis constraints are divided by 45deg angles

                    //Get angle between start point and mouse pointer
                    //origin Axis X
                    double angle = Math.Atan2(l.Y2 - l.Y1, l.X2 - l.X1); //rads

                    //Determine constraint axis based on angle between X axis and current line
                    //22.5 -> pi/8

                    //X AXIS -> 0
                    //45 -> PI/4
                    //90 -> PI/2
                    //135 -> PI/2 + PI/4 = 3PI/4
                    //180 -> PI
                    //180 -> -PI
                    //225 -> -3PI/4
                    //270 -> -PI/2
                    //360 -> 0

                    double snapAngle = Math.Ceiling(angle / (Math.PI / 8.0)) * (Math.PI / 8.0);
                    //calculate new points based on snapAngle

                    double maxDim = Math.Max(Math.Abs(l.X2 - l.X1), Math.Abs(l.Y2 - l.Y1));
                    l.X2 = l.X1 + Math.Cos(snapAngle) * maxDim;
                    l.Y2 = l.Y1 + Math.Sin(snapAngle) * maxDim;
                }

                if (canvasEventArgs.MouseState == MouseState.UP)
                {
                    current.ShapeState = ShapeState.FINISHED;
                    Canvas.SetLeft(l, 0);
                    Canvas.SetTop(l, 0);
                }
                else if (canvasEventArgs.MouseState == MouseState.MOVE)
                {
                    current.ShapeState = ShapeState.DRAWING;
                }
            }

            return(current);
        }
Example #9
0
 public TikzEllipse(Ellipse ellipse, TikzStyle tikzStyle) : base(ellipse, tikzStyle)
 {
 }
Example #10
0
        public TikzLine(ArrowLine line, TikzStyle tikzStyle) : base(line, tikzStyle)
        {

        }
Example #11
0
 public TikzBezier(ArrowPath path, TikzStyle tikzStyle) : base(path, tikzStyle)
 {
 }
Example #12
0
 public TikzRectangle(Rectangle rectangle, TikzStyle tikzStyle) : base(rectangle, tikzStyle)
 {
 }
Example #13
0
 protected TikzShape(Shape shape, TikzStyle tikzStyle)
 {
     Shape     = shape;
     TikzStyle = tikzStyle;
 }
Example #14
0
 public virtual DrawingShape GetShape(CanvasEventArgs canvasEventArgs, TikzStyle style)
 {
     return(null);
 }
Example #15
0
        public DrawingShape GetShape(CanvasEventArgs a, TikzStyle style)
        {
            if (click == 0) // first click, draw a straight line
            {
                if (a.MouseState == MouseState.DOWN)
                {
                    //FIXME: small bug here, sometimes when a user clicks for the first time long line appears for a split second, noticeable but should not influence performance

                    firstPoint = a.Point;

                    bezier = new BezierSegment()
                    {
                        Point3 = a.Point.GetSystemPoint()
                    };
                    figure = new PathFigure();
                    figure.Segments.Add(bezier);
                    path = new ArrowPath();

                    path.SetStyle(style);
                    path.Margin = ShapeUtils.GetMargin(firstPoint.X, firstPoint.Y);

                    pf        = new PathFigure[] { figure };
                    path.Data = new PathGeometry(pf);

                    current = new DrawingShape(
                        new TikzBezier(path, style),
                        ShapeState.START
                        );
                }
                else if (a.MouseState == MouseState.MOVE)
                {
                    bezier.Point3 = GetPointWithoutMargin(firstPoint, a.Point);
                }
                else
                {
                    bezier.Point3 = GetPointWithoutMargin(firstPoint, a.Point);
                    click++;
                }

                return(current);
            }
            else if (click == 1) // second click, select first control point
            {
                if (a.MouseState == MouseState.DOWN)
                {
                    secondPointSelected = true;
                    bezier.Point1       = GetPointWithoutMargin(firstPoint, a.Point);
                }
                else if (a.MouseState == MouseState.MOVE)
                {
                    if (secondPointSelected)
                    {
                        bezier.Point1 = GetPointWithoutMargin(firstPoint, a.Point);
                    }
                }
                else
                {
                    bezier.Point1 = GetPointWithoutMargin(firstPoint, a.Point);
                    click++;
                }

                return(current);
            }
            else if (click == 2) // third click, select second control point
            {
                if (a.MouseState == MouseState.DOWN)
                {
                    thirdPointSelected = true;
                    bezier.Point2      = GetPointWithoutMargin(firstPoint, a.Point);
                }
                else if (a.MouseState == MouseState.MOVE)
                {
                    if (thirdPointSelected)
                    {
                        bezier.Point2 = GetPointWithoutMargin(firstPoint, a.Point);
                    }
                }
                else
                {
                    bezier.Point2      = GetPointWithoutMargin(firstPoint, a.Point);
                    current.ShapeState = ShapeState.FINISHED;
                    click = 0;
                    secondPointSelected = thirdPointSelected = false;
                }

                Canvas.SetLeft(current.TikzShape.Shape, 0);
                Canvas.SetTop(current.TikzShape.Shape, 0);

                return(current);
            }
            else
            {
                throw new Exception("Sth went wrong, bezier line should be drawn in 3 clicks");
            }
        }
Example #16
0
 public LocalShapeData(string toolName, List <CanvasEventArgs> keyPoints, TikzStyle style)
 {
     ToolName  = toolName;
     KeyPoints = keyPoints;
     Style     = style;
 }
Example #17
0
 private void RebuildStyle()
 {
     CurrentStyle = new TikzStyle(StrokeColor, FillColor, LineEnding, LineWidth, LineType);
 }