private void compareRefreshLists(RenderableObjectList newList, RenderableObjectList curList) { ArrayList addList = new ArrayList(); ArrayList delList = new ArrayList(); foreach (RenderableObject newObject in newList.ChildObjects) { bool foundObject = false; foreach (RenderableObject curObject in curList.ChildObjects) { string xmlSource = curObject.MetaData["XmlSource"] as string; if (xmlSource != null && xmlSource == this.m_DataSource && newObject.Name == curObject.Name) { foundObject = true; this.UpdateRenderable(curObject, newObject); break; } } if (!foundObject) { addList.Add(newObject); } } foreach (RenderableObject curObject in curList.ChildObjects) { bool foundObject = false; foreach (RenderableObject newObject in newList.ChildObjects) { string xmlSource = newObject.MetaData["XmlSource"] as string; if (xmlSource != null && xmlSource == this.m_DataSource && newObject.Name == curObject.Name) { foundObject = true; break; } } if (!foundObject) { string src = (string)curObject.MetaData["XmlSource"]; if (src != null || src == this.m_DataSource) { delList.Add(curObject); } } } foreach (RenderableObject o in addList) { curList.Add(o); } foreach (RenderableObject o in delList) { curList.Remove(o); } }
/// <summary> /// Return a list of all direct and indirect children that match the given name and/or object type. /// </summary> /// <example> Get all QuadTileSets defined in this world: /// <code> /// RenderableObjectList allQTS = CurrentWorld.RenderableObjects.GetObjects(null, typeof(QuadTileSet)); /// </code></example> /// <param name="name">The name of the <c>RenderableObject</c> to search for, or <c>null</c> if any name should match.</param> /// <param name="objectType">The object type to search for, or <c>null</c> if any type should match.</param> /// <returns>A list of all <c>RenderableObject</c>s that match the given search criteria (may be empty), or <c>null</c> if an error occurred.</returns> public virtual RenderableObjectList GetObjects(string name, Type objectType) { RenderableObjectList result = new RenderableObjectList("results"); this.m_childrenRWLock.AcquireReaderLock(Timeout.Infinite); try { foreach (RenderableObject ro in this.m_children) { if (ro.GetType() == typeof(RenderableObjectList)) { RenderableObjectList sub = ro as RenderableObjectList; RenderableObjectList subres = sub.GetObjects(name, objectType); foreach (RenderableObject hit in subres.ChildObjects) { result.Add(hit); } } if (ro.Name.Equals(name) && ((objectType == null) || (ro.GetType() == objectType))) { result.Add(ro); } } } catch { result = null; } finally { this.m_childrenRWLock.ReleaseReaderLock(); } return(result); }
/// <summary> /// Save a subset of the LM to a file. /// </summary> /// <param name="ro">RenderableObjectList to save</param> /// <param name="file">Location for output</param> public static void SaveAs(RenderableObject ro, string file) { XmlDocument worldDoc = new XmlDocument(); worldDoc.AppendChild((worldDoc.CreateXmlDeclaration("1.0", "utf-8", null))); if (ro is RenderableObjectList) { //worldDoc.AppendChild(saveLayer((RenderableObjectList)ro, worldDoc)); worldDoc.AppendChild(ro.ToXml(worldDoc)); } else { RenderableObjectList rol = new RenderableObjectList("Saved"); rol.Add(ro); worldDoc.AppendChild(saveLayer(rol, worldDoc)); } worldDoc.Save(file); }
/// <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 { WorldWind.Net.WebDownload download = new WorldWind.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 { 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], ParentApplication.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 = double.Parse(lineParts[i], System.Globalization.CultureInfo.InvariantCulture); fieldHash.Add(headers[i], value); } 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(); ParentApplication.WorldWindow.CurrentWorld.RenderableObjects.Add(m_wavingFlagsList); }
/// <summary> /// Add a child object to this layer. If the new object has the same name as an existing object in this /// ROL it gets a number appended. If the new object is a ROL and there was already a ROL with the same /// name then the children of the new ROL gets added to the old ROL. /// /// Not sure who uses this but the functionality was kept this way. /// </summary> public virtual void Add(RenderableObject ro) { ro.ParentList = this; RenderableObjectList dupList = null; RenderableObject duplicate = null; // We get a write lock here because if you get a reader lock and then upgrade // the data can change on us before we get the write lock. // // This is somewhat unfortunate since we spend a bit of time going through the // child list. // // if we can't get the writer lock in 2 seconds something is probably borked if (this.GetWriterLock(200)) { try { // find duplicate names foreach (RenderableObject childRo in this.m_children) { if (childRo is RenderableObjectList && ro is RenderableObjectList && childRo.Name == ro.Name) { dupList = (RenderableObjectList)childRo; break; } else if (childRo.Name == ro.Name) { duplicate = childRo; break; } } // if we have two ROLs with the same name, don't rename the new ROL but add the children of the new ROL to the // existing ROL. if (dupList != null) { RenderableObjectList rol = (RenderableObjectList)ro; foreach (RenderableObject childRo in rol.ChildObjects) { dupList.Add(childRo); } } else { // Try to find an unused number for this name if (duplicate != null) { for (int i = 1; i < 1000; i++) { ro.Name = string.Format("{0} [{1}]", duplicate.Name, i); bool found = false; foreach (RenderableObject childRo in this.m_children) { if (childRo.Name == ro.Name) { found = true; break; } } if (!found) { break; } } } // Add the new child this.m_children.Add(ro); // Resort during the next update // NeedsSort = true; } } finally { this.m_childrenRWLock.ReleaseWriterLock(); } } else { MessageBox.Show("Unable to add new object " + ro.Name); } }