Esempio n. 1
0
 public ClippingLine(String name, Point p1, Point p2, int thickness, Color color, Poly targetPoly) : base(name)
 {
     points = new List <Point>();
     points.Add(p1);
     points.Add(p2);
     this.thickness  = thickness;
     this.color      = color;
     this.targetPoly = targetPoly;
 }
Esempio n. 2
0
        private void CanvasImage_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (Drawing)
            {
                Point clickPoint = new Point(e.GetPosition(sender as System.Windows.IInputElement));

                if (floodFill)
                {
                    CanvasImage.Source = drawer.FloodFill(clickPoint, floodFillColor);
                    StopDrawing();

                    floodFill = false;
                    return;
                }


                switch (selectedShapeType)
                {
                case (ShapeType.Line):
                case (ShapeType.Circle):
                case (ShapeType.ClippingLine):

                    if (previousClickPoints.Count >= 1)
                    {
                        Point p1 = previousClickPoints[0];
                        Point p2 = clickPoint;

                        Shape newShape;
                        switch (selectedShapeType)
                        {
                        case ShapeType.Line:
                            newShape = new Line(selectedShapeType.ToString(), p1, p2, 1, new Color(0, 0, 0, 255));
                            break;

                        case ShapeType.Circle:
                            newShape = new Circle(selectedShapeType.ToString(), p1, p2, new Color(0, 0, 0, 255));
                            break;

                        case ShapeType.ClippingLine:
                            newShape = new ClippingLine(selectedShapeType.ToString(), p1, p2, 1, new Color(0, 0, 0, 255), lastCreatedPoly);
                            break;

                        default:
                            throw new NotImplementedException();
                        }

                        CanvasImage.Source      = drawer.AddShape(newShape);
                        ShapeList.SelectedIndex = ShapeList.Items.Count - 1;

                        StopDrawing();
                    }
                    else
                    {
                        previousClickPoints.Add(clickPoint);
                        activeProjectionPoints.Add(CreateProjectionPoint(clickPoint));
                    }
                    break;

                case (ShapeType.Poly):

                    if (previousClickPoints.Count >= 2)
                    {
                        if (clickPoint.Distance(previousClickPoints[0]) < (double)FINISH_POLY_THRESHOLD)       // If is new point is near the first placed point then create polygon
                        {
                            Shape newShape = new Poly(selectedShapeType.ToString(), new List <Point>(previousClickPoints), 1, new Color(0, 0, 0, 255));
                            CanvasImage.Source = drawer.AddShape(newShape);

                            lastCreatedPoly = newShape as Poly;     // For Cyrus-Beck algorithm

                            ShapeList.SelectedIndex = ShapeList.Items.Count - 1;
                            StopDrawing();
                        }
                        else
                        {
                            previousClickPoints.Add(clickPoint);
                            activeProjectionPoints.Add(CreateProjectionPoint(clickPoint));
                        }
                    }
                    else
                    {
                        previousClickPoints.Add(clickPoint);
                        activeProjectionPoints.Add(CreateProjectionPoint(clickPoint));
                    }

                    break;

                case (ShapeType.Capsule):
                    if (previousClickPoints.Count == 2)
                    {
                        Point p1       = previousClickPoints[0];
                        Point p2       = previousClickPoints[1];
                        Point p3       = clickPoint;
                        Shape newShape = new Capsule(selectedShapeType.ToString(), p1, p2, p3, new Color(0, 0, 0, 255));
                        CanvasImage.Source      = drawer.AddShape(newShape);
                        ShapeList.SelectedIndex = ShapeList.Items.Count - 1;
                        StopDrawing();
                    }
                    else
                    {
                        previousClickPoints.Add(clickPoint);
                        activeProjectionPoints.Add(CreateProjectionPoint(clickPoint));
                    }
                    break;

                case (ShapeType.Rectangle):
                    if (previousClickPoints.Count == 1)
                    {
                        Point p1       = previousClickPoints[0];
                        Point p2       = clickPoint;
                        Shape newShape = new Rectangle(selectedShapeType.ToString(), p1, p2, new Color(0, 0, 0, 255));
                        CanvasImage.Source      = drawer.AddShape(newShape);
                        ShapeList.SelectedIndex = ShapeList.Items.Count - 1;
                        StopDrawing();
                    }
                    else
                    {
                        previousClickPoints.Add(clickPoint);
                        activeProjectionPoints.Add(CreateProjectionPoint(clickPoint));
                    }
                    break;


                default:
                    throw new NotImplementedException();
                }
            }
            else
            {
                DeselectShape();
            }
        }