Пример #1
0
        /// <summary>
        /// Timer callback for GPS screen update
        /// </summary>
        /// <param name="state"></param>
        private void updateSceen(object state)
        {
            // have we moved?
            if (config.UseGPS &&
                (Math.Abs(oldGk.h_value - gk.h_value) > 0.01) &&
                (Math.Abs(oldGk.r_value - gk.r_value) > 0.01))
            {             // yes
                // copy the position we want to draw
                gkToRender = gk;

                OnPositionChanged();

                // call the UpdateData method via the updateDataHandler so that we
                // update the UI on the UI thread
                if (mainControler.MainForm.InvokeRequired)
                {
                    //IAsyncResult result =
                    this.mainControler.MainForm.BeginInvoke(updateDataHandler);
                    //result.AsyncWaitHandle.WaitOne();
                    //this.mainControler.MainForm.EndInvoke(result);
                }
                else
                {
                    SetInvalidateRegions();
                }
            }
            // if we have not moved, we ignore it
        }
Пример #2
0
        private void SetInvalidateRegions()
        {
            if (mainControler.GpsControler.Opened && mainControler.HasActiveDisplay)
            {
                if (config.GpsViewMode == GpsView.StaticMap)
                {
                    recList.Clear();

                    p = CoordCalculator.calculateDisplayCoords(oldGk, mainControler.MapPanel.DX,
                                                               mainControler.MapPanel.DY, mainControler.LayerManager.Scale);

                    // Clipping: We do not need to invalide if the point is out of our view
                    if (isInDrawingArea(p, mainControler.MapPanel.DrawingArea))
                    {
                        tempRec.X      = Convert.ToInt32(Math.Min(p.x - 2, Int32.MaxValue));
                        tempRec.Y      = Convert.ToInt32(Math.Min(p.y - 2, Int32.MaxValue));
                        tempRec.Width  = config.GpsLayerPointWidth + 4;
                        tempRec.Height = config.GpsLayerPointWidth + 4;
                        recList.Add(tempRec);
                    }
                    p = CoordCalculator.calculateDisplayCoords(gkToRender, mainControler.MapPanel.DX,
                                                               mainControler.MapPanel.DY, mainControler.LayerManager.Scale);

                    // Clipping: We do not need to invalide if the point is out of our view
                    if (isInDrawingArea(p, mainControler.MapPanel.DrawingArea))
                    {
                        tempRec.X = System.Convert.ToInt32(Math.Min(p.x - 2, Int32.MaxValue));
                        tempRec.Y = System.Convert.ToInt32(Math.Min(p.y - 2, Int32.MaxValue));
                        recList.Add(tempRec);
                        oldGk = gkToRender;
                    }
                    this.mainControler.MapPanel.InvalidateRegion(recList);
                }
                else //config.GpsViewMode == GpsView.staticPoint
                {
                    double scale = mainControler.LayerManager.Scale;
                    mainControler.MapPanel.DX =
                        mainControler.MapPanel.DrawingArea.Width / -2 + gkToRender.r_value * scale;
                    mainControler.MapPanel.DY =
                        this.mainControler.MapPanel.DrawingArea.Height / 2 + gkToRender.h_value * scale;
                    this.mainControler.MapPanel.RequesLayerChange();
                    this.mainControler.MapPanel.Invalidate();
                }
            }
        }
Пример #3
0
        private void radios_CheckedChanged(object sender, EventArgs e)
        {
            label1.Enabled = label2.Enabled = tbHW.Enabled = tBRW.Enabled = radioManual.Checked;

            if (radioGPS.Checked)
            {
                try
                {
                    GKCoord pos = mainControler.LayerManager.CurrentGPSPositon;
                    tBRW.Text = pos.r_value.ToString();
                    tbHW.Text = pos.h_value.ToString();
                }
                catch
                {
                    MessageBox.Show("Leider werden im Moment keine aktuellen Positionsdaten empfangen.");
                    radioManual.Checked = true;
                }
            }
            else
            {
                UpdateMapPos();
            }
        }
Пример #4
0
        public GPSLayer(MainControler mainControler)
        {
            this._layerType = LayerType.GPSPosition;

            // GPS init
            this.mainControler = mainControler;
            this.config = mainControler.Config;
            this.gpsTimer = new System.Threading.Timer(updateSceen, null, 0, config.GPSUpdateInterval);

            updateDataHandler = new EventHandler(UpdateData);
            updateStatusHandler = new EventHandler(UpdateStatus);
            mainControler.GpsControler.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged);
            mainControler.GpsControler.LocationChanged += new LocationChangedEventHandler(gps_LocationChanged);
            mainControler.SettingsLoaded += new MainControler.SettingsLoadedDelegate(mainControler_SettingsLoaded);

            this.mainControler.createNewCanvas(0, 0, 1.0);

            // make sure there are initialized values in
            gk.h_value = 0.0;
            gk.r_value = 0.0;

            oldGk = gk;
        }
Пример #5
0
        public GPSLayer(MainControler mainControler)
        {
            this._layerType = LayerType.GPSPosition;


            // GPS init
            this.mainControler = mainControler;
            this.config        = mainControler.Config;
            this.gpsTimer      = new System.Threading.Timer(updateSceen, null, 0, config.GPSUpdateInterval);

            updateDataHandler   = new EventHandler(UpdateData);
            updateStatusHandler = new EventHandler(UpdateStatus);
            mainControler.GpsControler.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged);
            mainControler.GpsControler.LocationChanged    += new LocationChangedEventHandler(gps_LocationChanged);
            mainControler.SettingsLoaded += new MainControler.SettingsLoadedDelegate(mainControler_SettingsLoaded);

            this.mainControler.createNewCanvas(0, 0, 1.0);

            // make sure there are initialized values in
            gk.h_value = 0.0;
            gk.r_value = 0.0;

            oldGk = gk;
        }
Пример #6
0
        protected void gps_LocationChanged(object sender, LocationChangedEventArgs args)
        {
            try
            {
                position = args.Position;
                if (position != null)
                {
                    if (position.LatitudeValid && position.LongitudeValid)
                    {
                        this.gk = mainControler.CoordCalculator.GeoGkGDAL(position, config.CoordGaußKruegerStripe);

                        if (_updateAsDataComes)
                        {
                            OnPositionChanged();
                            updateSceen(null);
                        }
                    }
                }
            }
            catch
            {
                // if something is going wrong here, we have a serious problem
            }
        }
Пример #7
0
 void GPSLayer_PositionChanged(GKCoord position)
 {
     currentPositon = position;
 }
Пример #8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            _stopwatch.Reset();
            _stopwatch.Start();

            SizeF textSize;
            String text = String.Empty;

            System.Drawing.Graphics gx
                = vectorRenderer.Graphics
                = e.Graphics; // Graphics.FromImage(backBuffer); //e.Graphics;

            gx.Clear(Color.White);

            this.dpiX = gx.DpiX;
            this.dpiY = gx.DpiY;

            double scale = mainControler.LayerManager.Scale;
            int layerCount = mainControler.LayerManager.LayerCount;
            LayerManager lm = mainControler.LayerManager;

            // TransportLayer
            // TODO: [9] Ist TransportShapes malen mit QuadTree schneller oder wenn man alles malt? (ab wann ist das wichtig?)
            lm.generateCurrentVisibleIShapes(d, drawingArea.Width, drawingArea.Height, absoluteZoom);

            // now draw the image previously created in the given order
            // ! We assume that there are no gaps (e.g. "1, 2, 4") in the mapping-list
            Layer layer;
            RenderProperties rp = new RenderProperties(gx, e.ClipRectangle, d.x, d.y,
                            absoluteZoom, screenChanged, this.drawingArea, scale, mHighlight);

            for (int i = layerCount - 1; i >= 0; i--)
            {
                layer = lm.getLayerFromMapping(i);
                if (layer.Visible)
                {
                    if (!(layer.Render(rp)))
                    {
                        this.Invalidate();
                        return;
                    }

                }
            }

            //IntPtr hBackBuffert = MapPanelBindings.GetRotatedBitmapNT(backBuffer.HBitmap, 0.0f, MakeCOLORREF(255, 255, 255));

            //Image newBackImage = Image.FromHbitmap(hBackBuffert);
            //gx = Graphics.FromImage(newBackImage);

            //rotateImage(backBuffer, 0);

            if (screenChanged)
            {
                mZoom = false;
                screenChanged = false;
            }

            StringFormat format = new StringFormat(StringFormatFlags.NoWrap);
            StylePen blackPen = new StylePen(StyleColor.Black, 1.0f);
            SolidStyleBrush blackBrush = new SolidStyleBrush(StyleColor.Black);

            #region Transportlayer

            lm.TransportPolygonLayer.Render(rp);
            lm.TransportPolylineLayer.Render(rp);
            lm.TransportPointLayer.Render(rp);

            #endregion

            #region GPS-Layer

            if (config.UseGPS)
                lm.GPSLayer.Render(rp);

            #endregion

            #region Längenanzeige
            if (config.ShowDistanceLine)
            {
                StylePen borderPen = new StylePen(StyleColor.White, 1.0f);

                // get the scaling factor for other dimensions
                int multiplikator = (int)(dpiX / 96.0);

                // get the amount of pixels representing one centimeter
                int width = Convert.ToInt32(dpiX / 2.54); ;

                blackPen.Width *= multiplikator;

                int left = drawingArea.X + 7*multiplikator;
                int right = left + width;
                int top = drawingArea.Bottom - 15 * multiplikator;
                int bottom = top + 7 * multiplikator;

                double dM = width / mainControler.LayerManager.Scale;

                if (dM > 1000) // display as kilometers
                    text = String.Format("{0}km", (dM / 1000).ToString("#0.0"));
                else if (dM > 1) // display as meters
                    text = String.Format("{0}m", Convert.ToInt32(dM).ToString());
                else // display as centimeters
                    text = String.Format("{0}cm", Convert.ToInt32(dM * 10).ToString());

                textSize = gx.MeasureString(text, font);

                int x = left + (int)((right - left - textSize.Width) / 2F);
                int y = top - 4 * multiplikator;

                // a white background for the text
                vectorRenderer.FillRectangle(new SolidStyleBrush(StyleColor.White),
                    new Rectangle(x - 1, y - 1, (int)textSize.Width + 2, (int)textSize.Height + 2));

                vectorRenderer.DrawLine(blackPen, left, top, left, bottom);
                vectorRenderer.DrawLine(blackPen, left, bottom, right, bottom);
                vectorRenderer.DrawLine(blackPen, right, bottom, right, top);

                // the white outline
                vectorRenderer.DrawLine(borderPen, left - 1, top, left - 1, bottom);
                vectorRenderer.DrawLine(borderPen, left + 1, top, left + 1, bottom - 1);
                vectorRenderer.DrawLine(borderPen, left - 1, top - 1, left + 1, top - 1);

                vectorRenderer.DrawLine(borderPen, left - 1, bottom + 1, right + 1, bottom + 1);
                vectorRenderer.DrawLine(borderPen, left + 1, bottom - 1, right - 1, bottom - 1);

                vectorRenderer.DrawLine(borderPen, right - 1, top, right - 1, bottom - 1);
                vectorRenderer.DrawLine(borderPen, right + 1, top, right + 1, bottom);
                vectorRenderer.DrawLine(borderPen, right - 1, top - 1, right + 1, top - 1);

                // the text
                vectorRenderer.DrawString(text,
                    font,
                    blackBrush, x, y, format);
            }
            #endregion

            #region Nordpfeil

            if (config.ShowNorthArrow)
            {
                // linke Seite (weiß)
                vectorRenderer.FillPolygon(new SolidStyleBrush(StyleColor.White), new Point[] {
                new Point(drawingArea.Right - 20, drawingArea.Bottom -27),
                new Point(drawingArea.Right - 25, drawingArea.Bottom -5),
                new Point(drawingArea.Right - 20, drawingArea.Bottom -8)});

                vectorRenderer.DrawLines(new StylePen(StyleColor.Black, 1.0f), new Point[] {
                new Point(drawingArea.Right - 20, drawingArea.Bottom -27),
                new Point(drawingArea.Right - 25, drawingArea.Bottom -5),
                new Point(drawingArea.Right - 20, drawingArea.Bottom -8)});

                // rechte Seite (schwarz)
                vectorRenderer.FillPolygon(new SolidStyleBrush(StyleColor.Black), new Point[] {
                new Point(drawingArea.Right - 20, drawingArea.Bottom -27),
                new Point(drawingArea.Right - 20, drawingArea.Bottom -8),
                new Point(drawingArea.Right - 14, drawingArea.Bottom -4),
                new Point(drawingArea.Right - 20, drawingArea.Bottom -27)});
            }

            #endregion

            #region Draw backbuffer (Backbuffer is currently disabled!)
                //e.Graphics.DrawImage(backBuffer, 0, 0);
            #endregion

            #region Zoom rectangle
            if (mZoom)
                e.Graphics.DrawRectangle(new Pen(Color.Red, 1.0f), zoomRec);
            #endregion

            #region SelectedItem / Tracking Info

            text = String.Empty;
            if (displayTrackingStatus)
            {
                text = _trackingStatus;
            } else if (selectedTransportShape != null)
            {
                text = String.Empty;

                if (selectedTransportShape as ShpPolyline != null)
                {
                    text = String.Format("Länge: {0}m", ((ShpPolyline)selectedTransportShape).Length.ToString("#0.00"));
                }
                else if (selectedTransportShape as ShpPolygon != null)
                {
                    ShpPolygon pg = (ShpPolygon)selectedTransportShape;

                    text = String.Format("Umfang: {0}m Fläche: {1} m²", pg.Perimeter.ToString("#0.00"), pg.Area.ToString("#0.00"));
                }
            }

            if (!String.IsNullOrEmpty(text))
            {
                textSize = gx.MeasureString(text, font);

                m_TextHeight = (int)(textSize.Height + 4);

                vectorRenderer.FillRectangle(new SolidStyleBrush(StyleColor.White), drawingArea.X, drawingArea.Y,
                    drawingArea.Width, m_TextHeight);

                vectorRenderer.DrawLine(new StylePen(StyleColor.Blue, 1.0f), drawingArea.X, drawingArea.Y + m_TextHeight,
                    drawingArea.Width, drawingArea.Y + m_TextHeight);

                vectorRenderer.DrawString(text, font, blackBrush, drawingArea.X + 1, drawingArea.Y + 2, format);
            }

            #endregion

            #region Meta-Define Drawings
            #if DRAW_INVALIDATEREC
            foreach (Rectangle r in this.rectangleList)
            {   GKCoord gk = new GKCoord();
                gk.r_value = r.X;
                gk.h_value = r.Y;
                PointD p = CoordCalculator.calculateDisplayCoords(gk, this.DX, this.DY, mainControler.LayerManager.Scale);
                gx.DrawRectangle(new Pen(Color.Pink), new Rectangle((int)(p.x),(int)(p.y),r.Width,r.Height));
            }
            #endif

            #if DRAW_GRID
                // Grid drawing
                for (int i = (int)(mainControler.LayerManager.ShapeArray[0].Width * mainControler.LayerManager.Scale); i >= 0;
                    i -= mainControler.LayerManager.ShapeArray[0].PartGrid.Cell_width)
                {

                    gx.DrawLine(new Pen(Color.Red), (int)d[0] + i, (int)d[1] + margin, (int)d[0] + i,
                         (int)(d[1] + mainControler.LayerManager.ShapeArray[0].Height * mainControler.LayerManager.Scale) - margin);
                }
                for (int i = (int)(mainControler.LayerManager.ShapeArray[0].Height * mainControler.LayerManager.Scale); i >= 0;
                    i -= mainControler.LayerManager.ShapeArray[0].PartGrid.Cell_height)
                {

                    gx.DrawLine(new Pen(Color.Red), (int)d[0] + margin, (int)d[1]  + i,
                        (int)(d[0] + mainControler.LayerManager.ShapeArray[0].Width * mainControler.LayerManager.Scale) - margin,
                        (int)d[1] + i);
                }
            #endif

            #if DRAW_QUADTREE
            mainControler.LayerManager.draw_QuadTree(gx, d);
            #endif

            #if DRAW_BOUNDINGBOXES
                            // Draw Boundingboxes
                           List<Rectangle> transportRectangleList = new List<Rectangle>();
                            // :: Points
                            mainControler.LayerManager.generateBBList(ref transportRectangleList, absoluteZoom);

                            if (transportRectangleList.Count != 0)
                            {
                                Pen temporaryPen = new Pen(Color.Green);
                                for (int i = transportRectangleList.Count - 1; i >= 0; i--)
                                    gx.DrawRectangle(temporaryPen, transportRectangleList[i]);
                            }
            #endif

            #endregion

            //Bounding Box of selected IShape
            //if (selectedTransportShape != null)
            //    vectorRenderer.DrawRectangle(new Pen(Color.Green), selectedTransportShape.getDisplayBoundingBox(
            //        d.x, d.y, config.ExPntLayerPointWidth, scale, 1));

            //Boundary rectangle
            Rectangle rc = this.ClientRectangle;
            rc.Width--;
            rc.Height--;
            //Draw boundary
            e.Graphics.DrawRectangle(new Pen(Color.Blue), rc);
            gx.Dispose();

            _stopwatch.Stop();

            // if the render time is higher than the gps update interval
            // we have to set the update interval higher
            if (_stopwatch.ElapsedMilliseconds >= config.GPSUpdateInterval) {
                // base update interval is render time * 1.2
                double newInterval = _stopwatch.ElapsedMilliseconds * 1.2;
                // since we want full 1000th as interval we round up to the next 1000
                try {
                    config.GPSUpdateInterval = Convert.ToUInt32( newInterval + ( 1000 - newInterval % 1000 ) );
                } catch { config.GPSUpdateInterval = 5000; }
                finally { mainControler.OnSettingsChanged(); }
            }
        }
Пример #9
0
        /// <summary>
        /// Timer callback for GPS screen update
        /// </summary>
        /// <param name="state"></param>
        private void updateSceen(object state)
        {
            // have we moved?
            if ( config.UseGPS
                && (Math.Abs(oldGk.h_value - gk.h_value) > 0.01)
                && (Math.Abs(oldGk.r_value - gk.r_value) > 0.01) )
            { // yes

                // copy the position we want to draw
                gkToRender = gk;

                OnPositionChanged();

                // call the UpdateData method via the updateDataHandler so that we
                // update the UI on the UI thread
                if (mainControler.MainForm.InvokeRequired)
                {
                    //IAsyncResult result =
                    this.mainControler.MainForm.BeginInvoke(updateDataHandler);
                    //result.AsyncWaitHandle.WaitOne();
                    //this.mainControler.MainForm.EndInvoke(result);
                }
                else SetInvalidateRegions();
            }
            // if we have not moved, we ignore it
        }
Пример #10
0
        private void SetInvalidateRegions()
        {
            if (mainControler.GpsControler.Opened && mainControler.HasActiveDisplay)
            {
                if (config.GpsViewMode == GpsView.StaticMap)
                {
                    recList.Clear();

                    p = CoordCalculator.calculateDisplayCoords(oldGk, mainControler.MapPanel.DX,
                        mainControler.MapPanel.DY, mainControler.LayerManager.Scale);

                    // Clipping: We do not need to invalide if the point is out of our view
                    if (isInDrawingArea(p, mainControler.MapPanel.DrawingArea))
                    {
                        tempRec.X = Convert.ToInt32(Math.Min(p.x - 2, Int32.MaxValue));
                        tempRec.Y = Convert.ToInt32(Math.Min(p.y - 2, Int32.MaxValue));
                        tempRec.Width = config.GpsLayerPointWidth + 4;
                        tempRec.Height = config.GpsLayerPointWidth + 4;
                        recList.Add(tempRec);
                    }
                    p = CoordCalculator.calculateDisplayCoords(gkToRender, mainControler.MapPanel.DX,
                        mainControler.MapPanel.DY, mainControler.LayerManager.Scale);

                    // Clipping: We do not need to invalide if the point is out of our view
                    if (isInDrawingArea(p, mainControler.MapPanel.DrawingArea))
                    {
                        tempRec.X = System.Convert.ToInt32(Math.Min(p.x - 2, Int32.MaxValue));
                        tempRec.Y = System.Convert.ToInt32(Math.Min(p.y - 2, Int32.MaxValue));
                        recList.Add(tempRec);
                        oldGk = gkToRender;
                    }
                    this.mainControler.MapPanel.InvalidateRegion(recList);
                }
                else //config.GpsViewMode == GpsView.staticPoint
                {
                    double scale = mainControler.LayerManager.Scale;
                    mainControler.MapPanel.DX =
                        mainControler.MapPanel.DrawingArea.Width / -2 + gkToRender.r_value * scale;
                    mainControler.MapPanel.DY =
                        this.mainControler.MapPanel.DrawingArea.Height / 2 + gkToRender.h_value * scale;
                    this.mainControler.MapPanel.RequesLayerChange();
                    this.mainControler.MapPanel.Invalidate();
                }
            }
        }
Пример #11
0
        protected void gps_LocationChanged(object sender, LocationChangedEventArgs args)
        {
            try
            {
                position = args.Position;
                if (position != null)
                {
                    if (position.LatitudeValid && position.LongitudeValid)
                    {
                        this.gk = mainControler.CoordCalculator.GeoGkGDAL(position, config.CoordGaußKruegerStripe);

                        if (_updateAsDataComes) {
                            OnPositionChanged();
                            updateSceen(null);
                        }
                    }
                }
            }
            catch
            {
               // if something is going wrong here, we have a serious problem
            }
        }