예제 #1
0
        private void Paint()
        {
            isPainting = true;
            testcanvas.Children.Clear();

            try
            {
                if (model.AvailableOutlinePolygon != null)
                {
                    Polygon p = model.AvailableOutlinePolygon;
                    p.Fill    = Brushes.White;
                    p.Opacity = 0.1;
                    p.ToolTip = "Available space";

                    testcanvas.Children.Add(p);
                }
            }
            catch (Exception e)
            {
                Logger.WriteLog(e);
            }


            foreach (_Room room in Rooms)
            {
                try
                {
                    List <_Point> boundaries = room.GetPoints();
                    if (!boundaries.Any())
                    {
                        continue;
                    }
                    //List<PointF> convertedPoints = boundaries.Select(i => new PointF((float) i.X, (float) i.Y)).ToList();
                    List <Point> convertedPointsForPolygon = boundaries.Select(i => new Point(i.X, i.Y)).ToList();
                    //System.Drawing.PointF center = Utils.GetCentroid(convertedPoints);
                    Polygon p = new Polygon();
                    p.Points  = new PointCollection(convertedPointsForPolygon);
                    p.Fill    = new SolidColorBrush(room.type.fillColor.ToMediaColor());
                    p.Opacity = 0.25;
                    p.ToolTip = room.ToString();

                    testcanvas.Children.Add(p);
                }
                catch (Exception e)
                {
                    Logger.WriteLog(e);
                }
            }
            var   allLinesFlat = model.AllLinesFlat();
            Brush greyBrush    = new SolidColorBrush(Color.FromArgb(100, 255, 255, 255));
            Brush redBrush     = Brushes.Red;
            Brush yellowBrush  = Brushes.Yellow;

            greyBrush.Opacity = 0.5;
            for (var i = 0; i < allLinesFlat.Count; i++)
            {
                _Line     line  = allLinesFlat[i];
                ShapeLine _line = new ShapeLine();
                if (line.HasDoor)
                {
                    ShapeLine _line2 = new ShapeLine();
                    _Point    n      = line.GetNV(true);
                    _line2.Stroke             = redBrush;
                    _line2.X1                 = (line.StartPoint.X + line.EndPoint.X) / 2;
                    _line2.X2                 = (line.StartPoint.X + line.EndPoint.X) / 2 + n.X * 10;
                    _line2.Y1                 = (line.StartPoint.Y + line.EndPoint.Y) / 2;
                    _line2.Y2                 = (line.StartPoint.Y + line.EndPoint.Y) / 2 + n.Y * 10;
                    _line2.StrokeEndLineCap   = PenLineCap.Triangle;
                    _line2.StrokeStartLineCap = PenLineCap.Round;
                    _line2.StrokeThickness    = 10;
                    _line2.ToolTip            = line.ToString();
                    testcanvas.Children.Add(_line2);
                }

                _line.Stroke = selectedLineIndices.Contains(i) ? yellowBrush : greyBrush;

                _line.X1 = line.StartPoint.X;
                _line.X2 = line.EndPoint.X;
                _line.Y1 = line.StartPoint.Y;
                _line.Y2 = line.EndPoint.Y;
                _line.StrokeEndLineCap   = PenLineCap.Triangle;
                _line.StrokeStartLineCap = PenLineCap.Round;
                _line.StrokeThickness    = 5;
                _line.ToolTip            = line.ToString();
                testcanvas.Children.Add(_line);
            }

            List <_Point> allPointsFlat   = model.AllPointsFlat();
            var           solidColorBrush = new SolidColorBrush(Color.FromArgb(90, 255, 0, 0));

            solidColorBrush.Opacity = 0.5;
            var GreenBrush = Brushes.GreenYellow;

            for (var i = 0; i < allPointsFlat.Count; i++)
            {
                _Point    point = allPointsFlat[i];
                ShapeLine _line = new ShapeLine();

                _line.Stroke = i.Equals(SelectedPointIndex) ? GreenBrush : solidColorBrush;

                _line.X1 = point.X;
                _line.X2 = point.X + 1;
                _line.Y1 = point.Y;
                _line.Y2 = point.Y + 1;
                _line.StrokeStartLineCap = PenLineCap.Round;
                _line.StrokeEndLineCap   = PenLineCap.Triangle;
                _line.StrokeThickness    = 10;
                _line.ToolTip            = point.ToString();
                testcanvas.Children.Add(_line);
            }

            isPainting = false;
        }