Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NodeEventArgs"/> class.
 /// </summary>
 /// <param name="node">Cost node to associated with.</param>
 public NodeEventArgs(CostNodeGlyph node)
 {
     if (node != null)
     {
         _costNodeGlyph = node;
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="RequestRateEventArgs"/> class.
        /// </summary>
        /// <param name="node">Node associated with this arguments.</param>
        /// <param name="rate">Rate.</param>
        public RequestRateEventArgs(CostNodeGlyph node, int rate)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            _costNodeGlyph = node;
            _rate = rate;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NodeEventArgs"/> class.
        /// </summary>
        /// <param name="node">Cost node to associated with.</param>
        /// <param name="e">Event to associated with.</param>
        public NodeEventArgs(CostNodeGlyph node, MouseEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            if (node != null)
            {
                _costNodeGlyph = node;
            }

            _mouseEventArgs = e;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Highlight all the routes including the costnode.
        /// </summary>
        /// <param name="node">Node to highlight routes on it.</param>
        /// <param name="g">Graphics to draw on.</param>
        private void HighLightRoutesOnNode(CostNodeGlyph node, Graphics g)
        {
            if (node == null)
            {
                return;
            }

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            int highLighted = 0;
            foreach (NodeRoute route in Utterance.Viterbi.NodeRoutes)
            {
                if (route.CostNodes.Contains(node.CostNode))
                {
                    HighLightRoute(route, g);
                    highLighted += 1;
                }
            }

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Select a cost node.
 /// </summary>
 /// <param name="node">Node to select.</param>
 private void SelectNode(CostNodeGlyph node)
 {
     if (node == null)
     {
         DeselectNode(this.SelectedNode);
     }
     else if (node != _selectedNode)
     {
         DeselectNode(_selectedNode);
         _selectedNode = node;
         _selectedNode.Selected = true;
         _utterance.Viterbi.SelectedRoute = FindRoute(node.CostNode);
     }
     else
     {
         _selectedNode.Selected = true;
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// De-select a costnode glyph.
        /// </summary>
        /// <param name="node">Node to deselect.</param>
        private void DeselectNode(CostNodeGlyph node)
        {
            if (node != null)
            {
                node.Selected = false;
                if (SelectedNode == node)
                {
                    _selectedNode = null;
                }

                _utterance.Viterbi.SelectedRoute = _utterance.Viterbi.NodeRoutes[0];
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Connect two cost node glyph.
        /// </summary>
        /// <param name="g">Graphics to draw on.</param>
        /// <param name="previous">Previous cost node glyph.</param>
        /// <param name="current">Current cost node glyph.</param>
        /// <param name="pen">Pen to draw with.</param>
        private void ConnectNodes(Graphics g, CostNodeGlyph previous,
            CostNodeGlyph current, Pen pen)
        {
            string prevKey = previous.CostNode.Key.ToString(CultureInfo.InvariantCulture)
                + " " + previous.CostNode.ClusterIndex.ToString(CultureInfo.InvariantCulture);
            string currKey = current.CostNode.Key.ToString(CultureInfo.InvariantCulture)
                + " " + current.CostNode.ClusterIndex.ToString(CultureInfo.InvariantCulture);

            if ((!_shownNodeGlyphs.ContainsKey(prevKey) || !_shownNodeGlyphs.ContainsKey(currKey)) &&
                this.NodeFolded)
            {
                return;
            }

            // page border and shadow
            Point prevPoint = new Point(previous.Rectangle.Right,
                previous.Rectangle.Top + (previous.Rectangle.Height / 2));
            Point currPoint = new Point(current.Rectangle.Left,
                current.Rectangle.Top + (current.Rectangle.Height / 2));
            g.DrawLine(pen, prevPoint, currPoint);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Build shown routes.
        /// </summary>
        /// <param name="routeCount">Route count to show.</param>
        private void BuildShownRoutes(int routeCount)
        {
            for (int i = 0; i < Math.Abs(_shownRouteCount); i++)
            {
                NodeRoute route = null;
                if (_shownRouteCount > 0)
                {
                    route = Utterance.Viterbi.NodeRoutes[i];
                }
                else
                {
                    route = Utterance.Viterbi.NodeRoutes[routeCount - 1 - i];
                }

                route.Visible = true;

                foreach (CostNode node in route.CostNodes)
                {
                    CostNodeGlyph glyph = new CostNodeGlyph();
                    glyph.CostNode = node;
                    string key = node.Key.ToString(CultureInfo.InvariantCulture)
                        + " " + node.ClusterIndex.ToString(CultureInfo.InvariantCulture);
                    if (!_shownNodeGlyphs.ContainsKey(key))
                    {
                        _shownNodeGlyphs.Add(key, glyph);
                    }
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Build shown clusters.
        /// </summary>
        private void BuildShownClusters()
        {
            _shownNodeGlyphs = new Dictionary<string, CostNodeGlyph>();

            _costNodeClusterGlyphs = new Collection<CostNodeClusterGlyph>();
            foreach (CostNodeCluster cluster in Utterance.Viterbi.CostNodeClusters)
            {
                CostNodeClusterGlyph clusterGlyph = new CostNodeClusterGlyph();
                clusterGlyph.CostNodeCluster = cluster;

                clusterGlyph.CostNodeGlyphs.Clear();
                foreach (CostNode node in cluster.CostNodes)
                {
                    CostNodeGlyph nodeGlyph = new CostNodeGlyph();
                    nodeGlyph.CostNode = node;
                    clusterGlyph.AddNode(nodeGlyph);
                }

                _costNodeClusterGlyphs.Add(clusterGlyph);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Hanlde OnMouseMove event.
        /// </summary>
        /// <param name="e">Event arguments.</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            Point logic = e.Location;
            logic.Offset(this.HorizontalScroll.Value, this.VerticalScroll.Value);
            IGlyph glyph = HitTest(logic);

            if (glyph is WordGlyph)
            {
                return;
            }

            CostNodeGlyph node = glyph as CostNodeGlyph;

            if (_prevMouseOverNode == null)
            {
                if (node != null)
                {
                    _prevMouseOverNode = node;
                    Invalidate();
                    _prevMouseOverNode.DoMouseEnter(this);
                    OnShowNode(this, new NodeEventArgs(node));
                }
            }
            else
            {
                if (node != _prevMouseOverNode)
                {
                    _prevMouseOverNode.DoMouseLeave(this);
                    _prevMouseOverNode = node;
                    Invalidate();
                    if (node != null)
                    {
                        _prevMouseOverNode.DoMouseEnter(this);
                        OnShowNode(this, new NodeEventArgs(node));
                    }
                }
            }

            if (node != null)
            {
                node.DoMouseMove(this, e);
            }
        }
        /// <summary>
        /// Add a costnode glyph to this cluster.
        /// </summary>
        /// <param name="node">Node to add.</param>
        public void AddNode(CostNodeGlyph node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.CostNode == null)
            {
                throw new ArgumentException("node.CostNode is null");
            }

            IndexedNodes.Add(node.CostNode.Key, node);
            CostNodeGlyphs.Add(node);
        }