예제 #1
0
        public void CopyFrom(ShapeLinesCollection shape)
        {
            Reset();

            List <ShapePoint> pts    = new List <ShapePoint>();
            List <ShapePoint> newPts = new List <ShapePoint>();

            for (int i = 0; i < shape.lines.Count; i++)
            {
                IShapeCurve tmp = shape.lines[i].Create();

                for (int j = 0; j < shape.lines[i].ControlPoints.Length; j++)
                {
                    int pos = pts.IndexOf(shape.lines[i].ControlPoints[j]);
                    if (pos == -1)
                    {
                        pts.Add(shape.lines[i].ControlPoints[j]);
                        pos = pts.IndexOf(shape.lines[i].ControlPoints[j]);
                        newPts.Insert(pos, new ShapePoint(shape.lines[i].ControlPoints[j].Location));
                    }
                    tmp.ControlPoints[j] = newPts[pos];
                }
                Add(tmp);
                tmp.Update();
            }
        }
예제 #2
0
        public void InsertPoint(IShapeCurve curve, PointF atPoint)
        {
            if (curve == null)
            {
                return;
            }

            if (curve is ShapeLine)
            {
                ShapePoint end     = curve.LastPoint;
                ShapePoint middle  = new ShapePoint(atPoint);
                ShapeLine  newLine = new ShapeLine(middle, end);
                curve.LastPoint = middle;
                lines.Insert(lines.IndexOf(curve) + 1, newLine);
                return;
            }

            if (curve is ShapeBezier)
            {
                PointF tg1 = new PointF(), tg2 = new PointF();

                ShapePoint end    = snappedCurve.LastPoint;
                ShapePoint middle = new ShapePoint(snappedPoint);

                if (!(curve as ShapeBezier).TangentAt(snappedPoint, ref tg1, ref tg2))
                {
                    return;
                }

                ShapeBezier newBezier = new ShapeBezier();

                newBezier.ControlPoints[0] = middle;
                newBezier.ControlPoints[1] = new ShapePoint(tg2);
                newBezier.ControlPoints[2] = curve.ControlPoints[2];
                newBezier.ControlPoints[3] = curve.LastPoint;

                curve.ControlPoints[2] = new ShapePoint(tg1);
                curve.ControlPoints[3] = middle;

                curve.Update();
                newBezier.Update();

                lines.Insert(lines.IndexOf(curve) + 1, newBezier);

                return;
            }
        }
예제 #3
0
 public void InsertPoint(IShapeCurve curve, PointF atPoint)
 {
     if (curve == null)
     {
         return;
     }
     if (curve is ShapeLine)
     {
         ShapePoint lastPoint = curve.LastPoint;
         ShapePoint from      = new ShapePoint(atPoint);
         ShapeLine  shapeLine = new ShapeLine(from, lastPoint);
         curve.LastPoint = from;
         this.lines.Insert(this.lines.IndexOf(curve) + 1, (IShapeCurve)shapeLine);
     }
     else
     {
         if (!(curve is ShapeBezier))
         {
             return;
         }
         PointF     from       = new PointF();
         PointF     to         = new PointF();
         ShapePoint lastPoint  = this.snappedCurve.LastPoint;
         ShapePoint shapePoint = new ShapePoint(this.snappedPoint);
         if (!(curve as ShapeBezier).TangentAt(this.snappedPoint, ref from, ref to))
         {
             return;
         }
         ShapeBezier shapeBezier = new ShapeBezier();
         shapeBezier.ControlPoints[0] = shapePoint;
         shapeBezier.ControlPoints[1] = new ShapePoint(to);
         shapeBezier.ControlPoints[2] = curve.ControlPoints[2];
         shapeBezier.ControlPoints[3] = curve.LastPoint;
         curve.ControlPoints[2]       = new ShapePoint(from);
         curve.ControlPoints[3]       = shapePoint;
         curve.Update();
         shapeBezier.Update();
         this.lines.Insert(this.lines.IndexOf(curve) + 1, (IShapeCurve)shapeBezier);
     }
 }
예제 #4
0
        public void CopyFrom(ShapeLinesCollection shape)
        {
            this.Reset();
            List <ShapePoint> shapePointList1 = new List <ShapePoint>();
            List <ShapePoint> shapePointList2 = new List <ShapePoint>();

            for (int index1 = 0; index1 < shape.lines.Count; ++index1)
            {
                IShapeCurve el = shape.lines[index1].Create();
                for (int index2 = 0; index2 < shape.lines[index1].ControlPoints.Length; ++index2)
                {
                    int index3 = shapePointList1.IndexOf(shape.lines[index1].ControlPoints[index2]);
                    if (index3 == -1)
                    {
                        shapePointList1.Add(shape.lines[index1].ControlPoints[index2]);
                        index3 = shapePointList1.IndexOf(shape.lines[index1].ControlPoints[index2]);
                        shapePointList2.Insert(index3, new ShapePoint(shape.lines[index1].ControlPoints[index2].Location));
                    }
                    el.ControlPoints[index2] = shapePointList2[index3];
                }
                this.Add(el);
                el.Update();
            }
        }