OpenASIP  2.0
AddRFImplementationCmd.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 AddRFImplementationCmd.cc
26  *
27  * Implementation of AddRFImplementationCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
34 #include "WxConversion.hh"
35 #include "HDBEditorConstants.hh"
36 #include "HDBEditor.hh"
37 #include "HDBEditorMainFrame.hh"
38 #include "HDBBrowserWindow.hh"
39 #include "HDBManager.hh"
41 #include "RFImplementation.hh"
42 #include "RFEntry.hh"
43 #include "ErrorDialog.hh"
44 
45 
46 /**
47  * The Constructor.
48  */
50  GUICommand(HDBEditorConstants::COMMAND_NAME_ADD_RF_IMPLEMENTATION, NULL) {
51 }
52 
53 
54 /**
55  * The Destructor.
56  */
58 }
59 
60 /**
61  * Executes the command.
62  */
63 bool
65 
66  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
67  if (manager == NULL) {
68  return false;
69  }
70 
71  HDBBrowserWindow* browser = wxGetApp().mainFrame().browser();
72 
74  = new HDB::RFImplementation("", "", "","", "", "", "");
75 
76  HDB::RFEntry* entry = NULL;
77 
78  if (browser->isRFEntrySelected()) {
79  entry = manager->rfByEntryID(browser->selectedRFEntry());
80  } else if (browser->isRFArchitectureSelected()) {
81  int id = manager->addRFEntry();
82  manager->setArchitectureForRF(id, browser->selectedRFArchitecture());
83  entry = manager->rfByEntryID(id);
84  } else {
85  return false;
86  }
87 
89 
90  if (dialog.ShowModal() == wxID_OK) {
91  try {
92  int id =
93  manager->addRFImplementation(*implementation, entry->id());
94  wxGetApp().mainFrame().update();
95  wxGetApp().mainFrame().browser()->selectRFImplementation(id);
96  } catch (Exception& e) {
97  wxString message = _T("Error:\n");
98  message.Append(WxConversion::toWxString(e.errorMessage()));
99  message.Append(_T("\n"));
100  message.Append(WxConversion::toWxString(e.lineNum()));
101  message.Append(_T(": "));
102  message.Append(WxConversion::toWxString(e.fileName()));
103  ErrorDialog dialog(parentWindow(), message);
104  dialog.ShowModal();
105  delete entry;
106  delete implementation;
107  return false;
108  }
109  } else {
110  delete implementation;
111  }
112 
113  delete entry;
114  return true;
115 }
116 
117 /**
118  * Returns name of the command icon file.
119  *
120  * @return Command icon file name.
121  */
122 std::string
124  return "";
125 }
126 
127 /**
128  * Returns the command id.
129  *
130  * @return Command identifier.
131  */
132 int
135 }
136 
137 
138 /**
139  * Creates a new instance of this command.
140  *
141  * @return Newly created instance of this command.
142  */
145  return new AddRFImplementationCmd();
146 }
147 
148 
149 /**
150  * Returns true if the command should be enabled in the tool/menubar.
151  *
152  * @return True if the command is enabled, false if not.
153  */
154 bool
156 
157  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
158 
159  if (manager == NULL) {
160  return false;
161  }
162 
163  HDBBrowserWindow* browser = wxGetApp().mainFrame().browser();
164 
165 
166  if (browser->isRFArchitectureSelected()) {
167  return true;
168  } else if (browser->isRFEntrySelected()) {
169  HDB::RFEntry* entry = manager->rfByEntryID(browser->selectedRFEntry());
170  if (entry->hasArchitecture() && !entry->hasImplementation()) {
171  delete entry;
172  return true;
173  }
174  delete entry;
175  }
176 
177  return false;
178 }
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
HDBBrowserWindow::isRFArchitectureSelected
bool isRFArchitectureSelected()
Definition: HDBBrowserWindow.cc:353
implementation
IDF::MachineImplementation * implementation
the implementation definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:61
HDB::HDBEntry::id
RowID id() const
Definition: HDBEntry.cc:85
HDBEditorConstants.hh
HDB::RFEntry
Definition: RFEntry.hh:47
AddRFImplementationCmd
Definition: AddRFImplementationCmd.hh:41
RFImplementationDialog.hh
AddRFImplementationCmd.hh
HDB::HDBManager::addRFEntry
RowID addRFEntry() const
Definition: HDBManager.cc:1557
AddRFImplementationCmd::Do
virtual bool Do()
Definition: AddRFImplementationCmd.cc:64
Exception::fileName
std::string fileName() const
GUICommand
Definition: GUICommand.hh:43
HDB::RFImplementation
Definition: RFImplementation.hh:50
ErrorDialog
Definition: ErrorDialog.hh:42
RFImplementation.hh
HDB::HDBManager::setArchitectureForRF
void setArchitectureForRF(RowID rfID, RowID archID) const
Definition: HDBManager.cc:1895
ErrorDialog.hh
HDBEditorMainFrame.hh
HDBEditorConstants::COMMAND_ADD_RF_IMPLEMENTATION
@ COMMAND_ADD_RF_IMPLEMENTATION
Definition: HDBEditorConstants.hh:52
HDB::HDBManager
Definition: HDBManager.hh:82
Exception
Definition: Exception.hh:54
AddRFImplementationCmd::isEnabled
virtual bool isEnabled()
Definition: AddRFImplementationCmd.cc:155
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
AddRFImplementationCmd::icon
virtual std::string icon() const
Definition: AddRFImplementationCmd.cc:123
AddRFImplementationCmd::~AddRFImplementationCmd
virtual ~AddRFImplementationCmd()
Definition: AddRFImplementationCmd.cc:57
HDB::HDBManager::addRFImplementation
RowID addRFImplementation(const RFImplementation &implementation, RowID rfEntryID)
Definition: HDBManager.cc:1640
AddRFImplementationCmd::create
virtual AddRFImplementationCmd * create() const
Definition: AddRFImplementationCmd.cc:144
HDBEditorConstants
Definition: HDBEditorConstants.hh:42
HDBBrowserWindow::selectedRFEntry
RowID selectedRFEntry()
Definition: HDBBrowserWindow.cc:549
RFEntry.hh
WxConversion.hh
AddRFImplementationCmd::AddRFImplementationCmd
AddRFImplementationCmd()
Definition: AddRFImplementationCmd.cc:49
HDBManager.hh
RFImplementationDialog
Definition: RFImplementationDialog.hh:45
HDB::RFEntry::hasArchitecture
virtual bool hasArchitecture() const
Definition: RFEntry.cc:117
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
HDBBrowserWindow::isRFEntrySelected
bool isRFEntrySelected()
Definition: HDBBrowserWindow.cc:397
HDB::HDBManager::rfByEntryID
RFEntry * rfByEntryID(RowID id) const
Definition: HDBManager.cc:2885
AddRFImplementationCmd::id
virtual int id() const
Definition: AddRFImplementationCmd.cc:133
HDBBrowserWindow::selectedRFArchitecture
RowID selectedRFArchitecture()
Definition: HDBBrowserWindow.cc:483