コード例 #1
0
        /// <summary>
        /// Event handler for the train graphic clicked event
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Event arguments</param>
        private void OnTrainGraphicClicked(object sender, EventArgs e)
        {
            try
            {
                TrainGraphic graphic = (TrainGraphic)sender;

                if (m_selectedTrackBlock != null)
                {
                    m_selectedTrackBlock.StopBlinking();
                }
                if (m_selectedTrain != null && m_selectedTrain != graphic)
                {
                    m_selectedTrain.StopBlinking();
                }

                m_selectedTrackBlock = null;
                m_selectedTrain      = graphic;

                blinkTimer.Start();

                if (TrainClicked != null)
                {
                    TrainClicked(graphic.Train);
                }
            }
            catch (InvalidCastException ex)
            {
                m_log.LogError(ex);
                throw ex;
            }
        }
コード例 #2
0
 public void BlinkTest1()
 {
     ITrain train = null; // TODO: Initialize to an appropriate value
     TrainGraphic target = new TrainGraphic(train); // TODO: Initialize to an appropriate value
     target.Blink();
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
コード例 #3
0
        /// <summary>
        /// Updates the display
        /// </summary>
        /// <param name="blocks">List of track blocks</param>
        /// <param name="trains">List of trains</param>
        public void UpdateDisplay(List <TrackBlock> updatedBlocks, List <ITrain> trains)
        {
            if (InvokeRequired)
            {
                Invoke(m_updateDelegate, updatedBlocks, trains);
            }
            else
            {
                //Update the block layout
                if (updatedBlocks != null)
                {
                    this.SuspendLayout();

                    foreach (TrackBlock b in updatedBlocks)
                    {
                        if (m_blockTable.ContainsKey(b))
                        {
                            m_blockTable[b].Invalidate();
                        }
                    }

                    //Upate the train locations
                    foreach (ITrain train in trains)
                    {
                        if (m_trainTable.ContainsKey(train))
                        {
                            TrainGraphic graphic = m_trainTable[train];

                            graphic.Left = System.Convert.ToInt32((train.GetPosition().X - m_layoutPosition.X) * m_scale - graphic.Width / 2);
                            graphic.Top  = System.Convert.ToInt32((train.GetPosition().Y - m_layoutPosition.Y) * m_scale - graphic.Height / 2);
                        }
                        else
                        {
                            //New train, add it to the list
                            TrainGraphic graphic = new TrainGraphic(train);

                            graphic.Location = new Point(System.Convert.ToInt32((train.GetPosition().X - m_layoutPosition.X) * m_scale - graphic.Width / 2),
                                                         System.Convert.ToInt32((train.GetPosition().Y - m_layoutPosition.Y) * m_scale - graphic.Height / 2));

                            graphic.TrainClicked += OnTrainGraphicClicked;
                            graphic.Disposed     += OnTrainDisposed;

                            Controls.Add(graphic);
                            graphic.Visible = true;
                            graphic.BringToFront();
                            m_trainTable[train] = graphic;
                        }
                    }

                    this.ResumeLayout();
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// A train was disposed. Remove the graphic
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Event arguments</param>
        private void OnTrainDisposed(object sender, EventArgs e)
        {
            try
            {
                ITrain train = (ITrain)sender;

                if (m_trainTable.ContainsKey(train))
                {
                    //Remove the train graphic from the display
                    if (m_selectedTrain == m_trainTable[train])
                    {
                        m_selectedTrain = null;
                    }

                    m_trainTable[train].Dispose();
                    m_trainTable.Remove(train);
                }
            }
            catch (InvalidCastException ex)
            {
                m_log.LogError("Received train disposing event but could not cast to train", ex);
            }
        }
コード例 #5
0
 public void TrainTest1()
 {
     ITrain train = null; // TODO: Initialize to an appropriate value
     TrainGraphic target = new TrainGraphic(train); // TODO: Initialize to an appropriate value
     ITrain expected = null; // TODO: Initialize to an appropriate value
     ITrain actual;
     target.Train = expected;
     actual = target.Train;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
コード例 #6
0
 public void TrainGraphicConstructorTest1()
 {
     ITrain train = null; // TODO: Initialize to an appropriate value
     TrainGraphic target = new TrainGraphic(train);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
コード例 #7
0
 public void SetScaleTest1()
 {
     ITrain train = null; // TODO: Initialize to an appropriate value
     TrainGraphic target = new TrainGraphic(train); // TODO: Initialize to an appropriate value
     double scale = 0F; // TODO: Initialize to an appropriate value
     bool expected = false; // TODO: Initialize to an appropriate value
     bool actual;
     actual = target.SetScale(scale);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }