OpenASIP 2.2
Loading...
Searching...
No Matches
CostEstimationDataDialog.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 CostEstimationDataDialog.cc
26 *
27 * Implementation of CostEstimationDataDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <wx/statline.h>
34#include <wx/valgen.h>
36#include "WxConversion.hh"
37#include "HDBManager.hh"
38#include "ErrorDialog.hh"
39#include "Conversion.hh"
40
41using namespace HDB;
42
43BEGIN_EVENT_TABLE(CostEstimationDataDialog, wxDialog)
45 EVT_CHOICE(ID_ENTRY_TYPE, CostEstimationDataDialog::onEntryTypeSelection)
47
48const wxString CostEstimationDataDialog::ENTRY_TYPE_NONE = _T("None");
49const wxString CostEstimationDataDialog::ENTRY_TYPE_FU = _T("FU");
50const wxString CostEstimationDataDialog::ENTRY_TYPE_RF = _T("RF");
51const wxString CostEstimationDataDialog::ENTRY_TYPE_BUS = _T("Bus");
52const wxString CostEstimationDataDialog::ENTRY_TYPE_SOCKET = _T("Socket");
53
54/**
55 * The Constructor.
56 *
57 * @param parent Parent window of the dialog.
58 * @param id Window identifier for the dialog.
59 * @param hdb HDBManager where the data is added/modified.
60 * @param dataID ID of the cost data to modify or -1 if a new data is being
61 * added.
62 */
64 wxWindow* parent, wxWindowID id, HDBManager& hdb, RowID pluginID,
65 RowID dataID):
66 wxDialog(parent, id, _T("Cost Estimation Data")),
67 hdb_(hdb), pluginID_(pluginID), dataID_(dataID) {
68
69 createContents(this, true, true);
70
71 typeChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_ENTRY_TYPE));
72 idChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_ENTRY_ID));
73
74 typeChoice_->Append(ENTRY_TYPE_NONE);
75 typeChoice_->Append(ENTRY_TYPE_FU);
76 typeChoice_->Append(ENTRY_TYPE_RF);
77 typeChoice_->Append(ENTRY_TYPE_BUS);
78 typeChoice_->Append(ENTRY_TYPE_SOCKET);
79
80 FindWindow(ID_NAME)->SetValidator(wxGenericValidator(&name_));
81 FindWindow(ID_VALUE)->SetValidator(wxGenericValidator(&value_));
82
83 if (dataID_ >= 0) {
84 typeChoice_->Disable();
85 idChoice_->Disable();
86 }
87
88}
89
90/**
91 * The Destructor.
92 */
95
96/**
97 * Transfers data to the dialog widgets.
98 *
99 * @return True, if the data was succesfully transferred.
100 */
101bool
103
104 if (dataID_ >= 0) {
108
109 if (data.hasFUReference()) {
110 typeChoice_->SetStringSelection(ENTRY_TYPE_FU);
112 } else if (data.hasRFReference()) {
113 typeChoice_->SetStringSelection(ENTRY_TYPE_RF);
115 } else if (data.hasBusReference()) {
116 typeChoice_->SetStringSelection(ENTRY_TYPE_BUS);
118 } else if (data.hasSocketReference()) {
119 typeChoice_->SetStringSelection(ENTRY_TYPE_SOCKET);
120 idChoice_->Append(
122 }
123 idChoice_->SetSelection(0);
124 } else {
125 typeChoice_->SetSelection(0);
126 wxCommandEvent dummy;
128 }
129
130 return wxDialog::TransferDataToWindow();
131}
132
133/**
134 * Event handler for the entry type choicer selections.
135 */
136void
138
139 idChoice_->Clear();
140
141 if (typeChoice_->GetStringSelection() == ENTRY_TYPE_FU) {
142 // Append FU entry IDs to the entry id choicer
143 const std::set<RowID> fuIDs = hdb_.fuEntryIDs();
144 std::set<RowID>::const_iterator iter = fuIDs.begin();
145 for (; iter != fuIDs.end(); iter++) {
146 idChoice_->Append(WxConversion::toWxString(*iter));
147 }
148 } else if (typeChoice_->GetStringSelection() == ENTRY_TYPE_RF) {
149 // Append RF entry IDs to the entry id choicer
150 const std::set<RowID> rfIDs = hdb_.rfEntryIDs();
151 std::set<RowID>::const_iterator iter = rfIDs.begin();
152 for (; iter != rfIDs.end(); iter++) {
153 idChoice_->Append(WxConversion::toWxString(*iter));
154 }
155 } else if (typeChoice_->GetStringSelection() == ENTRY_TYPE_BUS) {
156 // Append FU entry IDs to the entry id choicer
157 const std::set<RowID> busIDs = hdb_.busEntryIDs();
158 std::set<RowID>::const_iterator iter = busIDs.begin();
159 for (; iter != busIDs.end(); iter++) {
160 idChoice_->Append(WxConversion::toWxString(*iter));
161 }
162
163 } else if (typeChoice_->GetStringSelection() == ENTRY_TYPE_SOCKET) {
164 // Append FU entry IDs to the entry id choicer
165 const std::set<RowID> socketIDs = hdb_.socketEntryIDs();
166 std::set<RowID>::const_iterator iter = socketIDs.begin();
167 for (; iter != socketIDs.end(); iter++) {
168 idChoice_->Append(WxConversion::toWxString(*iter));
169 }
170 } else {
171 idChoice_->Disable();
172 return;
173 }
174
175 idChoice_->Enable();
176 idChoice_->SetSelection(0);
177}
178
179/**
180 * Event handler for the ok-button.
181 */
182void
184
185 TransferDataFromWindow();
186
187 if (name_.IsEmpty()) {
188 wxString message(_T("Data name not set."));
189 ErrorDialog dialog(this, message);
190 dialog.ShowModal();
191 return;
192 }
193
198 data.setValue(value);
199
200
201 std::string idStr =
202 WxConversion::toString(idChoice_->GetStringSelection());
203
204 if (typeChoice_->GetStringSelection() != ENTRY_TYPE_NONE) {
205
206 if (idStr == "") {
207 wxString message(_T("Invalid entry reference."));
208 ErrorDialog dialog(this, message);
209 dialog.ShowModal();
210 return;
211 }
212
213 RowID id = Conversion::toInt(idStr);
214
215 if (typeChoice_->GetStringSelection() == ENTRY_TYPE_FU) {
216 data.setFUReference(id);
217 } else if (typeChoice_->GetStringSelection() == ENTRY_TYPE_RF) {
218 data.setRFReference(id);
219 } else if (typeChoice_->GetStringSelection() == ENTRY_TYPE_BUS) {
220 data.setBusReference(id);
221 } else if (typeChoice_->GetStringSelection() == ENTRY_TYPE_SOCKET) {
222 data.setSocketReference(id);
223 }
224 }
225
226 if (dataID_ >= 0) {
228 } else {
230 }
231
232 EndModal(wxID_OK);
233}
234
235/**
236 * Creates the dialog widgets.
237 */
238wxSizer*
240 wxWindow* parent, bool call_fit, bool set_sizer) {
241
242 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
243
244 wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 );
245
246 wxStaticText *item2 = new wxStaticText( parent, ID_TEXT, wxT("Entry type:"), wxDefaultPosition, wxDefaultSize, 0 );
247 item1->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
248
249 wxString *strs3 = (wxString*) NULL;
250 wxChoice *item3 = new wxChoice( parent, ID_ENTRY_TYPE, wxDefaultPosition, wxSize(100,-1), 0, strs3, 0 );
251 item1->Add( item3, 0, wxGROW|wxALL, 5 );
252
253 wxStaticText *item4 = new wxStaticText( parent, ID_TEXT, wxT("Entry ID:"), wxDefaultPosition, wxDefaultSize, 0 );
254 item1->Add( item4, 0, wxALIGN_RIGHT|wxALL, 5 );
255
256 wxString *strs5 = (wxString*) NULL;
257 wxChoice *item5 = new wxChoice( parent, ID_ENTRY_ID, wxDefaultPosition, wxSize(100,-1), 0, strs5, 0 );
258 item1->Add( item5, 0, wxGROW|wxALL, 5 );
259
260 wxStaticText *item6 = new wxStaticText( parent, ID_TEXT, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
261 item1->Add( item6, 0, wxALIGN_RIGHT|wxALL, 5 );
262
263 wxTextCtrl *item7 = new wxTextCtrl( parent, ID_NAME, wxT(""), wxDefaultPosition, wxSize(200,-1), 0 );
264 item1->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );
265
266 wxStaticText *item8 = new wxStaticText( parent, ID_TEXT, wxT("Value:"), wxDefaultPosition, wxDefaultSize, 0 );
267 item1->Add( item8, 0, wxALIGN_RIGHT|wxALL, 5 );
268
269 wxTextCtrl *item9 = new wxTextCtrl( parent, ID_VALUE, wxT(""), wxDefaultPosition, wxSize(200,-1), 0 );
270 item1->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
271
272 item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
273
274 wxStaticLine *item10 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
275 item0->Add( item10, 0, wxGROW|wxALL, 5 );
276
277 wxBoxSizer *item11 = new wxBoxSizer( wxHORIZONTAL );
278
279 wxButton *item12 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
280 item11->Add( item12, 0, wxALIGN_CENTER|wxALL, 5 );
281
282 wxButton *item13 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
283 item11->Add( item13, 0, wxALIGN_CENTER|wxALL, 5 );
284
285 item0->Add( item11, 0, wxALL, 5 );
286
287 if (set_sizer)
288 {
289 parent->SetSizer( item0 );
290 if (call_fit)
291 item0->SetSizeHints( parent );
292 }
293
294 return item0;
295}
END_EVENT_TABLE() using namespace IDF
int RowID
Type definition of row ID in relational databases.
Definition DBTypes.hh:37
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
const string FU
const string RF
SimValue dummy(32)
a dummy simvalue which is given for operands that are not bound
static int toInt(const T &source)
wxChoice * typeChoice_
Entry reference type choice widget.
static const wxString ENTRY_TYPE_SOCKET
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
static const wxString ENTRY_TYPE_NONE
void onOK(wxCommandEvent &event)
static const wxString ENTRY_TYPE_BUS
static const wxString ENTRY_TYPE_FU
RowID dataID_
ID of the data to modify, or -1 if new data is being added.
HDB::HDBManager & hdb_
HDB Containing the data.
wxString value_
Value of the data.
RowID pluginID_
ID of the data's parent plugin.
wxChoice * idChoice_
Entry reference id choice widget.
static const wxString ENTRY_TYPE_RF
wxString name_
Name of the data.
void onEntryTypeSelection(wxCommandEvent &event)
DataObject value() const
void setBusReference(RowID busEntryID)
void setValue(const DataObject &value)
bool hasBusReference() const
bool hasFUReference() const
std::string name() const
void setPluginID(RowID pluginID)
RowID socketReference() const
void setRFReference(RowID rfEntryID)
bool hasSocketReference() const
void setSocketReference(RowID socketEntryID)
void setFUReference(RowID fuEntryID)
void setName(const std::string &name)
bool hasRFReference() const
virtual std::string stringValue() const
virtual void modifyCostEstimationData(RowID id, const CostEstimationData &data)
CostEstimationData costEstimationData(RowID id) const
std::set< RowID > socketEntryIDs() const
std::set< RowID > rfEntryIDs() const
std::set< RowID > busEntryIDs() const
std::set< RowID > fuEntryIDs() const
RowID addCostEstimationData(const CostEstimationData &data) const
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)