예제 #1
0
        public void UpdateTexture(Device device, string textureFileName)
        {
            if ((textureFileName != null) && textureFileName.Length > 0)
            {
                if (textureFileName.ToLower().StartsWith("http://") && BaseSavePath != null)
                {
                    // download it
                    try
                    {
                        Uri uri = new Uri(textureFileName);

                        // Set the subdirectory path to the hostname and replace . with _
                        string savePath = uri.Host;
                        savePath = savePath.Replace('.', '_');

                        // build the save file name from the component pieces
                        savePath = BaseSavePath + @"\" + savePath + uri.AbsolutePath;
                        savePath = savePath.Replace('/', '\\');

                        // Offline check
                        if (!World.Settings.WorkOffline)
                        {
                            MFW3D.Net.WebDownload webDownload = new MFW3D.Net.WebDownload(textureFileName);
                            webDownload.DownloadType = MFW3D.Net.DownloadType.Unspecified;
                            webDownload.DownloadFile(savePath);
                        }

                        // reset the texture file name for later use.
                        textureFileName = savePath;
                    }
                    catch { }
                }
            }

            // Clear old texture - don't know if this is necessary so commented out for the moment
            //if (Texture != null)
            //{
            //    Texture.Dispose();
            //}

            if (ImageHelper.IsGdiSupportedImageFormat(textureFileName))
            {
                // Load without rescaling source bitmap
                using (Image image = ImageHelper.LoadImage(textureFileName))
                    LoadImage(device, image);
            }
            else
            {
                // Only DirectX can read this file, might get upscaled depending on input dimensions.
                Texture = ImageHelper.LoadIconTexture(textureFileName);
                // Read texture level 0 size
                using (Surface s = Texture.GetSurfaceLevel(0))
                {
                    SurfaceDescription desc = s.Description;
                    Width  = desc.Width;
                    Height = desc.Height;
                }
            }
        }
예제 #2
0
        public override void Initialize(DrawArgs drawArgs)
        {
            if (m_points == null)
            {
                isInitialized = true;
                return;
            }

            if (m_imageUri != null)
            {
                //load image
                if (m_imageUri.ToLower().StartsWith("http://"))
                {
                    string             savePath = string.Format("{0}\\image", ConfigurationLoader.GetRenderablePathString(this));
                    System.IO.FileInfo file     = new System.IO.FileInfo(savePath);

                    if (!file.Exists)
                    {
                        //Offline check
                        if (!World.Settings.WorkOffline)
                        {
                            MFW3D.Net.WebDownload download = new MFW3D.Net.WebDownload(m_imageUri);

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

                            download.DownloadFile(file.FullName, MFW3D.Net.DownloadType.Unspecified);
                        }
                    }

                    //file might not have downloaded.  Especially if we are offline
                    if (!file.Exists)
                    {
                        m_texture = ImageHelper.LoadTexture(file.FullName);
                    }
                    else
                    {
                        m_texture = null;
                    }
                }
                else
                {
                    m_texture = ImageHelper.LoadTexture(m_imageUri);
                }
            }

            UpdateVertices();

            isInitialized = true;
        }
예제 #3
0
        private void m_RefreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                if (isUpdating)
                {
                    return;
                }

                isUpdating = true;

                if (m_ImageUri == null)
                {
                    return;
                }

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

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

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

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

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

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

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

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

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

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


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

                IsLoaded    = true;
                isUpdating  = false;
                displayText = null;
                if (m_RefreshTime == 0 && m_RefreshTimer.Enabled)
                {
                    m_RefreshTimer.Stop();
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
예제 #4
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;
        }
예제 #5
0
        void WorldWindow_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }

            if (m_Form == null)
            {
                return;
            }

            if (!m_Form.Visible)
            {
                return;
            }

            if (m_Form.KeyLayer == null)
            {
                return;
            }

            QuadTileSet qts = m_Form.KeyLayer;

            MFW3D.Net.Wms.WmsImageStore wms = (MFW3D.Net.Wms.WmsImageStore)qts.ImageStores[0];

            string requestUrl = wms.ServerGetMapUrl;

            string[] layerNameParts = wms.WMSLayerName.Split('&');
            string   layerName      = layerNameParts[0];
            string   getMapParts    =
                requestUrl += "?QUERY_LAYERS=" + layerName + "&SERVICE=WMS&VERSION=" + wms.Version + "&REQUEST=GetFeatureInfo&SRS=EPSG:4326&FEATURE_COUNT=10&INFO_FORMAT=text/plain&EXCEPTIONS=text/plain";

            // From Servir-Viz...
            Angle  LowerLeftX;
            Angle  LowerLeftY;
            Angle  UpperRightX;
            Angle  UpperRightY;
            string minx, miny, maxx, maxy;

            char[] degreeChar = { '?' };

            int mouseX = e.X;
            int mouseY = e.Y;

            int queryBoxWidth  = 2 * queryBoxOffset + 1;
            int queryBoxHeight = 2 * queryBoxOffset + 1;

            int queryX = queryBoxOffset + 1;
            int queryY = queryBoxOffset + 1;

            drawArgs.WorldCamera.PickingRayIntersectionWithTerrain(mouseX - queryBoxOffset, mouseY + queryBoxOffset, out LowerLeftY, out LowerLeftX, drawArgs.CurrentWorld);
            drawArgs.WorldCamera.PickingRayIntersectionWithTerrain(mouseX + queryBoxOffset, mouseY - queryBoxOffset, out UpperRightY, out UpperRightX, drawArgs.CurrentWorld);

            //drawArgs.WorldCamera.PickingRayIntersectionWithTerrain(0, 0 + drawArgs.screenHeight, out LowerLeftY, out LowerLeftX, drawArgs.CurrentWorld);
            //drawArgs.WorldCamera.PickingRayIntersectionWithTerrain(drawArgs.screenWidth, 0, out UpperRightY, out UpperRightX, drawArgs.CurrentWorld);

            minx = LowerLeftX.ToString().Contains("NaN") ? "-180.0" : LowerLeftX.ToString().TrimEnd(degreeChar);
            miny = LowerLeftY.ToString().Contains("NaN") ? "-90.0" : LowerLeftY.ToString().TrimEnd(degreeChar);
            maxx = UpperRightX.ToString().Contains("NaN") ? "180.0" : UpperRightX.ToString().TrimEnd(degreeChar);
            maxy = UpperRightY.ToString().Contains("NaN") ? "90.0" : UpperRightY.ToString().TrimEnd(degreeChar);

            // request has to include a bbox and the requested pixel coords relative to that box...
            requestUrl += "&layers=" + wms.WMSLayerName;
            requestUrl += "&WIDTH=" + queryBoxWidth.ToString() + "&HEIGHT=" + queryBoxHeight.ToString();
            requestUrl += "&BBOX=" + minx + "," + miny + "," + maxx + "," + maxy;
            requestUrl += "&X=" + queryX.ToString() + "&Y=" + queryY.ToString();

            if (!World.Settings.WorkOffline)
            {
                MFW3D.Net.WebDownload dl = new MFW3D.Net.WebDownload(requestUrl);
                System.IO.FileInfo    fi = new System.IO.FileInfo("GetFeatureInfo_response.txt");
                dl.DownloadFile(fi.FullName);
                //dl.SavedFilePath = fi.FullName;
                //dl.BackgroundDownloadFile(GetFeatureDlComplete);


                if (World.Settings.UseInternalBrowser)
                {
                    SplitContainer          sc      = (SplitContainer)drawArgs.parentControl.Parent.Parent;
                    InternalWebBrowserPanel browser = (InternalWebBrowserPanel)sc.Panel1.Controls[0];
                    browser.NavigateTo(fi.FullName);
                }
                else
                {
                    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
                    psi.FileName        = fi.FullName;
                    psi.Verb            = "open";
                    psi.UseShellExecute = true;

                    psi.CreateNoWindow = true;
                    System.Diagnostics.Process.Start(psi);
                }
            }
        }
예제 #6
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);
        }