コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: jcol27/HCDESLib
        }     // end of StopSimulation

        #endregion

        #region PlaySimulationTick

        public void PlaySimulationTick(object sender, EventArgs e)
        {
            // security call in case the timer ticks bfore
            // it disabled by stop simulation
            if (!VisualizationEnabled)
            {
                return;
            }

            DateTime timeOfCall;

            if (TickCallIsSimulationCall)
            {
                timeOfCall = CurrentTime;

                DateTime newTime;
                bool     modelRunning = SimulationEngine.RunSingleStepSimulationModel(CurrentTime, out newTime);

                // in case end of model is reached the simulation is stopped
                if (!modelRunning)
                {
                    StopSimulation(false);
                    return;
                } // end if

                SimulationDisplayClock.SetDateTime(CurrentTime);
                SimulationModel.SimulationDrawingEngine.CreateModelVisualization(CurrentTime, SimulationModel, SimulationEngine.CurrentlyTriggeredEvents);
                ProgressBarSimulationProgress.Value = SimulationModel.GetSimulationProgress(CurrentTime);

                _nextSimulationTime = newTime;
                _currentTime        = newTime;
            }
            else
            {
                timeOfCall = NextTimerTime;

                SimulationDisplayClock.SetDateTime(NextTimerTime);
                SimulationModel.SimulationDrawingEngine.CreateModelVisualization(NextTimerTime, SimulationModel, new List <Event>());
                ProgressBarSimulationProgress.Value = SimulationModel.GetSimulationProgress(CurrentTime);
                _nextTimerTime += ConstantTimerStep;
            } // end if

            SimulationTimer.Interval = TimeSpan.FromMilliseconds(Math.Max((int)(((NextTime - timeOfCall).Ticks / ConstantTimerStep.Ticks) * SimulationSpeed), 1));
        } // end of PlaySimulationTick
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: jcol27/HCDESLib
        //--------------------------------------------------------------------------------------------------
        // Constructor
        //--------------------------------------------------------------------------------------------------

        #region MainWindow

        public MainWindow()
        {
            Loaded += WainWindowOnLoad;

            InitializeComponent();

            #region InitalizeStartEndDate

            DatePickerStartDate.SelectedDate = DateTime.Now;
            DatePickerEndDate.SelectedDate   = DateTime.Now.AddMonths(1);

            #endregion

            #region InitiaizeDrawingSystem

            _drawingSystem = new DrawingOnCoordinateSystem(0, 300);
            DrawingSystem.VerticalAlignment   = VerticalAlignment.Stretch;
            DrawingSystem.HorizontalAlignment = HorizontalAlignment.Stretch;
            DrawingSystem.SetValue(Grid.RowProperty, 1);
            DrawingSystem.SetValue(Grid.ColumnProperty, 1);
            DrawingSystem.SetValue(Grid.ColumnSpanProperty, 2);

            MainGrid.Children.Add(DrawingSystem);

            #endregion

            #region IntiliazeBackgroundWorker

            _backGroundWorkerNonVisualization = new BackgroundWorker();
            _backGroundWorkerNonVisualization.WorkerReportsProgress      = true;
            _backGroundWorkerNonVisualization.WorkerSupportsCancellation = true;
            _backGroundWorkerNonVisualization.DoWork             += new System.ComponentModel.DoWorkEventHandler(BackGroundWorkerNonVisualizationDoWork);
            _backGroundWorkerNonVisualization.ProgressChanged    += new ProgressChangedEventHandler(BackGroundWorkerNonVisualizationProgressChanged);
            _backGroundWorkerNonVisualization.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackGroundWorkerNonVisualizationRunWorkerCompleted);

            #endregion

            ComboBoxTimeBase.SelectedIndex = 0;
            _simulationRunning             = false;
            _simulationInitialized         = false;

            _simulationTimer      = new DispatcherTimer();
            SimulationTimer.Tick += PlaySimulationTick;
            TextBoxSimSpeed.Text  = SimulationSpeed.ToString();

            CreateModel();

            #region InitializeClock

            _simulationDisplayClock = new DrawAnalogClockWithDate(Colors.Black, 0, 0);
            SimulationDisplayClock.VerticalAlignment   = VerticalAlignment.Stretch;
            SimulationDisplayClock.HorizontalAlignment = HorizontalAlignment.Stretch;
            SimulationDisplayClock.SetValue(Grid.RowProperty, 0);
            SimulationDisplayClock.SetValue(Grid.ColumnProperty, 2);

            MainGrid.Children.Add(SimulationDisplayClock);

            Loaded += delegate
            {
                SimulationDisplayClock.Initialize(SimulationModel.StartTime);
            };

            #endregion
        } // end of MainWindow