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); } }
/// <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); }
/// <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); } }