Пример #1
0
        public override void Initialize(DrawArgs drawArgs)
        {
            if (m_polygonFeature == null)
            {
                double    offset = 0.02;
                Point3d[] points = new Point3d[4];

                points[0] = new Point3d(
                    m_longitude - offset,
                    m_latitude - offset,
                    200000);

                points[1] = new Point3d(
                    m_longitude - offset,
                    m_latitude + offset,
                    200000);

                points[2] = new Point3d(
                    m_longitude + offset,
                    m_latitude + offset,
                    200000);

                points[3] = new Point3d(
                    m_longitude + offset,
                    m_latitude - offset,
                    200000);

                LinearRing outerRing = new LinearRing();
                outerRing.Points = points;

                m_polygonFeature = new PolygonFeature(
                    name,
                    World,
                    outerRing,
                    null,
                    System.Drawing.Color.Chocolate);

                m_polygonFeature.AltitudeMode = AltitudeMode.Absolute;
                m_polygonFeature.Extrude      = true;
                m_polygonFeature.Outline      = true;
                m_polygonFeature.OutlineColor = System.Drawing.Color.Chocolate;
            }

            FileInfo savedFlagFile   = new FileInfo(SavedImagePath);
            FileInfo placeHolderFile = new FileInfo(SavedImagePath + ".blk");

            if (savedFlagFile.Exists)
            {
                try
                {
                    m_texture = ImageHelper.LoadTexture(
                        savedFlagFile.FullName,
                        System.Drawing.Color.Black.ToArgb());
                }
                catch
                {
                    savedFlagFile.Delete();
                    savedFlagFile.Refresh();
                }
            }

            if (!savedFlagFile.Exists && !placeHolderFile.Exists)
            {
                if (!savedFlagFile.Directory.Exists)
                {
                    savedFlagFile.Directory.Create();
                }
                try
                {
                    // Offline check
                    if (World.Settings.WorkOffline)
                    {
                        throw new Exception("Offline mode active.");
                    }

                    MFW3D.Net.WebDownload download = new MFW3D.Net.WebDownload(m_imageUri);
                    download.DownloadFile(savedFlagFile.FullName);
                    download.Dispose();
                    savedFlagFile.Refresh();
                }
                catch
                {
                    FileStream fs = placeHolderFile.Create();
                    fs.Close();
                    fs = null;
                    placeHolderFile.Refresh();
                }

                if (savedFlagFile.Exists)
                {
                    m_texture = ImageHelper.LoadTexture(
                        savedFlagFile.FullName,
                        System.Drawing.Color.Black.ToArgb());
                }
            }

            if (m_vertexDeclaration == null)
            {
                VertexElement[] velements = new VertexElement[]
                {
                    new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                    new VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
                    new VertexElement(0, 24, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                    VertexElement.VertexDeclarationEnd
                };
                m_vertexDeclaration = new VertexDeclaration(drawArgs.device, velements);
            }

            UpdateVertices();
            isInitialized = true;
        }
Пример #2
0
        /// <summary>
        /// Plugin entry point - All plugins must implement this function
        /// </summary>
        public override void Load()
        {
            FileInfo savedFile = new FileInfo(SavedFilePath);

            if (!savedFile.Exists)
            {
                if (!savedFile.Directory.Exists)
                {
                    savedFile.Directory.Create();
                }

                try
                {
                    // Offline check
                    if (World.Settings.WorkOffline)
                    {
                        throw new Exception("Offline mode active.");
                    }

                    MFW3D.Net.WebDownload download = new MFW3D.Net.WebDownload(DataFileUri);
                    download.DownloadFile(savedFile.FullName);
                    download.Dispose();
                }
                catch { }
            }

            m_wavingFlagsList      = new RenderableObjectList("Waving Flags");
            m_wavingFlagsList.IsOn = false;
            System.Collections.Hashtable countryHash = new System.Collections.Hashtable();

            using (StreamReader reader = savedFile.OpenText())
            {
                string   header  = reader.ReadLine();
                string[] headers = header.Split('\t');

                string line = reader.ReadLine();
                while (line != null)
                {
                    System.Collections.Hashtable fieldHash = new System.Collections.Hashtable();
                    string[] lineParts = line.Split('\t');

                    //Log.Write(string.Format("{0}\t{1}", lineParts[0], lineParts[1]));
                    try
                    {
                        if ((lineParts[3].Length > 0) && (lineParts[4].Length > 0))
                        {
                            double latitude  = double.Parse(lineParts[3], System.Globalization.CultureInfo.InvariantCulture);
                            double longitude = double.Parse(lineParts[4], System.Globalization.CultureInfo.InvariantCulture);

                            if (lineParts[1].Length == 2)
                            {
                                string   flagFileUri   = FlagTextureDirectoryUri + "/" + lineParts[1] + FlagSuffix;
                                FileInfo savedFlagFile = new FileInfo(SavedFlagsDirectory + "\\" + lineParts[1] + ".dds");

                                WavingFlagLayer flag = new WavingFlagLayer(
                                    lineParts[0],
                                    Global.worldWindow.CurrentWorld,
                                    latitude,
                                    longitude,
                                    flagFileUri);

                                flag.SavedImagePath = savedFlagFile.FullName;
                                flag.ScaleX         = 100000;
                                flag.ScaleY         = 100000;
                                flag.ScaleZ         = 100000;
                                flag.Bar3D          = new Bar3D(flag.Name, flag.World, latitude, longitude, 0, flag.ScaleZ, System.Drawing.Color.Red);
                                flag.Bar3D.ScaleX   = 0.3f * flag.ScaleX;
                                flag.Bar3D.ScaleY   = 0.3f * flag.ScaleY;
                                flag.Bar3D.IsOn     = false;
                                flag.RenderPriority = RenderPriority.Custom;

                                flag.OnMouseEnterEvent += new EventHandler(flag_OnMouseEnterEvent);
                                flag.OnMouseLeaveEvent += new EventHandler(flag_OnMouseLeaveEvent);
                                flag.OnMouseUpEvent    += new System.Windows.Forms.MouseEventHandler(flag_OnMouseUpEvent);
                                m_wavingFlagsList.Add(flag);

                                for (int i = 0; i < lineParts.Length; i++)
                                {
                                    try
                                    {
                                        double value;
                                        if (double.TryParse(lineParts[i], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out value))
                                        {
                                            fieldHash.Add(headers[i], value);
                                        }
                                        else
                                        {
                                            fieldHash.Add(headers[i], lineParts[i]);
                                        }
                                    }
                                    catch
                                    {
                                        fieldHash.Add(headers[i], lineParts[i]);
                                    }
                                }
                                countryHash.Add(lineParts[0], fieldHash);
                            }
                            else
                            {
                                //Log.Write(Log.Levels.Debug, "blank: " + lineParts[0]);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Write(Log.Levels.Warning, string.Format("Exception: {0} - {1}", lineParts[0], ex.ToString()));
                    }

                    line = reader.ReadLine();
                }
                Headers = headers;
            }

            CountryHash = countryHash;

            InitializeCiaForm();

            Global.worldWindow.CurrentWorld.RenderableObjects.Add(m_wavingFlagsList);
        }