예제 #1
0
        /// <summary>
        /// Perform calculations and update data.
        /// </summary>
        /// <param name="updateTime">Time since last update.</param>
        /// <remarks>include base.Update(renderTime); in overloads to preserve updating UpdateTime field.</remarks>
        public override void Update(RenderTime updateTime)
        {
            // if we don't have a data provider, don't update

            if (MM_Repository.OverallDisplay.Contour == MM_Display.MM_Contour_Enum.None)
            {
                return;
            }

            if (!MM_Repository.ContourDataProviders.TryGetValue(MM_Repository.OverallDisplay.ContourData, out DataProvider))
            {
                return;
            }

            base.Update(updateTime);

            bool contourChanged = _lastProvider != MM_Repository.OverallDisplay.ContourData;

            if (Surface.Coordinates.ZoomLevel != _zoomLevel || _kdProxy == null || contourChanged || (updateTime.TotalTime - _lastUpdate).TotalSeconds > MM_Repository.OverallDisplay.ContourRefreshTime)
            {
                _lastUpdate   = updateTime.TotalTime;
                _lastProvider = MM_Repository.OverallDisplay.ContourData;
                _kdProxy      = new KDTree.KDTree <ContourData>(2);
                _zoomLevel    = Surface.Coordinates.ZoomLevel;

                foreach (var item in DataProvider.GetData())
                {
                    var coord = MM_Coordinates.LngLatToScreenVector2(item.LngLat, _zoomLevel);
                    item.XY = coord;

                    _kdProxy.AddPoint(new double[] { coord.X, coord.Y }, item);
                }

                if (_bmp != null)
                {
                    _bmp.Dispose();
                }

                if (contourChanged)
                {
                    Surface.AddOnscreenMessage("Contour layer changed: " + _lastProvider.ToString(), SharpDX.Color.Aqua);
                }
            }
        }
예제 #2
0
        public static void CalculateCoords(LineProxy proxy, MM_Line line, int zoomLevel)
        {
            proxy.Coordinates.Clear();
            //Ignore invalid lines
            if (float.IsNaN(line.CenterLngLat.X))
            {
                return;
            }

            // flip the line coords
            if (line.Coordinates.Count > 0 && (line.Substation2.LngLat == line.Coordinates[0] || line.Substation1.LngLat == line.Coordinates[line.Coordinates.Count - 1]))
            {
                line.Coordinates.Reverse();
            }

            if (line.Coordinates.Count == 0)
            {
                line.Coordinates.Add(line.Substation1.LngLat);
                line.Coordinates.Add(line.Substation2.LngLat);
            }
            //Determine if we need to flip coordinates because the substations have changed
            if (line.Coordinates.Count > 0 && (line.Substation2.LngLat == line.Coordinates[0] || line.Substation1.LngLat == line.Coordinates[line.Coordinates.Count - 1]))
            {
                line.Coordinates.Reverse();
            }

            Vector2 lastPoint = Vector2.Zero;
            Vector2 aggPoint  = Vector2.Zero;

            float minX = float.MaxValue;
            float minY = float.MaxValue;
            float maxY = float.MinValue;
            float maxX = float.MinValue;


            float length = 0;

            if (proxy.Segments == null)
            {
                proxy.Segments = new List <LineSegment>();
            }
            else
            {
                proxy.Segments.Clear();
            }
            if (line.Coordinates.Count > 0)
            {
                for (int i = 0; i < line.Coordinates.Count; i++)
                {
                    PointF  Pt           = line.Coordinates[i];
                    Vector2 currentPoint = MM_Coordinates.LngLatToScreenVector2(Pt, zoomLevel);
                    if (lastPoint.IsZero || lastPoint.X != currentPoint.X || lastPoint.Y != currentPoint.Y)
                    {
                        aggPoint.X += currentPoint.X;
                        aggPoint.Y += currentPoint.Y;
                    }
                    proxy.Coordinates.Add(currentPoint);


                    if (currentPoint.X < minX)
                    {
                        minX = currentPoint.X;
                    }
                    if (currentPoint.X > maxX)
                    {
                        maxX = currentPoint.X;
                    }

                    if (currentPoint.Y < minY)
                    {
                        minY = currentPoint.Y;
                    }
                    if (currentPoint.Y > maxY)
                    {
                        maxY = currentPoint.Y;
                    }

                    if (i > 0)
                    {
                        var segment = new LineSegment(lastPoint, currentPoint);
                        proxy.Segments.Add(segment);
                        length += segment.length;
                    }

                    lastPoint = currentPoint;
                }
            }
            proxy.Length = length;
            var bounds = new SharpDX.RectangleF(minX, minY, maxX - minX, maxY - minY);

            proxy.Bounds = bounds;

            lastPoint    = proxy.Coordinates[proxy.Coordinates.Count - 1];
            proxy.Center = new Vector2(aggPoint.X / (float)proxy.Coordinates.Count, aggPoint.Y / (float)proxy.Coordinates.Count);

            var lineAngle = (float)Math.Atan2(proxy.Coordinates[0].Y - lastPoint.Y, proxy.Coordinates[0].X - lastPoint.X);

            // if (lineAngle < 0)
            // {
            //     lineAngle += (float)(Math.PI * 2);
            // }
            if (lineAngle > (float)Math.PI / 2f)
            {
                lineAngle       = (float)lineAngle - (float)Math.PI;
                proxy.FlipSides = true;
            }
            else if (lineAngle < (float)Math.PI / -2f)
            {
                lineAngle       = (float)lineAngle - (float)Math.PI;
                proxy.FlipSides = true;
            }
            else
            {
                proxy.FlipSides = false;
            }

            //lineAngle *= 180f / (float)Math.PI;

            proxy.Angle = lineAngle;
        }
예제 #3
0
        /// <summary>
        /// Perform calculations and update data.
        /// </summary>
        /// <param name="updateTime">Time since last update.</param>
        /// <remarks>include base.Update(renderTime); in overloads to preserve updating UpdateTime field.</remarks>
        public override void Update(RenderTime updateTime)
        {
            base.Update(updateTime);
            if (!Surface.IsDirty && _lastZoom == Surface.Coordinates.ZoomLevel)
            {
                return;
            }

            _lastZoom = Surface.Coordinates.ZoomLevel;

            foreach (var substationKvp in MM_Repository.Substations)
            {
                var element = substationKvp.Value;

                SubstationProxy proxy;
                if (!_substationProxies.TryGetValue(element.TEID, out proxy))
                {
                    proxy = new SubstationProxy()
                    {
                        Substation  = element,
                        Coordinates = MM_Coordinates.LngLatToScreenVector2(element.LngLat, _lastZoom)
                    };
                    _substationProxies.Add(element.TEID, proxy);
                }
                proxy.Coordinates      = MM_Coordinates.LngLatToScreenVector2(element.LngLat, _lastZoom);
                proxy.BlackStartHidden = proxy.BlackStartDim = false;

                // calculate blackstart parameters
                if ((MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.HideNonOperatorElements || MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.DimNonOperatorElements) && (Array.IndexOf(proxy.Substation.Operators, MM_Repository.OverallDisplay.DisplayCompany) == -1))
                {
                    if (MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.HideNonOperatorElements)
                    {
                        proxy.BlackStartHidden = true;
                    }
                    else
                    {
                        proxy.BlackStartDim = true;
                    }
                }
                else if ((MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.HideNonBlackstartElements || MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.DimNonBlackstartElements) && (!element.IsBlackstart || Array.IndexOf(proxy.Substation.Operators, MM_Repository.OverallDisplay.DisplayCompany) == -1))
                {
                    if (MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.HideNonBlackstartElements)
                    {
                        proxy.BlackStartHidden = true;
                    }
                    else
                    {
                        proxy.BlackStartDim = true;
                    }
                }
                else if ((MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.HideExternalElements || MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.DimExternalElements) && !element.IsInternal)
                {
                    if (MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.HideExternalElements)
                    {
                        proxy.BlackStartHidden = true;
                    }
                    else
                    {
                        proxy.BlackStartDim = true;
                    }
                }



                //Handle null line operator values to keep from breaking the rest
                if ((element.Operators == null || element.Operators.Length == 0) &&
                    (MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.DimNonBlackstartElements ||
                     MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.DimNonOperatorElements))
                {
                    proxy.BlackStartDim = true;
                }
                else if (MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.DimNonBlackstartElements &&
                         (!element.IsBlackstart || Array.IndexOf(proxy.Substation.Operators, MM_Repository.OverallDisplay.DisplayCompany) == -1))
                {
                    proxy.BlackStartDim = true;
                }
                else if (MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.DimExternalElements && !element.IsInternal)
                {
                    proxy.BlackStartDim = true;
                }
                else if (MM_Repository.OverallDisplay.BlackstartMode == MM_Display.enumBlackstartMode.DimNonOperatorElements && Array.IndexOf(proxy.Substation.Operators, MM_Repository.OverallDisplay.DisplayCompany) == -1)
                {
                    proxy.BlackStartDim = true;
                }
                else
                {
                    proxy.BlackStartDim = false;
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Render our training layer
        /// </summary>
        /// <param name="renderTime"></param>
        public override void Render(RenderTime renderTime)
        {
            base.Render(renderTime);

            if (MM_Repository.Training == null || MM_Repository.Training.TrainingMode == Data_Elements.Training.MM_Training.enumTrainingMode.NotTraning)
            {
                return;
            }
            else
            {
                MM_Repository.Training.CheckTimes();
                String TextToDraw;
                Brush  DrawBrush;

                //Determine our question text and color

                if (MM_Repository.Training.TrainingMode == MM_Training.enumTrainingMode.UserWon)
                {
                    TextToDraw = "Congratulations! You won!";
                    DrawBrush  = LightGreenBrush;
                }
                else if (MM_Repository.Training.TrainingMode == MM_Training.enumTrainingMode.UserFailed)
                {
                    TextToDraw = "Sorry - please play again!";
                    DrawBrush  = RedBrush;
                }
                else
                {
                    TextToDraw = MM_Repository.Training.QuestionText;
                    DrawBrush  = QuestionBrush;
                }

                //Now, draw all of our strings
                DrawString(TextToDraw, VerticalAlignment.Top, HorizontalAlignment.Center, DrawBrush, QuestionFormat);
                DrawString("Score: " + MM_Repository.Training.Score.ToString("#,##0"), VerticalAlignment.Top, HorizontalAlignment.Left, DrawBrush, QuestionFormat);
                DrawString("[" + (MM_Repository.Training.CurrentLevel.ID + 1).ToString() + "]: " + MM_Repository.Training.CurrentLevel.Title, VerticalAlignment.Bottom, HorizontalAlignment.Left, DrawBrush, QuestionFormat);

                //If we're in question mode, show our countdown timer
                if (MM_Repository.Training.TrainingMode == MM_Training.enumTrainingMode.QuestionAsked)
                {
                    double TimeLeft = MM_Repository.Training.CurrentLevel.QuestionTimeout - MM_Repository.Training.TimeSincePresentation;
                    DrawString("Time: " + TimeLeft.ToString("0"), VerticalAlignment.Top, HorizontalAlignment.Right, DrawBrush, QuestionFormat);
                }



                //If we have the incorrect answer, draw accordingly.
                if (MM_Repository.Training.TrainingMode == MM_Training.enumTrainingMode.AnswerCorrect || MM_Repository.Training.TrainingMode == MM_Training.enumTrainingMode.AnswerWrong)
                {
                    bool Correct = MM_Repository.Training.TrainingMode == MM_Training.enumTrainingMode.AnswerCorrect;
                    DrawBrush = Correct ? CorrectBrush : IncorrectBrush;
                    DrawString(MM_Repository.Training.AnswerText, VerticalAlignment.Top, HorizontalAlignment.Center, DrawBrush, QuestionFormat, 1, 2);

                    RawVector2 CorrectAnswerXY = MM_Coordinates.LngLatToScreenVector2(MM_Repository.Training.CorrectAnswer, Surface.Coordinates.ZoomLevel);
                    CorrectAnswerXY.X -= Surface.Coordinates.TopLeftXY.X;
                    CorrectAnswerXY.Y -= Surface.Coordinates.TopLeftXY.Y;

                    if (!MM_Repository.Training.UserAnswer.IsEmpty)
                    {
                        RawVector2 UserAnswerXY = MM_Coordinates.LngLatToScreenVector2(MM_Repository.Training.UserAnswer, Surface.Coordinates.ZoomLevel);
                        UserAnswerXY.X -= Surface.Coordinates.TopLeftXY.X;
                        UserAnswerXY.Y -= Surface.Coordinates.TopLeftXY.Y;
                        DrawCrosshairBackground(UserAnswerXY, 8f);
                        Surface.RenderTarget2D.DrawLine(CorrectAnswerXY, UserAnswerXY, BlackBrush, 5f);

                        DrawCrosshairBackground(CorrectAnswerXY, 15f);
                        Surface.RenderTarget2D.DrawLine(CorrectAnswerXY, UserAnswerXY, CorrectBrush, 3f);
                        DrawCrosshair(WhiteBrush, UserAnswerXY, 10, "");
                    }

                    if (MM_Repository.Training.TargetElement is MM_Substation)
                    {
                        DrawCrosshair(DrawBrush, CorrectAnswerXY, 20, ((MM_Substation)MM_Repository.Training.TargetElement).LongName);
                    }
                    else
                    {
                        DrawCrosshair(DrawBrush, CorrectAnswerXY, 20, MM_Repository.Training.TargetElement.Name);
                    }
                }
            }
        }
예제 #5
0
 private Vector2 ConvertPoint(Vector2 point)
 {
     return(MM_Coordinates.LngLatToScreenVector2(point, 4) * _scale);
 }