Beispiel #1
0
        void NextFragmentMutant()
        {
            if (pointsMutant.Count > 0)
            {
                List <Segment> segments = new List <Segment>();

                Interfaces.Point firstPointBorder = null;
                Interfaces.Point prevPointBorder  = null;
                bool             isFirst          = true;


                foreach (var point in pointsMutant)
                {
                    if (isFirst)
                    {
                        firstPointBorder = point;
                        isFirst          = false;
                        prevPointBorder  = point;
                        continue;
                    }
                    segments.Add(new Line(prevPointBorder, point));
                    prevPointBorder = point;
                }
                segments.Add(new Line(prevPointBorder, firstPointBorder));

                listFragments.Add(segments);
                pointsMutant.Clear();
            }
        }
Beispiel #2
0
        private void DrawQuadrangle(OpenGL gl, Interfaces.Point firstPoint, Interfaces.Point lastPoint)
        {
            gl.Color(0, 0, 255, 0.14);
            gl.Begin(OpenGL.GL_QUADS);
            gl.Vertex(firstPoint.X, openGLControlView.Height - firstPoint.Y);
            gl.Vertex(firstPoint.X, openGLControlView.Height - lastPoint.Y);
            gl.Vertex(lastPoint.X, openGLControlView.Height - lastPoint.Y);
            gl.Vertex(lastPoint.X, openGLControlView.Height - firstPoint.Y);
            gl.End();

            gl.Color(0, 0, 0);
            gl.Begin(OpenGL.GL_LINES);
            gl.Vertex(firstPoint.X, openGLControlView.Height - firstPoint.Y);
            gl.Vertex(firstPoint.X, openGLControlView.Height - lastPoint.Y);

            gl.Vertex(firstPoint.X, openGLControlView.Height - lastPoint.Y);
            gl.Vertex(lastPoint.X, openGLControlView.Height - lastPoint.Y);

            gl.Vertex(lastPoint.X, openGLControlView.Height - lastPoint.Y);
            gl.Vertex(lastPoint.X, openGLControlView.Height - firstPoint.Y);

            gl.Vertex(lastPoint.X, openGLControlView.Height - firstPoint.Y);
            gl.Vertex(firstPoint.X, openGLControlView.Height - firstPoint.Y);
            gl.End();
        }
Beispiel #3
0
        private void DrawQuadrangle(OpenGL gl, Interfaces.Point firstPoint, Interfaces.Point lastPoint)
        {
            gl.Color(fillColor.R / 255.0f, fillColor.G / 255.0f, fillColor.B / 255.0f, fillColor.A / 255.0f);
            gl.Begin(OpenGL.GL_QUADS);
            gl.Vertex(firstPoint.X, openGLControlView.Height - firstPoint.Y);
            gl.Vertex(firstPoint.X, openGLControlView.Height - lastPoint.Y);
            gl.Vertex(lastPoint.X, openGLControlView.Height - lastPoint.Y);
            gl.Vertex(lastPoint.X, openGLControlView.Height - firstPoint.Y);
            gl.End();

            gl.Color(borderColor.R / 255.0f, borderColor.G / 255.0f, borderColor.B / 255.0f, borderColor.A / 255.0f);
            gl.Begin(OpenGL.GL_LINES);
            gl.Vertex(firstPoint.X, openGLControlView.Height - firstPoint.Y);
            gl.Vertex(firstPoint.X, openGLControlView.Height - lastPoint.Y);

            gl.Vertex(firstPoint.X, openGLControlView.Height - lastPoint.Y);
            gl.Vertex(lastPoint.X, openGLControlView.Height - lastPoint.Y);

            gl.Vertex(lastPoint.X, openGLControlView.Height - lastPoint.Y);
            gl.Vertex(lastPoint.X, openGLControlView.Height - firstPoint.Y);

            gl.Vertex(lastPoint.X, openGLControlView.Height - firstPoint.Y);
            gl.Vertex(firstPoint.X, openGLControlView.Height - firstPoint.Y);
            gl.End();
        }
Beispiel #4
0
        private void openGLControlView_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (isModeSelectFigures)
                {
                    pickCommand.Execute(Tuple.Create(new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY), true));
                }
                else
                {
                    // тут к координатам точки прибавляю смещение полотна
                    AddNewLastPoint(new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY));

                    if (selectedFigure == Figures.Triangle)
                    {
                        if (iPointTriangle > 2)
                        {
                            iPointTriangle = 1;
                        }
                        else if (iPointTriangle == 2)
                        {
                            iPointTriangle++;

                            IFigure figure = Factory.Create(
                                "Triangle",
                                new Dictionary <string, object>()
                            {
                                { "Point1", last3Points[0] },
                                { "Point2", last3Points[1] },
                                { "Point3", last3Points[2] },
                                { "BorderColor", borderColor },
                                { "FillColor", fillColor }
                            });

                            addCommand.Execute(figure);
                        }
                        else
                        {
                            iPointTriangle++;
                        }
                    }
                    else
                    {
                        last3Points[0] = new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY);
                        last3Points[1] = new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY);
                        last3Points[2] = new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY);
                    }

                    isMouseDown         = true;
                    isStartDrag         = true;
                    isChangedOpenGLView = true;
                }
            }
            if (e.Button == MouseButtons.Middle)
            {//Тут будем зажимать колёсико
                isMiddleButton = true;
                prevLocationX  = e.X;
                prevLocationY  = e.Y;
            }
        }
Beispiel #5
0
        void DrawContourCircle(OpenGL gl, Interfaces.Point centerPoint, Interfaces.Point borderPoint, int numSegments)
        {
            double r     = GetDistance(centerPoint, borderPoint);
            double theta = 2.0 * Math.PI / (double)(numSegments);
            double cos   = Math.Cos(theta);
            double sin   = Math.Sin(theta);
            double t;

            double x = 1;
            double y = 0;

            gl.Begin(OpenGL.GL_LINE_LOOP);
            for (int ii = 0; ii < numSegments; ii++)
            {
                gl.Color(borderColor.R / 255.0f, borderColor.G / 255.0f, borderColor.B / 255.0f, borderColor.A / 255.0f);
                // Радиус и отступ
                gl.Vertex(x * r + centerPoint.X, openGLControlView.Height - (y * r + centerPoint.Y));

                // Матрица поворота
                t = x;
                x = cos * x - sin * y;
                y = sin * t + cos * y;
            }
            gl.End();
        }
Beispiel #6
0
        private void openGLControlView_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (!isLoadOpenGLView)
                {
                    return;
                }

                if (isMouseDown && (selectedFigure != Figures.Triangle))
                {
                    if (isStartDrag)
                    {
                        last3Points[2] = new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY);
                    }

                    last3Points[2] = new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY);

                    isChangedOpenGLView = true;
                }
                isStartDrag = false;
            }
            if (e.Button == MouseButtons.Middle)
            {//Тут будет двигаться полотно при зажатом колёсике
                canvasPositionX    -= e.Location.X - prevLocationX;
                canvasPositionY    -= e.Location.Y - prevLocationY;
                isChangedOpenGLView = true;
                Refresh();
                //glTranslate(e.Location.X - prevLocationX, prevLocationY - e.Location.Y, 0);
                prevLocationX = e.X;
                prevLocationY = e.Y;
            }
        }
Beispiel #7
0
 void ILogicForCommand.save(string filename)
 {
     List<SVGShape> ShapeList = new List<SVGShape>();
     IFigure buf;
     for (int i = 0; i < Figures.Count; i++)
     {
         buf = Figures.getFigure(i);
         Tuple<IEnumerable<trTriangle>, IEnumerable<ILineContainer>> triangulation;
         triangulation = buf.NewTriangulation(1.0);
         if (buf is VectorGraphicsEditor.Rectangle)
         {
             List<Interfaces.Point> points = (List<Interfaces.Point>)triangulation.Item2;
             Interfaces.Point min = findMinPoint(points);
             Interfaces.Point max = findMaxPoint(points);
             double xh, yh;
             xh = (max.X - min.X);
             yh = (max.Y - min.Y);
             ShapeList.Add(new SVGRect(min.X + xh / 2.0, min.Y + yh / 2.0, xh, yh, buf.FillColor, buf.LineColor));
         }
         if (buf is VectorGraphicsEditor.Triangle)
         {
             ShapeList.Add(new SVGPolygon((List<Interfaces.Point>)triangulation.Item2, buf.FillColor, buf.LineColor));
         }
         if (buf is VectorGraphicsEditor.Mutant)
         {
             ShapeList.Add(new SVGPolygon((List<Interfaces.Point>)triangulation.Item2, buf.FillColor, buf.LineColor));
         }
     }
     SVGIO.export(ShapeList, filename, 800, 600);
 }
Beispiel #8
0
 private void DrawLine(OpenGL gl, Interfaces.Point firstPoint, Interfaces.Point lastPoint, Interfaces.Color color)
 {
     gl.Begin(OpenGL.GL_LINES);
     gl.Color(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
     gl.Vertex(firstPoint.X, openGLControlView.Height - firstPoint.Y);
     gl.Color(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
     gl.Vertex(lastPoint.X, openGLControlView.Height - lastPoint.Y);
     gl.End();
 }
Beispiel #9
0
 Interfaces.Point findMaxPoint(List<Interfaces.Point> list)
 {
     Interfaces.Point max = list[0];
     foreach (Interfaces.Point item in list)
     {
         if (max.X <= item.X || max.Y <= item.Y)
             max = item;
     }
     return max;
 }
Beispiel #10
0
 Interfaces.Point findMinPoint(List<Interfaces.Point> list)
 {
     Interfaces.Point min = list[0];
     foreach (Interfaces.Point item in list)
     {
         if (min.X > item.X || min.Y > item.Y)
             min = item;
     }
     return min;
 }
Beispiel #11
0
        // выделение фигуры мышкой добавляет в список выделенных фигур. если add - true. При этом можно
        // начать заново выделять, если add - false
        void ILogicForCommand.addCurientFigure(Interfaces.Point dot, bool add)
        {
            bool find = false;
            int  index;

            for (index = Figures.Count - 1; index >= 0; index--)
            {
                //Проверяем лежит ли данная точка в этой фигуре
                find = Figures.getFigure(index).IsPointInner(dot);
                //Если нашли
                if (find)
                {
                    //если надо добавить
                    if (add)
                    {
                        //и текущей фигуры нет в списке элементов
                        if (CurientFigures.IndexOf(index) < 0)
                        {
                            //то выходим из цикла, или продолжаем поиски
                            break;
                        }
                        //иначе выходим
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (find)
            {
                if (add)
                {
                    CurientFigures.Add(index);
                }
                else
                {
                    CurientFigures.Clear();
                    CurientFigures.Add(index);
                }
            }
            else
            {
                if (!add)
                {
                    CurientFigures.Clear();
                }
            }
        }
Beispiel #12
0
        private void openGLControlView_MouseDown(object sender, MouseEventArgs e)
        {
            if (isModeSelectFigures)
            {
                // logic.SelectFigure(e.X, e.Y);
            }
            else
            {
                AddNewLastPoint(new Interfaces.Point(e.X, e.Y));

                if (selectedFigure == Figures.Triangle)
                {
                    if (iPointTriangle > 2)
                    {
                        iPointTriangle = 1;
                    }
                    else if (iPointTriangle == 2)
                    {
                        iPointTriangle++;

                        //IFigure figure = Factory.Create(
                        //    "Triangle",
                        //    new Dictionary<string, object>()
                        //    {
                        //        { "Point1", last3Points[0] },
                        //        { "Point2", last3Points[1] },
                        //        { "Point3", last3Points[2] }
                        //    });

                        //containerFigures.addNewFigure(figure);
                    }
                    else
                    {
                        iPointTriangle++;
                    }
                }
                else
                {
                    last3Points[0] = new Interfaces.Point(e.X, e.Y);
                    last3Points[1] = new Interfaces.Point(e.X, e.Y);
                    last3Points[2] = new Interfaces.Point(e.X, e.Y);
                }

                isMouseDown         = true;
                isStartDrag         = true;
                isChangedOpenGLView = true;
            }
        }
Beispiel #13
0
        private void DrawText(OpenGL gl, Interfaces.Point placeTextPoint, string text)
        {
            double[] modelView  = new double[16];
            double[] projection = new double[16];
            int[]    viewport   = new int[4];
            double[] tx         = new double[1];
            double[] ty         = new double[1];
            double[] tz         = new double[1];

            gl.GetDouble(OpenGL.GL_MODELVIEW_MATRIX, modelView);
            gl.GetDouble(OpenGL.GL_PROJECTION_MATRIX, projection);
            gl.GetInteger(OpenGL.GL_VIEWPORT, viewport);

            gl.Project(placeTextPoint.X, placeTextPoint.Y, 0, modelView, projection, viewport, tx, ty, tz);
            gl.DrawText(Convert.ToInt32(tx[0]), openGLControlView.Height - Convert.ToInt32(ty[0]), 0.0f, 0.0f, 0.0f, "Arial", 12, text);
        }
Beispiel #14
0
        int ILogicForGUI.GetIndexByPoint(Interfaces.Point a)
        {
            bool find = false;
            int  index;

            for (index = Figures.Count - 1; index >= 0; index--)
            {
                //Проверяем лежит ли данная точка в этой фигуре
                find = Figures.getFigure(index).IsPointInner(a);
                if (find)
                {
                    return(index);
                }
            }
            return(-1);
        }
Beispiel #15
0
        void DrawEllipse(OpenGL gl, Interfaces.Point leftUpperPoint, Interfaces.Point rightDownPoint, int numSegments)
        {
            Interfaces.Point centerPoint = new Interfaces.Point(leftUpperPoint.X + (rightDownPoint.X - leftUpperPoint.X) / 2.0, leftUpperPoint.Y + (rightDownPoint.Y - leftUpperPoint.Y) / 2.0);
            Interfaces.Point r           = new Interfaces.Point(Math.Abs(rightDownPoint.X - centerPoint.X), Math.Abs(rightDownPoint.Y - centerPoint.Y));
            double           theta       = 2.0 * Math.PI / (double)(numSegments);
            double           cos         = Math.Cos(theta);
            double           sin         = Math.Sin(theta);
            double           t;

            double x = 1;
            double y = 0;

            gl.Begin(OpenGL.GL_LINE_LOOP);
            for (int ii = 0; ii < numSegments; ii++)
            {
                gl.Color(borderColor.R / 255.0f, borderColor.G / 255.0f, borderColor.B / 255.0f, borderColor.A / 255.0f);
                // Радиус и отступ
                gl.Vertex(x * r.X + centerPoint.X, openGLControlView.Height - (y * r.Y + centerPoint.Y));

                // Матрица поворота
                t = x;
                x = cos * x - sin * y;
                y = sin * t + cos * y;
            }
            gl.End();


            x = 1;
            y = 0;

            gl.Begin(OpenGL.GL_POLYGON);
            for (int ii = 0; ii < numSegments; ii++)
            {
                gl.Color(fillColor.R / 255.0f, fillColor.G / 255.0f, fillColor.B / 255.0f, fillColor.A / 255.0f);
                // Радиус и отступ
                gl.Vertex(x * r.X + centerPoint.X, openGLControlView.Height - (y * r.Y + centerPoint.Y));

                // Матрица поворота
                t = x;
                x = cos * x - sin * y;
                y = sin * t + cos * y;
            }
            gl.End();
        }
Beispiel #16
0
        void DrawCircle(OpenGL gl, Interfaces.Point centerPoint, Interfaces.Point borderPoint, int numSegments)
        {
            double r     = Math.Sqrt((borderPoint.X - centerPoint.X) * (borderPoint.X - centerPoint.X) + (borderPoint.Y - centerPoint.Y) * (borderPoint.Y - centerPoint.Y));
            double theta = 2.0 * Math.PI / (double)(numSegments);
            double cos   = Math.Cos(theta);
            double sin   = Math.Sin(theta);
            double t;

            double x = 1;
            double y = 0;

            gl.Color(0, 0, 0);
            gl.Begin(OpenGL.GL_LINE_LOOP);
            for (int ii = 0; ii < numSegments; ii++)
            {
                // Радиус и отступ
                gl.Vertex(x * r + centerPoint.X, openGLControlView.Height - (y * r + centerPoint.Y));

                // Матрица поворота
                t = x;
                x = cos * x - sin * y;
                y = sin * t + cos * y;
            }
            gl.End();


            x = 1;
            y = 0;

            gl.Color(0, 0, 255, 0.14);
            gl.Begin(OpenGL.GL_POLYGON);
            for (int ii = 0; ii < numSegments; ii++)
            {
                // Радиус и отступ
                gl.Vertex(x * r + centerPoint.X, openGLControlView.Height - (y * r + centerPoint.Y));

                // Матрица поворота
                t = x;
                x = cos * x - sin * y;
                y = sin * t + cos * y;
            }
            gl.End();
        }
Beispiel #17
0
        void ILogicForCommand.load(string filename)
        {
            Tuple<List<SVGShape>, int, int> fromfile = SVGIO.import(filename);
            Figures.clear();
            CurientFigures.Clear();
            foreach (SVGShape item in fromfile.Item1)
            {
                if (item is SVGCircle)
                {

                }
                if (item is SVGEllipse)
                {

                }
                if (item is SVGRect)
                {
                    SVGRect fig = (SVGRect)item;
                    Interfaces.Point downleft = new Interfaces.Point(fig.rx - fig.width / 2.0, fig.ry - fig.height / 2.0);
                    Interfaces.Point upright = new Interfaces.Point(fig.rx + fig.width / 2.0, fig.ry + fig.height / 2.0);
                    Figures.addNewFigure(new VectorGraphicsEditor.Rectangle(downleft, upright, fig.stroke, fig.fill)
                }
                if (item is SVGPolygon)
                {
                    SVGPolygon fig = (SVGPolygon)item;
                    if (fig.points.Count == 3)
                    {
                        Figures.addNewFigure(new VectorGraphicsEditor.Triangle(fig.points[0], fig.points[1], fig.points[2], fig.stroke, fig.fill));
                    }
                    else
                    {
                        List<List<Segment>> list = new List<List<Segment>>();
                        list.Add(PointToSegment(fig.points));
                        Figures.addNewFigure(new VectorGraphicsEditor.Mutant(list, fig.stroke, fig.fill, 1.0));
                    }
                }
                if (item is SVGPath)
                {

                }
            }
        }
Beispiel #18
0
        private void openGLControlView_MouseMove(object sender, MouseEventArgs e)
        {
            if (!isLoadOpenGLView)
            {
                return;
            }

            if (isMouseDown && (selectedFigure != Figures.Triangle))
            {
                if (isStartDrag)
                {
                    last3Points[2] = new Interfaces.Point(e.X, e.Y);
                }

                last3Points[2] = new Interfaces.Point(e.X, e.Y);

                isChangedOpenGLView = true;
            }
            isStartDrag = false;
        }
Beispiel #19
0
        void ILogicForCommand.GetIndexFromPick(Interfaces.Point a, int myIndex)
        {
            bool find = false;
            int  index;

            for (index = Figures.Count - 1; index >= 0; index--)
            {
                //Проверяем лежит ли данная точка в этой фигуре
                find = Figures.getFigure(index).IsPointInner(a);
                if (find)
                {
                    break;
                }
                if (index == 0)
                {
                    myIndex = -1;
                    return;
                }
            }
            myIndex = index;
        }
Beispiel #20
0
        private void DrawAll()
        {
            OpenGL gl            = openGLControlView.OpenGL;
            int    contextWidth  = openGLControlView.Width;
            int    contextHeight = openGLControlView.Height;

            preGL2D(gl, openGLControlView.Width, openGLControlView.Height);

            Graphics graphics = this.CreateGraphics();

            // Берем наименьший dpi
            minDpi = Math.Min(graphics.DpiX, graphics.DpiY);

            IEnumerable <IFigure> figures = logic.Figures;

            foreach (var figure in figures)
            {
                Tuple <IEnumerable <trTriangle>, IEnumerable <ILineContainer> > triangulation;
                triangulation = figure.NewTriangulation(minDpi);

                // Обход по всем треугольникам
                foreach (var triangle in triangulation.Item1)
                {
                    DrawTriangle(gl, triangle, figure.FillColor);
                }

                // Обход по границам
                foreach (var border in triangulation.Item2)
                {
                    Interfaces.Point firstPointBorder = null;
                    Interfaces.Point prevPointBorder  = null;
                    bool             isFirst          = true;
                    foreach (var point in border.Path)
                    {
                        if (isFirst)
                        {
                            firstPointBorder = point;
                            isFirst          = false;
                            prevPointBorder  = point;
                            continue;
                        }
                        DrawLine(gl, prevPointBorder, point, figure.LineColor);
                        prevPointBorder = point;
                    }
                    DrawLine(gl, prevPointBorder, firstPointBorder, figure.LineColor);
                }
            }

            // Циркуль
            if (mode == Modes.Divider)
            {
                Interfaces.Point centerPoint = new Interfaces.Point(last3Points[1].X, last3Points[1].Y);
                Interfaces.Point borderPoint = new Interfaces.Point(last3Points[2].X, last3Points[2].Y);

                DrawContourCircle(gl, centerPoint, borderPoint, 360);
                DrawText(gl, centerPoint, string.Format("{0:0.000}", GetDistance(centerPoint, borderPoint)));
            }
            // Линейка
            else if (mode == Modes.Scale)
            {
                Interfaces.Point aPoint = new Interfaces.Point(last3Points[1].X, last3Points[1].Y);
                Interfaces.Point bPoint = new Interfaces.Point(last3Points[2].X, last3Points[2].Y);

                DrawLine(gl, aPoint, bPoint, new Interfaces.Color(0, 0, 0, 255));
                DrawText(gl, new Interfaces.Point(aPoint.X + (bPoint.X - aPoint.X) / 2.0f, aPoint.Y + (bPoint.Y - aPoint.Y) / 2.0f - 10), string.Format("{0:0.000}", GetDistance(aPoint, bPoint)));
            }
            else
            {
                switch (selectedFigure)
                {
                case Figures.Quadrangle:
                    DrawQuadrangle(gl,
                                   new Interfaces.Point(last3Points[1].X, last3Points[1].Y),
                                   new Interfaces.Point(last3Points[2].X, last3Points[2].Y));
                    break;

                case Figures.Triangle:
                    if (iPointTriangle > 2)
                    {
                        DrawTriangle(gl,
                                     new Interfaces.Point[3] {
                            new Interfaces.Point(last3Points[0].X, last3Points[0].Y),
                            new Interfaces.Point(last3Points[1].X, last3Points[1].Y),
                            new Interfaces.Point(last3Points[2].X, last3Points[2].Y)
                        });
                    }
                    else
                    {
                        DrawPointsTriangle(gl);
                    }
                    break;

                case Figures.Line:
                    DrawLine(gl,
                             new Interfaces.Point(last3Points[1].X, last3Points[1].Y),
                             new Interfaces.Point(last3Points[2].X, last3Points[2].Y), borderColor);
                    break;

                case Figures.Ellipse:
                    DrawEllipse(gl,
                                new Interfaces.Point(last3Points[1].X, last3Points[1].Y),
                                new Interfaces.Point(last3Points[2].X, last3Points[2].Y),
                                360
                                );
                    break;

                case Figures.Circle:
                    DrawCircle(gl,
                               new Interfaces.Point(last3Points[1].X, last3Points[1].Y),
                               new Interfaces.Point(last3Points[2].X, last3Points[2].Y),
                               quantitySegments
                               );
                    break;

                case Figures.Mutant:
                    DrawPointsMutant(gl);
                    break;
                }
            }

            gl.Flush();
            gl.Finish();
        }
Beispiel #21
0
 Interfaces.Point ILogicForGUI.ToScreen(Interfaces.Point xy)
 {
     throw new NotImplementedException();
 }
Beispiel #22
0
 void DrawCircle(OpenGL gl, Interfaces.Point centerPoint, Interfaces.Point borderPoint, int numSegments)
 {
     DrawContourCircle(gl, centerPoint, borderPoint, numSegments);
     DrawFillCircle(gl, centerPoint, borderPoint, numSegments);
 }
Beispiel #23
0
 private double GetDistance(Interfaces.Point a, Interfaces.Point b)
 {
     return(Math.Sqrt((b.X - a.X) * (b.X - a.X) + (b.Y - a.Y) * (b.Y - a.Y)));
 }
Beispiel #24
0
 void AddNewLastPoint(Interfaces.Point lastPoint)
 {
     last3Points[0] = last3Points[1];
     last3Points[1] = last3Points[2];
     last3Points[2] = lastPoint;
 }
Beispiel #25
0
        private void openGLControlView_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (isModeSelectFigures)
                {
                    int index = -2;
                    index = logic.GetIndexByPoint(new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY));
                    if (!ctrlPressed)
                    {
                        listViewLayers.SelectedItems.Clear();
                    }

                    if (index != -1)
                    {
                        if (ctrlPressed)
                        {
                            if (logic.CurientPickFigures.Contains(index))
                            {
                                listViewLayers.Items[index].Selected = false;
                            }
                            else
                            {
                                listViewLayers.Items[index].Selected = true;
                            }
                        }
                        else
                        {
                            listViewLayers.Items[index].Selected = true;
                        }
                    }
                    isChangedOpenGLView = true;
                }
                else
                {
                    // тут к координатам точки прибавляю смещение полотна
                    AddNewLastPoint(new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY));
                    readyToDrawTempFigure = true;
                    switch (selectedFigure)
                    {
                    case Figures.Triangle:
                        readyToDrawTempFigure = true;
                        if (iPointTriangle > 2)
                        {
                            iPointTriangle = 1;
                        }
                        else if (iPointTriangle == 2)
                        {
                            iPointTriangle++;

                            IFigure figure = Factory.Create(
                                "Triangle",
                                new Dictionary <string, object>()
                            {
                                { "Point1", last3Points[0] },
                                { "Point2", last3Points[1] },
                                { "Point3", last3Points[2] },
                                { "BorderColor", borderColor },
                                { "FillColor", fillColor }
                            });
                            listViewLayers.Items.Add("Triangle " + countTriangles.ToString());
                            countTriangles++;
                            // пока не дорисовали ещё точек - мы не будем отрисовывать
                            // временную фигуру
                            readyToDrawTempFigure = false;

                            addCommand.Execute(figure);
                        }
                        else
                        {
                            iPointTriangle++;
                        }
                        break;

                    case Figures.Mutant:
                        pointsMutant.Add(new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY));
                        break;

                    default:
                        last3Points[0] = new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY);
                        last3Points[1] = new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY);
                        last3Points[2] = new Interfaces.Point(e.X - canvasPositionX, e.Y - canvasPositionY);
                        break;
                    }



                    isMouseDown         = true;
                    isStartDrag         = true;
                    isChangedOpenGLView = true;
                }
            }
            if (e.Button == MouseButtons.Right)
            {//Тут будем зажимать колёсико
                isMiddleButton = true;
                prevLocationX  = e.X;
                prevLocationY  = e.Y;
            }
        }
Beispiel #26
0
        private void openGLControlView_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isMouseDown = false;

                switch (selectedFigure)
                {
                case Figures.Line:

                    //containerFigures.addNewFigure(
                    //    Factory.Create(
                    //    "Line",
                    //    new Dictionary<string, object>()
                    //    {
                    //        { "Point1", last3Points[1] },
                    //        { "Point2", last3Points[2] }
                    //    })
                    //);
                    break;

                case Figures.Quadrangle:
                {
                    IFigure figure =
                        Factory.Create(
                            "Rectangle",
                            new Dictionary <string, object>()
                        {
                            { "DownLeft", new Interfaces.Point(last3Points[1].X, last3Points[2].Y) },
                            { "UpRight", new Interfaces.Point(last3Points[2].X, last3Points[1].Y) },
                            { "BorderColor", borderColor },
                            { "FillColor", fillColor }
                        });
                    addCommand.Execute(figure);
                }
                break;

                case Figures.Circle:
                {
                    Interfaces.Point centerPoint = new Interfaces.Point(last3Points[1].X, last3Points[1].Y);
                    Interfaces.Point borderPoint = new Interfaces.Point(last3Points[2].X, last3Points[2].Y);

                    double radius = GetDistance(centerPoint, borderPoint);

                    double a = radius;
                    double b = radius;


                    Interfaces.Point begPoint = new Interfaces.Point(centerPoint.X + radius, centerPoint.Y);
                    Interfaces.Point endPoint = new Interfaces.Point(centerPoint.X - radius, centerPoint.Y);

                    List <List <Segment> > fragments = new List <List <Segment> >();
                    List <Segment>         segments  = new List <Segment>();
                    segments.Add(new EllipseArc(centerPoint, a, b, 0, Math.PI, begPoint, endPoint, 0));
                    segments.Add(new EllipseArc(centerPoint, a, b, 0, Math.PI, endPoint, begPoint, 0));

                    fragments.Add(segments);

                    IFigure figure = new Mutant(fragments, borderColor, fillColor, 1);
                    addCommand.Execute(figure);
                }
                break;

                case Figures.Ellipse:

                {
                    Interfaces.Point centerPoint = new Interfaces.Point(last3Points[1].X + (last3Points[2].X - last3Points[1].X) / 2.0, last3Points[1].Y + (last3Points[2].Y - last3Points[1].Y) / 2.0);

                    double radius = GetDistance(last3Points[1], last3Points[2]) / 2.0;

                    double a = Math.Abs(centerPoint.X - last3Points[1].X);
                    double b = Math.Abs(centerPoint.Y - last3Points[1].Y);


                    Interfaces.Point begPoint = new Interfaces.Point(centerPoint.X + a, centerPoint.Y);
                    Interfaces.Point endPoint = new Interfaces.Point(centerPoint.X - a, centerPoint.Y);

                    List <List <Segment> > fragments = new List <List <Segment> >();
                    List <Segment>         segments  = new List <Segment>();
                    segments.Add(new EllipseArc(centerPoint, a, b, 0, Math.PI, begPoint, endPoint, 0));
                    segments.Add(new EllipseArc(centerPoint, a, b, 0, Math.PI, endPoint, begPoint, 0));

                    fragments.Add(segments);

                    IFigure figure = new Mutant(fragments, borderColor, fillColor, 1);
                    addCommand.Execute(figure);
                }
                break;
                }
                isStartDrag = false;
            }
            if (e.Button == MouseButtons.Middle)
            {
                isMiddleButton = false;
            }
        }
Beispiel #27
0
        private void DrawAll()
        {
            OpenGL gl            = openGLControlView.OpenGL;
            int    contextWidth  = openGLControlView.Width;
            int    contextHeight = openGLControlView.Height;

            preGL2D(gl, openGLControlView.Width, openGLControlView.Height);

            Graphics graphics = this.CreateGraphics();

            // Берем наименьший dpi
            minDpi = Math.Min(graphics.DpiX, graphics.DpiY);

            //foreach (var obj in listForDisplay)
            //{
            //    foreach (var line in obj)
            //    {
            //        int i = 0;
            //        Interfaces.Point[] pointsLines = new Interfaces.Point[3];
            //        foreach (var path in line.Path)
            //        {
            //            pointsLines[i] = path;
            //            i++;
            //        }

            //        DrawTriangle(gl, pointsLines);
            //    }
            //}

            List <IFigure> figures = containerFigures.getFigures();

            //Dictionary<string, object> figureParameters;

            foreach (var figure in figures)
            {
                //figureParameters = figure.Parameters;
                //if (figure is Rectangle)
                //{
                //    //Interfaces.Point leftDownPoint = (Interfaces.Point)figureParameters["DownLeft"];
                //    //Interfaces.Point rightUpPoint = (Interfaces.Point)figureParameters["UpRight"];
                //    //DrawQuadrangle(gl,
                //    //    new Interfaces.Point(leftDownPoint.X, rightUpPoint.Y),
                //    //    new Interfaces.Point(rightUpPoint.X, leftDownPoint.Y));
                //}

                Tuple <IEnumerable <trTriangle>, IEnumerable <ILineContainer> > triangulation;
                triangulation = figure.NewTriangulation(minDpi);

                // Обход по всем треугольникам
                foreach (var triangle in triangulation.Item1)
                {
                    DrawTriangle(gl, triangle, figure.FillColor);
                }


                foreach (var border in triangulation.Item2)
                {
                    Interfaces.Point firstPointBorder = null;
                    Interfaces.Point prevPointBorder  = null;
                    bool             isFirst          = true;
                    foreach (var point in border.Path)
                    {
                        if (isFirst)
                        {
                            firstPointBorder = point;
                            isFirst          = false;
                            prevPointBorder  = point;
                            continue;
                        }
                        DrawLine(gl, prevPointBorder, point);
                        prevPointBorder = point;
                    }
                    DrawLine(gl, prevPointBorder, firstPointBorder);
                }
            }

            switch (selectedFigure)
            {
            case Figures.Quadrangle:
                DrawQuadrangle(gl,
                               new Interfaces.Point(last3Points[1].X, last3Points[1].Y),
                               new Interfaces.Point(last3Points[2].X, last3Points[2].Y));
                break;

            case Figures.Triangle:
                if (iPointTriangle > 2)
                {
                    DrawTriangle(gl,
                                 new Interfaces.Point[3] {
                        new Interfaces.Point(last3Points[0].X, last3Points[0].Y),
                        new Interfaces.Point(last3Points[1].X, last3Points[1].Y),
                        new Interfaces.Point(last3Points[2].X, last3Points[2].Y)
                    });
                }
                else
                {
                    DrawPoints(gl);
                }
                break;

            case Figures.Line:
                DrawLine(gl,
                         new Interfaces.Point(last3Points[1].X, last3Points[1].Y),
                         new Interfaces.Point(last3Points[2].X, last3Points[2].Y));
                break;

            case Figures.Ellipse:
                DrawEllipse(gl,
                            new Interfaces.Point(last3Points[1].X, last3Points[1].Y),
                            new Interfaces.Point(last3Points[2].X, last3Points[2].Y),
                            360
                            );
                break;

            case Figures.Circle:
                DrawCircle(gl,
                           new Interfaces.Point(last3Points[1].X, last3Points[1].Y),
                           new Interfaces.Point(last3Points[2].X, last3Points[2].Y),
                           360
                           );
                break;
            }

            gl.Flush();
            gl.Finish();
        }
Beispiel #28
0
        private void openGLControlView_MouseUp(object sender, MouseEventArgs e)
        {
            if (isModeSelectFigures)
            {
                return;
            }
            else
            if (e.Button == MouseButtons.Left)
            {
                isMouseDown = false;

                switch (selectedFigure)
                {
                case Figures.Line:

                    //containerFigures.addNewFigure(
                    //    Factory.Create(
                    //    "Line",
                    //    new Dictionary<string, object>()
                    //    {
                    //        { "Point1", last3Points[1] },
                    //        { "Point2", last3Points[2] }
                    //    })
                    //);
                    break;

                case Figures.Quadrangle:
                {
                    IFigure figure =
                        Factory.Create(
                            "Rectangle",
                            new Dictionary <string, object>()
                        {
                            { "DownLeft", new Interfaces.Point(last3Points[1].X, last3Points[2].Y) },
                            { "UpRight", new Interfaces.Point(last3Points[2].X, last3Points[1].Y) },
                            { "BorderColor", borderColor },
                            { "FillColor", fillColor }
                        });
                    listViewLayers.Items.Add("Rectangle " + countRectangles.ToString());
                    countRectangles++;
                    // пока не дорисовали ещё точек - мы не будем отрисовывать
                    // временную фигуру
                    readyToDrawTempFigure = false;
                    addCommand.Execute(figure);
                }

                break;

                case Figures.Circle:
                {
                    Interfaces.Point centerPoint = new Interfaces.Point(last3Points[1].X, last3Points[1].Y);
                    Interfaces.Point borderPoint = new Interfaces.Point(last3Points[2].X, last3Points[2].Y);

                    double radius = GetDistance(centerPoint, borderPoint);

                    double a = radius;
                    double b = radius;


                    Interfaces.Point begPoint = new Interfaces.Point(centerPoint.X + radius, centerPoint.Y);
                    Interfaces.Point endPoint = new Interfaces.Point(centerPoint.X - radius, centerPoint.Y);

                    List <List <Segment> > fragments = new List <List <Segment> >();
                    List <Segment>         segments  = new List <Segment>();
                    segments.Add(new EllipseArc(centerPoint, a, b, 0, Math.PI, begPoint, endPoint, 0));
                    segments.Add(new EllipseArc(centerPoint, a, b, 0, Math.PI, endPoint, begPoint, 0));

                    fragments.Add(segments);

                    IFigure figure = new Mutant(fragments, borderColor, fillColor, 1);
                    addCommand.Execute(figure);
                    listViewLayers.Items.Add("Circle " + countCircles.ToString());
                    countCircles++;
                    // пока не дорисовали ещё точек - мы не будем отрисовывать
                    // временную фигуру
                    readyToDrawTempFigure = false;
                }
                break;

                case Figures.Ellipse:

                {
                    Interfaces.Point centerPoint = new Interfaces.Point(last3Points[1].X + (last3Points[2].X - last3Points[1].X) / 2.0, last3Points[1].Y + (last3Points[2].Y - last3Points[1].Y) / 2.0);

                    double radius = GetDistance(last3Points[1], last3Points[2]) / 2.0;

                    double a = Math.Abs(centerPoint.X - last3Points[1].X);
                    double b = Math.Abs(centerPoint.Y - last3Points[1].Y);


                    Interfaces.Point begPoint = new Interfaces.Point(centerPoint.X + a, centerPoint.Y);
                    Interfaces.Point endPoint = new Interfaces.Point(centerPoint.X - a, centerPoint.Y);

                    List <List <Segment> > fragments = new List <List <Segment> >();
                    List <Segment>         segments  = new List <Segment>();
                    segments.Add(new EllipseArc(centerPoint, a, b, 0, Math.PI, begPoint, endPoint, 0));
                    segments.Add(new EllipseArc(centerPoint, a, b, 0, Math.PI, endPoint, begPoint, 0));

                    fragments.Add(segments);

                    IFigure figure = new Mutant(fragments, borderColor, fillColor, 1);
                    addCommand.Execute(figure);
                    listViewLayers.Items.Add("Elipse " + countElipses.ToString());
                    countElipses++;
                    // пока не дорисовали ещё точек - мы не будем отрисовывать
                    // временную фигуру
                    readyToDrawTempFigure = false;
                }
                break;
                }
                isStartDrag = false;
            }
            if (e.Button == MouseButtons.Right)
            {
                isMiddleButton = false;
            }
        }