コード例 #1
0
        public override void OnMouseMove(Point p, TEMouseArgs e)
        {
            base.OnMouseMove(p, e);

            //Point mousep = e.GetPosition(overlay.canvas);
            Point mousep = overlay.Rasterizer.RasterizePixel(p);

            ////mousep = new Point(mousep.X, overlay.canvas.ActualHeight - mousep.Y);
            mousep = new Point(mousep.X, overlay.Height - mousep.Y);
            if (PreviewEllipse.Visible)
            {
                // compute rotated diagonal
                double angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform);
                //TikzMatrix R
                TikzMatrix R       = TikzMatrix.RotationMatrix(-angle);
                Vector     newdiag = R.Transform(mousep - origin);

                double width  = Math.Abs(newdiag.X),  // actually half the width/height!
                       height = Math.Abs(newdiag.Y);
                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                {
                    width = height = Math.Max(width, height);
                }

                R = R.Inverse();
                Point topleft = origin + R.Transform(new Vector(-width, -height));

                PreviewEllipse.SetPosition(topleft.X, topleft.Y, 2 * width, 2 * height);
            }
        }
コード例 #2
0
        public override void OnMouseMove(Point p, TEMouseArgs e)
        {
            base.OnMouseMove(p, e);

            //Point mousep = e.GetPosition(overlay.canvas);
            Point mousep = overlay.Rasterizer.RasterizePixel(p);

            ////mousep = new Point(mousep.X, overlay.canvas.ActualHeight - mousep.Y);
            mousep = new Point(mousep.X, overlay.Height - mousep.Y);
            if (PreviewRect.Visible)
            {
                // compute rotated diagonal
                double     angle   = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform);
                TikzMatrix R       = TikzMatrix.RotationMatrix(-angle);
                Vector     newdiag = R.Transform(mousep - origin);

                // update the size and position of the preview rect
                double width, height;
                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                {
                    // both sides the same
                    width   = height = Math.Max(Math.Abs(newdiag.X), Math.Abs(newdiag.Y));
                    newdiag = new Vector(Math.Sign(newdiag.X) * width, Math.Sign(newdiag.Y) * height);
                }
                else
                {
                    width  = Math.Abs(newdiag.X);
                    height = Math.Abs(newdiag.Y);
                }

                R = R.Inverse();
                Point topleft = origin + R.Transform(new Vector(Math.Min(0, newdiag.X), Math.Min(0, newdiag.Y)));

                //double x = (newdiag.X<0 ?  mousep.X : origin.X),
                //       y = (newdiag.Y<0 ?  mousep.Y : origin.Y);
                //SelectionRect.RenderTransform = new TranslateTransform(x, y);
                PreviewRect.SetPosition(topleft.X, topleft.Y, width, height);
            }
        }
コード例 #3
0
        public override void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
        {
            // add the rectangle
            if (PreviewRect.Visible)
            {
                if (!EnsureParseTreeExists())
                {
                    return;
                }

                Point firstpoint  = overlay.ScreenToTikz(origin, true);
                Point secondpoint = overlay.Rasterizer.RasterizePixelToTikz(p);

                double     angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform);
                TikzMatrix R     = TikzMatrix.RotationMatrix(angle);
                TikzMatrix RI    = R.Inverse();

                Point firstpointR = R.Transform(firstpoint), secondpointR = R.Transform(secondpoint);

                if (ForcePointsBLTR)
                {
                    // ensure first pt is bottom left, second top right
                    Rect r = new Rect(firstpointR, secondpointR);
                    firstpointR  = r.TopLeft; // note that we use upside down coordinates, so the c# notations are different
                    secondpointR = r.BottomRight;
                    firstpoint   = RI.Transform(firstpointR);
                    secondpoint  = RI.Transform(secondpointR);
                }

                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                {
                    // both sides the same
                    double sidelength = Math.Max(Math.Abs(firstpointR.X - secondpointR.X), Math.Abs(firstpointR.Y - secondpointR.Y));
                    secondpointR = new Point(
                        firstpointR.X + Math.Sign(secondpointR.X - firstpointR.X) * sidelength,
                        firstpointR.Y + Math.Sign(secondpointR.Y - firstpointR.Y) * sidelength);
                    secondpoint = RI.Transform(secondpointR);
                }

                overlay.BeginUpdate();

                if (AddNewCurAddTo())
                {
                    Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord();
                    tc1.type = overlay.UsePolarCoordinates? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                    Parser.Tikz_Coord tc2 = new Parser.Tikz_Coord();
                    tc2.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;

                    curAddTo.AddChild(new Parser.Tikz_Something(" "));
                    curAddTo.AddChild(tc1);
                    curAddTo.AddChild(new Parser.Tikz_Something(codeToInsert));
                    curAddTo.AddChild(tc2);

                    if (originRef == null)
                    {
                        tc1.SetAbsPos(firstpoint);
                    }
                    else
                    {
                        Tikz_Node tn = MakeReferenceableNode((originRef as OverlayNode).tikzitem);
                        tc1.type    = Tikz_CoordType.Named;
                        tc1.nameref = tn.name;
                    }

                    OverlayShapeVM hit = overlay.ObjectAtCursor;
                    if ((hit is OverlayNode) && IsReferenceable(hit as OverlayNode))
                    {
                        Tikz_Node tn = MakeReferenceableNode((hit as OverlayNode).tikzitem);
                        tc2.type    = Tikz_CoordType.Named;
                        tc2.nameref = tn.name;
                    }
                    else
                    {
                        tc2.SetAbsPos(secondpoint);
                    }

                    //           overlay.AddToDisplayTree(tc1);
                    //           overlay.AddToDisplayTree(tc2);

                    curAddTo.UpdateText();
                }

                overlay.EndUpdate();

                PreviewRect.Visible = false;
            }
        }
コード例 #4
0
        public override void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
        {
            // add the rectangle
            if (PreviewEllipse.Visible)
            {
                if (!EnsureParseTreeExists())
                {
                    return;
                }

                Point center      = overlay.ScreenToTikz(origin, true);
                Point secondpoint = overlay.Rasterizer.RasterizePixelToTikz(p); // in axis aligned (untranformed) tikz coordinates

                // compute rotated diagonal
                double     angle   = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform);
                TikzMatrix R       = TikzMatrix.RotationMatrix(angle);
                Vector     newdiag = R.Transform(secondpoint - center);

                double width  = Math.Abs(newdiag.X),  // actually half the width/height!
                       height = Math.Abs(newdiag.Y);

                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                {
                    width = height = Math.Max(width, height);
                }

                overlay.BeginUpdate();

                if (AddNewCurAddTo())
                {
                    Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord();
                    tc1.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;

                    curAddTo.AddChild(new Parser.Tikz_Something(" "));
                    curAddTo.AddChild(tc1);
                    // since there might be a coordinate tranform, the width/height have to be transformed
                    // (note: rotates are not very well supported here)
                    TikzMatrix M;
                    if (curAddTo.GetCurrentTransformAt(tc1, out M))
                    {
                        R = R.Inverse();
                        Point size_trans = M.Inverse().Transform(R.Transform(new Point(width, height)), true);
                        width  = size_trans.X;
                        height = size_trans.Y;
                    }
                    else
                    {
                        GlobalUI.UI.AddStatusLine(this, "Warning: Couldn't compute tranform at insertion position. Coordinates might be wrong.", true);
                    }

                    width  = Math.Round(width, (int)CompilerSettings.Instance.RoundToDecimals);
                    height = Math.Round(height, (int)CompilerSettings.Instance.RoundToDecimals);

                    if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control) && width == height)
                    {
                        curAddTo.AddChild(new Parser.Tikz_Something(" circle (" + width + ")"));
                    }
                    else
                    {
                        curAddTo.AddChild(new Parser.Tikz_Something(" ellipse (" + width + " and " + height + ")"));
                    }

                    if (originRef == null)
                    {
                        tc1.SetAbsPos(center);
                    }
                    else
                    {
                        Tikz_Node tn = MakeReferenceableNode((originRef as OverlayNode).tikzitem);
                        tc1.type    = Tikz_CoordType.Named;
                        tc1.nameref = tn.name;
                    }

                    //          overlay.AddToDisplayTree(tc1);

                    curAddTo.UpdateText();
                }

                overlay.EndUpdate();

                PreviewEllipse.Visible = false;
            }
        }
コード例 #5
0
ファイル: ArcTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
            {
                return;
            }

            Point ptikz = overlay.Rasterizer.RasterizePixelToTikz(p);

            p = overlay.Rasterizer.RasterizePixel(p);
            if (ContinueWithBigImage(ptikz) == false)
            {
                return;
            }

            if (pointcount == 0)
            {
                //overlay.SetCorrectRaster(overlay.CurEditing, true);
                center = ptikz;

                // set raster to polar, and such that origin is at center
                overlay.Rasterizer.View.IsCartesian = false;
                TikzMatrix M = overlay.Rasterizer.View.CoordinateTransform;
                M.m[0, 2] = center.X;
                M.m[1, 2] = center.Y;
                overlay.Rasterizer.View.CoordinateTransform = M;
                pointcount = 1;

                PreviewPie.center = PreviewArc.center = new Point(p.X, overlay.Height - p.Y);

                ////if (!overlay.canvas.Children.Contains(PreviewArc))
                ////    overlay.canvas.Children.Add(PreviewArc);
                ////if (!overlay.canvas.Children.Contains(PreviewPie))
                ////    overlay.canvas.Children.Add(PreviewPie);
            }
            else if (pointcount == 1)
            {
                p1            = ptikz;
                pointcount    = 2;
                PreviewPie.p1 = PreviewArc.p2 = new Point(p.X, overlay.Height - p.Y);

                // compute radius
                TikzMatrix M    = overlay.Rasterizer.View.CoordinateTransform;
                Point      ploc = M.Inverse().Transform(p1);
                overlay.Rasterizer.View.ForceRadiusTo = (ploc - (new Point(0, 0))).Length;
            }
            else if (pointcount == 2)
            {
                // **** create arc / pie ****
                overlay.BeginUpdate();
                // find next tikzpicture and add
                if (AddNewCurAddTo()) //(EnsureCurAddToExists(out lcreated))
                {
                    // Pie?
                    if (IsPie)
                    {
                        // create new coordinate
                        Tikz_Coord tc = new Parser.Tikz_Coord();
                        tc.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                        curAddTo.AddChild(tc);
                        tc.SetAbsPos(center);
                        curAddTo.AddChild(new Parser.Tikz_Something(" -- "));
                    }

                    Tikz_Coord tc1 = new Parser.Tikz_Coord();
                    if (IsPie)
                    {
                        tc1.type = Tikz_CoordType.Polar;
                        tc1.deco = "++";
                    }
                    curAddTo.AddChild(tc1);
                    tc1.SetAbsPos(p1);
                    curAddTo.AddChild(new Parser.Tikz_Something(" "));

                    // create arc
                    Tikz_Arc ta = new Tikz_Arc();
                    curAddTo.AddChild(ta);
                    ta.SetFromPoints(center, ptikz, IsLargeArc);

                    if (IsPie)
                    {
                        curAddTo.AddChild(new Parser.Tikz_Something(" -- cycle"));
                    }

                    //tn.UpdateText();
                    curAddTo.UpdateText();
                    //tpict.UpdateText();

                    // draw the added object in the overlay
                    overlay.AddToDisplayTree(curAddTo);
                }

                overlay.EndUpdate();

                // reset everything
                pointcount = 0;
                overlay.Rasterizer.View.ForceRadiusTo = -1;
                overlay.SetCorrectRaster(overlay.CurEditing, true);
            }
            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);
            UpdatePreviewDisplay(p);
        }
コード例 #6
0
 public static Matrix ToWpfMatrix(this TikzMatrix M)
 {
     // Which is correct? I think the first
     return(new Matrix(M.m[0, 0], M.m[1, 0], M.m[0, 1], M.m[1, 1], M.m[0, 2], M.m[1, 2]));
     //return new Matrix(m[0, 0], m[0, 1], m[1, 0], m[1, 1], m[0, 2], m[1, 2]);
 }
コード例 #7
0
ファイル: PdfOverlayModel.cs プロジェクト: wilsoc5/tikzedt
        public void SetCorrectRaster(TikzParseItem tpi, bool IsParent = false)
        {
            if (ParseTree == null)
            {
                return;
            }
            if (tpi == null)
            {
                Tikz_Picture tp = ParseTree.GetTikzPicture();
                if (tp != null)
                {
                    TikzMatrix M;
                    if (!tp.GetCurrentTransformAt(null, out M))
                    {
                        Rasterizer.View.CoordinateTransform = new TikzMatrix();   // if the program gets here, the global coord. transformation could not be understood->ovelay should display nothing
                    }
                    else
                    {
                        Rasterizer.View.CoordinateTransform = M;
                    }
                    //rasterizer.RasterOrigin = M.Transform(new Point(0, 0));
                    //rasterizer.RasterScale = M.m[1, 1];
                    Rasterizer.View.IsCartesian = !UsePolarCoordinates;
                }
            }
            else if (tpi is Tikz_Scope)
            {
                Tikz_Scope ts = tpi as Tikz_Scope;
                TikzMatrix M;
                if (IsParent)
                {
                    if (!ts.GetCurrentTransformAt(null, out M)) // todo
                    {
                        M = new TikzMatrix();                   // broken coords-> take unity as backup
                    }
                }
                else
                {
                    //if (!ts.parent.GetCurrentTransformAt(ts, out M))
                    //    M = new TikzMatrix();
                    if (!ts.GetRasterTransform(out M))
                    {
                        M = new TikzMatrix();
                    }
                }
                Rasterizer.View.CoordinateTransform = M;
                //rasterizer.RasterOrigin = M.Transform(new Point(0, 0));
                //rasterizer.RasterScale = M.m[1, 1];
                Rasterizer.View.IsCartesian = !IsParent || !UsePolarCoordinates;
            }
            else if (tpi is Tikz_XYItem)
            {
                Tikz_XYItem t = tpi as Tikz_XYItem;
                Point       offset;
                if (t.GetAbsPos(out offset, true))
                {
                    TikzMatrix M;
                    if (!t.parent.GetCurrentTransformAt(t, out M)) //.CloneIt();
                    {
                        M = new TikzMatrix();
                    }

                    M.m[0, 2] = offset.X;
                    M.m[1, 2] = offset.Y;
                    //rasterizer.RasterScale = M.m[1, 1];
                    Rasterizer.View.CoordinateTransform = M;
                    Rasterizer.View.IsCartesian         = !(t.IsPolar());
                }
                else
                {
                    throw new Exception("In PdfOverlay: Encountered drawn item without valid coordinates");
                }
            }
            else if (tpi is Tikz_Path)
            {
                Tikz_Path  ts = tpi as Tikz_Path;
                TikzMatrix M;
                if (IsParent)
                {
                    Point curPointAtEnd;
                    if (!ts.GetCurrentTransformAt(null, out M)) // todo
                    {
                        M = new TikzMatrix();                   // broken coords-> take unity as backup
                    }
                    if (ts.GetAbsOffset(out curPointAtEnd, null))
                    {
                        M.m[0, 2] = curPointAtEnd.X;
                        M.m[1, 2] = curPointAtEnd.Y;
                    }
                }
                else
                {
                    if (!ts.parent.GetCurrentTransformAt(ts, out M))
                    {
                        M = new TikzMatrix();
                    }
                    //if (!ts.GetRasterTransform(out M))
                    //    M = new TikzMatrix();
                }
                Rasterizer.View.CoordinateTransform = M;
                //rasterizer.RasterOrigin = M.Transform(new Point(0, 0));
                //rasterizer.RasterScale = M.m[1, 1];
                Rasterizer.View.IsCartesian = !IsParent || !UsePolarCoordinates;
            }
            else
            {
                Debug.WriteLine("Error in SetCorrectRaster: unsupported type");//Rasterizer.IsCartesian = true;  // should not get here
            }
        }