Exemplo n.º 1
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);
        }