OpenASIP 2.2
Loading...
Searching...
No Matches
HDBEditorModifyCmd.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 HDBEditorModifyCmd.cc
26 *
27 * Implementation of HDBEditorModifyCmd class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include "HDBEditorModifyCmd.hh"
34#include "WxConversion.hh"
35#include "HDBEditorConstants.hh"
36#include "HDBEditor.hh"
37#include "HDBEditorMainFrame.hh"
38#include "HDBBrowserWindow.hh"
39#include "HDBManager.hh"
40
42#include "FUImplementation.hh"
43#include "FUEntry.hh"
44#include "FUArchitecture.hh"
45
47#include "RFImplementation.hh"
48#include "RFEntry.hh"
49#include "RFArchitecture.hh"
50
52
53#include "ErrorDialog.hh"
54#include "Application.hh"
55
56
57/**
58 * The Constructor.
59 */
63
64
65/**
66 * The Destructor.
67 */
70
71/**
72 * Executes the command.
73 */
74bool
76
77 HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
78 if (manager == NULL) {
79 return false;
80 }
81
82 HDBBrowserWindow* browser = wxGetApp().mainFrame().browser();
83
84
85 if (browser->isFUImplementationSelected()) {
86
87 // FU implementation modification.
88
89 int entryID = manager->fuEntryIDOfImplementation(
90 browser->selectedFUImplementation());
91
92 HDB::FUEntry* entry = manager->fuByEntryID(entryID);
93
95 parentWindow(), -1, entry->implementation(),
96 entry->architecture().architecture());
97
98 if (dialog.ShowModal() == wxID_OK) {
99 try {
100 assert(entry->hasImplementation() &&
101 entry->implementation().hasID());
102
103 int implID = entry->implementation().id();
104 manager->removeFUImplementation(implID);
105 int id = manager->addFUImplementation(*entry);
106 wxGetApp().mainFrame().update();
107 wxGetApp().mainFrame().browser()->selectFUImplementation(id);
108 } catch (Exception& e) {
109 wxString message = _T("Error:\n");
110 message.Append(WxConversion::toWxString(e.errorMessage()));
111 message.Append(_T("\n"));
112 message.Append(WxConversion::toWxString(e.lineNum()));
113 message.Append(_T(": "));
114 message.Append(WxConversion::toWxString(e.fileName()));
115 ErrorDialog dialog(parentWindow(), message);
116 dialog.ShowModal();
117 delete entry;
118 return false;
119 }
120 } else {
121 delete entry;
122 }
123
124 return true;
125 } else if (browser->isRFImplementationSelected()) {
126
127 // RF implementation modification.
128
129 int entryID = manager->rfEntryIDOfImplementation(
130 browser->selectedRFImplementation());
131
132 HDB::RFEntry* entry = manager->rfByEntryID(entryID);
133
135 parentWindow(), -1, entry->implementation());
136
137 if (dialog.ShowModal() == wxID_OK) {
138 try {
139 assert(entry->hasImplementation() &&
140 entry->implementation().hasID());
141
142 int implID = entry->implementation().id();
143 manager->removeRFImplementation(implID);
144 int id = manager->addRFImplementation(
145 entry->implementation(), entryID);
146 //can be commented for not update DB-> fast editing
147 wxGetApp().mainFrame().update();
148 wxGetApp().mainFrame().browser()->selectRFImplementation(id);
149 } catch (Exception& e) {
150 wxString message = _T("Error:\n");
151 message.Append(WxConversion::toWxString(e.errorMessage()));
152 message.Append(_T("\n"));
153 message.Append(WxConversion::toWxString(e.lineNum()));
154 message.Append(_T(": "));
155 message.Append(WxConversion::toWxString(e.fileName()));
156 ErrorDialog dialog(parentWindow(), message);
157 dialog.ShowModal();
158 delete entry;
159 return false;
160 }
161 } else {
162 delete entry;
163 }
164
165 return true;
166 } else if (browser->isCostFunctionPluginSelected()) {
167
169 parentWindow(), -1,
170 *manager, browser->selectedCostFunctionPlugin());
171
172 dialog.ShowModal();
173 wxGetApp().mainFrame().update();
174 return true;
175 }
176
177 return false;
178}
179
180/**
181 * Returns name of the command icon file.
182 *
183 * @return Command icon file name.
184 */
185std::string
187 return "";
188}
189
190/**
191 * Returns the command id.
192 *
193 * @return Command identifier.
194 */
195int
199
200
201/**
202 * Creates a new instance of this command.
203 *
204 * @return Newly created instance of this command.
205 */
208 return new HDBEditorModifyCmd();
209}
210
211
212/**
213 * Returns true if the command should be enabled in the tool/menubar.
214 *
215 * @return True if the command is enabled, false if not.
216 */
217bool
219 HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
220
221 if (manager == NULL) {
222 return false;
223 }
224
225 HDBBrowserWindow* browser = wxGetApp().mainFrame().browser();
226
227 if (browser->isFUImplementationSelected() ||
228 browser->isRFImplementationSelected() ||
229 browser->isCostFunctionPluginSelected()) {
230 return true;
231 }
232
233 return false;
234}
#define assert(condition)
std::string fileName() const
std::string errorMessage() const
Definition Exception.cc:123
int lineNum() const
wxWindow * parentWindow() const
Definition GUICommand.cc:75
bool isCostFunctionPluginSelected()
RowID selectedCostFunctionPlugin()
virtual HDBEditorModifyCmd * create() const
virtual int id() const
virtual std::string icon() const
TTAMachine::FunctionUnit & architecture() const
FUImplementation & implementation() const
Definition FUEntry.cc:86
virtual bool hasImplementation() const
Definition FUEntry.cc:74
FUArchitecture & architecture() const
Definition FUEntry.cc:129
FUEntry * fuByEntryID(RowID id) const
virtual void removeFUImplementation(RowID implementationID) const
virtual void removeRFImplementation(RowID implID) const
RowID addFUImplementation(const FUEntry &entry) const
RowID addRFImplementation(const RFImplementation &implementation, RowID rfEntryID)
RowID fuEntryIDOfImplementation(RowID implID) const
RowID rfEntryIDOfImplementation(RowID implID) const
RFEntry * rfByEntryID(RowID id) const
virtual bool hasImplementation() const
Definition RFEntry.cc:74
RFImplementation & implementation() const
Definition RFEntry.cc:102
static wxString toWxString(const std::string &source)