OpenASIP 2.2
Loading...
Searching...
No Matches
ConsoleWindow.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 ConsoleWindow.cc
26 *
27 * Implementation of ConsoleWindow 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/textctrl.h>
34#include <wx/valtext.h>
35#include "ConsoleWindow.hh"
36#include "ProximLineReader.hh"
37#include "WxConversion.hh"
38#include "Proxim.hh"
40
41BEGIN_EVENT_TABLE(ConsoleWindow, ProximSimulatorWindow)
42 EVT_TEXT_ENTER(ID_INPUT, ConsoleWindow::textEntered)
49
50BEGIN_EVENT_TABLE(ConsoleWindow::ConsoleWindowInputCtrl, wxTextCtrl)
51 EVT_KEY_DOWN(ConsoleWindowInputCtrl::onKeyDown)
53
54
55//-----------------------------------------------------------------------------
56//
57// ConsoleWindowInputCtrl
58//
59//-----------------------------------------------------------------------------
60
61/**
62 * The Constructor.
63 *
64 * @param console Pointer to the parent console of the input widget.
65 */
67 ConsoleWindow* console) :
68 wxTextCtrl(console, ID_INPUT, _T(""), wxDefaultPosition,
69 wxSize(500,30), wxTE_PROCESS_ENTER),
70 console_(console) {
71
72}
73
74
75/**
76 * An event handler for the input control key events.
77 *
78 * Events are passed to the parent console's event handler.
79 *
80 * @param event Key press event to handle.
81 */
82void
86
87
88//-----------------------------------------------------------------------------
89//
90// ConsoleWindow
91//
92//-----------------------------------------------------------------------------
93
94
95/**
96 * The Constructor.
97 *
98 * @param parent Parent window of the console window.
99 * @param id Window identifier.
100 */
102 ProximMainFrame* parent,
103 wxWindowID id) :
104 ProximSimulatorWindow(parent, id),
105 outTextCtrl_(NULL),
106 inTextCtrl_(NULL),
107 historyIterator_(-1) {
108
110 lineReader_ = &wxGetApp().simulation()->lineReader();
111}
112
113
114/**
115 * The Destructor.
116 */
119
120/**
121 * Called when the simulator program, machine and memory models are deleted.
122 */
123void
125 // Do nothing.
126}
127
128
129/**
130 * Event handler for the user input to the text input widget.
131 *
132 * The text is passed to the linereader as input.
133 */
134void
136 std::string command = WxConversion::toString(inTextCtrl_->GetLineText(0));
137 lineReader_->input(command);
138 historyIterator_ = -1;
139 inTextCtrl_->Clear();
140}
141
142
143
144/**
145 * Appends text to the output window.
146 *
147 * @param text Text to append to the output window.
148 */
149void
150ConsoleWindow::write(std::string text) {
151
152 if (text == "") {
153 return;
154 }
155 wxString output = WxConversion::toWxString(text);
156 outTextCtrl_->AppendText(output);
157}
158
159
160/**
161 * Creates the window widgets.
162 */
163void
165
166 // output widget
167 outTextCtrl_ = new wxTextCtrl(
168 this, ID_OUTPUT, _T(""), wxDefaultPosition, wxDefaultSize,
169 wxTE_MULTILINE | wxTE_READONLY);
170
171 // input widget
173
174 // Sizer responsible for the window layout.
175 wxFlexGridSizer* sizer = new wxFlexGridSizer(1, 0, 0);
176 sizer->AddGrowableCol(0);
177 sizer->AddGrowableRow(0);
178
179 sizer->Add(outTextCtrl_, 0, wxGROW | wxALL, 5);
180 sizer->Add(inTextCtrl_, 0, wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5);
181 SetSizer(sizer);
182 sizer->SetSizeHints(this);
183}
184
185
186/**
187 * Handles simulator text output events.
188 *
189 * The event data contains the simulator interpreter output, which is appended
190 * to the text output widget.
191 *
192 * @param event Simulator interpreter text output event.
193 */
194void
196 // Append text to the output widget.
197 std::string text = event.data();
198 outTextCtrl_->AppendText(WxConversion::toWxString(text));
199 outTextCtrl_->ShowPosition(outTextCtrl_->GetLastPosition());
200}
201
202
203/**
204 * Handles simulator error events.
205 *
206 * The error text is printed in the console.
207 *
208 * @param event Simulator interpreter command event.
209 */
210void
212 std::string error = event.data();
213 wxTextAttr oldStyle = outTextCtrl_->GetDefaultStyle();
214 outTextCtrl_->SetDefaultStyle(wxTextAttr(*wxRED));
215 outTextCtrl_->AppendText(WxConversion::toWxString("\n" + error + "\n"));
216 outTextCtrl_->SetDefaultStyle(oldStyle);
217}
218
219
220/**
221 * Handles special keypresses in the input widget.
222 *
223 * @param event Keypress event to handle.
224 */
225void
226ConsoleWindow::onInputKey(wxKeyEvent& event) {
227
228 if (event.GetKeyCode() == WXK_UP) {
229 // Up key. Browses the command history backward.
233 return;
234 }
235 } else if (event.GetKeyCode() == WXK_DOWN) {
236 // Down key. Browses the command history forward.
237 if (historyIterator_ < 0) {
238 return;
239 }
241 } else {
242 // Key with no special fucntion. The key event is skipped.
243 event.Skip();
244 return;
245 }
246
247 // If the command history is browsed back to top, the
248 // input widget is cleared.
249 if (historyIterator_ < 0) {
250 inTextCtrl_->Clear();
251 return;
252 }
253
254 // Command browsed from the command history is set as the input
255 // widget value.
256 wxString command = WxConversion::toWxString(
258
259 inTextCtrl_->SetValue(command);
260 inTextCtrl_->SetInsertionPointEnd();
261}
262
263
264
265/**
266 * Clears text from the output text widget.
267 */
268void
270 outTextCtrl_->Clear();
271}
272
273/**
274 * An event handler for the event of the simulator to start processing
275 * a command.
276 *
277 * The Console window must stay enabled when the simulator is busy, so this
278 * method is overloaded to not to lock the window.
279 */
280void
284
285/**
286 * An event handler for the event of the simulator to complete command
287 * processing.
288 *
289 * The Console window is not locked during simulator processing, so there's
290 * no need to do anything.
291 */
292void
END_EVENT_TABLE() using namespace IDF
#define EVT_SIMULATOR_RUNTIME_WARNING(id, fn)
#define EVT_SIMULATOR_OUTPUT(id, fn)
#define EVT_SIMULATOR_RUNTIME_ERROR(id, fn)
#define EVT_SIMULATOR_COMMAND(id, fn)
#define EVT_SIMULATOR_ERROR(id, fn)
ConsoleWindow * console_
Parent console of the widget.
virtual void onSimulatorDone(SimulatorEvent &event)
virtual void onSimulatorBusy(SimulatorEvent &event)
void onSimulatorOutput(const SimulatorEvent &event)
virtual ~ConsoleWindow()
ProximLineReader * lineReader_
Linereader to send the user input to.
ConsoleWindow(ProximMainFrame *parent, wxWindowID id)
void textEntered(wxCommandEvent &event)
wxTextCtrl * inTextCtrl_
Input text control.
void onInputKey(wxKeyEvent &event)
int historyIterator_
Stores the command history iterator, used for command history browsing.
void write(std::string text)
wxTextCtrl * outTextCtrl_
Output text control.
void onError(const SimulatorEvent &event)
virtual void reset()
virtual std::size_t inputsInHistory() const
virtual std::string inputHistoryEntry(std::size_t age) const
void input(std::string command)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)