OpenASIP  2.0
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  */
61  GUICommand(HDBEditorConstants::COMMAND_NAME_MODIFY, NULL) {
62 }
63 
64 
65 /**
66  * The Destructor.
67  */
69 }
70 
71 /**
72  * Executes the command.
73  */
74 bool
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 
134  RFImplementationDialog dialog(
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  */
185 std::string
187  return "";
188 }
189 
190 /**
191  * Returns the command id.
192  *
193  * @return Command identifier.
194  */
195 int
198 }
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  */
217 bool
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 }
HDB::FUEntry
Definition: FUEntry.hh:49
HDB::HDBManager::addFUImplementation
RowID addFUImplementation(const FUEntry &entry) const
Definition: HDBManager.cc:1112
Exception::lineNum
int lineNum() const
WxConversion::toWxString
static wxString toWxString(const std::string &source)
HDB::RFEntry::hasImplementation
virtual bool hasImplementation() const
Definition: RFEntry.cc:74
HDBBrowserWindow.hh
HDBBrowserWindow
Definition: HDBBrowserWindow.hh:59
HDBEditor.hh
FUImplementationDialog
Definition: FUImplementationDialog.hh:52
FUArchitecture.hh
CostFunctionPluginDialog.hh
HDBEditorConstants.hh
HDB::RFEntry
Definition: RFEntry.hh:47
HDBBrowserWindow::isRFImplementationSelected
bool isRFImplementationSelected()
Definition: HDBBrowserWindow.cc:376
HDBEditorModifyCmd
Definition: HDBEditorModifyCmd.hh:41
HDBEditorModifyCmd::create
virtual HDBEditorModifyCmd * create() const
Definition: HDBEditorModifyCmd.cc:207
HDB::FUArchitecture::architecture
TTAMachine::FunctionUnit & architecture() const
Definition: FUArchitecture.cc:131
HDB::HDBManager::removeFUImplementation
virtual void removeFUImplementation(RowID implementationID) const
Definition: HDBManager.cc:1325
HDBEditorModifyCmd::HDBEditorModifyCmd
HDBEditorModifyCmd()
Definition: HDBEditorModifyCmd.cc:60
RFImplementationDialog.hh
HDBEditorModifyCmd::~HDBEditorModifyCmd
virtual ~HDBEditorModifyCmd()
Definition: HDBEditorModifyCmd.cc:68
HDBEditorModifyCmd.hh
HDB::HDBManager::rfEntryIDOfImplementation
RowID rfEntryIDOfImplementation(RowID implID) const
Definition: HDBManager.cc:2796
Exception::fileName
std::string fileName() const
assert
#define assert(condition)
Definition: Application.hh:86
CostFunctionPluginDialog
Definition: CostFunctionPluginDialog.hh:46
GUICommand
Definition: GUICommand.hh:43
HDBEditorConstants::COMMAND_MODIFY
@ COMMAND_MODIFY
Definition: HDBEditorConstants.hh:59
ErrorDialog
Definition: ErrorDialog.hh:42
FUImplementationDialog.hh
RFImplementation.hh
HDBEditorModifyCmd::isEnabled
virtual bool isEnabled()
Definition: HDBEditorModifyCmd.cc:218
ErrorDialog.hh
HDBEditorMainFrame.hh
HDB::FUEntry::architecture
FUArchitecture & architecture() const
Definition: FUEntry.cc:129
Application.hh
FUEntry.hh
HDBBrowserWindow::selectedCostFunctionPlugin
RowID selectedCostFunctionPlugin()
Definition: HDBBrowserWindow.cc:598
HDB::HDBManager::fuEntryIDOfImplementation
RowID fuEntryIDOfImplementation(RowID implID) const
Definition: HDBManager.cc:2765
HDB::HDBManager
Definition: HDBManager.hh:82
RFArchitecture.hh
HDBEditorModifyCmd::Do
virtual bool Do()
Definition: HDBEditorModifyCmd.cc:75
HDB::RFEntry::implementation
RFImplementation & implementation() const
Definition: RFEntry.cc:102
HDBBrowserWindow::selectedRFImplementation
RowID selectedRFImplementation()
Definition: HDBBrowserWindow.cc:517
Exception
Definition: Exception.hh:54
FUImplementation.hh
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
HDB::HDBManager::addRFImplementation
RowID addRFImplementation(const RFImplementation &implementation, RowID rfEntryID)
Definition: HDBManager.cc:1640
HDBBrowserWindow::selectedFUImplementation
RowID selectedFUImplementation()
Definition: HDBBrowserWindow.cc:500
HDB::HWBlockImplementation::id
RowID id() const
Definition: HWBlockImplementation.cc:128
HDBEditorConstants
Definition: HDBEditorConstants.hh:42
HDB::HDBManager::removeRFImplementation
virtual void removeRFImplementation(RowID implID) const
Definition: HDBManager.cc:1808
HDBEditorModifyCmd::icon
virtual std::string icon() const
Definition: HDBEditorModifyCmd.cc:186
RFEntry.hh
WxConversion.hh
HDB::FUEntry::hasImplementation
virtual bool hasImplementation() const
Definition: FUEntry.cc:74
HDB::FUEntry::implementation
FUImplementation & implementation() const
Definition: FUEntry.cc:86
HDBManager.hh
HDB::HDBManager::fuByEntryID
FUEntry * fuByEntryID(RowID id) const
Definition: HDBManager.cc:2828
HDBBrowserWindow::isFUImplementationSelected
bool isFUImplementationSelected()
Definition: HDBBrowserWindow.cc:364
HDBBrowserWindow::isCostFunctionPluginSelected
bool isCostFunctionPluginSelected()
Definition: HDBBrowserWindow.cc:428
HDB::HWBlockImplementation::hasID
bool hasID() const
Definition: HWBlockImplementation.cc:105
RFImplementationDialog
Definition: RFImplementationDialog.hh:45
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
HDBEditorModifyCmd::id
virtual int id() const
Definition: HDBEditorModifyCmd.cc:196
HDB::HDBManager::rfByEntryID
RFEntry * rfByEntryID(RowID id) const
Definition: HDBManager.cc:2885