private void updateList() { if (this.isExpanded) { RenderableObjectList rol = (RenderableObjectList)this.m_renderableObject; for (int i = 0; i < rol.ChildObjects.Count; i++) { RenderableObject childObject = (RenderableObject)rol.ChildObjects[i]; if (i >= this.m_subItems.Count) { LayerMenuItem newItem = new LayerMenuItem(this.m_parent, childObject); this.m_subItems.Add(newItem); } else { LayerMenuItem curItem = (LayerMenuItem)this.m_subItems[i]; if (curItem != null && curItem.RenderableObject != null && childObject != null && !curItem.RenderableObject.Name.Equals(childObject.Name)) { this.m_subItems.Insert(i, new LayerMenuItem(this.m_parent, childObject)); } } } int extraItems = this.m_subItems.Count - rol.ChildObjects.Count; if (extraItems > 0) { this.m_subItems.RemoveRange(rol.ChildObjects.Count, extraItems); } } }
private void SetLayerOpacity(string category, string name, float opacity, RenderableObject ro) { foreach (string key in ro.MetaData.Keys) { if (String.Compare(key, category, true) == 0) { if (ro.MetaData[key].GetType() == typeof(String)) { string curValue = ro.MetaData[key] as string; if (String.Compare(curValue, name, true) == 0) { ro.Opacity = (byte)(255 * opacity); } } break; } } RenderableObjectList rol = ro as RenderableObjectList; if (rol != null) { foreach (RenderableObject childRo in rol.ChildObjects) { SetLayerOpacity(category, name, opacity, childRo); } } }
/// <summary> /// 初始化一个 <see cref= "T:WorldWind.World"/> 新实例. /// </summary> /// <param name="name"></param> /// <param name="position"></param> /// <param name="orientation"></param> /// <param name="equatorialRadius"></param> /// <param name="cacheDirectory"></param> /// <param name="terrainAccessor"></param> public World(string name, Vector3 position, Quaternion orientation, double equatorialRadius, string cacheDirectory, TerrainAccessor terrainAccessor) : base(name, position, orientation) { this._equatorialRadius = equatorialRadius; this._terrainAccessor = terrainAccessor; this._renderableObjects = new RenderableObjectList(this.Name); this.MetaData.Add("CacheDirectory", cacheDirectory); }
private void savewmsbutton_Click(object sender, EventArgs e) { string wmslayerset = "<LayerSet Name=\"" + textBox3.Text + "\" ShowOnlyOneLayer=\"false\" ShowAtStartup=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"LayerSet.xsd\">\n"; wmslayerset += ParseNodeChildren(treeOgcCaps.Nodes[0], UsernameTextBox.Text, PasswordTextBox.Text); wmslayerset += "</LayerSet>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(wmslayerset); string xmlFileName = textBox1.Text + ".xml"; string wmsSave = Path.Combine( Path.Combine(MainApplication.Settings.ConfigPath, worldWindow.CurrentWorld.ToString()), xmlFileName); try { doc.Save(wmsSave); } catch (System.Xml.XmlException ex) { MessageBox.Show("Couldn't write \"" + wmsSave + "\":\n\n" + ex.Message); } RenderableObjectList layers = ConfigurationLoader.getRenderableFromLayerFile(wmsSave, worldWindow.CurrentWorld, worldWindow.Cache); worldWindow.CurrentWorld.RenderableObjects.Add(layers); }
private void AddLayerMenuButtons(WorldWindow ww, RenderableObject ro) { if (ro.MetaData.Contains("ToolBarImagePath")) { string imagePath = Path.Combine(PluginEngineGlobal.DirectoryPath, (string)ro.MetaData["ToolBarImagePath"]); if (File.Exists(imagePath)) { LayerShortcutMenuButton button = new LayerShortcutMenuButton(imagePath, ro); //HACK: Temporary fix if (ro.Name == "Placenames") { button.SetPushed(World.Settings.ShowPlacenames); } if (ro.Name == "Boundaries") { button.SetPushed(World.Settings.ShowBoundaries); } } } if (ro.GetType() == typeof(RenderableObjectList)) { RenderableObjectList rol = (RenderableObjectList)ro; foreach (RenderableObject child in rol.ChildObjects) { AddLayerMenuButtons(ww, child); } } }
//TODO: Quadtiles Sets and indeed any layer may be sourced //from multiple XML files and merged at runtime. No track //of the source XML's is kept. Merged XML's can be written //back to the original config load point(causing duplicates) //or to Application Data folder. Important design issues here //need to be decided on.] //TODO: Serialize "ExtendedInformation" nodes? What is that for anyway? /// <summary> /// Serializes Renderable Object Lists to LayersSets at the top level /// </summary> /// <param name="layerSet">Layerset Renderable Object to be serialized</param> /// <param name="worldDoc">World Document to which node is added</param> /// <returns>Node for Root Layerset</returns> private static XmlNode saveLayerSet(RenderableObjectList layerSet, XmlDocument worldDoc) { XmlNode layerSetNode = worldDoc.CreateElement("LayerSet"); // good default values? XmlAttribute name = worldDoc.CreateAttribute("Name"); name.Value = "LayerSet"; XmlAttribute showAtStartup = worldDoc.CreateAttribute("ShowAtStartup"); showAtStartup.Value = "true"; XmlAttribute showOnlyOneLayer = worldDoc.CreateAttribute("ShowOnlyOneLayer"); showOnlyOneLayer.Value = "true"; XmlAttribute xsi = worldDoc.CreateAttribute("xmlns:xsi"); xsi.Value = "http://www.w3.org/2001/XMLSchema-instance"; XmlAttribute xsi2 = worldDoc.CreateAttribute("xsi:noNamespaceSchemaLocation"); xsi2.Value = "LayerSet.xsd"; layerSetNode.Attributes.Append(name); layerSetNode.Attributes.Append(showAtStartup); layerSetNode.Attributes.Append(showOnlyOneLayer); layerSetNode.Attributes.Append(xsi); layerSetNode.Attributes.Append(xsi2); foreach (RenderableObject ro in layerSet.ChildObjects) { layerSetNode.AppendChild(ro.ToXml(worldDoc)); } return(layerSetNode); }
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> /// Unloads our plugin /// </summary> public override void Unload() { if (m_wavingFlagsList != null) { ParentApplication.WorldWindow.CurrentWorld.RenderableObjects.Remove(m_wavingFlagsList.Name); m_wavingFlagsList.Dispose(); m_wavingFlagsList = null; } }
public override void Dispose() { SaveRenderableStates(RenderableObjects); if (this.RenderableObjects != null) { this.RenderableObjects.Dispose(); this.RenderableObjects = null; } if (_WorldSurfaceRenderer != null) { _WorldSurfaceRenderer.Dispose(); } }
private void resetQuadTileSetCache(RenderableObject ro) { if (ro.IsOn && ro is QuadTileSet) { QuadTileSet qts = (QuadTileSet)ro; qts.ResetCacheForCurrentView(worldWindow.DrawArgs.WorldCamera); } else if (ro is RenderableObjectList) { RenderableObjectList rol = (RenderableObjectList)ro; foreach (RenderableObject curRo in rol.ChildObjects) { resetQuadTileSetCache(curRo); } } }
private void SaveRenderableStates(RenderableObjectList rol) { SaveRenderableState(rol); foreach (RenderableObject ro in rol.ChildObjects) { if (ro is RenderableObjectList) { RenderableObjectList childRol = (RenderableObjectList)ro; SaveRenderableStates(childRol); } else { SaveRenderableState(ro); } } }
// // REMOVED because we no longer ever render all ROs in a a ROL without explicitly checking // render priority anyway. // /// <summary> /// Sorts the children list according to priority - ONLY called in worker thread (in Update()) /// </summary> //private void SortChildren() //{ // int index = 0; // m_childrenRWLock.AcquireWriterLock(Timeout.Infinite); // try // { // while (index + 1 < m_children.Count) // { // RenderableObject a = (RenderableObject)m_children[index]; // RenderableObject b = (RenderableObject)m_children[index + 1]; // if (a.RenderPriority > b.RenderPriority) // { // // Swap // m_children[index] = b; // m_children[index + 1] = a; // index = 0; // continue; // } // index++; // } // } // finally // { // m_childrenRWLock.ReleaseWriterLock(); // m_needsSort = false; // } //} private void UpdateRenderable(RenderableObject oldRenderable, RenderableObject newRenderable) { if (oldRenderable is Icon && newRenderable is Icon) { Icon oldIcon = (Icon)oldRenderable; Icon newIcon = (Icon)newRenderable; oldIcon.SetPosition((float)newIcon.Latitude, (float)newIcon.Longitude, (float)newIcon.Altitude); } else if (oldRenderable is RenderableObjectList && newRenderable is RenderableObjectList) { RenderableObjectList oldList = (RenderableObjectList)oldRenderable; RenderableObjectList newList = (RenderableObjectList)newRenderable; this.compareRefreshLists(newList, oldList); } }
/// <summary> /// Enables layer with specified name /// </summary> /// <returns>False if layer not found.</returns> public virtual bool Enable(string name) { if (name == null || name.Length == 0) { return(true); } string lowerName = name.ToLower(); bool result = false; this.m_childrenRWLock.AcquireReaderLock(Timeout.Infinite); try { foreach (RenderableObject ro in this.m_children) { if (ro.Name.ToLower() == lowerName) { ro.IsOn = true; result = true; break; } RenderableObjectList rol = ro as RenderableObjectList; if (rol == null) { continue; } // Recurse down if (rol.Enable(name)) { rol.isOn = true; result = true; break; } } } 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); }
public virtual void TurnOffAllChildren() { this.m_childrenRWLock.AcquireReaderLock(Timeout.Infinite); try { foreach (RenderableObject ro in this.m_children) { ro.IsOn = false; if (ro is RenderableObjectList) { RenderableObjectList list = ro as RenderableObjectList; list.TurnOffAllChildren(); } } } finally { this.m_childrenRWLock.ReleaseReaderLock(); } }
private void btnLoad_Click(object sender, EventArgs e) { if (tbFileName.Text == "") { return; } if (tbFileName.Text.Trim().StartsWith(@"http://")) { mainapp.QuickInstall(tbFileName.Text); } else { if (!File.Exists(tbFileName.Text)) { MessageBox.Show(tbFileName.Text + " does not exist", "Load error"); return; } if (tbFileName.Text.EndsWith(".xml") && !chbLoadPermanently.Checked) { RenderableObjectList layer = ConfigurationLoader.getRenderableFromLayerFile(tbFileName.Text, mainapp.WorldWindow.CurrentWorld, mainapp.WorldWindow.Cache); mainapp.WorldWindow.CurrentWorld.RenderableObjects.Add(layer); MessageBox.Show("File loaded."); } else { mainapp.QuickInstall(tbFileName.Text); } } this.Close(); }
private void m_RefreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (!this.hasSkippedFirstRefresh) { this.hasSkippedFirstRefresh = true; return; } try { string dataSource = this.m_DataSource; RenderableObjectList newList = ConfigurationLoader.getRenderableFromLayerFile(dataSource, this.m_ParentWorld, this.m_Cache, false); if (newList != null) { this.compareRefreshLists(newList, this); } } catch (Exception ex) { Log.Write(ex); } }
/// <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> /// 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); } }
/// <summary> /// Permanently delete the layer /// </summary> public virtual void Delete() { RenderableObjectList list = this.ParentList; string xmlConfigFile = (string)this.MetaData["XmlSource"]; if (this.ParentList.Name == "Earth" & xmlConfigFile != null) { string message = "Permanently delete layer '" + this.Name + "' and rename its .xml config file to .bak?"; if (DialogResult.Yes != MessageBox.Show(message, "Delete layer", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)) { return; } //throw new Exception("Delete cancelled."); //MessageBox.Show("Checking xml source of " + this.Name); if (xmlConfigFile.Contains("http")) { throw new Exception("Can't delete network layers."); } //MessageBox.Show("Found " + xmlConfigFile); if (File.Exists(xmlConfigFile.Replace(".xml", ".bak"))) { //MessageBox.Show("Deleting old .bak"); File.Delete(xmlConfigFile.Replace(".xml", ".bak")); } //MessageBox.Show("Moving old .xml"); File.Move(xmlConfigFile, xmlConfigFile.Replace(".xml", ".bak")); //MessageBox.Show("File backed up, now removing from LM"); this.ParentList.Remove(this); //World.RenderableObjects.Remove(this); //MessageBox.Show("Removed"); } else if (xmlConfigFile == null) { string message = "Delete plugin layer '" + this.Name + "'?\n\nThis may cause problems for a running plugin that expects the layer to be\nthere. Restart the plugin in question to replace the layer after deleting."; if (DialogResult.Yes != MessageBox.Show(message, "Delete layer", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)) { return; } //throw new Exception("Delete cancelled."); this.ParentList.Remove(this); } else { throw new Exception("Can't delete this sub-item from the layer manager. Try deleting the top-level entry for this layer."); } // Needs re-thinking... /* * string xmlConfigFile = (string)MetaData["XmlSource"]; * //MessageBox.Show(xmlConfigFile); * if(xmlConfigFile == null) * xmlConfigFile = (string)ParentList.MetaData["XmlSource"]; * * if(xmlConfigFile == null || !File.Exists(xmlConfigFile)) * throw new ApplicationException("Error deleting layer."); * * XmlDocument doc = new XmlDocument(); * doc.Load(xmlConfigFile); * * XmlNodeList list; * XmlElement root = doc.DocumentElement; * list = root.SelectNodes("//ChildLayerSet[@Name='" + namestring + "'] || //*[Name='" + namestring + "']"); * MessageBox.Show("Checked childlayersets, returned " + list[0].ToString()); * * ParentList.Remove(Name); * MessageBox.Show("Removed " + Name + ", now changing " + xmlConfigFile); * * if (list != null) * MessageBox.Show("Removing " + list[0].ToString() + " from xml"); * * list[0].ParentNode.RemoveChild(list[0]); * MessageBox.Show("node removed, now saving file"); * * if (File.Exists(xmlConfigFile.Replace(".xml", ".bak"))) * { * MessageBox.Show("Deleting old .bak"); * File.Delete(xmlConfigFile.Replace(".xml", ".bak")); * * } * MessageBox.Show("Moving old .xml"); * File.Move(xmlConfigFile, xmlConfigFile.Replace(".xml",".bak")); * * MessageBox.Show("Saving new xml"); * doc.Save(xmlConfigFile); */ }
public int Render(DrawArgs drawArgs, int x, int y, int yOffset, int width, int height, SharpDX.Direct3D9.Font drawingFont, SharpDX.Direct3D9.Font wingdingsFont, SharpDX.Direct3D9.Font worldwinddingsFont, LayerMenuItem mouseOverItem) { if (this.ParentControl == null) { this.ParentControl = drawArgs.parentControl; } this._x = x; this._y = y + yOffset; this._width = width; int consumedHeight = 20; Rectangle textRect = drawingFont.MeasureString(null, this.m_renderableObject.Name, FontDrawFlags.SingleLine, Color.White.ToArgb()); consumedHeight = textRect.Height; if (this.m_renderableObject.Description != null && this.m_renderableObject.Description.Length > 0 && !(this.m_renderableObject is Icon)) { SizeF rectF = DrawArgs.Graphics.MeasureString(this.m_renderableObject.Description, drawArgs.defaultSubTitleFont, width - (this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset) ); consumedHeight += (int)rectF.Height + 15; } this.lastConsumedHeight = consumedHeight; // Layer manager client area height int totalHeight = height - y; this.updateList(); if (yOffset >= -consumedHeight) { // Part of item or whole item visible int color = this.m_renderableObject.IsOn ? this.itemOnColor : this.itemOffColor; if (mouseOverItem == this) { if (!this.m_renderableObject.IsOn) { // mouseover + inactive color (black) color = 0xff << 24; } MenuUtils.DrawBox(this.m_parent.ClientLeft, this._y, this.m_parent.ClientWidth, consumedHeight, 0, World.Settings.menuOutlineColor, drawArgs.device); } if (this.m_renderableObject is RenderableObjectList) { RenderableObjectList rol = (RenderableObjectList)this.m_renderableObject; if (!rol.DisableExpansion) { worldwinddingsFont.DrawText( null, (this.isExpanded ? "L" : "A"), new Rectangle(x + this._itemXOffset, this._y, this._expandArrowXSize, height), FontDrawFlags.SingleLine, color); } } string checkSymbol = null; if (this.m_renderableObject.ParentList != null && this.m_renderableObject.ParentList.ShowOnlyOneLayer) { // Radio check checkSymbol = this.m_renderableObject.IsOn ? "O" : "P"; } else { // Normal check checkSymbol = this.m_renderableObject.IsOn ? "N" : "F"; } worldwinddingsFont.DrawText( null, checkSymbol, new Rectangle( x + this._itemXOffset + this._expandArrowXSize, this._y, this._checkBoxXOffset, height), FontDrawFlags.NoClip, color); drawingFont.DrawText( null, this.m_renderableObject.Name, new Rectangle( x + this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset, this._y, width - (this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset), height), FontDrawFlags.SingleLine, color); if (this.m_renderableObject.Description != null && this.m_renderableObject.Description.Length > 0 && !(this.m_renderableObject is Icon)) { drawArgs.defaultSubTitleDrawingFont.DrawText( null, this.m_renderableObject.Description, new Rectangle( x + this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset, this._y + textRect.Height, width - (this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset), height), FontDrawFlags.WordBreak, Color.Gray.ToArgb()); } if (this.m_renderableObject.MetaData.Contains("InfoUri")) { Vector2[] underlineVerts = new Vector2[2]; underlineVerts[0].X = x + this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset; underlineVerts[0].Y = this._y + textRect.Height; underlineVerts[1].X = underlineVerts[0].X + textRect.Width; underlineVerts[1].Y = this._y + textRect.Height; MenuUtils.DrawLine(underlineVerts, color, drawArgs.device); } } if (this.isExpanded) { for (int i = 0; i < this.m_subItems.Count; i++) { int yRealOffset = yOffset + consumedHeight; if (yRealOffset > totalHeight) { // No more space for items break; } LayerMenuItem lmi = (LayerMenuItem)this.m_subItems[i]; consumedHeight += lmi.Render( drawArgs, x + this._subItemXIndent, y, yRealOffset, width - this._subItemXIndent, height, drawingFont, wingdingsFont, worldwinddingsFont, mouseOverItem); } } return(consumedHeight); }
private RenderableObject getRenderableObjectListFromLayerSet(World curWorld, LayerSet.Type_LayerSet curLayerSet, string layerSetFile)//ref TreeNode treeNode) { RenderableObjectList rol = null; // If the layer set has icons, use the icon list layer as parent if (curLayerSet.HasIcon()) { rol = new Icons(curLayerSet.Name.Value); rol.RenderPriority = RenderPriority.Icons; } else { rol = new RenderableObjectList(curLayerSet.Name.Value); } if (curLayerSet.HasShowOnlyOneLayer()) { rol.ShowOnlyOneLayer = curLayerSet.ShowOnlyOneLayer.Value; } // HACK: This should be part of the settings if (curLayerSet.Name.ToString().ToUpper() == "PLACENAMES") { rol.RenderPriority = RenderPriority.Placenames; } if (curLayerSet.HasExtendedInformation()) { if (curLayerSet.ExtendedInformation.HasToolBarImage()) { rol.MetaData.Add("ToolBarImagePath", curLayerSet.ExtendedInformation.ToolBarImage.Value); } } if (curLayerSet.HasImageLayer()) { for (int i = 0; i < curLayerSet.ImageLayerCount; i++) { LayerSet.Type_ImageLayer curImageLayerType = curLayerSet.GetImageLayerAt(i); // <TexturePath> could contain Url, relative path, or absolute path string imagePath = null; string imageUrl = null; if (curImageLayerType.TexturePath.Value.ToLower(System.Globalization.CultureInfo.InvariantCulture).StartsWith(("http://"))) { imageUrl = curImageLayerType.TexturePath.Value; } else { imagePath = curImageLayerType.TexturePath.Value; if (!Path.IsPathRooted(imagePath)) { imagePath = Path.Combine(PluginEngineGlobal.DirectoryPath, imagePath); } } int transparentColor = 0; if (curImageLayerType.HasTransparentColor()) { transparentColor = System.Drawing.Color.FromArgb( curImageLayerType.TransparentColor.Red.Value, curImageLayerType.TransparentColor.Green.Value, curImageLayerType.TransparentColor.Blue.Value).ToArgb(); } ImageLayer newImageLayer = new ImageLayer( curImageLayerType.Name.Value, curWorld, (float)curImageLayerType.DistanceAboveSurface.Value, imagePath, (float)curImageLayerType.BoundingBox.South.Value2.DoubleValue(), (float)curImageLayerType.BoundingBox.North.Value2.DoubleValue(), (float)curImageLayerType.BoundingBox.West.Value2.DoubleValue(), (float)curImageLayerType.BoundingBox.East.Value2.DoubleValue(), (byte)curImageLayerType.Opacity.Value, (curImageLayerType.TerrainMapped.Value ? curWorld.TerrainAccessor : null)); newImageLayer.ImageUrl = imageUrl; newImageLayer.TransparentColor = transparentColor; newImageLayer.IsOn = curImageLayerType.ShowAtStartup.Value; if (curImageLayerType.HasLegendImagePath()) { newImageLayer.LegendImagePath = curImageLayerType.LegendImagePath.Value; } if (curImageLayerType.HasExtendedInformation() && curImageLayerType.ExtendedInformation.HasToolBarImage()) { newImageLayer.MetaData.Add("ToolBarImagePath", Path.Combine(PluginEngineGlobal.DirectoryPath, curImageLayerType.ExtendedInformation.ToolBarImage.Value)); } rol.Add(newImageLayer); } } if (curLayerSet.HasQuadTileSet()) { for (int i = 0; i < curLayerSet.QuadTileSetCount; i++) { LayerSet.Type_QuadTileSet2 curQtsType = curLayerSet.GetQuadTileSetAt(i); } } if (curLayerSet.HasPathList()) { for (int i = 0; i < curLayerSet.PathListCount; i++) { LayerSet.Type_PathList2 newPathList = curLayerSet.GetPathListAt(i); PathList pl = new PathList( newPathList.Name.Value, curWorld, newPathList.MinDisplayAltitude.DoubleValue(), newPathList.MaxDisplayAltitude.DoubleValue(), PluginEngineGlobal.DirectoryPath + "//" + newPathList.PathsDirectory.Value, newPathList.DistanceAboveSurface.DoubleValue(), (newPathList.HasWinColorName() ? System.Drawing.Color.FromName(newPathList.WinColorName.Value) : System.Drawing.Color.FromArgb(newPathList.RGBColor.Red.Value, newPathList.RGBColor.Green.Value, newPathList.RGBColor.Blue.Value)), curWorld.TerrainAccessor); pl.IsOn = newPathList.ShowAtStartup.Value; if (newPathList.HasExtendedInformation() && newPathList.ExtendedInformation.HasToolBarImage()) { pl.MetaData.Add("ToolBarImagePath", Path.Combine(PluginEngineGlobal.DirectoryPath, newPathList.ExtendedInformation.ToolBarImage.Value)); } rol.Add(pl); } } if (curLayerSet.HasShapeFileLayer()) { for (int i = 0; i < curLayerSet.ShapeFileLayerCount; i++) { LayerSet.Type_ShapeFileLayer2 newShapefileLayer = curLayerSet.GetShapeFileLayerAt(i); Microsoft.DirectX.Direct3D.FontDescription fd = Global.GetLayerFontDescription(newShapefileLayer.DisplayFont); Microsoft.DirectX.Direct3D.Font font = worldWindow.DrawArgs.CreateFont(fd); ShapeLayer sp = new ShapeLayer( newShapefileLayer.Name.Value, curWorld, newShapefileLayer.DistanceAboveSurface.DoubleValue(), newShapefileLayer.MasterFilePath.Value, newShapefileLayer.MinimumViewAltitude.DoubleValue(), newShapefileLayer.MaximumViewAltitude.DoubleValue(), font, (newShapefileLayer.HasWinColorName() ? System.Drawing.Color.FromName(newShapefileLayer.WinColorName.Value) : System.Drawing.Color.FromArgb(newShapefileLayer.RGBColor.Red.Value, newShapefileLayer.RGBColor.Green.Value, newShapefileLayer.RGBColor.Blue.Value)), (newShapefileLayer.HasScalarKey() ? newShapefileLayer.ScalarKey.Value : null), (newShapefileLayer.HasShowBoundaries() ? newShapefileLayer.ShowBoundaries.Value : false), (newShapefileLayer.HasShowFilledRegions() ? newShapefileLayer.ShowFilledRegions.Value : false)); sp.IsOn = newShapefileLayer.ShowAtStartup.BoolValue(); if (newShapefileLayer.HasExtendedInformation() && newShapefileLayer.ExtendedInformation.HasToolBarImage()) { sp.MetaData.Add("ToolBarImagePath", Path.Combine(PluginEngineGlobal.DirectoryPath, newShapefileLayer.ExtendedInformation.ToolBarImage.Value)); } rol.Add(sp); } } if (curLayerSet.HasIcon()) { Icons icons = (Icons)rol; for (int i = 0; i < curLayerSet.IconCount; i++) { LayerSet.Type_Icon newIcon = curLayerSet.GetIconAt(i); string textureFullPath = newIcon.TextureFilePath.Value; if (textureFullPath.Length > 0 && !Path.IsPathRooted(textureFullPath)) { // Use absolute path to icon image textureFullPath = Path.Combine(PluginEngineGlobal.DirectoryPath, newIcon.TextureFilePath.Value); } WorldWind.Renderable.Icon ic = new WorldWind.Renderable.Icon( newIcon.Name.Value, (float)newIcon.Latitude.Value2.DoubleValue(), (float)newIcon.Longitude.Value2.DoubleValue(), (float)newIcon.DistanceAboveSurface.DoubleValue()); ic.TextureFileName = textureFullPath; ic.Width = newIcon.IconWidthPixels.Value; ic.Height = newIcon.IconHeightPixels.Value; ic.IsOn = newIcon.ShowAtStartup.Value; if (newIcon.HasDescription()) { ic.Description = newIcon.Description.Value; } if (newIcon.HasClickableUrl()) { ic.ClickableActionURL = newIcon.ClickableUrl.Value; } if (newIcon.HasMaximumDisplayAltitude()) { ic.MaximumDisplayDistance = (float)newIcon.MaximumDisplayAltitude.Value; } if (newIcon.HasMinimumDisplayAltitude()) { ic.MinimumDisplayDistance = (float)newIcon.MinimumDisplayAltitude.Value; } icons.Add(ic); } } if (curLayerSet.HasTiledPlacenameSet()) { for (int i = 0; i < curLayerSet.TiledPlacenameSetCount; i++) { LayerSet.Type_TiledPlacenameSet2 newPlacenames = curLayerSet.GetTiledPlacenameSetAt(i); string filePath = newPlacenames.PlacenameListFilePath.Value; if (!Path.IsPathRooted(filePath)) { filePath = Path.Combine(PluginEngineGlobal.DirectoryPath, filePath); } Microsoft.DirectX.Direct3D.FontDescription fd = Global.GetLayerFontDescription(newPlacenames.DisplayFont); TiledPlacenameSet tps = new TiledPlacenameSet( newPlacenames.Name.Value, curWorld, newPlacenames.DistanceAboveSurface.DoubleValue(), newPlacenames.MaximumDisplayAltitude.DoubleValue(), newPlacenames.MinimumDisplayAltitude.DoubleValue(), filePath, fd, (newPlacenames.HasWinColorName() ? System.Drawing.Color.FromName(newPlacenames.WinColorName.Value) : System.Drawing.Color.FromArgb(newPlacenames.RGBColor.Red.Value, newPlacenames.RGBColor.Green.Value, newPlacenames.RGBColor.Blue.Value)), (newPlacenames.HasIconFilePath() ? newPlacenames.IconFilePath.Value : null)); if (newPlacenames.HasExtendedInformation() && newPlacenames.ExtendedInformation.HasToolBarImage()) { tps.MetaData.Add("ToolBarImagePath", Path.Combine(PluginEngineGlobal.DirectoryPath, newPlacenames.ExtendedInformation.ToolBarImage.Value)); } tps.IsOn = newPlacenames.ShowAtStartup.Value; rol.Add(tps); } } if (curLayerSet.HasChildLayerSet()) { for (int i = 0; i < curLayerSet.ChildLayerSetCount; i++) { LayerSet.Type_LayerSet ls = curLayerSet.GetChildLayerSetAt(i); rol.Add(getRenderableObjectListFromLayerSet(curWorld, ls, layerSetFile)); } } rol.IsOn = curLayerSet.ShowAtStartup.Value; return(rol); }
public bool OnMouseUp(MouseEventArgs e) { if (e.Y < this._y) { // Above return(false); } if (e.Y <= this._y + 20) { if (e.X > this._x + this._itemXOffset && e.X < this._x + (this._itemXOffset + this._width) && e.Button == MouseButtons.Right) { this.m_parent.ShowContextMenu(e.X, e.Y, this); } if (e.X > this._x + this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset && e.X < this._x + (this._itemXOffset + this._width) && e.Button == MouseButtons.Left && this.m_renderableObject != null && this.m_renderableObject.MetaData.Contains("InfoUri")) { string infoUri = (string)this.m_renderableObject.MetaData["InfoUri"]; if (World.Settings.UseInternalBrowser || infoUri.StartsWith(@"worldwind://")) { SplitContainer sc = (SplitContainer)this.ParentControl.Parent.Parent; InternalWebBrowserPanel browser = (InternalWebBrowserPanel)sc.Panel1.Controls[0]; browser.NavigateTo(infoUri); } else { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = infoUri; psi.Verb = "open"; psi.UseShellExecute = true; psi.CreateNoWindow = true; Process.Start(psi); } } if (e.X > this._x + this._itemXOffset && e.X < this._x + (this._itemXOffset + this._expandArrowXSize) && this.m_renderableObject is RenderableObjectList) { RenderableObjectList rol = (RenderableObjectList)this.m_renderableObject; if (!rol.DisableExpansion) { this.isExpanded = !this.isExpanded; return(true); } } if (e.X > this._x + this._itemXOffset + this._expandArrowXSize && e.X < this._x + (this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset)) { if (!this.m_renderableObject.IsOn && this.m_renderableObject.ParentList != null && this.m_renderableObject.ParentList.ShowOnlyOneLayer) { this.m_renderableObject.ParentList.TurnOffAllChildren(); } this.m_renderableObject.IsOn = !this.m_renderableObject.IsOn; return(true); } } if (this.isExpanded) { foreach (LayerMenuItem lmi in this.m_subItems) { if (lmi.OnMouseUp(e)) { return(true); } } } return(false); }