Пример #1
0
        IEnumerable <OverlayShapeVM> GetAllDescendants(OverlayShapeVM OfParent = null)
        {
            IEnumerable <OverlayShapeVM> src = null;
            List <OverlayShapeVM>        ret = new List <OverlayShapeVM>();

            if (OfParent != null)
            {
                ret.Add(OfParent);
            }
            else
            {
                src = TopLevelItems;
            }

            if (OfParent is OverlayScope)
            {
                src = (OfParent as OverlayScope).children;
            }

            if (src != null)
            {
                ret.AddRange(src.SelectMany(os => GetAllDescendants(os)));
            }

            return(ret);
        }
Пример #2
0
        /// <summary>
        /// Determines whether the object represented by the OverlayShape item can be
        /// given a reference to. This is the case, e.g., for standard coordinates. It is
        /// however not the case for the coordinates in a smooth curve.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected bool IsReferenceable(OverlayShapeVM item)
        {
            if (!(item is OverlayNode))
            {
                return(false);
            }

            Tikz_XYItem it = (item as OverlayNode).tikzitem;

            // check whether item occurs in smooth curve
            // we check whether the parent's parent has the word "coordinates" preceding the parent (this is a bit of a hack)
            if (it is Tikz_Coord && (it.parent.parent is Tikz_Path))
            {
                Tikz_Path grandpa = it.parent.parent as Tikz_Path;
                for (int i = grandpa.Children.IndexOf(it.parent) - 1; i > 0; i--)
                {
                    if (!(grandpa.Children[i] is Tikz_Something))
                    {
                        break;
                    }
                    if (grandpa.Children[i].text.ToLower().Contains("coordinates"))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #3
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
            {
                return;
            }

            overlay.BeginUpdate();

            overlay.SetCorrectRaster(overlay.CurEditing, true);

            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);
            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
            {
                return;
            }

            // find next tikzpicture and add
            Parser.Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture();
            if (tpict != null)
            {
                Parser.Tikz_Node tn = new Parser.Tikz_Node();
                tn.label = "";
                tn.coord = new Parser.Tikz_Coord();
                if (!String.IsNullOrEmpty(overlay.NodeStyle))
                {
                    tn.options = "[" + overlay.NodeStyle + "]";
                }

                Parser.Tikz_Path tp = new Parser.Tikz_Path();
                tp.starttag = @"\node ";
                tp.endtag   = ";";

                tp.AddChild(tn);
                if (overlay.CurEditing != null)
                {
                    overlay.CurEditing.tikzitem.AddChild(tp);
                    overlay.CurEditing.tikzitem.AddChild(new Parser.Tikz_Something("\r\n"));
                }
                else
                {
                    tpict.AddChild(tp);
                    tpict.AddChild(new Parser.Tikz_Something("\r\n"));
                }
                // do it here since the coordinate calculation needs the parents' coord. transform
                tn.SetAbsPos(new Point(p.X, p.Y)); //hack

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

                //RedrawObjects();
                //         overlay.AddToDisplayTree(tp);
            }

            overlay.EndUpdate();
        }
Пример #4
0
        /// <summary>
        /// Tries to display a ring around the object at text position
        /// offset.
        /// </summary>
        /// <param name="offset">The text position.</param>
        public void MarkObjectAt(int offset)
        {
            OverlayShapeVM ols = DisplayTree.ObjectFromOffset(offset);

            if (ols != null)
            {
                View.MarkObject(ols);
            }
        }
Пример #5
0
 /// <summary>
 /// Adds an item to the list of selected items.
 /// </summary>
 /// <param name="o">The item to add.</param>
 /// <param name="Exclusive">If Exclusive is set, all other items are unselected.</param>
 public void AddItem(OverlayShapeVM o, bool Exclusive = false)
 {
     if (Exclusive)
         Clear(o);
     if (!SelectedItems.Contains(o))
     {
         o.IsSelected = true;
         SelectedItems.Add(o);
     }
 }
Пример #6
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {

            if (item != null)
            {
                // initiate a drag/drop operation
                curDragged = (OverlayShapeVM)item;
                DragOrigin = (new Point(item.Center.X, item.Center.Y)) - (Vector)p;
                ////DragOrigin = e.GetPosition(item);
                ////DragOrigin = new Point(DragOrigin.X, (item as OverlayShape).Height - DragOrigin.Y);
                DragOriginC = p;
                DragOriginO = new Point(curDragged.Center.X, curDragged.Center.Y);
                movedenough = false;
                //MessageBox.Show(o.ToString());

                // select the clicked shape
      /*          if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
                {
                    if (!ToggleItem(curDragged))
                    {
                        // unselected -> start no drag operation
                        curDragged = null;
                    }
                }
                else
                {
                    AddItem(curDragged, !IsItemSelected(curDragged));
                }*/

                // adjust raster origin/scale/polar/cartesian
                overlay.SetCorrectRaster(curDragged);

                // for an arc, display preview
                //if (curDragged.item is Tikz_Arc)
                //{
                    FillNodesOnArc();
                    //check whether starting moving arc was successful
                    if (PreviewArc.Spokes == null)
                    {
                        SetCursorNo();
                        curDragged = null;
                        return;
                    }
                    AdjustPreviewPos(p);
                    PreviewArc.Visible = true;
                //}

                // capture mouse. this is important if the user drags sth. outside canvas1's bounds
                if (curDragged != null) 
                    overlay.MouseCaptured = true;
            }
            


        }
Пример #7
0
        public override void OnRightMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            //base.OnRightMouseButtonDown(item, p, e);

            // if a node is selected, unselect it
            if (curSel != null)
            {
                curSel    = null;
                e.Handled = true;   // we don't want anything else to happen (contextmenu opening etc)
            }
        }
Пример #8
0
 OverlayShapeVM ObjectFromOffset(int offset, List <OverlayShapeVM> bag)
 {
     foreach (OverlayShapeVM ols in bag)
     {
         if (ols.item.StartPosition() <= offset && ols.item.StartPosition() + ols.item.ToString().Length > offset)
         {
             // check if there is a child that fits better
             if (ols is OverlayScope)
             {
                 OverlayShapeVM olsinner = ObjectFromOffset(offset, (ols as OverlayScope).children);
                 if (olsinner != null)
                 {
                     return(olsinner);
                 }
             }
             return(ols);
         }
     }
     return(null);
 }
Пример #9
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            // initiate drawing process
            Point mousep = overlay.Rasterizer.RasterizePixel(p);
            origin = new Point(mousep.X, overlay.Height - mousep.Y);

            if (IsReferenceable(item))
                originRef = item;
            else
                originRef = null;

            PreviewRect.SetPosition(origin.X, origin.Y, 0,0);

            // adjust rotation in case we are in a rotated frame
            double angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform) * 180 / Math.PI;
            PreviewRect.Rotation = angle;

            ////if (!overlay.canvas.Children.Contains(PreviewRect))
            ////    overlay.canvas.Children.Add(PreviewRect);
            /////PreviewRect.Visibility = Visibility.Visible;
            PreviewRect.Visible = true;

            overlay.MouseCaptured = true;
        }
Пример #10
0
        IEnumerable<OverlayShapeVM> GetAllDescendants(OverlayShapeVM OfParent = null)
        {
            IEnumerable<OverlayShapeVM> src = null;
            List<OverlayShapeVM> ret = new List<OverlayShapeVM>();
            if (OfParent != null)
                ret.Add(OfParent);
            else src = TopLevelItems;

            if (OfParent is OverlayScope)
                src = (OfParent as OverlayScope).children;

            if (src != null)
                ret.AddRange(src.SelectMany(os => GetAllDescendants(os)));

            return ret;
        }
Пример #11
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
            {
                return;
            }

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

            overlay.BeginUpdate();

            //overlay.SetCorrectRaster(overlay.CurEditing, true);
            UpdateRaster();
            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);


            // find next tikzpicture and add
            bool lcreated;

            if (EnsureCurAddToExists(out lcreated))
            {
                // on double click -> close path
                if (e.ClickCount == 2)
                {
                    if (!lcreated)
                    {
                        //if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
                        curAddTo.AddChild(new Parser.Tikz_Something(" -- cycle"));
                        //else
                        //    curAddTo.AddChild(new Parser.Tikz_Something(" cycle"));
                    }
                }
                else
                {
                    if (!lcreated)
                    {
                        if (!overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                        {
                            // add an edge
                            curAddTo.AddChild(new Parser.Tikz_Something(" -- "));
                        }
                        else
                        {
                            curAddTo.AddChild(new Parser.Tikz_Something(" "));
                        }
                    }

                    // create new coordinate. If some node was clicked, set a reference to that node. Otherwise, just make new coordinates
                    Tikz_Coord tc = new Tikz_Coord();
                    if (item is OverlayNode && IsReferenceable(item))
                    {
                        Tikz_Node tn = MakeReferenceableNode((item as OverlayNode).tikzitem);
                        tc.type    = Tikz_CoordType.Named;
                        tc.nameref = tn.name;
                        curAddTo.AddChild(tc);
                    }
                    else
                    {
                        // do it here since the coordinate calculation needs the parents' coord. transform
                        tc.type = overlay.UsePolarCoordinates ? Tikz_CoordType.Polar : Tikz_CoordType.Cartesian;
                        if (!lcreated)
                        {
                            tc.deco = overlay.NewNodeModifier;  // first node should always be in absolute coordinates
                        }
                        curAddTo.AddChild(tc);
                        tc.SetAbsPos(new Point(p.X, p.Y)); //hack

                        // if a nonempty node style is selected, also add a node with that style
                        if (!String.IsNullOrWhiteSpace(overlay.NodeStyle))
                        {
                            Tikz_Node tn = new Tikz_Node()
                            {
                                options = "[" + overlay.NodeStyle + "]",
                                coord   = null,
                                text    = ""
                            };
                            curAddTo.AddChild(new Tikz_Something(" "));
                            curAddTo.AddChild(tn);
                        }
                    }
                    //tn.UpdateText();
                    curAddTo.UpdateText();
                    //tpict.UpdateText();

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

            overlay.EndUpdate();
            UpdateRaster();

            // doubleclick also stops path drawing
            if (e.ClickCount == 2)
            {
                overlay.ActivateDefaultTool();
            }
        }
Пример #12
0
 public bool IsItemSelected(OverlayShapeVM o)
 {
     return SelectedItems.Contains(o);
 }
Пример #13
0
 void IPdfOverlayView.JumpToSourceDoIt(OverlayShapeVM o)
 {
     if (JumpToSource != null)
     {
         TikzParseItem tpi = o.item;
         if (tpi != null)
             JumpToSource(this, new JumpToSourceEventArgs() { JumpToPos = tpi.StartPosition(), SelectionLength = tpi.Length });
     }
 }
Пример #14
0
        public override void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
        {
            if (SelectionRect.Visible)
            {
                SelectionRect.Visible = false;
            }

            // adjust position of dragged item (in parsetree)
            if (curDragged != null && movedenough)
            {
                overlay.BeginUpdate();
                // determine the relative shift
                Vector relshift = curDragged.Center - DragOriginO;
                Vector relshift_tikz = relshift / overlay.Resolution;
                ShiftSelItemsInParseTree(relshift_tikz, overlay.DisplayTree.TopLevelItems);
                /*
                Point pp = new Point(Canvas.GetLeft(curDragged) + curDragged.Width / 2, Canvas.GetBottom(curDragged) + curDragged.Height / 2);
                pp = ScreenToTikz(pp);
                if (curDragged is OverlayNode)
                {
                    (curDragged as OverlayNode).tikzitem.SetAbsPos(pp);
                    (curDragged as OverlayNode).tikzitem.UpdateText();

                }
                else if (curDragged is OverlayScope)
                {
                    Point pdiff = new Point(e.GetPosition(canvas1).X - DragOriginC.X, e.GetPosition(canvas1).Y - DragOriginC.Y);
                    pdiff = rasterizer.RasterizePixel(pdiff);

                    double xs = pdiff.X / Resolution, ys = -pdiff.Y / Resolution;

                    curDragged.ShiftItemRelative(pdiff);
                }*/
                // update all item's positions
                overlay.DisplayTree.AdjustPositions();

                // update raster in case it has changed
                overlay.SetCorrectRaster(curDragged);

                curDragged = null;

                overlay.EndUpdate();
            }
        }
Пример #15
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
                return;

            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
                return;

            overlay.BeginUpdate();

            //overlay.SetCorrectRaster(overlay.CurEditing, true);
            UpdateRaster();
            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);


            // find next tikzpicture and add
            bool lcreated;
            if (EnsureCurAddToExists(out lcreated))
            {
                // on double click -> close path
                if (e.ClickCount == 2)
                {
                    if (!lcreated)
                    {
                        //if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
                        curAddTo.AddChild(new Parser.Tikz_Something(" -- cycle"));
                        //else
                        //    curAddTo.AddChild(new Parser.Tikz_Something(" cycle"));
                    }
                }
                else
                {
                    if (!lcreated)
                    {
                        if (!overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                            // add an edge
                            curAddTo.AddChild(new Parser.Tikz_Something(" -- "));
                        else
                            curAddTo.AddChild(new Parser.Tikz_Something(" "));
                    }

                    // create new coordinate. If some node was clicked, set a reference to that node. Otherwise, just make new coordinates
                    Tikz_Coord tc = new Tikz_Coord();
                    if (item is OverlayNode && IsReferenceable(item))
                    {
                        Tikz_Node tn = MakeReferenceableNode((item as OverlayNode).tikzitem);
                        tc.type = Tikz_CoordType.Named;
                        tc.nameref = tn.name;
                        curAddTo.AddChild(tc);
                    }
                    else
                    {
                        // do it here since the coordinate calculation needs the parents' coord. transform
                        tc.type = overlay.UsePolarCoordinates ? Tikz_CoordType.Polar : Tikz_CoordType.Cartesian;
                        if (!lcreated)
                            tc.deco = overlay.NewNodeModifier;  // first node should always be in absolute coordinates

                        curAddTo.AddChild(tc);
                        tc.SetAbsPos(new Point(p.X, p.Y)); //hack

                        // if a nonempty node style is selected, also add a node with that style
                        if (!String.IsNullOrWhiteSpace(overlay.NodeStyle))
                        {
                            Tikz_Node tn = new Tikz_Node()
                            {
                                options = "[" + overlay.NodeStyle + "]",
                                coord = null,
                                text = ""
                            };
                            curAddTo.AddChild(new Tikz_Something(" "));
                            curAddTo.AddChild(tn);
                        }
                    }
                    //tn.UpdateText();
                    curAddTo.UpdateText();
                    //tpict.UpdateText();

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

            overlay.EndUpdate();
            UpdateRaster();

            // doubleclick also stops path drawing
            if (e.ClickCount == 2)
                overlay.ActivateDefaultTool();
        }
Пример #16
0
        /// <summary>
        /// Determines whether the object represented by the OverlayShape item can be 
        /// given a reference to. This is the case, e.g., for standard coordinates. It is
        /// however not the case for the coordinates in a smooth curve.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected bool IsReferenceable(OverlayShapeVM item)
        {
            if (!(item is OverlayNode))
                return false;

            Tikz_XYItem it = (item as OverlayNode).tikzitem;

            // check whether item occurs in smooth curve 
            // we check whether the parent's parent has the word "coordinates" preceding the parent (this is a bit of a hack)
            if (it is Tikz_Coord && (it.parent.parent is Tikz_Path))
            {
                Tikz_Path grandpa = it.parent.parent as Tikz_Path;
                for (int i = grandpa.Children.IndexOf(it.parent) - 1; i > 0; i--)
                {
                    if (!(grandpa.Children[i] is Tikz_Something))
                        break;
                    if (grandpa.Children[i].text.ToLower().Contains("coordinates"))
                        return false;
                }

            }

            return true;

        }
Пример #17
0
        public override void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
        {
            if (PreviewArc.Spokes == null)
            {
                SetCursorDefault();
                return;
            }

            PreviewArc.Visible = false;
            // adjust position of dragged item (in parsetree)
            if (curDragged != null && movedenough && curDragged.item is Tikz_XYItem)
            {                

                overlay.BeginUpdate();
                // determine the relative shift
                Vector relshift = new Vector(curDragged.Center.X - DragOriginO.X, curDragged.Center.Y - DragOriginO.Y);
                Vector relshift_tikz = relshift / overlay.Resolution;

                // compute new radius 
                Point pold;
                (curDragged.item as Tikz_XYItem).GetAbsPos(out pold);
                Point pnew = pold + relshift_tikz;
                double Rnew = (pnew - center_tikz).Length;

                // adjust all position accordingly...                
                for (int i=0;i<nodesOnArc.Count;i++)
                {
                    Point newp = center_tikz + Rnew * (new Vector(Math.Cos(PreviewArc.Spokes[i]), Math.Sin(PreviewArc.Spokes[i])));

                    if (i == 0)
                    {
                        nodesOnArc[i].SetAbsPos(newp);
                    }
                    else
                    {
                        //if (nodesOnArc[i] == curDragged.item)
                        //(nodesOnArc[i] as Tikz_Arc).SetAbsPosRandPhi2(Rnew, PreviewArc.Spokes[i]);
                        (nodesOnArc[i] as Tikz_Arc).SetFromPoints(center_tikz, newp, PreviewArc.Spokes[i-1], PreviewArc.Spokes[i]);
                        //else
                        //    (nodesOnArc[i] as Tikz_Arc).SetAbsPosOnlyR(newp);
                        
                    }                        

                    nodesOnArc[i].UpdateText();
                   
                }

                

                // set first angle of arc segment directly after curDragged
                //if (curDraggedInd + 1 < nodesOnArc.Count)
                //{
                //    (nodesOnArc[curDraggedInd + 1] as Tikz_Arc).SetAbsPosRandPhi1(pnew);
                //}

               // ShiftSelItemsInParseTree(relshift_tikz, overlay.TopLevelItems);
                /*
                Point pp = new Point(Canvas.GetLeft(curDragged) + curDragged.Width / 2, Canvas.GetBottom(curDragged) + curDragged.Height / 2);
                pp = ScreenToTikz(pp);
                if (curDragged is OverlayNode)
                {
                    (curDragged as OverlayNode).tikzitem.SetAbsPos(pp);
                    (curDragged as OverlayNode).tikzitem.UpdateText();

                }
                else if (curDragged is OverlayScope)
                {
                    Point pdiff = new Point(e.GetPosition(canvas1).X - DragOriginC.X, e.GetPosition(canvas1).Y - DragOriginC.Y);
                    pdiff = rasterizer.RasterizePixel(pdiff);

                    double xs = pdiff.X / Resolution, ys = -pdiff.Y / Resolution;

                    curDragged.ShiftItemRelative(pdiff);
                }*/
                // update all item's positions
                overlay.DisplayTree.AdjustPositions();

                curDragged = null;
                PreviewArc.Spokes = null;

                overlay.EndUpdate();
            }
            else if (curDragged != null && curDragged.item is Tikz_XYItem)
            { //if not movedenough, reset all "moving variables" anyways
                curDragged = null;
                PreviewArc.Spokes = null;
            }
        }
Пример #18
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
                return;

            Point prast = overlay.Rasterizer.RasterizePixel(p);
            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
                return;

            overlay.BeginUpdate();

            overlay.SetCorrectRaster(overlay.CurEditing, true);

            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);


            // find next tikzpicture and add
            bool lcreated;
            if (EnsureCurAddToExists(out lcreated))
            {
                {
                    // there are three states:  (i)   new path -> add coordinate
                    //                          (ii)  add controlpoints
                    //                          (iii) 2 cps's added -> add bezier segment
                    if (CPCount == 2)
                    {
                        // add controls
                        Tikz_Controls tcont = new Tikz_Controls();
                        tcont.starttag = " .. controls ";
                        tcont.endtag = " ..";
                        Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord(), tc2 = new Parser.Tikz_Coord(); // control points
                        tc1.type = tc2.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;

                        tcont.AddChild(tc1);
                        tcont.AddChild(new Tikz_Something(" and "));
                        tcont.AddChild(tc2);

                        curAddTo.AddChild(tcont);

                        // the endpoint
                        Parser.Tikz_Coord tcend = new Parser.Tikz_Coord();
                        tcend.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                        curAddTo.AddChild(new Tikz_Something(" "));
                        curAddTo.AddChild(tcend);
                        
                        // do it here since the coordinate calculation needs the parents' coord. transform, and the second added point 
                        tcend.SetAbsPos(p);                        
                        tc1.SetAbsPos(CP1);
                        tc2.SetAbsPos(CP2);
 
                        tcont.UpdateText();
                        tcend.UpdateText();

                        // draw the added objects in the overlay
                 //       overlay.AddToDisplayTree(tcend);
                 //       overlay.AddToDisplayTree(tcont);

                        CPCount = 0;
                        Preview_CP1.Visible = Preview_CP2.Visible = false;
                    }
                    else if (lcreated)
                    {
                        // add starting point
                        // create new coordinate
                        Parser.Tikz_Coord tc = new Parser.Tikz_Coord();
                        tc.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                        curAddTo.AddChild(tc);
                        // do it here since the coordinate calculation needs the parents' coord. transform
                        tc.SetAbsPos(new Point(p.X, p.Y)); //hack
                        curAddTo.UpdateText();                        
                        // draw the added object in the overlay
                //        overlay.AddToDisplayTree(tc);

                        CPCount = 0;
                    } else 
                    {
                        // remember control points
                        if (CPCount == 0)
                        {
                            CP1 = p;

                            Preview_CP1.SetCenter(prast.X, prast.Y);
                            ////Canvas.SetLeft(Preview_CP1, prast.X - Preview_CP1.Width / 2);
                            ////Canvas.SetBottom(Preview_CP1, prast.Y - Preview_CP1.Height / 2);
                            ////if (!overlay.canvas.Children.Contains(Preview_CP1))
                            ////    overlay.canvas.Children.Add(Preview_CP1);
                            ////Preview_CP1.Visibility = Visibility.Visible;
                            Preview_CP1.Visible = true;
                        }
                        else if (CPCount == 1)
                        {
                            CP2 = p;
                            Preview_CP2.SetCenter(prast.X, prast.Y);
                            ////Canvas.SetLeft(Preview_CP2, prast.X - Preview_CP2.Width / 2);
                            ////Canvas.SetBottom(Preview_CP2, prast.Y - Preview_CP2.Height / 2);
                            ////if (!overlay.canvas.Children.Contains(Preview_CP2))
                            ////    overlay.canvas.Children.Add(Preview_CP2);
                            ////Preview_CP2.Visibility = Visibility.Visible;
                            Preview_CP2.Visible = true;
                        }
                        CPCount++;
                    }
                }
            }

            overlay.EndUpdate();
        }
Пример #19
0
 public void MarkObject(OverlayShapeVM v)
 {
     MarkObject_Timer.Stop();
     MarkObject_BlinkCount = 0;
     MarkObject_Marked = v;
     MarkObject_ShowMarker = true;
     MarkObject_Timer.Start();
     Invalidate();
 }
Пример #20
0
 public void JumpToSourceDoIt(OverlayShapeVM o)
 {
     if (o != null)
     {
         if (JumpToSource != null)
             JumpToSource(this, new JumpToSourceEventArgs() { JumpToPos=o.item.StartPosition(), SelectionLength=o.item.text.Length });
     }
 }
Пример #21
0
 public void JumpToSourceDoIt(OverlayShapeVM o)
 {
     View.JumpToSourceDoIt(o);
 }
Пример #22
0
 /// <summary>
 /// The displayed raster changes depending on the currently selected object.
 /// This method sets the raster, so as to fit the coordinate transformation at o.
 /// There are two cases:    (i)  (IsParent=false) o is the object being modified, so the relevant coordinate trsf. is that at o
 ///                         (ii) (IsParent=true)  o is a parent object to which items are added. 
 ///                              In this case the relevant transf. is that at the end of o, since new items are inserted at the end.
 /// </summary>
 /// <param name="o">The object. If null, it is taken to be the tikzpicture.</param>
 /// <param name="IsParent">Indicates whether object is to be modified (=moved) itself, or children added.</param>        
 public void SetCorrectRaster(OverlayShapeVM o, bool IsParent = false)
 {
     SetCorrectRaster(o == null ? null : o.item, IsParent);
 }
Пример #23
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            if (!(item is OverlayNode))
            {
                curSel = null;
                return;
            }
            OverlayNode n = item as OverlayNode;

            // make sure a referenceable item is selected... otherwise we cannot add an edge
            if (!IsReferenceable(item))
            {
                GlobalUI.UI.AddStatusLine(this, "Only items that are referenceable (=can be given names) can be connected with the edge tool.");
                return;
            }

            if (curSel == null)
            {
                curSel = n;
                return;
            }

            // make sure both nodes involved are nodes

            /*  if (!(curSel.tikzitem is Tikz_Node) || !(n.tikzitem is Tikz_Node))
             * {
             *    String which = ""; String verb = "is";
             *    if (!(curSel.tikzitem is Tikz_Node) && !(n.tikzitem is Tikz_Node))
             *    { which = "Both"; verb = "are"; }
             *    else if (!(curSel.tikzitem is Tikz_Node))
             *        which = "The first";
             *    else if (!(n.tikzitem is Tikz_Node))
             *        which = "The second";
             *    MainWindow.AddStatusLine(which + " of the selected coordinates " + verb + " not a node (i.e. not defined with \\node but rather with \\draw or \\path)", true);
             *    curSel = null;
             *    return; // hack
             * } */

            //the return from above must not interfere with BeginModify()
            overlay.BeginUpdate();

            // add an edge curSel to n
            //bool lcreated;
            //if (EnsureCurAddToExists(out lcreated))

            //always create new \draw command. otherwise it can happen that the \draw-command
            //is above the \node-definition which causes an error while compiling the latex code.
            if (AddNewCurAddTo())
            {
                // make sure both nodes involved have names
                Parser.Tikz_Node t1 = MakeReferenceableNode(curSel.tikzitem),
                                 t2 = MakeReferenceableNode(n.tikzitem);

                Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord();
                tc1.type = Parser.Tikz_CoordType.Named;
                Parser.Tikz_Coord tc2 = new Parser.Tikz_Coord();
                tc2.type = Parser.Tikz_CoordType.Named;

                curAddTo.AddChild(new Parser.Tikz_Something(" "));
                curAddTo.AddChild(tc1);
                if (t1 == t2)
                {
                    curAddTo.AddChild(new Parser.Tikz_Something(" edge[loop, looseness=20] "));
                }
                else
                {
                    curAddTo.AddChild(new Parser.Tikz_Something(" edge "));
                }
                curAddTo.AddChild(tc2);
                //tpict.AddChild(tp);

                // make sure both nodes have names

                /*              Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture();
                 *            if (t1.name == "")
                 *            {
                 *                t1.SetName(tpict.GetUniqueName());
                 *                t1.UpdateText();
                 *            }
                 *            if (t2.name == "")
                 *            {
                 *                t2.SetName(tpict.GetUniqueName());
                 *                t2.UpdateText();
                 *            }
                 */
                tc1.nameref = t1.name;
                tc2.nameref = t2.name;
                //tc1.UpdateText();
                curAddTo.UpdateText();
                //tpict.UpdateText();
                //                    txtCode_TextChanged

                //RedrawObjects();
                //if (OnModified != null)
                //    OnModified.Invoke();

                //edge was drawn. release currently selected node.
                curSel = null;

                //will neither want to path tool to start from this last select nodes.
                curAddTo = null;
            }
            //forgetting to call EndModify causes weird "No undo group should be open at this point"-message.
            overlay.EndUpdate();
        }
Пример #24
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
                return;

            overlay.BeginUpdate();

            overlay.SetCorrectRaster(overlay.CurEditing, true);

            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);
            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
                return;

            // find next tikzpicture and add
            Parser.Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture();
            if (tpict != null)
            {
                Parser.Tikz_Node tn = new Parser.Tikz_Node();
                tn.label = "";
                tn.coord = new Parser.Tikz_Coord();
                if (!String.IsNullOrEmpty(overlay.NodeStyle))
                    tn.options = "[" + overlay.NodeStyle + "]";

                Parser.Tikz_Path tp = new Parser.Tikz_Path();
                tp.starttag = @"\node ";
                tp.endtag = ";";

                tp.AddChild(tn);
                if (overlay.CurEditing != null)
                {
                    overlay.CurEditing.tikzitem.AddChild(tp);
                    overlay.CurEditing.tikzitem.AddChild(new Parser.Tikz_Something("\r\n"));
                }
                else
                {
                    tpict.AddChild(tp);
                    tpict.AddChild(new Parser.Tikz_Something("\r\n"));
                }
                // do it here since the coordinate calculation needs the parents' coord. transform
                tn.SetAbsPos(new Point(p.X, p.Y)); //hack

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

                //RedrawObjects();
                //         overlay.AddToDisplayTree(tp);
            }

            overlay.EndUpdate();
        }
Пример #25
0
 public void JumpToSourceDoIt(OverlayShapeVM o)
 {
     View.JumpToSourceDoIt(o);
 }
Пример #26
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {

            if (!(item is OverlayNode))
            {
                curSel = null;
                return;
            }
            OverlayNode n = item as OverlayNode;

            // make sure a referenceable item is selected... otherwise we cannot add an edge
            if (!IsReferenceable(item))
            {
                GlobalUI.UI.AddStatusLine(this, "Only items that are referenceable (=can be given names) can be connected with the edge tool.");
                return;
            }

            if (curSel == null)
            {
                curSel = n;
                return;
            }

            // make sure both nodes involved are nodes
            /*  if (!(curSel.tikzitem is Tikz_Node) || !(n.tikzitem is Tikz_Node))
              {
                  String which = ""; String verb = "is";
                  if (!(curSel.tikzitem is Tikz_Node) && !(n.tikzitem is Tikz_Node))
                  { which = "Both"; verb = "are"; }
                  else if (!(curSel.tikzitem is Tikz_Node))
                      which = "The first";
                  else if (!(n.tikzitem is Tikz_Node))
                      which = "The second";
                  MainWindow.AddStatusLine(which + " of the selected coordinates " + verb + " not a node (i.e. not defined with \\node but rather with \\draw or \\path)", true);
                  curSel = null;
                  return; // hack
              } */

            //the return from above must not interfere with BeginModify()
            overlay.BeginUpdate();

            // add an edge curSel to n
            //bool lcreated;
            //if (EnsureCurAddToExists(out lcreated))

            //always create new \draw command. otherwise it can happen that the \draw-command
            //is above the \node-definition which causes an error while compiling the latex code.
            if (AddNewCurAddTo())
            {
                // make sure both nodes involved have names
                Parser.Tikz_Node t1 = MakeReferenceableNode(curSel.tikzitem),
                                 t2 = MakeReferenceableNode(n.tikzitem);

                Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord();
                tc1.type = Parser.Tikz_CoordType.Named;
                Parser.Tikz_Coord tc2 = new Parser.Tikz_Coord();
                tc2.type = Parser.Tikz_CoordType.Named;

                curAddTo.AddChild(new Parser.Tikz_Something(" "));
                curAddTo.AddChild(tc1);
                if (t1 == t2)
                    curAddTo.AddChild(new Parser.Tikz_Something(" edge[loop, looseness=20] "));
                else
                    curAddTo.AddChild(new Parser.Tikz_Something(" edge "));
                curAddTo.AddChild(tc2);
                //tpict.AddChild(tp);                    

                // make sure both nodes have names
                /*              Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture();
                              if (t1.name == "")
                              {
                                  t1.SetName(tpict.GetUniqueName());
                                  t1.UpdateText();
                              }
                              if (t2.name == "")
                              {
                                  t2.SetName(tpict.GetUniqueName());
                                  t2.UpdateText();
                              }
                              */
                tc1.nameref = t1.name;
                tc2.nameref = t2.name;
                //tc1.UpdateText();
                curAddTo.UpdateText();
                //tpict.UpdateText();
                //                    txtCode_TextChanged

                //RedrawObjects();
                //if (OnModified != null)
                //    OnModified.Invoke();

                //edge was drawn. release currently selected node.
                curSel = null;

                //will neither want to path tool to start from this last select nodes.
                curAddTo = null;
            }
            //forgetting to call EndModify causes weird "No undo group should be open at this point"-message.
            overlay.EndUpdate();
        }
Пример #27
0
        public void MarkObject(OverlayShapeVM vv)
        {
            // Find the shape (view)
            Shape v = canvas1.Children.OfType<OverlayShapeView>().FirstOrDefault(osv => osv.TheUnderlyingShape == vv) as Shape;
            if (v == null)
                return;

            MarkerCenter = new Point(Canvas.GetLeft(v) + v.Width / 2, Canvas.GetBottom(v) + v.Height / 2);
            MarkerEllipse.Width = Math.Max(v.Width, v.Height);
            //MarkerEllipse.Width = Math.Max(ols.ActualWidth, ols.ActualHeight);
            //da.KeyFrames.Add(new DoubleKeyFrame());
            Canvas.SetBottom(MarkerEllipse, MarkerCenter.Y - MarkerEllipse.ActualHeight / 2);
            Canvas.SetLeft(MarkerEllipse, MarkerCenter.X - MarkerEllipse.ActualWidth / 2);

            if (!canvas1.Children.Contains(MarkerEllipse))
                canvas1.Children.Add(MarkerEllipse);
            Storyboard anim = (Storyboard)FindResource("MarkerAnimation");
            anim.Begin(this);
            MarkerEllipse.Visibility = System.Windows.Visibility.Visible;
        }
Пример #28
0
        public override void OnRightMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            //base.OnRightMouseButtonDown(item, p, e);

            // if a node is selected, unselect it
            if (curSel != null)
            {
                curSel = null;
                e.Handled = true;   // we don't want anything else to happen (contextmenu opening etc)
            }
        }
Пример #29
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {

            if (e.ClickCount == 2 && (item is OverlayScope)) // Select for editing
            {
                overlay.CurEditing = item as OverlayScope;
            }
            else if (e.ClickCount == 2 && (item is OverlayNode))
            {
                overlay.JumpToSourceDoIt(item);
            }
            else if (item is OverlayShapeVM)
            {
                // initiate a drag/drop operation
                curDragged = (OverlayShapeVM)item;
                DragOrigin = (Point)(item.Center - p); ////e.GetPosition(item);
                ////DragOrigin = new Point(DragOrigin.X, (item as OverlayShape).Height - DragOrigin.Y);
                DragOriginC = p;
                DragOriginO = curDragged.Center;
                movedenough = false;
                //MessageBox.Show(o.ToString());

                // select the clicked shape
                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                {
                    if (!ToggleItem(curDragged))
                    {
                        // unselected -> start no drag operation
                        curDragged = null;
                    }
                }
                else
                {
                    AddItem(curDragged, !IsItemSelected(curDragged));
                }

                // adjust raster origin/scale/polar/cartesian
                overlay.SetCorrectRaster(curDragged);

                // capture mouse. this is important if the user drags sth. outside canvas1's bounds
                if (curDragged != null)
                    overlay.MouseCaptured = true;
            }
            else if (item == null)
            {
                BeginSelectionChange(overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control));

                // display selection rectangle
                SelectionRectOrigin = overlay.CursorPosition;
                //SelectionRect.RenderTransform = new TranslateTransform(SelectionRectOrigin.X, SelectionRectOrigin.Y);
                SelectionRect.SetPosition(SelectionRectOrigin.X, SelectionRectOrigin.Y,0,0);
                ////Canvas.SetLeft(SelectionRect, SelectionRectOrigin.X);
                ////Canvas.SetTop(SelectionRect, SelectionRectOrigin.Y);
                ////SelectionRect.Width = 0;
                ////SelectionRect.Height = 0;
                ////Canvas.SetZIndex(SelectionRect, overlay.canvas.Children.Count);
                ////if (!overlay.canvas.Children.Contains(SelectionRect))
                ////    overlay.canvas.Children.Add(SelectionRect);
                ////SelectionRect.Visibility = System.Windows.Visibility.Visible;
                SelectionRect.Visible = true;
                overlay.MouseCaptured = true;

            }


        }
Пример #30
0
 /// <summary>
 /// The displayed raster changes depending on the currently selected object.
 /// This method sets the raster, so as to fit the coordinate transformation at o.
 /// There are two cases:    (i)  (IsParent=false) o is the object being modified, so the relevant coordinate trsf. is that at o
 ///                         (ii) (IsParent=true)  o is a parent object to which items are added.
 ///                              In this case the relevant transf. is that at the end of o, since new items are inserted at the end.
 /// </summary>
 /// <param name="o">The object. If null, it is taken to be the tikzpicture.</param>
 /// <param name="IsParent">Indicates whether object is to be modified (=moved) itself, or children added.</param>
 public void SetCorrectRaster(OverlayShapeVM o, bool IsParent = false)
 {
     SetCorrectRaster(o == null ? null : o.item, IsParent);
 }
Пример #31
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM 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);

            }
            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);

        }
Пример #32
0
 /// <summary>
 /// Set e.Handled if you want to turn off the default handling... like opening the context menu etc.
 /// </summary>
 /// <param name="item">The item on which the event occurred.</param>   
 /// <param name="p">The cursor position, in BOTTOM LEFT CENTERED pixel coordinates.</param>
 ///        
 public virtual void OnRightMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e) { }
Пример #33
0
 /// <summary>
 /// Clears the list, except possibly the item "except".
 /// </summary>
 /// <param name="except">The thing not to remove.</param>
 void Clear(OverlayShapeVM except = null)
 {
     foreach (OverlayShapeVM o in SelectedItems)
         if (o != except)
             o.IsSelected = false;
     SelectedItems.RemoveWhere(o => (o != except));
     //SelectedItems.Clear();
 }
Пример #34
0
 void RemoveItem(OverlayShapeVM o)
 {
     if (SelectedItems.Contains(o))
     {
         SelectedItems.Remove(o);
         o.IsSelected = false;
     }
 }
Пример #35
0
 /// <summary>
 /// Toggles selection state, returns new selection state.
 /// </summary>
 /// <param name="o"></param>
 /// <returns></returns>
 public bool ToggleItem(OverlayShapeVM o)
 {
     if (SelectedItems.Contains(o))
     {
         RemoveItem(o);
         return false;
     }
     else
     {
         AddItem(o);
         return true;
     }
 }
Пример #36
0
        Tikz_Option smoothOption; // this has to be changed to smooth cycle for closed curve

        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e) 
        {
            if (!EnsureParseTreeExists())
                return;

            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
                return;

            overlay.BeginUpdate();

            overlay.SetCorrectRaster(overlay.CurEditing, true);

            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);


            // find tikzpicture and add
            bool lcreated;
            if (EnsureCurAddToExists(out lcreated))
            {
                // on double click -> close path
                if (e.ClickCount == 2)
                {
                    if (!lcreated)
                    {
                        smoothOption.key = "smooth cycle";
                        smoothOption.UpdateText();
                    }
                }
                else
                {
                    if (!lcreated)
                    {
                        // for prettier formatting
                        curAddTo.AddChild(new Parser.Tikz_Something(" "));
                    }

                    // create new coordinate
                    Parser.Tikz_Coord tc = new Parser.Tikz_Coord();
                    tc.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                    curAddTo.AddChild(tc);
                    if (item is OverlayNode && IsReferenceable(item))
                    {
                        Tikz_Node tn = MakeReferenceableNode((item as OverlayNode).tikzitem);
                        tc.type = Tikz_CoordType.Named;
                        tc.nameref = tn.name;
                    }
                    else
                    {
                        // do it here since the coordinate calculation needs the parents' coord. transform
                        tc.SetAbsPos(new Point(p.X, p.Y)); 
                    }

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

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

            overlay.EndUpdate();

            // doubleclick also stops path drawing
            if (e.ClickCount == 2)
                overlay.ActivateDefaultTool();
        }
Пример #37
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            // initiate drawing process
            Point mousep = overlay.Rasterizer.RasterizePixel(p);
            origin = new Point(mousep.X, overlay.Height - mousep.Y);

            if (IsReferenceable(item))
                originRef = item;
            else
                originRef = null;

            PreviewEllipse.SetPosition(origin.X,origin.Y,0,0);

            double angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform) * 180 / Math.PI;
            PreviewEllipse.Rotation = angle;

            PreviewEllipse.Visible = true;

            overlay.MouseCaptured = true;
        }