public static dynamic GetTSObject(GridLabel dynObject)
 {
     if (dynObject is null)
     {
         return(null);
     }
     return(dynObject.teklaObject);
 }
Beispiel #2
0
        /// <summary>
        ///  Creates a grid of rows, columns and labels
        /// </summary>
        /// <param name="Width">Width of the grid</param>
        /// <param name="Height">Height of the grid</param>
        static Label[,] DefineGrid(Grid grid, int Width, int Height)
        {
            // clear old data
            grid.Children.Clear();
            grid.RowDefinitions.Clear();
            grid.ColumnDefinitions.Clear();

            // Create Columns
            for (int i = 0; i < Width; i++)
            {
                ColumnDefinition gridCol = new ColumnDefinition();
                gridCol.Width = new GridLength(1, GridUnitType.Star);
                grid.ColumnDefinitions.Add(gridCol);
            }

            // Create Rows
            for (int i = 0; i < Height; i++)
            {
                RowDefinition gridRow = new RowDefinition();
                gridRow.Height = new GridLength(1, GridUnitType.Star);
                grid.RowDefinitions.Add(gridRow);
            }

            // Create labels. Store the reference for later text population
            Label[,] labels = new Label[Width, Height];
            for (int w = 0; w < Width; w++)
            {
                for (int h = 0; h < Height; h++)
                {
                    // create a grid label
                    GridLabel label = new GridLabel(w, h);

                    // Add label to Grid
                    grid.Children.Add(label);

                    // store position for easy text population
                    labels[w, h] = label;
                }
            }

            return(labels);
        }
Beispiel #3
0
        /// <summary>
        ///  Creates a grid of rows, columns and labels
        /// </summary>
        /// <param name="Width">Width of the grid</param>
        /// <param name="Height">Height of the grid</param>
        static Label[,] DefineGrid(Grid grid, int Width, int Height)
        {
            // clear old data
            grid.Children.Clear();
            grid.RowDefinitions.Clear();
            grid.ColumnDefinitions.Clear();

            // Create Columns
            for (int i = 0; i < Width; i++)
            {
                ColumnDefinition gridCol = new ColumnDefinition();
                gridCol.Width = new GridLength(1, GridUnitType.Star);
                grid.ColumnDefinitions.Add(gridCol);
            }

            // Create Rows
            for (int i = 0; i < Height; i++)
            {
                RowDefinition gridRow = new RowDefinition();
                gridRow.Height = new GridLength(1, GridUnitType.Star);
                grid.RowDefinitions.Add(gridRow);
            }

            // Create labels. Store the reference for later text population
            Label[,] labels = new Label[Width, Height];
            for (int w = 0; w < Width; w++)
            {
                for (int h = 0; h < Height; h++)
                {
                    // create a grid label
                    GridLabel label = new GridLabel(w, h);

                    // Add label to Grid
                    grid.Children.Add(label);

                    // store position for easy text population
                    labels[w, h] = label;
                }
            }

            return labels;
        }
        /// <summary>
        /// Override PaintOnLayout method
        /// </summary>
        /// <param name="g">graphics</param>
        /// <param name="pageLocation">page location</param>
        /// <param name="zoom">zoom</param>
        public override void PaintOnLayout(Graphics g, PointF pageLocation, float zoom)
        {
            if (_mapFrame != null)
            {
                PointF    aP   = PageToScreen(this.Left, this.Top, pageLocation, zoom);
                Rectangle rect = new Rectangle((int)aP.X, (int)aP.Y, (int)(Width * zoom), (int)(Height * zoom));
                g.FillRectangle(new SolidBrush(_mapFrame.MapView.BackColor), rect);

                _mapFrame.MapView.PaintGraphics(g, rect);

                //Draw lon/lat grid labels
                if (_mapFrame.DrawGridLabel || _mapFrame.DrawGridTickLine)
                {
                    List <Extent> extentList = new List <Extent>();
                    Extent        maxExtent  = new Extent();
                    Extent        aExtent    = new Extent();
                    SizeF         aSF        = new SizeF();
                    SolidBrush    aBrush     = new SolidBrush(this.ForeColor);
                    Pen           aPen       = new Pen(_mapFrame.GridLineColor);
                    aPen.Width = _mapFrame.GridLineSize;
                    string drawStr;
                    PointF sP = new PointF(0, 0);
                    PointF eP = new PointF(0, 0);
                    Font   font = new Font(_mapFrame.GridFont.Name, _mapFrame.GridFont.Size * zoom, _mapFrame.GridFont.Style);
                    float  labX, labY;
                    int    len   = _mapFrame.TickLineLength;
                    int    space = len + _mapFrame.GridLabelShift;
                    if (_mapFrame.InsideTickLine)
                    {
                        space = _mapFrame.GridLabelShift;
                    }

                    for (int i = 0; i < _mapFrame.MapView.GridLabels.Count; i++)
                    {
                        GridLabel aGL = _mapFrame.MapView.GridLabels[i];
                        switch (_mapFrame.GridLabelPosition)
                        {
                        case GridLabelPosition.LeftBottom:
                            switch (aGL.LabDirection)
                            {
                            case Direction.East:
                            case Direction.North:
                                continue;
                            }
                            break;

                        case GridLabelPosition.LeftUp:
                            switch (aGL.LabDirection)
                            {
                            case Direction.East:
                            case Direction.South:
                                continue;
                            }
                            break;

                        case GridLabelPosition.RightBottom:
                            switch (aGL.LabDirection)
                            {
                            case Direction.Weast:
                            case Direction.North:
                                continue;
                            }
                            break;

                        case GridLabelPosition.RightUp:
                            switch (aGL.LabDirection)
                            {
                            case Direction.Weast:
                            case Direction.South:
                                continue;
                            }
                            break;
                        }

                        labX = (float)aGL.LabPoint.X;
                        labY = (float)aGL.LabPoint.Y;
                        labX = labX + this.Left * zoom + pageLocation.X;
                        labY = labY + this.Top * zoom + pageLocation.Y;
                        sP.X = labX;
                        sP.Y = labY;

                        drawStr = aGL.LabString;
                        if (_mapFrame.DrawDegreeSymbol)
                        {
                            if (drawStr.EndsWith("E") || drawStr.EndsWith("W") || drawStr.EndsWith("N") || drawStr.EndsWith("S"))
                            {
                                drawStr = drawStr.Substring(0, drawStr.Length - 1) + ((char)186).ToString() + drawStr.Substring(drawStr.Length - 1);
                            }
                            else
                            {
                                drawStr = drawStr + ((char)186).ToString();
                            }
                        }
                        aSF = g.MeasureString(drawStr, font);
                        switch (aGL.LabDirection)
                        {
                        case Direction.South:
                            labX = labX - aSF.Width / 2;
                            labY = labY + space;
                            eP.X = sP.X;
                            if (_mapFrame.InsideTickLine)
                            {
                                eP.Y = sP.Y - len;
                            }
                            else
                            {
                                eP.Y = sP.Y + len;
                            }
                            break;

                        case Direction.Weast:
                            labX = labX - aSF.Width - space;
                            labY = labY - aSF.Height / 2;
                            eP.Y = sP.Y;
                            if (_mapFrame.InsideTickLine)
                            {
                                eP.X = sP.X + len;
                            }
                            else
                            {
                                eP.X = sP.X - len;
                            }
                            break;

                        case Direction.North:
                            labX = labX - aSF.Width / 2;
                            labY = labY - aSF.Height - space;
                            eP.X = sP.X;
                            if (_mapFrame.InsideTickLine)
                            {
                                eP.Y = sP.Y + len;
                            }
                            else
                            {
                                eP.Y = sP.Y - len;
                            }
                            break;

                        case Direction.East:
                            labX = labX + space;
                            labY = labY - aSF.Height / 2;
                            eP.Y = sP.Y;
                            if (_mapFrame.InsideTickLine)
                            {
                                eP.X = sP.X - len;
                            }
                            else
                            {
                                eP.X = sP.X + len;
                            }
                            break;
                        }

                        bool  ifDraw = true;
                        float aSize  = aSF.Width / 2;
                        float bSize  = aSF.Height / 2;
                        aExtent.minX = labX;
                        aExtent.maxX = labX + aSF.Width;
                        aExtent.minY = labY - aSF.Height;
                        aExtent.maxY = labY;

                        //Judge extent
                        if (extentList.Count == 0)
                        {
                            maxExtent = aExtent;
                            extentList.Add(aExtent);
                        }
                        else
                        {
                            if (!MIMath.IsExtentCross(aExtent, maxExtent))
                            {
                                extentList.Add(aExtent);
                                maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent);
                            }
                            else
                            {
                                for (int j = 0; j < extentList.Count; j++)
                                {
                                    if (MIMath.IsExtentCross(aExtent, extentList[j]))
                                    {
                                        ifDraw = false;
                                        break;
                                    }
                                }
                                if (ifDraw)
                                {
                                    extentList.Add(aExtent);
                                    maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent);
                                }
                            }
                        }

                        if (ifDraw)
                        {
                            if (_mapFrame.DrawGridTickLine)
                            {
                                g.DrawLine(aPen, sP, eP);
                            }
                            if (_mapFrame.DrawGridLabel)
                            {
                                g.DrawString(drawStr, font, aBrush, labX, labY);
                            }
                        }
                    }

                    aPen.Dispose();
                    aBrush.Dispose();
                }

                //Draw neat line
                if (_mapFrame.DrawNeatLine)
                {
                    Pen aPen = new Pen(_mapFrame.NeatLineColor, _mapFrame.NeatLineSize);
                    g.DrawRectangle(aPen, rect);
                    aPen.Dispose();
                }
            }
        }
        /// <summary>
        /// Override paint method
        /// </summary>
        /// <param name="g">graphics</param>
        public override void Paint(Graphics g)
        {
            if (_mapFrame != null)
            {
                g.FillRectangle(new SolidBrush(_mapFrame.MapView.BackColor), _mapFrame.LayoutBounds);

                //Region oldRegion = g.Clip;
                //GraphicsPath path = new GraphicsPath();
                //Rectangle rect = this.Bounds;
                //path.AddRectangle(rect);
                //g.SetClip(path);
                //Matrix oldMatrix = g.Transform;
                //g.TranslateTransform(this.Left, this.Top);

                _mapFrame.MapView.PaintGraphics(g, _mapFrame.LayoutBounds);

                //Draw lon/lat grid labels
                if (_mapFrame.DrawGridLabel)
                {
                    List <Extent> extentList = new List <Extent>();
                    Extent        maxExtent  = new Extent();
                    Extent        aExtent    = new Extent();
                    SizeF         aSF        = new SizeF();
                    SolidBrush    aBrush     = new SolidBrush(this.ForeColor);
                    Pen           aPen       = new Pen(_mapFrame.GridLineColor);
                    aPen.Width = _mapFrame.GridLineSize;
                    string drawStr;
                    PointF sP = new PointF(0, 0);
                    PointF eP = new PointF(0, 0);
                    Font   font = new Font(_mapFrame.GridFont.Name, _mapFrame.GridFont.Size, _mapFrame.GridFont.Style);
                    float  labX, labY;
                    int    len   = 5;
                    int    space = len + 2;
                    for (int i = 0; i < _mapFrame.MapView.GridLabels.Count; i++)
                    {
                        GridLabel aGL = _mapFrame.MapView.GridLabels[i];
                        switch (_mapFrame.GridLabelPosition)
                        {
                        case GridLabelPosition.LeftBottom:
                            switch (aGL.LabDirection)
                            {
                            case Direction.East:
                            case Direction.North:
                                continue;
                            }
                            break;

                        case GridLabelPosition.LeftUp:
                            switch (aGL.LabDirection)
                            {
                            case Direction.East:
                            case Direction.South:
                                continue;
                            }
                            break;

                        case GridLabelPosition.RightBottom:
                            switch (aGL.LabDirection)
                            {
                            case Direction.Weast:
                            case Direction.North:
                                continue;
                            }
                            break;

                        case GridLabelPosition.RightUp:
                            switch (aGL.LabDirection)
                            {
                            case Direction.Weast:
                            case Direction.South:
                                continue;
                            }
                            break;
                        }

                        labX = (float)aGL.LabPoint.X;
                        labY = (float)aGL.LabPoint.Y;
                        labX = labX + this.Left;
                        labY = labY + this.Top;
                        sP.X = labX;
                        sP.Y = labY;

                        drawStr = aGL.LabString;
                        aSF     = g.MeasureString(drawStr, font);
                        switch (aGL.LabDirection)
                        {
                        case Direction.South:
                            labX = labX - aSF.Width / 2;
                            labY = labY + space;
                            eP.X = sP.X;
                            eP.Y = sP.Y + len;
                            break;

                        case Direction.Weast:
                            labX = labX - aSF.Width - space;
                            labY = labY - aSF.Height / 2;
                            eP.X = sP.X - len;
                            eP.Y = sP.Y;
                            break;

                        case Direction.North:
                            labX = labX - aSF.Width / 2;
                            labY = labY - aSF.Height - space;
                            eP.X = sP.X;
                            eP.Y = sP.Y - len;
                            break;

                        case Direction.East:
                            labX = labX + space;
                            labY = labY - aSF.Height / 2;
                            eP.X = sP.X + len;
                            eP.Y = sP.Y;
                            break;
                        }

                        bool  ifDraw = true;
                        float aSize  = aSF.Width / 2;
                        float bSize  = aSF.Height / 2;
                        aExtent.minX = labX;
                        aExtent.maxX = labX + aSF.Width;
                        aExtent.minY = labY - aSF.Height;
                        aExtent.maxY = labY;

                        //Judge extent
                        if (extentList.Count == 0)
                        {
                            maxExtent = aExtent;
                            extentList.Add(aExtent);
                        }
                        else
                        {
                            if (!MIMath.IsExtentCross(aExtent, maxExtent))
                            {
                                extentList.Add(aExtent);
                                maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent);
                            }
                            else
                            {
                                for (int j = 0; j < extentList.Count; j++)
                                {
                                    if (MIMath.IsExtentCross(aExtent, extentList[j]))
                                    {
                                        ifDraw = false;
                                        break;
                                    }
                                }
                                if (ifDraw)
                                {
                                    extentList.Add(aExtent);
                                    maxExtent = MIMath.GetLagerExtent(maxExtent, aExtent);
                                }
                            }
                        }

                        if (ifDraw)
                        {
                            g.DrawLine(aPen, sP, eP);
                            g.DrawString(drawStr, font, aBrush, labX, labY);
                        }
                    }

                    aPen.Dispose();
                    aBrush.Dispose();
                }

                //g.Transform = oldMatrix;
                //g.Clip = oldRegion;

                if (_mapFrame.DrawNeatLine)
                {
                    Pen aPen = new Pen(_mapFrame.NeatLineColor, _mapFrame.NeatLineSize);
                    g.DrawRectangle(aPen, _mapFrame.LayoutBounds);
                    aPen.Dispose();
                }
            }
        }