OpenASIP  2.0
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 
41 using namespace HDB;
42 
43 BEGIN_EVENT_TABLE(CostEstimationDataDialog, wxDialog)
45  EVT_CHOICE(ID_ENTRY_TYPE, CostEstimationDataDialog::onEntryTypeSelection)
47 
48 const wxString CostEstimationDataDialog::ENTRY_TYPE_NONE = _T("None");
49 const wxString CostEstimationDataDialog::ENTRY_TYPE_FU = _T("FU");
50 const wxString CostEstimationDataDialog::ENTRY_TYPE_RF = _T("RF");
51 const wxString CostEstimationDataDialog::ENTRY_TYPE_BUS = _T("Bus");
52 const 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  */
94 }
95 
96 /**
97  * Transfers data to the dialog widgets.
98  *
99  * @return True, if the data was succesfully transferred.
100  */
101 bool
103 
104  if (dataID_ >= 0) {
105  const CostEstimationData data = hdb_.costEstimationData(dataID_);
106  name_ = WxConversion::toWxString(data.name());
107  value_ = WxConversion::toWxString(data.value().stringValue());
108 
109  if (data.hasFUReference()) {
110  typeChoice_->SetStringSelection(ENTRY_TYPE_FU);
111  idChoice_->Append(WxConversion::toWxString(data.fuReference()));
112  } else if (data.hasRFReference()) {
113  typeChoice_->SetStringSelection(ENTRY_TYPE_RF);
114  idChoice_->Append(WxConversion::toWxString(data.rfReference()));
115  } else if (data.hasBusReference()) {
116  typeChoice_->SetStringSelection(ENTRY_TYPE_BUS);
117  idChoice_->Append(WxConversion::toWxString(data.busReference()));
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;
127  onEntryTypeSelection(dummy);
128  }
129 
130  return wxDialog::TransferDataToWindow();
131 }
132 
133 /**
134  * Event handler for the entry type choicer selections.
135  */
136 void
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  */
182 void
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 
194  CostEstimationData data;
195  data.setPluginID(pluginID_);
196  data.setName(WxConversion::toString(name_));
197  DataObject value(WxConversion::toString(value_));
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) {
227  hdb_.modifyCostEstimationData(dataID_, data);
228  } else {
229  hdb_.addCostEstimationData(data);
230  }
231 
232  EndModal(wxID_OK);
233 }
234 
235 /**
236  * Creates the dialog widgets.
237  */
238 wxSizer*
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 }
CostEstimationData::rfReference
RowID rfReference() const
Definition: CostEstimationData.cc:118
CostEstimationData::setName
void setName(const std::string &name)
WxConversion::toWxString
static wxString toWxString(const std::string &source)
CostEstimationData::name
std::string name() const
Definition: CostEstimationData.cc:58
HDB
Definition: CostDatabase.hh:49
FU
const string FU
Definition: IDFSerializer.cc:64
DataObject
Definition: DataObject.hh:50
DataObject::stringValue
virtual std::string stringValue() const
Definition: DataObject.cc:344
CostEstimationData::hasSocketReference
bool hasSocketReference() const
CostEstimationDataDialog::~CostEstimationDataDialog
virtual ~CostEstimationDataDialog()
Definition: CostEstimationDataDialog.cc:93
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
CostEstimationData::setFUReference
void setFUReference(RowID fuEntryID)
CostEstimationData::setRFReference
void setRFReference(RowID rfEntryID)
CostEstimationData::hasFUReference
bool hasFUReference() const
FindWindow
Definition: FindWindow.hh:49
CostEstimationData::setValue
void setValue(const DataObject &value)
CostEstimationDataDialog::onEntryTypeSelection
void onEntryTypeSelection(wxCommandEvent &event)
Definition: CostEstimationDataDialog.cc:137
CostEstimationDataDialog
Definition: CostEstimationDataDialog.hh:46
CostEstimationData::busReference
RowID busReference() const
Definition: CostEstimationData.cc:133
ErrorDialog
Definition: ErrorDialog.hh:42
CostEstimationData::setBusReference
void setBusReference(RowID busEntryID)
ErrorDialog.hh
Conversion.hh
dummy
SimValue dummy(32)
a dummy simvalue which is given for operands that are not bound
CostEstimationDataDialog::onOK
void onOK(wxCommandEvent &event)
Definition: CostEstimationDataDialog.cc:183
HDB::HDBManager
Definition: HDBManager.hh:82
CostEstimationData::socketReference
RowID socketReference() const
Definition: CostEstimationData.cc:148
CostEstimationDataDialog.hh
CostEstimationData
Definition: CostEstimationData.hh:42
CostEstimationData::value
DataObject value() const
Definition: CostEstimationData.cc:73
CostEstimationDataDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: CostEstimationDataDialog.cc:239
CostEstimationData::hasBusReference
bool hasBusReference() const
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
CostEstimationDataDialog::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: CostEstimationDataDialog.cc:102
CostEstimationData::fuReference
RowID fuReference() const
Definition: CostEstimationData.cc:103
CostEstimationData::setPluginID
void setPluginID(RowID pluginID)
CostEstimationData::hasRFReference
bool hasRFReference() const
CostEstimationData::setSocketReference
void setSocketReference(RowID socketEntryID)
WxConversion.hh
Conversion::toInt
static int toInt(const T &source)
HDBManager.hh
WxConversion::toString
static std::string toString(const wxString &source)
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF