Exemplo n.º 1
0
 public void AddCurve(Curve c)
 {
     graobjs.Add(c);
 }
Exemplo n.º 2
0
 public void RemoveCurve(Curve c)
 {
     graobjs.Remove(c);
 }
Exemplo n.º 3
0
        public static bool IsStartSelected(Point p, Curve curve)
        {
            Rectangle selection = new Rectangle(p.X - 4, p.Y - 4, 8, 8);

            if (selection.Contains(curve.Start))
            {
                return true;
            }
            return false;
        }
Exemplo n.º 4
0
        public static Curve CreateCurve(Point _start, Point _end)
        {
            Curve c = new Curve();

            int xdiff = _end.X - _start.X;
            int ydiff = _end.Y - _start.Y;

            int x1_3 = _start.X + xdiff / 3;
            int x2_3 = _start.X + xdiff * 2 / 3;
            int y1_3 = _start.Y + ydiff / 3;
            int y2_3 = _start.Y + ydiff * 2 / 3;

            c.CP1 = new Point(x1_3, y1_3);
            c.CP2 = new Point(x2_3, y2_3);

            c.Start = _start;
            c.End = _end;

            return c;
        }
Exemplo n.º 5
0
        public static bool ContainsPoint(Point p, Curve curve)
        {
            Rectangle selection = new Rectangle(p.X - 4, p.Y - 4, 8, 8);

            if (selection.Contains(curve.Start) | selection.Contains(curve.CP1) | selection.Contains(curve.CP2) | selection.Contains(curve.End))
            {
                return true;
            }
            return false;
        }
Exemplo n.º 6
0
        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);

            if (_PathCType == PathConstructorType.AddStart)
            {
                if (e.Button == MouseButtons.Left)
                {
                    _last_pathtreenode.PathObject.Path.Insert.InsertPoint = e.Location;

                    //Un point d'insert est le premier point d'un chemin (insert point is first point of path)
                    //Tous les chemins sont ici composés de courbes (all paths are composed by curves)
                    //Donc il est nécessaire de définir le premier point (so it's necessary to define first point)
                    //C'est juste au cas où (it's just a precaution)
                    //Sinon on décale tout (else we translate all)
                    if (_last_pathtreenode.PathObject.Path.GetGroup().Count == 0)
                    {
                        _last_pathcurve = new Drawing.Curve();

                        Drawing.Curve c = _last_pathcurve;
                        c.Start = e.Location;
                        _last_pathtreenode.PathObject.Path.AddCurve(c);
                    }
                    else
                    {
                        Point inverseLocationPoint = Point.Empty;
                        int counter = 0;

                        foreach(Drawing.IGraphicObject igo in _last_pathtreenode.PathObject.Path.GetGroup())
                        {

                            if(igo.GetType() == typeof(Drawing.Curve))
                            {
                                counter++;
                                Drawing.Curve c = (Drawing.Curve)igo;
                                if(inverseLocationPoint.IsEmpty == true)
                                {
                                    //Ceci est notre point de référence
                                    //(this is our reference point)
                                    //Si le premier point de toutes les courbes est vide
                                    //(if first point of all curves is void)
                                    Point notReal = c.Start;
                                    Point real = e.Location;
                                    inverseLocationPoint.X = notReal.X - real.X;
                                    inverseLocationPoint.Y = notReal.Y - real.Y;
                                }

                                if (inverseLocationPoint.IsEmpty == false
                                    && counter <= _last_pathtreenode.PathObject.Path.GetGroup().Count - 1)
                                {
                                    //Sinon on décale tout (else we translate all)
                                    //A l'aide du point inverse (with this inverse point)
                                    //A l'exception de la dernière courbe (except the last curve)
                                    //Car pour la dernière courbe seule le point de début est défini
                                    //(for the last curve only the first point is defined)
                                    c.Start = new Point(
                                        c.Start.X - inverseLocationPoint.X,
                                        c.Start.Y - inverseLocationPoint.Y);
                                    c.CP1 = new Point(
                                        c.CP1.X - inverseLocationPoint.X,
                                        c.CP1.Y - inverseLocationPoint.Y);
                                    c.CP2 = new Point(
                                        c.CP2.X - inverseLocationPoint.X,
                                        c.CP2.Y - inverseLocationPoint.Y);
                                    c.End = new Point(
                                        c.End.X - inverseLocationPoint.X,
                                        c.End.Y - inverseLocationPoint.Y);
                                }

                                if (inverseLocationPoint.IsEmpty == false
                                    && counter == _last_pathtreenode.PathObject.Path.GetGroup().Count)
                                {
                                    //Sinon on décale tout (else we translate all)
                                    //A l'aide du point inverse (with this inverse point)
                                    //A l'exception de la dernière courbe (except the last curve)
                                    //Car pour la dernière courbe seule le point de début est défini
                                    //(for the last curve only the first point is defined)
                                    c.Start = new Point(
                                        c.Start.X - inverseLocationPoint.X,
                                        c.Start.Y - inverseLocationPoint.Y);
                                }
                            }
                        }
                    }

                    Refresh();
                }
            }
            else if(_PathCType == PathConstructorType.AddCurve)
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (_last_pathtreenode.PathObject.Path.GetGroup().Count == 0)
                    {
                        _last_pathcurve = new Drawing.Curve();

                        Drawing.Curve c = _last_pathcurve;
                        c.Start = e.Location;
                        _last_pathtreenode.PathObject.Path.AddCurve(c);
                    }
                    else if (_last_pathcurve.Start.IsEmpty == false && _last_pathcurve.End.IsEmpty == true)
                    {
                        Drawing.Curve cv = Drawing.Curve.CreateCurve(_last_pathcurve.Start, e.Location);
                        _last_pathcurve.CP1 = cv.CP1;
                        _last_pathcurve.CP2 = cv.CP2;
                        _last_pathcurve.End = cv.End;

                        _last_pathcurve = new Drawing.Curve();

                        Drawing.Curve c = _last_pathcurve;
                        c.Start = e.Location;
                        _last_pathtreenode.PathObject.Path.AddCurve(c);

                    }

                    bool add_PTN = true;
                    foreach (PathTreeNode ptn in _pathlist)
                    {
                        if (ptn.Equals(_last_pathtreenode))
                        {
                            add_PTN = false;
                        }
                    }
                    if (add_PTN == true)
                    {
                        _pathlist.Add(_last_pathtreenode);
                    }
                    Refresh();
                }
            }
        }
Exemplo n.º 7
0
        public static List<Group> Deserialize(string filename)
        {
            List<Group> gs = new List<Group>();
            Group group = new Group();
            Line _line = new Line();
            Curve _curve = new Curve();

            string doc = System.IO.File.ReadAllText(filename);

            Generic gen = new Generic();
            Dictionary<string, string> coordinates = new Dictionary<string, string>();

            string line = "", expr = "", oldexpr = "", coor = "";
            StringReader sr = new StringReader(doc);
            while ((line = sr.ReadLine()) != null)
            {
                //1 - Groups ON (List<Group> gs)
                //2 - Group ON (Group group)
                //3 - Line ON (Line _line) ou Curve ON (Curve _curve)
                expr = gen.FromON(line, out coordinates);
                if (expr == "Group")
                {
                    group = new Group();
                    gs.Add(group);
                }
                else if (expr == "Line")
                {
                    _line = new Line();
                    group.AddLine(_line);
                    oldexpr = "Line";
                }
                else if (expr == "Curve")
                {
                    _curve = new Curve();
                    group.AddCurve(_curve);
                    oldexpr = "Curve";
                }

                //4 - Coordinates
                coor = gen.FromVOID(line, out coordinates);
                if (coor == "Start" && oldexpr == "Line")
                {
                    _line.Start = new Point(Convert.ToInt32(coordinates["X"]), Convert.ToInt32(coordinates["Y"]));
                }
                else if (coor == "End" && oldexpr == "Line")
                {
                    _line.End = new Point(Convert.ToInt32(coordinates["X"]), Convert.ToInt32(coordinates["Y"]));
                }
                else if (coor == "Start" && oldexpr == "Curve")
                {
                    _curve.Start = new Point(Convert.ToInt32(coordinates["X"]), Convert.ToInt32(coordinates["Y"]));
                }
                else if (coor == "CP1" && oldexpr == "Curve")
                {
                    _curve.CP1 = new Point(Convert.ToInt32(coordinates["X"]), Convert.ToInt32(coordinates["Y"]));
                }
                else if (coor == "CP2" && oldexpr == "Curve")
                {
                    _curve.CP2 = new Point(Convert.ToInt32(coordinates["X"]), Convert.ToInt32(coordinates["Y"]));
                }
                else if (coor == "End" && oldexpr == "Curve")
                {
                    _curve.End = new Point(Convert.ToInt32(coordinates["X"]), Convert.ToInt32(coordinates["Y"]));
                }
            }

            return gs;
        }