public static NetworkModel LoadNetworkModel(NetworkModel networkModel, UInt64[,] grid, Canvas myCanvas, MouseButtonEventHandler increase)
        {
            int counter = 0;

            networkModel = XmlHandler.Load <NetworkModel>(@"..\..\Geographic.xml");

            // SUBSTATIONS
            for (int i = 0; i < networkModel.Substations.Count; i++)
            {
                double decimalX, decimalY;
                CoordinatesHandler.ToLatLon(networkModel.Substations[i].X, networkModel.Substations[i].Y, 34, out decimalX, out decimalY);

                int indexI, indexJ;
                CoordinatesHandler.FromCoordsToIndex(decimalX, decimalY, out indexI, out indexJ);

                if (grid[indexI, indexJ] == 0)
                {
                    grid[indexI, indexJ] = networkModel.Substations[i].Id;

                    networkModel.Substations[i].Row    = indexI;
                    networkModel.Substations[i].Column = indexJ;
                    IndexesI.Add(indexI);
                    IndexesJ.Add(indexJ);

                    Entities.Add(networkModel.Substations[i].Id, networkModel.Substations[i]);
                }

                Ellipse image = ScreenHandler.DrawSubstationImage(indexI, indexJ, myCanvas, networkModel.Substations[i]);
                image.MouseLeftButtonDown        += increase;
                networkModel.Substations[i].Shape = image;
                myCanvas.Children.Add(image);
            }

            // NODES
            for (int i = 0; i < networkModel.Nodes.Count; i++)
            {
                double decimalX, decimalY;
                CoordinatesHandler.ToLatLon(networkModel.Nodes[i].X, networkModel.Nodes[i].Y, 34, out decimalX, out decimalY);

                int indexI, indexJ;
                CoordinatesHandler.FromCoordsToIndex(decimalX, decimalY, out indexI, out indexJ);

                if (grid[indexI, indexJ] == 0)
                {
                    grid[indexI, indexJ] = networkModel.Nodes[i].Id;
                }
                else
                {
                    bool spaceFound = FindFreeSpaceForNode(networkModel, grid, indexI, indexJ, i, out indexI, out indexJ);

                    grid[indexI, indexJ] = networkModel.Nodes[i].Id;

                    if (!spaceFound)
                    {
                        counter++;
                    }
                }
                networkModel.Nodes[i].Row    = indexI;
                networkModel.Nodes[i].Column = indexJ;
                IndexesI.Add(indexI);
                IndexesJ.Add(indexJ);

                Entities.Add(networkModel.Nodes[i].Id, networkModel.Nodes[i]);

                Ellipse image = ScreenHandler.DrawNodeImage(indexI, indexJ, myCanvas, networkModel.Nodes[i]);
                image.MouseLeftButtonDown  += increase;
                networkModel.Nodes[i].Shape = image;
                myCanvas.Children.Add(image);
            }

            // SWITCHES
            for (int i = 0; i < networkModel.Switches.Count; i++)
            {
                double decimalX, decimalY;
                CoordinatesHandler.ToLatLon(networkModel.Switches[i].X, networkModel.Switches[i].Y, 34, out decimalX, out decimalY);
                networkModel.Switches[i].X = decimalX;
                networkModel.Switches[i].Y = decimalY;

                int indexI, indexJ;
                CoordinatesHandler.FromCoordsToIndex(decimalX, decimalY, out indexI, out indexJ);

                if (grid[indexI, indexJ] == 0)
                {
                    grid[indexI, indexJ] = networkModel.Switches[i].Id;
                }
                else
                {
                    bool spaceFound = FindFreeSpaceForSwitch(networkModel, grid, indexI, indexJ, i, out indexI, out indexJ);

                    grid[indexI, indexJ] = networkModel.Switches[i].Id;

                    if (!spaceFound)
                    {
                        counter++;
                    }
                }

                networkModel.Switches[i].Row    = indexI;
                networkModel.Switches[i].Column = indexJ;
                IndexesI.Add(indexI);
                IndexesJ.Add(indexJ);

                Entities.Add(networkModel.Switches[i].Id, networkModel.Switches[i]);

                Ellipse image = ScreenHandler.DrawSwitchImage(indexI, indexJ, myCanvas, networkModel.Switches[i]);
                image.MouseLeftButtonDown     += increase;
                networkModel.Switches[i].Shape = image;
                myCanvas.Children.Add(image);
            }

            int minI = IndexesI.Min();          // 672
            int minJ = IndexesJ.Min();          // 726
            int maxI = IndexesI.Max();          // 811
            int maxJ = IndexesJ.Max();          // 951

            return(networkModel);
        }
Exemplo n.º 2
0
        public static NetworkModel LoadModelToMap(NetworkModel networkModel, ModelVisual3D myModel)
        {
            networkModel = XmlHandler.Load <NetworkModel>(@"..\..\Geographic.xml");

            // SUBSTATIONS
            for (int i = 0; i < networkModel.Substations.Count; i++)
            {
                double latitude, longitude, mapX, mapY;

                CoordinatesHandler.ToLatLon(networkModel.Substations[i].X, networkModel.Substations[i].Y, 34, out latitude, out longitude);
                networkModel.Substations[i].X = latitude;
                networkModel.Substations[i].Y = longitude;

                CoordinatesHandler.FromCoordinatesToMapPosition(latitude, longitude, out mapX, out mapY);
                networkModel.Substations[i].MapX = mapX;
                networkModel.Substations[i].MapY = mapY;

                if (mapX != -1 && mapY != -1)
                {
                    double z = 0;

                    if (Points.Count != 0 || i != 0)
                    {
                        int index = 0;

                        if (HasEntityInRadius(mapX, mapY, out index))
                        {
                            Points[index].Count++;
                            z = 0.05 * Points[index].Count;
                        }
                        else
                        {
                            z = 0;
                            Points.Add(new PointStack(mapX, mapY, 0));
                        }
                    }
                    else
                    {
                        z = 0;
                        Points.Add(new PointStack(mapX, mapY, 0));
                    }
                    GeometryModel3D model3D = ScreenHandler.Make3DCube(mapX, mapY, z, 0.05, EntityType.Substation, networkModel.Substations[i]);

                    ScreenHandler.Draw3DCube(model3D, myModel);
                }
            }

            // NODES
            for (int i = 0; i < networkModel.Nodes.Count; i++)
            {
                double latitude, longitude, mapX, mapY;

                CoordinatesHandler.ToLatLon(networkModel.Nodes[i].X, networkModel.Nodes[i].Y, 34, out latitude, out longitude);
                networkModel.Nodes[i].X = latitude;
                networkModel.Nodes[i].Y = longitude;

                CoordinatesHandler.FromCoordinatesToMapPosition(latitude, longitude, out mapX, out mapY);
                networkModel.Nodes[i].MapX = mapX;
                networkModel.Nodes[i].MapY = mapY;

                if (mapX != -1 && mapY != -1)
                {
                    double z = 0;

                    if (i != 0)
                    {
                        int index = 0;

                        if (HasEntityInRadius(mapX, mapY, out index))
                        {
                            Points[index].Count++;
                            z = 0.05 * Points[index].Count;
                        }
                        else
                        {
                            z = 0;
                            Points.Add(new PointStack(mapX, mapY, 0));
                        }
                    }
                    else
                    {
                        z = 0;
                        Points.Add(new PointStack(mapX, mapY, 0));
                    }

                    GeometryModel3D model3D = ScreenHandler.Make3DCube(mapX, mapY, z, 0.05, EntityType.Node, networkModel.Nodes[i]);

                    ScreenHandler.Draw3DCube(model3D, myModel);
                }
            }

            // SWITCHES
            for (int i = 0; i < networkModel.Switches.Count; i++)
            {
                double latitude, longitude, mapX, mapY;

                CoordinatesHandler.ToLatLon(networkModel.Switches[i].X, networkModel.Switches[i].Y, 34, out latitude, out longitude);
                networkModel.Switches[i].X = latitude;
                networkModel.Switches[i].Y = longitude;

                CoordinatesHandler.FromCoordinatesToMapPosition(latitude, longitude, out mapX, out mapY);
                networkModel.Switches[i].MapX = mapX;
                networkModel.Switches[i].MapY = mapY;

                if (mapX != -1 && mapY != -1)
                {
                    double z = 0;

                    if (i != 0)
                    {
                        int index = 0;

                        if (HasEntityInRadius(mapX, mapY, out index))
                        {
                            Points[index].Count++;
                            z = 0.05 * Points[index].Count;
                        }
                        else
                        {
                            z = 0;
                            Points.Add(new PointStack(mapX, mapY, 0));
                        }
                    }
                    else
                    {
                        z = 0;
                        Points.Add(new PointStack(mapX, mapY, 0));
                    }

                    GeometryModel3D model3D = ScreenHandler.Make3DCube(mapX, mapY, z, 0.05, EntityType.Switch, networkModel.Switches[i]);

                    ScreenHandler.Draw3DCube(model3D, myModel);
                }
            }

            // LINES
            int cnt = 0;

            for (int i = 0; i < networkModel.Lines.Count; i++)
            {
                double latitude1, longitude1, mapX1, mapY1, latitude2, longitude2, mapX2, mapY2;

                for (int j = 0; j < networkModel.Lines[i].Vertices.Count - 1; j++)
                {
                    CoordinatesHandler.ToLatLon(networkModel.Lines[i].Vertices[j].X, networkModel.Lines[i].Vertices[j].Y, 34, out latitude1, out longitude1);
                    networkModel.Lines[i].Vertices[j].X = latitude1;
                    networkModel.Lines[i].Vertices[j].Y = longitude1;

                    CoordinatesHandler.FromCoordinatesToMapPosition(latitude1, longitude1, out mapX1, out mapY1);

                    CoordinatesHandler.ToLatLon(networkModel.Lines[i].Vertices[j + 1].X, networkModel.Lines[i].Vertices[j + 1].Y, 34, out latitude2, out longitude2);
                    networkModel.Lines[i].Vertices[j + 1].X = latitude2;
                    networkModel.Lines[i].Vertices[j + 1].Y = longitude2;

                    CoordinatesHandler.FromCoordinatesToMapPosition(latitude2, longitude2, out mapX2, out mapY2);

                    if (mapX1 != -1 && mapY1 != -1 && mapX2 != -1 && mapY2 != -1)
                    {
                        cnt++;
                        ScreenHandler.DrawLine(mapX1, mapY1, mapX2, mapY2, myModel, networkModel.Lines[i]);

                        CountLine(networkModel.Lines[i].FirstEnd, networkModel);
                        CountLine(networkModel.Lines[i].SecondEnd, networkModel);
                    }
                }
            }
            return(networkModel);
        }