public void RefreshTree()
        {
            lock (m_tree)
            {
                for (int gid = 0, gc = m_groupViews.Count; gid != gc; ++gid)
                {
                    RailGroup rg = m_tree.Groups[gid];
                    GroupView gv = m_groupViews[gid];

                    Dictionary <int, bool> existingRails = new Dictionary <int, bool>();
                    List <int>             newRails      = new List <int>(rg.Rails.Count);
                    foreach (int i in gv.RailIds)
                    {
                        existingRails.Add(i, true);
                        newRails.Add(i);
                    }

                    Dictionary <int, bool> existingVisibleRails = new Dictionary <int, bool>();
                    foreach (int i in gv.VisibleRailIds)
                    {
                        existingVisibleRails.Add(i, true);
                    }

                    foreach (int di in rg.Rails)
                    {
                        bool exists = existingRails.ContainsKey(di);
                        if (!exists)
                        {
                            newRails.Add(di);
                        }
                        if (!existingVisibleRails.ContainsKey(di) && !exists)
                        {
                            gv.VisibleRailIds.Add(di);
                        }
                    }

                    gv.RailIds = newRails.ToArray();
                }

                for (int gid = m_groupViews.Count, gc = m_tree.Groups.Count; gid != gc; ++gid)
                {
                    RailGroup rg = m_tree.Groups[gid];

                    GroupView gv = new GroupView();
                    gv.GroupId        = gid;
                    gv.RailIds        = rg.Rails.ToArray();
                    gv.VisibleRailIds = new List <int>(gv.RailIds);
                    m_groupViews.Add(gv);
                }
            }

            ClampView();
            UpdateScroll();
            Invalidate();
        }
Exemple #2
0
        void m_intervalTreeView_AfterCheck(object sender, TreeViewEventArgs e)
        {
            RailGroup rg = e.Node.Tag as RailGroup;

            if (rg != null)
            {
                m_intervalControl.ShowGroup(rg, e.Node.Checked);
            }
            else
            {
                KeyValuePair <RailGroup, int> rgi = (KeyValuePair <RailGroup, int>)e.Node.Tag;
                m_intervalControl.ShowGroupRail(rgi.Key, rgi.Value, e.Node.Checked);
            }
        }
        public void ShowGroup(RailGroup rg, bool show)
        {
            int gid;

            lock (m_tree)
            {
                gid = m_tree.Groups.IndexOf(rg);
            }

            if (gid >= 0)
            {
                m_groupViews[gid].Visible = show;
                ClampView();
                ClampView();
                UpdateScroll();
                Invalidate();
            }
        }
        protected void OnSelectionChanged()
        {
            for (int gvi = 0, gvc = m_groupViews.Count; gvi != gvc; ++gvi)
            {
                GroupView gv = m_groupViews[gvi];

                lock (m_tree)
                {
                    RailGroup rg = m_tree.Groups[gv.GroupId];
                    gv.RailIds = rg.Style.ReorderRails(m_tree, gv.RailIds, SelectionStart, SelectionEnd);
                }

                RefreshVisibleRails(gvi);
            }

            if (SelectionChanged != null)
            {
                SelectionChanged(this, EventArgs.Empty);
            }

            Invalidate();
        }
        public void ShowGroupRail(RailGroup rg, int railId, bool show)
        {
            int gid;

            lock (m_tree)
            {
                gid = m_tree.Groups.IndexOf(rg);
            }

            if (gid >= 0)
            {
                if (show)
                {
                    m_groupViews[gid].VisibleRailIds.Add(railId);
                }
                else
                {
                    m_groupViews[gid].VisibleRailIds.Remove(railId);
                }

                RefreshVisibleRails(gid);
                Invalidate();
            }
        }
        protected override void glDraw()
        {
            if (m_tree != null)
            {
                lock (m_tree)
                {
                    ResourceInit();

                    PrepareViewport();

                    m_visible.Clear();

                    double unitsPerPy = GetSamplesPerPixelY();
                    double pyPerUnit  = 1.0 / unitsPerPy;

                    bool  showEdges   = RailHeightUnits * pyPerUnit >= 2.5;
                    float contraction = 0.0f;//RailHeightUnits * pyPerUnit >= 4.0 ? 2.0f * (float)unitsPerPy : 0.0f;

                    double groupHeaderHeightUnits = unitsPerPy * GroupHeaderHeightPx;

                    Int64 peLeft  = (Int64)(m_physExtents.Left * 1000000.0);
                    Int64 peRight = (Int64)(m_physExtents.Right * 1000000.0);
                    Int64 vLeft   = (Int64)(m_view.Left * 1000000.0);
                    Int64 vRight  = (Int64)(m_view.Right * 1000000.0);

                    {
                        double groupTopUnits = 0;

                        for (int gvi = 0, gvc = m_groupViews.Count; gvi < gvc; ++gvi)
                        {
                            GroupView gv = m_groupViews[gvi];

                            if (gv.Visible)
                            {
                                RailGroup rg = m_tree.Groups[gv.GroupId];

                                double groupHeaderTopUnits    = groupTopUnits;
                                double groupHeaderBottomUnits = groupTopUnits + groupHeaderHeightUnits;
                                double groupHeightUnits       = gv.VisibleRailIds.Count * RailHeightUnits;
                                double groupBottomUnits       = groupHeaderBottomUnits + groupHeightUnits;

                                gv.ProjectedTop = (int)((groupHeaderTopUnits - m_view.Top) * pyPerUnit);

                                double top = groupHeaderBottomUnits;
                                foreach (int railId in gv.VisibleRailIds)
                                {
                                    if (top + RailHeightUnits > m_view.Top)
                                    {
                                        foreach (Interval iv in m_tree.RangeEnum(railId, peLeft, peRight))
                                        {
                                            if ((Int64)iv.EndUs <= vLeft)
                                            {
                                                continue;
                                            }
                                            if ((Int64)iv.StartUs >= vRight)
                                            {
                                                continue;
                                            }

                                            BakedInterval biv = new BakedInterval(
                                                railId,
                                                rg.Style.GetIntervalColor(iv),
                                                new RectD(
                                                    ((Int64)iv.StartUs - vLeft) / 1000000.0,
                                                    top + contraction,
                                                    Math.Min(peRight, ((Int64)iv.EndUs - vLeft)) / 1000000.0,
                                                    top + RailHeightUnits - contraction),
                                                iv);
                                            m_visible.Add(biv);
                                        }
                                    }

                                    top += RailHeightUnits;

                                    if (top >= m_view.Bottom)
                                    {
                                        break;
                                    }
                                }

                                groupTopUnits = groupHeaderBottomUnits + groupHeightUnits;
                            }
                        }
                    }

                    if (RailHeightUnits * pyPerUnit >= 7.0)
                    {
                        double groupTopUnits = 0;

                        OpenGL.glBegin(OpenGL.GL_LINES);
                        OpenGL.glColor3f(0.0f, 0.0f, 0.0f);

                        for (int gvi = 0, gvc = m_groupViews.Count; gvi < gvc; ++gvi)
                        {
                            GroupView gv = m_groupViews[gvi];

                            if (gv.Visible)
                            {
                                RailGroup rg = m_tree.Groups[gv.GroupId];

                                double groupHeaderTopUnits    = groupTopUnits;
                                double groupHeaderBottomUnits = groupTopUnits + groupHeaderHeightUnits;
                                double groupHeightUnits       = gv.VisibleRailIds.Count * RailHeightUnits;
                                double groupBottomUnits       = groupHeaderBottomUnits + groupHeightUnits;

                                gv.ProjectedTop = (int)((groupHeaderTopUnits - m_view.Top) * pyPerUnit);

                                double top = groupHeaderBottomUnits + RailHeightUnits / 2.0f;

                                foreach (int railId in gv.VisibleRailIds)
                                {
                                    OpenGL.glVertex2f(0.0f, (float)(top - m_view.Top));
                                    OpenGL.glVertex2f((float)m_view.Width, (float)(top - m_view.Top));

                                    top += RailHeightUnits;
                                }

                                groupTopUnits = groupHeaderBottomUnits + groupHeightUnits;
                            }
                        }

                        OpenGL.glEnd();
                    }

                    {
                        OpenGL.glBegin(OpenGL.GL_QUADS);

                        foreach (var iv in m_visible)
                        {
                            float l = (float)(iv.BBox.Left);
                            float t = (float)(iv.BBox.Top - m_view.Top);
                            float r = (float)(iv.BBox.Right);
                            float b = (float)(iv.BBox.Bottom - m_view.Top);

                            Color color = iv.Color;

                            OpenGL.glColor3f(color.R * (1.0f / 255.0f), color.G * (1.0f / 255.0f), color.B * (1.0f / 255.0f));

                            OpenGL.glVertex2f(l, t);
                            OpenGL.glVertex2f(l, b);
                            OpenGL.glVertex2f(r, b);
                            OpenGL.glVertex2f(r, t);
                        }

                        OpenGL.glEnd();
                    }

                    if (showEdges)
                    {
                        OpenGL.glBegin(OpenGL.GL_LINES);

                        OpenGL.glColor3f(0.2f, 0.2f, 0.2f);

                        foreach (var iv in m_visible)
                        {
                            float l = (float)(iv.BBox.Left);
                            float t = (float)(iv.BBox.Top - m_view.Top);
                            float r = (float)(iv.BBox.Right);
                            float b = (float)(iv.BBox.Bottom - m_view.Top);

                            OpenGL.glVertex2f(l, t);
                            OpenGL.glVertex2f(l, b);

                            OpenGL.glVertex2f(l, b);
                            OpenGL.glVertex2f(r, b);

                            OpenGL.glVertex2f(r, b);
                            OpenGL.glVertex2f(r, t);

                            OpenGL.glVertex2f(r, t);
                            OpenGL.glVertex2f(l, t);
                        }

                        OpenGL.glEnd();
                    }

                    {
                        OpenGL.glBegin(OpenGL.GL_LINES);

                        OpenGL.glColor3f(0.6f, 0.6f, 0.6f);

                        float h = (float)m_view.Height;
                        for (float x = (float)Math.Floor(m_view.Left), xe = (float)Math.Floor(m_view.Right); x <= xe; ++x)
                        {
                            OpenGL.glVertex2f((float)(x - m_view.Left), 0);
                            OpenGL.glVertex2f((float)(x - m_view.Left), h);
                        }

                        OpenGL.glEnd();
                    }

                    DrawSelection();
                }

                PreparePxViewport();

                foreach (GroupView gv in m_groupViews)
                {
                    if (gv.Visible)
                    {
                        OpenGL.glBegin(OpenGL.GL_QUADS);
                        OpenGL.glColor3f(1.0f, 1.0f, 1.0f);
                        OpenGL.glVertex2f(0.0f, gv.ProjectedTop);
                        OpenGL.glVertex2f(0.0f, gv.ProjectedTop + 20);
                        OpenGL.glVertex2f(ClientSize.Width, gv.ProjectedTop + 20);
                        OpenGL.glVertex2f(ClientSize.Width, gv.ProjectedTop);
                        OpenGL.glEnd();

                        m_groupFont.Draw(0, gv.ProjectedTop + 2, Color.Black, m_tree.Groups[gv.GroupId].Name);
                    }
                }
            }
        }