OpenASIP 2.2
Loading...
Searching...
No Matches
ProximToolbox.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 ProximToolbox.cc
26 *
27 * Implementation of ProximToolbox class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <string>
34#include <vector>
35#include "ProximToolbox.hh"
36#include "Proxim.hh"
39#include "ProximMainFrame.hh"
42#include "NullProgram.hh"
43#include "NullMachine.hh"
44#include "ProximConstants.hh"
45#include "ExpressionScript.hh"
46#include "TclConditionScript.hh"
47#include "ErrorDialog.hh"
48#include "WxConversion.hh"
50
51using std::string;
52using std::vector;
53
54/**
55 * The Constructor.
56 */
59
60
61/**
62 * Returns the simulated machine.
63 *
64 * Returns NullMachine, if a machine is not loaded in the simulator.
65 *
66 * @return Reference to the simulated machine.
67 */
70
71 TracedSimulatorFrontend* frontend = wxGetApp().simulation()->frontend();
72 if (frontend == NULL) {
74 } else {
75 return frontend->machine();
76 }
77}
78
79
80/**
81 * Returns the simulated program.
82 *
83 * Returns NullProgram, if a program is not loaded in the simulator.
84 *
85 * @return Reference to the simulated program.
86 */
89
90 TracedSimulatorFrontend* frontend = wxGetApp().simulation()->frontend();
91 if (frontend == NULL) {
93 } else {
94 return frontend->program();
95 }
96}
97
98
99/**
100 * Returns pointer to the application main frame.
101 *
102 * @return Application main frame, or NULL if the main frame does not exist.
103 */
106 wxWindow* topWindow = wxGetApp().GetTopWindow();
107 if (topWindow != NULL) {
108 return dynamic_cast<ProximMainFrame*>(topWindow);
109 } else {
110 return NULL;
111 }
112}
113
114
115/**
116 * Returns pointer to the machine state window.
117 *
118 * Returns NULL if the machine state window does not exist.
119 *
120 * @return Pointer to the machine state window.
121 */
124
125 wxWindow* topWindow = wxGetApp().GetTopWindow();
126
127 if (topWindow == NULL) {
128 return NULL;
129 }
130
131 wxWindow* machineWin = topWindow->FindWindowById(
133
134 if (machineWin == NULL) {
135 return NULL;
136 }
137
138 return dynamic_cast<ProximMachineStateWindow*>(machineWin);
139}
140
141
142/**
143 * Returns pointer to the program disassembly window.
144 *
145 * Returns NULL if the disassembly window does not exist.
146 *
147 * @return Pointer to the disassembly window.
148 */
151
152 wxWindow* topWindow = wxGetApp().GetTopWindow();
153
154 if (topWindow == NULL) {
155 return NULL;
156 }
157
158 wxWindow* disasmWin = topWindow->FindWindowById(
160
161 if (disasmWin == NULL) {
162 return NULL;
163 }
164
165 return dynamic_cast<ProximDisassemblyWindow*>(disasmWin);
166}
167
168
169/**
170 * Adds a new simulator window in it's own floating frame.
171 *
172 * @param window Window to add.
173 * @param title Title of the frame.
174 */
175void
177 wxWindow* window, const wxString& title, bool stayOnTop,
178 const wxSize& minSize) {
179
180 // Create a new frame for the window.
181 long style = wxDEFAULT_FRAME_STYLE;
182 if (stayOnTop) {
183 style = (style | wxFRAME_FLOAT_ON_PARENT);
184 }
185
186 wxFrame* frame = new wxFrame(
187 mainFrame(), -1, title, wxDefaultPosition, wxDefaultSize, style);
188
189 window->Reparent(frame);
190 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
191 sizer->Add(window, 1, wxGROW);
192 sizer->SetSizeHints(window);
193 frame->SetSizer(sizer);
194 frame->Fit();
195 frame->SetSizeHints(minSize.GetWidth(), minSize.GetHeight());
196 frame->Show();
197 return;
198}
199
200/**
201 * Returns pointer to the simulator control language interpreter used by the
202 * simulator backend.
203 *
204 * @return Simulator control language interpreter of the simulator.
205 */
208
209 ProximSimulationThread* simulation = wxGetApp().simulation();
210 if (simulation == NULL) {
211 return NULL;
212 }
213
214 return simulation->interpreter();
215}
216
217/**
218 * Returns pointer to the simulator's frontend.
219 *
220 * @return Simulator frontend.
221 */
224 if (wxGetApp().simulation() == NULL) {
225 return NULL;
226 } else {
227 return wxGetApp().simulation()->frontend();
228 }
229}
230
231
232/**
233 * Returns reference to the line reader used by the simulator engine.
234 *
235 * @return Simulator linereader.
236 */
239 return wxGetApp().simulation()->lineReader();
240}
241
242
243/**
244 * Tests expression script validity.
245 *
246 * An error dialog is displayed if the script is not legal.
247 *
248 * @param parent Parent window for the possible error dialog to display.
249 * @param expression Expression script to test.
250 */
251bool
253 wxWindow* parent, const std::string& expression) {
254
255 ExpressionScript expressionScript(interpreter(), expression);
256
257 // Check condition script validity using script interpreter.
258 try {
259 expressionScript.execute();
260 } catch (const ScriptExecutionFailure& sef) {
261 // Condition erroneous. Display error dialog.
262 wxString message = _T("Error in expression:\n");
263 message.Append(WxConversion::toWxString(sef.errorMessage()));
264 ErrorDialog dialog(parent, message);
265 dialog.ShowModal();
266 return false;
267 }
268 return true;
269}
270
271/**
272 * Tests condition script validity.
273 *
274 * An error dialog is displayed if the script is not legal.
275 *
276 * @param parent Parent window for the possible error dialog to display.
277 * @param condition Condition script to test.
278 */
279bool
281 wxWindow* parent, const std::string& condition) {
282
283 TclConditionScript conditionScript(interpreter(), condition);
284
285 // Check condition script validity using script interpreter.
286 try {
287 conditionScript.execute();
288 } catch (const ScriptExecutionFailure& sef) {
289 // Condition erroneous. Display error dialog.
290 wxString message = _T("Error in condition:\n");
291 message.Append(WxConversion::toWxString(sef.errorMessage()));
292 ErrorDialog dialog(parent, message);
293 dialog.ShowModal();
294 return false;
295 }
296 return true;
297}
std::string errorMessage() const
Definition Exception.cc:123
SimulatorInterpreter * interpreter()
static void addFramedWindow(wxWindow *window, const wxString &title, bool stayOnTop=false, const wxSize &minSize=wxSize(100, 100))
static const TTAMachine::Machine & machine()
static bool testExpression(wxWindow *parent, const std::string &expression)
ProximToolbox()
Instantiation not allowed.
static const TTAProgram::Program & program()
static ProximMainFrame * mainFrame()
static ProximLineReader & lineReader()
static SimulatorInterpreter * interpreter()
static TracedSimulatorFrontend * frontend()
static bool testCondition(wxWindow *parent, const std::string &condition)
static ProximMachineStateWindow * machineStateWindow()
static ProximDisassemblyWindow * disassemblyWindow()
virtual DataObject execute()
Definition Script.cc:82
const TTAMachine::Machine & machine() const
const TTAProgram::Program & program() const
static NullMachine & instance()
static NullProgram & instance()
static wxString toWxString(const std::string &source)