コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
ファイル: Menu.cs プロジェクト: qaz734913414/MFW3DNet
 /// <summary>
 /// Initializes a new instance of the <see cref= "T:WorldWind.Menu.LayerShortcutMenuButton"/> class.
 /// </summary>
 /// <param name="imageFilePath"></param>
 /// <param name="ro"></param>
 public LayerShortcutMenuButton(
     string imageFilePath, MFW3D.Renderable.RenderableObject ro)
     : base(imageFilePath)
 {
     this.Description = ro.Name;
     this._ro         = ro;
     this._isPushed   = ro.IsOn;
 }
コード例 #3
0
 private string GetAbsoluteRenderableObjectPath(MFW3D.Renderable.RenderableObject ro)
 {
     if (ro.ParentList != null)
     {
         return(GetAbsoluteRenderableObjectPath(ro.ParentList) + "//" + ro.Name);
     }
     else
     {
         return(ro.Name);
     }
 }
コード例 #4
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;

                compareRefreshLists(newList, oldList);
            }
        }
コード例 #5
0
        ///<summary>
        ///  Goes to the extent specified by the bounding box for the QTS layer
        ///  or to the lat/lon for icons
        /// </summary>
        public void GetGoto()
        {
            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(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;
                        }
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// 返回第一个显示的对象名字
        /// </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;

            m_childrenRWLock.AcquireReaderLock(Timeout.Infinite);
            try
            {
                foreach (RenderableObject ro in this.m_children)
                {
                    if (ro.Name.Equals(name))
                    {
                        result = ro;
                        break;
                    }
                }
            }
            finally
            {
                m_childrenRWLock.ReleaseReaderLock();
            }
            return(result);
        }
コード例 #7
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.
            m_delRWLock.AcquireWriterLock(Timeout.Infinite);
            try
            {
                // if we need to clear everyone just do it.
                if (m_delAll)
                {
                    if (GetWriterLock(10))
                    {
                        try
                        {
                            while (m_children.Count > 0)
                            {
                                RenderableObject ro = (RenderableObject)m_children[0];
                                m_children.RemoveAt(0);
                                ro.Dispose();
                            }
                        }
                        finally
                        {
                            m_childrenRWLock.ReleaseWriterLock();
                        }
                        m_delAll = false;

                        // we can safely clear the list
                        m_delList.Clear();
                    }
                    else
                    {
                        // try next update cycle
                    }
                }
                else
                {
                    // get a writer lock so we can remove from the child list
                    if (GetWriterLock(10))
                    {
                        try
                        {
                            foreach (object data in 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
                            m_delList.Clear();
                        }
                        finally
                        {
                            m_childrenRWLock.ReleaseWriterLock();
                        }
                    }
                    else
                    {
                        // try next update cycle
                    }
                }
            }
            finally
            {
                m_delRWLock.ReleaseWriterLock();
            }
        }
コード例 #8
0
        /// <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);
            }
        }
コード例 #9
0
        private void m_UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                System.DateTime updateStart = System.DateTime.Now;

                for (int i = 0; i < m_WorldWindow.CurrentWorld.RenderableObjects.Count; i++)
                {
                    MFW3D.Renderable.RenderableObject curRo = (MFW3D.Renderable.RenderableObject)m_WorldWindow.CurrentWorld.RenderableObjects.ChildObjects[i];
                    if (i >= this.treeView1.Nodes.Count)
                    {
                        // Add a node
                        TreeNode             correctNode = new TreeNode(curRo.Name);
                        RenderableObjectInfo curRoi      = new RenderableObjectInfo();
                        curRoi.Renderable = curRo;
                        correctNode.Tag   = curRoi;

                        m_NodeHash.Add(correctNode.Text, correctNode);
                        this.treeView1.BeginInvoke(new AddTableTreeDelegate(this.AddTableTree), new object[] { correctNode });
                        updateNode(correctNode);
                    }
                    else
                    {
                        //compare nodes
                        TreeNode curTn = this.treeView1.Nodes[i];

                        RenderableObjectInfo curRoi = (RenderableObjectInfo)curTn.Tag;
                        if (curRoi.Renderable != null && curRoi.Renderable.Name == curRo.Name)
                        {
                            updateNode(curTn);
                            continue;
                        }
                        else
                        {
                            if (!m_NodeHash.Contains(curRo.Name))
                            {
                                //add it
                                curRoi            = new RenderableObjectInfo();
                                curRoi.Renderable = curRo;
                                curTn             = new TreeNode(curRo.Name);
                                curTn.Tag         = curRoi;

                                m_NodeHash.Add(curTn.Text, curTn);
                                this.treeView1.BeginInvoke(new InsertTableTreeDelegate(this.InsertTableTree), new object[] { i, curTn });
                            }
                            else
                            {
                                curTn = (TreeNode)m_NodeHash[curRo.Name];
                                try
                                {
                                    treeView1.BeginInvoke(new RemoveTableTreeDelegate(this.RemoveTableTree), new object[] { curTn });
                                }
                                catch
                                {}

                                treeView1.BeginInvoke(new InsertTableTreeDelegate(this.InsertTableTree), new object[] { i, curTn });
                            }
                        }

                        updateNode(curTn);
                    }
                }

                for (int i = m_WorldWindow.CurrentWorld.RenderableObjects.Count; i < this.treeView1.Nodes.Count; i++)
                {
                    this.treeView1.BeginInvoke(new RemoveAtTableTreeDelegate(this.RemoveAtTableTree), new object[] { i });
                }

                System.Collections.ArrayList deletionList = new ArrayList();
                foreach (TreeNode tn in m_NodeHash.Values)
                {
                    RenderableObjectInfo roi = (RenderableObjectInfo)tn.Tag;
                    if (roi == null || roi.Renderable == null || roi.LastSpotted < updateStart)
                    {
                        deletionList.Add(GetAbsoluteRenderableObjectPath(roi.Renderable));
                    }
                }

                foreach (string key in deletionList)
                {
                    m_NodeHash.Remove(key);
                }
            }
            catch
            {}
        }
コード例 #10
0
        private void refreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (isUpdating)
            {
                return;
            }
            isUpdating = true;
            try
            {
                for (int i = 0; i < this.ChildObjects.Count; i++)
                {
                    RenderableObject ro = (RenderableObject)this.ChildObjects[i];
                    if (ro != null && ro.IsOn && ro is Icon)
                    {
                        Icon icon = (Icon)ro;

                        if (icon.RefreshInterval == TimeSpan.MaxValue || icon.LastRefresh > System.DateTime.Now - icon.RefreshInterval)
                        {
                            continue;
                        }

                        object      key         = null;
                        IconTexture iconTexture = null;

                        if (icon.TextureFileName != null && icon.TextureFileName.Length > 0)
                        {
                            iconTexture = (IconTexture)DrawArgs.Textures[icon.TextureFileName];
                            if (iconTexture != null)
                            {
                                iconTexture.UpdateTexture(DrawArgs.Device, icon.TextureFileName);
                            }
                            else
                            {
                                key         = icon.TextureFileName;
                                iconTexture = new IconTexture(DrawArgs.Device, icon.TextureFileName);

                                iconTexture.ReferenceCount++;

                                // New texture, cache it
                                DrawArgs.Textures.Add(key, iconTexture);

                                // Use default dimensions if not set
                                if (icon.Width == 0)
                                {
                                    icon.Width = iconTexture.Width;
                                }
                                if (icon.Height == 0)
                                {
                                    icon.Height = iconTexture.Height;
                                }
                            }
                        }
                        else
                        {
                            // Icon image from bitmap
                            if (icon.Image != null)
                            {
                                iconTexture = (IconTexture)DrawArgs.Textures[icon.Image];
                                if (iconTexture != null)
                                {
                                    IconTexture tempTexture = iconTexture;
                                    DrawArgs.Textures[icon.SaveFilePath] = new IconTexture(DrawArgs.Device, icon.Image);
                                    tempTexture.Dispose();
                                }
                                else
                                {
                                    key         = icon.SaveFilePath;
                                    iconTexture = new IconTexture(DrawArgs.Device, icon.Image);

                                    // New texture, cache it
                                    DrawArgs.Textures.Add(key, iconTexture);

                                    // Use default dimensions if not set
                                    if (icon.Width == 0)
                                    {
                                        icon.Width = iconTexture.Width;
                                    }
                                    if (icon.Height == 0)
                                    {
                                        icon.Height = iconTexture.Height;
                                    }
                                }
                            }
                        }

                        icon.LastRefresh = System.DateTime.Now;
                    }
                }
            }
            catch { }
            finally
            {
                isUpdating = false;
            }
        }
コード例 #11
0
 /// <summary>
 /// Add a child object to this layer.
 /// </summary>
 /// <param name="ro">The renderable object to add to this layer</param>
 public override void Add(RenderableObject ro)
 {
     ro.ParentList = this;
     base.Add(ro);
 }