OpenASIP 2.2
Loading...
Searching...
No Matches
MainFrame.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 MainFrame.cc
26 *
27 * Definition of MainFrame class.
28 *
29 * @author Veli-Pekka Jääskeläinen (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <wx/sizer.h>
34#include <wx/statusbr.h>
35
36#include "MainFrame.hh"
37#include "Environment.hh"
38#include "ChildFrame.hh"
39#include "CommandRegistry.hh"
40#include "ProDe.hh"
41#include "AddFUCmd.hh"
42#include "AddSocketCmd.hh"
43#include "AddBridgeCmd.hh"
44#include "AddBusCmd.hh"
45#include "AddASCmd.hh"
46#include "AddGCUCmd.hh"
47#include "AddIUCmd.hh"
48#include "AddRFCmd.hh"
49#include "CopyComponentCmd.hh"
50#include "CutComponentCmd.hh"
51#include "PasteComponentCmd.hh"
52#include "DeleteComponentCmd.hh"
53#include "ModifyComponentCmd.hh"
54#include "EditOptionsCmd.hh"
55#include "SaveOptionsCmd.hh"
56#include "EditConnectionsCmd.hh"
58#include "EditTemplatesCmd.hh"
59#include "EditOTAFormatsCmd.hh"
60#include "ZoomInCmd.hh"
61#include "ZoomOutCmd.hh"
62#include "FitWindowCmd.hh"
63#include "FitHeightCmd.hh"
64#include "FitWidthCmd.hh"
65#include "VerifyMachineCmd.hh"
68#include "UserManualCmd.hh"
69#include "AboutCmd.hh"
70#include "NewDocumentCmd.hh"
71#include "OpenDocumentCmd.hh"
72#include "CloseDocumentCmd.hh"
73#include "SaveDocumentCmd.hh"
74#include "SaveDocumentAsCmd.hh"
75#include "QuitCmd.hh"
76#include "PrintCmd.hh"
77#include "PrintPreviewCmd.hh"
78#include "SelectCmd.hh"
79#include "UndoCmd.hh"
80#include "RedoCmd.hh"
82#include "ProDeExportCmd.hh"
83#include "EditBusOrderCmd.hh"
85#include "AddRFFromHDBCmd.hh"
86#include "AddIUFromHDBCmd.hh"
87#include "AddFUFromHDBCmd.hh"
89#include "EditMachineCmd.hh"
90#include "VLIWConnectICCmd.hh"
91#include "BlocksConnectICCmd.hh"
92
93#include "KeyboardShortcut.hh"
94#include "ProDeOptions.hh"
95#include "WxConversion.hh"
96#include "ProDeConstants.hh"
97#include "ErrorDialog.hh"
98
99
100BEGIN_EVENT_TABLE(MainFrame, wxDocMDIParentFrame)
101 EVT_KEY_DOWN(MainFrame::onKeyEvent)
102 EVT_MENU(-1, MainFrame::onCommandEvent)
103 EVT_TOOL(-1, MainFrame::onCommandEvent)
104 EVT_UPDATE_UI(-1, MainFrame::onUpdateUI)
106
107
108/**
109 * The Constructor.
110 *
111 * @param manager Pointer to the editor's document manager.
112 * @param parent Parent frame of the MainFrame.
113 * @param title Title of the MainFrame.
114 * @param position Position of the MainFrame on the screen.
115 * @param size Size of the MainFrame on the screen.
116 * @param style Style of the MainFrame.
117 */
119 wxDocManager* manager,
120 wxFrame* parent,
121 const wxString& title,
122 const wxPoint& position,
123 const wxSize& size,
124 long style):
125 wxDocMDIParentFrame(manager, parent, -1, title,
126 position, size, style, _T("MainFrame")) {
127
128 commandRegistry_ = wxGetApp().commandRegistry();
129 assert(commandRegistry_ != NULL);
130 commandRegistry_->addCommand(new NewDocumentCmd());
131 commandRegistry_->addCommand(new OpenDocumentCmd());
132 commandRegistry_->addCommand(new CloseDocumentCmd());
133 commandRegistry_->addCommand(new SaveDocumentCmd());
134 commandRegistry_->addCommand(new SaveDocumentAsCmd());
135 commandRegistry_->addCommand(new PrintCmd());
136 commandRegistry_->addCommand(new PrintPreviewCmd());
137 commandRegistry_->addCommand(new ProDeExportCmd());
138 commandRegistry_->addCommand(new QuitCmd());
139 commandRegistry_->addCommand(new UndoCmd());
140 commandRegistry_->addCommand(new RedoCmd());
141 commandRegistry_->addCommand(new AddFUCmd());
142 commandRegistry_->addCommand(new AddRFCmd());
143 commandRegistry_->addCommand(new AddBusCmd());
144 commandRegistry_->addCommand(new AddSocketCmd());
145 commandRegistry_->addCommand(new AddBridgeCmd());
146 commandRegistry_->addCommand(new AddIUCmd());
147 commandRegistry_->addCommand(new AddGCUCmd());
148 commandRegistry_->addCommand(new AddASCmd());
149 commandRegistry_->addCommand(new AddRFFromHDBCmd());
150 commandRegistry_->addCommand(new AddIUFromHDBCmd());
151 commandRegistry_->addCommand(new AddFUFromHDBCmd());
152 commandRegistry_->addCommand(new CopyComponentCmd());
153 commandRegistry_->addCommand(new CutComponentCmd());
154 commandRegistry_->addCommand(new PasteComponentCmd());
155 commandRegistry_->addCommand(new DeleteComponentCmd());
156 commandRegistry_->addCommand(new ModifyComponentCmd());
157 commandRegistry_->addCommand(new EditConnectionsCmd());
158 commandRegistry_->addCommand(new EditAddressSpacesCmd());
159 commandRegistry_->addCommand(new EditBusOrderCmd());
160 commandRegistry_->addCommand(new EditTemplatesCmd());
161 commandRegistry_->addCommand(new EditOTAFormatsCmd());
162 commandRegistry_->addCommand(new EditMachineCmd());
163 commandRegistry_->addCommand(new EditImmediateSlotsCmd());
164 commandRegistry_->addCommand(new SelectCmd());
165 commandRegistry_->addCommand(new FullyConnectBussesCmd());
166 commandRegistry_->addCommand(new ZoomInCmd());
167 commandRegistry_->addCommand(new ZoomOutCmd());
168 commandRegistry_->addCommand(new FitWindowCmd());
169 commandRegistry_->addCommand(new FitHeightCmd());
170 commandRegistry_->addCommand(new FitWidthCmd());
171 commandRegistry_->addCommand(new ToggleUnitDetailsCmd());
172 commandRegistry_->addCommand(new VerifyMachineCmd());
173 commandRegistry_->addCommand(new ImplementMachineCmd());
174 commandRegistry_->addCommand(new CallExplorerPluginCmd());
175 commandRegistry_->addCommand(new EditOptionsCmd());
176 commandRegistry_->addCommand(new SaveOptionsCmd());
177 commandRegistry_->addCommand(new UserManualCmd());
178 commandRegistry_->addCommand(new AboutCmd());
179 commandRegistry_->addCommand(new VLIWConnectICCmd());
180 commandRegistry_->addCommand(new BlocksConnectICCmd());
181
182 toolbar_ = NULL;
183 CreateStatusBar(2);
184 int widths[2] = {-2, -1};
185 SetStatusWidths(2, widths);
186
187 createMenubar();
188 createToolbar();
189}
190
191
192/**
193 * Toggles visibility of the toolbar.
194 */
195void
197 ProDeOptions* options = wxGetApp().options();
198 if (toolbar_ != NULL) {
199 options->setToolbarVisibility(false);
200 SetToolBar(NULL);
201 delete toolbar_;
202 toolbar_ = NULL;
203 } else {
204 options->setToolbarVisibility(true);
206 }
207 Layout();
208}
209
210
211/**
212 * Toggles visibility of the statusbar.
213 */
214void
216 wxStatusBar* statusbar = GetStatusBar();
217 if (statusbar != NULL) {
218 SetStatusBar(NULL);
219 delete statusbar;
220 statusbar = NULL;
221 } else {
222 CreateStatusBar(2);
223 int widths[2] = {-4, -1};
224 SetStatusWidths(2, widths);
225 }
226 Layout();
227 Fit();
228}
229
230
231/**
232 * Creates and returns a new options menu.
233 *
234 * @return Options menu.
235 */
236wxMenu*
238 wxMenu* optionsMenu = new wxMenu;
239 optionsMenu->Append(
242 _T("&Edit...")));
243
244 optionsMenu->AppendSeparator();
245 optionsMenu->Append(
248 _T("&Save")));
249
250 return optionsMenu;
251}
252
253
254/**
255 * Creates and returns a new help menu.
256 *
257 * @return Help menu.
258 */
259wxMenu*
261 wxMenu* helpMenu = new wxMenu;
262 helpMenu->Append(
265 _T("&User Manual...")));
266
267 helpMenu->Append(
270 _T("&About...")));
271
272 return helpMenu;
273}
274
275
276
277/**
278 * Handles menu and toolbar events.
279 *
280 * @param event Event to handle.
281 */
282void
283MainFrame::onCommandEvent(wxCommandEvent& event) {
284
285 if (event.GetId() == ID_VIEW_TOOLBAR) {
287 return;
288 }
289
290 if (event.GetId() == ID_VIEW_STATUSBAR) {
292 return;
293 }
294
295 GUICommand* command = wxGetApp().commandRegistry()
296 ->createCommand(event.GetId());
297
298 if (command == NULL) {
299 ErrorDialog dialog(this,
300 _T("No handler found for the command event!"));
301 dialog.ShowModal();
302 return;
303 }
304
305 if (!command->isEnabled()) {
306 delete command;
307 return;
308 }
309
310 wxView* view = wxGetApp().docManager()->GetCurrentView();
311 if (view != NULL) {
312 command->setParentWindow(this);
313 EditorCommand* editorCmd = dynamic_cast<EditorCommand*>(command);
314 if (editorCmd != NULL) {
315 editorCmd->setView(view);
316 }
317 command->Do();
318 updateUI();
319 delete command;
320 return;
321 }
322
323 // set command parent window and view
324 command->setParentWindow(this);
325 // execute the command
326 command->Do();
327 updateUI();
328 delete command;
329}
330
331
332/**
333 * Updates toolbar and menubar item enabled/disabled states.
334 *
335 * @param event Update event for the menu or toolbar item to be updated.
336 */
337void
338MainFrame::onUpdateUI(wxUpdateUIEvent& event) {
339
340 CommandRegistry* registry = wxGetApp().commandRegistry();
341 GUICommand* command = registry->createCommand(event.GetId());
342
343 if (command == NULL) {
344 event.Skip();
345 return;
346 }
347
348 wxView* view = wxGetApp().docManager()->GetCurrentView();
349 if (view != NULL) {
350 EditorCommand* editorCmd = dynamic_cast<EditorCommand*>(command);
351 if (editorCmd != NULL) {
352 editorCmd->setView(view);
353 }
354 }
355
356 if (command->isEnabled()) {
357 event.Enable(true);
358 } else {
359 event.Enable(false);
360 }
361
362 if (command->isChecked()) {
363 event.Check(command->isChecked());
364 }
365
366 delete command;
367}
368
369/**
370 * Updates enabled/disabled states of toolbar buttons and menu items.
371 */
372void
374
375 wxMenuBar* menubar = GetMenuBar();
376 for (unsigned i = 0; i < menubar->GetMenuCount(); i++) {
377 menubar->GetMenu(i)->UpdateUI();
378 }
379
380 if (toolbar_ == NULL) {
381 return;
382 }
383
384 CommandRegistry* registry = wxGetApp().commandRegistry();
385 ProDeOptions* options = wxGetApp().options();
386 ToolbarButton* tool = options->firstToolbarButton();
387
388 while (tool != NULL) {
389 int id = registry->commandId(tool->action());
390 if (!registry->isEnabled(tool->action())) {
391 toolbar_->EnableTool(id, false);
392 } else {
393 toolbar_->EnableTool(id, true);
394 }
395 tool = options->nextToolbarButton();
396 }
397
398}
399
400/**
401 * Handles key events on the canvas.
402 *
403 * @param event Key event to handle.
404 */
405void
407}
408
409
410/**
411 * Creates the default menubar.
412 */
413void
415 // File menu
416 wxMenu* fileMenu = new wxMenu;
417
418 fileMenu->Append(
421
422 fileMenu->Append(
425 ProDeConstants::COMMAND_OPEN_DOC).Prepend(_T("Open...")));
426
427 fileMenu->Append(
430 ProDeConstants::COMMAND_SAVE_DOC).Prepend(_T("&Save")));
431
432 fileMenu->Append(
435 ProDeConstants::COMMAND_SAVEAS_DOC).Prepend(_T("Save &As...")));
436
437 fileMenu->Append(
440 ProDeConstants::COMMAND_CLOSE_DOC).Prepend(_T("&Close")));
441
442 fileMenu->AppendSeparator();
443
444 fileMenu->Append(
447 ProDeConstants::COMMAND_PRINT).Prepend(_T("&Print...")));
448
449 fileMenu->Append(
452 _T("Print Pre&view...")));
453
454 fileMenu->Append(
457 _T("Export...")));
458
459 fileMenu->AppendSeparator();
460
461 fileMenu->Append(
463 menuAccelerator(ProDeConstants::COMMAND_QUIT).Prepend(_T("&Quit")));
464
465 // Edit menu
466 wxMenu* editMenu = new wxMenu;
467 wxMenu* addSubMenu = new wxMenu;
468 wxMenu* addFromHDBSubMenu = new wxMenu;
469
470 editMenu->Append(
473 _T("&Undo")));
474
475 editMenu->Append(
478 _T("&Redo")));
479
480 editMenu->AppendSeparator();
481 editMenu->Append(
484 _T("Cu&t")));
485
486 editMenu->Append(
489 _T("&Copy")));
490
491 editMenu->Append(
494 _T("&Paste")));
495
496 editMenu->AppendSeparator();
497
498 addSubMenu->Append(
501 _T("&Function Unit...")));
502
503 addSubMenu->Append(
506 _T("&Register File...")));
507
508 addSubMenu->Append(
511 _T("&Transport Bus...")));
512
513 addSubMenu->Append(
516 _T("&Socket...")));
517
518 addSubMenu->Append(
521 _T("&Bridge...")));
522
523 addSubMenu->Append(
526 _T("&Immediate Unit...")));
527
528 addSubMenu->Append(
531 _T("&Global Control Unit...")));
532
533 addSubMenu->Append(
536 _T("&Address Space...")));
537
538 editMenu->Append(ID_ADD_SUBMENU, _T("&Add"), addSubMenu);
539
540 addFromHDBSubMenu->Append(
543 _T("&Function Unit...")));
544
545 addFromHDBSubMenu->Append(
548 _T("&Immediate Unit...")));
549
550 addFromHDBSubMenu->Append(
553 _T("&Register File...")));
554
555 editMenu->Append(
557 _T("Add From &HDB"), addFromHDBSubMenu);
558
559 editMenu->Append(
562 _T("&Delete")));
563
564 editMenu->Append(
567 _T("&Modify...")));
568
569 editMenu->AppendSeparator();
570 editMenu->Append(
573 _T("Address &Spaces...")));
574
575 editMenu->Append(
578 _T("Instruction &Templates...")));
579
580 editMenu->Append(
583 .Prepend(_T("OTA Formats...")));
584
585 editMenu->Append(
588 _T("&Immediate Slots...")));
589
590 editMenu->Append(
593 _T("Transport Bus &Order...")));
594
595 editMenu->Append(
598 _T("Architecture Features...")));
599
600 // View menu
601 wxMenu* viewMenu = new wxMenu;
602 wxMenu* zoomSubMenu = new wxMenu;
603 zoomSubMenu->Append(
606 _T("Zoom &In")));
607
608 zoomSubMenu->Append(
611 _T("Zoom &Out")));
612
613 zoomSubMenu->AppendSeparator();
614 zoomSubMenu->Append(
617 _T("&Fit Window")));
618
619 zoomSubMenu->Append(
622 _T("Fit &Height")));
623
624 zoomSubMenu->Append(
627 _T("Fit &Width")));
628
629 viewMenu->Append(ID_ZOOM_SUBMENU, _T("&Zoom"), zoomSubMenu);
630 viewMenu->AppendSeparator();
631 viewMenu->AppendCheckItem(
634 _T("Unit &Details")));
635
636 viewMenu->AppendSeparator();
637 viewMenu->AppendCheckItem(ID_VIEW_TOOLBAR, _T("&Toolbar"));
638 viewMenu->AppendCheckItem(ID_VIEW_STATUSBAR, _T("&Statusbar"));
639 viewMenu->Check(ID_VIEW_STATUSBAR, true);
640 viewMenu->Check(ID_VIEW_TOOLBAR, true);
641
642 // Tool menu
643 wxMenu* toolMenu = new wxMenu;
644 toolMenu->Append(
647 _T("&Select")));
648
649 toolMenu->Append(
652 _T("&Edit Connections")));
653
654 toolMenu->AppendSeparator();
655 toolMenu->Append(
658 _T("&Fully Connect IC")));
659
660 toolMenu->Append(
663 _T("&VLIW Connect IC")));
664
665 toolMenu->Append(
668 .Prepend(_T("&Blocks Connect IC")));
669
670 toolMenu->Append(
673 _T("&Verify...")));
674
675 toolMenu->Append(
678 _T("&Processor Implementation...")));
679
680 toolMenu->Append(
683 _T("&Call Explorer Plugin...")));
684
685 // Options menu
686 wxMenu* optionsMenu = createOptionsMenu();
687
688 // Help menu
689 wxMenu* helpMenu = createHelpMenu();
690
691 // add menus to the menubar
692 wxMenuBar* menuBar = new wxMenuBar;
693 menuBar->Append(fileMenu, _T("&File"));
694 menuBar->Append(editMenu, _T("&Edit"));
695 menuBar->Append(viewMenu, _T("&View"));
696 menuBar->Append(toolMenu, _T("&Tools"));
697 menuBar->Append(optionsMenu, _T("&Options"));
698 menuBar->Append(helpMenu, _T("&Help"));
699
700 SetMenuBar(menuBar);
701}
702
703/**
704 * Returns a menu accelerator string for a command.
705 *
706 * The returned string can be appended to the menu item text to set the
707 * keyboard shortcut defined in the options for the command.
708 *
709 * @param id Command ID.
710 * @return Accelerator string.
711 */
712wxString
714
715 const CommandRegistry* reg = wxGetApp().commandRegistry();
716 const GUIOptions* options = wxGetApp().options();
717 std::string cmdName = reg->commandName(id);
718 const KeyboardShortcut* sc = options->keyboardShortcut(cmdName);
719
720 if (sc != NULL) {
721 wxString accel = _T("\t");
722 if (sc->ctrl()) {
723 accel.Append(_T("Ctrl-"));
724 accel.Append(WxConversion::toWxString(sc->key()));
725 return accel;
726 } else if (sc->alt()) {
727 accel.Append(_T("Alt-"));
728 accel.Append(WxConversion::toWxString(sc->key()));
729 return accel;
730 } else if (sc->fKey() > 0) {
731 accel.Append(_T("F"));
732 accel.Append(WxConversion::toWxString(sc->fKey()));
733 return accel;
734 } else {
735 // Invalid shortcut.
736 return _T("");
737 }
738 }
739 return _T("");
740}
741
742/**
743 * Creates the toolbar.
744 */
745void
747
748 // delete old toolbar
749 if (toolbar_ != NULL) {
750 delete toolbar_;
751 toolbar_ = NULL;
752 }
753
754 CommandRegistry* registry = wxGetApp().commandRegistry();
755 ProDeOptions* options = wxGetApp().options();
757
758 toolbar_ = options->createToolbar(this, *registry, iconPath);
759
760 // set new toolbar as the MainFrame toolbar
761 SetToolBar(toolbar_);
762 toolbar_->Show(true);
763}
764
765/**
766 * Performs routines before exiting a program
767 *
768 * @param event Command event to handle.
769 */
770void
771MainFrame::OnExit(wxCommandEvent& WXUNUSED(event)) {
772 Close();
773}
#define assert(condition)
END_EVENT_TABLE() using namespace IDF
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
bool isEnabled(const std::string command)
GUICommand * createCommand(const int id)
int commandId(const std::string name) const
std::string commandName(int id) const
void setView(wxView *view)
static std::string iconDirPath()
virtual bool Do()=0
void setParentWindow(wxWindow *view)
Definition GUICommand.cc:64
virtual bool isChecked() const
virtual bool isEnabled()=0
wxMenu * createOptionsMenu()
Definition MainFrame.cc:237
@ ID_ADD_FROM_HDB_SUBMENU
Definition MainFrame.hh:80
@ ID_VIEW_STATUSBAR
Definition MainFrame.hh:83
@ ID_ZOOM_SUBMENU
Definition MainFrame.hh:81
@ ID_ADD_SUBMENU
Definition MainFrame.hh:79
@ ID_VIEW_TOOLBAR
Definition MainFrame.hh:82
wxToolBar * toolbar_
Toolbar.
Definition MainFrame.hh:75
wxMenu * createHelpMenu()
Definition MainFrame.cc:260
wxString menuAccelerator(int id)
Definition MainFrame.cc:713
void onKeyEvent(wxKeyEvent &event)
Definition MainFrame.cc:406
void onToggleStatusbar()
Definition MainFrame.cc:215
void createMenubar()
Definition MainFrame.cc:414
void updateUI()
Definition MainFrame.cc:373
void createToolbar()
Definition MainFrame.cc:746
void onToggleToolbar()
Definition MainFrame.cc:196
void OnExit(wxCommandEvent &WXUNUSED(event))
Definition MainFrame.cc:771
void onUpdateUI(wxUpdateUIEvent &event)
Definition MainFrame.cc:338
void onCommandEvent(wxCommandEvent &event)
Definition MainFrame.cc:283
std::string action() const
static const int COMMAND_ID
Command ID.
static wxString toWxString(const std::string &source)