OpenASIP  2.0
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 
39 const int ProximStopDialog::UPDATE_INTERVAL = 100;
40 
41 BEGIN_EVENT_TABLE(ProximStopDialog, wxDialog)
42  EVT_CLOSE(ProximStopDialog::onClose)
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  */
78  delete timer_;
79  delete watch_;
80 }
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  */
89 void
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  */
126 void
127 ProximStopDialog::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  */
137 void
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  */
154 wxSizer*
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 }
WxConversion::toWxString
static wxString toWxString(const std::string &source)
ProximStopDialog::cycles_
ClockCycleCount cycles_
Cycles simulated on the last cps update.
Definition: ProximStopDialog.hh:94
ProximStopDialog::time_
long time_
Time elapsed on the cps update.
Definition: ProximStopDialog.hh:92
SRE_USER_REQUESTED
@ SRE_USER_REQUESTED
User requested the simulation to stop explicitly, e.g., by pressing ctrl-c in the CLI.
Definition: SimulatorConstants.hh:66
ProximStopDialog::ID_LABEL_TIME
@ ID_LABEL_TIME
Definition: ProximStopDialog.hh:68
ProximStopDialog::ID_TIME
@ ID_TIME
Definition: ProximStopDialog.hh:69
FindWindow
Definition: FindWindow.hh:49
ProximStopDialog::ID_STOP
@ ID_STOP
Definition: ProximStopDialog.hh:65
ProximStopDialog::ID_LABEL_CPS
@ ID_LABEL_CPS
Definition: ProximStopDialog.hh:70
ProximStopDialog::frontend_
SimulatorFrontend & frontend_
Simulator frontend to stop and track.
Definition: ProximStopDialog.hh:77
ProximStopDialog::ID_CPS
@ ID_CPS
Definition: ProximStopDialog.hh:71
ProximStopDialog::cyclesCtrl_
wxStaticText * cyclesCtrl_
Text displaying the simulated cycle count.
Definition: ProximStopDialog.hh:87
ProximStopDialog::ID_CYCLES
@ ID_CYCLES
Definition: ProximStopDialog.hh:67
ProximStopDialog::timeCtrl_
wxStaticText * timeCtrl_
Text displaying the elapsed simulation time.
Definition: ProximStopDialog.hh:85
ProximStopDialog::watch_
wxStopWatch * watch_
Stop watch measuring the simulation runtime.
Definition: ProximStopDialog.hh:82
ProximStopDialog
Definition: ProximStopDialog.hh:47
SimulatorFrontend.hh
SimulatorFrontend::isSimulationRunning
bool isSimulationRunning() const
Definition: SimulatorFrontend.cc:1260
ProximStopDialog::onStop
void onStop(wxCommandEvent &event)
Definition: ProximStopDialog.cc:127
SimulatorFrontend::cycleCount
ClockCycleCount cycleCount() const
Definition: SimulatorFrontend.cc:1194
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
ProximStopDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: ProximStopDialog.cc:155
ProximStopDialog::ID_TEXT
@ ID_TEXT
Definition: ProximStopDialog.hh:72
ProximStopDialog::cpsCtrl_
wxStaticText * cpsCtrl_
Text displaying the average cps value.
Definition: ProximStopDialog.hh:89
ProximStopDialog::ID_LINE
@ ID_LINE
Definition: ProximStopDialog.hh:73
ProximStopDialog::onClose
void onClose(wxCloseEvent &event)
Definition: ProximStopDialog.cc:138
ClockCycleCount
CycleCount ClockCycleCount
Alias for ClockCycleCount.
Definition: SimulatorConstants.hh:57
ProximStopDialog::onUpdate
void onUpdate(wxTimerEvent &event)
Definition: ProximStopDialog.cc:90
WxConversion.hh
ProximStopDialog.hh
ProximStopDialog::timer_
wxTimer * timer_
Timer which updates the dialog periodically.
Definition: ProximStopDialog.hh:80
ProximStopDialog::~ProximStopDialog
virtual ~ProximStopDialog()
Definition: ProximStopDialog.cc:77
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
ProximStopDialog::ID_LABEL_CYCLES
@ ID_LABEL_CYCLES
Definition: ProximStopDialog.hh:66
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
ProximStopDialog::UPDATE_INTERVAL
static const int UPDATE_INTERVAL
Dialog update itnerval in milliseconds.
Definition: ProximStopDialog.hh:97
SimulatorFrontend::prepareToStop
void prepareToStop(StopReason reason)
Definition: SimulatorFrontend.cc:1331