Example #1
0
        private void m_RefreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                if (this.isUpdating)
                {
                    return;
                }

                this.isUpdating = true;

                if (this.m_ImageUri == null)
                {
                    return;
                }

                if (this.m_ImageUri.ToLower().StartsWith("http://"))
                {
                    bool forceDownload = false;
                    if (this.m_SaveFilePath == null)
                    {
                        // TODO: hack, need to get the correct cache directory
                        this.m_SaveFilePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\Cache\\PictureBoxImages\\temp";
                        forceDownload       = true;
                    }
                    System.IO.FileInfo saveFile = new System.IO.FileInfo(this.m_SaveFilePath);

                    if (saveFile.Exists)
                    {
                        try
                        {
                            Texture texture = ImageHelper.LoadTexture(this.m_SaveFilePath);
                            texture.Dispose();
                        }
                        catch
                        {
                            saveFile.Delete();
                            saveFile.Refresh();
                        }
                    }
                    // Offline check added
                    if (!World.Settings.WorkOffline && (forceDownload || !saveFile.Exists ||
                                                        (this.m_RefreshTime > 0 && saveFile.LastWriteTime.Subtract(DateTime.Now) > TimeSpan.FromSeconds(this.m_RefreshTime))))
                    {
                        //download it
                        try
                        {
                            Net.WebDownload webDownload = new Net.WebDownload(this.m_ImageUri);
                            webDownload.DownloadType = Net.DownloadType.Unspecified;

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

                            webDownload.DownloadFile(this.m_SaveFilePath);
                        }
                        catch { }
                    }
                }
                else
                {
                    this.m_SaveFilePath = this.m_ImageUri;
                }

                if (this.m_ImageTexture != null && !this.m_ImageTexture.Disposed)
                {
                    this.m_ImageTexture.Dispose();
                    this.m_ImageTexture = null;
                }

                if (!System.IO.File.Exists(this.m_SaveFilePath))
                {
                    this.displayText = "Image Not Found";
                    return;
                }

                this.m_ImageTexture       = ImageHelper.LoadTexture(this.m_SaveFilePath);
                this.m_surfaceDescription = this.m_ImageTexture.GetLevelDescription(0);

                int width  = this.ClientSize.Width;
                int height = this.ClientSize.Height;

                if (this.ClientSize.Width == 0)
                {
                    width = this.m_surfaceDescription.Width;
                }
                if (this.ClientSize.Height == 0)
                {
                    height = this.m_surfaceDescription.Height;
                }

                if (this.ParentWidget is Form && this.SizeParentToImage)
                {
                    Form parentForm = (Form)this.ParentWidget;
                    parentForm.ClientSize = new System.Drawing.Size(width, height + parentForm.HeaderHeight);
                }
                else if (this.SizeParentToImage)
                {
                    this.ParentWidget.ClientSize = new System.Drawing.Size(width, height);
                }


                this.ClientSize        = new System.Drawing.Size(width, height);
                this.m_currentImageUri = this.m_ImageUri;

                this.IsLoaded    = true;
                this.isUpdating  = false;
                this.displayText = null;
                if (this.m_RefreshTime == 0 && this.m_RefreshTimer.Enabled)
                {
                    this.m_RefreshTimer.Stop();
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
Example #2
0
        public override void Initialize(DrawArgs drawArgs)
        {
            if (this.m_polygonFeature == null)
            {
                double offset = 0.02;
                Point3d[] points = new Point3d[4];

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

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

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

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

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

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

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

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

            if (savedFlagFile.Exists)
            {
                try
                {
                    this.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.");
                    
                    Net.WebDownload download = new Net.WebDownload(this.m_imageUri);
                    download.DownloadFile(savedFlagFile.FullName);
                    download.Dispose();
                    savedFlagFile.Refresh();
                }
                catch
                {
                    FileStream fs = placeHolderFile.Create();
                    fs.Close();
                    fs = null;
                    placeHolderFile.Refresh();
                }

                if (savedFlagFile.Exists)
                {
                    this.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);
            }

            this.UpdateVertices();
            this.isInitialized = true;
        }