Пример #1
0
        public bool CheckIntersection(VectorPath p)
        {
            bool i = false;

            foreach (VectorPath tp in paths)
            {
                if (tp == p)
                {
                    continue;
                }

                p.Intersects(tp);

                if (p.IsValidPos)
                {
                    i = true;
                }
            }

            if (!i)
            {
                foreach (VectorPath tp in paths)
                {
                    p.UpdateGoodPos();
                }
            }

            return(p.IsValidPos);
        }
Пример #2
0
        public void RotateSelection(float angle)
        {
            VectorPath[] paths = new VectorPath[origins.Count];
            PointF[]     o     = new PointF[origins.Count];
            float[]      a     = new float[origins.Count];

            int i = 0;

            foreach (VectorPath p in origins.Keys)
            {
                paths[i] = p;
                o[i]     = origins[p];
                a[i]     = angles[p];

                i++;
            }

            Matrix mt = new Matrix();

            mt.RotateAt(angle, new PointF(selCenterX, selCenterY));
            mt.TransformPoints(o);

            for (i = 0; i < paths.Length; i++)
            {
                paths[i].SetPos(o[i].X, o[i].Y);
                paths[i].Rotate(a[i] + angle);
            }

            foreach (VectorPath p in selection)
            {
                p.CheckDocumentLimits();
                CheckIntersection(p);
            }
        }
Пример #3
0
        public void SelectPath(VectorPath p)
        {
            if (p.Document != this || isTransforming)
            {
                return;
            }

            selection.Add(p);
            p.Selected = true;

            host.OnSelectionChanged();
        }
Пример #4
0
        internal void ImportPath(VectorPath p)
        {
            segments.Clear();
            polygons = null;

            BeginPath();

            Marca    = p.Document.Marca;
            Modelo   = p.Document.Modelo;
            Ano      = p.Document.Ano;
            NomePeca = p.NomePeca;

            foreach (VectorSegment s in p.segments)
            {
                if (s is VectorMoveSegment)
                {
                    MoveTo(s.End.X, s.End.Y);
                }

                if (s is VectorLineSegment)
                {
                    LineTo(s.End.X, s.End.Y);
                }

                if (s is VectorCubicSegment)
                {
                    VectorCubicSegment c = (VectorCubicSegment)s;
                    CurveTo(c.End.X, c.End.Y, c.Control1.X, c.Control1.Y, c.Control2.X, c.Control2.Y);
                }

                if (s is VectorQuadraticSegment)
                {
                    VectorQuadraticSegment q = (VectorQuadraticSegment)s;
                    QCurveTo(q.End.X, q.End.Y, q.Control.X, q.Control.Y);
                }

                if (s is VectorCloseSegment)
                {
                    ClosePolygon();
                }
            }

            ClosePath();

            p.importCount++;

            source     = p;
            p.Imported = true;

            posx = p.posx + 100;
            posy = p.posy + 100;
            id   = p.Id;
        }
Пример #5
0
        public void UnselectPath(VectorPath p)
        {
            if (p.Document != this || isTransforming)
            {
                return;
            }

            selection.Remove(p);

            p.Selected = false;

            host.OnSelectionChanged();
        }
Пример #6
0
        public bool Intersects(VectorPath path)
        {
            if (path == this)
            {
                return(false);
            }

            if (polygons == null)
            {
                BuildPolygons();
            }

            intersectList.Remove(path);
            path.intersectList.Remove(this);

            if (IsBoundInside(path))
            {
                List <PointF[]> tpoly = GetTransfomedPolygons();
                foreach (PointF[] pts in tpoly)
                {
                    foreach (PointF p in pts)
                    {
                        if (path.IsPointInside(p, false))
                        {
                            intersectList.Add(path);
                            path.intersectList.Add(this);

                            return(true);
                        }
                    }
                }

                tpoly = path.GetTransfomedPolygons();
                foreach (PointF[] pts in tpoly)
                {
                    foreach (PointF p in pts)
                    {
                        if (IsPointInside(p, false))
                        {
                            intersectList.Add(path);
                            path.intersectList.Add(this);
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Пример #7
0
        public void ImportSelection(VectorViewCtr src)
        {
            VectorDocument d = src.Document;

            if (d != null)
            {
                foreach (VectorPath p in src.Document.Selection)
                {
                    VectorPath path = document.ImportPath(p);
                }
            }



            Invalidate();
        }
Пример #8
0
        public bool IsBoundInside(VectorPath path)
        {
            PointF[] bp = GetBoundPoints();

            foreach (PointF p in bp)
            {
                if (path.IsPointInside(p, true))
                {
                    return(true);
                }
            }

            if (path.IsPointInside(new PointF(posx, posy), true))
            {
                return(true);
            }

            if (IsPointInside(new PointF(path.posx, path.posy), true))
            {
                return(true);
            }

            return(false);
        }
Пример #9
0
 public VectorEventArgs(VectorDocument doc, VectorPath path)
 {
     document  = doc;
     this.path = path;
 }
Пример #10
0
        void ParseSvgElement(SvgElement el)
        {
            VectorPath path = null;

            if (el is SvgPolygon)
            {
                SvgPolygon p = (SvgPolygon)el;
                path = CreatePath();

                int len = p.Points.Count;

                if (len % 2 != 0)
                {
                    len--;
                }

                for (int i = 0; i < len; i += 2)
                {
                    float x, y;

                    x = p.Points[i].Value / ppmx;
                    y = p.Points[i + 1].Value / ppmy;

                    if (i == 0)
                    {
                        path.MoveTo(x, y);
                    }
                    else
                    {
                        path.LineTo(x, y);
                    }
                }

                path.ClosePolygon();
            }

            if (el is SvgPath)
            {
                SvgPath p = (SvgPath)el;
                path = CreatePath();

                foreach (SvgElement e in p.Children)
                {
                    if (e is SvgTitle)
                    {
                        SvgTitle title = (SvgTitle)e;
                        path.Title = title.Content;
                    }
                }

                string tag, side;

                tag  = "";
                side = "";
                string guidStr = "";

                path.Side = VectorPathSide.None;

                if (p.TryGetAttribute("gf-tag", out tag))
                {
                    path.Tag = Encoding.UTF8.GetString(Convert.FromBase64String(tag));
                }

                try
                {
                    if (p.TryGetAttribute("gf-guid", out guidStr))
                    {
                        path.Guid = new Guid(guidStr);
                    }
                }
                catch
                {
                }

                if (p.TryGetAttribute("gf-side", out side))
                {
                    if (side == "left")
                    {
                        path.Side = VectorPathSide.Left;
                    }

                    if (side == "right")
                    {
                        path.Side = VectorPathSide.Right;
                    }
                }

                if (p.TryGetAttribute("gf-nome-peca", out string nomePeca))
                {
                    path.NomePeca = "";
                    try
                    {
                        path.NomePeca = Encoding.UTF8.GetString(Convert.FromBase64String(nomePeca));
                    }
                    catch
                    {
                    }
                }

                path.ForceAngle = false;
                string force = "";

                if (p.TryGetAttribute("gf-forceAngle", out force))
                {
                    bool pf = false;

                    if (bool.TryParse(force, out pf))
                    {
                        path.ForceAngle = pf;
                    }
                }

                float sx, sy, ex, ey;

                foreach (SvgPathSegment seg in p.PathData)
                {
                    sx = (seg.Start.X / ppmx);
                    sy = (seg.Start.Y / ppmy);
                    ex = (seg.End.X / ppmx);
                    ey = (seg.End.Y / ppmy);

                    if (seg is SvgLineSegment)
                    {
                        path.LineTo(ex, ey);
                    }
                    else if (seg is SvgCubicCurveSegment)
                    {
                        SvgCubicCurveSegment q = (SvgCubicCurveSegment)seg;
                        path.CurveTo(ex, ey, (q.FirstControlPoint.X / ppmx), (q.FirstControlPoint.Y / ppmy), (q.SecondControlPoint.X / ppmx), (q.SecondControlPoint.Y / ppmy));
                    }
                    else if (seg is SvgQuadraticCurveSegment)
                    {
                        SvgQuadraticCurveSegment q = (SvgQuadraticCurveSegment)seg;
                        path.QCurveTo(ex, ey, (q.ControlPoint.X / ppmx), (q.ControlPoint.Y / ppmy));
                    }
                    else if (seg is SvgClosePathSegment)
                    {
                        path.ClosePolygon();
                    }
                    else if (seg is SvgMoveToSegment)
                    {
                        path.MoveTo(ex, ey);
                    }
                    else
                    {
                    }
                }
            }
            else
            {
            }

            if (path != null)
            {
                path.ClosePath();
            }

            foreach (SvgElement n in el.Children)
            {
                ParseSvgElement(n);
            }
        }