예제 #1
0
        private void pictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (PaintMode)
            {
                if (figure is TriangleFigure)
                {
                    if (figure.Points.Count % 3 == 0)
                    {
                        figure = figureFactory.CreateFigure(figure.FigureController);
                    }
                }
                if (!(figure is CurveFigure ||
                      figure is IrregularPolygonFigure ||
                      figure is TriangleFigure))
                {
                    figure = figureFactory.CreateFigure(figure.FigureController);
                }
                if (figure is PolygonFigure)
                {
                    PolygonFigure tmp = (PolygonFigure)figure;
                    tmp.N  = (int)numericUpDown.Value;
                    figure = tmp;
                }
                pictureBox.Image = canvas.TmpBitmap;

                figure.FigureController.MouseDownHandle(e.Location, pen, figure, canvas);
                pictureBox.Image = canvas.MainBitmap;
            }
            if (PaintMode == false)
            {
                toolController.MouseDownHandle(e.Location, pen, figure, canvas, container, tool);
                pictureBox.Image = canvas.MainBitmap;
            }
        }
예제 #2
0
        private void numericUpDown_TextChanged(object sender, EventArgs e)
        {
            PolygonFigure tmp = (PolygonFigure)figure;

            tmp.N = (int)numericUpDown.Value;
            Button Btn = sender as Button;

            if (Btn != null)
            {
                setColor(this, Btn);
            }
            figure = tmp;
        }
예제 #3
0
        public void AppendLine(string line)
        {
            var parseResult = RecognizeRegex.Matches(line);
            switch (parseResult[0].ToString())
            {
                case "add polygon":
                    {
                        if (parseResult.Count < 2)
                        {
                            throw new Exception("Can not recognize the command.");
                        }
                        this.name = parseResult[1].ToString();
                        break;
                    }

                case "add point":
                    {
                        var point = new Point(
                            double.Parse(parseResult[1].ToString(), CultureInfo.InvariantCulture),
                            double.Parse(parseResult[2].ToString(), CultureInfo.InvariantCulture));
                        if (this.tempPoints.Contains(point))
                        {
                            throw new Exception("Point already exists.");
                        }

                        this.tempPoints.Add(point);
                        break;
                    }

                case "end polygon":
                    {
                        if (this.tempPoints.Count < 3)
                        {
                            throw new Exception("Number points < 3");
                        }

                        if (IsIntersection(this.tempPoints))
                        {
                            throw new Exception("Polygon intersects itself");
                        }

                        this.polygon = new PolygonFigure(this.tempPoints);
                        break;
                    }

                default:
                    {
                        throw new Exception("Unexpected end of polygon.");
                    }
            }
        }
예제 #4
0
        //private Workspace _workspace;

        public DataInitialization(int Width, int Height)
        {
            var unityContainerInit = new UnityContainer();

            _action = unityContainerInit.Resolve <Actions>();

            _selectClass = unityContainerInit.Resolve <Selection>();

            _pointSelection = unityContainerInit.Resolve <PointSelection>();

            _rectangleSelection = unityContainerInit.Resolve <RectangleSelection>();

            _drawClass = unityContainerInit.Resolve <DrawOnCanvas>(new OrderedParametersOverride(new object[] { Width, Height, _action }));

            _editDate = unityContainerInit.Resolve <EditData>(new OrderedParametersOverride(new object[] { _drawClass, _action }));

            _rectangl        = unityContainerInit.Resolve <RectangleFigure>();
            _ellipse         = unityContainerInit.Resolve <EllipseFigure>();
            _line            = unityContainerInit.Resolve <Line>();
            _poliLine        = unityContainerInit.Resolve <PolylineFigure>();
            _polygon         = unityContainerInit.Resolve <PolygonFigure>();
            _rectangleSelect = unityContainerInit.Resolve <RectangleSelect>();

            _listFigures.Add(_rectangl);
            _listFigures.Add(_ellipse);
            _listFigures.Add(_line);
            _listFigures.Add(_poliLine);
            _listFigures.Add(_polygon);

            _drawListFigures.Add(_rectangl);
            _drawListFigures.Add(_ellipse);
            _drawListFigures.Add(_line);
            _drawListFigures.Add(_poliLine);
            _drawListFigures.Add(_polygon);
            _drawListFigures.Add(_rectangleSelect);

            _selectionList.Add(_pointSelection);
            _selectionList.Add(_rectangleSelection);

            _modesList.Add(unityContainerInit.Resolve <DrawMode>(new OrderedParametersOverride(new object[] { _listFigures, _selectClass, _drawClass })));
            _modesList.Add(unityContainerInit.Resolve <SelectRegionMode>(new OrderedParametersOverride(new object[] { _listFigures, _selectClass, _drawClass, _editDate, _selectionList })));
            _modesList.Add(unityContainerInit.Resolve <SelectPointoMode>(new OrderedParametersOverride(new object[] { _listFigures, _selectClass, _drawClass, _editDate, _selectionList })));

            _workspace = new Workspace(_selectClass, _drawClass, _editDate, _listFigures, _modesList, _drawListFigures);
        }
예제 #5
0
        public void AppendLine(string line)
        {
            if (RecognizeRegexStart.IsMatch(line))
            {
                var match = RecognizeRegexStart.Match(line);
                this.name = match.Groups[1].ToString();
            }
            else if (RecognizeRegexEnd.IsMatch(line))
            {
                if (this.polygonPoints.Count >= 3)
                {
                    this.polygon        = new PolygonFigure(this.polygonPoints);
                    this.IsCommandReady = true;
                }
                else
                {
                    throw new Exception("Количество точек полигона должно быть больше 2");
                }
            }
            else if (RecognizeRegexAdd.IsMatch(line))
            {
                var match           = RecognizeRegexAdd.Match(line);
                var newPolygonPoint = new Point(
                    Convert.ToDouble(match.Groups[1].Value),
                    Convert.ToDouble(match.Groups[2].Value));
                var isCoincided = this.polygonPoints.Contains(newPolygonPoint);
                this.polygonPoints.Add(newPolygonPoint);

                if (isCoincided || IsIntersection(this.polygonPoints))
                {
                    throw new Exception("Точка полигона совпадает с одной из предыдущих или образует пересечение с одной из предыдущих сторон");
                }
            }
            else
            {
                throw new Exception("Неправильный формат ввода данных");
            }
        }
예제 #6
0
 /// <summary>
 ///  Write figure sides to Xml file using StreamWriter
 /// </summary>
 /// <param name="writer">StreamWriter object</param>
 /// <param name="figure">The figure whose sides should be written</param>
 protected void WriteSides(StreamWriter writer, PolygonFigure figure) => writer.WriteLine($"<{nameof(figure.Sides)}>{string.Join(" ", figure.Sides.Select(s => Convert.ToString(s)))}</{nameof(figure.Sides)}>");
예제 #7
0
 /// <summary>
 ///  Write figure sides to Xml file using XmlWriter
 /// </summary>
 /// <param name="writer">XmlWriter object</param>
 /// <param name="figure">The figure whose sides should be written</param>
 protected void WriteSides(XmlWriter writer, PolygonFigure figure) => writer.WriteElementString(nameof(figure.Sides), string.Join(" ", figure.Sides.Select(s => Convert.ToString(s))));
예제 #8
0
 public void Init()
 {
     this.polygon = new PolygonFigure(new List<Point> { new Point(0, 0), new Point(0, 1), new Point(1, 1) });
 }