예제 #1
0
        public static void reflectionTransform(Shape shape, TypeReflectionTransform type)
        {
            Line Ox = new Line(new Point(0, 200), new Point(400, 200));

            Ox.setTransformPoint(new Point(0, 0));
            translationTransform(Ox);
            Line Oy = new Line(new Point(200, 200), new Point(400, 400));

            Oy.setTransformPoint(new Point(0, 0));
            translationTransform(Oy);

            switch (shape.getTypeDraw())
            {
            case TypeDraw.Line:
                Line line = (Line)shape;
                line.setStartPoint(reflect(line.getStartPoint(), type));
                line.setEndPoint(reflect(line.getEndPoint(), type));
                break;

            case TypeDraw.Circle:
                Circle circle = (Circle)shape;
                circle.setCenterPoint(reflect(circle.getCenterPoint(), type));
                circle.setEndPoint(reflect(circle.getEndPoint(), type));
                break;

            case TypeDraw.Ellipse:
                Ellipse ellipse = (Ellipse)shape;
                ellipse.setStartPoint(reflect(ellipse.getStartPoint(), type));
                ellipse.setEndHightPoint(reflect(ellipse.getEndHightPoint(), type));
                ellipse.setEndWidthPoint(reflect(ellipse.getEndWidthPoint(), type));
                break;

            case TypeDraw.Parallelogram:
                Parallelogram parallelogram = (Parallelogram)shape;
                parallelogram.setPoint1(reflect(parallelogram.getPoint1(), type));
                parallelogram.setPoint2(reflect(parallelogram.getPoint2(), type));
                parallelogram.setPoint3(reflect(parallelogram.getPoint3(), type));
                break;

            case TypeDraw.Rectangle:
                Rectangle rectangle = (Rectangle)shape;
                rectangle.setStartPoint(reflect(rectangle.getStartPoint(), type));
                rectangle.setEndPoint(reflect(rectangle.getEndPoint(), type));
                break;

            case TypeDraw.Triangle:
                Triangle triangle = (Triangle)shape;
                triangle.setPoint1(reflect(triangle.getPoint1(), type));
                triangle.setPoint2(reflect(triangle.getPoint2(), type));
                triangle.setPoint3(reflect(triangle.getPoint3(), type));
                break;

            case TypeDraw.Square:
                Square square = (Square)shape;
                square.setPoint1(reflect(square.getPoint1(), type));
                square.setPoint2(reflect(square.getPoint2(), type));
                break;
            }
            shape.setTransformFlag(false);
        }
예제 #2
0
        private void getInfoShape()
        {
            if (choosedShape != null)
            {
                frm.richTextBox1.Clear();
                frm.richTextBox1.AppendText("Tên hình ảnh: " + choosedShape.getName() + "\n");
                frm.richTextBox1.AppendText("Màu sắc: " + choosedShape.getColor().ToString() + "\n");
                switch (choosedShape.getTypeDraw())
                {
                case TypeDraw.Line:
                    Line line = (Line)choosedShape;
                    frm.richTextBox1.AppendText("Điểm đầu: " + line.getStartPoint().ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm cuối: " + line.getEndPoint().ToString() + "\n");
                    frm.richTextBox1.AppendText("Chiều dài: " + line.getLength().ToString());
                    break;

                case TypeDraw.Circle:
                    Circle circle = (Circle)choosedShape;
                    frm.richTextBox1.AppendText("Tâm: " + circle.getCenterPoint().ToString() + "\n");
                    frm.richTextBox1.AppendText("Bán kính: " + circle.getRadius().ToString());
                    break;

                case TypeDraw.Ellipse:
                    Ellipse ellipse = (Ellipse)choosedShape;
                    frm.richTextBox1.AppendText("Tâm: " + ellipse.getStartPoint().ToString() + "\n");
                    frm.richTextBox1.AppendText("Bán kính nhỏ: " + ellipse.getWidthRadius().ToString() + "\n");
                    frm.richTextBox1.AppendText("Bán kính lớn: " + ellipse.getHeightRadius().ToString());
                    break;

                case TypeDraw.Parallelogram:
                    Parallelogram parallelogram = (Parallelogram)choosedShape;
                    frm.richTextBox1.AppendText("Điểm thứ I: " + parallelogram.getPoint1().ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ II: " + parallelogram.getPoint2().ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ III: " + parallelogram.getPoint3().ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ IV: " + parallelogram.getPoint4().ToString() + "\n");
                    frm.richTextBox1.AppendText("Chiều dài:" + parallelogram.getHeight().ToString() + "\n");
                    frm.richTextBox1.AppendText("Chiều rộng:" + parallelogram.getWidth().ToString() + "\n");
                    break;

                case TypeDraw.Rectangle:
                    Rectangle rectangle = (Rectangle)choosedShape;
                    frm.richTextBox1.AppendText("Điểm thứ I: " + rectangle.getStartPoint().ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ II: " + rectangle.getPoint12().ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ III: " + rectangle.getEndPoint().ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ VI: " + rectangle.getPoint21().ToString() + "\n");
                    frm.richTextBox1.AppendText("Chiều dài:" + rectangle.getHeigth() + "\n");
                    frm.richTextBox1.AppendText("Chiều rộng:" + rectangle.getWidth() + "\n");
                    break;

                case TypeDraw.Triangle:
                    Triangle triangle = (Triangle)choosedShape;
                    frm.richTextBox1.AppendText("Điểm thứ I" + triangle.getPoint1().ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ II" + triangle.getPoint2().ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ III" + triangle.getPoint3().ToString() + "\n");
                    frm.richTextBox1.AppendText("Độ dài cạnh I: " + triangle.getLength1() + "\n");
                    frm.richTextBox1.AppendText("Độ dài cạnh II: " + triangle.getLength2() + "\n");
                    frm.richTextBox1.AppendText("Độ dài cạnh III: " + triangle.getLength3() + "\n");
                    break;

                case TypeDraw.Square:
                    Square square = (Square)choosedShape;
                    frm.richTextBox1.AppendText("Điểm thứ I: " + square.getPoint1().ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ II: " + square.getPoint2().ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ III: " + square.getPoint3().ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ IV: " + square.getPoint4().ToString() + "\n");
                    frm.richTextBox1.AppendText("Độ dài cạnh: " + square.getEdge().ToString() + "\n");
                    break;

                case TypeDraw.Cube:
                    Cube cube = (Cube)choosedShape;
                    frm.richTextBox1.AppendText("Điểm thứ I: " + cube.getList3D().ElementAt(0).ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ II: " + cube.getList3D().ElementAt(1).ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ III: " + cube.getList3D().ElementAt(2).ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ IV: " + cube.getList3D().ElementAt(3).ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ V: " + cube.getList3D().ElementAt(4).ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ VI: " + cube.getList3D().ElementAt(5).ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ VII: " + cube.getList3D().ElementAt(6).ToString() + "\n");
                    break;

                case TypeDraw.Cylinder:
                    Cylinder cylinder = (Cylinder)choosedShape;
                    frm.richTextBox1.AppendText("Điểm thứ I: " + cylinder.getList3D().ElementAt(0).ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ II: " + cylinder.getList3D().ElementAt(1).ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ III: " + cylinder.getList3D().ElementAt(2).ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ IV: " + cylinder.getList3D().ElementAt(3).ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ V: " + cylinder.getList3D().ElementAt(4).ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ VI: " + cylinder.getList3D().ElementAt(5).ToString() + "\n");
                    frm.richTextBox1.AppendText("Điểm thứ VII: " + cylinder.getList3D().ElementAt(6).ToString() + "\n");
                    break;
                }
            }
        }
예제 #3
0
        public void paint(Object sender, PaintEventArgs e)
        {
            if (!choosedFlag)
            {
                List <Shape> _shapeSet;
                if (check2d)
                {
                    _shapeSet = shapeSet;
                }
                else
                {
                    _shapeSet = shapeSet3D;
                }
                foreach (Shape s in _shapeSet)
                {
                    Pen      pen = new Pen(s.getColor(), 3);
                    Graphics g   = frm.panel1.CreateGraphics();
                    switch (s.getTypeDraw())
                    {
                    case TypeDraw.Line:
                        Line line = (Line)s;
                        //g.DrawLine(pen, line.getStartPoint().X, line.getStartPoint().Y, line.getEndPoint().X, line.getEndPoint().Y);
                        //DDA_Line2(line);
                        //drawLinebyMidPoint(line);
                        DDA_Line2(line);
                        break;

                    case TypeDraw.Rectangle:
                        Rectangle   retangle  = (Rectangle)s;
                        List <Line> listLines = retangle.getAllLines();
                        if (listLines != null)
                        {
                            foreach (Line _line in listLines)
                            {
                                DDA_Line2(_line);
                            }
                        }
                        break;

                    case TypeDraw.Triangle:
                        Triangle triangle = (Triangle)s;
                        listLines = triangle.getAllLines();
                        if (listLines != null)
                        {
                            foreach (Line _line in listLines)
                            {
                                DDA_Line2(_line);
                            }
                        }
                        break;

                    case TypeDraw.Parallelogram:
                        Parallelogram parallelogram = (Parallelogram)s;
                        listLines = parallelogram.getAllLines();
                        if (listLines != null)
                        {
                            foreach (Line _line in listLines)
                            {
                                DDA_Line2(_line);
                            }
                        }
                        break;

                    case TypeDraw.Circle:
                        Circle circle = (Circle)s;
                        MidPoint_Circle(circle);
                        break;

                    case TypeDraw.Ellipse:
                        Ellipse ellipse = (Ellipse)s;
                        MidPoint_Ellipse(ellipse);    //,true);
                        break;

                    //case TypeDraw.Cube:
                    //    Cube cube = (Cube)s;
                    //g.DrawLine(new Pen(Color.Black), 200, 200, 400, 200);
                    //g.DrawLine(new Pen(Color.Black), 200, 200, 200, 400);
                    //g.DrawLine(new Pen(Color.Red), 200, 0, 200, 200);
                    //g.DrawLine(new Pen(Color.Red), 200, 200, 400, 200);
                    //g.DrawLine(new Pen(Color.Aqua), 200, 200, 400, 400);
                    //if(cube!=null)
                    //    foreach (Line _line in cube.getListLine())
                    //    {
                    //        //g.DrawLine(pen, _line.getStartPoint(), _line.getEndPoint());
                    //        drawLinebyMidPoint(_line,_line.getDottedLineFlag());
                    //    }
                    //break;
                    //case TypeDraw.Cylinder:
                    //Cylinder cylinder = (Cylinder)s;
                    //g.DrawLine(new Pen(Color.Black), 200, 200, 400, 200);
                    //g.DrawLine(new Pen(Color.Black), 200, 200, 200, 400);
                    ////g.DrawLine(new Pen(Color.Red), 200, 0, 200, 200);
                    ////g.DrawLine(new Pen(Color.Red), 200, 200, 400, 200);
                    //g.DrawLine(new Pen(Color.Aqua), 200, 200, 400, 400);
                    //foreach(Shape _s in cylinder.getListShape())
                    //{
                    //    if (_s.getTypeDraw() == TypeDraw.Line)
                    //        drawLinebyMidPoint((Line)_s);
                    //    else if (_s.getTypeDraw() == TypeDraw.Ellipse) {
                    //        Ellipse _e = (Ellipse)_s;
                    //        MidPoint_Ellipse(_e);//, _e.getDottedEllipseFlag());
                    //    }
                    //}
                    //break;
                    case TypeDraw.Square:
                        Square square = (Square)s;
                        listLines = square.getAllLines();
                        if (listLines != null)
                        {
                            foreach (Line _line in listLines)
                            {
                                DDA_Line2(_line);
                            }
                        }
                        break;
                    }
                    g.Dispose();
                }
            }
            else
            {
                if (choosedShape != null)
                {
                    if (shape != null && shape.getTransformFlag())
                    {
                        Transform.translationTransform(shape);
                        getInfoShape();
                    }
                    //Pen pen = new Pen(choosedShape.getColor(), 3);
                    //Graphics g = frm.panel1.CreateGraphics();
                    if (check2d)
                    {
                        switch (choosedShape.getTypeDraw())
                        {
                        case TypeDraw.Line:
                            Line line = (Line)choosedShape;
                            //g.DrawLine(pen, line.getStartPoint().X, line.getStartPoint().Y, line.getEndPoint().X, line.getEndPoint().Y);
                            //DDA_Line2(line);
                            DDA_Line2(line);
                            break;

                        case TypeDraw.Rectangle:
                            Rectangle   retangle  = (Rectangle)choosedShape;
                            List <Line> listLines = retangle.getAllLines();
                            if (listLines != null)
                            {
                                foreach (Line _line in listLines)
                                {
                                    DDA_Line2(_line);
                                }
                            }
                            break;

                        case TypeDraw.Triangle:
                            Triangle triangle = (Triangle)choosedShape;
                            listLines = triangle.getAllLines();
                            if (listLines != null)
                            {
                                foreach (Line _line in listLines)
                                {
                                    DDA_Line2(_line);
                                }
                            }
                            break;

                        case TypeDraw.Parallelogram:
                            Parallelogram parallelogram = (Parallelogram)choosedShape;
                            listLines = parallelogram.getAllLines();
                            if (listLines != null)
                            {
                                foreach (Line _line in listLines)
                                {
                                    DDA_Line2(_line);
                                }
                            }
                            break;

                        case TypeDraw.Circle:
                            Circle circle = (Circle)choosedShape;
                            MidPoint_Circle(circle);
                            break;

                        case TypeDraw.Ellipse:
                            Ellipse ellipse = (Ellipse)choosedShape;
                            MidPoint_Ellipse(ellipse);
                            break;

                        case TypeDraw.Square:
                            Square square = (Square)choosedShape;
                            listLines = square.getAllLines();
                            if (listLines != null)
                            {
                                foreach (Line _line in listLines)
                                {
                                    DDA_Line2(_line);
                                }
                            }
                            break;
                            //case TypeDraw.Cube:
                            //    Cube cube = (Cube)choosedShape;
                            //    if (cube != null)
                            //        foreach (Line _line in cube.getListLine())
                            //        {
                            //            //g.DrawLine(pen, _line.getStartPoint(), _line.getEndPoint());
                            //            drawLinebyMidPoint(_line, _line.getDottedLineFlag());
                            //        }
                            //    break;
                            //case TypeDraw.Cylinder:
                            //    Cylinder cylinder = (Cylinder)choosedShape;
                            //    foreach (Shape _s in cylinder.getListShape())
                            //    {
                            //        if (_s.getTypeDraw() == TypeDraw.Line)
                            //            drawLinebyMidPoint((Line)_s);
                            //        else if (_s.getTypeDraw() == TypeDraw.Ellipse)
                            //        {
                            //            Ellipse _e = (Ellipse)_s;
                            //            MidPoint_Ellipse(_e, _e.getDottedEllipseFlag());
                            //        }
                            //    }
                            //    break;
                        }
                        //g.Dispose();
                    }
                    else
                    {
                        switch (choosedShape.getTypeDraw())
                        {
                        case TypeDraw.Cube:
                            Cube cube = (Cube)choosedShape;
                            if (cube != null)
                            {
                                foreach (Line _line in cube.getListLine())
                                {
                                    //g.DrawLine(pen, _line.getStartPoint(), _line.getEndPoint());
                                    drawLinebyMidPoint(_line, _line.getDottedLineFlag());
                                }
                            }
                            break;

                        case TypeDraw.Cylinder:
                            Cylinder cylinder = (Cylinder)choosedShape;
                            foreach (Shape _s in cylinder.getListShape())
                            {
                                if (_s.getTypeDraw() == TypeDraw.Line)
                                {
                                    drawLinebyMidPoint((Line)_s);
                                }
                                else if (_s.getTypeDraw() == TypeDraw.Ellipse)
                                {
                                    Ellipse _e = (Ellipse)_s;
                                    MidPoint_Ellipse(_e);    //, _e.getDottedEllipseFlag());
                                }
                            }
                            break;
                        }
                    }
                }
            }
            //getInfoShape();
        }
예제 #4
0
        public static void rotationTransform(Shape shape, float rotation)
        {
            Point oldPositionShape = new Point(0, 0);

            switch (shape.getTypeDraw())
            {
            case TypeDraw.Circle:
                Circle circle = (Circle)shape;
                oldPositionShape = circle.getCenterPoint();
                break;

            case TypeDraw.Ellipse:
                Ellipse ellipse = (Ellipse)shape;
                oldPositionShape = ellipse.getStartPoint();
                break;

            case TypeDraw.Line:
                Line line = (Line)shape;
                oldPositionShape = line.getStartPoint();
                break;

            case TypeDraw.Parallelogram:
                Parallelogram parallelogram = (Parallelogram)shape;
                oldPositionShape = parallelogram.getPoint1();
                break;

            case TypeDraw.Rectangle:
                Rectangle rectangle = (Rectangle)shape;
                oldPositionShape = rectangle.getStartPoint();
                break;

            case TypeDraw.Rhombus:
                Rhombus rhombus = (Rhombus)shape;
                oldPositionShape = rhombus.getPoint1();
                break;

            case TypeDraw.Square:
                Square square = (Square)shape;
                oldPositionShape = square.getPoint1();
                break;

            case TypeDraw.Triangle:
                Triangle triangle = (Triangle)shape;
                oldPositionShape = triangle.getPoint1();
                break;
            }
            shape.setTransformPoint(new Point(0, 0));
            translationTransform(shape);

            double sin = Math.Sin((Math.PI * rotation) / 180);
            double cos = Math.Cos((Math.PI * rotation) / 180);

            switch (shape.getTypeDraw())
            {
            case TypeDraw.Circle:
                Circle circle = (Circle)shape;
                circle.setCenterPoint(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    circle.getCenterPoint().X, circle.getCenterPoint().Y, 1
                }));
                circle.setEndPoint(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    circle.getEndPoint().X, circle.getEndPoint().Y, 1
                }));
                break;

            case TypeDraw.Ellipse:
                Ellipse ellipse = (Ellipse)shape;
                ellipse.setStartPoint(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    ellipse.getStartPoint().X, ellipse.getStartPoint().Y, 1
                }));
                ellipse.setEndHightPoint(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    ellipse.getEndHightPoint().X, ellipse.getEndHightPoint().Y, 1
                }));
                ellipse.setEndWidthPoint(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    ellipse.getEndWidthPoint().X, ellipse.getEndWidthPoint().Y, 1
                }));
                break;

            case TypeDraw.Line:
                Line line = (Line)shape;
                line.setStartPoint(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    line.getStartPoint().X, line.getStartPoint().Y, 1
                }));
                line.setEndPoint(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    line.getEndPoint().X, line.getEndPoint().Y, 1
                }));
                break;

            case TypeDraw.Parallelogram:
                Parallelogram parallelogram = (Parallelogram)shape;
                parallelogram.setPoint1(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    parallelogram.getPoint1().X, parallelogram.getPoint1().Y, 1
                }));
                parallelogram.setPoint2(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    parallelogram.getPoint2().X, parallelogram.getPoint2().Y, 1
                }));
                parallelogram.setPoint3(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    parallelogram.getPoint3().X, parallelogram.getPoint3().Y, 1
                }));
                break;

            case TypeDraw.Rectangle:
                Rectangle rectangle = (Rectangle)shape;
                rectangle.setStartPoint(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    rectangle.getStartPoint().X, rectangle.getStartPoint().Y, 1
                }));
                rectangle.setEndPoint(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    rectangle.getEndPoint().X, rectangle.getEndPoint().Y, 1
                }));
                break;

            case TypeDraw.Rhombus:
                Rhombus rhombus = (Rhombus)shape;
                //not yet completed
                break;

            case TypeDraw.Square:
                Square square = (Square)shape;
                square.setPoint1(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    square.getPoint1().X, square.getPoint1().Y, 1
                }));
                square.setPoint2(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    square.getPoint2().X, square.getPoint2().Y, 1
                }));
                break;

            case TypeDraw.Triangle:
                Triangle triangle = (Triangle)shape;
                triangle.setPoint1(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    triangle.getPoint1().X, triangle.getPoint1().Y, 1
                }));
                triangle.setPoint2(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    triangle.getPoint2().X, triangle.getPoint2().Y, 1
                }));
                triangle.setPoint3(multiMatrix(TypeTransform.Rotation, sin, cos, new double[3] {
                    triangle.getPoint3().X, triangle.getPoint3().Y, 1
                }));
                break;
            }
            shape.setTransformPoint(oldPositionShape);
            translationTransform(shape);
        }
예제 #5
0
        public static void scalingTransform(Shape shape, int scalingX, int scalingY)
        {
            //Shape tempShape=shape;
            Point oldPoint = new Point(0, 0);

            shape.setTransformPoint(new Point(0, 0));

            switch (shape.getTypeDraw())
            {
            case TypeDraw.Line:
                Line line = (Line)shape;
                oldPoint = line.getStartPoint();
                translationTransform(shape);
                line.setStartPoint(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] {
                    line.getStartPoint().X, line.getStartPoint().Y, 1
                }));
                //if (line.getStartPoint().X < line.getEndPoint().X && line.getStartPoint().Y < line.getEndPoint().Y)
                //{
                //    if (line.getStartPoint().X > line.getEndPoint().X)
                //        scalingX = -scalingX;
                //    if (line.getStartPoint().Y > line.getEndPoint().Y)
                //        scalingY = -scalingY;
                //}
                //else if (line.getStartPoint().X < line.getEndPoint().X && line.getStartPoint().Y > line.getEndPoint().Y)
                //{
                //    if (line.getStartPoint().X > line.getEndPoint().X)
                //        scalingX = -scalingX;
                //    if (line.getStartPoint().Y < line.getEndPoint().Y)
                //        scalingY = -scalingY;
                //}
                line.setEndPoint(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] {
                    line.getEndPoint().X, line.getEndPoint().Y, 1
                }));
                //line.setEndPoint(new Point(line.getEndPoint().X + scalingX * (line.getEndPoint().X-line.getStartPoint().X), line.getEndPoint().Y + scalingY * (line.getEndPoint().Y - line.getStartPoint().Y)));
                break;

            case TypeDraw.Circle:
                Circle circle = (Circle)shape;
                oldPoint = circle.getCenterPoint();
                translationTransform(shape);
                circle.setCenterPoint(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] {
                    circle.getCenterPoint().X, circle.getCenterPoint().Y, 1
                }));
                circle.setEndPoint(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] {
                    circle.getEndPoint().X, circle.getEndPoint().Y, 1
                }));
                //if (circle.getCenterPoint().X < circle.getEndPoint().X)
                //    scalingX = -scalingX;
                //if (circle.getCenterPoint().Y < circle.getEndPoint().Y)
                //    scalingY = -scalingY;
                //circle.setEndPoint(new Point(circle.getEndPoint().X + scalingX * (circle.getEndPoint().X - circle.getCenterPoint().X), circle.getEndPoint().Y + scalingY * (circle.getEndPoint().Y - circle.getCenterPoint().Y)));
                break;

            case TypeDraw.Ellipse:
                Ellipse ellipse = (Ellipse)shape;
                oldPoint = ellipse.getStartPoint();
                translationTransform(shape);
                //ellipse.setStartPoint(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] { ellipse.getStartPoint().X, ellipse.getStartPoint().Y, 1 }));
                ellipse.setEndHightPoint(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] {
                    ellipse.getEndHightPoint().X, ellipse.getEndHightPoint().Y, 1
                }));
                ellipse.setEndWidthPoint(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] {
                    ellipse.getEndWidthPoint().X, ellipse.getEndWidthPoint().Y, 1
                }));
                break;

            case TypeDraw.Parallelogram:
                Parallelogram parallelogram = (Parallelogram)shape;
                oldPoint = parallelogram.getPoint1();
                translationTransform(shape);
                //parallelogram.setPoint1(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] { parallelogram.getPoint1().X, parallelogram.getPoint1().Y, 1 }));
                parallelogram.setPoint2(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] {
                    parallelogram.getPoint2().X, parallelogram.getPoint2().Y, 1
                }));
                parallelogram.setPoint3(multiMatrix(TypeTransform.Translation, scalingX, scalingY, new double[3] {
                    parallelogram.getPoint3().X, parallelogram.getPoint3().Y, 1
                }));
                //parallelogram.setPoint4(multiMatrix(dx, dy, new double[3] { parallelogram.getPoint1().X, parallelogram.getPoint1().Y, 1 }));
                break;

            case TypeDraw.Rectangle:
                Rectangle rectangle = (Rectangle)shape;
                oldPoint = rectangle.getStartPoint();
                translationTransform(shape);
                //rectangle.setStartPoint(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] { rectangle.getStartPoint().X, rectangle.getStartPoint().Y, 1 }));
                rectangle.setEndPoint(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] {
                    rectangle.getEndPoint().X, rectangle.getEndPoint().Y, 1
                }));
                break;

            case TypeDraw.Triangle:
                Triangle triangle = (Triangle)shape;
                oldPoint = triangle.getPoint1();
                translationTransform(shape);
                //triangle.setPoint1(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] { triangle.getPoint1().X, triangle.getPoint1().Y, 1 }));
                triangle.setPoint2(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] {
                    triangle.getPoint2().X, triangle.getPoint2().Y, 1
                }));
                triangle.setPoint3(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] {
                    triangle.getPoint3().X, triangle.getPoint3().Y, 1
                }));
                break;

            case TypeDraw.Square:
                Square square = (Square)shape;
                oldPoint = square.getPoint1();
                translationTransform(shape);
                square.setPoint2(multiMatrix(TypeTransform.Scaling, scalingX, scalingY, new double[3] {
                    square.getPoint2().X, square.getPoint2().Y, 1
                }));
                break;
            }
            shape.setTransformPoint(oldPoint);
            translationTransform(shape);
            shape.setTransformFlag(false);
        }
예제 #6
0
        public static void translationTransform(Shape shape)
        {
            int   dx, dy;
            Point newPosition = shape.getTransformPoint();

            switch (shape.getTypeDraw())
            {
            case TypeDraw.Line:
                Line line = (Line)shape;
                dx = newPosition.X - line.getStartPoint().X;
                dy = newPosition.Y - line.getStartPoint().Y;
                line.setStartPoint(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    line.getStartPoint().X, line.getStartPoint().Y, 1
                }));
                line.setEndPoint(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    line.getEndPoint().X, line.getEndPoint().Y, 1
                }));
                break;

            case TypeDraw.Circle:
                Circle circle = (Circle)shape;
                dx = newPosition.X - circle.getCenterPoint().X;
                dy = newPosition.Y - circle.getCenterPoint().Y;
                circle.setCenterPoint(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    circle.getCenterPoint().X, circle.getCenterPoint().Y, 1
                }));
                circle.setEndPoint(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    circle.getEndPoint().X, circle.getEndPoint().Y, 1
                }));
                break;

            case TypeDraw.Ellipse:
                Ellipse ellipse = (Ellipse)shape;
                dx = newPosition.X - ellipse.getStartPoint().X;
                dy = newPosition.Y - ellipse.getStartPoint().Y;
                ellipse.setStartPoint(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    ellipse.getStartPoint().X, ellipse.getStartPoint().Y, 1
                }));
                ellipse.setEndHightPoint(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    ellipse.getEndHightPoint().X, ellipse.getEndHightPoint().Y, 1
                }));
                ellipse.setEndWidthPoint(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    ellipse.getEndWidthPoint().X, ellipse.getEndWidthPoint().Y, 1
                }));
                break;

            case TypeDraw.Parallelogram:
                Parallelogram parallelogram = (Parallelogram)shape;
                dx = newPosition.X - parallelogram.getPoint1().X;
                dy = newPosition.Y - parallelogram.getPoint1().Y;
                parallelogram.setPoint1(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    parallelogram.getPoint1().X, parallelogram.getPoint1().Y, 1
                }));
                parallelogram.setPoint2(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    parallelogram.getPoint2().X, parallelogram.getPoint2().Y, 1
                }));
                parallelogram.setPoint3(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    parallelogram.getPoint3().X, parallelogram.getPoint3().Y, 1
                }));
                //parallelogram.setPoint4(multiMatrix(dx, dy, new double[3] { parallelogram.getPoint1().X, parallelogram.getPoint1().Y, 1 }));
                break;

            case TypeDraw.Rectangle:
                Rectangle rectangle = (Rectangle)shape;
                dx = newPosition.X - rectangle.getStartPoint().X;
                dy = newPosition.Y - rectangle.getStartPoint().Y;
                rectangle.setStartPoint(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    rectangle.getStartPoint().X, rectangle.getStartPoint().Y, 1
                }));
                rectangle.setEndPoint(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    rectangle.getEndPoint().X, rectangle.getEndPoint().Y, 1
                }));
                break;

            case TypeDraw.Triangle:
                Triangle triangle = (Triangle)shape;
                dx = newPosition.X - triangle.getPoint1().X;
                dy = newPosition.Y - triangle.getPoint1().Y;
                triangle.setPoint1(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    triangle.getPoint1().X, triangle.getPoint1().Y, 1
                }));
                triangle.setPoint2(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    triangle.getPoint2().X, triangle.getPoint2().Y, 1
                }));
                triangle.setPoint3(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    triangle.getPoint3().X, triangle.getPoint3().Y, 1
                }));
                break;

            case TypeDraw.Square:
                Square square = (Square)shape;
                dx = newPosition.X - square.getPoint1().X;
                dy = newPosition.Y - square.getPoint1().Y;
                square.setPoint1(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    square.getPoint1().X, square.getPoint1().Y, 1
                }));
                square.setPoint2(multiMatrix(TypeTransform.Translation, dx, dy, new double[3] {
                    square.getPoint2().X, square.getPoint2().Y, 1
                }));
                break;
            }
            shape.setTransformFlag(false);
        }
예제 #7
0
        private void panel1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (drawShape.getShape() == null)
                {
                    MessageBox.Show("Bạn vui lòng chọn hình trước khi vẽ");
                    return;
                }
                if (!drawShape.getShape().checkDrawable())//if (!endClick)
                {
                    switch (drawShape.getShape().getTypeDraw())
                    {
                    case TypeDraw.Line:
                        Line line = (Line)drawShape.getShape();
                        //line.setStartPoint(new Point(Convert.ToInt16(round(e.X)), Convert.ToInt16(round(e.Y))));
                        line.setStartPoint(new Point(round(e.X), round(e.Y)));
                        break;

                    case TypeDraw.Rectangle:
                        Rectangle rectangle = (Rectangle)drawShape.getShape();
                        rectangle.setStartPoint(new Point(round(e.X), round(e.Y)));
                        break;

                    case TypeDraw.Triangle:
                        Triangle triangle = (Triangle)drawShape.getShape();
                        if (triangle.getRemainingClick() == 3)
                        {
                            triangle.setPoint1(new Point(round(e.X), round(e.Y)));
                        }
                        else if (triangle.getRemainingClick() == 2)
                        {
                            triangle.setPoint2(new Point(round(e.X), round(e.Y)));
                        }
                        break;

                    case TypeDraw.Parallelogram:
                        Parallelogram parallelogram = (Parallelogram)drawShape.getShape();
                        if (parallelogram.getRemainingClick() == 3)
                        {
                            parallelogram.setPoint1(new Point(round(e.X), round(e.Y)));
                        }
                        else if (parallelogram.getRemainingClick() == 2)
                        {
                            parallelogram.setPoint2(new Point(round(e.X), round(e.Y)));
                        }
                        break;

                    case TypeDraw.Circle:
                        Circle circle = (Circle)drawShape.getShape();
                        circle.setCenterPoint(new Point(round(e.X), round(e.Y)));
                        break;

                    case TypeDraw.Ellipse:
                        Ellipse ellipse = (Ellipse)drawShape.getShape();
                        if (ellipse.getRemainingClick() == 3)
                        {
                            ellipse.setStartPoint(new Point(round(e.X), round(e.Y)));
                        }
                        else if (ellipse.getRemainingClick() == 2)
                        {
                            ellipse.setEndWidthPoint(new Point(round(e.X), round(e.Y)));
                        }
                        break;

                    case TypeDraw.Square:
                        Square square = (Square)drawShape.getShape();
                        square.setPoint1(new Point(round(e.X), round(e.Y)));
                        break;
                    }
                }
                else
                {
                    if (drawShape.getShape().getTransformFlag())
                    {
                        drawShape.getShape().setTransformPoint(new Point(round(e.X), round(e.Y)));
                    }
                    else
                    {
                        switch (drawShape.getShape().getTypeDraw())
                        {
                        case TypeDraw.Line:
                            Line line = (Line)drawShape.getShape();
                            //line.setEndPoint(new Point(Convert.ToInt16(round(e.X)), Convert.ToInt16(round(e.Y))));
                            line.setEndPoint(new Point(round(e.X), round(e.Y)));
                            break;

                        case TypeDraw.Rectangle:
                            Rectangle rectangle = (Rectangle)drawShape.getShape();
                            rectangle.setEndPoint(new Point(round(e.X), round(e.Y)));
                            break;

                        case TypeDraw.Triangle:
                            Triangle triangle = (Triangle)drawShape.getShape();
                            triangle.setPoint3(new Point(round(e.X), round(e.Y)));
                            break;

                        case TypeDraw.Parallelogram:
                            Parallelogram paralleogram = (Parallelogram)drawShape.getShape();
                            paralleogram.setPoint3(new Point(round(e.X), round(e.Y)));
                            break;

                        case TypeDraw.Circle:
                            Circle circle = (Circle)drawShape.getShape();
                            circle.setEndPoint(new Point(round(e.X), round(e.Y)));
                            break;

                        case TypeDraw.Ellipse:
                            Ellipse ellipse = (Ellipse)drawShape.getShape();
                            ellipse.setEndHightPoint(new Point(round(e.X), round(e.Y)));
                            break;

                        case TypeDraw.Cube:
                            //Cube cube = (Cube)drawShape.getShape();
                            //cube.setStartPoint(new Point(round(e.X), round(e.Y)));
                            //new InputCubeForm(drawShape).ShowDialog();
                            return;

                            break;

                        case TypeDraw.Cylinder:
                            //Cylinder cylinder = (Cylinder)drawShape.getShape();
                            //cylinder.setPoint(new Point(round(e.X), round(e.Y)));
                            return;

                            break;

                        case TypeDraw.Square:
                            Square square = (Square)drawShape.getShape();
                            square.setPoint2(new Point(round(e.X), round(e.Y)));
                            break;
                        }
                        drawShape.addShapeToShapeSet();
                        drawShape.resetShape();
                        button9.Enabled  = false;
                        button12.Enabled = false;
                        button14.Enabled = false;
                        button15.Enabled = false;
                        button17.Enabled = false;
                        button13.Enabled = false;
                        if (drawShape.getShapeSet().Count == 0)
                        {
                            button8.Enabled = false;
                        }
                    }
                    panel1.Refresh();
                }
            }
            else if (e.Button == MouseButtons.Right) //cancel and clear the current shape in screen
            {
                drawShape.resetShape();
                //panel1.Paint += new PaintEventHandler(drawShape.paint);
                panel1.Refresh();
            }
        }