コード例 #1
0
ファイル: PdfOverlayModel.cs プロジェクト: wilsoc5/tikzedt
        /// <summary>
        /// Gets a list of all descendants of the specified parent in the Display tree, including the parent itself.
        /// </summary>
        /// <param name="OfParent">The parent. If null, it is taken to be the root.</param>
        /// <returns></returns>
        public IEnumerable <OverlayShape> GetAllDescendants(OverlayShape OfParent = null)
        {
            IEnumerable <OverlayShape> src = null;
            List <OverlayShape>        ret = new List <OverlayShape>();

            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
ファイル: PdfOverlayModel.cs プロジェクト: wilsoc5/tikzedt
        /// <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)
        {
            OverlayShape ols = ObjectFromOffset(offset, TopLevelItems);

            if (ols != null)
            {
                View.MarkObject(ols.View);
            }
        }
コード例 #3
0
ファイル: SelectionTool.cs プロジェクト: JoeyEremondi/tikzedt
 /// <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(OverlayShape o, bool Exclusive = false)
 {
     if (Exclusive)
         Clear(o);
     if (!SelectedItems.Contains(o))
     {
         o.SetSelectedColor();
         SelectedItems.Add(o);
     }
 }
コード例 #4
0
ファイル: ArcEditTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {

            if (item != null)
            {
                // initiate a drag/drop operation
                curDragged = (OverlayShape)item;
                DragOrigin = (new Point(item.View.GetLeft(), item.View.GetBottom()))-(Vector)p ;
                ////DragOrigin = e.GetPosition(item);
                ////DragOrigin = new Point(DragOrigin.X, (item as OverlayShape).Height - DragOrigin.Y);
                DragOriginC = p;
                DragOriginO = new Point(curDragged.View.GetLeft(), curDragged.View.GetBottom());
                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;
            }
            


        }
コード例 #5
0
ファイル: PdfOverlayModel.cs プロジェクト: wilsoc5/tikzedt
 /// <summary>
 /// This method searches recursively among all items in the displaytree for one whose associated code segment
 /// contains the position offset. In case multiple items match, the deepest (in the tree) one is chosen.
 /// E.g., if a scope contains a node, and the offset matches the node, it also also lies within the scope,
 /// but the node is returned.
 /// </summary>
 /// <param name="offset">The code position.</param>
 /// <param name="bag">Overlayshapes to search in.</param>
 /// <returns></returns>
 public OverlayShape ObjectFromOffset(int offset, List <OverlayShape> bag)
 {
     foreach (OverlayShape 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)
             {
                 OverlayShape olsinner = ObjectFromOffset(offset, (ols as OverlayScope).children);
                 if (olsinner != null)
                 {
                     return(olsinner);
                 }
             }
             return(ols);
         }
     }
     return(null);
 }
コード例 #6
0
        public override void OnLeftMouseButtonDown(OverlayShape 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;
        }
コード例 #7
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape 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))
            {
                MainWindow.AddStatusLine("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();
        }
コード例 #8
0
ファイル: ArcEditTool.cs プロジェクト: JoeyEremondi/tikzedt
        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.View.GetLeft() - DragOriginO.X, curDragged.View.GetBottom() - 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
                foreach (OverlayShape o in overlay.TopLevelItems)
                    o.AdjustPosition(overlay.Resolution);

                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;
            }
        }
コード例 #9
0
ファイル: SelectionTool.cs プロジェクト: JoeyEremondi/tikzedt
 public bool IsItemSelected(OverlayShape o)
 {
     return SelectedItems.Contains(o);
 }
コード例 #10
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnRightMouseButtonDown(OverlayShape 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)
            }
        }
コード例 #11
0
ファイル: SelectionTool.cs プロジェクト: JoeyEremondi/tikzedt
        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
                Point relshift = new Point(curDragged.View.GetLeft() - DragOriginO.X, curDragged.View.GetBottom() - DragOriginO.Y);
                Point relshift_tikz = new Point(relshift.X / overlay.Resolution, relshift.Y / overlay.Resolution);
                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
                foreach (OverlayShape o in overlay.TopLevelItems)
                    o.AdjustPosition(overlay.Resolution);

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

                curDragged = null;

                overlay.EndUpdate();
            }
        }
コード例 #12
0
        Tikz_Option smoothOption; // this has to be changed to smooth cycle for closed curve

        public override void OnLeftMouseButtonDown(OverlayShape 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();
        }
コード例 #13
0
ファイル: ArcTool.cs プロジェクト: JoeyEremondi/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);

        }
コード例 #14
0
ファイル: PdfOverlayModel.cs プロジェクト: wilsoc5/tikzedt
 /// <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 moved itself, or children added.</param>
 public void SetCorrectRaster(OverlayShape o, bool IsParent = false)
 {
     SetCorrectRaster(o == null ? null : o.item, IsParent);
 }
コード例 #15
0
ファイル: SelectionTool.cs プロジェクト: JoeyEremondi/tikzedt
 void RemoveItem(OverlayShape o)
 {
     if (SelectedItems.Contains(o))
     {
         SelectedItems.Remove(o);
         o.SetStdColor();
     }
 }
コード例 #16
0
 public void JumpToSourceDoIt(OverlayShape o)
 {
     View.JumpToSourceDoIt(o);
 }
コード例 #17
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 moved itself, or children added.</param>        
 public void SetCorrectRaster(OverlayShape o, bool IsParent = false)
 {
     SetCorrectRaster(o == null ? null : o.item, IsParent);
 }
コード例 #18
0
        /// <summary>
        /// Gets a list of all descendants of the specified parent in the Display tree, including the parent itself.
        /// </summary>
        /// <param name="OfParent">The parent. If null, it is taken to be the root.</param>
        /// <returns></returns>
        public IEnumerable<OverlayShape> GetAllDescendants(OverlayShape OfParent = null)
        {
            IEnumerable<OverlayShape> src = null;
            List<OverlayShape> ret = new List<OverlayShape>();
            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;
        }
コード例 #19
0
ファイル: BezierTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape 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();
        }
コード例 #20
0
        public override void OnLeftMouseButtonDown(OverlayShape 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;
        }
コード例 #21
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
        /// <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(OverlayShape 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;

        }
コード例 #22
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape 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 (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();
        }
コード例 #23
0
ファイル: SelectionTool.cs プロジェクト: JoeyEremondi/tikzedt
 /// <summary>
 /// Toggles selection state, returns new selection state.
 /// </summary>
 /// <param name="o"></param>
 /// <returns></returns>
 public bool ToggleItem(OverlayShape o)
 {
     if (SelectedItems.Contains(o))
     {
         RemoveItem(o);
         return false;
     }
     else
     {
         AddItem(o);
         return true;
     }
 }
コード例 #24
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
 /// <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(OverlayShape item, Point p, TEMouseArgs e) { }
コード例 #25
0
ファイル: PdfOverlayModel.cs プロジェクト: wilsoc5/tikzedt
 public void JumpToSourceDoIt(OverlayShape o)
 {
     View.JumpToSourceDoIt(o);
 }
コード例 #26
0
ファイル: SelectionTool.cs プロジェクト: JoeyEremondi/tikzedt
 /// <summary>
 /// Clears the list, except possibly the item "except".
 /// </summary>
 /// <param name="except">The thing not to remove.</param>
 void Clear(OverlayShape except = null)
 {
     foreach (OverlayShape o in SelectedItems)
         if (o != except)
             o.SetStdColor();
     SelectedItems.RemoveWhere(o => (o != except));
     //SelectedItems.Clear();
 }
コード例 #27
0
ファイル: SelectionTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape 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 OverlayShape)
            {
                // initiate a drag/drop operation
                curDragged = (OverlayShape)item;
                DragOrigin = (Point)((new Point(item.View.GetLeft(), item.View.GetBottom()))-p); ////e.GetPosition(item);
                ////DragOrigin = new Point(DragOrigin.X, (item as OverlayShape).Height - DragOrigin.Y);
                DragOriginC = p;
                DragOriginO = new Point(curDragged.View.GetLeft(), curDragged.View.GetBottom());
                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;

            }


        }
コード例 #28
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape 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();
                    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.type = overlay.UsePolarCoordinates ? Tikz_CoordType.Polar : Tikz_CoordType.Cartesian;
                        if (!lcreated) 
                            tc.deco = overlay.NewNodeModifier;  // first node should always be in absolute coordinates
                        tc.SetAbsPos(new Point(p.X, p.Y)); //hack

                        // if a nonempty node style is selected, also add a node with that style
                        if (overlay.NodeStyle.Trim() != "")
                        {
                            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();
        }