Example #1
0
        public void Draw(IDisplay display, IGeometry geometry, TextSymbolAlignment symbolAlignment)
        {
            if (_font == null)
            {
                return;
            }

            if (geometry is IPoint)
            {
                #region IPoint

                double x = ((IPoint)geometry).X;
                double y = ((IPoint)geometry).Y;
                display.World2Image(ref x, ref y);
                IPoint p = new gView.Framework.Geometry.Point(x, y);

                DrawAtPoint(display, p, _text, 0, StringFormatFromAlignment(symbolAlignment));

                #endregion
            }
            if (geometry is IMultiPoint)
            {
                #region IMultiPoint

                IMultiPoint pColl = (IMultiPoint)geometry;
                for (int i = 0; i < pColl.PointCount; i++)
                {
                    double x = pColl[i].X;
                    double y = pColl[i].Y;

                    display.World2Image(ref x, ref y);
                    IPoint p = new gView.Framework.Geometry.Point(x, y);

                    DrawAtPoint(display, p, _text, 0, StringFormatFromAlignment(symbolAlignment));
                }

                #endregion
            }
            else if (geometry is IDisplayPath && ((IDisplayPath)geometry).AnnotationPolygonCollision is AnnotationPolygonCollection)
            {
                if (String.IsNullOrEmpty(_text))
                {
                    return;
                }

                IDisplayPath path = (IDisplayPath)geometry;
                AnnotationPolygonCollection apc = path.AnnotationPolygonCollision as AnnotationPolygonCollection;
                var format = StringFormatFromAlignment(symbolAlignment);
                format.LineAlignment = StringAlignment.Center;
                format.Alignment     = StringAlignment.Center;

                if (_text.Length == apc.Count)
                {
                    int drawingLevels = this.DrawingLevels; // Für Blockout und Glowing Text -> Zuerst den Blockout für alle Zeichen...
                    for (int level = 0; level < drawingLevels; level++)
                    {
                        for (int i = 0; i < _text.Length; i++)
                        {
                            AnnotationPolygon ap = apc[i] as AnnotationPolygon;
                            if (ap != null)
                            {
                                var centerPoint = ap.CenterPoint;
                                DrawAtPoint(display, new Geometry.Point(centerPoint.X, centerPoint.Y), _text[i].ToString(), (float)ap.Angle, format, level);
                            }
                        }
                    }
                }

                #region Old Method

                /*
                 #region Text On Path
                 * StringFormat format = stringFormatFromAlignment;
                 * DisplayCharacterRanges ranges = new DisplayCharacterRanges(display.GraphicsContext, _font, format, _text);
                 *
                 * double sizeW = ranges.Width;
                 * double len = path.Length;
                 * double stat0 = len / 2 - sizeW / 2, stat1 = stat0 + sizeW;
                 * if (stat0 < 0) return;
                 *
                 #region Richtung des Textes
                 * Geometry.Point p1_ = SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat0);
                 * Geometry.Point p2_ = SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat1);
                 * if (p1_ == null || p2_ == null)
                 *  return;
                 * if (p1_.X > p2_.X)
                 * {
                 #region Swap Path Direction
                 *  path.ChangeDirection();
                 #endregion
                 * }
                 #endregion
                 *
                 * AnnotationPolygonCollection charPolygons = new AnnotationPolygonCollection();
                 * double x, y, angle;
                 *
                 * for (int i = 0; i < _text.Length; i++)
                 * {
                 *  RectangleF cSize = ranges[i];
                 *  Geometry.Point p1, p2;
                 *  while (true)
                 *  {
                 *      p1 = SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat0);
                 *      p2 = SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat0 + cSize.Width);
                 *      if (p1 == null || p2 == null)
                 *          return;
                 *
                 *      angle = Math.Atan2(p2.Y - p1.Y, p2.X - p1.X) * 180.0 / Math.PI;
                 *
                 *      x = p1.X; y = p1.Y;
                 *      AnnotationPolygon polygon = null;
                 *      switch (format.LineAlignment)
                 *      {
                 *          case StringAlignment.Near:
                 *              polygon = new Symbology.AnnotationPolygon((float)x + .1f * cSize.Width, (float)y + .2f * cSize.Height,
                 *                                                         .8f * cSize.Width, .6f * cSize.Height);
                 *              break;
                 *          case StringAlignment.Far:
                 *              polygon = new Symbology.AnnotationPolygon((float)x + .1f * cSize.Width, (float)y - .8f * cSize.Height,
                 *                                                         .8f * cSize.Width, .6f * cSize.Height);
                 *              break;
                 *          default:
                 *              polygon = new Symbology.AnnotationPolygon((float)x + .1f * cSize.Width, (float)y - .6f * cSize.Height / 2f,
                 *                                                         .8f * cSize.Width, .6f * cSize.Height);
                 *              break;
                 *      }
                 *      polygon.Rotate((float)x, (float)y, Angle + angle);
                 *      if (charPolygons.CheckCollision(polygon))
                 *      {
                 *          stat0 += cSize.Width / 10.0;
                 *          continue;
                 *      }
                 *      charPolygons.Add(polygon);
                 *
                 *      //using (System.Drawing.Drawing2D.GraphicsPath grpath = new System.Drawing.Drawing2D.GraphicsPath())
                 *      //{
                 *      //    grpath.StartFigure();
                 *      //    grpath.AddLine(polygon[0], polygon[1]);
                 *      //    grpath.AddLine(polygon[1], polygon[2]);
                 *      //    grpath.AddLine(polygon[2], polygon[3]);
                 *      //    grpath.CloseFigure();
                 *
                 *      //    display.GraphicsContext.FillPath(Brushes.Aqua, grpath);
                 *      //}
                 *
                 *      break;
                 *  }
                 *
                 *  if (format.Alignment == StringAlignment.Center)
                 *  {
                 *      x = p1.X * 0.5 + p2.X * 0.5;
                 *      y = p1.Y * 0.5 + p2.Y * 0.5;
                 *  }
                 *  else if (format.Alignment == StringAlignment.Far)
                 *  {
                 *      x = p2.X;
                 *      y = p2.Y;
                 *  }
                 *  else
                 *  {
                 *      x = p1.X;
                 *      y = p1.Y;
                 *  }
                 *  DrawAtPoint(display, new Geometry.Point(x, y), _text[i].ToString(), (float)angle, format);
                 *
                 *  stat0 += (double)cSize.Width;
                 * }
                 * //display.GraphicsContext.FillEllipse(Brushes.Green, (float)p1_.X - 3, (float)p1_.Y - 3, 6f, 6f);
                 * //display.GraphicsContext.FillEllipse(Brushes.Blue, (float)p2_.X - 3, (float)p2_.Y - 3, 6f, 6f);
                 #endregion
                 * */
                #endregion
            }
            else if (geometry is IPolyline)
            {
                IPolyline pLine = (IPolyline)geometry;
                for (int iPath = 0; iPath < pLine.PathCount; iPath++)
                {
                    IPath path = pLine[iPath];
                    if (path.PointCount == 0)
                    {
                        continue;
                    }

                    #region Parallel Text

                    IPoint p1 = path[0], p2;
                    for (int iPoint = 1; iPoint < path.PointCount; iPoint++)
                    {
                        p2 = path[iPoint];
                        double angle = -Math.Atan2(p2.Y - p1.Y, p2.X - p1.X) * 180.0 / Math.PI;
                        if (display.DisplayTransformation.UseTransformation)
                        {
                            angle -= display.DisplayTransformation.DisplayRotation;
                        }

                        var format = StringFormatFromAlignment(symbolAlignment);

                        if (angle < 0)
                        {
                            angle += 360;
                        }

                        if (angle > 90 && angle < 270)
                        {
                            if (format.Alignment != StringAlignment.Center)
                            {
                                // swap points & alignment
                                var p_ = p1;
                                p1 = p2;
                                p2 = p_;
                                if (format.Alignment == StringAlignment.Far)
                                {
                                    format.Alignment = StringAlignment.Near;
                                }
                                else if (format.Alignment == StringAlignment.Near)
                                {
                                    format.Alignment = StringAlignment.Far;
                                }
                            }
                            angle -= 180;
                        }


                        double x, y;
                        if (format.Alignment == StringAlignment.Center)
                        {
                            x = p1.X * 0.5 + p2.X * 0.5;
                            y = p1.Y * 0.5 + p2.Y * 0.5;
                        }
                        else if (format.Alignment == StringAlignment.Far)
                        {
                            x = p2.X;
                            y = p2.Y;
                        }
                        else
                        {
                            x = p1.X;
                            y = p1.Y;
                        }
                        display.World2Image(ref x, ref y);
                        IPoint p = new gView.Framework.Geometry.Point(x, y);

                        //_text += "  " + angle.ToString();
                        DrawAtPoint(display, p, _text, (float)angle, format);
                        p1 = p2;
                    }

                    #endregion
                }
            }
            else if (geometry is IPolygon)
            {
                /*
                 * GraphicsPath path = DisplayOperations.Geometry2GraphicsPath(display, geometry);
                 *
                 * foreach (PointF point in gView.SpatialAlgorithms.Algorithm.LabelPoints(path))
                 * {
                 *  DrawAtPoint(display, new gView.Framework.Geometry.Point(point.X, point.Y), 0, stringFormatFromAlignment);
                 * }
                 * */
            }
            else if (geometry is IAggregateGeometry)
            {
                for (int i = 0; i < ((IAggregateGeometry)geometry).GeometryCount; i++)
                {
                    Draw(display, ((IAggregateGeometry)geometry)[i]);
                }
            }
        }
Example #2
0
        public List <IAnnotationPolygonCollision> AnnotationPolygon(IDisplay display, IGeometry geometry, TextSymbolAlignment symbolAlignment)
        {
            if (_font == null || _text == null || display.Canvas == null)
            {
                return(null);
            }

            List <IAnnotationPolygonCollision> polygons = new List <IAnnotationPolygonCollision>();

            if (geometry is IPoint)
            {
                #region IPoint

                double x = ((IPoint)geometry).X;
                double y = ((IPoint)geometry).Y;
                display.World2Image(ref x, ref y);

                var annotationPolygon = AnnotationPolygon(display, (float)x, (float)y, symbolAlignment);
                annotationPolygon.Rotate((float)x, (float)y, Angle);

                polygons.Add(annotationPolygon);

                #endregion
            }
            else if (geometry is IMultiPoint)
            {
                #region IMultipoint
                IMultiPoint pColl = (IMultiPoint)geometry;
                for (int i = 0; i < pColl.PointCount; i++)
                {
                    double x = pColl[i].X;
                    double y = pColl[i].Y;

                    display.World2Image(ref x, ref y);

                    var annotationPolygon = AnnotationPolygon(display, (float)x, (float)y, symbolAlignment);
                    annotationPolygon.Rotate((float)x, (float)y, Angle);

                    polygons.Add(annotationPolygon);
                }
                #endregion
            }
            else if (geometry is IDisplayPath)
            {
                if (String.IsNullOrEmpty(_text))
                {
                    return(null);
                }

                IDisplayPath path = (IDisplayPath)geometry;

                #region Text On Path
                var format = StringFormatFromAlignment(_align);

                IDisplayCharacterRanges ranges = this.MeasureCharacterWidth(display);
                float sizeW = ranges.Width;
                float stat0 = path.Chainage, stat1 = stat0 + sizeW, stat = stat0;
                if (stat0 < 0)
                {
                    return(null);
                }

                #region Richtung des Textes

                CanvasPointF?p1_ = path.PointAt(stat0);  //SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat0);
                CanvasPointF?p2_ = path.PointAt(stat1);  //SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat1);
                if (!p1_.HasValue || !p2_.HasValue)
                {
                    return(null);
                }

                if (p1_.Value.X > p2_.Value.X)
                {
                    #region Swap Path Direction

                    path.ChangeDirection();
                    stat  = stat0 = path.Length - stat1;
                    stat1 = stat0 + sizeW;

                    #endregion
                }
                #endregion

                AnnotationPolygonCollection charPolygons = new AnnotationPolygonCollection();
                float x, y, angle;

                for (int i = 0; i < _text.Length; i++)
                {
                    CanvasRectangleF cSize = ranges[i];
                    int counter            = 0;

                    while (true)
                    {
                        CanvasPointF?p1 = path.PointAt(stat);  //SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat);
                        CanvasPointF?p2 = path.PointAt(stat + cSize.Width);
                        if (!p1.HasValue || !p2.HasValue)
                        {
                            return(null);
                        }

                        angle = (float)(Math.Atan2(p2.Value.Y - p1.Value.Y, p2.Value.X - p1.Value.X) * 180.0 / Math.PI);

                        //float ccc = 0f;
                        //angle = 0f;
                        //for (float xxx = 0f; xxx <= cSize.Width; xxx += cSize.Width / 10f, ccc += 1f)
                        //{
                        //    p2 = path.PointAt(stat + xxx/*cSize.Width*/); //SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat + cSize.Width);
                        //    if (p1 == null || p2 == null)
                        //        return null;

                        //    angle += (float)(Math.Atan2(((PointF)p2).Y - ((PointF)p1).Y, ((PointF)p2).X - ((PointF)p1).X) * 180.0 / Math.PI);
                        //}
                        //angle /= ccc;

                        x = p1.Value.X; y = p1.Value.Y;
                        AnnotationPolygon polygon = null;
                        switch (format.LineAlignment)
                        {
                        case StringAlignment.Near:
                            polygon = new Symbology.AnnotationPolygon((float)x + .1f * cSize.Width, (float)y + .2f * cSize.Height,
                                                                      .8f * cSize.Width, .6f * cSize.Height);
                            break;

                        case StringAlignment.Far:
                            polygon = new Symbology.AnnotationPolygon((float)x + .1f * cSize.Width, (float)y - .8f * cSize.Height,
                                                                      .8f * cSize.Width, .6f * cSize.Height);
                            break;

                        default:
                            polygon = new Symbology.AnnotationPolygon((float)x + .1f * cSize.Width, (float)y - .6f * cSize.Height / 2f,
                                                                      .8f * cSize.Width, .6f * cSize.Height);
                            break;
                        }
                        polygon.Rotate((float)x, (float)y, Angle + angle);
                        if (charPolygons.CheckCollision(polygon))
                        {
                            stat += cSize.Width / 10.0f;
                            counter++;
                            if (counter > 7)
                            {
                                return(null);
                            }

                            continue;
                        }
                        charPolygons.Add(polygon);

                        //using (System.Drawing.Drawing2D.GraphicsPath grpath = new System.Drawing.Drawing2D.GraphicsPath())
                        //{
                        //    grpath.StartFigure();
                        //    grpath.AddLine(polygon[0], polygon[1]);
                        //    grpath.AddLine(polygon[1], polygon[2]);
                        //    grpath.AddLine(polygon[2], polygon[3]);
                        //    grpath.CloseFigure();

                        //    display.GraphicsContext.FillPath(Brushes.Aqua, grpath);
                        //}

                        break;
                    }
                    stat += cSize.Width;// +_font.Height * 0.1f;
                }

                if (charPolygons.Count > 0)
                {
                    #region Glättung
                    //for (int i = 1; i < charPolygons.Count - 1; i++)
                    //{
                    //    double angle0 = ((AnnotationPolygon)charPolygons[i - 1]).Angle;
                    //    double angle2 = ((AnnotationPolygon)charPolygons[i + 1]).Angle;
                    //    ((AnnotationPolygon)charPolygons[i]).Angle = (angle0 + angle2) * 0.5;

                    //    float x0 = ((AnnotationPolygon)charPolygons[i - 1]).X1;
                    //    float y0 = ((AnnotationPolygon)charPolygons[i - 1]).Y1;
                    //    float x2 = ((AnnotationPolygon)charPolygons[i + 1]).X1;
                    //    float y2 = ((AnnotationPolygon)charPolygons[i + 1]).Y1;
                    //    ((AnnotationPolygon)charPolygons[i]).X1 = (x0 + x2) * 0.5f;
                    //    ((AnnotationPolygon)charPolygons[i]).Y1 = (y0 + y2) * 0.5f;
                    //}
                    #endregion

                    polygons.Add(charPolygons);
                    path.AnnotationPolygonCollision = charPolygons;
                }
                #endregion
            }
            else if (geometry is IPolyline)
            {
                IPolyline pLine = (IPolyline)geometry;
                for (int iPath = 0; iPath < pLine.PathCount; iPath++)
                {
                    IPath path = pLine[iPath];
                    if (path.PointCount == 0)
                    {
                        continue;
                    }

                    #region Simple Method
                    IPoint p1 = path[0], p2;
                    for (int iPoint = 1; iPoint < path.PointCount; iPoint++)
                    {
                        p2 = path[iPoint];
                        double angle = -Math.Atan2(p2.Y - p1.Y, p2.X - p1.X) * 180.0 / Math.PI;
                        if (display.DisplayTransformation.UseTransformation)
                        {
                            angle -= display.DisplayTransformation.DisplayRotation;
                        }

                        if (angle < 0)
                        {
                            angle += 360;
                        }

                        if (angle > 90 && angle < 270)
                        {
                            angle -= 180;
                        }

                        var    format = StringFormatFromAlignment(_align);
                        double x, y;
                        if (format.Alignment == StringAlignment.Center)
                        {
                            x = p1.X * 0.5 + p2.X * 0.5;
                            y = p1.Y * 0.5 + p2.Y * 0.5;
                        }
                        else if (format.Alignment == StringAlignment.Far)
                        {
                            x = p2.X;
                            y = p2.Y;
                        }
                        else
                        {
                            x = p1.X;
                            y = p1.Y;
                        }
                        display.World2Image(ref x, ref y);

                        var annotationPolygon = AnnotationPolygon(display, (float)x, (float)y, symbolAlignment);
                        annotationPolygon.Rotate((float)x, (float)y, Angle);

                        polygons.Add(annotationPolygon);
                        p1 = p2;
                    }
                    #endregion
                }
            }

            return(polygons.Count > 0 ? polygons : null);
        }