OpenASIP 2.2
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ConsoleWindow Class Reference

#include <ConsoleWindow.hh>

Inheritance diagram for ConsoleWindow:
Inheritance graph
Collaboration diagram for ConsoleWindow:
Collaboration graph

Classes

class  ConsoleWindowInputCtrl
 

Public Member Functions

 ConsoleWindow (ProximMainFrame *parent, wxWindowID id)
 
virtual ~ConsoleWindow ()
 
virtual void reset ()
 
void write (std::string text)
 
void clear ()
 

Private Types

enum  { ID_INPUT = 20000 , ID_OUTPUT }
 IDs for the window widgets. More...
 

Private Member Functions

virtual void onSimulatorBusy (SimulatorEvent &event)
 
virtual void onSimulatorDone (SimulatorEvent &event)
 
void createContents ()
 
void onSimulatorOutput (const SimulatorEvent &event)
 
void onError (const SimulatorEvent &event)
 
void textEntered (wxCommandEvent &event)
 
void onInputKey (wxKeyEvent &event)
 

Private Attributes

wxTextCtrl * outTextCtrl_
 Output text control.
 
wxTextCtrl * inTextCtrl_
 Input text control.
 
ProximLineReaderlineReader_
 Linereader to send the user input to.
 
int historyIterator_
 Stores the command history iterator, used for command history browsing.
 

Additional Inherited Members

- Protected Member Functions inherited from ProximSimulatorWindow
 ProximSimulatorWindow (ProximMainFrame *mainFrame, wxWindowID id=-1, wxPoint pos=wxDefaultPosition, wxSize size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
 
virtual ~ProximSimulatorWindow ()
 

Detailed Description

Simulator console window class.

ConsoleWindow is a console with a multiline textual output window, and a singleline textual input widget. Commands are requested from the console window using SimulatorEvents.

Definition at line 51 of file ConsoleWindow.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

IDs for the window widgets.

Enumerator
ID_INPUT 
ID_OUTPUT 

Definition at line 78 of file ConsoleWindow.hh.

78 {
79 ID_INPUT = 20000,
81 };

Constructor & Destructor Documentation

◆ ConsoleWindow()

ConsoleWindow::ConsoleWindow ( ProximMainFrame parent,
wxWindowID  id 
)

The Constructor.

Parameters
parentParent window of the console window.
idWindow identifier.

Definition at line 101 of file ConsoleWindow.cc.

103 :
104 ProximSimulatorWindow(parent, id),
105 outTextCtrl_(NULL),
106 inTextCtrl_(NULL),
107 historyIterator_(-1) {
108
110 lineReader_ = &wxGetApp().simulation()->lineReader();
111}
ProximLineReader * lineReader_
Linereader to send the user input to.
wxTextCtrl * inTextCtrl_
Input text control.
int historyIterator_
Stores the command history iterator, used for command history browsing.
wxTextCtrl * outTextCtrl_
Output text control.

References createContents(), and lineReader_.

Here is the call graph for this function:

◆ ~ConsoleWindow()

ConsoleWindow::~ConsoleWindow ( )
virtual

The Destructor.

Definition at line 117 of file ConsoleWindow.cc.

117 {
118}

Member Function Documentation

◆ clear()

void ConsoleWindow::clear ( )

Clears text from the output text widget.

Definition at line 269 of file ConsoleWindow.cc.

269 {
270 outTextCtrl_->Clear();
271}

References outTextCtrl_.

Referenced by ProximClearConsoleCmd::Do().

◆ createContents()

void ConsoleWindow::createContents ( )
private

Creates the window widgets.

Definition at line 164 of file ConsoleWindow.cc.

164 {
165
166 // output widget
167 outTextCtrl_ = new wxTextCtrl(
168 this, ID_OUTPUT, _T(""), wxDefaultPosition, wxDefaultSize,
169 wxTE_MULTILINE | wxTE_READONLY);
170
171 // input widget
172 inTextCtrl_ = new ConsoleWindowInputCtrl(this);
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}

References ID_OUTPUT, inTextCtrl_, and outTextCtrl_.

Referenced by ConsoleWindow().

◆ onError()

void ConsoleWindow::onError ( const SimulatorEvent event)
private

Handles simulator error events.

The error text is printed in the console.

Parameters
eventSimulator interpreter command event.

Definition at line 211 of file ConsoleWindow.cc.

211 {
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}
static wxString toWxString(const std::string &source)

References outTextCtrl_, and WxConversion::toWxString().

Here is the call graph for this function:

◆ onInputKey()

void ConsoleWindow::onInputKey ( wxKeyEvent &  event)
private

Handles special keypresses in the input widget.

Parameters
eventKeypress event to handle.

Definition at line 226 of file ConsoleWindow.cc.

226 {
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}
virtual std::size_t inputsInHistory() const
virtual std::string inputHistoryEntry(std::size_t age) const

References historyIterator_, LineReader::inputHistoryEntry(), LineReader::inputsInHistory(), inTextCtrl_, lineReader_, and WxConversion::toWxString().

Referenced by ConsoleWindow::ConsoleWindowInputCtrl::onKeyDown().

Here is the call graph for this function:

◆ onSimulatorBusy()

void ConsoleWindow::onSimulatorBusy ( SimulatorEvent event)
privatevirtual

An event handler for the event of the simulator to start processing a command.

The Console window must stay enabled when the simulator is busy, so this method is overloaded to not to lock the window.

Reimplemented from ProximSimulatorWindow.

Definition at line 281 of file ConsoleWindow.cc.

281 {
282 // Do nothing.
283}

◆ onSimulatorDone()

void ConsoleWindow::onSimulatorDone ( SimulatorEvent event)
privatevirtual

An event handler for the event of the simulator to complete command processing.

The Console window is not locked during simulator processing, so there's no need to do anything.

Reimplemented from ProximSimulatorWindow.

Definition at line 293 of file ConsoleWindow.cc.

293 {
294 // Do nothing.
295}

◆ onSimulatorOutput()

void ConsoleWindow::onSimulatorOutput ( const SimulatorEvent event)
private

Handles simulator text output events.

The event data contains the simulator interpreter output, which is appended to the text output widget.

Parameters
eventSimulator interpreter text output event.

Definition at line 195 of file ConsoleWindow.cc.

195 {
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}

References outTextCtrl_, and WxConversion::toWxString().

Here is the call graph for this function:

◆ reset()

void ConsoleWindow::reset ( )
virtual

Called when the simulator program, machine and memory models are deleted.

Reimplemented from ProximSimulatorWindow.

Definition at line 124 of file ConsoleWindow.cc.

124 {
125 // Do nothing.
126}

◆ textEntered()

void ConsoleWindow::textEntered ( wxCommandEvent &  event)
private

Event handler for the user input to the text input widget.

The text is passed to the linereader as input.

Definition at line 135 of file ConsoleWindow.cc.

135 {
136 std::string command = WxConversion::toString(inTextCtrl_->GetLineText(0));
137 lineReader_->input(command);
138 historyIterator_ = -1;
139 inTextCtrl_->Clear();
140}
void input(std::string command)
static std::string toString(const wxString &source)

References historyIterator_, ProximLineReader::input(), inTextCtrl_, lineReader_, and WxConversion::toString().

Here is the call graph for this function:

◆ write()

void ConsoleWindow::write ( std::string  text)

Appends text to the output window.

Parameters
textText to append to the output window.

Definition at line 150 of file ConsoleWindow.cc.

150 {
151
152 if (text == "") {
153 return;
154 }
155 wxString output = WxConversion::toWxString(text);
156 outTextCtrl_->AppendText(output);
157}

References outTextCtrl_, and WxConversion::toWxString().

Here is the call graph for this function:

Member Data Documentation

◆ historyIterator_

int ConsoleWindow::historyIterator_
private

Stores the command history iterator, used for command history browsing.

Definition at line 75 of file ConsoleWindow.hh.

Referenced by onInputKey(), and textEntered().

◆ inTextCtrl_

wxTextCtrl* ConsoleWindow::inTextCtrl_
private

Input text control.

Definition at line 71 of file ConsoleWindow.hh.

Referenced by createContents(), onInputKey(), and textEntered().

◆ lineReader_

ProximLineReader* ConsoleWindow::lineReader_
private

Linereader to send the user input to.

Definition at line 73 of file ConsoleWindow.hh.

Referenced by ConsoleWindow(), onInputKey(), and textEntered().

◆ outTextCtrl_

wxTextCtrl* ConsoleWindow::outTextCtrl_
private

Output text control.

Definition at line 69 of file ConsoleWindow.hh.

Referenced by clear(), createContents(), onError(), onSimulatorOutput(), and write().


The documentation for this class was generated from the following files: