Example #1
0
        //
        //  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);
            }
        }
Example #2
0
 private string getFullRenderableObjectName(RenderableObject ro, string name)
 {
     if (ro.ParentList == null)
     {
         return("/" + name);
     }
     else
     {
         if (name == null)
         {
             return(this.getFullRenderableObjectName(ro.ParentList, ro.Name));
         }
         else
         {
             return(this.getFullRenderableObjectName(ro.ParentList, ro.Name + "/" + name));
         }
     }
 }
Example #3
0
        private int getIRenderableIndexFromParent(RenderableObject renderable)
        {
            if (renderable.ParentList == null)
            {
                return(-1);
            }
            else
            {
                for (int index = 0; index < renderable.ParentList.ChildObjects.Count; index++)
                {
                    if (renderable == renderable.ParentList.ChildObjects[index])
                    {
                        return(index);
                    }
                }
            }

            return(-1);
        }
Example #4
0
        ///<summary>
        ///  Goes to the extent specified by the bounding box for the QTS layer
        ///  or to the lat/lon for icons
        /// </summary>
        protected virtual void OnGotoClick(object sender, EventArgs e)
        {
            lock (this.ParentList.ChildObjects.SyncRoot)
            {
                for (int i = 0; i < this.ParentList.ChildObjects.Count; i++)
                {
                    RenderableObject ro = (RenderableObject)this.ParentList.ChildObjects[i];
                    if (ro.Name.Equals(this.name))
                    {
                        if (ro is QuadTileSet)
                        {
                            QuadTileSet qts = (QuadTileSet)ro;
                            DrawArgs.Camera.SetPosition((qts.North + qts.South) / 2, (qts.East + qts.West) / 2);
                            double perpendicularViewRange = (qts.North - qts.South > qts.East - qts.West ? qts.North - qts.South : qts.East - qts.West);
                            double altitude = qts.LayerRadius * Math.Sin(MathEngine.DegreesToRadians(perpendicularViewRange * 0.5));

                            DrawArgs.Camera.Altitude = altitude;

                            break;
                        }
                        if (ro is Icon)
                        {
                            Icon ico = (Icon)ro;
                            DrawArgs.Camera.SetPosition(ico.Latitude, ico.Longitude);
                            DrawArgs.Camera.Altitude /= 2;

                            break;
                        }
                        if (ro is ShapeFileLayer)
                        {
                            ShapeFileLayer slayer = (ShapeFileLayer)ro;
                            DrawArgs.Camera.SetPosition((slayer.North + slayer.South) / 2, (slayer.East + slayer.West) / 2);
                            double perpendicularViewRange = (slayer.North - slayer.South > slayer.East - slayer.West ? slayer.North - slayer.South : slayer.East - slayer.West);
                            double altitude = slayer.MaxAltitude;

                            DrawArgs.Camera.Altitude = altitude;

                            break;
                        }
                    }
                }
            }
        }
Example #5
0
        /// <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);
        }
Example #6
0
        /// <summary>
        /// Return the first direct child with a given name.
        /// </summary>
        /// <example>Get the placenames LayerSet.
        /// <code>
        /// RenderableObject placenames = CurrentWorld.RenderableObjects.GetObject("Placenames"));
        /// </code></example>
        /// <param name="name">The name to search for</param>
        /// <returns>The first <c>RenderableObject</c> that matched the specified name, or <c>nullk</c> if none was found.</returns>
        public virtual RenderableObject GetObject(string name)
        {
            RenderableObject result = null;

            this.m_childrenRWLock.AcquireReaderLock(Timeout.Infinite);
            try
            {
                foreach (RenderableObject ro in this.m_children)
                {
                    if (ro.Name.Equals(name))
                    {
                        result = ro;
                        break;
                    }
                }
            }
            finally
            {
                this.m_childrenRWLock.ReleaseReaderLock();
            }
            return(result);
        }
Example #7
0
        /// <summary>
        /// Gets the xml for properties in the base RO class.
        /// </summary>
        /// <param name="ro">The RenderableObject to parse</param>
        /// <param name="roNode">the XmlNode for the object</param>
        public static void getRenderableObjectProperties(RenderableObject ro, XmlNode roNode)
        {
            XmlDocument worldDoc = roNode.OwnerDocument;

            // TODO: what about Thumbnail, ThumbnailImage, IconImagePath, etc.?
            // do those even get used for anything?

            XmlNode nameNode = worldDoc.CreateElement("Name");

            nameNode.AppendChild(worldDoc.CreateTextNode(ro.Name));
            roNode.AppendChild(nameNode);

            XmlNode descNode = worldDoc.CreateElement("Description");

            descNode.AppendChild(worldDoc.CreateTextNode(ro.Description));
            roNode.AppendChild(descNode);

            XmlNode opacityNode = worldDoc.CreateElement("Opacity");

            opacityNode.AppendChild(worldDoc.CreateTextNode(ro.Opacity.ToString(CultureInfo.InvariantCulture)));
            roNode.AppendChild(nameNode);

            XmlNode renderPriorityNode = worldDoc.CreateElement("RenderPriority");

            renderPriorityNode.AppendChild(worldDoc.CreateTextNode(ro.RenderPriority.ToString()));
            roNode.AppendChild(renderPriorityNode);

            // Attributes
            XmlAttribute isOnAttribute = worldDoc.CreateAttribute("ShowAtStartup");

            isOnAttribute.Value = ro.IsOn.ToString(CultureInfo.InvariantCulture);
            roNode.Attributes.Append(isOnAttribute);

            XmlAttribute infoUriAttribute = worldDoc.CreateAttribute("InfoUri");

            infoUriAttribute.Value = (string)ro.MetaData["InfoUri"];
            roNode.Attributes.Append(infoUriAttribute);
        }
Example #8
0
 public SurfaceImage(string imageFilePath, double north, double south, double west, double east, Texture texture, RenderableObject parentRenderable)
 {
     m_ParentRenderable = parentRenderable;
     m_ImageFilePath    = imageFilePath;
     m_North            = north;
     m_South            = south;
     m_West             = west;
     m_East             = east;
     m_Texture          = texture;
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref= "T:WorldWind.LayerMenuItem"/> class.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="renderableObject"></param>
 public LayerMenuItem(LayerManagerMenu parent, RenderableObject renderableObject)
 {
     this.m_renderableObject = renderableObject;
     this.m_parent           = parent;
 }
Example #10
0
        /// <summary>
        /// Removes all deleted ROs.  Called only in Update (Worker thread)
        /// </summary>
        private void Remove()
        {
            // get the writer lock for the delList because we need to clear at the end.
            // if we just do a reader lock and upgrade you can get another
            // writer in there which means we'd clear the delList before
            // we remove new items for deletion from the child list.
            this.m_delRWLock.AcquireWriterLock(Timeout.Infinite);
            try
            {
                // if we need to clear everyone just do it.
                if (this.m_delAll)
                {
                    if (this.GetWriterLock(10))
                    {
                        try
                        {
                            while (this.m_children.Count > 0)
                            {
                                RenderableObject ro = (RenderableObject)this.m_children[0];
                                this.m_children.RemoveAt(0);
                                ro.Dispose();
                            }
                        }
                        finally
                        {
                            this.m_childrenRWLock.ReleaseWriterLock();
                        }

                        this.m_delAll = false;

                        // we can safely clear the list
                        this.m_delList.Clear();
                    }
                    else
                    {
                        // try next update cycle
                    }
                }
                else
                {
                    // get a writer lock so we can remove from the child list
                    if (this.GetWriterLock(10))
                    {
                        try
                        {
                            foreach (object data in this.m_delList)
                            {
                                RenderableObject rod = data as RenderableObject;
                                if (rod != null)
                                {
                                    this.m_children.Remove(rod);
                                    rod.ParentList = null;
                                    rod.Dispose();
                                }
                                string objectName = data as String;
                                if (objectName != null)
                                {
                                    for (int i = 0; i < this.m_children.Count; i++)
                                    {
                                        RenderableObject ro = (RenderableObject)this.m_children[i];
                                        if (ro.Name.Equals(objectName))
                                        {
                                            this.m_children.RemoveAt(i);
                                            ro.ParentList = null;
                                            ro.Dispose();
                                            break;
                                        }
                                    }
                                }
                            }

                            // we can safely clear the list
                            this.m_delList.Clear();
                        }
                        finally
                        {
                            this.m_childrenRWLock.ReleaseWriterLock();
                        }
                    }
                    else
                    {
                        // try next update cycle
                    }
                }
            }
            finally
            {
                this.m_delRWLock.ReleaseWriterLock();
            }
        }
Example #11
0
        /// <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);
            }
        }