OpenASIP  2.0
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"
49 #include "SimulatorInterpreter.hh"
50 
51 using std::string;
52 using std::vector;
53 
54 /**
55  * The Constructor.
56  */
58 }
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  */
175 void
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  */
251 bool
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  */
279 bool
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 }
ProximMainFrame
Definition: ProximMainFrame.hh:58
TracedSimulatorFrontend
Definition: TracedSimulatorFrontend.hh:49
Script::execute
virtual DataObject execute()
Definition: Script.cc:82
TclConditionScript.hh
TTAProgram::Program
Definition: Program.hh:63
ProximConstants::ID_MACHINE_STATE_WINDOW
@ ID_MACHINE_STATE_WINDOW
Definition: ProximConstants.hh:92
ProximToolbox::frontend
static TracedSimulatorFrontend * frontend()
Definition: ProximToolbox.cc:223
WxConversion::toWxString
static wxString toWxString(const std::string &source)
ProximToolbox::testExpression
static bool testExpression(wxWindow *parent, const std::string &expression)
Definition: ProximToolbox.cc:252
ProximToolbox::mainFrame
static ProximMainFrame * mainFrame()
Definition: ProximToolbox.cc:105
SimulatorFrontend::program
const TTAProgram::Program & program() const
Definition: SimulatorFrontend.cc:276
ProximConstants::ID_DISASSEMBLY_WINDOW
@ ID_DISASSEMBLY_WINDOW
Definition: ProximConstants.hh:91
SimulatorFrontend::machine
const TTAMachine::Machine & machine() const
Definition: SimulatorFrontend.cc:263
ProximToolbox::testCondition
static bool testCondition(wxWindow *parent, const std::string &condition)
Definition: ProximToolbox.cc:280
ProximMachineStateWindow.hh
ExpressionScript
Definition: ExpressionScript.hh:44
ProximToolbox::program
static const TTAProgram::Program & program()
Definition: ProximToolbox.cc:88
ProximSimulationThread
Definition: ProximSimulationThread.hh:55
ProximSimulationThread::interpreter
SimulatorInterpreter * interpreter()
Definition: ProximSimulationThread.cc:244
ProximMachineStateWindow
Definition: ProximMachineStateWindow.hh:56
ProximSimulationThread.hh
Proxim.hh
TclConditionScript
Definition: TclConditionScript.hh:50
ProximDisassemblyWindow.hh
ProximToolbox::interpreter
static SimulatorInterpreter * interpreter()
Definition: ProximToolbox.cc:207
TTAProgram::NullProgram::instance
static NullProgram & instance()
Definition: NullProgram.cc:72
ProximToolbox.hh
NullMachine.hh
SimulatorInterpreter
Definition: SimulatorInterpreter.hh:49
ErrorDialog
Definition: ErrorDialog.hh:42
ErrorDialog.hh
ProximToolbox::addFramedWindow
static void addFramedWindow(wxWindow *window, const wxString &title, bool stayOnTop=false, const wxSize &minSize=wxSize(100, 100))
Definition: ProximToolbox.cc:176
ProximLineReader
Definition: ProximLineReader.hh:60
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
TTAMachine::NullMachine::instance
static NullMachine & instance()
Definition: NullMachine.cc:60
ProximToolbox::machineStateWindow
static ProximMachineStateWindow * machineStateWindow()
Definition: ProximToolbox.cc:123
ProximToolbox::machine
static const TTAMachine::Machine & machine()
Definition: ProximToolbox.cc:69
TracedSimulatorFrontend.hh
ProximConstants.hh
ScriptExecutionFailure
Definition: Exception.hh:657
ProximMainFrame.hh
SimulatorInterpreter.hh
WxConversion.hh
ProximToolbox::disassemblyWindow
static ProximDisassemblyWindow * disassemblyWindow()
Definition: ProximToolbox.cc:150
ProximDisassemblyWindow
Definition: ProximDisassemblyWindow.hh:58
NullProgram.hh
ProximToolbox::lineReader
static ProximLineReader & lineReader()
Definition: ProximToolbox.cc:238
ProximToolbox::ProximToolbox
ProximToolbox()
Instantiation not allowed.
Definition: ProximToolbox.cc:57
TTAMachine::Machine
Definition: Machine.hh:73
ExpressionScript.hh