OpenASIP  2.0
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  */
47  GUICommand(HDBEditorConstants::COMMAND_NAME_DELETE, NULL) {
48 }
49 
50 
51 /**
52  * The Destructor.
53  */
55 }
56 
57 /**
58  * Executes the command.
59  */
60 bool
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();
157  manager->removeOperationImplementation(id);
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  */
183 std::string
185  return "";
186 }
187 
188 
189 /**
190  * Returns the command id.
191  *
192  * @return Command identifier of this command.
193  */
194 int
197 }
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  */
216 bool
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  */
251 bool
252 HDBEditorDeleteCmd::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 
HDB::HDBManager::removeOperationImplementationResource
void removeOperationImplementationResource(RowID id)
Definition: HDBManager.cc:2658
WxConversion::toWxString
static wxString toWxString(const std::string &source)
HDBBrowserWindow.hh
HDBBrowserWindow
Definition: HDBBrowserWindow.hh:59
HDBEditorDeleteCmd::icon
virtual std::string icon() const
Definition: HDBEditorDeleteCmd.cc:184
HDB::HDBManager::removeFUEntry
virtual void removeFUEntry(RowID id) const
Definition: HDBManager.cc:1039
HDBEditor.hh
HDBBrowserWindow::isRFArchitectureSelected
bool isRFArchitectureSelected()
Definition: HDBBrowserWindow.cc:353
HDB::HDBManager::removeOperationImplementation
void removeOperationImplementation(RowID id)
Definition: HDBManager.cc:2622
HDBEditorConstants.hh
HDB::HDBManager::removeBusEntry
virtual void removeBusEntry(RowID id) const
Definition: HDBManager.cc:3418
HDBBrowserWindow::isRFImplementationSelected
bool isRFImplementationSelected()
Definition: HDBBrowserWindow.cc:376
HDB::HDBManager::removeRFEntry
virtual void removeRFEntry(RowID id) const
Definition: HDBManager.cc:1583
HDBEditorDeleteCmd::Do
virtual bool Do()
Definition: HDBEditorDeleteCmd.cc:61
HDB::HDBManager::removeSocketEntry
virtual void removeSocketEntry(RowID id) const
Definition: HDBManager.cc:3631
HDB::HDBManager::rfEntryIDOfImplementation
RowID rfEntryIDOfImplementation(RowID implID) const
Definition: HDBManager.cc:2796
MessageDialog
Definition: MessageDialog.hh:44
HDBBrowserWindow::isSocketEntrySelected
bool isSocketEntrySelected()
Definition: HDBBrowserWindow.cc:417
DBTypes.hh
HDBBrowserWindow::selectedOperationImplementationResource
RowID selectedOperationImplementationResource()
Definition: HDBBrowserWindow.cc:632
GUICommand
Definition: GUICommand.hh:43
HDBBrowserWindow::isBusEntrySelected
bool isBusEntrySelected()
Definition: HDBBrowserWindow.cc:407
HDBEditorDeleteCmd.hh
HDBBrowserWindow::isFUEntrySelected
bool isFUEntrySelected()
Definition: HDBBrowserWindow.cc:387
HDB::HDBManager::canRemoveFUArchitecture
bool canRemoveFUArchitecture(RowID archID) const
Definition: HDBManager.cc:904
HDBEditorDeleteCmd::HDBEditorDeleteCmd
HDBEditorDeleteCmd()
Definition: HDBEditorDeleteCmd.cc:46
HDBEditorMainFrame.hh
HDBBrowserWindow::selectedFUArchitecture
RowID selectedFUArchitecture()
Definition: HDBBrowserWindow.cc:466
HDBBrowserWindow::isOperationImplementationResourceSelected
bool isOperationImplementationResourceSelected()
Definition: HDBBrowserWindow.cc:439
InformationDialog.hh
HDBBrowserWindow::selectedCostFunctionPlugin
RowID selectedCostFunctionPlugin()
Definition: HDBBrowserWindow.cc:598
HDBEditorDeleteCmd
Definition: HDBEditorDeleteCmd.hh:41
HDB::HDBManager::fuEntryIDOfImplementation
RowID fuEntryIDOfImplementation(RowID implID) const
Definition: HDBManager.cc:2765
HDB::HDBManager
Definition: HDBManager.hh:82
HDBEditorDeleteCmd::id
virtual int id() const
Definition: HDBEditorDeleteCmd.cc:195
HDBBrowserWindow::selectedRFImplementation
RowID selectedRFImplementation()
Definition: HDBBrowserWindow.cc:517
HDBEditorDeleteCmd::isEnabled
virtual bool isEnabled()
Definition: HDBEditorDeleteCmd.cc:217
HDBBrowserWindow::selectedOperationImplementation
RowID selectedOperationImplementation()
Definition: HDBBrowserWindow.cc:614
HDB::HDBManager::removeCostFunctionPlugin
virtual void removeCostFunctionPlugin(RowID pluginID) const
Definition: HDBManager.cc:684
HDBBrowserWindow::selectedFUImplementation
RowID selectedFUImplementation()
Definition: HDBBrowserWindow.cc:500
HDBEditorDeleteCmd::create
virtual HDBEditorDeleteCmd * create() const
Definition: HDBEditorDeleteCmd.cc:206
HDBEditorConstants
Definition: HDBEditorConstants.hh:42
HDBBrowserWindow::selectedRFEntry
RowID selectedRFEntry()
Definition: HDBBrowserWindow.cc:549
HDBEditorConstants::COMMAND_DELETE
@ COMMAND_DELETE
Definition: HDBEditorConstants.hh:60
HDBEditorDeleteCmd::~HDBEditorDeleteCmd
virtual ~HDBEditorDeleteCmd()
Definition: HDBEditorDeleteCmd.cc:54
HDBBrowserWindow::selectedBusEntry
RowID selectedBusEntry()
Definition: HDBBrowserWindow.cc:565
HDBBrowserWindow::isFUArchitectureSelected
bool isFUArchitectureSelected()
Definition: HDBBrowserWindow.cc:343
WxConversion.hh
HDBEditorDeleteCmd::confirmDeletion
bool confirmDeletion(const wxString &component)
Definition: HDBEditorDeleteCmd.cc:252
InformationDialog
Definition: InformationDialog.hh:42
HDBBrowserWindow::selectedSocketEntry
RowID selectedSocketEntry()
Definition: HDBBrowserWindow.cc:581
HDBBrowserWindow::isOperationImplementationSelected
bool isOperationImplementationSelected()
Definition: HDBBrowserWindow.cc:453
HDB::HDBManager::canRemoveRFArchitecture
bool canRemoveRFArchitecture(RowID archID) const
Definition: HDBManager.cc:1508
HDB::HDBManager::removeFUArchitecture
virtual void removeFUArchitecture(RowID archID) const
Definition: HDBManager.cc:941
HDBManager.hh
HDBBrowserWindow::isFUImplementationSelected
bool isFUImplementationSelected()
Definition: HDBBrowserWindow.cc:364
HDBBrowserWindow::isCostFunctionPluginSelected
bool isCostFunctionPluginSelected()
Definition: HDBBrowserWindow.cc:428
HDB::HDBManager::removeRFArchitecture
virtual void removeRFArchitecture(RowID archID) const
Definition: HDBManager.cc:1535
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
HDBBrowserWindow::selectedFUEntry
RowID selectedFUEntry()
Definition: HDBBrowserWindow.cc:533
HDBBrowserWindow::isRFEntrySelected
bool isRFEntrySelected()
Definition: HDBBrowserWindow.cc:397
HDBBrowserWindow::selectedRFArchitecture
RowID selectedRFArchitecture()
Definition: HDBBrowserWindow.cc:483