OpenASIP  2.0
EditParameterDialog.cc
Go to the documentation of this file.
1 
2 /*
3  Copyright (c) 2002-2009 Tampere University.
4 
5  This file is part of TTA-Based Codesign Environment (TCE).
6 
7  Permission is hereby granted, free of charge, to any person obtaining a
8  copy of this software and associated documentation files (the "Software"),
9  to deal in the Software without restriction, including without limitation
10  the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  and/or sell copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following conditions:
13 
14  The above copyright notice and this permission notice shall be included in
15  all copies or substantial portions of the Software.
16 
17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  DEALINGS IN THE SOFTWARE.
24  */
25 /**
26  * @file EditParameterDialog.cc
27  *
28  * Definition of EditParameterDialog class.
29  *
30  * @author Viljami Korhonen 2008 (viljami.korhonen-no.spam-.tut.fi)
31  * @note rating: red
32  */
33 
34 #include <string>
35 #include <wx/statline.h>
36 #include <wx/valgen.h>
37 #include <wx/spinctrl.h>
38 #include <boost/format.hpp>
39 
40 #include "CallExplorerPlugin.hh"
41 #include "Conversion.hh"
42 #include "WxConversion.hh"
43 #include "WarningDialog.hh"
44 #include "AddressSpace.hh"
45 #include "ModelConstants.hh"
46 #include "NumberControl.hh"
47 #include "InformationDialog.hh"
48 #include "MachineTester.hh"
49 #include "GUITextGenerator.hh"
50 #include "WidgetTools.hh"
51 #include "ProDeTextGenerator.hh"
52 #include "DesignSpaceExplorer.hh"
53 #include "EditParameterDialog.hh"
54 
55 using boost::format;
56 using std::string;
57 using namespace TTAMachine;
58 
59 BEGIN_EVENT_TABLE(EditParameterDialog, wxDialog)
64 
65 
66 /**
67  * The Constructor.
68  *
69  * @param parent Parent window of the dialog.
70  * @param addressSpace The address space to be modified with the dialog.
71  */
73  wxWindow* parent,
74  ExplorerPluginParameter* parameter):
75  wxDialog(parent, -1, _T(""), wxDefaultPosition), parameter_(parameter)
76  {
77  createContents(this, true, true);
78 
79  paramName_ = dynamic_cast<wxStaticText*>(FindWindow(ID_NAME));
80  paramType_ = dynamic_cast<wxStaticText*>(FindWindow(ID_TYPE));
81  paramValue_ = dynamic_cast<wxTextCtrl*>(FindWindow(ID_VALUE));
82 
83  // set widget texts
84  setTexts();
85 
86  TransferDataToWindow();
87 }
88 
89 
90 /**
91  * The Destructor.
92  */
94 }
95 
96 
97 /**
98  * Sets texts for widgets.
99  */
100 void
103 
104  // Dialog title
105  format fmt = prodeTexts->text(
107  SetTitle(WxConversion::toWxString(fmt.str()));
108 
109  paramName_->SetLabel(WxConversion::toWxString(parameter_->name()));
110  paramType_->SetLabel(WxConversion::toWxString(parameter_->typeAsString()));
111  paramValue_->Clear();
112  paramValue_->AppendText(WxConversion::toWxString(parameter_->value()));
113 }
114 
115 
116 /**
117  * Transfers data from the AddressSpace object to the dialog widgets.
118  *
119  * @return false, if an error occured in the transfer, true otherwise.
120  */
121 bool
123  return wxWindow::TransferDataToWindow();
124 }
125 
126 
127 /**
128  * Validates input in the controls, and updates the AddressSpace.
129  */
130 void
132  EndModal(wxID_OK);
133 }
134 
135 
136 /**
137  * Stores new value set by the user.
138  */
139 void
140 EditParameterDialog::onOk(wxCommandEvent&) {
141 
142  std::string value = WxConversion::toString(paramValue_->GetValue());
143 
144  parameter_->setValue(value);
145 
146  EndModal(wxID_OK);
147 }
148 
149 
150 /**
151  * Creates the dialog window contents.
152  *
153  * This method was generated with wxDesigner, thus the ugly code and
154  * too long lines.
155  *
156  * @return Main sizer of the created contents.
157  * @param parent The dialog window.
158  * @param call_fit If true, fits the contents inside the dialog.
159  * @param set_sizer If true, sets the main sizer as dialog contents.
160  */
161 wxSizer*
163  wxWindow* parent,
164  bool call_fit,
165  bool set_sizer) {
166 
167  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
168 
169  wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
170 
171  wxStaticText *item2 = new wxStaticText( parent, ID_TEXT, wxT("Parameter Name:"), wxDefaultPosition, wxDefaultSize, 0 );
172  item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
173 
174  wxStaticText *item3 = new wxStaticText( parent, ID_NAME, wxT("xxxxxxxxxxxxxxx"), wxDefaultPosition, wxSize(150,-1), 0 );
175  item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
176 
177  item0->Add( item1, 0, wxALL, 5 );
178 
179  wxBoxSizer *item4 = new wxBoxSizer( wxHORIZONTAL );
180 
181  wxStaticText *item5 = new wxStaticText( parent, ID_TEXT, wxT("Parameter Type:"), wxDefaultPosition, wxDefaultSize, 0 );
182  item4->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );
183 
184  wxStaticText *item6 = new wxStaticText( parent, ID_TYPE, wxT("xxxxxxxxxxxx"), wxDefaultPosition, wxSize(150,-1), 0 );
185  item4->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
186 
187  item0->Add( item4, 0, wxALL, 5 );
188 
189  wxBoxSizer *item7 = new wxBoxSizer( wxHORIZONTAL );
190 
191  wxStaticText *item8 = new wxStaticText( parent, ID_TEXT, wxT("Value:"), wxDefaultPosition, wxDefaultSize, 0 );
192  item7->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
193 
194  wxTextCtrl *item9 = new wxTextCtrl( parent, ID_VALUE, wxT(""), wxDefaultPosition, wxSize(110,-1), 0 );
195  item7->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
196 
197  item0->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );
198 
199  wxBoxSizer *item10 = new wxBoxSizer( wxHORIZONTAL );
200 
201  wxButton *item11 = new wxButton( parent, ID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
202  item10->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
203 
204  wxButton *item12 = new wxButton( parent, ID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
205  item10->Add( item12, 0, wxALL, 5 );
206 
207  item0->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
208 
209  if (set_sizer)
210  {
211  parent->SetSizer( item0 );
212  if (call_fit)
213  item0->SetSizeHints( parent );
214  }
215 
216  return item0;
217 }
218 
219 
EditParameterDialog::~EditParameterDialog
virtual ~EditParameterDialog()
Definition: EditParameterDialog.cc:93
EditParameterDialog::onClose
void onClose(wxCommandEvent &event)
Definition: EditParameterDialog.cc:131
EditParameterDialog.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
AddressSpace.hh
EditParameterDialog::onOk
void onOk(wxCommandEvent &event)
Definition: EditParameterDialog.cc:140
WidgetTools.hh
FindWindow
Definition: FindWindow.hh:49
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
CallExplorerPlugin.hh
ProDeTextGenerator.hh
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
WarningDialog.hh
NumberControl.hh
ExplorerPluginParameter
Definition: ExplorerPluginParameter.hh:46
Conversion.hh
InformationDialog.hh
ModelConstants.hh
EditParameterDialog
Definition: EditParameterDialog.hh:49
EditParameterDialog::setTexts
void setTexts()
Definition: EditParameterDialog.cc:101
GUITextGenerator.hh
MachineTester.hh
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
DesignSpaceExplorer.hh
WxConversion.hh
ProDeTextGenerator::TXT_EDIT_PARAMETER_TITLE
@ TXT_EDIT_PARAMETER_TITLE
Edit parameter title.
Definition: ProDeTextGenerator.hh:214
EditParameterDialog::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: EditParameterDialog.cc:122
TTAMachine
Definition: Assembler.hh:48
WxConversion::toString
static std::string toString(const wxString &source)
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
EditParameterDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: EditParameterDialog.cc:162