OpenASIP 2.2
Loading...
Searching...
No Matches
HDBEditorDeleteCmd.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 HDBEditorDeleteCmd.cc
26 *
27 * Implementation of HDBEditorDeleteCmd class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include "HDBEditorDeleteCmd.hh"
34#include "WxConversion.hh"
35#include "HDBEditorConstants.hh"
36#include "HDBEditor.hh"
37#include "HDBEditorMainFrame.hh"
38#include "DBTypes.hh"
39#include "HDBManager.hh"
40#include "HDBBrowserWindow.hh"
41#include "InformationDialog.hh"
42
43/**
44 * The Constructor.
45 */
49
50
51/**
52 * The Destructor.
53 */
56
57/**
58 * Executes the command.
59 */
60bool
62 HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
63
64 if (manager == NULL) {
65 return false;
66 }
67
68 HDBBrowserWindow* browser = wxGetApp().browser();
69 if (browser->isFUArchitectureSelected()) {
70 int id = browser->selectedFUArchitecture();
71 if (manager->canRemoveFUArchitecture(id)) {
72 if (confirmDeletion(_T("FU Architecture"))) {
73 manager->removeFUArchitecture(id);
74 } else {
75 return false;
76 }
77 } else {
78 wxString message = _T("FU Architecture ");
79 message.Append(WxConversion::toWxString(id));
80 message.Append(_T(" cannot be removed,\n"));
81 message.Append(_T("because it has an implementation."));
82 InformationDialog dialog(parentWindow(), message);
83 dialog.ShowModal();
84 return false;
85 }
86 } else if (browser->isRFArchitectureSelected()) {
87 int id = browser->selectedRFArchitecture();
88 if (manager->canRemoveRFArchitecture(id)) {
89 if (confirmDeletion(_T("RF Architecture"))) {
90 manager->removeRFArchitecture(id);
91 } else {
92 return false;
93 }
94 } else {
95 wxString message = _T("RF Architecture ");
96 message.Append(WxConversion::toWxString(id));
97 message.Append(_T(" cannot be removed,\n"));
98 message.Append(_T("because it has an implementation."));
99 InformationDialog dialog(parentWindow(), message);
100 dialog.ShowModal();
101 return false;
102 }
103 } else if (browser->isFUImplementationSelected()) {
104 if (confirmDeletion(_T("FU Implementation"))) {
105 int id = manager->fuEntryIDOfImplementation(
106 browser->selectedFUImplementation());
107 manager->removeFUEntry(id);
108 } else {
109 return false;
110 }
111 } else if (browser->isRFImplementationSelected()) {
112 if (confirmDeletion(_T("RF Implementation"))) {
113 int id = manager->rfEntryIDOfImplementation(
114 browser->selectedRFImplementation());
115 manager->removeRFEntry(id);
116 } else {
117 return false;
118 }
119 } else if (browser->isCostFunctionPluginSelected()) {
120 if (confirmDeletion(_T("Cost Function Plugin"))) {
121 int id = browser->selectedCostFunctionPlugin();
122 manager->removeCostFunctionPlugin(id);
123 } else {
124 return false;
125 }
126 } else if (browser->isFUEntrySelected()) {
127 if (confirmDeletion(_T("FU Entry"))) {
128 int id = browser->selectedFUEntry();
129 manager->removeFUEntry(id);
130 } else {
131 return false;
132 }
133 } else if (browser->isRFEntrySelected()) {
134 if (confirmDeletion(_T("RF Entry"))) {
135 int id = browser->selectedRFEntry();
136 manager->removeRFEntry(id);
137 } else {
138 return false;
139 }
140 } else if (browser->isBusEntrySelected()) {
141 if (confirmDeletion(_T("Bus Entry"))) {
142 int id = browser->selectedBusEntry();
143 manager->removeBusEntry(id);
144 } else {
145 return false;
146 }
147 } else if (browser->isSocketEntrySelected()) {
148 if (confirmDeletion(_T("Socket Entry"))) {
149 int id = browser->selectedSocketEntry();
150 manager->removeSocketEntry(id);
151 } else {
152 return false;
153 }
154 } else if (browser->isOperationImplementationSelected()) {
155 if (confirmDeletion(_T("Operation Implementation"))) {
156 int id = browser->selectedOperationImplementation();
158 } else {
159 return false;
160 }
161 } else if (browser->isOperationImplementationResourceSelected()) {
162 if (confirmDeletion(_T("Operation Implementation Resource"))) {
163 int id = browser->selectedOperationImplementationResource();
165 } else {
166 return false;
167 }
168 } else {
169 return false;
170 }
171
172 wxGetApp().mainFrame().update();
173
174 return true;
175}
176
177
178/**
179 * Returns name of the command icon file.
180 *
181 * @return Command icon file name.
182 */
183std::string
185 return "";
186}
187
188
189/**
190 * Returns the command id.
191 *
192 * @return Command identifier of this command.
193 */
194int
198
199
200/**
201 * Creates a new instance of this command.
202 *
203 * @return Newly created instance of this command.
204 */
207 return new HDBEditorDeleteCmd();
208}
209
210
211/**
212 * Returns true if the command should be enabled in the menu/toolbar.
213 *
214 * @return True if the command is enabled, false if not.
215 */
216bool
218 HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
219
220 if (manager == NULL) {
221 return false;
222 }
223
224 HDBBrowserWindow* browser = wxGetApp().browser();
225
226 if (browser->isFUArchitectureSelected() ||
227 browser->isRFArchitectureSelected() ||
228 browser->isFUImplementationSelected() ||
229 browser->isRFImplementationSelected() ||
230 browser->isCostFunctionPluginSelected() ||
231 browser->isFUEntrySelected() ||
232 browser->isRFEntrySelected() ||
233 browser->isBusEntrySelected() ||
234 browser->isSocketEntrySelected() ||
237 ) {
238
239 return true;
240 }
241
242 return false;
243}
244
245/**
246 * Creates a dialog box to confirm deletion.
247 *
248 * @param component Type of component to be deleted.
249 * @return true if Yes was pressed, false otherwise.
250 */
251bool
252HDBEditorDeleteCmd::confirmDeletion(const wxString& component){
253 wxString message = _T("Are you sure you want to delete this ");
254 message.Append(component);
255 message.Append(_T("?"));
256 MessageDialog dialog(parentWindow(), _T("Confirm deletion"), message,
257 wxYES_DEFAULT | wxYES_NO);
258 return dialog.ShowModal() == wxID_YES;
259}
260
wxWindow * parentWindow() const
Definition GUICommand.cc:75
bool isCostFunctionPluginSelected()
RowID selectedOperationImplementation()
bool isOperationImplementationResourceSelected()
RowID selectedOperationImplementationResource()
bool isOperationImplementationSelected()
RowID selectedCostFunctionPlugin()
virtual HDBEditorDeleteCmd * create() const
virtual int id() const
virtual std::string icon() const
bool confirmDeletion(const wxString &component)
virtual void removeFUEntry(RowID id) const
void removeOperationImplementation(RowID id)
virtual void removeSocketEntry(RowID id) const
void removeOperationImplementationResource(RowID id)
bool canRemoveFUArchitecture(RowID archID) const
virtual void removeRFEntry(RowID id) const
RowID fuEntryIDOfImplementation(RowID implID) const
virtual void removeBusEntry(RowID id) const
virtual void removeRFArchitecture(RowID archID) const
RowID rfEntryIDOfImplementation(RowID implID) const
virtual void removeCostFunctionPlugin(RowID pluginID) const
bool canRemoveRFArchitecture(RowID archID) const
virtual void removeFUArchitecture(RowID archID) const
static wxString toWxString(const std::string &source)