Exemplo n.º 1
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;
                }
            }
        }
Exemplo n.º 2
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();
        }