コード例 #1
0
		/// <summary>
		/// Adds an image to the animation list
		/// </summary>
		private void AddAnimationFrame(WMSDownload dl)
		{
			// Make sure we're on the right thread
			if( InvokeRequired ) 
			{
				// run asynchronously
				AddAnimationFrameDelegate dlgt =
					new AddAnimationFrameDelegate(AddAnimationFrame);
				this.BeginInvoke(dlgt, new object[] { dl });
				return;
			}

			if(this.currentlyAnimatingNode==null)
				return;

			lock(this.animationFrames.SyncRoot) 
			{
				this.animationFrames.Add(dl);
				if(this.animationFrames.Count != 1 && 
					this.progressBarTotalProgress.Value != this.progressBarTotalProgress.Maximum) 
				{
					this.progressBarTotalProgress.Value = this.animationFrames.Count;
					WMSLayer curLayer = (WMSLayer)this.currentlyAnimatingNode.Tag;
					if(curLayer.dates != null)
						this.progressBarTotalProgress.Maximum = curLayer.dates.Length;
				}
			}
		}
コード例 #2
0
		private void downloadLayer(WMSLayer layer, string curDate)
		{
			bool cancel = (this.downloadState == DownloadState.Cancel);
			if(cancel)
				return;

			string fileName = "Default";
			string time="";
			if(curDate != null)
			{
				time = "&time=" + curDate;
				fileName = curDate.Replace(":","");
			}

			string layerPath = 	CacheDirectory;
			if(layer.Name!=null)
				layerPath = Path.Combine( CacheDirectory, layer.Name );

			const string fileType = "png";
			string url = AnimatedEarthManager.ServerUrl+ 
				"?service=" + this.serviceName +
				"&version=" + WmsVersion + 
				"&request=GetMap" + 
				"&layers=" + layer.Name + 
				"&format=image/png" + 
				"&width=" + (layer.Width != 0 ? layer.Width.ToString(CultureInfo.InvariantCulture) : "1024") + 
				"&height=" + (layer.Height != 0 ? layer.Height.ToString(CultureInfo.InvariantCulture) : "512") + 
				time +
				"&crs=" + layer.crs +
				"&bbox=" + String.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", layer.west, layer.south, layer.east, layer.north);
			WMSDownload wmsDownload = new WMSDownload( url );
			wmsDownload.Date = curDate;
			wmsDownload.Title = layer.Title;
			wmsDownload.West = layer.west;
			wmsDownload.South = layer.south;
			wmsDownload.East = layer.east;
			wmsDownload.North = layer.north;

			// Use fast dds format if available
			wmsDownload.SavedFilePath = Path.Combine( layerPath, fileName) + ".dds";
			if(File.Exists(wmsDownload.SavedFilePath)) 
			{
				AddAnimationFrame(wmsDownload);
				return;
			}

			// Or try the original format from server
			wmsDownload.SavedFilePath = Path.Combine(layerPath, fileName) + "." + fileType;
			if(File.Exists(wmsDownload.SavedFilePath)) 
			{
				AddAnimationFrame(wmsDownload);
				return;
			}

			// File wasn't available locally - queue it for download
			lock(this.downloadQueue.SyncRoot) 
			{
				this.downloadQueue.Enqueue(wmsDownload);
			}
		}
コード例 #3
0
		/// <summary>
		/// Download thread runs this function.
		/// </summary>
		private void Downloader() 
		{
			while(true)
			{
				if(this.animationState == AnimationState.Pending)
				{
					Thread.Sleep(100);
					continue;
				}

				lock(this.downloadQueue)
				{
					if(this.downloadQueue.Count <= 0)
					{
						Thread.Sleep(100);
						continue;
					}
			
					this.wmsDownload = (WMSDownload)this.downloadQueue.Dequeue();
				}

				if(File.Exists(wmsDownload.SavedFilePath)) 
				{
					AddAnimationFrame(wmsDownload);
					return;
				}

				// Download
				try
				{
					this.downloadState = DownloadState.Downloading;
					updateStatusBar( string.Format( CultureInfo.CurrentCulture,
						"Downloading {0} ({1}/{2})",
						wmsDownload.Date,
						this.animationFrames.Count+1,
						this.currentlySelectedLayer.AnimationFrameCount ) );
				
					using( WebDownload dl = new WebDownload( wmsDownload.Url) )
					{
						dl.DownloadType = DownloadType.Wms;
						dl.ProgressCallback += new DownloadProgressHandler(updateCurrentProgressBar);
						dl.DownloadFile(wmsDownload.SavedFilePath);
					}
					Download_CompleteCallback(wmsDownload);
				}
				catch(ThreadAbortException)
				{
					// Normal shutdown
				}
				catch(Exception caught)
				{
					updateStatusBar(caught.Message);
					// Abort download.
					return;
				}
			}
		}
コード例 #4
0
		private void Download_CompleteCallback(WMSDownload wdl) 
		{
			// Not running on UI thread
			try 
			{
				updateStatusBar( "Converting: " + wdl.Date );
				string srcPath = wdl.SavedFilePath;

				// Convert to DDS 
				
/*			// TODO: Investigate whether conversion really improves playback speed.
				wdl.SavedFilePath = Path.Combine(
					Path.GetDirectoryName(wdl.SavedFilePath),
					Path.GetFileNameWithoutExtension(wdl.SavedFilePath)) + ".dds";
				Directory.CreateDirectory(Path.GetDirectoryName(wdl.SavedFilePath));
				ImageHelper.ConvertToDxt3(srcPath, wdl.SavedFilePath,this.worldWindow.DrawArgs.device, 
					!WorldWindow.World.Settings.KeepOriginalSvsImages);
*/
				AddAnimationFrame(wdl);
				updateStatusBar( "" );
				this.downloadState = DownloadState.Pending;
			}
			catch(Exception caught) 
			{
				this.PauseAnimation();
				this.worldWindow.Caption = caught.Message;
				updateStatusBar( caught.Message );
				Thread.Sleep(600);
			}
		}
コード例 #5
0
ファイル: WMSBrowser.cs プロジェクト: jpespartero/WorldWind
		public ImageLayerInfo( WMSDownload dl )
		{
			this.Id = dl.Name + "-" + Path.GetFileName(dl.SavedFilePath);
			this.Description = dl.Title;
			this.ImageFilePath = dl.SavedFilePath + ".dds";
			this.North = (float)dl.North;
			this.South = (float)dl.South;
			this.West = (float)dl.West;
			this.East = (float)dl.East;
		}
コード例 #6
0
ファイル: WMSBrowser.cs プロジェクト: jpespartero/WorldWind
		public WMSDownload GetWmsRequest( string dateString, 
			WMSLayerStyle curStyle,
			decimal north,
			decimal south,
			decimal west,
			decimal east,
			string cacheDirectory)
		{
			string url =	GetWMSRequestUrl(dateString,
				(curStyle != null ? curStyle.name : null),
				north,
				south,
				west,
				east);

			WMSDownload wmsDownload = new WMSDownload( url );
		
			wmsDownload.North = north;
			wmsDownload.South = south;
			wmsDownload.West = west;
			wmsDownload.East =  east;

			//fix widening errors from conversion of float to decimal for upDown controls
			// TODO: Is this widening thing needed anymore?
			if(this._west > this._east)
			{
				if(wmsDownload.West > this._west)
					wmsDownload.West = this._west;
				if(wmsDownload.East < this._east)
					wmsDownload.East = this._east;
			}
			else
			{
				if(wmsDownload.West < this._west)
					wmsDownload.West = this._west;

				if(wmsDownload.East > this._east)
					wmsDownload.East = this._east;
			}

			if(wmsDownload.North > this._north)
				wmsDownload.North = this._north;
			if(wmsDownload.South < this._south)
				wmsDownload.South = this._south;

			wmsDownload.Title = this._title;
			if(curStyle != null)
				wmsDownload.Title += " (" + curStyle.title + ")";
			
			string path = Path.Combine( cacheDirectory , Path.Combine( 
				this._parentWMSList.Name,
				this._name + (curStyle != null ? curStyle.name : "")));	
			if(dateString!=null && dateString.Length>0)
			{
				wmsDownload.SavedFilePath = Path.Combine( path, dateString.Replace(":",""));
				wmsDownload.Title += "\n" + dateString;
			}
			else
				wmsDownload.SavedFilePath = Path.Combine( path, "Default" );	
			return wmsDownload;
		}
コード例 #7
0
ファイル: WMSBrowser.cs プロジェクト: jpespartero/WorldWind
		private void EnqueueDownload(WMSDownload dl)
		{
			this.downloadQueue.Enqueue(dl);
			StartDownloadThread();
		}
コード例 #8
0
ファイル: WMSBrowser.cs プロジェクト: jpespartero/WorldWind
		/// <summary>
		/// Convert if requested and prepare downloaded data for display
		/// </summary>
		private void ProcessDownloadedImage(WMSDownload wdl, Stream dataStream)
		{
			try
			{
				string ddsFile = wdl.SavedFilePath + ".dds";
				if( wdl.Date.Length>0)
					UpdateStatusBar( "Converting " + wdl.Date );
				else
					UpdateStatusBar( "Converting... " );
				Directory.CreateDirectory(Path.GetDirectoryName(wdl.SavedFilePath));
				if (dataStream.Length==0)
					throw new WebException("Server returned no data.");
				ImageHelper.ConvertToDxt3(dataStream, ddsFile );
				if(this.animationState == AnimationState.Cancel || animationState == AnimationState.Stop)
					return;
		
				ImageLayerInfo imageLayerInfo = new ImageLayerInfo(wdl);
				imageLayerInfo.Save(wdl.SavedFilePath + ".wwi");
				lock(this.animationFrames.SyncRoot)
					animationFrames.Add(imageLayerInfo);
				
				if(this.animationState == AnimationState.Cancel || this.animationState == AnimationState.Stop)
					return;

				UpdateStatusBar( "" );
			}
			catch(Exception caught)
			{
				this.worldWindow.Caption = caught.Message;
				Log.Write( caught );
			}
		}
コード例 #9
0
ファイル: WMSBrowser.cs プロジェクト: jpespartero/WorldWind
		private bool isCachedFileBoundsAvailable(WMSDownload cachedDownloadInfo)
		{
			if(cachedDownloadInfo.North == this.numericUpDownNorth.Value && 
				cachedDownloadInfo.South == this.numericUpDownSouth.Value &&
				cachedDownloadInfo.West == this.numericUpDownWest.Value &&
				cachedDownloadInfo.East == this.numericUpDownEast.Value)
				return true;
			else
				return false;
		}