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 == m_DataSource && newObject.Name == curObject.Name) { foundObject = true; 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 == m_DataSource && newObject.Name == curObject.Name) { foundObject = true; break; } } if (!foundObject) { string src = (string)curObject.MetaData["XmlSource"]; if (src != null || src == m_DataSource) { delList.Add(curObject); } } } foreach (RenderableObject o in addList) { curList.Add(o); } foreach (RenderableObject o in delList) { curList.Remove(o); } }
private void updateNode(TreeNode tn) { RenderableObjectInfo roi = (RenderableObjectInfo)tn.Tag; roi.LastSpotted = System.DateTime.Now; if (tn.Checked != roi.Renderable.IsOn) { tn.Checked = roi.Renderable.IsOn; //treeView1.BeginInvoke(new UpdateCheckStateNodeDelegate(this.UpdateCheckStateNode), new object[] {tn, roi.Renderable.IsOn}); } if (roi.Renderable is MFW3D.Renderable.RenderableObjectList) { MFW3D.Renderable.RenderableObjectList rol = (MFW3D.Renderable.RenderableObjectList)roi.Renderable; for (int i = 0; i < rol.Count; i++) { MFW3D.Renderable.RenderableObject childRo = (MFW3D.Renderable.RenderableObject)rol.ChildObjects[i]; string absolutePath = GetAbsoluteRenderableObjectPath(childRo); TreeNode correctNode = (TreeNode)m_NodeHash[absolutePath]; if (correctNode == null) { correctNode = new TreeNode(childRo.Name); RenderableObjectInfo curRoi = new RenderableObjectInfo(); curRoi.Renderable = childRo; correctNode.Tag = curRoi; m_NodeHash.Add(absolutePath, correctNode); treeView1.BeginInvoke(new UpdateChildNodeDelegate(this.UpdateChildNodeTree), new object[] { tn, correctNode }); } updateNode(correctNode); } } }
// // 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; 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; m_childrenRWLock.AcquireReaderLock(Timeout.Infinite); try { foreach (RenderableObject ro in 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 { m_childrenRWLock.ReleaseReaderLock(); } return(result); }
public virtual void TurnOffAllChildren() { 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 { m_childrenRWLock.ReleaseReaderLock(); } }
/// <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; } if (xmlConfigFile.Contains("http")) { throw new Exception("Can't delete network layers."); } if (File.Exists(xmlConfigFile.Replace(".xml", ".bak"))) { File.Delete(xmlConfigFile.Replace(".xml", ".bak")); } File.Move(xmlConfigFile, xmlConfigFile.Replace(".xml", ".bak")); this.ParentList.Remove(this); } 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; } 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."); } }
private void m_RefreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (!hasSkippedFirstRefresh) { hasSkippedFirstRefresh = true; return; } try { string dataSource = m_DataSource; RenderableObjectList newList = ConfigurationLoader.getRenderableFromLayerFile(dataSource, m_ParentWorld, m_Cache, false); if (newList != null) { compareRefreshLists(newList, this); } } catch (Exception ex) { Log.Write(ex); } }
/// <summary> /// 返回直接或间接的对象,根据名字查询 /// </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"); 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 { m_childrenRWLock.ReleaseReaderLock(); } return(result); }
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) { 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 && m_renderableObject != null && m_renderableObject.MetaData.Contains("InfoUri")) { string infoUri = (string)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) && m_renderableObject is MFW3D.Renderable.RenderableObjectList) { MFW3D.Renderable.RenderableObjectList rol = (MFW3D.Renderable.RenderableObjectList)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 (!m_renderableObject.IsOn && m_renderableObject.ParentList != null && m_renderableObject.ParentList.ShowOnlyOneLayer) { m_renderableObject.ParentList.TurnOffAllChildren(); } m_renderableObject.IsOn = !m_renderableObject.IsOn; return(true); } } if (isExpanded) { foreach (LayerMenuItem lmi in m_subItems) { if (lmi.OnMouseUp(e)) { return(true); } } } return(false); }
/// <summary> /// 添加对象到图层. 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 (GetWriterLock(200)) { try { // find duplicate names foreach (RenderableObject childRo in 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 m_children) { if (childRo.Name == ro.Name) { found = true; break; } } if (!found) { break; } } } // Add the new child m_children.Add(ro); // Resort during the next update // NeedsSort = true; } } finally { m_childrenRWLock.ReleaseWriterLock(); } } else { MessageBox.Show("Unable to add new object " + ro.Name); } }