OpenASIP 2.2
Loading...
Searching...
No Matches
ProximMainFrame.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2017 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 ProximMainFrame.cc
26 *
27 * Implementation of ProximMainFrame 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/progdlg.h>
34#include <boost/format.hpp>
35
36#include "ProximMainFrame.hh"
37#include "ProximConstants.hh"
38#include "ErrorDialog.hh"
39#include "WarningDialog.hh"
40#include "GUICommand.hh"
41#include "Proxim.hh"
42#include "WxConversion.hh"
43#include "ContainerTools.hh"
44#include "Exception.hh"
45#include "ProximToolbox.hh"
46#include "Environment.hh"
47#include "FileSystem.hh"
48#include "GUIOptions.hh"
49
52#include "ProximCDCmd.hh"
53#include "ProximRunCmd.hh"
54#include "ProximStepICmd.hh"
55#include "ProximNextICmd.hh"
56#include "ProximResumeCmd.hh"
57#include "ProximKillCmd.hh"
58#include "ProximQuitCmd.hh"
60#include "ProximAboutCmd.hh"
64#include "ProximOptionsCmd.hh"
69#include "UserManualCmd.hh"
70#include "ProximFindCmd.hh"
71
72#include "ConsoleWindow.hh"
74#include "ProximMemoryWindow.hh"
77#include "ProximPortWindow.hh"
83#include "ProximStopDialog.hh"
85#include "MemorySystem.hh"
87
88BEGIN_EVENT_TABLE(ProximMainFrame, wxFrame)
89 EVT_KEY_DOWN(ProximMainFrame::onKeyEvent)
92 ProximConstants::COMMAND_LAST,
93 ProximMainFrame::onCommandEvent)
94 EVT_MENU_RANGE(ProximConstants::COMMAND_TOGGLE_CONSOLE_WIN,
95 ProximConstants::COMMAND_TOGGLE_BREAKPOINT_WIN,
96 ProximMainFrame::onToggleWindow)
97 EVT_MENU(UserManualCmd::COMMAND_ID, ProximMainFrame::onCommandEvent)
98 EVT_COMMAND_RANGE(ProximConstants::COMMAND_FIRST,
99 ProximConstants::COMMAND_LAST,
100 wxEVT_COMMAND_BUTTON_CLICKED,
101 ProximMainFrame::onCommandEvent)
102 EVT_UPDATE_UI_RANGE(ProximConstants::COMMAND_FIRST,
103 ProximConstants::COMMAND_LAST,
104 ProximMainFrame::updateCommand)
105
106 EVT_UPDATE_UI_RANGE(ProximConstants::COMMAND_TOGGLE_CONSOLE_WIN,
107 ProximConstants::COMMAND_TOGGLE_BREAKPOINT_WIN,
108 ProximMainFrame::updateToggleItem)
109
110 EVT_SIMULATOR_START(0, ProximMainFrame::onSimulatorEvent)
111 EVT_SIMULATOR_STOP(0, ProximMainFrame::onSimulatorEvent)
112 EVT_SIMULATOR_RUN(0, ProximMainFrame::onSimulatorEvent)
113 EVT_SIMULATOR_OUTPUT(0, ProximMainFrame::onSimulatorEvent)
114 EVT_SIMULATOR_ERROR(0, ProximMainFrame::onSimulatorEvent)
115 EVT_SIMULATOR_COMMAND(0, ProximMainFrame::onSimulatorEvent)
116 EVT_SIMULATOR_COMMAND_DONE(0, ProximMainFrame::onSimulatorEvent)
121 EVT_SIMULATOR_RUNTIME_ERROR(0, ProximMainFrame::onSimulatorEvent)
123 EVT_SIMULATOR_TERMINATED(0, ProximMainFrame::onSimulatorTerminated)
126
127/**
128 * The constructor.
129 *
130 * @param title Frame title.
131 * @param pos Frame position on screen.
132 * @param size Frame size.
133 */
135 const wxString& title,
136 const wxPoint& pos,
137 const wxSize& size):
138 wxFrame((wxFrame*)NULL, -1, title, pos, size),
139 topSplitter_(NULL), toolbar_(NULL), stopDialogInstantiated_(false),
140 isReset_(false) {
141
142 CommandRegistry& cmdRegistry = wxGetApp().commandRegistry();
143 cmdRegistry.addCommand(new ProximOpenMachineCmd());
144 cmdRegistry.addCommand(new ProximOpenProgramCmd());
145 cmdRegistry.addCommand(new ProximCDCmd());
146 cmdRegistry.addCommand(new ProximRunCmd());
147 cmdRegistry.addCommand(new ProximStepICmd());
148 cmdRegistry.addCommand(new ProximNextICmd());
149 cmdRegistry.addCommand(new ProximResumeCmd());
150 cmdRegistry.addCommand(new ProximKillCmd());
151 cmdRegistry.addCommand(new ProximQuitCmd());
152 cmdRegistry.addCommand(new ProximClearConsoleCmd());
153 cmdRegistry.addCommand(new ProximAboutCmd());
154 cmdRegistry.addCommand(new ProximNewPortWindowCmd());
155 cmdRegistry.addCommand(new ProximNewRegisterWindowCmd());
156 cmdRegistry.addCommand(new ProximSimulatorSettingsCmd());
157 cmdRegistry.addCommand(new ProximOptionsCmd());
158 cmdRegistry.addCommand(new ProximExecuteFileCmd());
159 cmdRegistry.addCommand(new HighlightTopExecCountsCmd());
160 cmdRegistry.addCommand(new HighlightExecPercentageCmd());
161 cmdRegistry.addCommand(new ClearDisassemblyHighlightCmd());
162 cmdRegistry.addCommand(new UserManualCmd());
163 cmdRegistry.addCommand(new ProximFindCmd());
164
165 resetMutex_ = new wxMutex();
166 resetCondition_ = new wxCondition(*resetMutex_);
167
168 initialize();
169
170}
171
172
173/**
174 * The destructor.
175 */
179
180
181/**
182 * Initializes the frame instance.
183 *
184 * Creates the sizer managing the window layout, and creates an instance
185 * of the default windows.
186 */
187void
189
191
192 wxStatusBar* statusbar = CreateStatusBar();
193 int widths[3] = {-1, 200, 200};
194 statusbar->SetFieldsCount(3, widths);
195
196 sizer_ = new wxBoxSizer(wxVERTICAL);
197
200
201 dockWindow(disasmWindow);
203 SetSizer(sizer_);
204
206
207 SetSizeHints(400, 300);
208}
209
210/**
211 * Closes the GUI when the simulator engine is terminated.
212 */
213void
217
218
219/**
220 * Creates the proxim main frame menubar.
221 */
222void
224
225 wxMenu* fileMenu = new wxMenu();
226 wxMenu* viewMenu = new wxMenu();
227 wxMenu* editMenu = new wxMenu();
228 wxMenu* commandMenu = new wxMenu();
229 wxMenu* sourceMenu = new wxMenu();
230 wxMenu* programMenu = new wxMenu();
231 wxMenu* dataMenu = new wxMenu();
232 wxMenu* helpMenu = new wxMenu();
233 wxMenu* highlightMenu = new wxMenu();
234
235 // File menu
236 fileMenu->Append(
239 _T("Open &Machine...")));
240
241 fileMenu->Append(
244 _T("Open &Program...")));
245
246 fileMenu->Append(
249 _T("&Change Directory...")));
250
251 fileMenu->AppendSeparator();
252
253 fileMenu->Append(
256 _T("&Quit")));
257
258 wxMenuBar* menuBar = new wxMenuBar;
259 menuBar->Append(fileMenu, _T("&File"));
260
261 // View menu
262 viewMenu->AppendCheckItem(
264 _T("&Simulator Console"));
265
266 viewMenu->AppendCheckItem(
268 _T("Program &Disassembly"));
269
270 viewMenu->AppendCheckItem(
272 _T("&Memory Window"));
273
274 viewMenu->AppendCheckItem(
276 _T("Simulator &Control"));
277
278 viewMenu->AppendCheckItem(
280 _T("&Machine Window"));
281
282 viewMenu->AppendCheckItem(
284 _T("&Breakpoint Window"));
285
286 viewMenu->AppendCheckItem(
288 _T("&Debugger Window"));
289
290 viewMenu->AppendSeparator();
291 viewMenu->Append(
294 _T("New &Register Window")));
295
296 viewMenu->Append(
299 _T("New &Port Window")));
300
301 viewMenu->Check(ProximConstants::COMMAND_TOGGLE_CONSOLE_WIN, true);
302 viewMenu->Check(ProximConstants::COMMAND_TOGGLE_DISASM_WIN, true);
303 viewMenu->Enable(ProximConstants::COMMAND_TOGGLE_CONSOLE_WIN, false);
304 viewMenu->Enable(ProximConstants::COMMAND_TOGGLE_DISASM_WIN, false);
305
306 menuBar->Append(viewMenu, _T("&View"));
307
308 editMenu->Append(
311 _T("Simulator Settings...")));
312
313 editMenu->Append(
316 _T("Options...")));
317
318 // Edit menu
319 menuBar->Append(editMenu, _T("&Edit"));
320
321 // Command menu
322 commandMenu->Append(
325 _T("&Clear Console")));
326
327 commandMenu->Append(
330 _T("&Execute File...")));
331
332 commandMenu->Append(
335 _T("&Find in disassembly...")));
336
337 commandMenu->AppendSeparator();
338 commandMenu->AppendCheckItem(
340 _T("Command &History Window"));
341
342 menuBar->Append(commandMenu, _T("&Command"));
343
344 // Source menu
345 menuBar->Append(sourceMenu, _T("&Source"));
346 sourceMenu->Append(17000, _T("&Profile Data"), highlightMenu);
347
348 highlightMenu->Append(
352 _T("None")));
353
354 highlightMenu->Append(
358 _T("Highlight Top Execution Counts")));
359
360 highlightMenu->Append(
364 _T("Highlight Move Executions")));
365
366 // Program menu
367 programMenu->Append(
369 menuAccelerator(ProximConstants::COMMAND_RUN).Prepend(_T("&Run")));
370
371 programMenu->AppendSeparator();
372
373 programMenu->Append(
376 _T("&Step Instruction")));
377
378 programMenu->Append(
381 _T("&Next Instruction")));
382
383 programMenu->Append(
386 _T("R&esume")));
387
388 programMenu->AppendSeparator();
389 programMenu->Append(
391 menuAccelerator(ProximConstants::COMMAND_KILL).Prepend(_T("&Kill")));
392
393 menuBar->Append(programMenu, _T("&Program"));
394
395 // Data menu
396 menuBar->Append(dataMenu, _T("&Data"));
397
398 // Help menu
399 helpMenu->Append(
402 _T("&User Manual...")));
403
404 helpMenu->Append(
407 _T("&About...")));
408
409 menuBar->Append(helpMenu, _T("&Help"));
410
411 SetMenuBar(menuBar);
412
414}
415
416/**
417 * Creates the main frame toolbar.
418 */
419void
421
422 if (toolbar_ != NULL) {
423 delete toolbar_;
424 toolbar_ = NULL;
425 }
426
427 CommandRegistry& registry = wxGetApp().commandRegistry();
428 GUIOptions& options = wxGetApp().options();
430
431 toolbar_ = options.createToolbar(this, registry, iconPath);
432
433 SetToolBar(toolbar_);
434 toolbar_->Show(options.toolbarVisibility());
435}
436
437
438/**
439 * Returns a menu accelerator string for a command.
440 *
441 * The returned string can be appended to the menu item text to set the
442 * keyboard shortcut defined in the options for the command.
443 *
444 * @param id Command ID.
445 * @return Accelerator string.
446 */
447wxString
449
450 const CommandRegistry& reg = wxGetApp().commandRegistry();
451 const GUIOptions& options = wxGetApp().options();
452 std::string cmdName = reg.commandName(id);
453 const KeyboardShortcut* sc = options.keyboardShortcut(cmdName);
454
455 if (sc != NULL) {
456 wxString accel = _T("\t");
457 if (sc->ctrl()) {
458 accel.Append(_T("Ctrl-"));
459 accel.Append(WxConversion::toWxString(sc->key()));
460 return accel;
461 } else if (sc->alt()) {
462 accel.Append(_T("Alt-"));
463 accel.Append(WxConversion::toWxString(sc->key()));
464 return accel;
465 } else if (sc->fKey() > 0) {
466 accel.Append(_T("F"));
467 accel.Append(WxConversion::toWxString(sc->fKey()));
468 return accel;
469 } else {
470 // Invalid shortcut.
471 return _T("");
472 }
473 }
474
475 return _T("");
476}
477
478
479/**
480 * Handles command events from the menubar.
481 *
482 * Commands are handled using Proxim command registry. A command is
483 * requested from the registry with the command event ID. If a command
484 * is found in the registry, the command will be executed. Otherwise
485 * an errordialog is displayed.
486 *
487 * @param event Command event to handle.
488 */
489void
490ProximMainFrame::onCommandEvent(wxCommandEvent& event) {
491
492 GUICommand* command =
493 wxGetApp().commandRegistry().createCommand(event.GetId());
494
495 if (command == NULL) {
496 ErrorDialog dialog(
497 this, _T("No handler found for the command event"));
498 dialog.ShowModal();
499 return;
500 }
501
502 command->setParentWindow(this);
503 command->Do();
504 delete command;
505}
506
507
508/**
509 * Docks a simulation subwindow to the mainframe.
510 *
511 * @param window Sub window to add.
512 */
513void
515
516 // If the frame is empty, the window is added directly to the sizer
517 // w/o a splitterwindow.
518 if (topSplitter_ == NULL) {
519 topSplitter_ = window;
520 sizer_->Add(window);
521 return;
522 }
523
524 // The frame already contained window(s). A new splitter window is created,
525 // and the old contents of the frame is set as the top half of the
526 // splitter window, and the new window as the bottom half of the
527 // splitter. Finally, the old contents of the frame is replaced with the
528 // new splitter window.
529 sizer_->Detach(topSplitter_);
530 wxSplitterWindow* newSplitter = new wxSplitterWindow(this, wxHORIZONTAL);
531 newSplitter->SetMinimumPaneSize(25);
532 window->Reparent(newSplitter);
533 topSplitter_->Reparent(newSplitter);
534 newSplitter->SplitHorizontally(topSplitter_, window);
535 topSplitter_ = newSplitter;
536 sizer_->Add(newSplitter, 1, wxGROW);
537 sizer_->Layout();
538 newSplitter->SetSashPosition(topSplitter_->GetSize().GetHeight() / 2);
539}
540
541
542
543/**
544 * Handles simulator events.
545 *
546 * The events are passed to all subwindows registered as simulator listeners.
547 *
548 * @param event Simulator event to handle.
549 */
550void
552
554
555 WXTYPE eventType = event.GetEventType();
556
557 if (eventType == SimulatorEvent::EVT_SIMULATOR_COMMAND) {
558 wxSetCursor(*wxHOURGLASS_CURSOR);
559 wxString status = _T("Executing command '");
560 status.Append(WxConversion::toWxString(event.data()));
561 status.Append(_T("'."));
562 GetStatusBar()->SetStatusText(status);
563 GetMenuBar()->Disable();
564
565 // If a toolbar button is disabled and re-enabled when a mouse cursor
566 // is over the button, the button can't be clicked until the cursor
567 // is moved away from the button and back over it. This prevents
568 // stepi button to work when clicked repeatedly. Stepi
569 // commands do not disable toolbar buttons when executed to avoid
570 // this problem.
571 std::string command = event.data();
573 GetToolBar()->Disable();
574 }
575 }
576
578 wxSetCursor(*wxSTANDARD_CURSOR);
579 GetStatusBar()->SetStatusText(_T(""));
580 GetMenuBar()->Enable();
581
582 std::string command = event.data();
583 // Kludge to make stepi button to work better. See comment
584 // in the previous if-clause.
586 GetToolBar()->Enable();
587 }
588 }
589
591 wxString message = WxConversion::toWxString(event.data());
592 ErrorDialog dialog(this, message);
593 dialog.ShowModal();
594 }
595
597 wxString message = WxConversion::toWxString(event.data());
598 WarningDialog dialog(this, message);
599 dialog.ShowModal();
600 }
601
602 // Loading program.
604 wxString message = _T("Loading program... ");
605 message.Append(WxConversion::toWxString(event.data()));
606 GetStatusBar()->SetStatusText(message);
607 }
608
609 // Program loaded
611 wxString message = _T("Program loaded.");
612 GetStatusBar()->SetStatusText(message);
614 }
615
616 // Loading machine.
618 wxString message = _T("Loading machine... ");
619 message.Append(WxConversion::toWxString(event.data()));
620 GetStatusBar()->SetStatusText(message);
621 }
622
623 // Machine loaded
625 wxString message = _T("Machine loaded.");
626 GetStatusBar()->SetStatusText(message);
627 }
628
629 // Program is being simulated.
630 if (eventType == SimulatorEvent::EVT_SIMULATOR_RUN) {
631 // If an instance of stop dialog is already visible, do not create
632 // a new one.
635 wxString message = _T("Running simulation... ");
636 message.Append(WxConversion::toWxString(event.data()));
637 GetStatusBar()->SetStatusText(message);
638 ProximStopDialog dialog(this, -1, *ProximToolbox::frontend());
639 dialog.ShowModal();
641
642 // Another workaround for a gtk-bug where button goes out of focus.
643 GetToolBar()->Show(false);
644 GetToolBar()->Show(true);
645 }
646 }
647
648 for (unsigned i = 0; i < subwindows.size(); i++) {
649 wxWindow * window = subwindows[i];
650 wxPostEvent(window, event);
651 }
652
653 // Update menus.
654 wxMenuBar* menubar = GetMenuBar();
655 for (unsigned i = 0; i < menubar->GetMenuCount(); i++) {
656 menubar->GetMenu(i)->UpdateUI();
657 }
658}
659
660/**
661 * Adds a window to the list of subwindows to send the simulator events to.
662 *
663 * @param window Window to be added.
664 */
665void
668 subwindows.push_back(window);
669 }
670}
671
672/**
673 * Removes window from the list of subwindows to send the simulator events to.
674 *
675 * @param window Window to be removed.
676 */
677void
680 std::string procName = "ProximMainFrame::removeSubWindow";
681 throw InstanceNotFound(__FILE__, __LINE__, procName);
682 }
683}
684
685/**
686 * Event handler for View menu check items.
687 *
688 * @param event View menu event to handle.
689 */
690void
691ProximMainFrame::onToggleWindow(wxCommandEvent& event) {
692
693 int id = event.GetId();
694
695 switch (id) {
696
698 // Toggle memory window.
699 wxWindow* memoryWindow = FindWindowById(ProximConstants::ID_MEMORY_WINDOW);
700 if (memoryWindow == NULL) {
701 memoryWindow = new ProximMemoryWindow(
704 memoryWindow, _T("Memory"), false, wxSize(620, 400));
705 } else {
706 memoryWindow->GetParent()->Destroy();
707 memoryWindow = NULL;
708 }
709 return;
710
711 }
712
714 // Toggle control window.
715 wxWindow* controlWindow =
717 if (controlWindow == NULL) {
718 controlWindow = new ProximControlWindow(
721 controlWindow, _T("Simulator control"), false);
722 } else {
723 controlWindow->GetParent()->Destroy();
724 controlWindow = NULL;
725 }
726 return;
727
728 }
729
731 // Toggle machine window.
732 wxWindow* machineWindow = FindWindowById(
734 if (machineWindow == NULL) {
735 machineWindow = new ProximMachineStateWindow(
738 machineWindow, _T("Simulated Machine"), false, wxSize(600,400));
739 } else {
740 machineWindow->GetParent()->Destroy();
741 machineWindow = NULL;
742 }
743 return;
744
745 }
746
748 // Toggle breakpoitn window.
749 wxWindow* breakpointWindow = FindWindowById(
751 if (breakpointWindow == NULL) {
752 breakpointWindow = new ProximBreakpointWindow(
755 breakpointWindow, _T("Breakpoints"), false);
756 } else {
757 breakpointWindow->GetParent()->Close();
758 breakpointWindow = NULL;
759 }
760 return;
761
762 }
763
765 // Toggle command history window.
766 wxWindow* historyWindow = FindWindowById(
768 if (historyWindow == NULL) {
769 historyWindow = new ProximCmdHistoryWindow(
773 historyWindow, _T("Command History"), false);
774 } else {
775 historyWindow->GetParent()->Close();
776 historyWindow = NULL;
777 }
778 return;
779
780 }
781
783 // Toggle command history window.
784 wxWindow* debuggerWindow = FindWindowById(
786 if (debuggerWindow == NULL) {
787 debuggerWindow = new ProximDebuggerWindow(
790 debuggerWindow, _T("Source code debugger"), false);
791 } else {
792 debuggerWindow->GetParent()->Close();
793 debuggerWindow = NULL;
794 }
795 return;
796
797 }
798 }
799 event.Skip();
800}
801
802
803/**
804 * Event handler for wxUpdateUIEvents.
805 *
806 * Proxim updates buttons and menu items for command registry commands using
807 * wxUpdateUIEvents. When a wxUpdateUIEvent is received, command registry
808 * is searched for corresponding command ID. If a command is found, the
809 * UI element enabled or disabled according to the command's isEnabled()
810 * return value.
811 *
812 * @param event Upadate event to handle.
813 */
814void
815ProximMainFrame::updateCommand(wxUpdateUIEvent& event) {
816
817 if (wxGetApp().simulation() == NULL) {
818 return;
819 }
820
821 GUICommand* command =
822 wxGetApp().commandRegistry().createCommand(event.GetId());
823
824 if (command != NULL) {
825 event.Enable(command->isEnabled());
826 delete command;
827 } else {
828 event.Enable(false);
829 }
830}
831
832
833/**
834 * Event handler which updates view-menu check item check-marks.
835 *
836 * When a wxUpdateUIEvent is received for view-menu check item, the
837 * main frame checks if corresponding subwindow exists and updates the
838 * menu item.
839 */
840void
841ProximMainFrame::updateToggleItem(wxUpdateUIEvent& event) {
842
843 // memory window check-item
844 if (event.GetId() == ProximConstants::COMMAND_TOGGLE_MEMORY_WIN) {
845 bool exists = FindWindowById(ProximConstants::ID_MEMORY_WINDOW);
846 if (exists) {
847 event.Check(true);
848 } else {
849 event.Check(false);
850 }
851 }
852
853 // simulator control window check-item
854 if (event.GetId() == ProximConstants::COMMAND_TOGGLE_CONTROL_WIN) {
855 bool exists = FindWindowById(ProximConstants::ID_CONTROL_WINDOW);
856 if (exists) {
857 event.Check(true);
858 } else {
859 event.Check(false);
860 }
861 }
862
863 // machine window check-item
864 if (event.GetId() == ProximConstants::COMMAND_TOGGLE_MACHINE_WIN) {
865 bool exists = FindWindowById(ProximConstants::ID_MACHINE_STATE_WINDOW);
866 if (exists) {
867 event.Check(true);
868 } else {
869 event.Check(false);
870 }
871 }
872
873 // breakpoint window check-item
875 bool exists = FindWindowById(ProximConstants::ID_BREAKPOINT_WINDOW);
876 if (exists) {
877 event.Check(true);
878 } else {
879 event.Check(false);
880 }
881 }
882
883 // command history window check-item
885 bool exists = FindWindowById(ProximConstants::ID_CMD_HISTORY_WINDOW);
886 if (exists) {
887 event.Check(true);
888 } else {
889 event.Check(false);
890 }
891 }
892
893 // debugger window check-item
895 bool exists = FindWindowById(ProximConstants::ID_DEBUGGER_WINDOW);
896 if (exists) {
897 event.Check(true);
898 } else {
899 event.Check(false);
900 }
901 }
902}
903
904/**
905 * Handles key events.
906 *
907 * @param event Key event to handle.
908 */
909void
910ProximMainFrame::onKeyEvent(wxKeyEvent& event) {
911 event.Skip();
912}
913
914
915/**
916 * Handles system close events.
917 *
918 * This event handler is called for example when the window is being closed
919 * using the frame close button X.
920 *
921 * @param event Close event to handle;
922 */
923void
924ProximMainFrame::onClose(wxCloseEvent& event) {
925 if (event.CanVeto()) {
926 // Execute quit-command.
927 GUICommand* quitCommand = wxGetApp().commandRegistry().createCommand(
929 if (quitCommand->isEnabled()) {
930 quitCommand->setParentWindow(this);
931 if (!quitCommand->Do()) {
932 event.Veto();
933 }
934 }
935 event.Veto();
936 delete quitCommand;
937 return;
938 }
939}
940
941
942/**
943 * Updates simulation status and cycle count in the statusbar.
944 */
945void
947 const SimulatorFrontend* simulation = ProximToolbox::frontend();
948 wxString status;
949 ClockCycleCount cycles = 0;
950 if (simulation == NULL) {
951 status = _T("Not initialzed");
952 } else if (simulation->isSimulationInitialized()) {
953 cycles = simulation->cycleCount();
954 status = _T("Initialized");
955 } else if (simulation->isSimulationRunning()) {
956 cycles = simulation->cycleCount();
957 status = _T("Running");
958 } else if (simulation->isSimulationStopped()) {
959 cycles = simulation->cycleCount();
960 status = _T("Stopped");
961 } else if (simulation->hasSimulationEnded()) {
962 cycles = simulation->cycleCount();
963 status = _T("Finished");
964 }
965
966 wxStatusBar* statusBar = GetStatusBar();
967 statusBar->SetStatusText(status, 1);
968
969 wxString cyclesStr = WxConversion::toWxString((boost::format("%.0f") %
970 cycles).str());
971 cyclesStr.Prepend(_T("Cycles: "));
972 statusBar->SetStatusText(cyclesStr, 2);
973}
974
975
976/**
977 * Updates "Memory Window" menu item depending on if memory is available
978 */
979void
981 if (!wxGetApp().simulation() ||
982 !wxGetApp().simulation()->frontend() ||
983 !wxGetApp().simulation()->frontend()->isSimulationInitialized() ||
984 wxGetApp().simulation()->frontend()->memorySystem().
985 memoryCount() == 0) {
986 GetMenuBar()->Enable(ProximConstants::COMMAND_TOGGLE_MEMORY_WIN, false);
987 wxWindow* memoryWindow = FindWindowById(ProximConstants::ID_MEMORY_WINDOW);
988 if (memoryWindow != NULL) {
989 memoryWindow->Destroy();
990 memoryWindow = NULL;
991 }
992 } else {
993 GetMenuBar()->Enable(ProximConstants::COMMAND_TOGGLE_MEMORY_WIN, true);
994 }
995}
996
997
998/**
999 * Event handler for the simulator reset event.
1000 */
1001void
1005
1006
1007/**
1008 * Resets all subwidnows, which acess simulator data directly.
1009 *
1010 * If this fucntion is from another thread than the GUI thread,
1011 * a reset event is passed to the GUI thread, which will reset
1012 * the windows in the GUI thread. The caller thread is blocked and
1013 * wont return from this function until the reset is complete.
1014 */
1015void
1017 if (wxThread::IsMain()) {
1018 for (int i = subwindows.size() - 1; i >= 0; i--) {
1019 subwindows[i]->reset();
1020 }
1021 isReset_ = true;
1022 resetCondition_->Signal();
1023 } else {
1025 wxPostEvent(this, event);
1026 while (!isReset_) {
1027 resetCondition_->WaitTimeout(100);
1028 }
1029 isReset_ = false;
1030 }
1031}
END_EVENT_TABLE() using namespace IDF
find Finds info of the inner loops in the false
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
EVT_MENU_RANGE(ProximConstants::COMMAND_FIRST, ProximConstants::COMMAND_LAST, ProximMainFrame::onCommandEvent) EVT_MENU_RANGE(ProximConstants
CycleCount ClockCycleCount
Alias for ClockCycleCount.
#define EVT_SIMULATOR_LOADING_MACHINE(id, fn)
#define EVT_SIMULATOR_RUNTIME_WARNING(id, fn)
#define EVT_SIMULATOR_OUTPUT(id, fn)
#define EVT_SIMULATOR_COMMAND_DONE(id, fn)
#define EVT_SIMULATOR_LOADING_PROGRAM(id, fn)
#define EVT_SIMULATOR_RUNTIME_ERROR(id, fn)
#define EVT_SIMULATOR_COMMAND(id, fn)
#define EVT_SIMULATOR_PROGRAM_LOADED(id, fn)
#define EVT_SIMULATOR_RUN(id, fn)
#define EVT_SIMULATOR_TERMINATED(id, fn)
#define EVT_SIMULATOR_STOP(id, fn)
#define EVT_SIMULATOR_START(id, fn)
#define EVT_SIMULATOR_ERROR(id, fn)
#define EVT_SIMULATOR_RESET(id, fn)
#define EVT_SIMULATOR_MACHINE_LOADED(id, fn)
void addCommand(GUICommand *command)
std::string commandName(int id) const
static bool removeValueIfExists(ContainerType &aContainer, const ElementType &aKey)
static bool containsValue(const ContainerType &aContainer, const ElementType &aKey)
static std::string iconDirPath()
virtual bool Do()=0
void setParentWindow(wxWindow *view)
Definition GUICommand.cc:64
virtual bool isEnabled()=0
static const std::string SCL_STEP_INSTRUCTION
Command for stepping an instruction.
static const std::string COMMAND_NAME_QUIT
Name of the quit command.
std::vector< ProximSimulatorWindow * > subwindows
List of subwindows where to send the simulator events.
void updateCommand(wxUpdateUIEvent &event)
void updateToggleItem(wxUpdateUIEvent &event)
void onReset(const SimulatorEvent &event)
void dockWindow(wxWindow *window)
wxToolBar * toolbar_
Mainframe toolbar.
bool stopDialogInstantiated_
True, if an instance of the stop dialog is currently visible.
wxBoxSizer * sizer_
Toplevel sizer of the window managing the basic layout.
void addSubWindow(ProximSimulatorWindow *window)
void onCommandEvent(wxCommandEvent &event)
wxWindow * topSplitter_
Top level splitter window of the splitted subwindow hierarchy.
void updateMemoryWindowMenuItem()
void onSimulatorTerminated(SimulatorEvent &event)
wxString menuAccelerator(int id)
void onToggleWindow(wxCommandEvent &event)
void onSimulatorEvent(SimulatorEvent &event)
virtual ~ProximMainFrame()
void onClose(wxCloseEvent &event)
void onKeyEvent(wxKeyEvent &event)
wxCondition * resetCondition_
Condition which is signalled when the subwindow reset is complete.
void removeSubWindow(ProximSimulatorWindow *window)
bool isReset_
True if the subwindow reset is complete.
static void addFramedWindow(wxWindow *window, const wxString &title, bool stayOnTop=false, const wxSize &minSize=wxSize(100, 100))
static ProximLineReader & lineReader()
static TracedSimulatorFrontend * frontend()
static const wxEventType EVT_SIMULATOR_RESET
Sent before program,machine or memory model is destroyed.
static const wxEventType EVT_SIMULATOR_RUNTIME_WARNING
Runtime warning event.
static const wxEventType EVT_SIMULATOR_RUNTIME_ERROR
Runtime error event.
static const wxEventType EVT_SIMULATOR_MACHINE_LOADED
Machine loaded event.
static const wxEventType EVT_SIMULATOR_RUN
Simulation ran/resumed.
static const wxEventType EVT_SIMULATOR_PROGRAM_LOADED
Program loaded event.
static const wxEventType EVT_SIMULATOR_LOADING_MACHINE
Machine loading started.
static const wxEventType EVT_SIMULATOR_COMMAND_DONE
Command execution completed.
static const wxEventType EVT_SIMULATOR_COMMAND
Command received from the GUI.
std::string data() const
static const wxEventType EVT_SIMULATOR_LOADING_PROGRAM
Program loading started.
bool hasSimulationEnded() const
ClockCycleCount cycleCount() const
bool isSimulationInitialized() const
bool isSimulationStopped() const
bool isSimulationRunning() const
static const int COMMAND_ID
Command ID.
static wxString toWxString(const std::string &source)