OpenASIP 2.2
Loading...
Searching...
No Matches
AddIUCmd.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 AddIUCmd.cc
26 *
27 * Definition of AddIUCmd class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30 */
31
32#include <wx/wx.h>
33#include <wx/docview.h>
34
35#include "AddIUCmd.hh"
36#include "IUDialog.hh"
37#include "Model.hh"
38#include "MDFDocument.hh"
39#include "ModelConstants.hh"
40#include "ProDeConstants.hh"
41#include "ErrorDialog.hh"
42#include "ProDe.hh"
43#include "ImmediateUnit.hh"
44#include "Conversion.hh"
45
46using std::string;
47using namespace TTAMachine;
48
49/**
50 * The Constructor.
51 */
53 EditorCommand(ProDeConstants::CMD_NAME_ADD_IU) {
54}
55
56
57
58/**
59 * Executes the command.
60 *
61 * @return true, if the command was succesfully executed, false otherwise.
62 */
63bool
65
66 assert(parentWindow() != NULL);
67 assert(view() != NULL);
68
69
70 Model* model =
71 dynamic_cast<MDFDocument*>(view()->GetDocument())->getModel();
72
73 model->pushToStack();
74
75 // Generate name for the new IU.
79 int i = 1;
80 while (navigator.hasItem(newName)) {
83 i++;
84 }
85
86 ImmediateUnit* iu =
92
93 iu->setMachine(*(model->getMachine()));
94
95 IUDialog dialog(parentWindow(), iu);
96
97 if (dialog.ShowModal() == wxID_OK) {
98 model->notifyObservers();
99 return true;
100 } else {
101 // immediate unit creation was cancelled
102 model->popFromStack();
103 return false;
104 }
105 return false;
106}
107
108
109/**
110 * Returns id of this command.
111 *
112 * @return ID for this command to be used in menus and toolbars.
113 */
114int
118
119
120/**
121 * Creates and returns a new instance of this command.
122 *
123 * @return Newly created instance of this command.
124 */
127 return new AddIUCmd();
128}
129
130
131/**
132 * Returns short version of the command name.
133 *
134 * @return Short name of the command to be used in the toolbar.
135 */
136string
140
141
142/**
143 * Returns true when the command is executable, false when not.
144 *
145 * This command is executable when a document is open.
146 *
147 * @return True, if a document is open.
148 */
149bool
151 wxDocManager* manager = wxGetApp().docManager();
152 if (manager->GetCurrentView() != NULL) {
153 return true;
154 }
155 return false;
156}
#define assert(condition)
virtual AddIUCmd * create() const
Definition AddIUCmd.cc:126
virtual bool Do()
Definition AddIUCmd.cc:64
virtual int id() const
Definition AddIUCmd.cc:115
virtual bool isEnabled()
Definition AddIUCmd.cc:150
virtual std::string shortName() const
Definition AddIUCmd.cc:137
static std::string toString(const T &source)
wxView * view() const
wxWindow * parentWindow() const
Definition GUICommand.cc:75
static const int DEFAULT_IU_GUARD_LATENCY
Default local IU guard latency.
static const int DEFAULT_WIDTH
Default bit width.
static const int DEFAULT_IU_SIZE
Default immediate unit size.
static const int DEFAULT_IU_MAX_READS
Default maximum read ports of a immediate unit.
Definition Model.hh:50
void pushToStack()
Definition Model.cc:167
void notifyObservers(bool modified=true)
Definition Model.cc:152
void popFromStack(bool modified=false)
Definition Model.cc:195
TTAMachine::Machine * getMachine()
Definition Model.cc:88
static const std::string COMP_NEW_NAME_PREFIX_IU
Prefix for new immediate unit names.
static const std::string CMD_SNAME_ADD_IU
Command name for the "Add Immediate Unit" command.
bool hasItem(const std::string &name) const
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition Machine.cc:416
@ ZERO
Zero extension.
Definition Machine.hh:81
virtual void setMachine(Machine &mach)
Definition Unit.cc:253