OpenASIP 2.2
Loading...
Searching...
No Matches
ProximStopDialog.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file ProximStopDialog.cc
26 *
27 * Implementation of ProximStopDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <wx/statline.h>
34#include <boost/format.hpp>
35#include "ProximStopDialog.hh"
36#include "WxConversion.hh"
37#include "SimulatorFrontend.hh"
38
40
41BEGIN_EVENT_TABLE(ProximStopDialog, wxDialog)
44 EVT_TIMER(0, ProximStopDialog::onUpdate)
46
47/**
48 * The Constructor.
49 *
50 * @param parent Parent window of the dialog.
51 * @param id Window identifier.
52 * @param frontend Simulator frontend to stop.
53 */
55 wxWindow* parent, wxWindowID id, SimulatorFrontend& frontend):
56 wxDialog(parent, id, _T("Simulation running..."), wxDefaultPosition),
57 frontend_(frontend), time_(0) {
58
59 createContents(this, true, true);
60
61 cyclesCtrl_ = dynamic_cast<wxStaticText*>(FindWindow(ID_CYCLES));
62 timeCtrl_ = dynamic_cast<wxStaticText*>(FindWindow(ID_TIME));
63 cpsCtrl_ = dynamic_cast<wxStaticText*>(FindWindow(ID_CPS));
64 cpsCtrl_->SetLabel(_T(""));
65
66 timer_ = new wxTimer(this, 0);
67 watch_ = new wxStopWatch();
68
69 cycles_ = frontend_.cycleCount();
70 timer_->Start(UPDATE_INTERVAL);
71}
72
73
74/**
75 * The Destructor.
76 */
81
82/**
83 * Event handler for the dialog update timer.
84 *
85 * Updates the cycle count and simulation time. Also checks if the simulation
86 * is still running. If the simulation is no longer running, the dialog is
87 * closed automatically.
88 */
89void
91
93 // simualtion not running anymore
94 EndModal(wxID_OK);
95 }
96
98 cyclesCtrl_->SetLabel(WxConversion::toWxString((boost::format("%.0f") %
99 cycles).str()));
100 long time = watch_->Time();
101 unsigned seconds = (time / 1000) % 60;
102 unsigned minutes = (time / 1000) / 60;
103 wxString timeStr = WxConversion::toWxString(seconds);
104 if (seconds < 10) {
105 timeStr.Prepend(_T(":0"));
106 } else {
107 timeStr.Prepend(_T(":"));
108 }
109 timeStr.Prepend(WxConversion::toWxString(minutes));
110 timeCtrl_->SetLabel(timeStr);
111
112 if (time - time_ > 1000) {
113 int cps = (1000 * (cycles - cycles_)) / (time - time_);
114 wxString cpsStr = WxConversion::toWxString(cps);
115 cpsCtrl_->SetLabel(cpsStr);
116 time_ = time;
117 cycles_ = cycles;
118 }
119}
120
121/**
122 * Event handler for the Stop button.
123 *
124 * Request simulator stop and closes the dialog.
125 */
126void
127ProximStopDialog::onStop(wxCommandEvent&) {
129 EndModal(wxID_OK);
130}
131
132/**
133 * Event handler for the windowmanager dialog close button.
134 *
135 * Requests simulator stop and closes the dialog.
136 */
137void
140 EndModal(wxID_OK);
141}
142
143
144/**
145 * Creates the dialog widgets.
146 *
147 * Code generated by wxDesigner. Do not modify manually.
148 *
149 * @param parent Parent window of the dialog.
150 * @param call_fit If true, the parent window is resized to fit the widgets.
151 * @param set_sizer If true, Sets the created widgets as parent window
152 * contents.
153 */
154wxSizer*
156 wxWindow *parent, bool call_fit, bool set_sizer) {
157 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
158
159 item0->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
160
161 wxStaticText *item1 = new wxStaticText( parent, ID_TEXT, wxT("Simulation running..."), wxDefaultPosition, wxDefaultSize, 0 );
162 item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
163
164 item0->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
165
166 wxFlexGridSizer *item2 = new wxFlexGridSizer( 2, 0, 0 );
167
168 wxStaticText *item3 = new wxStaticText( parent, ID_LABEL_CYCLES, wxT("Cycles:"), wxDefaultPosition, wxDefaultSize, 0 );
169 item2->Add( item3, 0, wxALIGN_RIGHT|wxALL, 5 );
170
171 wxStaticText *item4 = new wxStaticText( parent, ID_CYCLES, wxT("???????????????????"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );
172 item2->Add( item4, 0, wxALL, 5 );
173
174 wxStaticText *item5 = new wxStaticText( parent, ID_LABEL_TIME, wxT("Time:"), wxDefaultPosition, wxDefaultSize, 0 );
175 item2->Add( item5, 0, wxALIGN_RIGHT|wxALL, 5 );
176
177 wxStaticText *item6 = new wxStaticText( parent, ID_TIME, wxT("???????????????????"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );
178 item2->Add( item6, 0, wxALL, 5 );
179
180 wxStaticText *item7 = new wxStaticText( parent, ID_LABEL_CPS, wxT("Avg. cycles/sec:"), wxDefaultPosition, wxDefaultSize, 0 );
181 item2->Add( item7, 0, wxALIGN_RIGHT|wxALL, 5 );
182
183 wxStaticText *item8 = new wxStaticText( parent, ID_CPS, wxT("???????????????????"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );
184 item2->Add( item8, 0, wxALL, 5 );
185
186 item0->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
187
188 wxStaticLine *item9 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(300,-1), wxLI_HORIZONTAL );
189 item0->Add( item9, 0, wxGROW|wxALL, 5 );
190
191 wxButton *item10 = new wxButton( parent, ID_STOP, wxT("&Stop"), wxDefaultPosition, wxDefaultSize, 0 );
192 item0->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
193
194 if (set_sizer)
195 {
196 parent->SetSizer( item0 );
197 if (call_fit)
198 item0->SetSizeHints( parent );
199 }
200
201 return item0;
202}
END_EVENT_TABLE() using namespace IDF
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
CycleCount ClockCycleCount
Alias for ClockCycleCount.
@ SRE_USER_REQUESTED
User requested the simulation to stop explicitly, e.g., by pressing ctrl-c in the CLI.
void onStop(wxCommandEvent &event)
void onUpdate(wxTimerEvent &event)
wxStopWatch * watch_
Stop watch measuring the simulation runtime.
wxStaticText * cyclesCtrl_
Text displaying the simulated cycle count.
static const int UPDATE_INTERVAL
Dialog update itnerval in milliseconds.
ClockCycleCount cycles_
Cycles simulated on the last cps update.
wxStaticText * timeCtrl_
Text displaying the elapsed simulation time.
wxStaticText * cpsCtrl_
Text displaying the average cps value.
virtual ~ProximStopDialog()
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
void onClose(wxCloseEvent &event)
long time_
Time elapsed on the cps update.
wxTimer * timer_
Timer which updates the dialog periodically.
SimulatorFrontend & frontend_
Simulator frontend to stop and track.
ClockCycleCount cycleCount() const
bool isSimulationRunning() const
void prepareToStop(StopReason reason)
static wxString toWxString(const std::string &source)