Esempio n. 1
0
        /// <summary>
        /// Draw the layer.
        /// </summary>
        /// <param name="renderTime">Time since last render.</param>
        /// <remarks>include base.Render(renderTime); in overloads to preserve updating RenderTime field.</remarks>
        public override void Render(RenderTime renderTime)
        {
            base.Render(renderTime);
            if (MM_Repository.OverallDisplay.MapTiles == MM_MapTile.enumMapType.None)
            {
                return;
            }

            var tx = Surface.RenderTarget2D.Transform;

            Surface.RenderTarget2D.Transform = SharpDX.Matrix3x2.Identity;
            BaseMapTileProxy backgroundTile;
            Point            topLeftTile      = MM_Coordinates.XYToTile(Surface.Coordinates.TopLeftXY);
            Point            bottomRightTile  = MM_Coordinates.XYToTile(Surface.Coordinates.BottomRightXY);
            Point            topLeftTileShift = new Point(Surface.Coordinates.TopLeftXY.X % MM_Repository.OverallDisplay.MapTileSize.Width, Surface.Coordinates.TopLeftXY.Y % MM_Repository.OverallDisplay.MapTileSize.Height);
            int extraRadius = 4;

            SharpDX.RectangleF tileSourceRect = new SharpDX.RectangleF(0, 0, MM_Repository.OverallDisplay.MapTileSize.Width, MM_Repository.OverallDisplay.MapTileSize.Height);

            if (MM_Repository.OverallDisplay.MapTiles != MM_MapTile.enumMapType.None)
            {
                int startX = topLeftTile.X - extraRadius;
                int endX   = bottomRightTile.X + extraRadius;
                int startY = topLeftTile.Y - extraRadius;
                int endY   = bottomRightTile.Y + extraRadius;


                foreach (var thisTile in Spiral(topLeftTile, bottomRightTile, extraRadius))
                {
                    TileCoordinates tileCoord = new TileCoordinates(MM_Repository.OverallDisplay.MapTiles, thisTile, (int)Surface.Coordinates.ZoomLevel);
                    if (TryGetTile(tileCoord, out backgroundTile))
                    {
                        if (!backgroundTile.IsReady)
                        {
                            continue;
                        }

                        var targetRect = new SharpDX.RectangleF(((thisTile.X - topLeftTile.X) * MM_Repository.OverallDisplay.MapTileSize.Width) - topLeftTileShift.X, ((thisTile.Y - topLeftTile.Y) * MM_Repository.OverallDisplay.MapTileSize.Height) - topLeftTileShift.Y, MM_Repository.OverallDisplay.MapTileSize.Width, MM_Repository.OverallDisplay.MapTileSize.Height);
                        Surface.RenderTarget2D.DrawBitmap(backgroundTile.Bitmap, targetRect, MM_Repository.OverallDisplay.MapTransparency, BitmapInterpolationMode.NearestNeighbor, tileSourceRect);
                    }
                }

                //for (Point thisTile = new Point(topLeftTile.X - extraRadius, topLeftTile.Y - extraRadius); thisTile.X <= bottomRightTile.X + extraRadius; thisTile.X++, thisTile.Y = topLeftTile.Y)
                //{
                //    for (; thisTile.Y <= bottomRightTile.Y + extraRadius; thisTile.Y++)
                //    {
                //        TileCoordinates tileCoord = new TileCoordinates(MM_Repository.OverallDisplay.MapTiles, thisTile, (int)Surface.Coordinates.ZoomLevel);
                //        if (TryGetTile(tileCoord, out backgroundTile))
                //        {
                //            if (!backgroundTile.IsReady) continue;
                //
                //            var targetRect = new SharpDX.RectangleF(((thisTile.X - topLeftTile.X) * MM_Repository.OverallDisplay.MapTileSize.Width) - topLeftTileShift.X, ((thisTile.Y - topLeftTile.Y) * MM_Repository.OverallDisplay.MapTileSize.Height) - topLeftTileShift.Y, MM_Repository.OverallDisplay.MapTileSize.Width, MM_Repository.OverallDisplay.MapTileSize.Height);
                //            Surface.RenderTarget2D.DrawBitmap(backgroundTile.Bitmap, targetRect, MM_Repository.OverallDisplay.MapTransparency, BitmapInterpolationMode.NearestNeighbor, tileSourceRect);
                //        }
                //    }
                //}
            }

            Surface.RenderTarget2D.Transform = tx;
        }
Esempio n. 2
0
        /// <summary>
        /// Initialize the Macomber Map
        /// </summary>
        /// <param name="Coordinates">The coordinates to be used in the map</param>
        /// <param name="Starter">Our startup form</param>
        public MacomberMap_Form(MM_Coordinates Coordinates, MM_Startup_Form Starter)
        {
            InitializeComponent();


            var size = ClientSize;

            this.Size = Screen.PrimaryScreen.WorkingArea.Size;
            if (this.Size.Width >= 1900)
            {
                size = new Size(1900, this.Size.Height);
            }
            if (this.Size.Height >= 1200)
            {
                size = new Size(this.Size.Width, 1180);
            }
            this.ClientSize = new Size(size.Width - 10, size.Height - 10);
            this.Size       = ClientSize;

            this.Title   = "Main Map";
            this.Starter = Starter;
            MM_System_Interfaces.LogError("MM: Initializing network map/coordinates");
            InitNetworkMap(Coordinates);

            if (!Data_Integration.Permissions.ShowViolations)
            {
                SwitchMMView(false, false);
            }


            //Assign our integration layer, add the thread and form to it

            Data_Integration.RunningForms.Add(this);
            Data_Integration.RunningThreads.Add(System.Threading.Thread.CurrentThread);
            System.Threading.Thread.Sleep(3000); // wait for model kv levels to load
            //Assign our controls
            MM_System_Interfaces.LogError("MM: Starting network map");
            ctlNetworkMap.SetControls(ctlViolationViewer, 0);
            MM_System_Interfaces.LogError("MM: Starting violation viewer");
            ctlViolationViewer.SetControls(ctlNetworkMap);
            MM_System_Interfaces.LogError("MM: Starting key indicators");

            ctlKeyIndicators.SetControls(ctlNetworkMap, ctlViolationViewer, MM_Repository.xConfiguration.DocumentElement["DisplayParameters"]["KeyIndicators"]);

            ResizeLeftSlider(this, null);

            //Set up our results helper
            ResultsHelper         = new MM_Search_Results_Helper();
            ResultsHelper.Visible = false;
            Controls.Add(ResultsHelper);
            ResultsHelper.BringToFront();
            (this.FindForm() as MacomberMap_Form).ctlKeyIndicators.AssignResultsHelper(ResultsHelper);



            //Set up our main timer
            Program.MainFormChecker = new System.Threading.Timer(Program.ThreadChecker, System.Threading.Thread.CurrentThread, 15000, 15000);

            StartRender();
        }
Esempio n. 3
0
        private void DrawLasso()
        {
            if (_coordinates == null)
            {
                return;
            }

            if (_coordinates.LassoPoints.Count > 1)
            {
                var           points = MM_Coordinates.ConvertPoints(_coordinates.LassoPoints, 4).Select(p => p * _scale).ToList();
                RawRectangleF bounds;
                var           geometry = Surface.CreateRegionPathGeometry(points, out bounds, filled: true, closed: true, simplify: true);

                _target.FillGeometry(geometry, Surface.Brushes.GetBrush(_coordinates.LassoColor, 0.5f));
                _target.DrawGeometry(geometry, Surface.Brushes.GetBrush(Color4.White), 2f);
                geometry.Dispose();
            }
            else if (!_coordinates.LassoEnd.IsEmpty)
            {
                var start = ConvertPoint(_coordinates.LassoStart);
                var end   = ConvertPoint(_coordinates.LassoEnd);

                var rawRectangleF = new RawRectangleF(start.X, start.Y, end.X, end.Y);
                _target.FillRectangle(rawRectangleF, Surface.Brushes.GetBrush(_coordinates.LassoColor, 0.5f));
                _target.DrawRectangle(rawRectangleF, Surface.Brushes.GetBrush(Color4.White), 2f);
            }
        }
Esempio n. 4
0
 private void UpdateCoordinatesKDTree(IList <MM_Substation> subs, int zoomLevel)
 {
     foreach (var sub in subs)
     {
         var xy = MM_Coordinates.LngLatToXY(sub.LngLat, zoomLevel);
         _kdTree.AddPoint(new double[] { xy.X, xy.Y }, sub);
     }
 }
Esempio n. 5
0
 internal void FixCoordinatesNull()
 {
     if (Coordinates == null)
     {
         // TODO: Fix this boundary issue
         Coordinates = new MM_Coordinates(-105.589265200513f, 44.5322075f, -86.09185f, 29.2118549f, 4);
         //Coordinates = new MM_Coordinates(MM_Repository.Counties["STATE"].Min, MM_Repository.Counties["STATE"].Max, Data_Integration.Permissions.MinZoom);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Load in a new tile
        /// </summary>
        /// <param name="tileCoordinates"></param>
        public MM_MapTile(TileCoordinates tileCoordinates)
        {
            this.TileCoordinates = tileCoordinates;


            //Determine our tile's positioning
            this.TopLeft       = MM_Coordinates.TileTopLeft(tileCoordinates.TileXY, tileCoordinates.ZoomLevel);
            this.BottomRight   = MM_Coordinates.TileBottomRight(tileCoordinates.TileXY, tileCoordinates.ZoomLevel);
            this.TopLeftXY     = new Point(tileCoordinates.TileXY.X * MM_Repository.OverallDisplay.MapTileSize.Width, tileCoordinates.TileXY.Y * MM_Repository.OverallDisplay.MapTileSize.Height);
            this.BottomRightXY = new Point(((tileCoordinates.TileXY.X + 1) * MM_Repository.OverallDisplay.MapTileSize.Width) - 1, ((tileCoordinates.TileXY.Y + 1) * MM_Repository.OverallDisplay.MapTileSize.Height) - 1);
            this.Saving        = false;
            this.Failed        = false;
        }
Esempio n. 7
0
        /// <summary>
        /// Create a new layer
        /// </summary>
        /// <param name="surface">The <see cref="Direct3DSurface"/> this layer belongs to.</param>
        /// <param name="name">The name of the layer.</param>
        /// <param name="order">The order of the layer</param>
        public MinimapLayer(Direct3DSurface surface, MM_Violation_Viewer violationViewer) : base(surface, "Minimap", 99999)
        {
            _violationViewer = violationViewer;

            var map = this.Surface as MM_Network_Map_DX;

            _coordinates = map.Coordinates;
            violationViewer.ViolationsChanged += (s, e) => _isDirty = true;
            // Hook events to update render state
            MM_Repository.ViewChanged += v => _isDirty = true;
            _coordinates.Panned       += (center, newCenter) => _isDirty = true;
            _coordinates.Zoomed       += (zoom, newZoom) => _isDirty = true;
            _coordinates.LassoDrawing += () => _isDirty = true;
        }
Esempio n. 8
0
 /// <summary>
 /// Initialize the network map
 /// </summary>
 /// <param name="Coordinates">The coordinates to be used for the map</param>
 private void InitNetworkMap(MM_Coordinates Coordinates)
 {
     this.ctlNetworkMap           = new MM_Network_Map_DX(Coordinates);
     this.ctlNetworkMap.Dock      = System.Windows.Forms.DockStyle.Fill;
     this.ctlNetworkMap.ForeColor = System.Drawing.Color.FromArgb(224, 224, 224);
     this.ctlNetworkMap.Location  = new System.Drawing.Point(0, 0);
     this.ctlNetworkMap.Name      = "ctlNetworkMap";
     this.ctlNetworkMap.Padding   = new System.Windows.Forms.Padding(0, 0, 10, 0);
     this.ctlNetworkMap.Size      = new System.Drawing.Size(1135, 544);
     this.ctlNetworkMap.TabIndex  = 0;
     this.splHorizontal.Panel2.Controls.Add(this.ctlNetworkMap);
     this.ViolationForm                 = new Form();
     this.ViolationForm.Text            = "Violation Viewer - " + Data_Integration.UserName.ToUpper() + " - Macomber Map®";
     this.ViolationForm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
     this.ViolationForm.FormClosing    += new FormClosingEventHandler(ViolationForm_FormClosing);
     this.ViolationForm.Icon            = this.Icon;
     // ReloadModelTimer = new System.Threading.Timer(cb => { ReloadModel(); }, null, 60 * 1000, 2 * 60 * 1000);
 }
Esempio n. 9
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);
                }
            }
        }
Esempio n. 10
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 value in regions.Values)
            {
                value.Geometry.Dispose();
            }
            regions.Clear();

            foreach (var boundary in MM_Repository.Counties.Values.ToList())
            {
                RawRectangleF bounds;
                var           geometry = Surface.CreateRegionPathGeometry(MM_Coordinates.ConvertPoints(boundary.Coordinates, Surface.Coordinates.ZoomLevel).ToList(), out bounds, filled: true, simplify: true);

                var region = new RegionProxy(geometry, boundary.DisplayParameter.ForeColor, boundary.DisplayParameter.Width, bounds);
                region.Boundary = boundary;
                if (boundary.Name == "STATE")
                {
                    state = region;
                }
                else
                {
                    regions.Add(boundary, region);
                }
            }

            foreach (MM_Boundary boundary in MM_Repository.Districts.Values.ToList())
            {
                RawRectangleF bounds;
                var           geometry = Surface.CreateRegionPathGeometry(MM_Coordinates.ConvertPoints(boundary.Coordinates, Surface.Coordinates.ZoomLevel).ToList(), out bounds, simplify: true);
                var           region   = new RegionProxy(geometry, boundary.DisplayParameter.ForeColor, boundary.DisplayParameter.Width, bounds);
                regions.Add(boundary, region);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Load Content and initialize unmanaged resources.
        /// </summary>
        public override void LoadContent()
        {
            int width  = 256;
            int height = 256;

            var size  = Surface.RenderTarget2D.PixelSize;
            var sizeV = new Vector2(size.Width, size.Height);

            _start        = sizeV - new Vector2(width, height) - new Vector2(10, 10);
            _end          = sizeV - new Vector2(10, 10);
            _viewLocation = new SharpDX.RectangleF(_start.X, _start.Y, _end.X - _start.X, _end.Y - _start.Y);

            base.LoadContent();

            if (_font == null || _font.IsDisposed)
            {
                _font = Surface.Fonts.GetTextFormat(MM_Repository.OverallDisplay.NetworkMapFont, 5);
            }

            if (_target == null || _target.IsDisposed)
            {
                _target = Surface.CreateRenderTarget(width, height);
            }

            MM_Boundary State;

            if (MM_Repository.Counties.TryGetValue("STATE", out State))
            {
                RawRectangleF bounds;
                var           geometry = Surface.CreateRegionPathGeometry(MM_Coordinates.ConvertPoints(State.Coordinates, 4).ToList(), out bounds, filled: true, simplify: true);
                geometry.Dispose();

                _scale = new Vector2(width / (bounds.Right - bounds.Left), height / (bounds.Bottom - bounds.Top));

                var geometryScaled = Surface.CreateRegionPathGeometry(MM_Coordinates.ConvertPoints(State.Coordinates, 4).ToList(), out bounds, filled: true, compression: 0.001f, simplify: true, scaleX: _scale.X, scaleY: _scale.Y);
                _location = new Vector2(bounds.Left, bounds.Top);

                _state = new RegionProxy(geometryScaled, State.DisplayParameter.ForeColor, State.DisplayParameter.Width, bounds);
            }
        }
Esempio n. 12
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);
                    }
                }
            }
        }
Esempio n. 13
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;
        }
Esempio n. 14
0
        /// <summary>
        /// Hanlde our element selection on our mouse down. If no element has been selected, just make sure the element is highlighted.
        /// </summary>
        /// <param name="SelectedElement"></param>
        /// <param name="Coordinates"></param>
        /// <param name="PixelLocation"></param>
        /// <param name="HighlightedElement"></param>
        public MM_Coordinate_Suggestion HandleElementSelection(MM_Element SelectedElement, MM_Coordinates Coordinates, Point PixelLocation, ref MM_Element HighlightedElement)
        {
            MM_Coordinate_Suggestion FoundSuggestion = null;

            //Update the status of our element
            UpdateElement(SelectedElement);

            //Now, if our selected element is also highlighted, let's activate it
            if (HighlightedElement == SelectedElement)
            {
                if (!Suggestions.TryGetValue(SelectedElement, out FoundSuggestion))
                {
                    Suggestions.Add(SelectedElement, FoundSuggestion = new MM_Coordinate_Suggestion(SelectedElement, Coordinates));
                    ActiveChanges.Rows.Add(SelectedElement.ElemType, SelectedElement.Name, SelectedElement.TEID);
                }
                //If we're a line, determine how we should handle things based on our pixel location

                if (SelectedElement is MM_Line)
                {
                    int HitThreshold = 3;
                    FoundSuggestion.LineIndex = -1;

                    //First, go through and check to see if we have a close match
                    for (int a = 0; a < FoundSuggestion.SuggestedCoordinatesXY.Length; a++)
                    {
                        if (Math.Abs(FoundSuggestion.SuggestedCoordinatesXY[a].X - PixelLocation.X) < HitThreshold && Math.Abs(FoundSuggestion.SuggestedCoordinatesXY[a].Y - PixelLocation.Y) < HitThreshold)
                        {
                            FoundSuggestion.LineIndex = a;
                        }
                    }

                    //If not, continue looking in between our points
                    if (FoundSuggestion.LineIndex == -1)
                    {
                        for (int a = 1; a < FoundSuggestion.SuggestedCoordinatesXY.Length; a++)
                        {
                            Point Pt1   = FoundSuggestion.SuggestedCoordinatesXY[a - 1];
                            Point Pt2   = FoundSuggestion.SuggestedCoordinatesXY[a];
                            float Slope = (Single)(Pt1.Y - Pt2.Y) / (Single)(Pt1.X - Pt2.X);
                            float YInt  = Pt1.Y - (Slope * Pt1.X);
                            float TestY = (Slope * PixelLocation.X) + YInt;
                            if (Math.Abs(TestY - PixelLocation.Y) < HitThreshold)
                            {
                                if ((PixelLocation.X >= Pt1.X && PixelLocation.X <= Pt2.X) || (PixelLocation.X <= Pt1.X && PixelLocation.X >= Pt2.X))
                                {
                                    if ((PixelLocation.Y >= Pt1.Y && PixelLocation.Y <= Pt2.Y) || (PixelLocation.Y <= Pt1.Y && PixelLocation.Y >= Pt2.Y))
                                    {
                                        List <PointF> UpdatedCoordinates = new List <PointF>(FoundSuggestion.SuggestedCoordinates);
                                        UpdatedCoordinates.Insert(a, MM_Coordinates.XYToLngLat(PixelLocation, Coordinates.ZoomLevel));
                                        (SelectedElement as MM_Line).Coordinates = FoundSuggestion.SuggestedCoordinates.ToList();
                                        FoundSuggestion.SuggestedCoordinates     = UpdatedCoordinates.ToArray();

                                        List <Point> UpdatedCoordinateXY = new List <Point>(FoundSuggestion.SuggestedCoordinatesXY);
                                        UpdatedCoordinateXY.Insert(a, PixelLocation);
                                        FoundSuggestion.SuggestedCoordinatesXY = UpdatedCoordinateXY.ToArray();
                                        FoundSuggestion.LineIndex = a;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            HighlightedElement = SelectedElement;
            return(FoundSuggestion);
        }
Esempio n. 15
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;
                }
            }
        }
Esempio n. 16
0
        static void Main(params string[] args)
        {
            // CreateModelXml user password filepath (Build thMM_System_Interfacesis as a console app for this job).
            if (args.Length > 0 && args[0].Equals("CreateModelXml", StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    System.Console.Error.WriteLine("Starting XML Model creator client");
                    MM_Server_Interface.LoadModelFromSql = true;
                    MM_System_Interfaces.Headless        = true;
                    MM_Repository.OverallDisplay         = new MM_Display();
                    MM_Coordinates coord = new MM_Coordinates(-109f, 29f, -86f, 51f, 1f);

                    System.Console.Error.WriteLine("Waiting for server...");
                    while (MM_Server_Interface.MMServers == null || MM_Server_Interface.MMServers.Count == 0)
                    {
                        Thread.Sleep(3000);
                    }

                    var list = MM_Server_Interface.MMServers.Values.ToList();

                    System.Console.Error.WriteLine("Connecting to server: " + list[0].ServerName);

                    string user     = "******";
                    string password = "";
                    string file     = "MacomberMap-Combined.MM_Model";

                    if (args.Length > 1)
                    {
                        if (args[1].EndsWith(".MM_Model"))
                        {
                            file = args[1];
                        }
                        else
                        {
                            user = args[1];
                        }
                    }
                    if (args.Length > 2)
                    {
                        if (args[2].EndsWith(".MM_Model"))
                        {
                            file = args[2];
                        }
                        else
                        {
                            password = args[2];
                        }
                    }
                    if (args.Length > 3)
                    {
                        file = args[3];
                    }
                    Exception exp = new Exception();
                    MM_Server_Interface.TryLogin(list[0].ServerName, list[0].ServerURI, user, password, out exp);
                    MM_Server_Interface.LoadMacomberMapConfiguration();

                    Data_Integration.InitializationComplete = false;
                    System.Console.Error.WriteLine("Starting SQL Model Loader...");
                    SqlModelLoader sqlModelLoader = new SqlModelLoader();
                    sqlModelLoader.ConnectionString = Settings.Default.ModelDatabase;
                    sqlModelLoader.LoadStaticRepository();
                    System.Console.Error.WriteLine("Rolling up Elements...");
                    Data_Integration.UseEstimates = false;
                    Data_Integration.RollUpElementsToSubstation();
                    Data_Integration.CommLoaded                 = true;
                    Data_Integration.ModelLoadCompletion        = DateTime.Now;
                    Data_Integration.NetworkSource              = new MM_Data_Source();
                    Data_Integration.NetworkSource.Estimates    = false;
                    Data_Integration.NetworkSource.Database     = "NETMOM";
                    Data_Integration.NetworkSource.Application  = "RTNET";
                    Data_Integration.NetworkSource.BackColor    = Color.Blue;
                    Data_Integration.NetworkSource.Telemetry    = true;
                    Data_Integration.NetworkSource.Default      = true;
                    Data_Integration.NetworkSource.Master       = true;
                    Data_Integration.NetworkSource.ViolationApp = "RTCA";
                    Data_Integration.InitializationComplete     = true;
                    // Data_Integration.RestartModel(MM_Server_Interface.Client);
                    Data_Integration.SaveXMLData(file, coord);
                    System.Console.WriteLine("Waiting for data...");
                    for (int i = 0; i < 60 * 8; i++)
                    {
                        System.Console.Write(".");
                        Thread.Sleep(1000); // wait for EMS data to flow in.
                    }
                    Data_Integration.SaveXMLData(file, coord);
                }
                catch (Exception ex)
                {
                    System.Console.Error.WriteLine(ex.Message);
                    System.Console.Error.WriteLine(ex.StackTrace);
                    System.Environment.Exit(1);
                }
                System.Environment.Exit(0);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += Application_ThreadException;
            //   Application.Run(new frmControlTester());
            // return;
            try
            {
                Microsoft.Win32.RegistryKey key;
                key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Policies", true);

                if (!key.GetSubKeyNames().Contains("Chromium"))
                {
                    key.CreateSubKey("Chromium");
                }
                key = key.OpenSubKey("Chromium", true);
                if (!key.GetSubKeyNames().Contains("EnabledPlugins"))
                {
                    key.CreateSubKey("EnabledPlugins");
                }
                key = key.OpenSubKey("EnabledPlugins", true);

                if (!key.GetValueNames().Contains("1"))
                {
                    key.SetValue("1", "Silverlight*");
                    key.SetValue("2", "npapi");
                }
            }
            catch (Exception ex)
            {
                MM_System_Interfaces.LogError(ex);
            }
            if (Environment.CommandLine.IndexOf("/Test", StringComparison.CurrentCultureIgnoreCase) != -1)
            {
                Application.Run(new frmTest());
            }
            else
            {
                using (MM_Startup_Form Startup = new MM_Startup_Form())
                    if (Startup.ShowDialog(StartNetworkMap) == DialogResult.OK)
                    {
                        Application.Run();
                    }
                    else
                    {
                        Application.Exit();
                    }
            }
        }
Esempio n. 17
0
 private Vector2 ConvertPoint(Vector2 point)
 {
     return(MM_Coordinates.LngLatToScreenVector2(point, 4) * _scale);
 }